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