xref: /xnu-12377.41.6/tests/safe_allocation_src/ctor.default.cpp (revision bbb1b6f9e71b8cdde6e5cd6f4841f207dee3d828)
1*bbb1b6f9SApple OSS Distributions //
2*bbb1b6f9SApple OSS Distributions // Tests for
3*bbb1b6f9SApple OSS Distributions //  explicit safe_allocation();
4*bbb1b6f9SApple OSS Distributions //
5*bbb1b6f9SApple OSS Distributions 
6*bbb1b6f9SApple OSS Distributions #include <libkern/c++/safe_allocation.h>
7*bbb1b6f9SApple OSS Distributions #include <darwintest.h>
8*bbb1b6f9SApple OSS Distributions #include "test_utils.h"
9*bbb1b6f9SApple OSS Distributions 
10*bbb1b6f9SApple OSS Distributions struct T {
11*bbb1b6f9SApple OSS Distributions 	int i;
12*bbb1b6f9SApple OSS Distributions };
13*bbb1b6f9SApple OSS Distributions 
14*bbb1b6f9SApple OSS Distributions template <typename T>
15*bbb1b6f9SApple OSS Distributions static void
tests()16*bbb1b6f9SApple OSS Distributions tests()
17*bbb1b6f9SApple OSS Distributions {
18*bbb1b6f9SApple OSS Distributions 	{
19*bbb1b6f9SApple OSS Distributions 		test_safe_allocation<T> array;
20*bbb1b6f9SApple OSS Distributions 		CHECK(array.data() == nullptr);
21*bbb1b6f9SApple OSS Distributions 		CHECK(array.size() == 0);
22*bbb1b6f9SApple OSS Distributions 		CHECK(array.begin() == array.end());
23*bbb1b6f9SApple OSS Distributions 	}
24*bbb1b6f9SApple OSS Distributions 	{
25*bbb1b6f9SApple OSS Distributions 		test_safe_allocation<T> array{};
26*bbb1b6f9SApple OSS Distributions 		CHECK(array.data() == nullptr);
27*bbb1b6f9SApple OSS Distributions 		CHECK(array.size() == 0);
28*bbb1b6f9SApple OSS Distributions 		CHECK(array.begin() == array.end());
29*bbb1b6f9SApple OSS Distributions 	}
30*bbb1b6f9SApple OSS Distributions 	{
31*bbb1b6f9SApple OSS Distributions 		test_safe_allocation<T> array = test_safe_allocation<T>();
32*bbb1b6f9SApple OSS Distributions 		CHECK(array.data() == nullptr);
33*bbb1b6f9SApple OSS Distributions 		CHECK(array.size() == 0);
34*bbb1b6f9SApple OSS Distributions 		CHECK(array.begin() == array.end());
35*bbb1b6f9SApple OSS Distributions 	}
36*bbb1b6f9SApple OSS Distributions }
37*bbb1b6f9SApple OSS Distributions 
38*bbb1b6f9SApple OSS Distributions T_DECL(ctor_default, "safe_allocation.ctor.default", T_META_TAG_VM_PREFERRED) {
39*bbb1b6f9SApple OSS Distributions 	tests<T>();
40*bbb1b6f9SApple OSS Distributions 	tests<T const>();
41*bbb1b6f9SApple OSS Distributions }
42