| 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 13 matching lines...) Expand all Loading... |
| 24 SK_DECLARE_INST_COUNT(Reporter) | 24 SK_DECLARE_INST_COUNT(Reporter) |
| 25 Reporter(); | 25 Reporter(); |
| 26 | 26 |
| 27 enum Result { | 27 enum Result { |
| 28 kPassed, // must begin with 0 | 28 kPassed, // must begin with 0 |
| 29 kFailed, | 29 kFailed, |
| 30 ///// | 30 ///// |
| 31 kLastResult = kFailed | 31 kLastResult = kFailed |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 void resetReporting(); | |
| 35 void bumpTestCount() { sk_atomic_inc(&fTestCount); } | 34 void bumpTestCount() { sk_atomic_inc(&fTestCount); } |
| 36 int countTests() const { return fTestCount; } | 35 int countTests() const { return fTestCount; } |
| 37 int countResults(Result r) { | |
| 38 SkASSERT((unsigned)r <= kLastResult); | |
| 39 return fResultCount[r]; | |
| 40 } | |
| 41 | 36 |
| 42 void startTest(Test*); | 37 void startTest(Test*); |
| 43 void report(const char testDesc[], Result); | 38 void report(const char testDesc[], Result); |
| 44 void endTest(Test*); | 39 void endTest(Test*); |
| 45 virtual bool allowExtendedTest() const { return false; } | 40 virtual bool allowExtendedTest() const { return false; } |
| 46 virtual bool allowThreaded() const { return false; } | 41 virtual bool allowThreaded() const { return false; } |
| 47 // helpers for tests | 42 // helpers for tests |
| 48 void assertTrue(bool cond, const char desc[]) { | |
| 49 if (!cond) { | |
| 50 this->report(desc, kFailed); | |
| 51 } | |
| 52 } | |
| 53 void assertFalse(bool cond, const char desc[]) { | |
| 54 if (cond) { | |
| 55 this->report(desc, kFailed); | |
| 56 } | |
| 57 } | |
| 58 void reportFailed(const char desc[]) { | 43 void reportFailed(const char desc[]) { |
| 59 this->report(desc, kFailed); | 44 this->report(desc, kFailed); |
| 60 } | 45 } |
| 61 void reportFailed(const SkString& desc) { | 46 void reportFailed(const SkString& desc) { |
| 62 this->report(desc.c_str(), kFailed); | 47 this->report(desc.c_str(), kFailed); |
| 63 } | 48 } |
| 64 | 49 |
| 65 bool getCurrSuccess() const { | |
| 66 return fCurrTestSuccess; | |
| 67 } | |
| 68 | 50 |
| 69 protected: | 51 protected: |
| 70 virtual void onStart(Test*) {} | 52 virtual void onStart(Test*) {} |
| 71 virtual void onReport(const char desc[], Result) {} | 53 virtual void onReport(const char desc[], Result) {} |
| 72 virtual void onEnd(Test*) {} | 54 virtual void onEnd(Test*) {} |
| 73 | 55 |
| 74 private: | 56 private: |
| 75 Test* fCurrTest; | 57 int32_t fTestCount; |
| 76 int fTestCount; | |
| 77 int fResultCount[kLastResult+1]; | |
| 78 bool fCurrTestSuccess; | |
| 79 | 58 |
| 80 typedef SkRefCnt INHERITED; | 59 typedef SkRefCnt INHERITED; |
| 81 }; | 60 }; |
| 82 | 61 |
| 83 class Test { | 62 class Test { |
| 84 public: | 63 public: |
| 85 Test(); | 64 Test(); |
| 86 virtual ~Test(); | 65 virtual ~Test(); |
| 87 | 66 |
| 88 Reporter* getReporter() const { return fReporter; } | 67 Reporter* getReporter() const { return fReporter; } |
| 89 void setReporter(Reporter*); | 68 void setReporter(Reporter*); |
| 90 | 69 |
| 91 const char* getName(); | 70 const char* getName(); |
| 92 bool run(); // returns true on success | 71 void run(); |
| 72 bool passed() const { return fPassed; } |
| 93 | 73 |
| 94 static const SkString& GetTmpDir(); | 74 static const SkString& GetTmpDir(); |
| 95 | 75 |
| 96 static const SkString& GetResourcePath(); | 76 static const SkString& GetResourcePath(); |
| 97 | 77 |
| 78 virtual bool isThreadsafe() const { return true; } |
| 79 |
| 98 protected: | 80 protected: |
| 99 virtual void onGetName(SkString*) = 0; | 81 virtual void onGetName(SkString*) = 0; |
| 100 virtual void onRun(Reporter*) = 0; | 82 virtual void onRun(Reporter*) = 0; |
| 101 | 83 |
| 102 private: | 84 private: |
| 103 Reporter* fReporter; | 85 Reporter* fReporter; |
| 104 SkString fName; | 86 SkString fName; |
| 87 bool fPassed; |
| 105 }; | 88 }; |
| 106 | 89 |
| 107 class GpuTest : public Test{ | 90 class GpuTest : public Test{ |
| 108 public: | 91 public: |
| 109 GpuTest() : Test() {} | 92 GpuTest() : Test() {} |
| 110 static GrContextFactory* GetGrContextFactory(); | 93 static GrContextFactory* GetGrContextFactory(); |
| 111 static void DestroyContexts(); | 94 static void DestroyContexts(); |
| 95 virtual bool isThreadsafe() const { return false; } |
| 112 private: | 96 private: |
| 113 }; | 97 }; |
| 114 | 98 |
| 115 typedef SkTRegistry<Test*, void*> TestRegistry; | 99 typedef SkTRegistry<Test*, void*> TestRegistry; |
| 116 } | 100 } |
| 117 | 101 |
| 118 #define REPORTER_ASSERT(r, cond) \ | 102 #define REPORTER_ASSERT(r, cond) \ |
| 119 do { \ | 103 do { \ |
| 120 if (!(cond)) { \ | 104 if (!(cond)) { \ |
| 121 SkString desc; \ | 105 SkString desc; \ |
| 122 desc.printf("%s:%d: %s", __FILE__, __LINE__, #cond); \ | 106 desc.printf("%s:%d: %s", __FILE__, __LINE__, #cond); \ |
| 123 r->reportFailed(desc); \ | 107 r->reportFailed(desc); \ |
| 124 } \ | 108 } \ |
| 125 } while(0) | 109 } while(0) |
| 126 | 110 |
| 127 #define REPORTER_ASSERT_MESSAGE(r, cond, message) \ | 111 #define REPORTER_ASSERT_MESSAGE(r, cond, message) \ |
| 128 do { \ | 112 do { \ |
| 129 if (!(cond)) { \ | 113 if (!(cond)) { \ |
| 130 SkString desc; \ | 114 SkString desc; \ |
| 131 desc.printf("%s %s:%d: %s", message, __FILE__, __LINE__, #cond); \ | 115 desc.printf("%s %s:%d: %s", message, __FILE__, __LINE__, #cond); \ |
| 132 r->reportFailed(desc); \ | 116 r->reportFailed(desc); \ |
| 133 } \ | 117 } \ |
| 134 } while(0) | 118 } while(0) |
| 135 | 119 |
| 136 | 120 |
| 137 #endif | 121 #endif |
| OLD | NEW |