| 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 /** |
| 24 * Information about a single failure from a Test. |
| 25 * |
| 26 * Not intended to be created/modified directly. To create one, use one of |
| 27 * |
| 28 * REPORTER_ASSERT |
| 29 * REPORTER_ASSERT_MESSAGE |
| 30 * ERRORF |
| 31 * |
| 32 * described in more detail further down in this file. |
| 33 */ |
| 34 struct Failure { |
| 35 const char* fileName; |
| 36 int lineNo; |
| 37 const char* condition; |
| 38 SkString message; |
| 39 |
| 40 // Helper to combine the failure info into one string. |
| 41 void getFailureString(SkString* result) const { |
| 42 if (!result) { |
| 43 return; |
| 44 } |
| 45 result->printf("%s:%d\t", fileName, lineNo); |
| 46 if (!message.isEmpty()) { |
| 47 result->append(message); |
| 48 if (strlen(condition) > 0) { |
| 49 result->append(": "); |
| 50 } |
| 51 } |
| 52 result->append(condition); |
| 53 } |
| 54 }; |
| 55 |
| 56 |
| 23 class Reporter : public SkRefCnt { | 57 class Reporter : public SkRefCnt { |
| 24 public: | 58 public: |
| 25 SK_DECLARE_INST_COUNT(Reporter) | 59 SK_DECLARE_INST_COUNT(Reporter) |
| 26 Reporter(); | 60 Reporter(); |
| 27 | 61 |
| 28 int countTests() const { return fTestCount; } | 62 int countTests() const { return fTestCount; } |
| 29 | 63 |
| 30 void startTest(Test*); | 64 void startTest(Test*); |
| 31 void reportFailed(const SkString& desc); | 65 void reportFailed(const Failure&); |
| 32 void endTest(Test*); | 66 void endTest(Test*); |
| 33 | 67 |
| 34 virtual bool allowExtendedTest() const { return false; } | 68 virtual bool allowExtendedTest() const { return false; } |
| 35 virtual bool verbose() const { return false; } | 69 virtual bool verbose() const { return false; } |
| 36 virtual void bumpTestCount() { sk_atomic_inc(&fTestCount); } | 70 virtual void bumpTestCount() { sk_atomic_inc(&fTestCount); } |
| 37 | 71 |
| 38 protected: | 72 protected: |
| 39 virtual void onStart(Test*) {} | 73 virtual void onStart(Test*) {} |
| 40 virtual void onReportFailed(const SkString& desc) {} | 74 virtual void onReportFailed(const Failure&) {} |
| 41 virtual void onEnd(Test*) {} | 75 virtual void onEnd(Test*) {} |
| 42 | 76 |
| 43 private: | 77 private: |
| 44 int32_t fTestCount; | 78 int32_t fTestCount; |
| 45 | 79 |
| 46 typedef SkRefCnt INHERITED; | 80 typedef SkRefCnt INHERITED; |
| 47 }; | 81 }; |
| 48 | 82 |
| 49 class Test { | 83 class Test { |
| 50 public: | 84 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"); | 137 REPORTER_ASSERT_MESSAGE(reporter, x == 15, "x should be 15"); |
| 104 ... | 138 ... |
| 105 if (x != 15) { | 139 if (x != 15) { |
| 106 ERRORF(reporter, "x should be 15, but is %d", x); | 140 ERRORF(reporter, "x should be 15, but is %d", x); |
| 107 return; | 141 return; |
| 108 } | 142 } |
| 109 ... | 143 ... |
| 110 } | 144 } |
| 111 */ | 145 */ |
| 112 | 146 |
| 113 #define REPORTER_ASSERT(r, cond) \ | 147 #define REPORTER_ASSERT(r, cond) \ |
| 114 do { \ | 148 do { \ |
| 115 if (!(cond)) { \ | 149 if (!(cond)) { \ |
| 116 SkString desc; \ | 150 skiatest::Failure failure = { __FILE__, __LINE__, \ |
| 117 desc.printf("%s:%d\t%s", __FILE__, __LINE__, #cond); \ | 151 #cond, SkString() }; \ |
| 118 r->reportFailed(desc); \ | 152 r->reportFailed(failure); \ |
| 119 } \ | 153 } \ |
| 120 } while(0) | 154 } while(0) |
| 121 | 155 |
| 122 #define REPORTER_ASSERT_MESSAGE(r, cond, message) \ | 156 #define REPORTER_ASSERT_MESSAGE(r, cond, message) \ |
| 123 do { \ | 157 do { \ |
| 124 if (!(cond)) { \ | 158 if (!(cond)) { \ |
| 125 SkString desc; \ | 159 skiatest::Failure failure = { __FILE__, __LINE__, \ |
| 126 desc.printf("%s:%d\t%s: %s", __FILE__, __LINE__, \ | 160 #cond, SkString(message) }; \ |
| 127 message, #cond); \ | 161 r->reportFailed(failure); \ |
| 128 r->reportFailed(desc); \ | 162 } \ |
| 129 } \ | |
| 130 } while(0) | 163 } while(0) |
| 131 | 164 |
| 132 #define ERRORF(reporter, ...) \ | 165 #define ERRORF(r, ...) \ |
| 133 do { \ | 166 do { \ |
| 134 SkString desc; \ | 167 SkString desc; \ |
| 135 desc.printf("%s:%d\t", __FILE__, __LINE__); \ | 168 desc.appendf(__VA_ARGS__) ; \ |
| 136 desc.appendf(__VA_ARGS__) ; \ | 169 skiatest::Failure failure = { __FILE__, __LINE__, \ |
| 137 (reporter)->reportFailed(desc); \ | 170 "", SkString(desc) }; \ |
| 171 r->reportFailed(failure); \ |
| 138 } while(0) | 172 } while(0) |
| 139 | 173 |
| 140 #define DEF_TEST(name, reporter) \ | 174 #define DEF_TEST(name, reporter) \ |
| 141 static void test_##name(skiatest::Reporter*); \ | 175 static void test_##name(skiatest::Reporter*); \ |
| 142 namespace skiatest { \ | 176 namespace skiatest { \ |
| 143 class name##Class : public Test { \ | 177 class name##Class : public Test { \ |
| 144 public: \ | 178 public: \ |
| 145 static Test* Factory(void*) { return SkNEW(name##Class); } \ | 179 static Test* Factory(void*) { return SkNEW(name##Class); } \ |
| 146 protected: \ | 180 protected: \ |
| 147 virtual void onGetName(SkString* name) SK_OVERRIDE { \ | 181 virtual void onGetName(SkString* name) SK_OVERRIDE { \ |
| (...skipping 17 matching lines...) Expand all Loading... |
| 165 } \ | 199 } \ |
| 166 virtual void onRun(Reporter* r) SK_OVERRIDE { \ | 200 virtual void onRun(Reporter* r) SK_OVERRIDE { \ |
| 167 test_##name(r, fGrContextFactory); \ | 201 test_##name(r, fGrContextFactory); \ |
| 168 } \ | 202 } \ |
| 169 }; \ | 203 }; \ |
| 170 static TestRegistry gReg_##name##Class(name##Class::Factory); \ | 204 static TestRegistry gReg_##name##Class(name##Class::Factory); \ |
| 171 } \ | 205 } \ |
| 172 static void test_##name(skiatest::Reporter* reporter, GrContextFactory* fact
ory) | 206 static void test_##name(skiatest::Reporter* reporter, GrContextFactory* fact
ory) |
| 173 | 207 |
| 174 #endif | 208 #endif |
| OLD | NEW |