1 //
2 // Tests for
3 //  aggregate-initialization of `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 	T(int k) : i(k)
16 	{
17 	}
18 	int i;
19 	friend bool
20 	operator==(T const& a, T const& b)
21 	{
22 		return a.i == b.i;
23 	}
24 };
25 
26 template <typename T>
27 static void
28 tests()
29 {
30 	{
31 		test_bounded_array<T, 5> array = {T(1), T(2), T(3), T(4), T(5)};
32 		CHECK(array.size() == 5);
33 		CHECK(array[0] == T(1));
34 		CHECK(array[1] == T(2));
35 		CHECK(array[2] == T(3));
36 		CHECK(array[3] == T(4));
37 		CHECK(array[4] == T(5));
38 	}
39 
40 	{
41 		test_bounded_array<T, 5> array{T(1), T(2), T(3), T(4), T(5)};
42 		CHECK(array.size() == 5);
43 		CHECK(array[0] == T(1));
44 		CHECK(array[1] == T(2));
45 		CHECK(array[2] == T(3));
46 		CHECK(array[3] == T(4));
47 		CHECK(array[4] == T(5));
48 	}
49 
50 	// Check with a 0-sized array
51 	{
52 		test_bounded_array<T, 0> array = {};
53 		CHECK(array.size() == 0);
54 	}
55 }
56 
57 T_DECL(ctor_aggregate_init, "bounded_array.ctor.aggregate_init") {
58 	tests<T>();
59 }
60