Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / tests / GrBinHashKeyTest.cpp
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
11 #include "GrMurmur3HashKey.h"
12 #include "GrBinHashKey.h"
13
14 #include "Test.h"
15
16 template<typename KeyType> static void TestHash(skiatest::Reporter* reporter) {
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_);
21
22     KeyType keyA;
23     keyA.setKeyData(testStringA);
24     // test copy constructor and comparison
25     KeyType keyA2(keyA);
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
33     KeyType keyB;
34     keyB.setKeyData(testStringB);
35     REPORTER_ASSERT(reporter, keyA.getHash() != keyB.getHash());
36 }
37
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
48 #endif