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