| 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 #include "Test.h" | 8 #include "Test.h" |
| 9 | 9 |
| 10 #include "SkTLazy.h" | 10 #include "SkString.h" |
| 11 #include "SkTArray.h" |
| 11 | 12 |
| 12 #if SK_SUPPORT_GPU | 13 #if SK_SUPPORT_GPU |
| 13 #include "GrContext.h" | 14 #include "GrContext.h" |
| 14 #include "gl/SkNativeGLContext.h" | 15 #include "gl/SkNativeGLContext.h" |
| 15 #else | 16 #else |
| 16 class GrContext; | 17 class GrContext; |
| 17 #endif | 18 #endif |
| 18 | 19 |
| 19 SK_DEFINE_INST_COUNT(skiatest::Reporter) | 20 SK_DEFINE_INST_COUNT(skiatest::Reporter) |
| 20 | 21 |
| 21 using namespace skiatest; | 22 using namespace skiatest; |
| 22 | 23 |
| 23 Reporter::Reporter() | 24 Reporter::Reporter() : fTestCount(0) { |
| 24 : fTestCount(0) { | |
| 25 this->resetReporting(); | |
| 26 } | |
| 27 | |
| 28 void Reporter::resetReporting() { | |
| 29 fCurrTest = NULL; | |
| 30 fTestCount = 0; | |
| 31 sk_bzero(fResultCount, sizeof(fResultCount)); | |
| 32 } | 25 } |
| 33 | 26 |
| 34 void Reporter::startTest(Test* test) { | 27 void Reporter::startTest(Test* test) { |
| 35 SkASSERT(NULL == fCurrTest); | 28 this->bumpTestCount(); |
| 36 fCurrTest = test; | |
| 37 this->onStart(test); | 29 this->onStart(test); |
| 38 fTestCount += 1; | |
| 39 fCurrTestSuccess = true; // we're optimistic | |
| 40 } | 30 } |
| 41 | 31 |
| 42 void Reporter::report(const char desc[], Result result) { | 32 void Reporter::report(const char desc[], Result result) { |
| 43 if (NULL == desc) { | 33 this->onReport(desc ? desc : "<no description>", result); |
| 44 desc = "<no description>"; | |
| 45 } | |
| 46 this->onReport(desc, result); | |
| 47 fResultCount[result] += 1; | |
| 48 if (kFailed == result) { | |
| 49 fCurrTestSuccess = false; | |
| 50 } | |
| 51 } | 34 } |
| 52 | 35 |
| 53 void Reporter::endTest(Test* test) { | 36 void Reporter::endTest(Test* test) { |
| 54 SkASSERT(test == fCurrTest); | |
| 55 this->onEnd(test); | 37 this->onEnd(test); |
| 56 fCurrTest = NULL; | |
| 57 } | 38 } |
| 58 | 39 |
| 59 /////////////////////////////////////////////////////////////////////////////// | 40 /////////////////////////////////////////////////////////////////////////////// |
| 60 | 41 |
| 61 Test::Test() : fReporter(NULL) {} | 42 Test::Test() : fReporter(NULL), fPassed(true) {} |
| 62 | 43 |
| 63 Test::~Test() { | 44 Test::~Test() { |
| 64 SkSafeUnref(fReporter); | 45 SkSafeUnref(fReporter); |
| 65 } | 46 } |
| 66 | 47 |
| 67 void Test::setReporter(Reporter* r) { | 48 void Test::setReporter(Reporter* r) { |
| 68 SkRefCnt_SafeAssign(fReporter, r); | 49 SkRefCnt_SafeAssign(fReporter, r); |
| 69 } | 50 } |
| 70 | 51 |
| 71 const char* Test::getName() { | 52 const char* Test::getName() { |
| 72 if (fName.size() == 0) { | 53 if (fName.size() == 0) { |
| 73 this->onGetName(&fName); | 54 this->onGetName(&fName); |
| 74 } | 55 } |
| 75 return fName.c_str(); | 56 return fName.c_str(); |
| 76 } | 57 } |
| 77 | 58 |
| 78 bool Test::run() { | 59 namespace { |
| 60 class LocalReporter : public Reporter { |
| 61 public: |
| 62 LocalReporter() {} |
| 63 |
| 64 int failure_size() const { return fFailures.count(); } |
| 65 const char* failure(int i) const { return fFailures[i].c_str(); } |
| 66 |
| 67 protected: |
| 68 void onReport(const char desc[], Result result) SK_OVERRIDE { |
| 69 if (kFailed == result) { |
| 70 fFailures.push_back().set(desc); |
| 71 } |
| 72 } |
| 73 |
| 74 private: |
| 75 SkTArray<SkString> fFailures; |
| 76 }; |
| 77 } // namespace |
| 78 |
| 79 void Test::run() { |
| 80 // Tell (likely shared) fReporter that this test has started. |
| 79 fReporter->startTest(this); | 81 fReporter->startTest(this); |
| 80 this->onRun(fReporter); | 82 |
| 83 // Run the test into a LocalReporter so we know if it's passed or failed wit
hout interference |
| 84 // from other tests that might share fReporter. |
| 85 LocalReporter local; |
| 86 this->onRun(&local); |
| 87 fPassed = local.failure_size() == 0; |
| 88 |
| 89 // Now tell fReporter about any failures and wrap up. |
| 90 for (int i = 0; i < local.failure_size(); i++) { |
| 91 fReporter->report(local.failure(i), Reporter::kFailed); |
| 92 } |
| 81 fReporter->endTest(this); | 93 fReporter->endTest(this); |
| 82 return fReporter->getCurrSuccess(); | |
| 83 } | 94 } |
| 84 | 95 |
| 85 /////////////////////////////////////////////////////////////////////////////// | 96 /////////////////////////////////////////////////////////////////////////////// |
| 86 | 97 |
| 87 #if SK_SUPPORT_GPU | 98 #if SK_SUPPORT_GPU |
| 88 #include "GrContextFactory.h" | 99 #include "GrContextFactory.h" |
| 89 GrContextFactory gGrContextFactory; | 100 GrContextFactory gGrContextFactory; |
| 90 #endif | 101 #endif |
| 91 | 102 |
| 92 GrContextFactory* GpuTest::GetGrContextFactory() { | 103 GrContextFactory* GpuTest::GetGrContextFactory() { |
| 93 #if SK_SUPPORT_GPU | 104 #if SK_SUPPORT_GPU |
| 94 return &gGrContextFactory; | 105 return &gGrContextFactory; |
| 95 #else | 106 #else |
| 96 return NULL; | 107 return NULL; |
| 97 #endif | 108 #endif |
| 98 } | 109 } |
| 99 | 110 |
| 100 void GpuTest::DestroyContexts() { | 111 void GpuTest::DestroyContexts() { |
| 101 #if SK_SUPPORT_GPU | 112 #if SK_SUPPORT_GPU |
| 102 gGrContextFactory.destroyContexts(); | 113 gGrContextFactory.destroyContexts(); |
| 103 #endif | 114 #endif |
| 104 } | 115 } |
| OLD | NEW |