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