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