xref: /xnu-8796.141.3/tests/bounded_array_src/ctor.default.cpp (revision 1b191cb58250d0705d8a51287127505aa4bc0789)
1*1b191cb5SApple OSS Distributions //
2*1b191cb5SApple OSS Distributions // Tests for
3*1b191cb5SApple OSS Distributions //  bounded_array();
4*1b191cb5SApple OSS Distributions //
5*1b191cb5SApple OSS Distributions 
6*1b191cb5SApple OSS Distributions #include <libkern/c++/bounded_array.h>
7*1b191cb5SApple OSS Distributions #include <darwintest.h>
8*1b191cb5SApple OSS Distributions #include <darwintest_utils.h>
9*1b191cb5SApple OSS Distributions #include "test_policy.h"
10*1b191cb5SApple OSS Distributions 
11*1b191cb5SApple OSS Distributions struct T {
TT12*1b191cb5SApple OSS Distributions 	T() : i(4)
13*1b191cb5SApple OSS Distributions 	{
14*1b191cb5SApple OSS Distributions 	}
15*1b191cb5SApple OSS Distributions 	int i;
16*1b191cb5SApple OSS Distributions 	friend bool
operator ==(T const & a,T const & b)17*1b191cb5SApple OSS Distributions 	operator==(T const& a, T const& b)
18*1b191cb5SApple OSS Distributions 	{
19*1b191cb5SApple OSS Distributions 		return a.i == b.i;
20*1b191cb5SApple OSS Distributions 	}
21*1b191cb5SApple OSS Distributions };
22*1b191cb5SApple OSS Distributions 
23*1b191cb5SApple OSS Distributions template <typename T>
24*1b191cb5SApple OSS Distributions static void
tests()25*1b191cb5SApple OSS Distributions tests()
26*1b191cb5SApple OSS Distributions {
27*1b191cb5SApple OSS Distributions 	{
28*1b191cb5SApple OSS Distributions 		test_bounded_array<T, 10> array;
29*1b191cb5SApple OSS Distributions 		CHECK(array.size() == 10);
30*1b191cb5SApple OSS Distributions 		T* end = array.data() + array.size();
31*1b191cb5SApple OSS Distributions 		for (auto it = array.data(); it != end; ++it) {
32*1b191cb5SApple OSS Distributions 			CHECK(*it == T());
33*1b191cb5SApple OSS Distributions 		}
34*1b191cb5SApple OSS Distributions 	}
35*1b191cb5SApple OSS Distributions 	{
36*1b191cb5SApple OSS Distributions 		test_bounded_array<T, 10> array{};
37*1b191cb5SApple OSS Distributions 		CHECK(array.size() == 10);
38*1b191cb5SApple OSS Distributions 		T* end = array.data() + array.size();
39*1b191cb5SApple OSS Distributions 		for (auto it = array.data(); it != end; ++it) {
40*1b191cb5SApple OSS Distributions 			CHECK(*it == T());
41*1b191cb5SApple OSS Distributions 		}
42*1b191cb5SApple OSS Distributions 	}
43*1b191cb5SApple OSS Distributions 	{
44*1b191cb5SApple OSS Distributions 		test_bounded_array<T, 10> array = {};
45*1b191cb5SApple OSS Distributions 		CHECK(array.size() == 10);
46*1b191cb5SApple OSS Distributions 		T* end = array.data() + array.size();
47*1b191cb5SApple OSS Distributions 		for (auto it = array.data(); it != end; ++it) {
48*1b191cb5SApple OSS Distributions 			CHECK(*it == T());
49*1b191cb5SApple OSS Distributions 		}
50*1b191cb5SApple OSS Distributions 	}
51*1b191cb5SApple OSS Distributions 	{
52*1b191cb5SApple OSS Distributions 		test_bounded_array<T, 10> array = test_bounded_array<T, 10>();
53*1b191cb5SApple OSS Distributions 		CHECK(array.size() == 10);
54*1b191cb5SApple OSS Distributions 		T* end = array.data() + array.size();
55*1b191cb5SApple OSS Distributions 		for (auto it = array.data(); it != end; ++it) {
56*1b191cb5SApple OSS Distributions 			CHECK(*it == T());
57*1b191cb5SApple OSS Distributions 		}
58*1b191cb5SApple OSS Distributions 	}
59*1b191cb5SApple OSS Distributions 
60*1b191cb5SApple OSS Distributions 	// Check with a 0-sized array
61*1b191cb5SApple OSS Distributions 	{
62*1b191cb5SApple OSS Distributions 		test_bounded_array<T, 0> array;
63*1b191cb5SApple OSS Distributions 		CHECK(array.size() == 0);
64*1b191cb5SApple OSS Distributions 	}
65*1b191cb5SApple OSS Distributions }
66*1b191cb5SApple OSS Distributions 
67*1b191cb5SApple OSS Distributions T_DECL(ctor_default, "bounded_array.ctor.default") {
68*1b191cb5SApple OSS Distributions 	tests<T>();
69*1b191cb5SApple OSS Distributions }
70