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