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