1*0f4c859eSApple OSS Distributions //
2*0f4c859eSApple OSS Distributions // Tests for
3*0f4c859eSApple OSS Distributions // iterator begin();
4*0f4c859eSApple OSS Distributions // const_iterator begin() const;
5*0f4c859eSApple OSS Distributions //
6*0f4c859eSApple OSS Distributions // iterator end();
7*0f4c859eSApple OSS Distributions // const_iterator end() const;
8*0f4c859eSApple OSS Distributions //
9*0f4c859eSApple OSS Distributions
10*0f4c859eSApple OSS Distributions #include <libkern/c++/bounded_array.h>
11*0f4c859eSApple OSS Distributions #include "test_policy.h"
12*0f4c859eSApple OSS Distributions #include <darwintest.h>
13*0f4c859eSApple OSS Distributions #include <type_traits>
14*0f4c859eSApple OSS Distributions
15*0f4c859eSApple OSS Distributions struct T { int i; };
16*0f4c859eSApple OSS Distributions
17*0f4c859eSApple OSS Distributions template <typename T>
18*0f4c859eSApple OSS Distributions static void
tests()19*0f4c859eSApple OSS Distributions tests()
20*0f4c859eSApple OSS Distributions {
21*0f4c859eSApple OSS Distributions // Check begin()/end() for a non-empty array
22*0f4c859eSApple OSS Distributions {
23*0f4c859eSApple OSS Distributions test_bounded_array<T, 5> array = {T{0}, T{1}, T{2}, T{3}, T{4}};
24*0f4c859eSApple OSS Distributions test_bounded_ptr<T> begin = array.begin();
25*0f4c859eSApple OSS Distributions test_bounded_ptr<T> end = array.end();
26*0f4c859eSApple OSS Distributions CHECK(begin.discard_bounds() == array.data());
27*0f4c859eSApple OSS Distributions CHECK(end.unsafe_discard_bounds() == array.data() + 5);
28*0f4c859eSApple OSS Distributions }
29*0f4c859eSApple OSS Distributions {
30*0f4c859eSApple OSS Distributions test_bounded_array<T, 5> const array = {T{0}, T{1}, T{2}, T{3}, T{4}};
31*0f4c859eSApple OSS Distributions test_bounded_ptr<T const> begin = array.begin();
32*0f4c859eSApple OSS Distributions test_bounded_ptr<T const> end = array.end();
33*0f4c859eSApple OSS Distributions CHECK(begin.discard_bounds() == array.data());
34*0f4c859eSApple OSS Distributions CHECK(end.unsafe_discard_bounds() == array.data() + 5);
35*0f4c859eSApple OSS Distributions }
36*0f4c859eSApple OSS Distributions
37*0f4c859eSApple OSS Distributions // Check begin()/end() for an empty array
38*0f4c859eSApple OSS Distributions {
39*0f4c859eSApple OSS Distributions test_bounded_array<T, 0> array = {};
40*0f4c859eSApple OSS Distributions test_bounded_ptr<T> begin = array.begin();
41*0f4c859eSApple OSS Distributions test_bounded_ptr<T> end = array.end();
42*0f4c859eSApple OSS Distributions CHECK(begin.unsafe_discard_bounds() == array.data());
43*0f4c859eSApple OSS Distributions CHECK(end.unsafe_discard_bounds() == array.data());
44*0f4c859eSApple OSS Distributions }
45*0f4c859eSApple OSS Distributions {
46*0f4c859eSApple OSS Distributions test_bounded_array<T, 0> const array = {};
47*0f4c859eSApple OSS Distributions test_bounded_ptr<T const> begin = array.begin();
48*0f4c859eSApple OSS Distributions test_bounded_ptr<T const> end = array.end();
49*0f4c859eSApple OSS Distributions CHECK(begin.unsafe_discard_bounds() == array.data());
50*0f4c859eSApple OSS Distributions CHECK(end.unsafe_discard_bounds() == array.data());
51*0f4c859eSApple OSS Distributions }
52*0f4c859eSApple OSS Distributions
53*0f4c859eSApple OSS Distributions // Check associated types
54*0f4c859eSApple OSS Distributions {
55*0f4c859eSApple OSS Distributions using A = test_bounded_array<T, 10>;
56*0f4c859eSApple OSS Distributions static_assert(std::is_same_v<typename A::iterator, test_bounded_ptr<T> >);
57*0f4c859eSApple OSS Distributions static_assert(std::is_same_v<typename A::const_iterator, test_bounded_ptr<T const> >);
58*0f4c859eSApple OSS Distributions }
59*0f4c859eSApple OSS Distributions }
60*0f4c859eSApple OSS Distributions
61*0f4c859eSApple OSS Distributions T_DECL(begin_end, "bounded_array.begin_end") {
62*0f4c859eSApple OSS Distributions tests<T>();
63*0f4c859eSApple OSS Distributions }
64