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 | |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 16 | template<typename KeyType> static void TestHash(skiatest::Reporter* reporter) { |
tfarina@chromium.org | bbff208 | 2014-01-31 21:48:52 +0000 | [diff] [blame] | 17 | const char* testStringA_ = "abcdABCD"; |
| 18 | const char* testStringB_ = "abcdBBCD"; |
| 19 | const uint32_t* testStringA = reinterpret_cast<const uint32_t*>(testStringA_); |
| 20 | const uint32_t* testStringB = reinterpret_cast<const uint32_t*>(testStringB_); |
tfarina@chromium.org | bbff208 | 2014-01-31 21:48:52 +0000 | [diff] [blame] | 21 | |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 22 | KeyType keyA; |
tfarina@chromium.org | bbff208 | 2014-01-31 21:48:52 +0000 | [diff] [blame] | 23 | keyA.setKeyData(testStringA); |
| 24 | // test copy constructor and comparison |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 25 | KeyType keyA2(keyA); |
tfarina@chromium.org | bbff208 | 2014-01-31 21:48:52 +0000 | [diff] [blame] | 26 | REPORTER_ASSERT(reporter, keyA == keyA2); |
| 27 | REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash()); |
| 28 | // test re-init |
| 29 | keyA2.setKeyData(testStringA); |
| 30 | REPORTER_ASSERT(reporter, keyA == keyA2); |
| 31 | REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash()); |
| 32 | // test sorting |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 33 | KeyType keyB; |
tfarina@chromium.org | bbff208 | 2014-01-31 21:48:52 +0000 | [diff] [blame] | 34 | keyB.setKeyData(testStringB); |
tfarina@chromium.org | bbff208 | 2014-01-31 21:48:52 +0000 | [diff] [blame] | 35 | REPORTER_ASSERT(reporter, keyA.getHash() != keyB.getHash()); |
| 36 | } |
| 37 | |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 38 | |
| 39 | DEF_TEST(GrBinHashKey, reporter) { |
| 40 | enum { |
| 41 | kDataLenUsedForKey = 8 |
| 42 | }; |
| 43 | |
| 44 | TestHash<GrBinHashKey<kDataLenUsedForKey> >(reporter); |
| 45 | TestHash<GrMurmur3HashKey<kDataLenUsedForKey> >(reporter); |
| 46 | } |
| 47 | |
tfarina@chromium.org | bbff208 | 2014-01-31 21:48:52 +0000 | [diff] [blame] | 48 | #endif |