1 // 2 // Tests for 3 // template <typename T, typename Policy> 4 // bool operator==(std::nullptr_t, bounded_ptr<T, Policy> const& p); 5 // 6 // template <typename T, typename Policy> 7 // bool operator!=(std::nullptr_t, bounded_ptr<T, Policy> const& p); 8 // 9 // template <typename T, typename Policy> 10 // bool operator==(bounded_ptr<T, Policy> const& p, std::nullptr_t); 11 // 12 // template <typename T, typename Policy> 13 // bool operator!=(bounded_ptr<T, Policy> const& p, std::nullptr_t); 14 // 15 16 #include <libkern/c++/bounded_ptr.h> 17 #include <darwintest.h> 18 #include <darwintest_utils.h> 19 #include "test_utils.h" 20 21 #define _assert(...) T_ASSERT_TRUE((__VA_ARGS__), # __VA_ARGS__) 22 23 struct T { }; 24 25 struct non_default_policy { 26 static constexpr void 27 trap(char const*) 28 { 29 } 30 }; 31 32 template <typename T, typename QualT> 33 static void 34 tests() 35 { 36 T t; 37 38 { 39 test_bounded_ptr<QualT> const ptr(&t, &t, &t + 1); 40 _assert(!(ptr == nullptr)); 41 _assert(!(nullptr == ptr)); 42 _assert(ptr != nullptr); 43 _assert(nullptr != ptr); 44 } 45 { 46 test_bounded_ptr<QualT> const ptr = nullptr; 47 _assert(ptr == nullptr); 48 _assert(nullptr == ptr); 49 _assert(!(ptr != nullptr)); 50 _assert(!(nullptr != ptr)); 51 } 52 53 // Test with a custom policy 54 { 55 libkern::bounded_ptr<QualT, non_default_policy> const ptr = nullptr; 56 _assert(ptr == nullptr); 57 _assert(nullptr == ptr); 58 _assert(!(ptr != nullptr)); 59 _assert(!(nullptr != ptr)); 60 } 61 } 62 63 T_DECL(compare_equal_nullptr, "bounded_ptr.compare.equal.nullptr") { 64 tests<T, T>(); 65 tests<T, T const>(); 66 tests<T, T volatile>(); 67 tests<T, T const volatile>(); 68 } 69