OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "GrBinHashKey.h" | 9 #include "GrBinHashKey.h" |
10 #include "GrDrawTarget.h" | 10 #include "GrDrawTarget.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "GrTBSearch.h" | 27 #include "GrTBSearch.h" |
28 | 28 |
29 static void test_bsearch() { | 29 static void test_bsearch() { |
30 const int array[] = { | 30 const int array[] = { |
31 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99 | 31 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99 |
32 }; | 32 }; |
33 | 33 |
34 for (size_t n = 0; n < GR_ARRAY_COUNT(array); n++) { | 34 for (size_t n = 0; n < GR_ARRAY_COUNT(array); n++) { |
35 for (size_t i = 0; i < n; i++) { | 35 for (size_t i = 0; i < n; i++) { |
36 int index = GrTBSearch<int, int>(array, n, array[i]); | 36 int index = GrTBSearch<int, int>(array, n, array[i]); |
37 GrAssert(index == (int) i); | 37 SkASSERT(index == (int) i); |
38 index = GrTBSearch<int, int>(array, n, -array[i]); | 38 index = GrTBSearch<int, int>(array, n, -array[i]); |
39 GrAssert(index < 0); | 39 SkASSERT(index < 0); |
40 } | 40 } |
41 } | 41 } |
42 } | 42 } |
43 #endif | 43 #endif |
44 | 44 |
45 // bogus empty class for GrBinHashKey | 45 // bogus empty class for GrBinHashKey |
46 class BogusEntry {}; | 46 class BogusEntry {}; |
47 | 47 |
48 static void test_binHashKey() | 48 static void test_binHashKey() |
49 { | 49 { |
50 const char* testStringA_ = "abcdABCD"; | 50 const char* testStringA_ = "abcdABCD"; |
51 const char* testStringB_ = "abcdBBCD"; | 51 const char* testStringB_ = "abcdBBCD"; |
52 const uint32_t* testStringA = reinterpret_cast<const uint32_t*>(testStringA_
); | 52 const uint32_t* testStringA = reinterpret_cast<const uint32_t*>(testStringA_
); |
53 const uint32_t* testStringB = reinterpret_cast<const uint32_t*>(testStringB_
); | 53 const uint32_t* testStringB = reinterpret_cast<const uint32_t*>(testStringB_
); |
54 enum { | 54 enum { |
55 kDataLenUsedForKey = 8 | 55 kDataLenUsedForKey = 8 |
56 }; | 56 }; |
57 | 57 |
58 GrTBinHashKey<BogusEntry, kDataLenUsedForKey> keyA; | 58 GrTBinHashKey<BogusEntry, kDataLenUsedForKey> keyA; |
59 keyA.setKeyData(testStringA); | 59 keyA.setKeyData(testStringA); |
60 // test copy constructor and comparison | 60 // test copy constructor and comparison |
61 GrTBinHashKey<BogusEntry, kDataLenUsedForKey> keyA2(keyA); | 61 GrTBinHashKey<BogusEntry, kDataLenUsedForKey> keyA2(keyA); |
62 GrAssert(keyA.compare(keyA2) == 0); | 62 SkASSERT(keyA.compare(keyA2) == 0); |
63 GrAssert(keyA.getHash() == keyA2.getHash()); | 63 SkASSERT(keyA.getHash() == keyA2.getHash()); |
64 // test re-init | 64 // test re-init |
65 keyA2.setKeyData(testStringA); | 65 keyA2.setKeyData(testStringA); |
66 GrAssert(keyA.compare(keyA2) == 0); | 66 SkASSERT(keyA.compare(keyA2) == 0); |
67 GrAssert(keyA.getHash() == keyA2.getHash()); | 67 SkASSERT(keyA.getHash() == keyA2.getHash()); |
68 // test sorting | 68 // test sorting |
69 GrTBinHashKey<BogusEntry, kDataLenUsedForKey> keyB; | 69 GrTBinHashKey<BogusEntry, kDataLenUsedForKey> keyB; |
70 keyB.setKeyData(testStringB); | 70 keyB.setKeyData(testStringB); |
71 GrAssert(keyA.compare(keyB) < 0); | 71 SkASSERT(keyA.compare(keyB) < 0); |
72 GrAssert(keyA.getHash() != keyB.getHash()); | 72 SkASSERT(keyA.getHash() != keyB.getHash()); |
73 } | 73 } |
74 | 74 |
75 | 75 |
76 void gr_run_unittests() { | 76 void gr_run_unittests() { |
77 GR_DEBUGCODE(test_bsearch();) | 77 GR_DEBUGCODE(test_bsearch();) |
78 test_binHashKey(); | 78 test_binHashKey(); |
79 GrRedBlackTree<int>::UnitTest(); | 79 GrRedBlackTree<int>::UnitTest(); |
80 } | 80 } |
OLD | NEW |