Chromium Code Reviews| 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" |
| 11 #include "SkMatrix.h" | 11 #include "SkMatrix.h" |
| 12 #include "GrRedBlackTree.h" | 12 #include "GrRedBlackTree.h" |
| 13 | 13 |
| 14 // FIXME: needs to be in a header | 14 // FIXME: needs to be in a header |
| 15 void gr_run_unittests(); | 15 void gr_run_unittests(); |
| 16 | 16 |
| 17 // If we aren't inheriting these as #defines from elsewhere, | 17 // If we aren't inheriting these as #defines from elsewhere, |
| 18 // clang demands they be declared before we #include the template | 18 // clang demands they be declared before we #include the template |
| 19 // that relies on them. | 19 // that relies on them. |
| 20 #if GR_DEBUG | |
| 20 static bool LT(const int& elem, int value) { | 21 static bool LT(const int& elem, int value) { |
| 21 return elem < value; | 22 return elem < value; |
| 22 } | 23 } |
| 23 static bool EQ(const int& elem, int value) { | 24 static bool EQ(const int& elem, int value) { |
| 24 return elem == value; | 25 return elem == value; |
| 25 } | 26 } |
| 26 #include "GrTBSearch.h" | 27 #include "GrTBSearch.h" |
| 27 | 28 |
| 28 static void test_bsearch() { | 29 static void test_bsearch() { |
| 29 const int array[] = { | 30 const int array[] = { |
| 30 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 |
| 31 }; | 32 }; |
| 32 | 33 |
| 33 for (size_t n = 0; n < GR_ARRAY_COUNT(array); n++) { | 34 for (size_t n = 0; n < GR_ARRAY_COUNT(array); n++) { |
| 34 for (size_t i = 0; i < n; i++) { | 35 for (size_t i = 0; i < n; i++) { |
| 35 int index = GrTBSearch<int, int>(array, n, array[i]); | 36 int index = GrTBSearch<int, int>(array, n, array[i]); |
| 36 GrAssert(index == (int) i); | 37 GrAssert(index == (int) i); |
| 37 index = GrTBSearch<int, int>(array, n, -array[i]); | 38 index = GrTBSearch<int, int>(array, n, -array[i]); |
| 38 GrAssert(index < 0); | 39 GrAssert(index < 0); |
|
sugoi
2013/03/05 21:21:28
This code does nothing in RELEASE since all these
| |
| 39 } | 40 } |
| 40 } | 41 } |
| 41 } | 42 } |
| 43 #endif | |
| 42 | 44 |
| 43 // bogus empty class for GrBinHashKey | 45 // bogus empty class for GrBinHashKey |
| 44 class BogusEntry {}; | 46 class BogusEntry {}; |
| 45 | 47 |
| 46 static void test_binHashKey() | 48 static void test_binHashKey() |
| 47 { | 49 { |
| 48 const char* testStringA_ = "abcdABCD"; | 50 const char* testStringA_ = "abcdABCD"; |
| 49 const char* testStringB_ = "abcdBBCD"; | 51 const char* testStringB_ = "abcdBBCD"; |
| 50 const uint32_t* testStringA = reinterpret_cast<const uint32_t*>(testStringA_ ); | 52 const uint32_t* testStringA = reinterpret_cast<const uint32_t*>(testStringA_ ); |
| 51 const uint32_t* testStringB = reinterpret_cast<const uint32_t*>(testStringB_ ); | 53 const uint32_t* testStringB = reinterpret_cast<const uint32_t*>(testStringB_ ); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 65 GrAssert(keyA.getHash() == keyA2.getHash()); | 67 GrAssert(keyA.getHash() == keyA2.getHash()); |
| 66 // test sorting | 68 // test sorting |
| 67 GrTBinHashKey<BogusEntry, kDataLenUsedForKey> keyB; | 69 GrTBinHashKey<BogusEntry, kDataLenUsedForKey> keyB; |
| 68 keyB.setKeyData(testStringB); | 70 keyB.setKeyData(testStringB); |
| 69 GrAssert(keyA.compare(keyB) < 0); | 71 GrAssert(keyA.compare(keyB) < 0); |
| 70 GrAssert(keyA.getHash() != keyB.getHash()); | 72 GrAssert(keyA.getHash() != keyB.getHash()); |
| 71 } | 73 } |
| 72 | 74 |
| 73 | 75 |
| 74 void gr_run_unittests() { | 76 void gr_run_unittests() { |
| 75 test_bsearch(); | 77 GR_DEBUGCODE(test_bsearch();) |
| 76 test_binHashKey(); | 78 test_binHashKey(); |
| 77 GrRedBlackTree<int>::UnitTest(); | 79 GrRedBlackTree<int>::UnitTest(); |
| 78 GrDrawState::VertexAttributesUnitTest(); | 80 GrDrawState::VertexAttributesUnitTest(); |
| 79 } | 81 } |
| OLD | NEW |