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 // Run the test. | |
81 LocalReporter local; | |
82 this->onRun(&local); | |
scroggo
2013/04/17 17:34:52
Does anyone depend on the ordering between onRun a
mtklein
2013/04/17 18:13:59
Nope. Actually, this is a good point. Moving the
| |
83 fPassed = local.failure_size() == 0; | |
84 | |
85 // Now all at once pretend the test is running for the benefit of fReporter. | |
79 fReporter->startTest(this); | 86 fReporter->startTest(this); |
80 this->onRun(fReporter); | 87 for (int i = 0; i < local.failure_size(); i++) { |
88 fReporter->report(local.failure(i), Reporter::kFailed); | |
89 } | |
81 fReporter->endTest(this); | 90 fReporter->endTest(this); |
82 return fReporter->getCurrSuccess(); | |
83 } | 91 } |
84 | 92 |
85 /////////////////////////////////////////////////////////////////////////////// | 93 /////////////////////////////////////////////////////////////////////////////// |
86 | 94 |
87 #if SK_SUPPORT_GPU | 95 #if SK_SUPPORT_GPU |
88 #include "GrContextFactory.h" | 96 #include "GrContextFactory.h" |
89 GrContextFactory gGrContextFactory; | 97 GrContextFactory gGrContextFactory; |
90 #endif | 98 #endif |
91 | 99 |
92 GrContextFactory* GpuTest::GetGrContextFactory() { | 100 GrContextFactory* GpuTest::GetGrContextFactory() { |
93 #if SK_SUPPORT_GPU | 101 #if SK_SUPPORT_GPU |
94 return &gGrContextFactory; | 102 return &gGrContextFactory; |
95 #else | 103 #else |
96 return NULL; | 104 return NULL; |
97 #endif | 105 #endif |
98 } | 106 } |
99 | 107 |
100 void GpuTest::DestroyContexts() { | 108 void GpuTest::DestroyContexts() { |
101 #if SK_SUPPORT_GPU | 109 #if SK_SUPPORT_GPU |
102 gGrContextFactory.destroyContexts(); | 110 gGrContextFactory.destroyContexts(); |
103 #endif | 111 #endif |
104 } | 112 } |
OLD | NEW |