]>
git.saurik.com Git - apple/xnu.git/blob - tests/bounded_ptr_src/compare.order.cpp
3 // template <typename T, typename U, typename P1, typename P2>
4 // bool operator<(bounded_ptr<T, P1> const& a, bounded_ptr<U, P2> const& b);
6 // template <typename T, typename U, typename P1, typename P2>
7 // bool operator<=(bounded_ptr<T, P1> const& a, bounded_ptr<U, P2> const& b);
9 // template <typename T, typename U, typename P1, typename P2>
10 // bool operator>(bounded_ptr<T, P1> const& a, bounded_ptr<U, P2> const& b);
12 // template <typename T, typename U, typename P1, typename P2>
13 // bool operator>=(bounded_ptr<T, P1> const& a, bounded_ptr<U, P2> 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 struct dummy_policy1
{
30 struct dummy_policy2
{
37 template <typename T
, typename U
>
52 template <typename T
, typename U
>
67 template <typename T
, typename TQual
>
71 std::array
<T
, 5> array
= {T
{0}, T
{1}, T
{2}, T
{3}, T
{4}};
73 // Pointers with the same bounds
75 test_bounded_ptr
<TQual
> const a(array
.begin(), array
.begin(), array
.end());
76 test_bounded_ptr
<TQual
> const b(array
.begin(), array
.begin(), array
.end());
80 test_bounded_ptr
<TQual
> const a(array
.begin(), array
.begin(), array
.end());
81 test_bounded_ptr
<TQual
> const b(array
.begin() + 1, array
.begin(), array
.end());
85 test_bounded_ptr
<TQual
> const a(array
.begin(), array
.begin(), array
.end());
86 test_bounded_ptr
<TQual
> const b(array
.begin() + 2, array
.begin(), array
.end());
90 test_bounded_ptr
<TQual
> const a(array
.begin(), array
.begin(), array
.end());
91 test_bounded_ptr
<TQual
> const b(array
.end(), array
.begin(), array
.end());
95 test_bounded_ptr
<TQual
> const a(array
.end(), array
.begin(), array
.end());
96 test_bounded_ptr
<TQual
> const b(array
.end(), array
.begin(), array
.end());
100 // Compare null pointers
102 test_bounded_ptr
<TQual
> const a
;
103 test_bounded_ptr
<TQual
> const b(array
.begin(), array
.begin(), array
.end());
107 test_bounded_ptr
<TQual
> const a
;
108 test_bounded_ptr
<TQual
> const b
;
112 // Pointers with different bounds
114 // Overlapping bounds, equal
115 test_bounded_ptr
<TQual
> const a(array
.begin(), array
.begin() + 2, array
.end());
116 test_bounded_ptr
<TQual
> const b(array
.begin(), array
.begin(), array
.end());
120 // Overlapping bounds, not equal
121 test_bounded_ptr
<TQual
> const a(array
.begin(), array
.begin() + 2, array
.end());
122 test_bounded_ptr
<TQual
> const b(array
.begin() + 2, array
.begin(), array
.end());
126 // Non-overlapping bounds, equal
127 test_bounded_ptr
<TQual
> const a(array
.begin(), array
.begin(), array
.begin() + 1);
128 test_bounded_ptr
<TQual
> const b(array
.begin(), array
.begin() + 2, array
.end());
132 // Non-overlapping bounds, not equal
133 test_bounded_ptr
<TQual
> const a(array
.begin(), array
.begin(), array
.begin() + 1);
134 test_bounded_ptr
<TQual
> const b(array
.begin() + 3, array
.begin() + 2, array
.end());
138 // Test with different policies
140 libkern::bounded_ptr
<TQual
, dummy_policy1
> const a(array
.begin(), array
.begin(), array
.end());
141 libkern::bounded_ptr
<TQual
, dummy_policy2
> const b(array
.begin(), array
.begin(), array
.end());
146 struct Base
{ int i
; };
147 struct Derived
: Base
{ };
149 template <typename Related
>
153 std::array
<Derived
, 5> array
= {Derived
{0}, Derived
{1}, Derived
{2}, Derived
{3}, Derived
{4}};
154 test_bounded_ptr
<Derived
> const a(array
.begin(), array
.begin(), array
.end() - 1);
155 test_bounded_ptr
<Related
> const b(array
.begin(), array
.begin(), array
.end() - 1);
159 T_DECL(compare_order
, "bounded_ptr.compare.order") {
160 tests
<Derived
, Derived
>();
161 tests
<Derived
, Derived
const>();
162 tests
<Derived
, Derived
volatile>();
163 tests
<Derived
, Derived
const volatile>();
164 tests_convert
<Base
>();
165 tests_convert
<Base
const>();
166 tests_convert
<Base
volatile>();
167 tests_convert
<Base
const volatile>();