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