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