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 "SkRefCnt.h" | 11 #include "SkRefCnt.h" |
12 #include "SkString.h" | 12 #include "SkString.h" |
13 #include "SkTRegistry.h" | 13 #include "SkTRegistry.h" |
14 #include "SkThread.h" | 14 #include "SkThread.h" |
15 #include "SkTypes.h" | 15 #include "SkTypes.h" |
16 | 16 |
17 class GrContextFactory; | 17 class GrContextFactory; |
18 | 18 |
19 namespace skiatest { | 19 namespace skiatest { |
20 | 20 |
21 class Test; | 21 class Test; |
22 | 22 |
23 struct Failure { | |
24 SkString fileName; | |
mtklein
2014/11/06 15:24:05
Given that you know filename and condition are goi
scroggo
2014/11/06 16:52:33
To be fair, someone *could* skip the macro and cre
| |
25 int lineNo; | |
26 SkString condition; | |
27 SkString message; | |
28 | |
29 // Helper to combine the failure message into one string. | |
30 static void GetFailureString(SkString* result, const Failure& failure) { | |
mtklein
2014/11/06 15:24:05
Seems like this is simpler as SkString getFailureS
scroggo
2014/11/06 16:52:33
Definitely simpler.
FWIW, I almost made it an out
| |
31 if (!result) { | |
32 return; | |
33 } | |
34 result->printf("%s:%d\t", failure.fileName.c_str(), failure.lineNo); | |
35 if (!failure.message.isEmpty()) { | |
36 if (!failure.condition.isEmpty()) { | |
37 result->appendf("%s: %s", failure.message.c_str(), failure.c ondition.c_str()); | |
38 } else { | |
39 result->append(failure.message); | |
40 } | |
41 } else if (!failure.condition.isEmpty()) { | |
42 // Condition, but no message. | |
43 result->append(failure.condition); | |
44 } | |
45 } | |
46 }; | |
47 | |
48 | |
23 class Reporter : public SkRefCnt { | 49 class Reporter : public SkRefCnt { |
24 public: | 50 public: |
25 SK_DECLARE_INST_COUNT(Reporter) | 51 SK_DECLARE_INST_COUNT(Reporter) |
26 Reporter(); | 52 Reporter(); |
27 | 53 |
28 int countTests() const { return fTestCount; } | 54 int countTests() const { return fTestCount; } |
29 | 55 |
30 void startTest(Test*); | 56 void startTest(Test*); |
31 void reportFailed(const SkString& desc); | 57 void reportFailed(const Failure&); |
32 void endTest(Test*); | 58 void endTest(Test*); |
33 | 59 |
34 virtual bool allowExtendedTest() const { return false; } | 60 virtual bool allowExtendedTest() const { return false; } |
35 virtual bool verbose() const { return false; } | 61 virtual bool verbose() const { return false; } |
36 virtual void bumpTestCount() { sk_atomic_inc(&fTestCount); } | 62 virtual void bumpTestCount() { sk_atomic_inc(&fTestCount); } |
37 | 63 |
38 protected: | 64 protected: |
39 virtual void onStart(Test*) {} | 65 virtual void onStart(Test*) {} |
40 virtual void onReportFailed(const SkString& desc) {} | 66 virtual void onReportFailed(const Failure&) {} |
41 virtual void onEnd(Test*) {} | 67 virtual void onEnd(Test*) {} |
42 | 68 |
43 private: | 69 private: |
44 int32_t fTestCount; | 70 int32_t fTestCount; |
45 | 71 |
46 typedef SkRefCnt INHERITED; | 72 typedef SkRefCnt INHERITED; |
47 }; | 73 }; |
48 | 74 |
49 class Test { | 75 class Test { |
50 public: | 76 public: |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 REPORTER_ASSERT_MESSAGE(reporter, x == 15, "x should be 15"); | 129 REPORTER_ASSERT_MESSAGE(reporter, x == 15, "x should be 15"); |
104 ... | 130 ... |
105 if (x != 15) { | 131 if (x != 15) { |
106 ERRORF(reporter, "x should be 15, but is %d", x); | 132 ERRORF(reporter, "x should be 15, but is %d", x); |
107 return; | 133 return; |
108 } | 134 } |
109 ... | 135 ... |
110 } | 136 } |
111 */ | 137 */ |
112 | 138 |
113 #define REPORTER_ASSERT(r, cond) \ | 139 #define REPORTER_ASSERT(r, cond) \ |
114 do { \ | 140 do { \ |
115 if (!(cond)) { \ | 141 if (!(cond)) { \ |
116 SkString desc; \ | 142 skiatest::Failure failure = { SkString(__FILE__), __LINE__, \ |
117 desc.printf("%s:%d\t%s", __FILE__, __LINE__, #cond); \ | 143 SkString(#cond), \ |
118 r->reportFailed(desc); \ | 144 SkString() }; \ |
119 } \ | 145 r->reportFailed(failure); \ |
146 } \ | |
120 } while(0) | 147 } while(0) |
121 | 148 |
122 #define REPORTER_ASSERT_MESSAGE(r, cond, message) \ | 149 #define REPORTER_ASSERT_MESSAGE(r, cond, message) \ |
123 do { \ | 150 do { \ |
124 if (!(cond)) { \ | 151 if (!(cond)) { \ |
125 SkString desc; \ | 152 skiatest::Failure failure = { SkString(__FILE__), __LINE__, \ |
126 desc.printf("%s:%d\t%s: %s", __FILE__, __LINE__, \ | 153 SkString(#cond), \ |
127 message, #cond); \ | 154 SkString(message) }; \ |
128 r->reportFailed(desc); \ | 155 r->reportFailed(failure); \ |
129 } \ | 156 } \ |
130 } while(0) | 157 } while(0) |
131 | 158 |
132 #define ERRORF(reporter, ...) \ | 159 #define ERRORF(r, ...) \ |
133 do { \ | 160 do { \ |
134 SkString desc; \ | 161 SkString desc; \ |
135 desc.printf("%s:%d\t", __FILE__, __LINE__); \ | 162 desc.appendf(__VA_ARGS__) ; \ |
136 desc.appendf(__VA_ARGS__) ; \ | 163 skiatest::Failure failure = { SkString(__FILE__), __LINE__, \ |
137 (reporter)->reportFailed(desc); \ | 164 SkString(), \ |
mtklein
2014/11/06 15:24:05
Might want something like "<ERRORF>" or "unconditi
scroggo
2014/11/06 16:52:32
I'm not sure that adds any more information. The o
| |
165 SkString(desc) }; \ | |
166 r->reportFailed(failure); \ | |
138 } while(0) | 167 } while(0) |
139 | 168 |
140 #define DEF_TEST(name, reporter) \ | 169 #define DEF_TEST(name, reporter) \ |
141 static void test_##name(skiatest::Reporter*); \ | 170 static void test_##name(skiatest::Reporter*); \ |
142 namespace skiatest { \ | 171 namespace skiatest { \ |
143 class name##Class : public Test { \ | 172 class name##Class : public Test { \ |
144 public: \ | 173 public: \ |
145 static Test* Factory(void*) { return SkNEW(name##Class); } \ | 174 static Test* Factory(void*) { return SkNEW(name##Class); } \ |
146 protected: \ | 175 protected: \ |
147 virtual void onGetName(SkString* name) SK_OVERRIDE { \ | 176 virtual void onGetName(SkString* name) SK_OVERRIDE { \ |
(...skipping 17 matching lines...) Expand all Loading... | |
165 } \ | 194 } \ |
166 virtual void onRun(Reporter* r) SK_OVERRIDE { \ | 195 virtual void onRun(Reporter* r) SK_OVERRIDE { \ |
167 test_##name(r, fGrContextFactory); \ | 196 test_##name(r, fGrContextFactory); \ |
168 } \ | 197 } \ |
169 }; \ | 198 }; \ |
170 static TestRegistry gReg_##name##Class(name##Class::Factory); \ | 199 static TestRegistry gReg_##name##Class(name##Class::Factory); \ |
171 } \ | 200 } \ |
172 static void test_##name(skiatest::Reporter* reporter, GrContextFactory* fact ory) | 201 static void test_##name(skiatest::Reporter* reporter, GrContextFactory* fact ory) |
173 | 202 |
174 #endif | 203 #endif |
OLD | NEW |