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