OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
4 * | 3 * |
5 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
8 #include "Test.h" | |
9 | 7 |
10 // This is a GPU-backend specific test | 8 // This is a GPU-backend specific test |
11 #if SK_SUPPORT_GPU | 9 #if SK_SUPPORT_GPU |
| 10 |
12 #include "GrBinHashKey.h" | 11 #include "GrBinHashKey.h" |
13 #include "GrDrawTarget.h" | |
14 #include "GrRedBlackTree.h" | |
15 #include "SkMatrix.h" | |
16 | 12 |
17 // If we aren't inheriting these as #defines from elsewhere, | 13 #include "Test.h" |
18 // clang demands they be declared before we #include the template | |
19 // that relies on them. | |
20 static bool LT(const int& elem, int value) { | |
21 return elem < value; | |
22 } | |
23 static bool EQ(const int& elem, int value) { | |
24 return elem == value; | |
25 } | |
26 #include "GrTBSearch.h" | |
27 | 14 |
28 | 15 DEF_TEST(GrBinHashKeyTest, reporter) { |
29 DEF_TEST(GrUnitTests_bsearch, reporter) { | |
30 const int array[] = { | |
31 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99 | |
32 }; | |
33 | |
34 for (int n = 0; n < static_cast<int>(GR_ARRAY_COUNT(array)); ++n) { | |
35 for (int i = 0; i < n; i++) { | |
36 int index = GrTBSearch<int, int>(array, n, array[i]); | |
37 REPORTER_ASSERT(reporter, index == (int) i); | |
38 index = GrTBSearch<int, int>(array, n, -array[i]); | |
39 REPORTER_ASSERT(reporter, index < 0); | |
40 } | |
41 } | |
42 } | |
43 | |
44 DEF_TEST(GrUnitTests_binHashKey, reporter) { | |
45 const char* testStringA_ = "abcdABCD"; | 16 const char* testStringA_ = "abcdABCD"; |
46 const char* testStringB_ = "abcdBBCD"; | 17 const char* testStringB_ = "abcdBBCD"; |
47 const uint32_t* testStringA = reinterpret_cast<const uint32_t*>(testStringA_
); | 18 const uint32_t* testStringA = reinterpret_cast<const uint32_t*>(testStringA_
); |
48 const uint32_t* testStringB = reinterpret_cast<const uint32_t*>(testStringB_
); | 19 const uint32_t* testStringB = reinterpret_cast<const uint32_t*>(testStringB_
); |
49 enum { | 20 enum { |
50 kDataLenUsedForKey = 8 | 21 kDataLenUsedForKey = 8 |
51 }; | 22 }; |
52 | 23 |
53 GrBinHashKey<kDataLenUsedForKey> keyA; | 24 GrBinHashKey<kDataLenUsedForKey> keyA; |
54 keyA.setKeyData(testStringA); | 25 keyA.setKeyData(testStringA); |
55 // test copy constructor and comparison | 26 // test copy constructor and comparison |
56 GrBinHashKey<kDataLenUsedForKey> keyA2(keyA); | 27 GrBinHashKey<kDataLenUsedForKey> keyA2(keyA); |
57 REPORTER_ASSERT(reporter, keyA == keyA2); | 28 REPORTER_ASSERT(reporter, keyA == keyA2); |
58 REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash()); | 29 REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash()); |
59 // test re-init | 30 // test re-init |
60 keyA2.setKeyData(testStringA); | 31 keyA2.setKeyData(testStringA); |
61 REPORTER_ASSERT(reporter, keyA == keyA2); | 32 REPORTER_ASSERT(reporter, keyA == keyA2); |
62 REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash()); | 33 REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash()); |
63 // test sorting | 34 // test sorting |
64 GrBinHashKey<kDataLenUsedForKey> keyB; | 35 GrBinHashKey<kDataLenUsedForKey> keyB; |
65 keyB.setKeyData(testStringB); | 36 keyB.setKeyData(testStringB); |
66 REPORTER_ASSERT(reporter, keyA < keyB); | 37 REPORTER_ASSERT(reporter, keyA < keyB); |
67 REPORTER_ASSERT(reporter, keyA.getHash() != keyB.getHash()); | 38 REPORTER_ASSERT(reporter, keyA.getHash() != keyB.getHash()); |
68 } | 39 } |
69 | 40 |
70 | |
71 #endif | 41 #endif |
OLD | NEW |