aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-03-05 01:00:50 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-03-05 01:00:50 +0000
commit1f6cf695b30d2a7a4e7f046f04868a6e430b05b0 (patch)
tree03b1dd25e63c67efc53e47b87c13d0f23b9202cc /tests
parente492ac4fb638678408e421c2b74dea106286bbbd (diff)
Counterproposal to 182733007: Add iterator to SkTDynamicHash
BUG=skia: R=egdaniel@google.com, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/177263005 git-svn-id: http://skia.googlecode.com/svn/trunk@13663 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r--tests/DynamicHashTest.cpp60
1 files changed, 51 insertions, 9 deletions
diff --git a/tests/DynamicHashTest.cpp b/tests/DynamicHashTest.cpp
index db6622d7a7..14ecf7a5be 100644
--- a/tests/DynamicHashTest.cpp
+++ b/tests/DynamicHashTest.cpp
@@ -35,7 +35,7 @@ private:
#define ASSERT(x) REPORTER_ASSERT(reporter, x)
-static void test_growth(skiatest::Reporter* reporter) {
+DEF_TEST(DynamicHash_growth, reporter) {
Entry a = { 1, 2.0 };
Entry b = { 2, 3.0 };
Entry c = { 3, 4.0 };
@@ -63,7 +63,7 @@ static void test_growth(skiatest::Reporter* reporter) {
ASSERT(hash.count() == 5);
}
-static void test_add(skiatest::Reporter* reporter) {
+DEF_TEST(DynamicHash_add, reporter) {
Hash hash;
Entry a = { 1, 2.0 };
Entry b = { 2, 3.0 };
@@ -75,7 +75,7 @@ static void test_add(skiatest::Reporter* reporter) {
ASSERT(hash.count() == 2);
}
-static void test_lookup(skiatest::Reporter* reporter) {
+DEF_TEST(DynamicHash_lookup, reporter) {
Hash hash;
// These collide.
@@ -110,7 +110,7 @@ static void test_lookup(skiatest::Reporter* reporter) {
ASSERT(hash.find(9) == NULL);
}
-static void test_remove(skiatest::Reporter* reporter) {
+DEF_TEST(DynamicHash_remove, reporter) {
Hash hash;
// These collide.
@@ -136,9 +136,51 @@ static void test_remove(skiatest::Reporter* reporter) {
ASSERT(hash.find(5)->value == 3.0);
}
-DEF_TEST(DynamicHash, reporter) {
- test_growth(reporter);
- test_add(reporter);
- test_lookup(reporter);
- test_remove(reporter);
+DEF_TEST(DynamicHash_iterator, reporter) {
+ Hash hash;
+
+ int count = 0;
+ // this should fall out of loop immediately
+ for (Hash::Iter iter(&hash); !iter.done(); ++iter) {
+ ++count;
+ }
+ ASSERT(0 == count);
+
+ // These collide.
+ Entry a = { 1, 2.0 };
+ Entry b = { 5, 3.0 };
+ Entry c = { 9, 4.0 };
+
+ hash.add(&a);
+ hash.add(&b);
+ hash.add(&c);
+
+ // should see all 3 unique keys when iterating over hash
+ count = 0;
+ int keys[3] = {0, 0, 0};
+ for (Hash::Iter iter(&hash); !iter.done(); ++iter) {
+ int key = (*iter).key;
+ keys[count] = key;
+ ASSERT(hash.find(key) != NULL);
+ ++count;
+ }
+ ASSERT(3 == count);
+ ASSERT(keys[0] != keys[1]);
+ ASSERT(keys[0] != keys[2]);
+ ASSERT(keys[1] != keys[2]);
+
+ // should see 2 unique keys when iterating over hash that aren't 1
+ hash.remove(1);
+ count = 0;
+ memset(keys,0,sizeof(keys));
+ for (Hash::Iter iter(&hash); !iter.done(); ++iter) {
+ int key = (*iter).key;
+ keys[count] = key;
+ ASSERT(key != 1);
+ ASSERT(hash.find(key) != NULL);
+ ++count;
+ }
+ ASSERT(2 == count);
+ ASSERT(keys[0] != keys[1]);
}
+