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