1*043036a2SApple OSS Distributions // 2*043036a2SApple OSS Distributions // Tests for 3*043036a2SApple OSS Distributions // template <size_t N> 4*043036a2SApple OSS Distributions // bounded_array_ref(T (&array)[N]); 5*043036a2SApple OSS Distributions // 6*043036a2SApple OSS Distributions 7*043036a2SApple OSS Distributions #include <libkern/c++/bounded_array_ref.h> 8*043036a2SApple OSS Distributions #include "test_policy.h" 9*043036a2SApple OSS Distributions #include <darwintest.h> 10*043036a2SApple OSS Distributions #include <darwintest_utils.h> 11*043036a2SApple OSS Distributions 12*043036a2SApple OSS Distributions struct T { int i; }; 13*043036a2SApple OSS Distributions inline bool operator ==(T const & a,T const & b)14*043036a2SApple OSS Distributionsoperator==(T const& a, T const& b) 15*043036a2SApple OSS Distributions { 16*043036a2SApple OSS Distributions return a.i == b.i; 17*043036a2SApple OSS Distributions }; 18*043036a2SApple OSS Distributions 19*043036a2SApple OSS Distributions template <typename T> 20*043036a2SApple OSS Distributions static void tests()21*043036a2SApple OSS Distributionstests() 22*043036a2SApple OSS Distributions { 23*043036a2SApple OSS Distributions { 24*043036a2SApple OSS Distributions T array[5] = {T{0}, T{1}, T{2}, T{3}, T{4}}; 25*043036a2SApple OSS Distributions test_bounded_array_ref<T> view(array); 26*043036a2SApple OSS Distributions CHECK(view.data() == &array[0]); 27*043036a2SApple OSS Distributions CHECK(view.size() == 5); 28*043036a2SApple OSS Distributions CHECK(view[0] == T{0}); 29*043036a2SApple OSS Distributions CHECK(view[1] == T{1}); 30*043036a2SApple OSS Distributions CHECK(view[2] == T{2}); 31*043036a2SApple OSS Distributions CHECK(view[3] == T{3}); 32*043036a2SApple OSS Distributions CHECK(view[4] == T{4}); 33*043036a2SApple OSS Distributions } 34*043036a2SApple OSS Distributions 35*043036a2SApple OSS Distributions { 36*043036a2SApple OSS Distributions T array[1] = {T{11}}; 37*043036a2SApple OSS Distributions test_bounded_array_ref<T> view(array); 38*043036a2SApple OSS Distributions CHECK(view.data() == &array[0]); 39*043036a2SApple OSS Distributions CHECK(view.size() == 1); 40*043036a2SApple OSS Distributions CHECK(view[0] == T{11}); 41*043036a2SApple OSS Distributions } 42*043036a2SApple OSS Distributions 43*043036a2SApple OSS Distributions // Also test implicit construction 44*043036a2SApple OSS Distributions { 45*043036a2SApple OSS Distributions T array[1] = {T{11}}; 46*043036a2SApple OSS Distributions test_bounded_array_ref<T> view = array; 47*043036a2SApple OSS Distributions CHECK(view.data() == &array[0]); 48*043036a2SApple OSS Distributions CHECK(view.size() == 1); 49*043036a2SApple OSS Distributions } 50*043036a2SApple OSS Distributions { 51*043036a2SApple OSS Distributions T array[1] = {T{11}}; 52*043036a2SApple OSS Distributions auto check = [&array](test_bounded_array_ref<T> view) { 53*043036a2SApple OSS Distributions CHECK(view.data() == &array[0]); 54*043036a2SApple OSS Distributions CHECK(view.size() == 1); 55*043036a2SApple OSS Distributions }; 56*043036a2SApple OSS Distributions check(array); 57*043036a2SApple OSS Distributions } 58*043036a2SApple OSS Distributions } 59*043036a2SApple OSS Distributions 60*043036a2SApple OSS Distributions T_DECL(ctor_C_array, "bounded_array_ref.ctor.C_array", T_META_TAG_VM_PREFERRED) { 61*043036a2SApple OSS Distributions tests<T>(); 62*043036a2SApple OSS Distributions } 63