1*bb611c8fSApple OSS Distributions // 2*bb611c8fSApple OSS Distributions // Tests for 3*bb611c8fSApple OSS Distributions // size_t size() const; 4*bb611c8fSApple OSS Distributions // 5*bb611c8fSApple OSS Distributions 6*bb611c8fSApple OSS Distributions #include <libkern/c++/bounded_array_ref.h> 7*bb611c8fSApple OSS Distributions #include "test_policy.h" 8*bb611c8fSApple OSS Distributions #include <cstddef> 9*bb611c8fSApple OSS Distributions #include <darwintest.h> 10*bb611c8fSApple OSS Distributions #include <darwintest_utils.h> 11*bb611c8fSApple OSS Distributions 12*bb611c8fSApple OSS Distributions struct T { int i; }; 13*bb611c8fSApple OSS Distributions 14*bb611c8fSApple OSS Distributions template <typename T> 15*bb611c8fSApple OSS Distributions static void 16*bb611c8fSApple OSS Distributions tests() 17*bb611c8fSApple OSS Distributions { 18*bb611c8fSApple OSS Distributions T array[5] = {T{0}, T{1}, T{2}, T{3}, T{4}}; 19*bb611c8fSApple OSS Distributions 20*bb611c8fSApple OSS Distributions { 21*bb611c8fSApple OSS Distributions test_bounded_array_ref<T> const view(&array[0], static_cast<std::size_t>(0)); 22*bb611c8fSApple OSS Distributions std::size_t size = view.size(); 23*bb611c8fSApple OSS Distributions CHECK(size == 0); 24*bb611c8fSApple OSS Distributions } 25*bb611c8fSApple OSS Distributions { 26*bb611c8fSApple OSS Distributions test_bounded_array_ref<T> const view(&array[0], 1); 27*bb611c8fSApple OSS Distributions std::size_t size = view.size(); 28*bb611c8fSApple OSS Distributions CHECK(size == 1); 29*bb611c8fSApple OSS Distributions } 30*bb611c8fSApple OSS Distributions { 31*bb611c8fSApple OSS Distributions test_bounded_array_ref<T> const view(&array[0], 2); 32*bb611c8fSApple OSS Distributions std::size_t size = view.size(); 33*bb611c8fSApple OSS Distributions CHECK(size == 2); 34*bb611c8fSApple OSS Distributions } 35*bb611c8fSApple OSS Distributions { 36*bb611c8fSApple OSS Distributions test_bounded_array_ref<T> const view(&array[0], 5); 37*bb611c8fSApple OSS Distributions std::size_t size = view.size(); 38*bb611c8fSApple OSS Distributions CHECK(size == 5); 39*bb611c8fSApple OSS Distributions } 40*bb611c8fSApple OSS Distributions } 41*bb611c8fSApple OSS Distributions 42*bb611c8fSApple OSS Distributions T_DECL(size, "bounded_array_ref.size") { 43*bb611c8fSApple OSS Distributions tests<T>(); 44*bb611c8fSApple OSS Distributions tests<T const>(); 45*bb611c8fSApple OSS Distributions } 46