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

Unified Diff: tests/SListTest.cpp

Issue 187233002: Fast implementation of QuadTree (Closed) Base URL: https://skia.googlesource.com/skia.git@bbh_select
Patch Set: I give up, stoopid compiler 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 | « tests/ObjectPoolTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/SListTest.cpp
diff --git a/tests/SListTest.cpp b/tests/SListTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..72a82814f9b8834a04d1143ae964e73e3447f0ea
--- /dev/null
+++ b/tests/SListTest.cpp
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkTInternalSList.h"
+#include "Test.h"
+
+class SListEntry {
+public:
+ SListEntry* next() { return getSListNext(); }
+private:
+ SK_DECLARE_INTERNAL_SLIST_INTERFACE(SListEntry);
+};
+
+static bool verifyEmptyList(skiatest::Reporter* reporter,
+ const SkTInternalSList<SListEntry>& list,
+ const char* stage) {
+
+ if (!list.isEmpty()) {
+ ERRORF(reporter, "%s - List not empty", stage);
+ return false;
+ }
+ if (0 != list.getCount()) {
+ ERRORF(reporter, "%s - List count is not zero, %d instead", stage, list.getCount());
+ return false;
+ }
+ if (NULL != list.head()) {
+ ERRORF(reporter, "%s - List has elements when empty", stage);
+ return false;
+ }
+ return true;
+}
+
+static bool verifyList(skiatest::Reporter* reporter,
+ const SkTInternalSList<SListEntry>& list,
+ const char* stage,
+ SListEntry* start, int count, int step = 1) {
+ SListEntry* next = list.head();
+ if (list.getCount() != count) {
+ ERRORF(reporter, "%s - List was too short, %d instead of %d", stage, list.getCount(), count);
+ return false;
+ }
+ int index = 0;
+ for(SListEntry* value = start; index < count; value += step, ++index) {
+ if (NULL == next) {
+ ERRORF(reporter, "%s - List too short, should be %d", stage, count);
+ return false;
+ }
+ if (next!= value) {
+ ERRORF(reporter, "%s - List entries at index %d of %d don't match", stage, index, count);
+ return false;
+ }
+ next = next->next();
+ }
+ if (NULL != next) {
+ ERRORF(reporter, "%s - List too long, should be %d", stage, count);
+ return false;
+ }
+ return true;
+}
+
+static void testTInternalSList(skiatest::Reporter* reporter) {
+ // Build a test array of data
+ static const int testArraySize = 10;
+ SListEntry testArray[testArraySize];
+ // Basic add remove tests
+ SkTInternalSList<SListEntry> list;
+ verifyEmptyList(reporter, list, "start");
+ // Push values in, testing on the way
+ for (int index = 0; index < testArraySize; ++index) {
+ list.push(&testArray[index]);
+ if (!verifyList(reporter, list, "push", &testArray[index], index+1, -1)) {
+ return;
+ }
+ }
+ // Now remove them again
+ for (int index = testArraySize - 1; index >= 0; --index) {
+ REPORTER_ASSERT(reporter, &testArray[index] == list.pop());
+ if ((index != 0) &&
+ !verifyList(reporter, list, "pop", &testArray[index-1], index, -1)) {
+ return;
+ }
+ }
+ verifyEmptyList(reporter, list, "end");
+ // Move between list tests
+ for (int index = 0; index < testArraySize; ++index) {
+ list.push(&testArray[index]);
+ }
+ verifyList(reporter, list, "swap", &testArray[testArraySize-1], testArraySize, -1);
+ SkTInternalSList<SListEntry> other;
+ // Check swap moves the list over unchanged
+ other.swap(&list);
+ verifyEmptyList(reporter, list, "swap");
+ verifyList(reporter, other, "swap", &testArray[testArraySize-1], testArraySize, -1);
+ // Check pushAll optimizes to a swap when one of the is empty
+ list.pushAll(&other);
+ verifyList(reporter, list, "pushAll-empty", &testArray[testArraySize-1], testArraySize, -1);
+ verifyEmptyList(reporter, other, "pushAll-empty");
+ // Check pushAll when non empty works
+ other.push(list.pop());
+ other.pushAll(&list);
+ verifyEmptyList(reporter, list, "pushAll");
+ verifyList(reporter, other, "pushAll", &testArray[0], testArraySize, 1);
+}
+
+DEF_TEST(SList, reporter) {
+ testTInternalSList(reporter);
+}
« no previous file with comments | « tests/ObjectPoolTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698