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