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