blob: 4bbe83a33d7eea4a1f1bf9e104dfe223f509b201 [file] [log] [blame]
reed@android.comed673312009-02-27 16:24:51 +00001#include "Test.h"
2
3using namespace skiatest;
4
5Reporter::Reporter() {
6 this->resetReporting();
7}
8
9void Reporter::resetReporting() {
10 fCurrTest = NULL;
11 fTestCount = 0;
reed@android.com4516f472009-06-29 16:25:36 +000012 sk_bzero(fResultCount, sizeof(fResultCount));
reed@android.comed673312009-02-27 16:24:51 +000013}
14
15void Reporter::startTest(Test* test) {
16 SkASSERT(NULL == fCurrTest);
17 fCurrTest = test;
18 this->onStart(test);
19 fTestCount += 1;
reed@android.comeeb3b7f2009-04-09 04:06:54 +000020 fCurrTestSuccess = true; // we're optimistic
reed@android.comed673312009-02-27 16:24:51 +000021}
22
23void 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.comeeb3b7f2009-04-09 04:06:54 +000029 if (kFailed == result) {
30 fCurrTestSuccess = false;
31 }
reed@android.comed673312009-02-27 16:24:51 +000032}
33
34void Reporter::endTest(Test* test) {
35 SkASSERT(test == fCurrTest);
36 this->onEnd(test);
37 fCurrTest = NULL;
38}
39
40///////////////////////////////////////////////////////////////////////////////
41
42Test::Test() : fReporter(NULL) {}
43
44Test::~Test() {
45 fReporter->safeUnref();
46}
47
48void Test::setReporter(Reporter* r) {
49 SkRefCnt_SafeAssign(fReporter, r);
50}
51
52const char* Test::getName() {
53 if (fName.size() == 0) {
54 this->onGetName(&fName);
55 }
56 return fName.c_str();
57}
58
reed@android.comeeb3b7f2009-04-09 04:06:54 +000059bool Test::run() {
reed@android.comed673312009-02-27 16:24:51 +000060 fReporter->startTest(this);
61 this->onRun(fReporter);
62 fReporter->endTest(this);
reed@android.comeeb3b7f2009-04-09 04:06:54 +000063 return fReporter->getCurrSuccess();
reed@android.comed673312009-02-27 16:24:51 +000064}
65