1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2015 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#include "include/core/SkRefCnt.h" 9cb93a386Sopenharmony_ci#include "include/core/SkString.h" 10cb93a386Sopenharmony_ci#include "include/private/SkChecksum.h" 11cb93a386Sopenharmony_ci#include "include/private/SkTHash.h" 12cb93a386Sopenharmony_ci#include "src/core/SkOpts.h" 13cb93a386Sopenharmony_ci#include "tests/Test.h" 14cb93a386Sopenharmony_ci 15cb93a386Sopenharmony_ci#include <tuple> 16cb93a386Sopenharmony_ci 17cb93a386Sopenharmony_ci// Tests use of const foreach(). map.count() is of course the better way to do this. 18cb93a386Sopenharmony_cistatic int count(const SkTHashMap<int, double>& map) { 19cb93a386Sopenharmony_ci int n = 0; 20cb93a386Sopenharmony_ci map.foreach([&n](int, double) { n++; }); 21cb93a386Sopenharmony_ci return n; 22cb93a386Sopenharmony_ci} 23cb93a386Sopenharmony_ci 24cb93a386Sopenharmony_ciDEF_TEST(HashMap, r) { 25cb93a386Sopenharmony_ci SkTHashMap<int, double> map; 26cb93a386Sopenharmony_ci 27cb93a386Sopenharmony_ci map.set(3, 4.0); 28cb93a386Sopenharmony_ci REPORTER_ASSERT(r, map.count() == 1); 29cb93a386Sopenharmony_ci 30cb93a386Sopenharmony_ci REPORTER_ASSERT(r, map.approxBytesUsed() > 0); 31cb93a386Sopenharmony_ci 32cb93a386Sopenharmony_ci double* found = map.find(3); 33cb93a386Sopenharmony_ci REPORTER_ASSERT(r, found); 34cb93a386Sopenharmony_ci REPORTER_ASSERT(r, *found == 4.0); 35cb93a386Sopenharmony_ci 36cb93a386Sopenharmony_ci map.foreach([](int key, double* d){ *d = -key; }); 37cb93a386Sopenharmony_ci REPORTER_ASSERT(r, count(map) == 1); 38cb93a386Sopenharmony_ci 39cb93a386Sopenharmony_ci found = map.find(3); 40cb93a386Sopenharmony_ci REPORTER_ASSERT(r, found); 41cb93a386Sopenharmony_ci REPORTER_ASSERT(r, *found == -3.0); 42cb93a386Sopenharmony_ci 43cb93a386Sopenharmony_ci REPORTER_ASSERT(r, !map.find(2)); 44cb93a386Sopenharmony_ci 45cb93a386Sopenharmony_ci const int N = 20; 46cb93a386Sopenharmony_ci 47cb93a386Sopenharmony_ci for (int i = 0; i < N; i++) { 48cb93a386Sopenharmony_ci map.set(i, 2.0*i); 49cb93a386Sopenharmony_ci } 50cb93a386Sopenharmony_ci 51cb93a386Sopenharmony_ci // Test walking the map with iterators, using preincrement (++iter). 52cb93a386Sopenharmony_ci for (SkTHashMap<int, double>::Iter iter = map.begin(); iter != map.end(); ++iter) { 53cb93a386Sopenharmony_ci REPORTER_ASSERT(r, iter->first * 2 == (*iter).second); 54cb93a386Sopenharmony_ci } 55cb93a386Sopenharmony_ci 56cb93a386Sopenharmony_ci // Test walking the map with range-based for. 57cb93a386Sopenharmony_ci for (auto& entry : map) { 58cb93a386Sopenharmony_ci REPORTER_ASSERT(r, entry.first * 2 == entry.second); 59cb93a386Sopenharmony_ci } 60cb93a386Sopenharmony_ci 61cb93a386Sopenharmony_ci // Ensure that iteration works equally well on a const map, using postincrement (iter++). 62cb93a386Sopenharmony_ci const auto& cmap = map; 63cb93a386Sopenharmony_ci for (SkTHashMap<int, double>::Iter iter = cmap.begin(); iter != cmap.end(); iter++) { 64cb93a386Sopenharmony_ci REPORTER_ASSERT(r, iter->first * 2 == (*iter).second); 65cb93a386Sopenharmony_ci } 66cb93a386Sopenharmony_ci 67cb93a386Sopenharmony_ci // Ensure that range-based for works equally well on a const map. 68cb93a386Sopenharmony_ci for (const auto& entry : cmap) { 69cb93a386Sopenharmony_ci REPORTER_ASSERT(r, entry.first * 2 == entry.second); 70cb93a386Sopenharmony_ci } 71cb93a386Sopenharmony_ci 72cb93a386Sopenharmony_ci // Ensure that structured bindings work. 73cb93a386Sopenharmony_ci for (const auto& [number, timesTwo] : cmap) { 74cb93a386Sopenharmony_ci REPORTER_ASSERT(r, number * 2 == timesTwo); 75cb93a386Sopenharmony_ci } 76cb93a386Sopenharmony_ci 77cb93a386Sopenharmony_ci SkTHashMap<int, double> clone = map; 78cb93a386Sopenharmony_ci 79cb93a386Sopenharmony_ci for (int i = 0; i < N; i++) { 80cb93a386Sopenharmony_ci found = map.find(i); 81cb93a386Sopenharmony_ci REPORTER_ASSERT(r, found); 82cb93a386Sopenharmony_ci REPORTER_ASSERT(r, *found == i*2.0); 83cb93a386Sopenharmony_ci 84cb93a386Sopenharmony_ci found = clone.find(i); 85cb93a386Sopenharmony_ci REPORTER_ASSERT(r, found); 86cb93a386Sopenharmony_ci REPORTER_ASSERT(r, *found == i*2.0); 87cb93a386Sopenharmony_ci } 88cb93a386Sopenharmony_ci for (int i = N; i < 2*N; i++) { 89cb93a386Sopenharmony_ci REPORTER_ASSERT(r, !map.find(i)); 90cb93a386Sopenharmony_ci REPORTER_ASSERT(r, !clone.find(i)); 91cb93a386Sopenharmony_ci } 92cb93a386Sopenharmony_ci 93cb93a386Sopenharmony_ci REPORTER_ASSERT(r, map.count() == N); 94cb93a386Sopenharmony_ci REPORTER_ASSERT(r, clone.count() == N); 95cb93a386Sopenharmony_ci 96cb93a386Sopenharmony_ci for (int i = 0; i < N/2; i++) { 97cb93a386Sopenharmony_ci map.remove(i); 98cb93a386Sopenharmony_ci } 99cb93a386Sopenharmony_ci for (int i = 0; i < N; i++) { 100cb93a386Sopenharmony_ci found = map.find(i); 101cb93a386Sopenharmony_ci REPORTER_ASSERT(r, (found == nullptr) == (i < N/2)); 102cb93a386Sopenharmony_ci 103cb93a386Sopenharmony_ci found = clone.find(i); 104cb93a386Sopenharmony_ci REPORTER_ASSERT(r, *found == i*2.0); 105cb93a386Sopenharmony_ci } 106cb93a386Sopenharmony_ci REPORTER_ASSERT(r, map.count() == N/2); 107cb93a386Sopenharmony_ci REPORTER_ASSERT(r, clone.count() == N); 108cb93a386Sopenharmony_ci 109cb93a386Sopenharmony_ci map.reset(); 110cb93a386Sopenharmony_ci REPORTER_ASSERT(r, map.count() == 0); 111cb93a386Sopenharmony_ci REPORTER_ASSERT(r, clone.count() == N); 112cb93a386Sopenharmony_ci 113cb93a386Sopenharmony_ci clone = map; 114cb93a386Sopenharmony_ci REPORTER_ASSERT(r, clone.count() == 0); 115cb93a386Sopenharmony_ci 116cb93a386Sopenharmony_ci { 117cb93a386Sopenharmony_ci // Test that we don't leave dangling values in empty slots. 118cb93a386Sopenharmony_ci SkTHashMap<int, sk_sp<SkRefCnt>> refMap; 119cb93a386Sopenharmony_ci auto ref = sk_make_sp<SkRefCnt>(); 120cb93a386Sopenharmony_ci REPORTER_ASSERT(r, ref->unique()); 121cb93a386Sopenharmony_ci 122cb93a386Sopenharmony_ci refMap.set(0, ref); 123cb93a386Sopenharmony_ci REPORTER_ASSERT(r, refMap.count() == 1); 124cb93a386Sopenharmony_ci REPORTER_ASSERT(r, !ref->unique()); 125cb93a386Sopenharmony_ci 126cb93a386Sopenharmony_ci refMap.remove(0); 127cb93a386Sopenharmony_ci REPORTER_ASSERT(r, refMap.count() == 0); 128cb93a386Sopenharmony_ci REPORTER_ASSERT(r, ref->unique()); 129cb93a386Sopenharmony_ci } 130cb93a386Sopenharmony_ci} 131cb93a386Sopenharmony_ci 132cb93a386Sopenharmony_ciDEF_TEST(HashSet, r) { 133cb93a386Sopenharmony_ci SkTHashSet<SkString> set; 134cb93a386Sopenharmony_ci 135cb93a386Sopenharmony_ci set.add(SkString("Hello")); 136cb93a386Sopenharmony_ci set.add(SkString("World")); 137cb93a386Sopenharmony_ci REPORTER_ASSERT(r, set.count() == 2); 138cb93a386Sopenharmony_ci REPORTER_ASSERT(r, set.contains(SkString("Hello"))); 139cb93a386Sopenharmony_ci REPORTER_ASSERT(r, set.contains(SkString("World"))); 140cb93a386Sopenharmony_ci REPORTER_ASSERT(r, !set.contains(SkString("Goodbye"))); 141cb93a386Sopenharmony_ci REPORTER_ASSERT(r, set.find(SkString("Hello"))); 142cb93a386Sopenharmony_ci REPORTER_ASSERT(r, *set.find(SkString("Hello")) == SkString("Hello")); 143cb93a386Sopenharmony_ci 144cb93a386Sopenharmony_ci // Test walking the set with iterators, using preincrement (++iter). 145cb93a386Sopenharmony_ci for (SkTHashSet<SkString>::Iter iter = set.begin(); iter != set.end(); ++iter) { 146cb93a386Sopenharmony_ci REPORTER_ASSERT(r, iter->equals("Hello") || (*iter).equals("World")); 147cb93a386Sopenharmony_ci } 148cb93a386Sopenharmony_ci 149cb93a386Sopenharmony_ci // Test walking the set with iterators, using postincrement (iter++). 150cb93a386Sopenharmony_ci for (SkTHashSet<SkString>::Iter iter = set.begin(); iter != set.end(); iter++) { 151cb93a386Sopenharmony_ci REPORTER_ASSERT(r, iter->equals("Hello") || (*iter).equals("World")); 152cb93a386Sopenharmony_ci } 153cb93a386Sopenharmony_ci 154cb93a386Sopenharmony_ci // Test walking the set with range-based for. 155cb93a386Sopenharmony_ci for (auto& entry : set) { 156cb93a386Sopenharmony_ci REPORTER_ASSERT(r, entry.equals("Hello") || entry.equals("World")); 157cb93a386Sopenharmony_ci } 158cb93a386Sopenharmony_ci 159cb93a386Sopenharmony_ci // Ensure that iteration works equally well on a const set. 160cb93a386Sopenharmony_ci const auto& cset = set; 161cb93a386Sopenharmony_ci for (SkTHashSet<SkString>::Iter iter = cset.begin(); iter != cset.end(); iter++) { 162cb93a386Sopenharmony_ci REPORTER_ASSERT(r, iter->equals("Hello") || (*iter).equals("World")); 163cb93a386Sopenharmony_ci } 164cb93a386Sopenharmony_ci 165cb93a386Sopenharmony_ci // Ensure that range-based for works equally well on a const set. 166cb93a386Sopenharmony_ci for (auto& entry : cset) { 167cb93a386Sopenharmony_ci REPORTER_ASSERT(r, entry.equals("Hello") || entry.equals("World")); 168cb93a386Sopenharmony_ci } 169cb93a386Sopenharmony_ci 170cb93a386Sopenharmony_ci SkTHashSet<SkString> clone = set; 171cb93a386Sopenharmony_ci REPORTER_ASSERT(r, clone.count() == 2); 172cb93a386Sopenharmony_ci REPORTER_ASSERT(r, clone.contains(SkString("Hello"))); 173cb93a386Sopenharmony_ci REPORTER_ASSERT(r, clone.contains(SkString("World"))); 174cb93a386Sopenharmony_ci REPORTER_ASSERT(r, !clone.contains(SkString("Goodbye"))); 175cb93a386Sopenharmony_ci REPORTER_ASSERT(r, clone.find(SkString("Hello"))); 176cb93a386Sopenharmony_ci REPORTER_ASSERT(r, *clone.find(SkString("Hello")) == SkString("Hello")); 177cb93a386Sopenharmony_ci 178cb93a386Sopenharmony_ci set.remove(SkString("Hello")); 179cb93a386Sopenharmony_ci REPORTER_ASSERT(r, !set.contains(SkString("Hello"))); 180cb93a386Sopenharmony_ci REPORTER_ASSERT(r, set.count() == 1); 181cb93a386Sopenharmony_ci REPORTER_ASSERT(r, clone.contains(SkString("Hello"))); 182cb93a386Sopenharmony_ci REPORTER_ASSERT(r, clone.count() == 2); 183cb93a386Sopenharmony_ci 184cb93a386Sopenharmony_ci set.reset(); 185cb93a386Sopenharmony_ci REPORTER_ASSERT(r, set.count() == 0); 186cb93a386Sopenharmony_ci 187cb93a386Sopenharmony_ci clone = set; 188cb93a386Sopenharmony_ci REPORTER_ASSERT(r, clone.count() == 0); 189cb93a386Sopenharmony_ci} 190cb93a386Sopenharmony_ci 191cb93a386Sopenharmony_cinamespace { 192cb93a386Sopenharmony_ci 193cb93a386Sopenharmony_ciclass CopyCounter { 194cb93a386Sopenharmony_cipublic: 195cb93a386Sopenharmony_ci CopyCounter() : fID(0), fCounter(nullptr) {} 196cb93a386Sopenharmony_ci 197cb93a386Sopenharmony_ci CopyCounter(uint32_t id, uint32_t* counter) : fID(id), fCounter(counter) {} 198cb93a386Sopenharmony_ci 199cb93a386Sopenharmony_ci CopyCounter(const CopyCounter& other) 200cb93a386Sopenharmony_ci : fID(other.fID) 201cb93a386Sopenharmony_ci , fCounter(other.fCounter) { 202cb93a386Sopenharmony_ci SkASSERT(fCounter); 203cb93a386Sopenharmony_ci *fCounter += 1; 204cb93a386Sopenharmony_ci } 205cb93a386Sopenharmony_ci 206cb93a386Sopenharmony_ci void operator=(const CopyCounter& other) { 207cb93a386Sopenharmony_ci fID = other.fID; 208cb93a386Sopenharmony_ci fCounter = other.fCounter; 209cb93a386Sopenharmony_ci *fCounter += 1; 210cb93a386Sopenharmony_ci } 211cb93a386Sopenharmony_ci 212cb93a386Sopenharmony_ci CopyCounter(CopyCounter&& other) { *this = std::move(other); } 213cb93a386Sopenharmony_ci void operator=(CopyCounter&& other) { 214cb93a386Sopenharmony_ci fID = other.fID; 215cb93a386Sopenharmony_ci fCounter = other.fCounter; 216cb93a386Sopenharmony_ci } 217cb93a386Sopenharmony_ci 218cb93a386Sopenharmony_ci 219cb93a386Sopenharmony_ci bool operator==(const CopyCounter& other) const { 220cb93a386Sopenharmony_ci return fID == other.fID; 221cb93a386Sopenharmony_ci } 222cb93a386Sopenharmony_ci 223cb93a386Sopenharmony_ciprivate: 224cb93a386Sopenharmony_ci uint32_t fID; 225cb93a386Sopenharmony_ci uint32_t* fCounter; 226cb93a386Sopenharmony_ci}; 227cb93a386Sopenharmony_ci 228cb93a386Sopenharmony_cistruct HashCopyCounter { 229cb93a386Sopenharmony_ci uint32_t operator()(const CopyCounter&) const { 230cb93a386Sopenharmony_ci return 0; // let them collide, what do we care? 231cb93a386Sopenharmony_ci } 232cb93a386Sopenharmony_ci}; 233cb93a386Sopenharmony_ci 234cb93a386Sopenharmony_ci} // namespace 235cb93a386Sopenharmony_ci 236cb93a386Sopenharmony_ciDEF_TEST(HashSetCopyCounter, r) { 237cb93a386Sopenharmony_ci SkTHashSet<CopyCounter, HashCopyCounter> set; 238cb93a386Sopenharmony_ci 239cb93a386Sopenharmony_ci uint32_t globalCounter = 0; 240cb93a386Sopenharmony_ci CopyCounter copyCounter1(1, &globalCounter); 241cb93a386Sopenharmony_ci CopyCounter copyCounter2(2, &globalCounter); 242cb93a386Sopenharmony_ci REPORTER_ASSERT(r, globalCounter == 0); 243cb93a386Sopenharmony_ci 244cb93a386Sopenharmony_ci set.add(copyCounter1); 245cb93a386Sopenharmony_ci REPORTER_ASSERT(r, globalCounter == 1); 246cb93a386Sopenharmony_ci REPORTER_ASSERT(r, set.contains(copyCounter1)); 247cb93a386Sopenharmony_ci REPORTER_ASSERT(r, globalCounter == 1); 248cb93a386Sopenharmony_ci set.add(copyCounter1); 249cb93a386Sopenharmony_ci // We allow copies for same-value adds for now. 250cb93a386Sopenharmony_ci REPORTER_ASSERT(r, globalCounter == 2); 251cb93a386Sopenharmony_ci 252cb93a386Sopenharmony_ci set.add(copyCounter2); 253cb93a386Sopenharmony_ci REPORTER_ASSERT(r, globalCounter == 3); 254cb93a386Sopenharmony_ci REPORTER_ASSERT(r, set.contains(copyCounter1)); 255cb93a386Sopenharmony_ci REPORTER_ASSERT(r, set.contains(copyCounter2)); 256cb93a386Sopenharmony_ci REPORTER_ASSERT(r, globalCounter == 3); 257cb93a386Sopenharmony_ci set.add(copyCounter1); 258cb93a386Sopenharmony_ci set.add(copyCounter2); 259cb93a386Sopenharmony_ci // We allow copies for same-value adds for now. 260cb93a386Sopenharmony_ci REPORTER_ASSERT(r, globalCounter == 5); 261cb93a386Sopenharmony_ci} 262cb93a386Sopenharmony_ci 263cb93a386Sopenharmony_ci 264cb93a386Sopenharmony_ciDEF_TEST(HashFindOrNull, r) { 265cb93a386Sopenharmony_ci struct Entry { 266cb93a386Sopenharmony_ci int key = 0; 267cb93a386Sopenharmony_ci int val = 0; 268cb93a386Sopenharmony_ci }; 269cb93a386Sopenharmony_ci 270cb93a386Sopenharmony_ci struct HashTraits { 271cb93a386Sopenharmony_ci static int GetKey(const Entry* e) { return e->key; } 272cb93a386Sopenharmony_ci static uint32_t Hash(int key) { return key; } 273cb93a386Sopenharmony_ci }; 274cb93a386Sopenharmony_ci 275cb93a386Sopenharmony_ci SkTHashTable<Entry*, int, HashTraits> table; 276cb93a386Sopenharmony_ci 277cb93a386Sopenharmony_ci REPORTER_ASSERT(r, nullptr == table.findOrNull(7)); 278cb93a386Sopenharmony_ci 279cb93a386Sopenharmony_ci Entry seven = { 7, 24 }; 280cb93a386Sopenharmony_ci table.set(&seven); 281cb93a386Sopenharmony_ci 282cb93a386Sopenharmony_ci REPORTER_ASSERT(r, &seven == table.findOrNull(7)); 283cb93a386Sopenharmony_ci} 284cb93a386Sopenharmony_ci 285cb93a386Sopenharmony_ciDEF_TEST(HashTableGrowsAndShrinks, r) { 286cb93a386Sopenharmony_ci SkTHashSet<int> s; 287cb93a386Sopenharmony_ci auto check_count_cap = [&](int count, int cap) { 288cb93a386Sopenharmony_ci REPORTER_ASSERT(r, s.count() == count); 289cb93a386Sopenharmony_ci REPORTER_ASSERT(r, s.approxBytesUsed() == (sizeof(int) + sizeof(uint32_t)) * cap); 290cb93a386Sopenharmony_ci }; 291cb93a386Sopenharmony_ci 292cb93a386Sopenharmony_ci // Add and remove some elements to test basic growth and shrink patterns. 293cb93a386Sopenharmony_ci check_count_cap(0,0); 294cb93a386Sopenharmony_ci s.add(1); check_count_cap(1,4); 295cb93a386Sopenharmony_ci s.add(2); check_count_cap(2,4); 296cb93a386Sopenharmony_ci s.add(3); check_count_cap(3,4); 297cb93a386Sopenharmony_ci s.add(4); check_count_cap(4,8); 298cb93a386Sopenharmony_ci 299cb93a386Sopenharmony_ci s.remove(4); check_count_cap(3,8); 300cb93a386Sopenharmony_ci s.remove(3); check_count_cap(2,4); 301cb93a386Sopenharmony_ci s.remove(2); check_count_cap(1,4); 302cb93a386Sopenharmony_ci s.remove(1); check_count_cap(0,4); 303cb93a386Sopenharmony_ci 304cb93a386Sopenharmony_ci s.add(1); check_count_cap(1,4); 305cb93a386Sopenharmony_ci s.add(2); check_count_cap(2,4); 306cb93a386Sopenharmony_ci s.add(3); check_count_cap(3,4); 307cb93a386Sopenharmony_ci s.add(4); check_count_cap(4,8); 308cb93a386Sopenharmony_ci 309cb93a386Sopenharmony_ci // Add and remove single elements repeatedly to test hysteresis 310cb93a386Sopenharmony_ci // avoids reallocating these small tables all the time. 311cb93a386Sopenharmony_ci for (int i = 0; i < 10; i++) { 312cb93a386Sopenharmony_ci s. add(5); check_count_cap(5,8); 313cb93a386Sopenharmony_ci s.remove(5); check_count_cap(4,8); 314cb93a386Sopenharmony_ci } 315cb93a386Sopenharmony_ci 316cb93a386Sopenharmony_ci s.remove(4); check_count_cap(3,8); 317cb93a386Sopenharmony_ci for (int i = 0; i < 10; i++) { 318cb93a386Sopenharmony_ci s. add(4); check_count_cap(4,8); 319cb93a386Sopenharmony_ci s.remove(4); check_count_cap(3,8); 320cb93a386Sopenharmony_ci } 321cb93a386Sopenharmony_ci 322cb93a386Sopenharmony_ci s.remove(3); check_count_cap(2,4); 323cb93a386Sopenharmony_ci for (int i = 0; i < 10; i++) { 324cb93a386Sopenharmony_ci s. add(4); check_count_cap(3,4); 325cb93a386Sopenharmony_ci s.remove(4); check_count_cap(2,4); 326cb93a386Sopenharmony_ci } 327cb93a386Sopenharmony_ci 328cb93a386Sopenharmony_ci s.remove(2); check_count_cap(1,4); 329cb93a386Sopenharmony_ci for (int i = 0; i < 10; i++) { 330cb93a386Sopenharmony_ci s. add(2); check_count_cap(2,4); 331cb93a386Sopenharmony_ci s.remove(2); check_count_cap(1,4); 332cb93a386Sopenharmony_ci } 333cb93a386Sopenharmony_ci} 334cb93a386Sopenharmony_ci 335cb93a386Sopenharmony_ciDEF_TEST(HashCollision, r) { 336cb93a386Sopenharmony_ci 337cb93a386Sopenharmony_ci // Two different sets of data. Same hash. 338cb93a386Sopenharmony_ci uint8_t data1[] = { 339cb93a386Sopenharmony_ci 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 40, 0, 0, 0, 2, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 63, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40, 0, 0, 0, 3, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 7, 0, 0, 0, 5, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 28, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, 6, 0, 0, 0, 13, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 6, 0, 0, 0, 13, 0, 0, 0, 14, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, 8, 0, 0, 0, 17, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 8, 0, 0, 0, 17, 0, 0, 0, 18, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 44, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 48, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 52, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 128, 63, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 27, 0, 0, 0, 16, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, 16, 0, 0, 0, 21, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, 28, 0, 0, 0, 21, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 16, 0, 0, 0, 21, 0, 0, 0, 22, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 28, 0, 0, 0, 21, 0, 0, 0, 22, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 0, 0, 0, 31, 0, 0, 0, 27, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 0, 0, 0, 32, 0, 0, 0, 27, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, 33, 0, 0, 0, 23, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 33, 0, 0, 0, 23, 0, 0, 0, 24, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 340cb93a386Sopenharmony_ci }; 341cb93a386Sopenharmony_ci uint8_t data2[] = { 342cb93a386Sopenharmony_ci 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 40, 0, 0, 0, 2, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 63, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40, 0, 0, 0, 3, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 7, 0, 0, 0, 5, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 28, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, 6, 0, 0, 0, 13, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 6, 0, 0, 0, 13, 0, 0, 0, 14, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, 8, 0, 0, 0, 17, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 8, 0, 0, 0, 17, 0, 0, 0, 18, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 44, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 48, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 52, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 128, 63, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 27, 0, 0, 0, 16, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, 16, 0, 0, 0, 21, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, 28, 0, 0, 0, 21, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 16, 0, 0, 0, 21, 0, 0, 0, 22, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 28, 0, 0, 0, 21, 0, 0, 0, 22, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0, 0, 31, 0, 0, 0, 27, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0, 0, 32, 0, 0, 0, 27, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, 33, 0, 0, 0, 23, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 33, 0, 0, 0, 23, 0, 0, 0, 24, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 343cb93a386Sopenharmony_ci }; 344cb93a386Sopenharmony_ci 345cb93a386Sopenharmony_ci REPORTER_ASSERT(r, sizeof(data1) == sizeof(data2)); 346cb93a386Sopenharmony_ci REPORTER_ASSERT(r, memcmp(data1, data2, sizeof(data1)) != 0); 347cb93a386Sopenharmony_ci 348cb93a386Sopenharmony_ci uint32_t hash1 = SkOpts::hash(data1, sizeof(data1), 0); 349cb93a386Sopenharmony_ci uint32_t hash2 = SkOpts::hash(data2, sizeof(data2), 0); 350cb93a386Sopenharmony_ci REPORTER_ASSERT(r, hash1 != hash2); 351cb93a386Sopenharmony_ci} 352