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