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