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 #include "TestClassDef.h"
10
11 // This is a GPU-backend specific test
12 #if SK_SUPPORT_GPU
13 #include "GrBinHashKey.h"
14 #include "GrDrawTarget.h"
15 #include "SkMatrix.h"
16 #include "GrRedBlackTree.h"
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.
LT(const int & elem,int value)21 static bool LT(const int& elem, int value) {
22 return elem < value;
23 }
EQ(const int & elem,int value)24 static bool EQ(const int& elem, int value) {
25 return elem == value;
26 }
27 #include "GrTBSearch.h"
28
29
DEF_TEST(GrUnitTests_bsearch,reporter)30 DEF_TEST(GrUnitTests_bsearch, reporter) {
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
35 for (int n = 0; n < static_cast<int>(GR_ARRAY_COUNT(array)); ++n) {
36 for (int i = 0; i < n; i++) {
37 int index = GrTBSearch<int, int>(array, n, array[i]);
38 REPORTER_ASSERT(reporter, index == (int) i);
39 index = GrTBSearch<int, int>(array, n, -array[i]);
40 REPORTER_ASSERT(reporter, index < 0);
41 }
42 }
43 }
44
DEF_TEST(GrUnitTests_binHashKey,reporter)45 DEF_TEST(GrUnitTests_binHashKey, reporter) {
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_);
50 enum {
51 kDataLenUsedForKey = 8
52 };
53
54 GrBinHashKey<kDataLenUsedForKey> keyA;
55 keyA.setKeyData(testStringA);
56 // test copy constructor and comparison
57 GrBinHashKey<kDataLenUsedForKey> keyA2(keyA);
58 REPORTER_ASSERT(reporter, keyA == keyA2);
59 REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash());
60 // test re-init
61 keyA2.setKeyData(testStringA);
62 REPORTER_ASSERT(reporter, keyA == keyA2);
63 REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash());
64 // test sorting
65 GrBinHashKey<kDataLenUsedForKey> keyB;
66 keyB.setKeyData(testStringB);
67 REPORTER_ASSERT(reporter, keyA < keyB);
68 REPORTER_ASSERT(reporter, keyA.getHash() != keyB.getHash());
69 }
70
71
DEF_TEST(GrUnitTests_redBlackTree,reporter)72 DEF_TEST(GrUnitTests_redBlackTree, reporter) {
73 // TODO(mtklein): unwrap this and use reporter.
74 GrRedBlackTree<int>::UnitTest();
75 }
76
77 #endif
78