1*c54f35caSApple OSS Distributions // 2*c54f35caSApple OSS Distributions // Tests for 3*c54f35caSApple OSS Distributions // bounded_array(); 4*c54f35caSApple OSS Distributions // 5*c54f35caSApple OSS Distributions 6*c54f35caSApple OSS Distributions #include <libkern/c++/bounded_array.h> 7*c54f35caSApple OSS Distributions #include <darwintest.h> 8*c54f35caSApple OSS Distributions #include <darwintest_utils.h> 9*c54f35caSApple OSS Distributions #include "test_policy.h" 10*c54f35caSApple OSS Distributions 11*c54f35caSApple OSS Distributions struct T { TT12*c54f35caSApple OSS Distributions T() : i(4) 13*c54f35caSApple OSS Distributions { 14*c54f35caSApple OSS Distributions } 15*c54f35caSApple OSS Distributions int i; 16*c54f35caSApple OSS Distributions friend bool operator ==(T const & a,T const & b)17*c54f35caSApple OSS Distributions operator==(T const& a, T const& b) 18*c54f35caSApple OSS Distributions { 19*c54f35caSApple OSS Distributions return a.i == b.i; 20*c54f35caSApple OSS Distributions } 21*c54f35caSApple OSS Distributions }; 22*c54f35caSApple OSS Distributions 23*c54f35caSApple OSS Distributions template <typename T> 24*c54f35caSApple OSS Distributions static void tests()25*c54f35caSApple OSS Distributionstests() 26*c54f35caSApple OSS Distributions { 27*c54f35caSApple OSS Distributions { 28*c54f35caSApple OSS Distributions test_bounded_array<T, 10> array; 29*c54f35caSApple OSS Distributions CHECK(array.size() == 10); 30*c54f35caSApple OSS Distributions T* end = array.data() + array.size(); 31*c54f35caSApple OSS Distributions for (auto it = array.data(); it != end; ++it) { 32*c54f35caSApple OSS Distributions CHECK(*it == T()); 33*c54f35caSApple OSS Distributions } 34*c54f35caSApple OSS Distributions } 35*c54f35caSApple OSS Distributions { 36*c54f35caSApple OSS Distributions test_bounded_array<T, 10> array{}; 37*c54f35caSApple OSS Distributions CHECK(array.size() == 10); 38*c54f35caSApple OSS Distributions T* end = array.data() + array.size(); 39*c54f35caSApple OSS Distributions for (auto it = array.data(); it != end; ++it) { 40*c54f35caSApple OSS Distributions CHECK(*it == T()); 41*c54f35caSApple OSS Distributions } 42*c54f35caSApple OSS Distributions } 43*c54f35caSApple OSS Distributions { 44*c54f35caSApple OSS Distributions test_bounded_array<T, 10> array = {}; 45*c54f35caSApple OSS Distributions CHECK(array.size() == 10); 46*c54f35caSApple OSS Distributions T* end = array.data() + array.size(); 47*c54f35caSApple OSS Distributions for (auto it = array.data(); it != end; ++it) { 48*c54f35caSApple OSS Distributions CHECK(*it == T()); 49*c54f35caSApple OSS Distributions } 50*c54f35caSApple OSS Distributions } 51*c54f35caSApple OSS Distributions { 52*c54f35caSApple OSS Distributions test_bounded_array<T, 10> array = test_bounded_array<T, 10>(); 53*c54f35caSApple OSS Distributions CHECK(array.size() == 10); 54*c54f35caSApple OSS Distributions T* end = array.data() + array.size(); 55*c54f35caSApple OSS Distributions for (auto it = array.data(); it != end; ++it) { 56*c54f35caSApple OSS Distributions CHECK(*it == T()); 57*c54f35caSApple OSS Distributions } 58*c54f35caSApple OSS Distributions } 59*c54f35caSApple OSS Distributions 60*c54f35caSApple OSS Distributions // Check with a 0-sized array 61*c54f35caSApple OSS Distributions { 62*c54f35caSApple OSS Distributions test_bounded_array<T, 0> array; 63*c54f35caSApple OSS Distributions CHECK(array.size() == 0); 64*c54f35caSApple OSS Distributions } 65*c54f35caSApple OSS Distributions } 66*c54f35caSApple OSS Distributions 67*c54f35caSApple OSS Distributions T_DECL(ctor_default, "bounded_array.ctor.default") { 68*c54f35caSApple OSS Distributions tests<T>(); 69*c54f35caSApple OSS Distributions } 70