1*bb611c8fSApple OSS Distributions // 2*bb611c8fSApple OSS Distributions // Tests for 3*bb611c8fSApple OSS Distributions // iterator begin(); 4*bb611c8fSApple OSS Distributions // const_iterator begin() const; 5*bb611c8fSApple OSS Distributions // 6*bb611c8fSApple OSS Distributions // iterator end(); 7*bb611c8fSApple OSS Distributions // const_iterator end() const; 8*bb611c8fSApple OSS Distributions // 9*bb611c8fSApple OSS Distributions 10*bb611c8fSApple OSS Distributions #include <libkern/c++/bounded_array.h> 11*bb611c8fSApple OSS Distributions #include "test_policy.h" 12*bb611c8fSApple OSS Distributions #include <darwintest.h> 13*bb611c8fSApple OSS Distributions #include <type_traits> 14*bb611c8fSApple OSS Distributions 15*bb611c8fSApple OSS Distributions struct T { int i; }; 16*bb611c8fSApple OSS Distributions 17*bb611c8fSApple OSS Distributions template <typename T> 18*bb611c8fSApple OSS Distributions static void 19*bb611c8fSApple OSS Distributions tests() 20*bb611c8fSApple OSS Distributions { 21*bb611c8fSApple OSS Distributions // Check begin()/end() for a non-empty array 22*bb611c8fSApple OSS Distributions { 23*bb611c8fSApple OSS Distributions test_bounded_array<T, 5> array = {T{0}, T{1}, T{2}, T{3}, T{4}}; 24*bb611c8fSApple OSS Distributions test_bounded_ptr<T> begin = array.begin(); 25*bb611c8fSApple OSS Distributions test_bounded_ptr<T> end = array.end(); 26*bb611c8fSApple OSS Distributions CHECK(begin.discard_bounds() == array.data()); 27*bb611c8fSApple OSS Distributions CHECK(end.unsafe_discard_bounds() == array.data() + 5); 28*bb611c8fSApple OSS Distributions } 29*bb611c8fSApple OSS Distributions { 30*bb611c8fSApple OSS Distributions test_bounded_array<T, 5> const array = {T{0}, T{1}, T{2}, T{3}, T{4}}; 31*bb611c8fSApple OSS Distributions test_bounded_ptr<T const> begin = array.begin(); 32*bb611c8fSApple OSS Distributions test_bounded_ptr<T const> end = array.end(); 33*bb611c8fSApple OSS Distributions CHECK(begin.discard_bounds() == array.data()); 34*bb611c8fSApple OSS Distributions CHECK(end.unsafe_discard_bounds() == array.data() + 5); 35*bb611c8fSApple OSS Distributions } 36*bb611c8fSApple OSS Distributions 37*bb611c8fSApple OSS Distributions // Check begin()/end() for an empty array 38*bb611c8fSApple OSS Distributions { 39*bb611c8fSApple OSS Distributions test_bounded_array<T, 0> array = {}; 40*bb611c8fSApple OSS Distributions test_bounded_ptr<T> begin = array.begin(); 41*bb611c8fSApple OSS Distributions test_bounded_ptr<T> end = array.end(); 42*bb611c8fSApple OSS Distributions CHECK(begin.unsafe_discard_bounds() == array.data()); 43*bb611c8fSApple OSS Distributions CHECK(end.unsafe_discard_bounds() == array.data()); 44*bb611c8fSApple OSS Distributions } 45*bb611c8fSApple OSS Distributions { 46*bb611c8fSApple OSS Distributions test_bounded_array<T, 0> const array = {}; 47*bb611c8fSApple OSS Distributions test_bounded_ptr<T const> begin = array.begin(); 48*bb611c8fSApple OSS Distributions test_bounded_ptr<T const> end = array.end(); 49*bb611c8fSApple OSS Distributions CHECK(begin.unsafe_discard_bounds() == array.data()); 50*bb611c8fSApple OSS Distributions CHECK(end.unsafe_discard_bounds() == array.data()); 51*bb611c8fSApple OSS Distributions } 52*bb611c8fSApple OSS Distributions 53*bb611c8fSApple OSS Distributions // Check associated types 54*bb611c8fSApple OSS Distributions { 55*bb611c8fSApple OSS Distributions using A = test_bounded_array<T, 10>; 56*bb611c8fSApple OSS Distributions static_assert(std::is_same_v<typename A::iterator, test_bounded_ptr<T> >); 57*bb611c8fSApple OSS Distributions static_assert(std::is_same_v<typename A::const_iterator, test_bounded_ptr<T const> >); 58*bb611c8fSApple OSS Distributions } 59*bb611c8fSApple OSS Distributions } 60*bb611c8fSApple OSS Distributions 61*bb611c8fSApple OSS Distributions T_DECL(begin_end, "bounded_array.begin_end") { 62*bb611c8fSApple OSS Distributions tests<T>(); 63*bb611c8fSApple OSS Distributions } 64