1*bbb1b6f9SApple OSS Distributions //
2*bbb1b6f9SApple OSS Distributions // Tests for
3*bbb1b6f9SApple OSS Distributions // template <size_t N>
4*bbb1b6f9SApple OSS Distributions // bounded_array_ref(bounded_array<T, N, TrappingPolicy>& data);
5*bbb1b6f9SApple OSS Distributions //
6*bbb1b6f9SApple OSS Distributions
7*bbb1b6f9SApple OSS Distributions #include <libkern/c++/bounded_array_ref.h>
8*bbb1b6f9SApple OSS Distributions #include "test_policy.h"
9*bbb1b6f9SApple OSS Distributions #include <darwintest.h>
10*bbb1b6f9SApple OSS Distributions #include <darwintest_utils.h>
11*bbb1b6f9SApple OSS Distributions
12*bbb1b6f9SApple OSS Distributions struct T { int i; };
13*bbb1b6f9SApple OSS Distributions inline bool
operator ==(T const & a,T const & b)14*bbb1b6f9SApple OSS Distributions operator==(T const& a, T const& b)
15*bbb1b6f9SApple OSS Distributions {
16*bbb1b6f9SApple OSS Distributions return a.i == b.i;
17*bbb1b6f9SApple OSS Distributions };
18*bbb1b6f9SApple OSS Distributions
19*bbb1b6f9SApple OSS Distributions template <typename T>
20*bbb1b6f9SApple OSS Distributions static void
tests()21*bbb1b6f9SApple OSS Distributions tests()
22*bbb1b6f9SApple OSS Distributions {
23*bbb1b6f9SApple OSS Distributions {
24*bbb1b6f9SApple OSS Distributions test_bounded_array<T, 5> array = {T{0}, T{1}, T{2}, T{3}, T{4}};
25*bbb1b6f9SApple OSS Distributions test_bounded_array_ref<T> view(array);
26*bbb1b6f9SApple OSS Distributions CHECK(view.data() == array.data());
27*bbb1b6f9SApple OSS Distributions CHECK(view.size() == 5);
28*bbb1b6f9SApple OSS Distributions CHECK(view[0] == T{0});
29*bbb1b6f9SApple OSS Distributions CHECK(view[1] == T{1});
30*bbb1b6f9SApple OSS Distributions CHECK(view[2] == T{2});
31*bbb1b6f9SApple OSS Distributions CHECK(view[3] == T{3});
32*bbb1b6f9SApple OSS Distributions CHECK(view[4] == T{4});
33*bbb1b6f9SApple OSS Distributions }
34*bbb1b6f9SApple OSS Distributions
35*bbb1b6f9SApple OSS Distributions {
36*bbb1b6f9SApple OSS Distributions test_bounded_array<T, 1> array = {T{11}};
37*bbb1b6f9SApple OSS Distributions test_bounded_array_ref<T> view(array);
38*bbb1b6f9SApple OSS Distributions CHECK(view.data() == array.data());
39*bbb1b6f9SApple OSS Distributions CHECK(view.size() == 1);
40*bbb1b6f9SApple OSS Distributions CHECK(view[0] == T{11});
41*bbb1b6f9SApple OSS Distributions }
42*bbb1b6f9SApple OSS Distributions
43*bbb1b6f9SApple OSS Distributions {
44*bbb1b6f9SApple OSS Distributions test_bounded_array<T, 0> array = {};
45*bbb1b6f9SApple OSS Distributions test_bounded_array_ref<T> view(array);
46*bbb1b6f9SApple OSS Distributions CHECK(view.data() == array.data());
47*bbb1b6f9SApple OSS Distributions CHECK(view.size() == 0);
48*bbb1b6f9SApple OSS Distributions }
49*bbb1b6f9SApple OSS Distributions
50*bbb1b6f9SApple OSS Distributions // Also test implicit construction
51*bbb1b6f9SApple OSS Distributions {
52*bbb1b6f9SApple OSS Distributions test_bounded_array<T, 1> array = {T{11}};
53*bbb1b6f9SApple OSS Distributions test_bounded_array_ref<T> view = array;
54*bbb1b6f9SApple OSS Distributions CHECK(view.data() == array.data());
55*bbb1b6f9SApple OSS Distributions CHECK(view.size() == 1);
56*bbb1b6f9SApple OSS Distributions }
57*bbb1b6f9SApple OSS Distributions {
58*bbb1b6f9SApple OSS Distributions test_bounded_array<T, 1> array = {T{11}};
59*bbb1b6f9SApple OSS Distributions auto check = [&array](test_bounded_array_ref<T> view) {
60*bbb1b6f9SApple OSS Distributions CHECK(view.data() == array.data());
61*bbb1b6f9SApple OSS Distributions CHECK(view.size() == 1);
62*bbb1b6f9SApple OSS Distributions };
63*bbb1b6f9SApple OSS Distributions check(array);
64*bbb1b6f9SApple OSS Distributions }
65*bbb1b6f9SApple OSS Distributions }
66*bbb1b6f9SApple OSS Distributions
67*bbb1b6f9SApple OSS Distributions T_DECL(ctor_bounded_array, "bounded_array_ref.ctor.bounded_array", T_META_TAG_VM_PREFERRED) {
68*bbb1b6f9SApple OSS Distributions tests<T>();
69*bbb1b6f9SApple OSS Distributions }
70