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