blob: 175719d3cd238d119d6306e356aedb2ea9361bd7 [file] [log] [blame]
tfarina@chromium.orgbbff2082014-01-31 21:48:52 +00001/*
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
bsalomon744998e2014-08-28 09:54:34 -070011#include "GrMurmur3HashKey.h"
tfarina@chromium.orgbbff2082014-01-31 21:48:52 +000012#include "GrBinHashKey.h"
13
14#include "Test.h"
15
mtklein19996ed2014-11-21 06:48:43 -080016struct AlignedKey {
17 uint32_t align;
18 char key[8];
19};
20
robertphillips3d533ac2014-07-20 09:40:00 -070021template<typename KeyType> static void TestHash(skiatest::Reporter* reporter) {
mtklein19996ed2014-11-21 06:48:43 -080022 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.orgbbff2082014-01-31 21:48:52 +000027
robertphillips3d533ac2014-07-20 09:40:00 -070028 KeyType keyA;
tfarina@chromium.orgbbff2082014-01-31 21:48:52 +000029 keyA.setKeyData(testStringA);
30 // test copy constructor and comparison
robertphillips3d533ac2014-07-20 09:40:00 -070031 KeyType keyA2(keyA);
tfarina@chromium.orgbbff2082014-01-31 21:48:52 +000032 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
robertphillips3d533ac2014-07-20 09:40:00 -070039 KeyType keyB;
tfarina@chromium.orgbbff2082014-01-31 21:48:52 +000040 keyB.setKeyData(testStringB);
tfarina@chromium.orgbbff2082014-01-31 21:48:52 +000041 REPORTER_ASSERT(reporter, keyA.getHash() != keyB.getHash());
42}
43
robertphillips3d533ac2014-07-20 09:40:00 -070044
45DEF_TEST(GrBinHashKey, reporter) {
46 enum {
47 kDataLenUsedForKey = 8
48 };
49
50 TestHash<GrBinHashKey<kDataLenUsedForKey> >(reporter);
51 TestHash<GrMurmur3HashKey<kDataLenUsedForKey> >(reporter);
52}
53
tfarina@chromium.orgbbff2082014-01-31 21:48:52 +000054#endif