aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/TArrayTest.cpp
diff options
context:
space:
mode:
authorGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-03-21 19:39:02 +0000
committerGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-03-21 19:39:02 +0000
commit95ebd17cf4f66952862289882ee5ac00da31cb8a (patch)
treec9f257f7a39deeb036fc3295fc11e99c2cf079ef /tests/TArrayTest.cpp
parentb463d5668a498b672b80047f09901981afe513ed (diff)
Add removeShuffle to SkTArray and add SkTArray tests.
R=reed@google.com Review URL: https://codereview.chromium.org/208153008 git-svn-id: http://skia.googlecode.com/svn/trunk@13895 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/TArrayTest.cpp')
-rw-r--r--tests/TArrayTest.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/TArrayTest.cpp b/tests/TArrayTest.cpp
new file mode 100644
index 0000000000..f86cfe40f7
--- /dev/null
+++ b/tests/TArrayTest.cpp
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkTArray.h"
+#include "Test.h"
+
+// Tests the SkTArray<T> class template.
+
+template <bool MEM_COPY>
+static void TestTSet_basic(skiatest::Reporter* reporter) {
+ SkTArray<int, MEM_COPY> a;
+
+ // Starts empty.
+ REPORTER_ASSERT(reporter, a.empty());
+ REPORTER_ASSERT(reporter, a.count() == 0);
+
+ // { }, add a default constructed element
+ REPORTER_ASSERT(reporter, a.push_back());
+ REPORTER_ASSERT(reporter, !a.empty());
+ REPORTER_ASSERT(reporter, a.count() == 1);
+
+ // { 0 }, removeShuffle the only element.
+ a.removeShuffle(0);
+ REPORTER_ASSERT(reporter, a.empty());
+ REPORTER_ASSERT(reporter, a.count() == 0);
+
+ // { }, add a default, add a 1, remove first
+ REPORTER_ASSERT(reporter, a.push_back());
+ REPORTER_ASSERT(reporter, a.push_back() = 1);
+ a.removeShuffle(0);
+ REPORTER_ASSERT(reporter, !a.empty());
+ REPORTER_ASSERT(reporter, a.count() == 1);
+ REPORTER_ASSERT(reporter, a[0] == 1);
+
+ // { 1 }, replace with new array
+ int b[5] = { 0, 1, 2, 3, 4 };
+ a.reset(b, SK_ARRAY_COUNT(b));
+ REPORTER_ASSERT(reporter, a.count() == SK_ARRAY_COUNT(b));
+ REPORTER_ASSERT(reporter, a[2] == 2);
+ REPORTER_ASSERT(reporter, a[4] == 4);
+
+ // { 0, 1, 2, 3, 4 }, removeShuffle the last
+ a.removeShuffle(4);
+ REPORTER_ASSERT(reporter, a.count() == SK_ARRAY_COUNT(b) - 1);
+ REPORTER_ASSERT(reporter, a[3] == 3);
+
+ // { 0, 1, 2, 3 }, remove a middle, note shuffle
+ a.removeShuffle(1);
+ REPORTER_ASSERT(reporter, a.count() == SK_ARRAY_COUNT(b) - 2);
+ REPORTER_ASSERT(reporter, a[0] == 0);
+ REPORTER_ASSERT(reporter, a[1] == 3);
+ REPORTER_ASSERT(reporter, a[2] == 2);
+
+ // {0, 3, 2 }
+}
+
+DEF_TEST(TArray, reporter) {
+ TestTSet_basic<true>(reporter);
+ TestTSet_basic<false>(reporter);
+}