| OLD | NEW |
| 1 /* |
| 2 * Copyright 2015 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 1 #include "SkChecksum.h" | 8 #include "SkChecksum.h" |
| 2 #include "SkString.h" | 9 #include "SkString.h" |
| 3 #include "SkTHash.h" | 10 #include "SkTHash.h" |
| 4 #include "Test.h" | 11 #include "Test.h" |
| 5 | 12 |
| 6 // Tests use of const foreach(). map.count() is of course the better way to do
this. | 13 // Tests use of const foreach(). map.count() is of course the better way to do
this. |
| 7 static int count(const SkTHashMap<int, double>& map) { | 14 static int count(const SkTHashMap<int, double>& map) { |
| 8 int n = 0; | 15 int n = 0; |
| 9 map.foreach([&n](int, double) { n++; }); | 16 map.foreach([&n](int, double) { n++; }); |
| 10 return n; | 17 return n; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 61 |
| 55 set.add(SkString("Hello")); | 62 set.add(SkString("Hello")); |
| 56 set.add(SkString("World")); | 63 set.add(SkString("World")); |
| 57 | 64 |
| 58 REPORTER_ASSERT(r, set.count() == 2); | 65 REPORTER_ASSERT(r, set.count() == 2); |
| 59 | 66 |
| 60 REPORTER_ASSERT(r, set.contains(SkString("Hello"))); | 67 REPORTER_ASSERT(r, set.contains(SkString("Hello"))); |
| 61 REPORTER_ASSERT(r, set.contains(SkString("World"))); | 68 REPORTER_ASSERT(r, set.contains(SkString("World"))); |
| 62 REPORTER_ASSERT(r, !set.contains(SkString("Goodbye"))); | 69 REPORTER_ASSERT(r, !set.contains(SkString("Goodbye"))); |
| 63 | 70 |
| 71 REPORTER_ASSERT(r, set.find(SkString("Hello"))); |
| 72 REPORTER_ASSERT(r, *set.find(SkString("Hello")) == SkString("Hello")); |
| 73 |
| 64 set.reset(); | 74 set.reset(); |
| 65 REPORTER_ASSERT(r, set.count() == 0); | 75 REPORTER_ASSERT(r, set.count() == 0); |
| 66 } | 76 } |
| 67 | 77 |
| 68 namespace { | 78 namespace { |
| 69 | 79 |
| 70 class CopyCounter { | 80 class CopyCounter { |
| 71 public: | 81 public: |
| 72 CopyCounter() : fID(0), fCounter(NULL) {} | 82 CopyCounter() : fID(0), fCounter(NULL) {} |
| 73 | 83 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 set.add(copyCounter2); | 130 set.add(copyCounter2); |
| 121 REPORTER_ASSERT(r, globalCounter == 3); | 131 REPORTER_ASSERT(r, globalCounter == 3); |
| 122 REPORTER_ASSERT(r, set.contains(copyCounter1)); | 132 REPORTER_ASSERT(r, set.contains(copyCounter1)); |
| 123 REPORTER_ASSERT(r, set.contains(copyCounter2)); | 133 REPORTER_ASSERT(r, set.contains(copyCounter2)); |
| 124 REPORTER_ASSERT(r, globalCounter == 3); | 134 REPORTER_ASSERT(r, globalCounter == 3); |
| 125 set.add(copyCounter1); | 135 set.add(copyCounter1); |
| 126 set.add(copyCounter2); | 136 set.add(copyCounter2); |
| 127 // We allow copies for same-value adds for now. | 137 // We allow copies for same-value adds for now. |
| 128 REPORTER_ASSERT(r, globalCounter == 5); | 138 REPORTER_ASSERT(r, globalCounter == 5); |
| 129 } | 139 } |
| OLD | NEW |