1*bb611c8fSApple OSS Distributions //
2*bb611c8fSApple OSS Distributions // Tests for
3*bb611c8fSApple OSS Distributions //  bounded_ptr& operator=(std::nullptr_t);
4*bb611c8fSApple OSS Distributions //
5*bb611c8fSApple OSS Distributions 
6*bb611c8fSApple OSS Distributions #include <cstddef>
7*bb611c8fSApple OSS Distributions #include <libkern/c++/bounded_ptr.h>
8*bb611c8fSApple OSS Distributions #include <darwintest.h>
9*bb611c8fSApple OSS Distributions #include <darwintest_utils.h>
10*bb611c8fSApple OSS Distributions #include "test_utils.h"
11*bb611c8fSApple OSS Distributions 
12*bb611c8fSApple OSS Distributions #define _assert(...) T_ASSERT_TRUE((__VA_ARGS__), # __VA_ARGS__)
13*bb611c8fSApple OSS Distributions 
14*bb611c8fSApple OSS Distributions struct T { };
15*bb611c8fSApple OSS Distributions 
16*bb611c8fSApple OSS Distributions template <typename T, typename TQual>
17*bb611c8fSApple OSS Distributions static void
18*bb611c8fSApple OSS Distributions tests()
19*bb611c8fSApple OSS Distributions {
20*bb611c8fSApple OSS Distributions 	T obj{};
21*bb611c8fSApple OSS Distributions 
22*bb611c8fSApple OSS Distributions 	// Assign from nullptr
23*bb611c8fSApple OSS Distributions 	{
24*bb611c8fSApple OSS Distributions 		test_bounded_ptr<TQual> p(&obj, &obj, &obj + 1);
25*bb611c8fSApple OSS Distributions 		_assert(p != nullptr);
26*bb611c8fSApple OSS Distributions 		test_bounded_ptr<TQual>& ref = (p = nullptr);
27*bb611c8fSApple OSS Distributions 		_assert(&ref == &p);
28*bb611c8fSApple OSS Distributions 		_assert(p == nullptr);
29*bb611c8fSApple OSS Distributions 	}
30*bb611c8fSApple OSS Distributions 
31*bb611c8fSApple OSS Distributions 	// Assign from NULL
32*bb611c8fSApple OSS Distributions 	{
33*bb611c8fSApple OSS Distributions 		test_bounded_ptr<TQual> p(&obj, &obj, &obj + 1);
34*bb611c8fSApple OSS Distributions 		_assert(p != nullptr);
35*bb611c8fSApple OSS Distributions 		test_bounded_ptr<TQual>& ref = (p = NULL);
36*bb611c8fSApple OSS Distributions 		_assert(&ref == &p);
37*bb611c8fSApple OSS Distributions 		_assert(p == nullptr);
38*bb611c8fSApple OSS Distributions 	}
39*bb611c8fSApple OSS Distributions 
40*bb611c8fSApple OSS Distributions 	// Assign from 0
41*bb611c8fSApple OSS Distributions 	{
42*bb611c8fSApple OSS Distributions 		test_bounded_ptr<TQual> p(&obj, &obj, &obj + 1);
43*bb611c8fSApple OSS Distributions 		_assert(p != nullptr);
44*bb611c8fSApple OSS Distributions 		test_bounded_ptr<TQual>& ref = (p = 0);
45*bb611c8fSApple OSS Distributions 		_assert(&ref == &p);
46*bb611c8fSApple OSS Distributions 		_assert(p == nullptr);
47*bb611c8fSApple OSS Distributions 	}
48*bb611c8fSApple OSS Distributions }
49*bb611c8fSApple OSS Distributions 
50*bb611c8fSApple OSS Distributions T_DECL(assign_nullptr, "bounded_ptr.assign.nullptr") {
51*bb611c8fSApple OSS Distributions 	tests<T, T>();
52*bb611c8fSApple OSS Distributions 	tests<T, T const>();
53*bb611c8fSApple OSS Distributions 	tests<T, T volatile>();
54*bb611c8fSApple OSS Distributions 	tests<T, T const volatile>();
55*bb611c8fSApple OSS Distributions }
56