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