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