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