1bb611c8fSApple OSS Distributions //
2bb611c8fSApple OSS Distributions // Tests for
3bb611c8fSApple OSS Distributions // size_t size() const;
4bb611c8fSApple OSS Distributions //
5bb611c8fSApple OSS Distributions
6bb611c8fSApple OSS Distributions #include <libkern/c++/bounded_array_ref.h>
7bb611c8fSApple OSS Distributions #include "test_policy.h"
8bb611c8fSApple OSS Distributions #include <cstddef>
9bb611c8fSApple OSS Distributions #include <darwintest.h>
10bb611c8fSApple OSS Distributions #include <darwintest_utils.h>
11bb611c8fSApple OSS Distributions
12bb611c8fSApple OSS Distributions struct T { int i; };
13bb611c8fSApple OSS Distributions
14bb611c8fSApple OSS Distributions template <typename T>
15bb611c8fSApple OSS Distributions static void
tests()16bb611c8fSApple OSS Distributions tests()
17bb611c8fSApple OSS Distributions {
18bb611c8fSApple OSS Distributions T array[5] = {T{0}, T{1}, T{2}, T{3}, T{4}};
19bb611c8fSApple OSS Distributions
20bb611c8fSApple OSS Distributions {
21bb611c8fSApple OSS Distributions test_bounded_array_ref<T> const view(&array[0], static_cast<std::size_t>(0));
22bb611c8fSApple OSS Distributions std::size_t size = view.size();
23bb611c8fSApple OSS Distributions CHECK(size == 0);
24bb611c8fSApple OSS Distributions }
25bb611c8fSApple OSS Distributions {
26bb611c8fSApple OSS Distributions test_bounded_array_ref<T> const view(&array[0], 1);
27bb611c8fSApple OSS Distributions std::size_t size = view.size();
28bb611c8fSApple OSS Distributions CHECK(size == 1);
29bb611c8fSApple OSS Distributions }
30bb611c8fSApple OSS Distributions {
31bb611c8fSApple OSS Distributions test_bounded_array_ref<T> const view(&array[0], 2);
32bb611c8fSApple OSS Distributions std::size_t size = view.size();
33bb611c8fSApple OSS Distributions CHECK(size == 2);
34bb611c8fSApple OSS Distributions }
35bb611c8fSApple OSS Distributions {
36bb611c8fSApple OSS Distributions test_bounded_array_ref<T> const view(&array[0], 5);
37bb611c8fSApple OSS Distributions std::size_t size = view.size();
38bb611c8fSApple OSS Distributions CHECK(size == 5);
39bb611c8fSApple OSS Distributions }
40bb611c8fSApple OSS Distributions }
41bb611c8fSApple OSS Distributions
42*8d741a5dSApple OSS Distributions T_DECL(size, "bounded_array_ref.size", T_META_TAG_VM_PREFERRED) {
43bb611c8fSApple OSS Distributions tests<T>();
44bb611c8fSApple OSS Distributions tests<T const>();
45bb611c8fSApple OSS Distributions }
46