diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-02-22 13:16:38 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-02-22 13:16:38 +0000 |
commit | 4c09d5cd4b9e6f0be1352f62288efdedc1bc3de3 (patch) | |
tree | 5dc6c6edc01fe1e0e970e9befadc0859f2d26a81 /tests/DequeTest.cpp | |
parent | aff86f3fe3f286c5e93cb1f9d3f1c3a819b8cc12 (diff) |
rename SkDeque::Iter to SkDeque::F2BIter, since it runs front-to-back (in preparation
for another iter that runs back-to-front (B2FIter).
add unittest for Deque
git-svn-id: http://skia.googlecode.com/svn/trunk@821 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/DequeTest.cpp')
-rw-r--r-- | tests/DequeTest.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/DequeTest.cpp b/tests/DequeTest.cpp new file mode 100644 index 0000000000..3b8991adda --- /dev/null +++ b/tests/DequeTest.cpp @@ -0,0 +1,62 @@ +#include "Test.h" +#include "SkDeque.h" + +static void assert_count(skiatest::Reporter* reporter, const SkDeque& deq, int count) { + if (0 == count) { + REPORTER_ASSERT(reporter, deq.empty()); + REPORTER_ASSERT(reporter, 0 == deq.count()); + REPORTER_ASSERT(reporter, sizeof(int) == deq.elemSize()); + REPORTER_ASSERT(reporter, NULL == deq.front()); + REPORTER_ASSERT(reporter, NULL == deq.back()); + } else { + REPORTER_ASSERT(reporter, !deq.empty()); + REPORTER_ASSERT(reporter, count == deq.count()); + REPORTER_ASSERT(reporter, sizeof(int) == deq.elemSize()); + REPORTER_ASSERT(reporter, NULL != deq.front()); + REPORTER_ASSERT(reporter, NULL != deq.back()); + if (1 == count) { + REPORTER_ASSERT(reporter, deq.back() == deq.front()); + } else { + REPORTER_ASSERT(reporter, deq.back() != deq.front()); + } + } +} + +static void assert_f2biter(skiatest::Reporter* reporter, const SkDeque& deq, + int max, int min) { + SkDeque::F2BIter iter(deq); + void* ptr; + + int value = max; + while ((ptr = iter.next()) != NULL) { + REPORTER_ASSERT(reporter, value == *(int*)ptr); + value -= 1; + } + REPORTER_ASSERT(reporter, value+1 == min); +} + +static void TestDeque(skiatest::Reporter* reporter) { + SkDeque deq(sizeof(int)); + int i; + + assert_count(reporter, deq, 0); + for (i = 1; i <= 10; i++) { + *(int*)deq.push_front() = i; + } + assert_count(reporter, deq, 10); + assert_f2biter(reporter, deq, 10, 1); + + for (i = 0; i < 5; i++) { + deq.pop_front(); + } + assert_count(reporter, deq, 5); + assert_f2biter(reporter, deq, 5, 1); + + for (i = 0; i < 5; i++) { + deq.pop_front(); + } + assert_count(reporter, deq, 0); +} + +#include "TestClassDef.h" +DEFINE_TESTCLASS("Deque", TestDequeClass, TestDeque) |