| OLD | NEW |
| (Empty) |
| 1 | |
| 2 /* | |
| 3 * Copyright 2010 Google Inc. | |
| 4 * | |
| 5 * Use of this source code is governed by a BSD-style license that can be | |
| 6 * found in the LICENSE file. | |
| 7 */ | |
| 8 #include "Test.h" | |
| 9 | |
| 10 // This is a GPU-backend specific test | |
| 11 #if SK_SUPPORT_GPU | |
| 12 #include "GrBinHashKey.h" | |
| 13 #include "GrDrawTarget.h" | |
| 14 #include "GrRedBlackTree.h" | |
| 15 #include "SkMatrix.h" | |
| 16 | |
| 17 // If we aren't inheriting these as #defines from elsewhere, | |
| 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 | |
| 28 | |
| 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"; | |
| 46 const char* testStringB_ = "abcdBBCD"; | |
| 47 const uint32_t* testStringA = reinterpret_cast<const uint32_t*>(testStringA_
); | |
| 48 const uint32_t* testStringB = reinterpret_cast<const uint32_t*>(testStringB_
); | |
| 49 enum { | |
| 50 kDataLenUsedForKey = 8 | |
| 51 }; | |
| 52 | |
| 53 GrBinHashKey<kDataLenUsedForKey> keyA; | |
| 54 keyA.setKeyData(testStringA); | |
| 55 // test copy constructor and comparison | |
| 56 GrBinHashKey<kDataLenUsedForKey> keyA2(keyA); | |
| 57 REPORTER_ASSERT(reporter, keyA == keyA2); | |
| 58 REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash()); | |
| 59 // test re-init | |
| 60 keyA2.setKeyData(testStringA); | |
| 61 REPORTER_ASSERT(reporter, keyA == keyA2); | |
| 62 REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash()); | |
| 63 // test sorting | |
| 64 GrBinHashKey<kDataLenUsedForKey> keyB; | |
| 65 keyB.setKeyData(testStringB); | |
| 66 REPORTER_ASSERT(reporter, keyA < keyB); | |
| 67 REPORTER_ASSERT(reporter, keyA.getHash() != keyB.getHash()); | |
| 68 } | |
| 69 | |
| 70 | |
| 71 #endif | |
| OLD | NEW |