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