]> git.saurik.com Git - apple/xnu.git/blob - tests/bounded_array_src/data.cpp
xnu-7195.101.1.tar.gz
[apple/xnu.git] / tests / bounded_array_src / data.cpp
1 //
2 // Tests for
3 // T* data();
4 // T const* data() const;
5 //
6
7 #include <libkern/c++/bounded_array.h>
8 #include "test_policy.h"
9 #include <darwintest.h>
10 #include <type_traits>
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 T* data = array.data();
26 CHECK(data != nullptr);
27 CHECK(data[0] == T{0});
28 CHECK(data[1] == T{1});
29 CHECK(data[2] == T{2});
30 CHECK(data[3] == T{3});
31 CHECK(data[4] == T{4});
32 }
33 {
34 test_bounded_array<T, 5> const array = {T{0}, T{1}, T{2}, T{3}, T{4}};
35 T const* data = array.data();
36 CHECK(data != nullptr);
37 CHECK(data[0] == T{0});
38 CHECK(data[1] == T{1});
39 CHECK(data[2] == T{2});
40 CHECK(data[3] == T{3});
41 CHECK(data[4] == T{4});
42 }
43
44 {
45 test_bounded_array<T, 0> array = {};
46 T* data = array.data();
47 CHECK(data != nullptr);
48 }
49 {
50 test_bounded_array<T, 0> const array = {};
51 T const* data = array.data();
52 CHECK(data != nullptr);
53 }
54 }
55
56 T_DECL(data, "bounded_array.data") {
57 tests<T>();
58 }