aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/GrUnitTests.cpp
blob: d444afc17859936729da8b673f21155603262027 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

/*
 * Copyright 2010 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
#include "Test.h"
#include "TestClassDef.h"

// This is a GPU-backend specific test
#if SK_SUPPORT_GPU
#include "GrBinHashKey.h"
#include "GrDrawTarget.h"
#include "SkMatrix.h"
#include "GrRedBlackTree.h"

// If we aren't inheriting these as #defines from elsewhere,
// clang demands they be declared before we #include the template
// that relies on them.
static bool LT(const int& elem, int value) {
    return elem < value;
}
static bool EQ(const int& elem, int value) {
    return elem == value;
}
#include "GrTBSearch.h"


DEF_TEST(GrUnitTests_bsearch, reporter) {
    const int array[] = {
        1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99
    };

    for (int n = 0; n < static_cast<int>(GR_ARRAY_COUNT(array)); ++n) {
        for (int i = 0; i < n; i++) {
            int index = GrTBSearch<int, int>(array, n, array[i]);
            REPORTER_ASSERT(reporter, index == (int) i);
            index = GrTBSearch<int, int>(array, n, -array[i]);
            REPORTER_ASSERT(reporter, index < 0);
        }
    }
}

DEF_TEST(GrUnitTests_binHashKey, reporter) {
    const char* testStringA_ = "abcdABCD";
    const char* testStringB_ = "abcdBBCD";
    const uint32_t* testStringA = reinterpret_cast<const uint32_t*>(testStringA_);
    const uint32_t* testStringB = reinterpret_cast<const uint32_t*>(testStringB_);
    enum {
        kDataLenUsedForKey = 8
    };

    GrBinHashKey<kDataLenUsedForKey> keyA;
    keyA.setKeyData(testStringA);
    // test copy constructor and comparison
    GrBinHashKey<kDataLenUsedForKey> keyA2(keyA);
    REPORTER_ASSERT(reporter, keyA == keyA2);
    REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash());
    // test re-init
    keyA2.setKeyData(testStringA);
    REPORTER_ASSERT(reporter, keyA == keyA2);
    REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash());
    // test sorting
    GrBinHashKey<kDataLenUsedForKey> keyB;
    keyB.setKeyData(testStringB);
    REPORTER_ASSERT(reporter, keyA < keyB);
    REPORTER_ASSERT(reporter, keyA.getHash() != keyB.getHash());
}


DEF_TEST(GrUnitTests_redBlackTree, reporter) {
    // TODO(mtklein): unwrap this and use reporter.
    GrRedBlackTree<int>::UnitTest();
}

#endif