OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Test.h" | 8 #include "Test.h" |
9 | 9 |
10 #include "SkCommandLineFlags.h" | 10 #include "SkCommandLineFlags.h" |
11 #include "SkError.h" | 11 #include "SkError.h" |
12 #include "SkString.h" | 12 #include "SkString.h" |
13 #include "SkTArray.h" | |
14 #include "SkTime.h" | 13 #include "SkTime.h" |
15 | 14 |
16 #if SK_SUPPORT_GPU | |
17 #include "GrContext.h" | |
18 #include "gl/SkGLContext.h" | |
19 #else | |
20 class GrContext; | |
21 #endif | |
22 | |
23 DEFINE_string2(tmpDir, t, NULL, "tmp directory for tests to use."); | |
24 | |
25 using namespace skiatest; | 15 using namespace skiatest; |
mtklein
2015/01/15 23:46:46
Remove this or remove all the skiatest:: below?
hal.canary
2015/01/16 15:31:57
Done.
| |
26 | 16 |
27 Reporter::Reporter() : fTestCount(0) { | 17 skiatest::Reporter::~Reporter() { |
mtklein
2015/01/15 23:46:46
Any reason we don't just put this little nothing d
hal.canary
2015/01/16 15:31:57
Done.
| |
28 } | 18 } |
29 | 19 |
30 void Reporter::startTest(Test* test) { | 20 SkString skiatest::FailureToString(const skiatest::Failure& failure) { |
31 this->onStart(test); | 21 SkString result = |
22 SkStringPrintf("%s:%d\t", failure.fileName, failure.lineNo); | |
23 if (!failure.message.isEmpty()) { | |
24 result.append(failure.message); | |
25 if (strlen(failure.condition) > 0) { | |
26 result.append(": "); | |
27 } | |
28 } | |
29 result.append(failure.condition); | |
30 return result; | |
32 } | 31 } |
33 | 32 |
34 void Reporter::reportFailed(const skiatest::Failure& failure) { | 33 // SkMSec skiatest::TimeTest(const skiatest::Test& test, |
35 this->onReportFailed(failure); | 34 // Reporter* reporter, |
mtklein
2015/01/15 23:46:46
Yeah, die die die.
hal.canary
2015/01/16 15:31:57
Done.
| |
36 } | 35 // GrContextFactory* grContextFactory) { |
37 | 36 // SkASSERT(grContextFactory || !test.needsGpu) |
38 void Reporter::endTest(Test* test) { | 37 // // Clear the Skia error callback before running any test, to |
39 this->onEnd(test); | 38 // // ensure that tests don't have unintended side effects when |
40 } | 39 // // running more than one. |
41 | 40 // SkSetErrorCallback(NULL, NULL); |
42 /////////////////////////////////////////////////////////////////////////////// | 41 // const SkMSec start = SkTime::GetMSecs(); |
43 | 42 // test.proc(reporter, grContextFactory); |
44 Test::Test() : fReporter(NULL), fPassed(true) {} | 43 // return SkTime::GetMSecs() - start; |
45 | 44 // } |
46 Test::~Test() { | |
47 SkSafeUnref(fReporter); | |
48 } | |
49 | |
50 void Test::setReporter(Reporter* r) { | |
51 SkRefCnt_SafeAssign(fReporter, r); | |
52 } | |
53 | |
54 const char* Test::getName() { | |
55 if (fName.size() == 0) { | |
56 this->onGetName(&fName); | |
57 } | |
58 return fName.c_str(); | |
59 } | |
60 | |
61 class LocalReporter : public Reporter { | |
62 public: | |
63 explicit LocalReporter(Reporter* reporterToMimic) : fReporter(reporterToMimi c) {} | |
64 | |
65 int numFailures() const { return fFailures.count(); } | |
66 const skiatest::Failure& failure(int i) const { return fFailures[i]; } | |
67 | |
68 protected: | |
69 void onReportFailed(const Failure& failure) SK_OVERRIDE { | |
70 fFailures.push_back(failure); | |
71 } | |
72 | |
73 // Proxy down to fReporter. We assume these calls are threadsafe. | |
74 bool allowExtendedTest() const SK_OVERRIDE { | |
75 return fReporter->allowExtendedTest(); | |
76 } | |
77 | |
78 void bumpTestCount() SK_OVERRIDE { | |
79 fReporter->bumpTestCount(); | |
80 } | |
81 | |
82 bool verbose() const SK_OVERRIDE { | |
83 return fReporter->verbose(); | |
84 } | |
85 | |
86 private: | |
87 Reporter* fReporter; // Unowned. | |
88 SkTArray<skiatest::Failure> fFailures; | |
89 }; | |
90 | |
91 void Test::run() { | |
92 // Clear the Skia error callback before running any test, to ensure that tes ts | |
93 // don't have unintended side effects when running more than one. | |
94 SkSetErrorCallback( NULL, NULL ); | |
95 | |
96 // Tell (likely shared) fReporter that this test has started. | |
97 fReporter->startTest(this); | |
98 | |
99 const SkMSec start = SkTime::GetMSecs(); | |
100 // Run the test into a LocalReporter so we know if it's passed or failed wit hout interference | |
101 // from other tests that might share fReporter. | |
102 LocalReporter local(fReporter); | |
103 this->onRun(&local); | |
104 fPassed = local.numFailures() == 0; | |
105 fElapsed = SkTime::GetMSecs() - start; | |
106 | |
107 // Now tell fReporter about any failures and wrap up. | |
108 for (int i = 0; i < local.numFailures(); i++) { | |
109 fReporter->reportFailed(local.failure(i)); | |
110 } | |
111 fReporter->endTest(this); | |
112 | |
113 } | |
114 | |
115 SkString Test::GetTmpDir() { | |
116 const char* tmpDir = FLAGS_tmpDir.isEmpty() ? NULL : FLAGS_tmpDir[0]; | |
117 return SkString(tmpDir); | |
118 } | |
OLD | NEW |