2010-12-22 21:39:39 +00:00
|
|
|
/*
|
|
|
|
Copyright 2010 Google Inc.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-03-04 20:29:08 +00:00
|
|
|
#include "GrDrawTarget.h"
|
2010-12-22 21:39:39 +00:00
|
|
|
#include "GrTDArray.h"
|
|
|
|
#include "GrTBSearch.h"
|
|
|
|
#include "GrMatrix.h"
|
2011-02-22 16:37:47 +00:00
|
|
|
#include "GrRedBlackTree.h"
|
2011-03-04 20:29:08 +00:00
|
|
|
#include "GrPath.h"
|
2010-12-22 21:39:39 +00:00
|
|
|
|
|
|
|
static void dump(const GrTDArray<int>& array) {
|
|
|
|
#if 0
|
|
|
|
for (int i = 0; i < array.count(); i++) {
|
|
|
|
printf(" %d", array[i]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_tdarray() {
|
|
|
|
GrTDArray<int> array;
|
2011-02-22 16:37:47 +00:00
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
*array.append() = 0; dump(array);
|
|
|
|
*array.append() = 2; dump(array);
|
|
|
|
*array.append() = 4; dump(array);
|
|
|
|
*array.append() = 6; dump(array);
|
|
|
|
GrAssert(array.count() == 4);
|
|
|
|
|
|
|
|
*array.insert(0) = -1; dump(array);
|
|
|
|
*array.insert(2) = 1; dump(array);
|
|
|
|
*array.insert(4) = 3; dump(array);
|
|
|
|
*array.insert(7) = 7; dump(array);
|
|
|
|
GrAssert(array.count() == 8);
|
|
|
|
array.remove(3); dump(array);
|
|
|
|
array.remove(0); dump(array);
|
|
|
|
array.removeShuffle(4); dump(array);
|
|
|
|
array.removeShuffle(1); dump(array);
|
|
|
|
GrAssert(array.count() == 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool LT(const int& elem, int value) {
|
|
|
|
return elem < value;
|
|
|
|
}
|
|
|
|
static bool EQ(const int& elem, int value) {
|
|
|
|
return elem == value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_bsearch() {
|
|
|
|
const int array[] = {
|
|
|
|
1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t n = 0; n < GR_ARRAY_COUNT(array); n++) {
|
|
|
|
for (size_t i = 0; i < n; i++) {
|
|
|
|
int index = GrTBSearch<int, int>(array, n, array[i]);
|
|
|
|
GrAssert(index == i);
|
|
|
|
index = GrTBSearch<int, int>(array, n, -array[i]);
|
|
|
|
GrAssert(index < 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gr_run_unittests() {
|
|
|
|
test_tdarray();
|
|
|
|
test_bsearch();
|
|
|
|
GrMatrix::UnitTest();
|
2011-02-22 16:37:47 +00:00
|
|
|
GrRedBlackTree<int>::UnitTest();
|
2011-03-04 20:29:08 +00:00
|
|
|
GrPath::ConvexUnitTest();
|
|
|
|
GrDrawTarget::VertexLayoutUnitTest();
|
2010-12-22 21:39:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|