2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
10 #include "SkCommandLineFlags.h"
17 #include "GrContext.h"
18 #include "gl/SkNativeGLContext.h"
23 DEFINE_string2(tmpDir, t, NULL, "tmp directory for tests to use.");
25 using namespace skiatest;
27 Reporter::Reporter() : fTestCount(0) {
30 void Reporter::startTest(Test* test) {
34 void Reporter::reportFailed(const SkString& desc) {
35 this->onReportFailed(desc);
38 void Reporter::endTest(Test* test) {
42 ///////////////////////////////////////////////////////////////////////////////
44 Test::Test() : fReporter(NULL), fPassed(true) {}
47 SkSafeUnref(fReporter);
50 void Test::setReporter(Reporter* r) {
51 SkRefCnt_SafeAssign(fReporter, r);
54 const char* Test::getName() {
55 if (fName.size() == 0) {
56 this->onGetName(&fName);
61 class LocalReporter : public Reporter {
63 explicit LocalReporter(Reporter* reporterToMimic) : fReporter(reporterToMimic) {}
65 int numFailures() const { return fFailures.count(); }
66 const SkString& failure(int i) const { return fFailures[i]; }
69 virtual void onReportFailed(const SkString& desc) SK_OVERRIDE {
70 fFailures.push_back(desc);
73 // Proxy down to fReporter. We assume these calls are threadsafe.
74 virtual bool allowExtendedTest() const SK_OVERRIDE {
75 return fReporter->allowExtendedTest();
78 virtual void bumpTestCount() SK_OVERRIDE {
79 fReporter->bumpTestCount();
82 virtual bool verbose() const SK_OVERRIDE {
83 return fReporter->verbose();
87 Reporter* fReporter; // Unowned.
88 SkTArray<SkString> fFailures;
92 // Clear the Skia error callback before running any test, to ensure that tests
93 // don't have unintended side effects when running more than one.
94 SkSetErrorCallback( NULL, NULL );
96 // Tell (likely shared) fReporter that this test has started.
97 fReporter->startTest(this);
99 const SkMSec start = SkTime::GetMSecs();
100 // Run the test into a LocalReporter so we know if it's passed or failed without interference
101 // from other tests that might share fReporter.
102 LocalReporter local(fReporter);
104 fPassed = local.numFailures() == 0;
105 fElapsed = SkTime::GetMSecs() - start;
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));
111 fReporter->endTest(this);
115 SkString Test::GetTmpDir() {
116 const char* tmpDir = FLAGS_tmpDir.isEmpty() ? NULL : FLAGS_tmpDir[0];
117 return SkString(tmpDir);