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 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 class GpuTest : public Test{ | 80 class GpuTest : public Test{ |
81 public: | 81 public: |
82 GpuTest() : Test() {} | 82 GpuTest() : Test() {} |
83 static GrContextFactory* GetGrContextFactory(); | 83 static GrContextFactory* GetGrContextFactory(); |
84 static void DestroyContexts(); | 84 static void DestroyContexts(); |
85 virtual bool isThreadsafe() const { return false; } | 85 virtual bool isThreadsafe() const { return false; } |
86 private: | 86 private: |
87 }; | 87 }; |
88 | 88 |
89 typedef SkTRegistry<Test*(*)(void*)> TestRegistry; | 89 typedef SkTRegistry<Test*(*)(void*)> TestRegistry; |
90 } | 90 } // namespace skiatest |
| 91 |
| 92 /* |
| 93 Use the following macros to make use of the skiatest classes, e.g. |
| 94 |
| 95 #include "Test.h" |
| 96 |
| 97 DEF_TEST(TestName, reporter) { |
| 98 ... |
| 99 REPORTER_ASSERT(reporter, x == 15); |
| 100 ... |
| 101 REPORTER_ASSERT_MESSAGE(reporter, x == 15, "x should be 15"); |
| 102 ... |
| 103 if (x != 15) { |
| 104 ERRORF(reporter, "x should be 15, but is %d", x); |
| 105 return; |
| 106 } |
| 107 ... |
| 108 } |
| 109 */ |
91 | 110 |
92 #define REPORTER_ASSERT(r, cond) \ | 111 #define REPORTER_ASSERT(r, cond) \ |
93 do { \ | 112 do { \ |
94 if (!(cond)) { \ | 113 if (!(cond)) { \ |
95 SkString desc; \ | 114 SkString desc; \ |
96 desc.printf("%s:%d\t%s", __FILE__, __LINE__, #cond); \ | 115 desc.printf("%s:%d\t%s", __FILE__, __LINE__, #cond); \ |
97 r->reportFailed(desc); \ | 116 r->reportFailed(desc); \ |
98 } \ | 117 } \ |
99 } while(0) | 118 } while(0) |
100 | 119 |
101 #define REPORTER_ASSERT_MESSAGE(r, cond, message) \ | 120 #define REPORTER_ASSERT_MESSAGE(r, cond, message) \ |
102 do { \ | 121 do { \ |
103 if (!(cond)) { \ | 122 if (!(cond)) { \ |
104 SkString desc; \ | 123 SkString desc; \ |
105 desc.printf("%s:%d\t%s: %s", __FILE__, __LINE__, \ | 124 desc.printf("%s:%d\t%s: %s", __FILE__, __LINE__, \ |
106 message, #cond); \ | 125 message, #cond); \ |
107 r->reportFailed(desc); \ | 126 r->reportFailed(desc); \ |
108 } \ | 127 } \ |
109 } while(0) | 128 } while(0) |
110 | 129 |
111 #define ERRORF(reporter, ...) \ | 130 #define ERRORF(reporter, ...) \ |
112 do { \ | 131 do { \ |
113 SkString desc; \ | 132 SkString desc; \ |
114 desc.printf("%s:%d\t", __FILE__, __LINE__); \ | 133 desc.printf("%s:%d\t", __FILE__, __LINE__); \ |
115 desc.appendf(__VA_ARGS__) ; \ | 134 desc.appendf(__VA_ARGS__) ; \ |
116 (reporter)->reportFailed(desc); \ | 135 (reporter)->reportFailed(desc); \ |
117 } while(0) | 136 } while(0) |
118 | 137 |
| 138 #define DEF_TEST(name, reporter) \ |
| 139 static void name(skiatest::Reporter*); \ |
| 140 namespace skiatest { \ |
| 141 class name##Class : public Test { \ |
| 142 public: \ |
| 143 static Test* Factory(void*) { return SkNEW(name##Class); } \ |
| 144 protected: \ |
| 145 virtual void onGetName(SkString* name) SK_OVERRIDE { \ |
| 146 name->set(#name); \ |
| 147 } \ |
| 148 virtual void onRun(Reporter* r) SK_OVERRIDE { name(r); } \ |
| 149 }; \ |
| 150 static TestRegistry gReg_##name##Class(name##Class::Factory); \ |
| 151 } \ |
| 152 static void name(skiatest::Reporter* reporter) |
| 153 |
| 154 #define DEF_GPUTEST(name, reporter, factory) \ |
| 155 static void name(skiatest::Reporter*, GrContextFactory*); \ |
| 156 namespace skiatest { \ |
| 157 class name##Class : public GpuTest { \ |
| 158 public: \ |
| 159 static Test* Factory(void*) { return SkNEW(name##Class); } \ |
| 160 protected: \ |
| 161 virtual void onGetName(SkString* name) SK_OVERRIDE { \ |
| 162 name->set(#name); \ |
| 163 } \ |
| 164 virtual void onRun(Reporter* r) SK_OVERRIDE { \ |
| 165 name(r, GetGrContextFactory()); \ |
| 166 } \ |
| 167 }; \ |
| 168 static TestRegistry gReg_##name##Class(name##Class::Factory); \ |
| 169 } \ |
| 170 static void name(skiatest::Reporter* reporter, GrContextFactory* factory) |
| 171 |
119 #endif | 172 #endif |
OLD | NEW |