blob: 2efd2f9324d8d74668cd2609d638f1b55a6692fb [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
11#include "GrBinHashKey.h"
12
13#include "Test.h"
14
robertphillips3d533ac2014-07-20 09:40:00 -070015template<typename KeyType> static void TestHash(skiatest::Reporter* reporter) {
tfarina@chromium.orgbbff2082014-01-31 21:48:52 +000016 const char* testStringA_ = "abcdABCD";
17 const char* testStringB_ = "abcdBBCD";
18 const uint32_t* testStringA = reinterpret_cast<const uint32_t*>(testStringA_);
19 const uint32_t* testStringB = reinterpret_cast<const uint32_t*>(testStringB_);
tfarina@chromium.orgbbff2082014-01-31 21:48:52 +000020
robertphillips3d533ac2014-07-20 09:40:00 -070021 KeyType keyA;
tfarina@chromium.orgbbff2082014-01-31 21:48:52 +000022 keyA.setKeyData(testStringA);
23 // test copy constructor and comparison
robertphillips3d533ac2014-07-20 09:40:00 -070024 KeyType keyA2(keyA);
tfarina@chromium.orgbbff2082014-01-31 21:48:52 +000025 REPORTER_ASSERT(reporter, keyA == keyA2);
26 REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash());
27 // test re-init
28 keyA2.setKeyData(testStringA);
29 REPORTER_ASSERT(reporter, keyA == keyA2);
30 REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash());
31 // test sorting
robertphillips3d533ac2014-07-20 09:40:00 -070032 KeyType keyB;
tfarina@chromium.orgbbff2082014-01-31 21:48:52 +000033 keyB.setKeyData(testStringB);
tfarina@chromium.orgbbff2082014-01-31 21:48:52 +000034 REPORTER_ASSERT(reporter, keyA.getHash() != keyB.getHash());
35}
36
robertphillips3d533ac2014-07-20 09:40:00 -070037
38DEF_TEST(GrBinHashKey, reporter) {
39 enum {
40 kDataLenUsedForKey = 8
41 };
42
43 TestHash<GrBinHashKey<kDataLenUsedForKey> >(reporter);
44 TestHash<GrMurmur3HashKey<kDataLenUsedForKey> >(reporter);
45}
46
tfarina@chromium.orgbbff2082014-01-31 21:48:52 +000047#endif