xref: /xnu-8796.121.2/tests/bounded_array_src/data.cpp (revision c54f35ca767986246321eb901baf8f5ff7923f6a)
1*c54f35caSApple OSS Distributions //
2*c54f35caSApple OSS Distributions // Tests for
3*c54f35caSApple OSS Distributions //  T* data();
4*c54f35caSApple OSS Distributions //  T const* data() const;
5*c54f35caSApple OSS Distributions //
6*c54f35caSApple OSS Distributions 
7*c54f35caSApple OSS Distributions #include <libkern/c++/bounded_array.h>
8*c54f35caSApple OSS Distributions #include "test_policy.h"
9*c54f35caSApple OSS Distributions #include <darwintest.h>
10*c54f35caSApple OSS Distributions #include <type_traits>
11*c54f35caSApple OSS Distributions 
12*c54f35caSApple OSS Distributions struct T { int i; };
13*c54f35caSApple OSS Distributions inline bool
operator ==(T const & a,T const & b)14*c54f35caSApple OSS Distributions operator==(T const& a, T const& b)
15*c54f35caSApple OSS Distributions {
16*c54f35caSApple OSS Distributions 	return a.i == b.i;
17*c54f35caSApple OSS Distributions }
18*c54f35caSApple OSS Distributions 
19*c54f35caSApple OSS Distributions template <typename T>
20*c54f35caSApple OSS Distributions static void
tests()21*c54f35caSApple OSS Distributions tests()
22*c54f35caSApple OSS Distributions {
23*c54f35caSApple OSS Distributions 	{
24*c54f35caSApple OSS Distributions 		test_bounded_array<T, 5> array = {T{0}, T{1}, T{2}, T{3}, T{4}};
25*c54f35caSApple OSS Distributions 		T* data = array.data();
26*c54f35caSApple OSS Distributions 		CHECK(data != nullptr);
27*c54f35caSApple OSS Distributions 		CHECK(data[0] == T{0});
28*c54f35caSApple OSS Distributions 		CHECK(data[1] == T{1});
29*c54f35caSApple OSS Distributions 		CHECK(data[2] == T{2});
30*c54f35caSApple OSS Distributions 		CHECK(data[3] == T{3});
31*c54f35caSApple OSS Distributions 		CHECK(data[4] == T{4});
32*c54f35caSApple OSS Distributions 	}
33*c54f35caSApple OSS Distributions 	{
34*c54f35caSApple OSS Distributions 		test_bounded_array<T, 5> const array = {T{0}, T{1}, T{2}, T{3}, T{4}};
35*c54f35caSApple OSS Distributions 		T const* data = array.data();
36*c54f35caSApple OSS Distributions 		CHECK(data != nullptr);
37*c54f35caSApple OSS Distributions 		CHECK(data[0] == T{0});
38*c54f35caSApple OSS Distributions 		CHECK(data[1] == T{1});
39*c54f35caSApple OSS Distributions 		CHECK(data[2] == T{2});
40*c54f35caSApple OSS Distributions 		CHECK(data[3] == T{3});
41*c54f35caSApple OSS Distributions 		CHECK(data[4] == T{4});
42*c54f35caSApple OSS Distributions 	}
43*c54f35caSApple OSS Distributions 
44*c54f35caSApple OSS Distributions 	{
45*c54f35caSApple OSS Distributions 		test_bounded_array<T, 0> array = {};
46*c54f35caSApple OSS Distributions 		T* data = array.data();
47*c54f35caSApple OSS Distributions 		CHECK(data != nullptr);
48*c54f35caSApple OSS Distributions 	}
49*c54f35caSApple OSS Distributions 	{
50*c54f35caSApple OSS Distributions 		test_bounded_array<T, 0> const array = {};
51*c54f35caSApple OSS Distributions 		T const* data = array.data();
52*c54f35caSApple OSS Distributions 		CHECK(data != nullptr);
53*c54f35caSApple OSS Distributions 	}
54*c54f35caSApple OSS Distributions }
55*c54f35caSApple OSS Distributions 
56*c54f35caSApple OSS Distributions T_DECL(data, "bounded_array.data") {
57*c54f35caSApple OSS Distributions 	tests<T>();
58*c54f35caSApple OSS Distributions }
59