OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #ifndef skiatest_Test_DEFINED | 8 #ifndef skiatest_Test_DEFINED |
9 #define skiatest_Test_DEFINED | 9 #define skiatest_Test_DEFINED |
10 | 10 |
11 #include "SkString.h" | 11 #include "SkString.h" |
12 #include "SkTRegistry.h" | 12 #include "SkTRegistry.h" |
13 #include "SkTypes.h" | 13 #include "SkTypes.h" |
14 | 14 |
15 class GrContextFactory; | 15 class GrContextFactory; |
| 16 class GrContext; |
| 17 class SkGLContext; |
16 | 18 |
17 namespace skiatest { | 19 namespace skiatest { |
18 | 20 |
19 SkString GetTmpDir(); | 21 SkString GetTmpDir(); |
20 | 22 |
21 struct Failure { | 23 struct Failure { |
22 Failure(const char* f, int l, const char* c, const SkString& m) | 24 Failure(const char* f, int l, const char* c, const SkString& m) |
23 : fileName(f), lineNo(l), condition(c), message(m) {} | 25 : fileName(f), lineNo(l), condition(c), message(m) {} |
24 const char* fileName; | 26 const char* fileName; |
25 int lineNo; | 27 int lineNo; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 ... | 64 ... |
63 REPORTER_ASSERT_MESSAGE(reporter, x == 15, "x should be 15"); | 65 REPORTER_ASSERT_MESSAGE(reporter, x == 15, "x should be 15"); |
64 ... | 66 ... |
65 if (x != 15) { | 67 if (x != 15) { |
66 ERRORF(reporter, "x should be 15, but is %d", x); | 68 ERRORF(reporter, "x should be 15, but is %d", x); |
67 return; | 69 return; |
68 } | 70 } |
69 ... | 71 ... |
70 } | 72 } |
71 */ | 73 */ |
| 74 enum GPUTestContexts { |
| 75 kNone_GPUTestContexts = 0, |
| 76 kNull_GPUTestContexts = 1, |
| 77 kNative_GPUTestContexts = 1 << 1, |
| 78 kOther_GPUTestContexts = 1 << 2, // Other than native, used only for
below. |
| 79 kAllRendering_GPUTestContexts = kNative_GPUTestContexts | kOther_GPUTestCont
exts, |
| 80 kAll_GPUTestContexts = kAllRendering_GPUTestContexts | kNull_GPUTes
tContexts |
| 81 }; |
| 82 template<typename T> |
| 83 void RunWithGPUTestContexts(T testFunction, GPUTestContexts contexts, Reporter*
reporter, |
| 84 GrContextFactory* factory); |
72 } // namespace skiatest | 85 } // namespace skiatest |
73 | 86 |
74 #define REPORTER_ASSERT(r, cond) \ | 87 #define REPORTER_ASSERT(r, cond) \ |
75 do { \ | 88 do { \ |
76 if (!(cond)) { \ | 89 if (!(cond)) { \ |
77 REPORT_FAILURE(r, #cond, SkString()); \ | 90 REPORT_FAILURE(r, #cond, SkString()); \ |
78 } \ | 91 } \ |
79 } while (0) | 92 } while (0) |
80 | 93 |
81 #define REPORTER_ASSERT_MESSAGE(r, cond, message) \ | 94 #define REPORTER_ASSERT_MESSAGE(r, cond, message) \ |
82 do { \ | 95 do { \ |
83 if (!(cond)) { \ | 96 if (!(cond)) { \ |
84 REPORT_FAILURE(r, #cond, SkString(message)); \ | 97 REPORT_FAILURE(r, #cond, SkString(message)); \ |
85 } \ | 98 } \ |
86 } while (0) | 99 } while (0) |
87 | 100 |
88 #define ERRORF(r, ...) \ | 101 #define ERRORF(r, ...) \ |
89 do { \ | 102 do { \ |
90 REPORT_FAILURE(r, "", SkStringPrintf(__VA_ARGS__)); \ | 103 REPORT_FAILURE(r, "", SkStringPrintf(__VA_ARGS__)); \ |
91 } while (0) | 104 } while (0) |
92 | 105 |
93 #define DEF_TEST(name, reporter) \ | 106 #define DEF_TEST(name, reporter) \ |
94 static void test_##name(skiatest::Reporter*, GrContextFactory*); \ | 107 static void test_##name(skiatest::Reporter*, GrContextFactory*); \ |
95 skiatest::TestRegistry name##TestRegistry( \ | 108 skiatest::TestRegistry name##TestRegistry( \ |
96 skiatest::Test(#name, false, test_##name)); \ | 109 skiatest::Test(#name, false, test_##name)); \ |
97 void test_##name(skiatest::Reporter* reporter, GrContextFactory*) | 110 void test_##name(skiatest::Reporter* reporter, GrContextFactory*) |
98 | 111 |
| 112 #define GPUTEST_EXPAND_MSVC(x) x |
| 113 #define GPUTEST_APPLY(C, ...) GPUTEST_EXPAND_MSVC(C(__VA_ARGS__)) |
| 114 #define GPUTEST_SELECT(a1, a2, N, ...) N |
| 115 |
| 116 #define GPUTEST_CONTEXT_ARGS1(a1) GrContext* a1 |
| 117 #define GPUTEST_CONTEXT_ARGS2(a1, a2) GrContext* a1, SkGLContext* a2 |
| 118 #define GPUTEST_CONTEXT_ARGS(...)
\ |
| 119 GPUTEST_APPLY(GPUTEST_SELECT(__VA_ARGS__, GPUTEST_CONTEXT_ARGS2, GPUTEST_CON
TEXT_ARGS1), \ |
| 120 __VA_ARGS__) |
| 121 |
99 #define DEF_GPUTEST(name, reporter, factory) \ | 122 #define DEF_GPUTEST(name, reporter, factory) \ |
100 static void test_##name(skiatest::Reporter*, GrContextFactory*); \ | 123 static void test_##name(skiatest::Reporter*, GrContextFactory*); \ |
101 skiatest::TestRegistry name##TestRegistry( \ | 124 skiatest::TestRegistry name##TestRegistry( \ |
102 skiatest::Test(#name, true, test_##name)); \ | 125 skiatest::Test(#name, true, test_##name)); \ |
103 void test_##name(skiatest::Reporter* reporter, GrContextFactory* factory) | 126 void test_##name(skiatest::Reporter* reporter, GrContextFactory* factory) |
104 | 127 |
| 128 #define DEF_GPUTEST_FOR_CONTEXTS(name, contexts, reporter, ...)
\ |
| 129 static void test_##name(skiatest::Reporter*, GPUTEST_CONTEXT_ARGS(__VA_ARGS_
_)); \ |
| 130 static void test_gpu_contexts_##name(skiatest::Reporter* reporter,
\ |
| 131 GrContextFactory* factory) {
\ |
| 132 skiatest::RunWithGPUTestContexts(test_##name, contexts, reporter, factor
y); \ |
| 133 }
\ |
| 134 skiatest::TestRegistry name##TestRegistry(
\ |
| 135 skiatest::Test(#name, true, test_gpu_contexts_##name));
\ |
| 136 void test_##name(skiatest::Reporter* reporter, GPUTEST_CONTEXT_ARGS(__VA_ARG
S__)) |
| 137 |
| 138 #define DEF_GPUTEST_FOR_ALL_CONTEXTS(name, reporter, ...) \ |
| 139 DEF_GPUTEST_FOR_CONTEXTS(name, skiatest::kAll_GPUTestContexts, reporter,
__VA_ARGS__) |
| 140 #define DEF_GPUTEST_FOR_RENDERING_CONTEXTS(name, reporter, ...) \ |
| 141 DEF_GPUTEST_FOR_CONTEXTS(name, skiatest::kAllRendering_GPUTestContexts,
reporter, __VA_ARGS__) |
| 142 #define DEF_GPUTEST_FOR_NULL_CONTEXT(name, reporter, ...) \ |
| 143 DEF_GPUTEST_FOR_CONTEXTS(name, skiatest::kNull_GPUTestContexts, reporter
, __VA_ARGS__) |
| 144 #define DEF_GPUTEST_FOR_NATIVE_CONTEXT(name, reporter, ...) \ |
| 145 DEF_GPUTEST_FOR_CONTEXTS(name, skiatest::kNative_GPUTestContexts, report
er, __VA_ARGS__) |
| 146 |
105 #define REQUIRE_PDF_DOCUMENT(TEST_NAME, REPORTER) \ | 147 #define REQUIRE_PDF_DOCUMENT(TEST_NAME, REPORTER) \ |
106 do { \ | 148 do { \ |
107 SkDynamicMemoryWStream testStream; \ | 149 SkDynamicMemoryWStream testStream; \ |
108 SkAutoTUnref<SkDocument> testDoc(SkDocument::CreatePDF(&testStream)); \ | 150 SkAutoTUnref<SkDocument> testDoc(SkDocument::CreatePDF(&testStream)); \ |
109 if (!testDoc) { \ | 151 if (!testDoc) { \ |
110 if ((REPORTER) && (REPORTER)->verbose()) { \ | 152 if ((REPORTER) && (REPORTER)->verbose()) { \ |
111 SkDebugf("PDF disabled; %s test skipped.", #TEST_NAME); \ | 153 SkDebugf("PDF disabled; %s test skipped.", #TEST_NAME); \ |
112 } \ | 154 } \ |
113 return; \ | 155 return; \ |
114 } \ | 156 } \ |
115 } while (false) | 157 } while (false) |
116 | 158 |
117 #endif | 159 #endif |
OLD | NEW |