]> git.saurik.com Git - apple/xnu.git/blob - tests/bounded_array_ref_src/data.cpp
xnu-7195.81.3.tar.gz
[apple/xnu.git] / tests / bounded_array_ref_src / data.cpp
1 //
2 // Tests for
3 // T* data() const;
4 //
5
6 #include <libkern/c++/bounded_array_ref.h>
7 #include "test_policy.h"
8 #include <cstddef>
9 #include <darwintest.h>
10 #include <darwintest_utils.h>
11
12 struct T { int i; };
13
14 template <typename T>
15 static void
16 tests()
17 {
18 T array[5] = {T{0}, T{1}, T{2}, T{3}, T{4}};
19
20 {
21 test_bounded_array_ref<T> const view(&array[0], static_cast<std::size_t>(0));
22 T* data = view.data();
23 CHECK(data == &array[0]);
24 }
25 {
26 test_bounded_array_ref<T> const view(&array[0], 1);
27 T* data = view.data();
28 CHECK(data == &array[0]);
29 }
30
31 {
32 test_bounded_array_ref<T> const view(&array[1], 2);
33 T* data = view.data();
34 CHECK(data == &array[1]);
35 }
36 {
37 test_bounded_array_ref<T> const view(&array[2], 2);
38 T* data = view.data();
39 CHECK(data == &array[2]);
40 }
41 }
42
43 T_DECL(data, "bounded_array_ref.data") {
44 tests<T>();
45 tests<T const>();
46 }