1 //
2 // Tests for
3 //  safe_allocation(std::nullptr_t);
4 //
5 
6 #include <libkern/c++/safe_allocation.h>
7 #include <darwintest.h>
8 #include "test_utils.h"
9 
10 struct T {
11 	int i;
12 };
13 
14 template <typename T>
15 static void
tests()16 tests()
17 {
18 	{
19 		test_safe_allocation<T> array(nullptr);
20 		CHECK(array.data() == nullptr);
21 		CHECK(array.size() == 0);
22 		CHECK(array.begin() == array.end());
23 	}
24 	{
25 		test_safe_allocation<T> array{nullptr};
26 		CHECK(array.data() == nullptr);
27 		CHECK(array.size() == 0);
28 		CHECK(array.begin() == array.end());
29 	}
30 	{
31 		test_safe_allocation<T> array = nullptr;
32 		CHECK(array.data() == nullptr);
33 		CHECK(array.size() == 0);
34 		CHECK(array.begin() == array.end());
35 	}
36 	{
37 		auto f = [](test_safe_allocation<T> array) {
38 			    CHECK(array.data() == nullptr);
39 			    CHECK(array.size() == 0);
40 			    CHECK(array.begin() == array.end());
41 		    };
42 		f(nullptr);
43 	}
44 }
45 
46 T_DECL(ctor_nullptr, "safe_allocation.ctor.nullptr", T_META_TAG_VM_PREFERRED) {
47 	tests<T>();
48 	tests<T const>();
49 }
50