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