]> git.saurik.com Git - apple/xnu.git/blob - tests/bounded_array_ref_src/ctor.begin_end.cpp
xnu-7195.50.7.100.1.tar.gz
[apple/xnu.git] / tests / bounded_array_ref_src / ctor.begin_end.cpp
1 //
2 // Tests for
3 // explicit bounded_array_ref(T* first, T* last);
4 //
5
6 #include <libkern/c++/bounded_array_ref.h>
7 #include "test_policy.h"
8 #include <darwintest.h>
9 #include <darwintest_utils.h>
10
11 struct T { int i; };
12 inline bool
13 operator==(T const& a, T const& b)
14 {
15 return a.i == b.i;
16 };
17
18 template <typename T>
19 static void
20 tests()
21 {
22 T array[5] = {T{0}, T{1}, T{2}, T{3}, T{4}};
23
24 // T{0} T{1} T{2} T{3} T{4} <one-past-last>
25 // ^ ^
26 // | |
27 // first last
28 {
29 T* first = &array[0];
30 T* last = &array[5];
31 test_bounded_array_ref<T> view(first, last);
32 CHECK(view.data() == &array[0]);
33 CHECK(view.size() == 5);
34 CHECK(view[0] == T{0});
35 CHECK(view[1] == T{1});
36 CHECK(view[2] == T{2});
37 CHECK(view[3] == T{3});
38 CHECK(view[4] == T{4});
39 }
40
41 // T{0} T{1} T{2} T{3} T{4} <one-past-last>
42 // ^ ^
43 // | |
44 // first last
45 {
46 T* first = &array[0];
47 T* last = &array[1];
48 test_bounded_array_ref<T> view(first, last);
49 CHECK(view.data() == &array[0]);
50 CHECK(view.size() == 1);
51 CHECK(view[0] == T{0});
52 }
53
54 // T{0} T{1} T{2} T{3} T{4} <one-past-last>
55 // ^
56 // |
57 // first,last
58 {
59 T* first = &array[0];
60 T* last = &array[0];
61 test_bounded_array_ref<T> view(first, last);
62 CHECK(view.size() == 0);
63 }
64
65 // T{0} T{1} T{2} T{3} T{4} <one-past-last>
66 // ^
67 // |
68 // first,last
69 {
70 T* first = &array[5];
71 T* last = &array[5];
72 test_bounded_array_ref<T> view(first, last);
73 CHECK(view.size() == 0);
74 }
75 }
76
77 T_DECL(ctor_begin_end, "bounded_array_ref.ctor.begin_end") {
78 tests<T>();
79 tests<T const>();
80 }