| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "Test.h" | 8 #include "Test.h" |
| 9 #include "SkTHashCache.h" | 9 #include "SkTHashCache.h" |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 Tint key; | 40 Tint key; |
| 41 int value; | 41 int value; |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 typedef SkTHashCache<Element, Tint> CacheType; | 44 typedef SkTHashCache<Element, Tint> CacheType; |
| 45 | 45 |
| 46 DEF_TEST(THashCache, reporter) { | 46 DEF_TEST(THashCache, reporter) { |
| 47 Tint k11 = {11}; | 47 Tint k11 = {11}; |
| 48 Element e11(k11, 22); | 48 Element e11(k11, 22); |
| 49 | 49 |
| 50 e11.value = e11.value; | |
| 51 Element e11Collision(k11, 0); | 50 Element e11Collision(k11, 0); |
| 52 // Element e42(4, 2); | 51 // Element e42(4, 2); |
| 53 | 52 |
| 54 //Some tests for the class Element | 53 //Some tests for the class Element |
| 55 REPORTER_ASSERT(reporter, Element::GetKey(e11) == k11); | 54 REPORTER_ASSERT(reporter, Element::GetKey(e11) == k11); |
| 56 REPORTER_ASSERT(reporter, Element::Hash(k11) == 11); | 55 REPORTER_ASSERT(reporter, Element::Hash(k11) == 11); |
| 57 | 56 |
| 58 CacheType cache; | 57 CacheType cache; |
| 59 | 58 |
| 60 // Is the cahce correctly initialized ? | 59 // Is the cahce correctly initialized ? |
| 61 REPORTER_ASSERT(reporter, 0 == cache.size()); | 60 REPORTER_ASSERT(reporter, 0 == cache.size()); |
| 62 REPORTER_ASSERT(reporter, NULL == cache.find(k11)); | 61 REPORTER_ASSERT(reporter, NULL == cache.find(k11)); |
| 63 | 62 |
| 64 Element& e11_c = cache.add(e11); | 63 Element& e11_c = cache.add(e11); |
| 65 e11_c.value = e11_c.value; | |
| 66 | 64 |
| 67 // Tests for simple insertion, verifying that the returned element | 65 // Tests for simple insertion, verifying that the returned element |
| 68 // has the same values as the original one | 66 // has the same values as the original one |
| 69 REPORTER_ASSERT(reporter, 1 == cache.size()); | 67 REPORTER_ASSERT(reporter, 1 == cache.size()); |
| 70 REPORTER_ASSERT(reporter, NULL != cache.find(k11)); | 68 REPORTER_ASSERT(reporter, NULL != cache.find(k11)); |
| 71 REPORTER_ASSERT(reporter, e11_c == e11); | 69 REPORTER_ASSERT(reporter, e11_c == e11); |
| 72 | 70 |
| 73 Element& e11Collision_c = cache.add(e11Collision); | 71 Element& e11Collision_c = cache.add(e11Collision); |
| 74 // Verifying that, in case of collision, the element alerady in the cache is
not removed | 72 // Verifying that, in case of collision, the element alerady in the cache is
not removed |
| 75 REPORTER_ASSERT(reporter, e11Collision_c == e11); | 73 REPORTER_ASSERT(reporter, e11Collision_c == e11); |
| 76 REPORTER_ASSERT(reporter, 1 == cache.size()); | 74 REPORTER_ASSERT(reporter, 1 == cache.size()); |
| 77 | 75 |
| 78 Tint k42 = {42}; | 76 Tint k42 = {42}; |
| 79 Element e42(k42, 2); | 77 Element e42(k42, 2); |
| 80 cache.add(e42); | 78 cache.add(e42); |
| 81 // Can we add more than one element? | 79 // Can we add more than one element? |
| 82 REPORTER_ASSERT(reporter, NULL != cache.find(k11)); | 80 REPORTER_ASSERT(reporter, NULL != cache.find(k11)); |
| 83 REPORTER_ASSERT(reporter, NULL != cache.find(k42)); | 81 REPORTER_ASSERT(reporter, NULL != cache.find(k42)); |
| 84 REPORTER_ASSERT(reporter, 2 == cache.size()); | 82 REPORTER_ASSERT(reporter, 2 == cache.size()); |
| 85 | 83 |
| 86 cache.reset(); | 84 cache.reset(); |
| 87 // Does clear do its job? | 85 // Does clear do its job? |
| 88 REPORTER_ASSERT(reporter, 0 == cache.size()); | 86 REPORTER_ASSERT(reporter, 0 == cache.size()); |
| 89 REPORTER_ASSERT(reporter, NULL == cache.find(k11)); | 87 REPORTER_ASSERT(reporter, NULL == cache.find(k11)); |
| 90 REPORTER_ASSERT(reporter, NULL == cache.find(k42)); | 88 REPORTER_ASSERT(reporter, NULL == cache.find(k42)); |
| 91 } | 89 } |
| OLD | NEW |