]> git.saurik.com Git - apple/xnu.git/blob - tests/bounded_array_ref_src/begin_end.cpp
xnu-7195.101.1.tar.gz
[apple/xnu.git] / tests / bounded_array_ref_src / begin_end.cpp
1 //
2 // Tests for
3 // iterator begin() const;
4 // iterator end() const;
5 //
6
7 #include <libkern/c++/bounded_array_ref.h>
8 #include "test_policy.h"
9 #include <darwintest.h>
10 #include <type_traits>
11
12 struct T { int i; };
13
14 template <typename T>
15 static void
16 tests()
17 {
18 using AR = test_bounded_array_ref<T>;
19
20 // Check begin()/end() for a non-null array ref
21 {
22 T array[5] = {T{0}, T{1}, T{2}, T{3}, T{4}};
23 AR const view(array);
24 test_bounded_ptr<T> begin = view.begin();
25 test_bounded_ptr<T> end = view.end();
26 CHECK(begin.discard_bounds() == &array[0]);
27 CHECK(end.unsafe_discard_bounds() == &array[5]);
28 }
29
30 // Check begin()/end() for a null array ref
31 {
32 AR const view;
33 test_bounded_ptr<T> begin = view.begin();
34 test_bounded_ptr<T> end = view.end();
35 CHECK(begin.unsafe_discard_bounds() == nullptr);
36 CHECK(end.unsafe_discard_bounds() == nullptr);
37 }
38
39 // Check associated types
40 {
41 static_assert(std::is_same_v<typename AR::iterator, test_bounded_ptr<T> >);
42 }
43 }
44
45 T_DECL(begin_end, "bounded_array_ref.begin_end") {
46 tests<T>();
47 }