Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2137)

Unified Diff: tests/TArrayTest.cpp

Issue 208153008: Add test for SkTArray. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkTArray.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/TArrayTest.cpp
===================================================================
--- tests/TArrayTest.cpp (revision 0)
+++ tests/TArrayTest.cpp (working copy)
@@ -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);
+}
« no previous file with comments | « include/core/SkTArray.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698