blob: 16fd9dc95da5bb2909d30c5627548af0d786d6e9 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
2 Copyright 2010 Google Inc.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000018#include "GrDrawTarget.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000019#include "GrTDArray.h"
20#include "GrTBSearch.h"
21#include "GrMatrix.h"
bsalomon@google.com6034c502011-02-22 16:37:47 +000022#include "GrRedBlackTree.h"
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000023#include "GrPath.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000024
25static void dump(const GrTDArray<int>& array) {
26#if 0
27 for (int i = 0; i < array.count(); i++) {
28 printf(" %d", array[i]);
29 }
30 printf("\n");
31#endif
32}
33
34static void test_tdarray() {
35 GrTDArray<int> array;
bsalomon@google.com6034c502011-02-22 16:37:47 +000036
reed@google.comac10a2d2010-12-22 21:39:39 +000037 *array.append() = 0; dump(array);
38 *array.append() = 2; dump(array);
39 *array.append() = 4; dump(array);
40 *array.append() = 6; dump(array);
41 GrAssert(array.count() == 4);
42
43 *array.insert(0) = -1; dump(array);
44 *array.insert(2) = 1; dump(array);
45 *array.insert(4) = 3; dump(array);
46 *array.insert(7) = 7; dump(array);
47 GrAssert(array.count() == 8);
48 array.remove(3); dump(array);
49 array.remove(0); dump(array);
50 array.removeShuffle(4); dump(array);
51 array.removeShuffle(1); dump(array);
52 GrAssert(array.count() == 4);
53}
54
55static bool LT(const int& elem, int value) {
56 return elem < value;
57}
58static bool EQ(const int& elem, int value) {
59 return elem == value;
60}
61
62static void test_bsearch() {
63 const int array[] = {
64 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99
65 };
66
67 for (size_t n = 0; n < GR_ARRAY_COUNT(array); n++) {
68 for (size_t i = 0; i < n; i++) {
69 int index = GrTBSearch<int, int>(array, n, array[i]);
70 GrAssert(index == i);
71 index = GrTBSearch<int, int>(array, n, -array[i]);
72 GrAssert(index < 0);
73 }
74 }
75}
76
reed@google.comac10a2d2010-12-22 21:39:39 +000077void gr_run_unittests() {
78 test_tdarray();
79 test_bsearch();
reed@google.comac10a2d2010-12-22 21:39:39 +000080 GrMatrix::UnitTest();
bsalomon@google.com6034c502011-02-22 16:37:47 +000081 GrRedBlackTree<int>::UnitTest();
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000082 GrPath::ConvexUnitTest();
83 GrDrawTarget::VertexLayoutUnitTest();
reed@google.comac10a2d2010-12-22 21:39:39 +000084}
85
86