blob: 605fd9f29a429d2e5f94a37c4fce03af2a57a369 [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
robertphillips3d533ac2014-07-20 09:40:00 -070016template<typename KeyType> static void TestHash(skiatest::Reporter* reporter) {
tfarina@chromium.orgbbff2082014-01-31 21:48:52 +000017 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.orgbbff2082014-01-31 21:48:52 +000021
robertphillips3d533ac2014-07-20 09:40:00 -070022 KeyType keyA;
tfarina@chromium.orgbbff2082014-01-31 21:48:52 +000023 keyA.setKeyData(testStringA);
24 // test copy constructor and comparison
robertphillips3d533ac2014-07-20 09:40:00 -070025 KeyType keyA2(keyA);
tfarina@chromium.orgbbff2082014-01-31 21:48:52 +000026 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
robertphillips3d533ac2014-07-20 09:40:00 -070033 KeyType keyB;
tfarina@chromium.orgbbff2082014-01-31 21:48:52 +000034 keyB.setKeyData(testStringB);
tfarina@chromium.orgbbff2082014-01-31 21:48:52 +000035 REPORTER_ASSERT(reporter, keyA.getHash() != keyB.getHash());
36}
37
robertphillips3d533ac2014-07-20 09:40:00 -070038
39DEF_TEST(GrBinHashKey, reporter) {
40 enum {
41 kDataLenUsedForKey = 8
42 };
43
44 TestHash<GrBinHashKey<kDataLenUsedForKey> >(reporter);
45 TestHash<GrMurmur3HashKey<kDataLenUsedForKey> >(reporter);
46}
47
tfarina@chromium.orgbbff2082014-01-31 21:48:52 +000048#endif