tfarina@chromium.org | bbff208 | 2014-01-31 21:48:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2010 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 | |
| 8 | // This is a GPU-backend specific test |
| 9 | #if SK_SUPPORT_GPU |
| 10 | |
bsalomon | 744998e | 2014-08-28 09:54:34 -0700 | [diff] [blame] | 11 | #include "GrMurmur3HashKey.h" |
tfarina@chromium.org | bbff208 | 2014-01-31 21:48:52 +0000 | [diff] [blame] | 12 | #include "GrBinHashKey.h" |
| 13 | |
| 14 | #include "Test.h" |
| 15 | |
mtklein | 19996ed | 2014-11-21 06:48:43 -0800 | [diff] [blame] | 16 | struct AlignedKey { |
| 17 | uint32_t align; |
| 18 | char key[8]; |
| 19 | }; |
| 20 | |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 21 | template<typename KeyType> static void TestHash(skiatest::Reporter* reporter) { |
mtklein | 19996ed | 2014-11-21 06:48:43 -0800 | [diff] [blame] | 22 | AlignedKey a, b; |
| 23 | memcpy(&a.key, "abcdABCD", 8); |
| 24 | memcpy(&b.key, "abcdBBCD", 8); |
| 25 | const uint32_t* testStringA = reinterpret_cast<const uint32_t*>(&a.key); |
| 26 | const uint32_t* testStringB = reinterpret_cast<const uint32_t*>(&b.key); |
tfarina@chromium.org | bbff208 | 2014-01-31 21:48:52 +0000 | [diff] [blame] | 27 | |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 28 | KeyType keyA; |
tfarina@chromium.org | bbff208 | 2014-01-31 21:48:52 +0000 | [diff] [blame] | 29 | keyA.setKeyData(testStringA); |
| 30 | // test copy constructor and comparison |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 31 | KeyType keyA2(keyA); |
tfarina@chromium.org | bbff208 | 2014-01-31 21:48:52 +0000 | [diff] [blame] | 32 | REPORTER_ASSERT(reporter, keyA == keyA2); |
| 33 | REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash()); |
| 34 | // test re-init |
| 35 | keyA2.setKeyData(testStringA); |
| 36 | REPORTER_ASSERT(reporter, keyA == keyA2); |
| 37 | REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash()); |
| 38 | // test sorting |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 39 | KeyType keyB; |
tfarina@chromium.org | bbff208 | 2014-01-31 21:48:52 +0000 | [diff] [blame] | 40 | keyB.setKeyData(testStringB); |
tfarina@chromium.org | bbff208 | 2014-01-31 21:48:52 +0000 | [diff] [blame] | 41 | REPORTER_ASSERT(reporter, keyA.getHash() != keyB.getHash()); |
| 42 | } |
| 43 | |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 44 | |
| 45 | DEF_TEST(GrBinHashKey, reporter) { |
| 46 | enum { |
| 47 | kDataLenUsedForKey = 8 |
| 48 | }; |
| 49 | |
| 50 | TestHash<GrBinHashKey<kDataLenUsedForKey> >(reporter); |
| 51 | TestHash<GrMurmur3HashKey<kDataLenUsedForKey> >(reporter); |
| 52 | } |
| 53 | |
tfarina@chromium.org | bbff208 | 2014-01-31 21:48:52 +0000 | [diff] [blame] | 54 | #endif |