]>
git.saurik.com Git - apple/xnu.git/blob - tests/bounded_ptr_src/compare.equal.cpp
3 // template <typename T, typename P1, typename U, typename P2>
4 // bool operator==(bounded_ptr<T, P1> const& a, bounded_ptr<U, P2> const& b);
6 // template <typename T, typename P1, typename U, typename P2>
7 // bool operator!=(bounded_ptr<T, P1> const& a, bounded_ptr<U, P2> const& b);
10 #include <libkern/c++/bounded_ptr.h>
12 #include <darwintest.h>
13 #include <darwintest_utils.h>
14 #include "test_utils.h"
16 #define _assert(...) T_ASSERT_TRUE((__VA_ARGS__), # __VA_ARGS__)
18 struct dummy_policy1
{
24 struct dummy_policy2
{
31 template <typename T
, typename U
>
41 template <typename T
, typename U
>
51 template <typename T
, typename TQual
>
55 std::array
<T
, 5> array
= {T
{0}, T
{1}, T
{2}, T
{3}, T
{4}};
57 // Pointers with the same bounds
59 test_bounded_ptr
<TQual
> const a(array
.begin(), array
.begin(), array
.end());
60 test_bounded_ptr
<TQual
> const b(array
.begin(), array
.begin(), array
.end());
64 test_bounded_ptr
<TQual
> const a(array
.begin(), array
.begin(), array
.end());
65 test_bounded_ptr
<TQual
> const b(array
.begin() + 1, array
.begin(), array
.end());
69 test_bounded_ptr
<TQual
> const a(array
.begin(), array
.begin(), array
.end());
70 test_bounded_ptr
<TQual
> const b(array
.begin() + 2, array
.begin(), array
.end());
74 test_bounded_ptr
<TQual
> const a(array
.begin(), array
.begin(), array
.end());
75 test_bounded_ptr
<TQual
> const b(array
.end(), array
.begin(), array
.end());
79 test_bounded_ptr
<TQual
> const a(array
.end(), array
.begin(), array
.end());
80 test_bounded_ptr
<TQual
> const b(array
.end(), array
.begin(), array
.end());
84 // Compare null pointers
86 test_bounded_ptr
<TQual
> const a
;
87 test_bounded_ptr
<TQual
> const b(array
.begin(), array
.begin(), array
.end());
91 test_bounded_ptr
<TQual
> const a
;
92 test_bounded_ptr
<TQual
> const b
;
96 // Pointers with different bounds
98 // Overlapping bounds, equal
99 test_bounded_ptr
<TQual
> const a(array
.begin(), array
.begin() + 2, array
.end());
100 test_bounded_ptr
<TQual
> const b(array
.begin(), array
.begin(), array
.end());
104 // Overlapping bounds, not equal
105 test_bounded_ptr
<TQual
> const a(array
.begin(), array
.begin() + 2, array
.end());
106 test_bounded_ptr
<TQual
> const b(array
.begin() + 2, array
.begin(), array
.end());
110 // Non-overlapping bounds, equal
111 test_bounded_ptr
<TQual
> const a(array
.begin(), array
.begin(), array
.begin() + 1);
112 test_bounded_ptr
<TQual
> const b(array
.begin(), array
.begin() + 2, array
.end());
116 // Non-overlapping bounds, not equal
117 test_bounded_ptr
<TQual
> const a(array
.begin(), array
.begin(), array
.begin() + 1);
118 test_bounded_ptr
<TQual
> const b(array
.begin() + 3, array
.begin() + 2, array
.end());
122 // Test with different policies
124 libkern::bounded_ptr
<TQual
, dummy_policy1
> const a(array
.begin(), array
.begin(), array
.end());
125 libkern::bounded_ptr
<TQual
, dummy_policy2
> const b(array
.begin(), array
.begin(), array
.end());
130 struct Base
{ int i
; };
131 struct Derived
: Base
{ };
133 template <typename Related
>
137 std::array
<Derived
, 5> array
= {Derived
{0}, Derived
{1}, Derived
{2}, Derived
{3}, Derived
{4}};
138 test_bounded_ptr
<Derived
> const a(array
.begin(), array
.begin(), array
.end() - 1);
139 test_bounded_ptr
<Related
> const b(array
.begin(), array
.begin(), array
.end() - 1);
143 T_DECL(compare_equal
, "bounded_ptr.compare.equal") {
144 tests
<Derived
, Derived
>();
145 tests
<Derived
, Derived
const>();
146 tests
<Derived
, Derived
volatile>();
147 tests
<Derived
, Derived
const volatile>();
148 tests_convert
<Base
>();
149 tests_convert
<Base
const>();
150 tests_convert
<Base
volatile>();
151 tests_convert
<Base
const volatile>();