X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/eb6b6ca394357805f2bdba989abae309f718b4d8..f427ee49d309d8fc33ebf3042c3a775f2f530ded:/tests/bounded_array_ref_src/begin_end.cpp?ds=inline diff --git a/tests/bounded_array_ref_src/begin_end.cpp b/tests/bounded_array_ref_src/begin_end.cpp new file mode 100644 index 000000000..067bc6417 --- /dev/null +++ b/tests/bounded_array_ref_src/begin_end.cpp @@ -0,0 +1,47 @@ +// +// Tests for +// iterator begin() const; +// iterator end() const; +// + +#include +#include "test_policy.h" +#include +#include + +struct T { int i; }; + +template +static void +tests() +{ + using AR = test_bounded_array_ref; + + // Check begin()/end() for a non-null array ref + { + T array[5] = {T{0}, T{1}, T{2}, T{3}, T{4}}; + AR const view(array); + test_bounded_ptr begin = view.begin(); + test_bounded_ptr end = view.end(); + CHECK(begin.discard_bounds() == &array[0]); + CHECK(end.unsafe_discard_bounds() == &array[5]); + } + + // Check begin()/end() for a null array ref + { + AR const view; + test_bounded_ptr begin = view.begin(); + test_bounded_ptr end = view.end(); + CHECK(begin.unsafe_discard_bounds() == nullptr); + CHECK(end.unsafe_discard_bounds() == nullptr); + } + + // Check associated types + { + static_assert(std::is_same_v >); + } +} + +T_DECL(begin_end, "bounded_array_ref.begin_end") { + tests(); +}