1*bb611c8fSApple OSS Distributions //
2*bb611c8fSApple OSS Distributions // Tests for
3*bb611c8fSApple OSS Distributions //  aggregate-initialization of `bounded_array`
4*bb611c8fSApple OSS Distributions //
5*bb611c8fSApple OSS Distributions 
6*bb611c8fSApple OSS Distributions #include <libkern/c++/bounded_array.h>
7*bb611c8fSApple OSS Distributions #include <darwintest.h>
8*bb611c8fSApple OSS Distributions #include <darwintest_utils.h>
9*bb611c8fSApple OSS Distributions #include "test_policy.h"
10*bb611c8fSApple OSS Distributions 
11*bb611c8fSApple OSS Distributions struct T {
12*bb611c8fSApple OSS Distributions 	T() : i(4)
13*bb611c8fSApple OSS Distributions 	{
14*bb611c8fSApple OSS Distributions 	}
15*bb611c8fSApple OSS Distributions 	T(int k) : i(k)
16*bb611c8fSApple OSS Distributions 	{
17*bb611c8fSApple OSS Distributions 	}
18*bb611c8fSApple OSS Distributions 	int i;
19*bb611c8fSApple OSS Distributions 	friend bool
20*bb611c8fSApple OSS Distributions 	operator==(T const& a, T const& b)
21*bb611c8fSApple OSS Distributions 	{
22*bb611c8fSApple OSS Distributions 		return a.i == b.i;
23*bb611c8fSApple OSS Distributions 	}
24*bb611c8fSApple OSS Distributions };
25*bb611c8fSApple OSS Distributions 
26*bb611c8fSApple OSS Distributions template <typename T>
27*bb611c8fSApple OSS Distributions static void
28*bb611c8fSApple OSS Distributions tests()
29*bb611c8fSApple OSS Distributions {
30*bb611c8fSApple OSS Distributions 	{
31*bb611c8fSApple OSS Distributions 		test_bounded_array<T, 5> array = {T(1), T(2), T(3), T(4), T(5)};
32*bb611c8fSApple OSS Distributions 		CHECK(array.size() == 5);
33*bb611c8fSApple OSS Distributions 		CHECK(array[0] == T(1));
34*bb611c8fSApple OSS Distributions 		CHECK(array[1] == T(2));
35*bb611c8fSApple OSS Distributions 		CHECK(array[2] == T(3));
36*bb611c8fSApple OSS Distributions 		CHECK(array[3] == T(4));
37*bb611c8fSApple OSS Distributions 		CHECK(array[4] == T(5));
38*bb611c8fSApple OSS Distributions 	}
39*bb611c8fSApple OSS Distributions 
40*bb611c8fSApple OSS Distributions 	{
41*bb611c8fSApple OSS Distributions 		test_bounded_array<T, 5> array{T(1), T(2), T(3), T(4), T(5)};
42*bb611c8fSApple OSS Distributions 		CHECK(array.size() == 5);
43*bb611c8fSApple OSS Distributions 		CHECK(array[0] == T(1));
44*bb611c8fSApple OSS Distributions 		CHECK(array[1] == T(2));
45*bb611c8fSApple OSS Distributions 		CHECK(array[2] == T(3));
46*bb611c8fSApple OSS Distributions 		CHECK(array[3] == T(4));
47*bb611c8fSApple OSS Distributions 		CHECK(array[4] == T(5));
48*bb611c8fSApple OSS Distributions 	}
49*bb611c8fSApple OSS Distributions 
50*bb611c8fSApple OSS Distributions 	// Check with a 0-sized array
51*bb611c8fSApple OSS Distributions 	{
52*bb611c8fSApple OSS Distributions 		test_bounded_array<T, 0> array = {};
53*bb611c8fSApple OSS Distributions 		CHECK(array.size() == 0);
54*bb611c8fSApple OSS Distributions 	}
55*bb611c8fSApple OSS Distributions }
56*bb611c8fSApple OSS Distributions 
57*bb611c8fSApple OSS Distributions T_DECL(ctor_aggregate_init, "bounded_array.ctor.aggregate_init") {
58*bb611c8fSApple OSS Distributions 	tests<T>();
59*bb611c8fSApple OSS Distributions }
60