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