]>
git.saurik.com Git - apple/xnu.git/blob - tests/bounded_ptr_src/compare.equal.raw.cpp
3 // template <typename T, typename P, typename U>
4 // bool operator==(bounded_ptr<T, P> const& a, U* b);
6 // template <typename T, typename P, typename U>
7 // bool operator==(U* a, bounded_ptr<T, P> const& b);
9 // template <typename T, typename P, typename U>
10 // bool operator!=(bounded_ptr<T, P> const& a, U* b);
12 // template <typename T, typename P, typename U>
13 // bool operator!=(U* a, bounded_ptr<T, P> const& b);
16 #include <libkern/c++/bounded_ptr.h>
18 #include <darwintest.h>
19 #include <darwintest_utils.h>
20 #include "test_utils.h"
22 #define _assert(...) T_ASSERT_TRUE((__VA_ARGS__), # __VA_ARGS__)
24 template <typename T
, typename U
>
34 template <typename T
, typename U
>
44 template <typename T
, typename TQual
>
48 std::array
<T
, 5> array
= {T
{0}, T
{1}, T
{2}, T
{3}, T
{4}};
50 // Compare pointers within the bounds
52 // T{0} T{1} T{2} T{3} T{4} <one-past-last>
56 test_bounded_ptr
<TQual
> const a(array
.begin(), array
.begin(), array
.end());
57 TQual
* b
= array
.begin();
61 // T{0} T{1} T{2} T{3} T{4} <one-past-last>
65 test_bounded_ptr
<TQual
> const a(array
.begin() + 1, array
.begin(), array
.end());
66 TQual
* b
= array
.begin() + 1;
70 // T{0} T{1} T{2} T{3} T{4} <one-past-last>
74 test_bounded_ptr
<TQual
> const a(array
.begin(), array
.begin(), array
.end());
75 TQual
* b
= array
.begin() + 2;
79 // T{0} T{1} T{2} T{3} T{4} <one-past-last>
83 test_bounded_ptr
<TQual
> const a(array
.end(), array
.begin(), array
.end());
84 TQual
* b
= array
.end();
88 // T{0} T{1} T{2} T{3} T{4} <one-past-last>
92 test_bounded_ptr
<TQual
> const a(array
.begin() + 2, array
.begin(), array
.begin() + 3);
93 TQual
* b
= array
.begin() + 4;
97 // Check when the bounded_ptr is outside of its bounds
99 // T{0} T{1} T{2} T{3} T{4} <one-past-last>
103 test_bounded_ptr
<TQual
> const a(array
.begin(), array
.begin() + 2, array
.end());
104 TQual
* b
= array
.begin();
108 // T{0} T{1} T{2} T{3} T{4} <one-past-last>
112 test_bounded_ptr
<TQual
> const a(array
.end() - 1, array
.begin(), array
.end() - 2);
113 TQual
* b
= array
.end() - 1;
117 // T{0} T{1} T{2} T{3} T{4} <one-past-last>
121 test_bounded_ptr
<TQual
> const a(array
.end(), array
.begin(), array
.end() - 1);
122 TQual
* b
= array
.end();
126 // T{0} T{1} T{2} T{3} T{4} <one-past-last>
130 test_bounded_ptr
<TQual
> const a(array
.end() - 1, array
.begin(), array
.end() - 2);
131 TQual
* b
= array
.end();
135 // Test comparing against a null pointer
137 test_bounded_ptr
<TQual
> a
= nullptr;
142 test_bounded_ptr
<TQual
> a(array
.end() - 1, array
.begin(), array
.end() - 2);
147 test_bounded_ptr
<TQual
> a
= nullptr;
148 TQual
* b
= array
.begin();
153 struct Base
{ int i
; };
154 struct Derived
: Base
{ };
156 template <typename Related
>
160 std::array
<Derived
, 5> array
= {Derived
{0}, Derived
{1}, Derived
{2}, Derived
{3}, Derived
{4}};
163 test_bounded_ptr
<Derived
> const a(array
.begin(), array
.begin(), array
.end() - 1);
164 Related
* b
= array
.begin();
168 test_bounded_ptr
<Related
> const a(array
.begin(), array
.begin(), array
.end() - 1);
169 Derived
* b
= array
.begin();
173 // Test comparisons against cv-void*
175 test_bounded_ptr
<Related
> const a(array
.begin(), array
.begin(), array
.end() - 1);
176 void* b
= array
.begin();
181 T_DECL(compare_equal_raw
, "bounded_ptr.compare.equal.raw") {
182 tests
<Derived
, Derived
>();
183 tests
<Derived
, Derived
const>();
184 tests
<Derived
, Derived
volatile>();
185 tests
<Derived
, Derived
const volatile>();
186 tests_convert
<Base
>();
187 tests_convert
<Base
const>();
188 tests_convert
<Base
volatile>();
189 tests_convert
<Base
const volatile>();