blob: d444afc17859936729da8b673f21155603262027 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * 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.
reed@google.comac10a2d2010-12-22 21:39:39 +00007 */
commit-bot@chromium.org742058f2013-11-28 08:24:29 +00008#include "Test.h"
9#include "TestClassDef.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000010
commit-bot@chromium.org742058f2013-11-28 08:24:29 +000011// This is a GPU-backend specific test
12#if SK_SUPPORT_GPU
junov@google.comf93e7172011-03-31 21:26:24 +000013#include "GrBinHashKey.h"
tomhudson@google.coma87cd2a2011-06-15 16:50:27 +000014#include "GrDrawTarget.h"
bsalomon@google.comb9086a02012-11-01 18:02:54 +000015#include "SkMatrix.h"
tomhudson@google.coma87cd2a2011-06-15 16:50:27 +000016#include "GrRedBlackTree.h"
tomhudson@google.coma87cd2a2011-06-15 16:50:27 +000017
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.
21static bool LT(const int& elem, int value) {
22 return elem < value;
23}
24static bool EQ(const int& elem, int value) {
25 return elem == value;
26}
27#include "GrTBSearch.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000028
commit-bot@chromium.org742058f2013-11-28 08:24:29 +000029
30DEF_TEST(GrUnitTests_bsearch, reporter) {
reed@google.comac10a2d2010-12-22 21:39:39 +000031 const int array[] = {
32 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99
33 };
34
robertphillips@google.com8b169312013-10-15 17:47:36 +000035 for (int n = 0; n < static_cast<int>(GR_ARRAY_COUNT(array)); ++n) {
36 for (int i = 0; i < n; i++) {
reed@google.comac10a2d2010-12-22 21:39:39 +000037 int index = GrTBSearch<int, int>(array, n, array[i]);
commit-bot@chromium.org742058f2013-11-28 08:24:29 +000038 REPORTER_ASSERT(reporter, index == (int) i);
reed@google.comac10a2d2010-12-22 21:39:39 +000039 index = GrTBSearch<int, int>(array, n, -array[i]);
commit-bot@chromium.org742058f2013-11-28 08:24:29 +000040 REPORTER_ASSERT(reporter, index < 0);
reed@google.comac10a2d2010-12-22 21:39:39 +000041 }
42 }
43}
44
commit-bot@chromium.org742058f2013-11-28 08:24:29 +000045DEF_TEST(GrUnitTests_binHashKey, reporter) {
junov@google.comf7c00f62011-08-18 18:15:16 +000046 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_);
junov@google.comf93e7172011-03-31 21:26:24 +000050 enum {
tomhudson@google.com78e7d2c2011-06-01 20:43:05 +000051 kDataLenUsedForKey = 8
junov@google.comf93e7172011-03-31 21:26:24 +000052 };
53
commit-bot@chromium.org742058f2013-11-28 08:24:29 +000054 GrBinHashKey<kDataLenUsedForKey> keyA;
junov@google.comf7c00f62011-08-18 18:15:16 +000055 keyA.setKeyData(testStringA);
56 // test copy constructor and comparison
commit-bot@chromium.org742058f2013-11-28 08:24:29 +000057 GrBinHashKey<kDataLenUsedForKey> keyA2(keyA);
58 REPORTER_ASSERT(reporter, keyA == keyA2);
59 REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash());
junov@google.comf7c00f62011-08-18 18:15:16 +000060 // test re-init
61 keyA2.setKeyData(testStringA);
commit-bot@chromium.org742058f2013-11-28 08:24:29 +000062 REPORTER_ASSERT(reporter, keyA == keyA2);
63 REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash());
junov@google.comf7c00f62011-08-18 18:15:16 +000064 // test sorting
commit-bot@chromium.org742058f2013-11-28 08:24:29 +000065 GrBinHashKey<kDataLenUsedForKey> keyB;
junov@google.comf7c00f62011-08-18 18:15:16 +000066 keyB.setKeyData(testStringB);
commit-bot@chromium.org742058f2013-11-28 08:24:29 +000067 REPORTER_ASSERT(reporter, keyA < keyB);
68 REPORTER_ASSERT(reporter, keyA.getHash() != keyB.getHash());
junov@google.comf93e7172011-03-31 21:26:24 +000069}
70
reed@google.com07f3ee12011-05-16 17:21:57 +000071
commit-bot@chromium.org742058f2013-11-28 08:24:29 +000072DEF_TEST(GrUnitTests_redBlackTree, reporter) {
73 // TODO(mtklein): unwrap this and use reporter.
bsalomon@google.com6034c502011-02-22 16:37:47 +000074 GrRedBlackTree<int>::UnitTest();
reed@google.comac10a2d2010-12-22 21:39:39 +000075}
commit-bot@chromium.org742058f2013-11-28 08:24:29 +000076
77#endif