Index: tests/TDArrayTest.cpp |
diff --git a/tests/TDArrayTest.cpp b/tests/TDArrayTest.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8db498d8220fba43af5efba3758101e58f62d968 |
--- /dev/null |
+++ b/tests/TDArrayTest.cpp |
@@ -0,0 +1,101 @@ |
+/* |
+ * Copyright 2013 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#include "Test.h" |
+#include "SkTDArray.h" |
+ |
+static void basic_empty(skiatest::Reporter* reporter, SkTDArray<int>& a) { |
+ REPORTER_ASSERT(reporter, a.isEmpty()); |
+ REPORTER_ASSERT(reporter, !a.contains(-1)); |
+ REPORTER_ASSERT(reporter, !a.contains(0)); |
+ REPORTER_ASSERT(reporter, !a.contains(1)); |
+ REPORTER_ASSERT(reporter, a.count() == 0); |
+} |
+ |
+static void basic_add_first(skiatest::Reporter* reporter, SkTDArray<int>& a) { |
+ int* elem; |
+ REPORTER_ASSERT(reporter, elem = a.append()); |
+ *elem = 0; |
+ REPORTER_ASSERT(reporter, !a.isEmpty()); |
+ REPORTER_ASSERT(reporter, !a.contains(-1)); |
+ REPORTER_ASSERT(reporter, a.contains(0)); |
+ REPORTER_ASSERT(reporter, !a.contains(1)); |
+ REPORTER_ASSERT(reporter, a.count() == 1); |
+ REPORTER_ASSERT(reporter, a.begin() != NULL); |
+} |
+ |
+static void basic_add_second(skiatest::Reporter* reporter, SkTDArray<int>& a) { |
+ int* elem; |
+ REPORTER_ASSERT(reporter, elem = a.append()); |
+ *elem = 1; |
+ REPORTER_ASSERT(reporter, !a.isEmpty()); |
+ REPORTER_ASSERT(reporter, !a.contains(-1)); |
+ REPORTER_ASSERT(reporter, a.contains(0)); |
+ REPORTER_ASSERT(reporter, a.contains(1)); |
+ REPORTER_ASSERT(reporter, a.count() == 2); |
+ REPORTER_ASSERT(reporter, a.begin() != NULL); |
+} |
+ |
+int testArray[] = {1, 2, 3}; |
+ |
+static void basic(skiatest::Reporter* reporter) { |
+ SkTDArray<int> a; |
+ basic_empty(reporter, a); |
+ basic_add_first(reporter, a); |
+ |
+ SkSTDArray<1, int> b; |
+ basic_empty(reporter, b); |
+ basic_add_first(reporter, b); |
+ |
+ SkSTDArray<1, int> c(b); |
+ |
+ int* storage = b.begin(); |
+ basic_add_second(reporter, b); |
+ int* alloc = b.begin(); |
+ REPORTER_ASSERT(reporter, storage != alloc); |
+ |
+ REPORTER_ASSERT(reporter, c.count() == 1 && c[0] == 0); |
+ |
+ b = c; |
+ REPORTER_ASSERT(reporter, b.count() == c.count() && b.count() == 1); |
+ REPORTER_ASSERT(reporter, b[0] == 0); |
+ REPORTER_ASSERT(reporter, c[0] == 0); |
+ |
+ SkSTDArray<3, int> d(testArray, SK_ARRAY_COUNT(testArray)); |
+ REPORTER_ASSERT(reporter, d.count() == 3); |
+ |
+ SkSTDArray<2, int> e; |
+ e = d; |
+ REPORTER_ASSERT(reporter, e.count() == 3); |
+ |
+#ifdef SK_DEBUG |
+ a.validate(); |
+ b.validate(); |
+ c.validate(); |
+ d.validate(); |
+#endif |
+ |
+ c.reset(); |
+ REPORTER_ASSERT(reporter, c.count() == 0); |
+ |
+ int* data = b.detach(); |
+ REPORTER_ASSERT(reporter, b.count() == 0); |
+ sk_free(data); |
+ |
+ a = c; |
+ REPORTER_ASSERT(reporter, a.count() == c.count() && a.count() == 0); |
+ |
+#ifdef SK_DEBUG |
+ a.validate(); |
+ b.validate(); |
+ c.validate(); |
+#endif |
+} |
+ |
+DEF_TEST(TDArray, reporter) { |
+ basic(reporter); |
+} |