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