]>
git.saurik.com Git - apple/xnu.git/blob - tests/bounded_ptr_src/compare.order.raw.cpp
3 // template <typename T, typename U, typename P>
4 // bool operator<(T* a, bounded_ptr<U, P> const& b);
6 // template <typename T, typename U, typename P>
7 // bool operator<(bounded_ptr<T, P> const& a, U* b);
9 // template <typename T, typename U, typename P>
10 // bool operator<=(T* a, bounded_ptr<U, P> const& b);
12 // template <typename T, typename U, typename P>
13 // bool operator<=(bounded_ptr<T, P> const& a, U* b);
15 // template <typename T, typename U, typename P>
16 // bool operator>(T* a, bounded_ptr<U, P> const& b);
18 // template <typename T, typename U, typename P>
19 // bool operator>(bounded_ptr<T, P> const& a, U* b);
21 // template <typename T, typename U, typename P>
22 // bool operator>=(T* a, bounded_ptr<U, P> const& b);
24 // template <typename T, typename U, typename P>
25 // bool operator>=(bounded_ptr<T, P> const& a, U* b);
28 #include <libkern/c++/bounded_ptr.h>
30 #include <darwintest.h>
31 #include <darwintest_utils.h>
32 #include "test_utils.h"
34 #define _assert(...) T_ASSERT_TRUE((__VA_ARGS__), # __VA_ARGS__)
36 template <typename T
, typename U
>
51 template <typename T
, typename U
>
66 template <typename T
, typename TQual
>
70 std::array
<T
, 5> array
= {T
{0}, T
{1}, T
{2}, T
{3}, T
{4}};
72 // Compare pointers within the bounds
74 // T{0} T{1} T{2} T{3} T{4} <one-past-last>
78 test_bounded_ptr
<TQual
> const a(array
.begin(), array
.begin(), array
.end());
79 TQual
* b
= array
.begin();
83 // T{0} T{1} T{2} T{3} T{4} <one-past-last>
87 test_bounded_ptr
<TQual
> const a(array
.begin() + 1, array
.begin(), array
.end());
88 TQual
* b
= array
.begin() + 1;
92 // T{0} T{1} T{2} T{3} T{4} <one-past-last>
96 test_bounded_ptr
<TQual
> const a(array
.begin(), array
.begin(), array
.end());
97 TQual
* b
= array
.begin() + 2;
101 // T{0} T{1} T{2} T{3} T{4} <one-past-last>
105 test_bounded_ptr
<TQual
> const a(array
.end(), array
.begin(), array
.end());
106 TQual
* b
= array
.end();
110 // T{0} T{1} T{2} T{3} T{4} <one-past-last>
114 test_bounded_ptr
<TQual
> const a(array
.begin() + 2, array
.begin(), array
.begin() + 3);
115 TQual
* b
= array
.begin() + 4;
119 // Check when the bounded_ptr is outside of its bounds
121 // T{0} T{1} T{2} T{3} T{4} <one-past-last>
125 test_bounded_ptr
<TQual
> const a(array
.begin(), array
.begin() + 2, array
.end());
126 TQual
* b
= array
.begin();
130 // T{0} T{1} T{2} T{3} T{4} <one-past-last>
134 test_bounded_ptr
<TQual
> const a(array
.end() - 1, array
.begin(), array
.end() - 2);
135 TQual
* b
= array
.end() - 1;
139 // T{0} T{1} T{2} T{3} T{4} <one-past-last>
143 test_bounded_ptr
<TQual
> const a(array
.end(), array
.begin(), array
.end() - 1);
144 TQual
* b
= array
.end();
148 // T{0} T{1} T{2} T{3} T{4} <one-past-last>
152 test_bounded_ptr
<TQual
> const a(array
.end() - 1, array
.begin(), array
.end() - 2);
153 TQual
* b
= array
.end();
157 // Test comparing against a null pointer
159 test_bounded_ptr
<TQual
> a
= nullptr;
164 test_bounded_ptr
<TQual
> a(array
.end() - 1, array
.begin(), array
.end() - 2);
169 test_bounded_ptr
<TQual
> a
= nullptr;
170 TQual
* b
= array
.begin();
175 struct Base
{ int i
; };
176 struct Derived
: Base
{ };
178 template <typename Related
>
182 std::array
<Derived
, 5> array
= {Derived
{0}, Derived
{1}, Derived
{2}, Derived
{3}, Derived
{4}};
185 test_bounded_ptr
<Derived
> const a(array
.begin() + 1, array
.begin(), array
.end() - 1);
186 Related
* b
= array
.begin();
190 test_bounded_ptr
<Related
> const a(array
.begin(), array
.begin(), array
.end() - 1);
191 Derived
* b
= array
.begin() + 1;
195 // Test comparisons against cv-void*
197 test_bounded_ptr
<Related
> const a(array
.begin(), array
.begin(), array
.end() - 1);
198 void* b
= array
.begin() + 1;
203 T_DECL(compare_order_raw
, "bounded_ptr.compare.order.raw") {
204 tests
<Derived
, Derived
>();
205 tests
<Derived
, Derived
const>();
206 tests
<Derived
, Derived
volatile>();
207 tests
<Derived
, Derived
const volatile>();
208 tests_convert
<Base
>();
209 tests_convert
<Base
const>();
210 tests_convert
<Base
volatile>();
211 tests_convert
<Base
const volatile>();