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