1 //
2 // Tests for
3 //  bounded_ptr(std::nullptr_t);
4 //
5 
6 #include <libkern/c++/bounded_ptr.h>
7 #include <darwintest.h>
8 #include <darwintest_utils.h>
9 #include "test_utils.h"
10 
11 #define _assert(...) T_ASSERT_TRUE((__VA_ARGS__), # __VA_ARGS__)
12 
13 struct T { };
14 
15 template <typename T>
16 static void
tests()17 tests()
18 {
19 	// Test with nullptr
20 	{
21 		test_bounded_ptr<T> p = nullptr;
22 		_assert(p == nullptr);
23 	}
24 	{
25 		test_bounded_ptr<T> p{nullptr};
26 		_assert(p == nullptr);
27 	}
28 	{
29 		test_bounded_ptr<T> p(nullptr);
30 		_assert(p == nullptr);
31 	}
32 	{
33 		test_bounded_ptr<T> p = static_cast<test_bounded_ptr<T> >(nullptr);
34 		_assert(p == nullptr);
35 	}
36 	{
37 		auto f = [](test_bounded_ptr<T> p) {
38 			    _assert(p == nullptr);
39 		    };
40 		f(nullptr);
41 	}
42 
43 	// Test with NULL
44 	{
45 		test_bounded_ptr<T> p = NULL;
46 		_assert(p == nullptr);
47 	}
48 	{
49 		test_bounded_ptr<T> p{NULL};
50 		_assert(p == nullptr);
51 	}
52 	{
53 		test_bounded_ptr<T> p(NULL);
54 		_assert(p == nullptr);
55 	}
56 	{
57 		test_bounded_ptr<T> p = static_cast<test_bounded_ptr<T> >(NULL);
58 		_assert(p == nullptr);
59 	}
60 	{
61 		auto f = [](test_bounded_ptr<T> p) {
62 			    _assert(p == nullptr);
63 		    };
64 		f(NULL);
65 	}
66 
67 	// Test with 0
68 	{
69 		test_bounded_ptr<T> p = 0;
70 		_assert(p == nullptr);
71 	}
72 	{
73 		test_bounded_ptr<T> p{0};
74 		_assert(p == nullptr);
75 	}
76 	{
77 		test_bounded_ptr<T> p(0);
78 		_assert(p == nullptr);
79 	}
80 	{
81 		test_bounded_ptr<T> p = static_cast<test_bounded_ptr<T> >(0);
82 		_assert(p == nullptr);
83 	}
84 	{
85 		auto f = [](test_bounded_ptr<T> p) {
86 			    _assert(p == nullptr);
87 		    };
88 		f(0);
89 	}
90 }
91 
92 T_DECL(ctor_nullptr, "bounded_ptr.ctor.nullptr", T_META_TAG_VM_PREFERRED) {
93 	tests<T>();
94 	tests<T const>();
95 	tests<T volatile>();
96 	tests<T const volatile>();
97 }
98