epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
commit-bot@chromium.org | 742058f | 2013-11-28 08:24:29 +0000 | [diff] [blame^] | 8 | #include "Test.h" |
| 9 | #include "TestClassDef.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 10 | |
commit-bot@chromium.org | 742058f | 2013-11-28 08:24:29 +0000 | [diff] [blame^] | 11 | // This is a GPU-backend specific test |
| 12 | #if SK_SUPPORT_GPU |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 13 | #include "GrBinHashKey.h" |
tomhudson@google.com | a87cd2a | 2011-06-15 16:50:27 +0000 | [diff] [blame] | 14 | #include "GrDrawTarget.h" |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 15 | #include "SkMatrix.h" |
tomhudson@google.com | a87cd2a | 2011-06-15 16:50:27 +0000 | [diff] [blame] | 16 | #include "GrRedBlackTree.h" |
tomhudson@google.com | a87cd2a | 2011-06-15 16:50:27 +0000 | [diff] [blame] | 17 | |
| 18 | // If we aren't inheriting these as #defines from elsewhere, |
| 19 | // clang demands they be declared before we #include the template |
| 20 | // that relies on them. |
| 21 | static bool LT(const int& elem, int value) { |
| 22 | return elem < value; |
| 23 | } |
| 24 | static bool EQ(const int& elem, int value) { |
| 25 | return elem == value; |
| 26 | } |
| 27 | #include "GrTBSearch.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 28 | |
commit-bot@chromium.org | 742058f | 2013-11-28 08:24:29 +0000 | [diff] [blame^] | 29 | |
| 30 | DEF_TEST(GrUnitTests_bsearch, reporter) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 31 | const int array[] = { |
| 32 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99 |
| 33 | }; |
| 34 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 35 | for (int n = 0; n < static_cast<int>(GR_ARRAY_COUNT(array)); ++n) { |
| 36 | for (int i = 0; i < n; i++) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 37 | int index = GrTBSearch<int, int>(array, n, array[i]); |
commit-bot@chromium.org | 742058f | 2013-11-28 08:24:29 +0000 | [diff] [blame^] | 38 | REPORTER_ASSERT(reporter, index == (int) i); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 39 | index = GrTBSearch<int, int>(array, n, -array[i]); |
commit-bot@chromium.org | 742058f | 2013-11-28 08:24:29 +0000 | [diff] [blame^] | 40 | REPORTER_ASSERT(reporter, index < 0); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
commit-bot@chromium.org | 742058f | 2013-11-28 08:24:29 +0000 | [diff] [blame^] | 45 | DEF_TEST(GrUnitTests_binHashKey, reporter) { |
junov@google.com | f7c00f6 | 2011-08-18 18:15:16 +0000 | [diff] [blame] | 46 | const char* testStringA_ = "abcdABCD"; |
| 47 | const char* testStringB_ = "abcdBBCD"; |
| 48 | const uint32_t* testStringA = reinterpret_cast<const uint32_t*>(testStringA_); |
| 49 | const uint32_t* testStringB = reinterpret_cast<const uint32_t*>(testStringB_); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 50 | enum { |
tomhudson@google.com | 78e7d2c | 2011-06-01 20:43:05 +0000 | [diff] [blame] | 51 | kDataLenUsedForKey = 8 |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
commit-bot@chromium.org | 742058f | 2013-11-28 08:24:29 +0000 | [diff] [blame^] | 54 | GrBinHashKey<kDataLenUsedForKey> keyA; |
junov@google.com | f7c00f6 | 2011-08-18 18:15:16 +0000 | [diff] [blame] | 55 | keyA.setKeyData(testStringA); |
| 56 | // test copy constructor and comparison |
commit-bot@chromium.org | 742058f | 2013-11-28 08:24:29 +0000 | [diff] [blame^] | 57 | GrBinHashKey<kDataLenUsedForKey> keyA2(keyA); |
| 58 | REPORTER_ASSERT(reporter, keyA == keyA2); |
| 59 | REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash()); |
junov@google.com | f7c00f6 | 2011-08-18 18:15:16 +0000 | [diff] [blame] | 60 | // test re-init |
| 61 | keyA2.setKeyData(testStringA); |
commit-bot@chromium.org | 742058f | 2013-11-28 08:24:29 +0000 | [diff] [blame^] | 62 | REPORTER_ASSERT(reporter, keyA == keyA2); |
| 63 | REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash()); |
junov@google.com | f7c00f6 | 2011-08-18 18:15:16 +0000 | [diff] [blame] | 64 | // test sorting |
commit-bot@chromium.org | 742058f | 2013-11-28 08:24:29 +0000 | [diff] [blame^] | 65 | GrBinHashKey<kDataLenUsedForKey> keyB; |
junov@google.com | f7c00f6 | 2011-08-18 18:15:16 +0000 | [diff] [blame] | 66 | keyB.setKeyData(testStringB); |
commit-bot@chromium.org | 742058f | 2013-11-28 08:24:29 +0000 | [diff] [blame^] | 67 | REPORTER_ASSERT(reporter, keyA < keyB); |
| 68 | REPORTER_ASSERT(reporter, keyA.getHash() != keyB.getHash()); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 69 | } |
| 70 | |
reed@google.com | 07f3ee1 | 2011-05-16 17:21:57 +0000 | [diff] [blame] | 71 | |
commit-bot@chromium.org | 742058f | 2013-11-28 08:24:29 +0000 | [diff] [blame^] | 72 | DEF_TEST(GrUnitTests_redBlackTree, reporter) { |
| 73 | // TODO(mtklein): unwrap this and use reporter. |
bsalomon@google.com | 6034c50 | 2011-02-22 16:37:47 +0000 | [diff] [blame] | 74 | GrRedBlackTree<int>::UnitTest(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 75 | } |
commit-bot@chromium.org | 742058f | 2013-11-28 08:24:29 +0000 | [diff] [blame^] | 76 | |
| 77 | #endif |