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