]> git.saurik.com Git - apple/xnu.git/blobdiff - tests/bounded_array_ref_src/operator.subscript.cpp
xnu-7195.50.7.100.1.tar.gz
[apple/xnu.git] / tests / bounded_array_ref_src / operator.subscript.cpp
diff --git a/tests/bounded_array_ref_src/operator.subscript.cpp b/tests/bounded_array_ref_src/operator.subscript.cpp
new file mode 100644 (file)
index 0000000..ae7ed08
--- /dev/null
@@ -0,0 +1,35 @@
+//
+// Tests for
+//  T& operator[](ptrdiff_t n) const;
+//
+
+#include <libkern/c++/bounded_array_ref.h>
+#include "test_policy.h"
+#include <darwintest.h>
+#include <darwintest_utils.h>
+
+struct T { int i; };
+inline bool
+operator==(T const& a, T const& b)
+{
+       return a.i == b.i;
+};
+
+template <typename T>
+static void
+tests()
+{
+       {
+               T array[5] = {T{0}, T{1}, T{2}, T{3}, T{4}};
+               test_bounded_array_ref<T> view(array);
+               CHECK(view[0] == T{0});
+               CHECK(view[1] == T{1});
+               CHECK(view[2] == T{2});
+               CHECK(view[3] == T{3});
+               CHECK(view[4] == T{4});
+       }
+}
+
+T_DECL(operator_subscript, "bounded_array_ref.operator.subscript") {
+       tests<T>();
+}