1bb611c8fSApple OSS Distributions //
2bb611c8fSApple OSS Distributions // Tests for
3bb611c8fSApple OSS Distributions // T* data();
4bb611c8fSApple OSS Distributions // T const* data() const;
5bb611c8fSApple OSS Distributions //
6bb611c8fSApple OSS Distributions
7bb611c8fSApple OSS Distributions #include <libkern/c++/bounded_array.h>
8bb611c8fSApple OSS Distributions #include "test_policy.h"
9bb611c8fSApple OSS Distributions #include <darwintest.h>
10bb611c8fSApple OSS Distributions #include <type_traits>
11bb611c8fSApple OSS Distributions
12bb611c8fSApple OSS Distributions struct T { int i; };
13bb611c8fSApple OSS Distributions inline bool
operator ==(T const & a,T const & b)14bb611c8fSApple OSS Distributions operator==(T const& a, T const& b)
15bb611c8fSApple OSS Distributions {
16bb611c8fSApple OSS Distributions return a.i == b.i;
17bb611c8fSApple OSS Distributions }
18bb611c8fSApple OSS Distributions
19bb611c8fSApple OSS Distributions template <typename T>
20bb611c8fSApple OSS Distributions static void
tests()21bb611c8fSApple OSS Distributions tests()
22bb611c8fSApple OSS Distributions {
23bb611c8fSApple OSS Distributions {
24bb611c8fSApple OSS Distributions test_bounded_array<T, 5> array = {T{0}, T{1}, T{2}, T{3}, T{4}};
25bb611c8fSApple OSS Distributions T* data = array.data();
26bb611c8fSApple OSS Distributions CHECK(data != nullptr);
27bb611c8fSApple OSS Distributions CHECK(data[0] == T{0});
28bb611c8fSApple OSS Distributions CHECK(data[1] == T{1});
29bb611c8fSApple OSS Distributions CHECK(data[2] == T{2});
30bb611c8fSApple OSS Distributions CHECK(data[3] == T{3});
31bb611c8fSApple OSS Distributions CHECK(data[4] == T{4});
32bb611c8fSApple OSS Distributions }
33bb611c8fSApple OSS Distributions {
34bb611c8fSApple OSS Distributions test_bounded_array<T, 5> const array = {T{0}, T{1}, T{2}, T{3}, T{4}};
35bb611c8fSApple OSS Distributions T const* data = array.data();
36bb611c8fSApple OSS Distributions CHECK(data != nullptr);
37bb611c8fSApple OSS Distributions CHECK(data[0] == T{0});
38bb611c8fSApple OSS Distributions CHECK(data[1] == T{1});
39bb611c8fSApple OSS Distributions CHECK(data[2] == T{2});
40bb611c8fSApple OSS Distributions CHECK(data[3] == T{3});
41bb611c8fSApple OSS Distributions CHECK(data[4] == T{4});
42bb611c8fSApple OSS Distributions }
43bb611c8fSApple OSS Distributions
44bb611c8fSApple OSS Distributions {
45bb611c8fSApple OSS Distributions test_bounded_array<T, 0> array = {};
46bb611c8fSApple OSS Distributions T* data = array.data();
47bb611c8fSApple OSS Distributions CHECK(data != nullptr);
48bb611c8fSApple OSS Distributions }
49bb611c8fSApple OSS Distributions {
50bb611c8fSApple OSS Distributions test_bounded_array<T, 0> const array = {};
51bb611c8fSApple OSS Distributions T const* data = array.data();
52bb611c8fSApple OSS Distributions CHECK(data != nullptr);
53bb611c8fSApple OSS Distributions }
54bb611c8fSApple OSS Distributions }
55bb611c8fSApple OSS Distributions
56*8d741a5dSApple OSS Distributions T_DECL(data, "bounded_array.data", T_META_TAG_VM_PREFERRED) {
57bb611c8fSApple OSS Distributions tests<T>();
58bb611c8fSApple OSS Distributions }
59