OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 // This is a GPU-backend specific test | 8 // This is a GPU-backend specific test |
9 #if SK_SUPPORT_GPU | 9 #if SK_SUPPORT_GPU |
10 | 10 |
11 #include "GrMurmur3HashKey.h" | 11 #include "GrMurmur3HashKey.h" |
12 #include "GrBinHashKey.h" | 12 #include "GrBinHashKey.h" |
13 | 13 |
14 #include "Test.h" | 14 #include "Test.h" |
15 | 15 |
| 16 struct AlignedKey { |
| 17 uint32_t align; |
| 18 char key[8]; |
| 19 }; |
| 20 |
16 template<typename KeyType> static void TestHash(skiatest::Reporter* reporter) { | 21 template<typename KeyType> static void TestHash(skiatest::Reporter* reporter) { |
17 const char* testStringA_ = "abcdABCD"; | 22 AlignedKey a, b; |
18 const char* testStringB_ = "abcdBBCD"; | 23 memcpy(&a.key, "abcdABCD", 8); |
19 const uint32_t* testStringA = reinterpret_cast<const uint32_t*>(testStringA_
); | 24 memcpy(&b.key, "abcdBBCD", 8); |
20 const uint32_t* testStringB = reinterpret_cast<const uint32_t*>(testStringB_
); | 25 const uint32_t* testStringA = reinterpret_cast<const uint32_t*>(&a.key); |
| 26 const uint32_t* testStringB = reinterpret_cast<const uint32_t*>(&b.key); |
21 | 27 |
22 KeyType keyA; | 28 KeyType keyA; |
23 keyA.setKeyData(testStringA); | 29 keyA.setKeyData(testStringA); |
24 // test copy constructor and comparison | 30 // test copy constructor and comparison |
25 KeyType keyA2(keyA); | 31 KeyType keyA2(keyA); |
26 REPORTER_ASSERT(reporter, keyA == keyA2); | 32 REPORTER_ASSERT(reporter, keyA == keyA2); |
27 REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash()); | 33 REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash()); |
28 // test re-init | 34 // test re-init |
29 keyA2.setKeyData(testStringA); | 35 keyA2.setKeyData(testStringA); |
30 REPORTER_ASSERT(reporter, keyA == keyA2); | 36 REPORTER_ASSERT(reporter, keyA == keyA2); |
31 REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash()); | 37 REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash()); |
32 // test sorting | 38 // test sorting |
33 KeyType keyB; | 39 KeyType keyB; |
34 keyB.setKeyData(testStringB); | 40 keyB.setKeyData(testStringB); |
35 REPORTER_ASSERT(reporter, keyA.getHash() != keyB.getHash()); | 41 REPORTER_ASSERT(reporter, keyA.getHash() != keyB.getHash()); |
36 } | 42 } |
37 | 43 |
38 | 44 |
39 DEF_TEST(GrBinHashKey, reporter) { | 45 DEF_TEST(GrBinHashKey, reporter) { |
40 enum { | 46 enum { |
41 kDataLenUsedForKey = 8 | 47 kDataLenUsedForKey = 8 |
42 }; | 48 }; |
43 | 49 |
44 TestHash<GrBinHashKey<kDataLenUsedForKey> >(reporter); | 50 TestHash<GrBinHashKey<kDataLenUsedForKey> >(reporter); |
45 TestHash<GrMurmur3HashKey<kDataLenUsedForKey> >(reporter); | 51 TestHash<GrMurmur3HashKey<kDataLenUsedForKey> >(reporter); |
46 } | 52 } |
47 | 53 |
48 #endif | 54 #endif |
OLD | NEW |