diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2010-12-22 21:39:39 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2010-12-22 21:39:39 +0000 |
commit | ac10a2d039c5d52eed66e27cbbc503ab523c1cd5 (patch) | |
tree | c5be0c3dd15052016e7d32f376507cb1ea7101dd /gpu/src/gr_unittests.cpp | |
parent | ea8509cd3b1771b36054313d3ccd56679df56044 (diff) |
add gpu backend (not hooked up yet)
git-svn-id: http://skia.googlecode.com/svn/trunk@649 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gpu/src/gr_unittests.cpp')
-rw-r--r-- | gpu/src/gr_unittests.cpp | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/gpu/src/gr_unittests.cpp b/gpu/src/gr_unittests.cpp new file mode 100644 index 0000000000..a9fd40d124 --- /dev/null +++ b/gpu/src/gr_unittests.cpp @@ -0,0 +1,143 @@ +/* + 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. + */ + + +#include "GrClip.h" +#include "GrTDArray.h" +#include "GrTBSearch.h" +#include "GrMatrix.h" + +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; + + *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); + } + } +} + +static void dump(const GrClip& clip, const char message[]) { + GrPrintf("--- dump clip %s\n", message); + GrClipIter iter(clip); + while (!iter.isDone()) { + GrIRect r; + iter.getRect(&r); + GrPrintf("--- [%d %d %d %d]\n", r.fLeft, r.fTop, r.fRight, r.fBottom); + iter.next(); + } +} + +static void test_clip() { + GrClip clip; + GrAssert(clip.isEmpty()); + GrAssert(!clip.isRect()); + GrAssert(!clip.isComplex()); + GrAssert(clip.getBounds().equalsLTRB(0, 0, 0, 0)); + GrAssert(0 == clip.countRects()); + + clip.setRect(GrIRect(10, 10, 10, 10)); + GrAssert(clip.isEmpty()); + GrAssert(!clip.isRect()); + GrAssert(!clip.isComplex()); + GrAssert(clip.getBounds().equalsLTRB(0, 0, 0, 0)); + GrAssert(0 == clip.countRects()); + dump(clip, "empty"); + + clip.setRect(GrIRect(10, 10, 20, 20)); + GrAssert(!clip.isEmpty()); + GrAssert(clip.isRect()); + GrAssert(!clip.isComplex()); + GrAssert(clip.getBounds().equalsLTRB(10, 10, 20, 20)); + GrAssert(1 == clip.countRects()); + GrAssert(clip.getRects()[0] == clip.getBounds()); + dump(clip, "rect"); + + clip.addRect(GrIRect(20, 20, 25, 25)); + GrAssert(!clip.isEmpty()); + GrAssert(!clip.isRect()); + GrAssert(clip.isComplex()); + GrAssert(clip.getBounds().equalsLTRB(10, 10, 25, 25)); + GrAssert(2 == clip.countRects()); + dump(clip, "complex"); + + GrClip c1(clip); + GrAssert(c1 == clip); + GrClip c2; + GrAssert(c2 != c1); + c2 = clip; + GrAssert(c2 == clip); + + clip.setEmpty(); + GrAssert(clip.isEmpty()); + GrAssert(!clip.isRect()); + GrAssert(!clip.isComplex()); + GrAssert(clip.getBounds().equalsLTRB(0, 0, 0, 0)); + + GrAssert(c1 != clip); + GrAssert(c2 != clip); +} + +void gr_run_unittests() { + test_tdarray(); + test_bsearch(); + test_clip(); + GrMatrix::UnitTest(); +} + + |