reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 1 | #include "Test.h" |
| 2 | |
| 3 | using namespace skiatest; |
| 4 | |
| 5 | Reporter::Reporter() { |
| 6 | this->resetReporting(); |
| 7 | } |
| 8 | |
| 9 | void Reporter::resetReporting() { |
| 10 | fCurrTest = NULL; |
| 11 | fTestCount = 0; |
reed@android.com | 4516f47 | 2009-06-29 16:25:36 +0000 | [diff] [blame] | 12 | sk_bzero(fResultCount, sizeof(fResultCount)); |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 13 | } |
| 14 | |
| 15 | void Reporter::startTest(Test* test) { |
| 16 | SkASSERT(NULL == fCurrTest); |
| 17 | fCurrTest = test; |
| 18 | this->onStart(test); |
| 19 | fTestCount += 1; |
reed@android.com | eeb3b7f | 2009-04-09 04:06:54 +0000 | [diff] [blame] | 20 | fCurrTestSuccess = true; // we're optimistic |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | void Reporter::report(const char desc[], Result result) { |
| 24 | if (NULL == desc) { |
| 25 | desc = "<no description>"; |
| 26 | } |
| 27 | this->onReport(desc, result); |
| 28 | fResultCount[result] += 1; |
reed@android.com | eeb3b7f | 2009-04-09 04:06:54 +0000 | [diff] [blame] | 29 | if (kFailed == result) { |
| 30 | fCurrTestSuccess = false; |
| 31 | } |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | void Reporter::endTest(Test* test) { |
| 35 | SkASSERT(test == fCurrTest); |
| 36 | this->onEnd(test); |
| 37 | fCurrTest = NULL; |
| 38 | } |
| 39 | |
| 40 | /////////////////////////////////////////////////////////////////////////////// |
| 41 | |
| 42 | Test::Test() : fReporter(NULL) {} |
| 43 | |
| 44 | Test::~Test() { |
| 45 | fReporter->safeUnref(); |
| 46 | } |
| 47 | |
| 48 | void Test::setReporter(Reporter* r) { |
| 49 | SkRefCnt_SafeAssign(fReporter, r); |
| 50 | } |
| 51 | |
| 52 | const char* Test::getName() { |
| 53 | if (fName.size() == 0) { |
| 54 | this->onGetName(&fName); |
| 55 | } |
| 56 | return fName.c_str(); |
| 57 | } |
| 58 | |
reed@android.com | eeb3b7f | 2009-04-09 04:06:54 +0000 | [diff] [blame] | 59 | bool Test::run() { |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 60 | fReporter->startTest(this); |
| 61 | this->onRun(fReporter); |
| 62 | fReporter->endTest(this); |
reed@android.com | eeb3b7f | 2009-04-09 04:06:54 +0000 | [diff] [blame] | 63 | return fReporter->getCurrSuccess(); |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 64 | } |
| 65 | |