]>
git.saurik.com Git - apple/xnu.git/blob - tests/bounded_ptr_src/arith.inc_dec.cpp
3 // bounded_ptr& operator++();
4 // bounded_ptr operator++(int);
5 // bounded_ptr& operator--();
6 // bounded_ptr operator--(int);
9 #include <libkern/c++/bounded_ptr.h>
11 #include <darwintest.h>
12 #include <darwintest_utils.h>
13 #include "test_utils.h"
15 #define _assert(...) T_ASSERT_TRUE((__VA_ARGS__), # __VA_ARGS__)
21 template <typename T
, typename QualT
>
25 std::array
<T
, 5> array
= {T
{0}, T
{1}, T
{2}, T
{3}, T
{4}};
28 // Test pre-increment and pre-decrement
29 test_bounded_ptr
<QualT
> ptr(array
.begin(), array
.begin(), array
.end());
30 _assert(&*ptr
== &array
[0]);
34 _assert(&ref
== &ptr
);
35 _assert(&*ptr
== &array
[1]);
40 _assert(&ref
== &ptr
);
41 _assert(&*ptr
== &array
[2]);
45 _assert(&ref
== &ptr
);
46 _assert(&*ptr
== &array
[3]);
50 _assert(&ref
== &ptr
);
51 _assert(&*ptr
== &array
[4]);
55 _assert(&ref
== &ptr
);
56 // ptr is now one-past-last
60 _assert(&ref
== &ptr
);
61 _assert(&*ptr
== &array
[4]);
65 _assert(&ref
== &ptr
);
66 _assert(&*ptr
== &array
[3]);
70 _assert(&ref
== &ptr
);
71 _assert(&*ptr
== &array
[2]);
75 _assert(&ref
== &ptr
);
76 _assert(&*ptr
== &array
[1]);
80 _assert(&ref
== &ptr
);
81 _assert(&*ptr
== &array
[0]);
85 // Test post-increment and post-decrement
86 test_bounded_ptr
<QualT
> ptr(array
.begin(), array
.begin(), array
.end());
87 _assert(&*ptr
== &array
[0]);
91 _assert(&*prev
== &array
[0]);
92 _assert(&*ptr
== &array
[1]);
96 _assert(&*prev
== &array
[1]);
97 _assert(&*ptr
== &array
[2]);
101 _assert(&*prev
== &array
[2]);
102 _assert(&*ptr
== &array
[3]);
106 _assert(&*prev
== &array
[3]);
107 _assert(&*ptr
== &array
[4]);
111 _assert(&*prev
== &array
[4]);
112 _assert(ptr
== array
.end());
116 _assert(prev
== array
.end());
117 _assert(&*ptr
== &array
[4]);
121 _assert(&*prev
== &array
[4]);
122 _assert(&*ptr
== &array
[3]);
126 _assert(&*prev
== &array
[3]);
127 _assert(&*ptr
== &array
[2]);
131 _assert(&*prev
== &array
[2]);
132 _assert(&*ptr
== &array
[1]);
136 _assert(&*prev
== &array
[1]);
137 _assert(&*ptr
== &array
[0]);
142 T_DECL(arith_inc_dec
, "bounded_ptr.arith.inc_dec") {
145 tests
<T
, T
volatile>();
146 tests
<T
, T
const volatile>();