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