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