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