Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: tests/HashTest.cpp

Issue 1405053002: SkTHash: hash from fnptr to functor type (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/ChecksumTest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 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 "SkChecksum.h" 8 #include "SkChecksum.h"
9 #include "SkString.h" 9 #include "SkString.h"
10 #include "SkTHash.h" 10 #include "SkTHash.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 bool operator==(const CopyCounter& other) const { 114 bool operator==(const CopyCounter& other) const {
115 return fID == other.fID; 115 return fID == other.fID;
116 } 116 }
117 117
118 private: 118 private:
119 uint32_t fID; 119 uint32_t fID;
120 uint32_t* fCounter; 120 uint32_t* fCounter;
121 }; 121 };
122 122
123 uint32_t hash_copy_counter(const CopyCounter&) { 123 struct HashCopyCounter {
124 return 0; // let them collide, what do we care? 124 uint32_t operator()(const CopyCounter&) const {
125 } 125 return 0; // let them collide, what do we care?
126 }
127 };
126 128
127 } 129 }
128 130
129 DEF_TEST(HashSetCopyCounter, r) { 131 DEF_TEST(HashSetCopyCounter, r) {
130 SkTHashSet<CopyCounter, hash_copy_counter> set; 132 SkTHashSet<CopyCounter, HashCopyCounter> set;
131 133
132 uint32_t globalCounter = 0; 134 uint32_t globalCounter = 0;
133 CopyCounter copyCounter1(1, &globalCounter); 135 CopyCounter copyCounter1(1, &globalCounter);
134 CopyCounter copyCounter2(2, &globalCounter); 136 CopyCounter copyCounter2(2, &globalCounter);
135 REPORTER_ASSERT(r, globalCounter == 0); 137 REPORTER_ASSERT(r, globalCounter == 0);
136 138
137 set.add(copyCounter1); 139 set.add(copyCounter1);
138 REPORTER_ASSERT(r, globalCounter == 1); 140 REPORTER_ASSERT(r, globalCounter == 1);
139 REPORTER_ASSERT(r, set.contains(copyCounter1)); 141 REPORTER_ASSERT(r, set.contains(copyCounter1));
140 REPORTER_ASSERT(r, globalCounter == 1); 142 REPORTER_ASSERT(r, globalCounter == 1);
141 set.add(copyCounter1); 143 set.add(copyCounter1);
142 // We allow copies for same-value adds for now. 144 // We allow copies for same-value adds for now.
143 REPORTER_ASSERT(r, globalCounter == 2); 145 REPORTER_ASSERT(r, globalCounter == 2);
144 146
145 set.add(copyCounter2); 147 set.add(copyCounter2);
146 REPORTER_ASSERT(r, globalCounter == 3); 148 REPORTER_ASSERT(r, globalCounter == 3);
147 REPORTER_ASSERT(r, set.contains(copyCounter1)); 149 REPORTER_ASSERT(r, set.contains(copyCounter1));
148 REPORTER_ASSERT(r, set.contains(copyCounter2)); 150 REPORTER_ASSERT(r, set.contains(copyCounter2));
149 REPORTER_ASSERT(r, globalCounter == 3); 151 REPORTER_ASSERT(r, globalCounter == 3);
150 set.add(copyCounter1); 152 set.add(copyCounter1);
151 set.add(copyCounter2); 153 set.add(copyCounter2);
152 // We allow copies for same-value adds for now. 154 // We allow copies for same-value adds for now.
153 REPORTER_ASSERT(r, globalCounter == 5); 155 REPORTER_ASSERT(r, globalCounter == 5);
154 } 156 }
OLDNEW
« no previous file with comments | « tests/ChecksumTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698