diff options
author | mtklein <mtklein@chromium.org> | 2015-02-20 12:35:32 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-20 12:35:32 -0800 |
commit | 2aa1f7e6799501974532d35c1f6c3a0447121b95 (patch) | |
tree | bd4ad170d9a5205cf1e93fb5d19665eb3d6cb900 /tests | |
parent | e5524cd52d56f9b70d9b4a83bd73a3fa75d56509 (diff) |
Port GrGLCaps over to use SkTHash.
I've written some new hashtable interfaces that should be easier to use,
and I've been trying to roll them out bit by bit, hopefully replacing
SkTDynamicHash, SkTMultiMap, SkTHashCache, etc.
This turns the cache in GrGLCaps::readPixelsSupported() into an SkTHashMap,
mapping the format key to a bool. Functionally, it's the same.
BUG=skia:
Review URL: https://codereview.chromium.org/948473002
Diffstat (limited to 'tests')
-rw-r--r-- | tests/HashTest.cpp | 6 | ||||
-rw-r--r-- | tests/THashCache.cpp | 89 |
2 files changed, 6 insertions, 89 deletions
diff --git a/tests/HashTest.cpp b/tests/HashTest.cpp index 00857f63dc..623e597eeb 100644 --- a/tests/HashTest.cpp +++ b/tests/HashTest.cpp @@ -39,6 +39,9 @@ DEF_TEST(HashMap, r) { } REPORTER_ASSERT(r, map.count() == N); + + map.reset(); + REPORTER_ASSERT(r, map.count() == 0); } namespace { uint32_t hash_string(const SkString& s) { return SkToInt(s.size()); } } @@ -54,6 +57,9 @@ DEF_TEST(HashSet, r) { REPORTER_ASSERT(r, set.contains(SkString("Hello"))); REPORTER_ASSERT(r, set.contains(SkString("World"))); REPORTER_ASSERT(r, !set.contains(SkString("Goodbye"))); + + set.reset(); + REPORTER_ASSERT(r, set.count() == 0); } namespace { diff --git a/tests/THashCache.cpp b/tests/THashCache.cpp deleted file mode 100644 index c35df6c746..0000000000 --- a/tests/THashCache.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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 "Test.h" -#include "SkTHashCache.h" - - -// Tests the SkTHashCache<T> class template. - -struct Tint { - uint32_t value; - - bool operator==(const Tint& rhs) const { - return value == rhs.value; - } -}; - -class Element { -public: - - bool operator==(const Element& rhs) const { - return value == rhs.value && key == rhs.key; - } - - static const Tint& GetKey(const Element& element) { - return element.key; - } - - static uint32_t Hash(const Tint& key) { - return key.value; - } - - Element(Tint key, int value) : key(key), value(value) { - } - - Tint key; - int value; -}; - -typedef SkTHashCache<Element, Tint> CacheType; - -DEF_TEST(THashCache, reporter) { - Tint k11 = {11}; - Element e11(k11, 22); - - Element e11Collision(k11, 0); - // Element e42(4, 2); - - //Some tests for the class Element - REPORTER_ASSERT(reporter, Element::GetKey(e11) == k11); - REPORTER_ASSERT(reporter, Element::Hash(k11) == 11); - - CacheType cache; - - // Is the cahce correctly initialized ? - REPORTER_ASSERT(reporter, 0 == cache.size()); - REPORTER_ASSERT(reporter, NULL == cache.find(k11)); - - Element& e11_c = cache.add(e11); - - // Tests for simple insertion, verifying that the returned element - // has the same values as the original one - REPORTER_ASSERT(reporter, 1 == cache.size()); - REPORTER_ASSERT(reporter, NULL != cache.find(k11)); - REPORTER_ASSERT(reporter, e11_c == e11); - - Element& e11Collision_c = cache.add(e11Collision); - // Verifying that, in case of collision, the element alerady in the cache is not removed - REPORTER_ASSERT(reporter, e11Collision_c == e11); - REPORTER_ASSERT(reporter, 1 == cache.size()); - - Tint k42 = {42}; - Element e42(k42, 2); - cache.add(e42); - // Can we add more than one element? - REPORTER_ASSERT(reporter, NULL != cache.find(k11)); - REPORTER_ASSERT(reporter, NULL != cache.find(k42)); - REPORTER_ASSERT(reporter, 2 == cache.size()); - - cache.reset(); - // Does clear do its job? - REPORTER_ASSERT(reporter, 0 == cache.size()); - REPORTER_ASSERT(reporter, NULL == cache.find(k11)); - REPORTER_ASSERT(reporter, NULL == cache.find(k42)); -} |