1*c54f35caSApple OSS Distributions //
2*c54f35caSApple OSS Distributions // Tests for
3*c54f35caSApple OSS Distributions // template <size_t N>
4*c54f35caSApple OSS Distributions // bounded_array_ref(bounded_array<T, N, TrappingPolicy>& data);
5*c54f35caSApple OSS Distributions //
6*c54f35caSApple OSS Distributions
7*c54f35caSApple OSS Distributions #include <libkern/c++/bounded_array_ref.h>
8*c54f35caSApple OSS Distributions #include "test_policy.h"
9*c54f35caSApple OSS Distributions #include <darwintest.h>
10*c54f35caSApple OSS Distributions #include <darwintest_utils.h>
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 test_bounded_array_ref<T> view(array);
26*c54f35caSApple OSS Distributions CHECK(view.data() == array.data());
27*c54f35caSApple OSS Distributions CHECK(view.size() == 5);
28*c54f35caSApple OSS Distributions CHECK(view[0] == T{0});
29*c54f35caSApple OSS Distributions CHECK(view[1] == T{1});
30*c54f35caSApple OSS Distributions CHECK(view[2] == T{2});
31*c54f35caSApple OSS Distributions CHECK(view[3] == T{3});
32*c54f35caSApple OSS Distributions CHECK(view[4] == T{4});
33*c54f35caSApple OSS Distributions }
34*c54f35caSApple OSS Distributions
35*c54f35caSApple OSS Distributions {
36*c54f35caSApple OSS Distributions test_bounded_array<T, 1> array = {T{11}};
37*c54f35caSApple OSS Distributions test_bounded_array_ref<T> view(array);
38*c54f35caSApple OSS Distributions CHECK(view.data() == array.data());
39*c54f35caSApple OSS Distributions CHECK(view.size() == 1);
40*c54f35caSApple OSS Distributions CHECK(view[0] == T{11});
41*c54f35caSApple OSS Distributions }
42*c54f35caSApple OSS Distributions
43*c54f35caSApple OSS Distributions {
44*c54f35caSApple OSS Distributions test_bounded_array<T, 0> array = {};
45*c54f35caSApple OSS Distributions test_bounded_array_ref<T> view(array);
46*c54f35caSApple OSS Distributions CHECK(view.data() == array.data());
47*c54f35caSApple OSS Distributions CHECK(view.size() == 0);
48*c54f35caSApple OSS Distributions }
49*c54f35caSApple OSS Distributions
50*c54f35caSApple OSS Distributions // Also test implicit construction
51*c54f35caSApple OSS Distributions {
52*c54f35caSApple OSS Distributions test_bounded_array<T, 1> array = {T{11}};
53*c54f35caSApple OSS Distributions test_bounded_array_ref<T> view = array;
54*c54f35caSApple OSS Distributions CHECK(view.data() == array.data());
55*c54f35caSApple OSS Distributions CHECK(view.size() == 1);
56*c54f35caSApple OSS Distributions }
57*c54f35caSApple OSS Distributions {
58*c54f35caSApple OSS Distributions test_bounded_array<T, 1> array = {T{11}};
59*c54f35caSApple OSS Distributions auto check = [&array](test_bounded_array_ref<T> view) {
60*c54f35caSApple OSS Distributions CHECK(view.data() == array.data());
61*c54f35caSApple OSS Distributions CHECK(view.size() == 1);
62*c54f35caSApple OSS Distributions };
63*c54f35caSApple OSS Distributions check(array);
64*c54f35caSApple OSS Distributions }
65*c54f35caSApple OSS Distributions }
66*c54f35caSApple OSS Distributions
67*c54f35caSApple OSS Distributions T_DECL(ctor_bounded_array, "bounded_array_ref.ctor.bounded_array") {
68*c54f35caSApple OSS Distributions tests<T>();
69*c54f35caSApple OSS Distributions }
70