2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2009-02-27 16:24:51 +00:00
|
|
|
#include "Test.h"
|
|
|
|
|
2011-08-16 15:45:58 +00:00
|
|
|
#include "GrContext.h"
|
2011-10-13 13:33:08 +00:00
|
|
|
#include "SkGLContext.h"
|
2011-08-16 15:45:58 +00:00
|
|
|
#include "SkTLazy.h"
|
|
|
|
|
2009-02-27 16:24:51 +00:00
|
|
|
using namespace skiatest;
|
|
|
|
|
|
|
|
Reporter::Reporter() {
|
|
|
|
this->resetReporting();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Reporter::resetReporting() {
|
|
|
|
fCurrTest = NULL;
|
|
|
|
fTestCount = 0;
|
2009-06-29 16:25:36 +00:00
|
|
|
sk_bzero(fResultCount, sizeof(fResultCount));
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Reporter::startTest(Test* test) {
|
|
|
|
SkASSERT(NULL == fCurrTest);
|
|
|
|
fCurrTest = test;
|
|
|
|
this->onStart(test);
|
|
|
|
fTestCount += 1;
|
2009-04-09 04:06:54 +00:00
|
|
|
fCurrTestSuccess = true; // we're optimistic
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Reporter::report(const char desc[], Result result) {
|
|
|
|
if (NULL == desc) {
|
|
|
|
desc = "<no description>";
|
|
|
|
}
|
|
|
|
this->onReport(desc, result);
|
|
|
|
fResultCount[result] += 1;
|
2009-04-09 04:06:54 +00:00
|
|
|
if (kFailed == result) {
|
|
|
|
fCurrTestSuccess = false;
|
|
|
|
}
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Reporter::endTest(Test* test) {
|
|
|
|
SkASSERT(test == fCurrTest);
|
|
|
|
this->onEnd(test);
|
|
|
|
fCurrTest = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
Test::Test() : fReporter(NULL) {}
|
|
|
|
|
|
|
|
Test::~Test() {
|
2011-02-07 15:30:46 +00:00
|
|
|
SkSafeUnref(fReporter);
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Test::setReporter(Reporter* r) {
|
|
|
|
SkRefCnt_SafeAssign(fReporter, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* Test::getName() {
|
|
|
|
if (fName.size() == 0) {
|
|
|
|
this->onGetName(&fName);
|
|
|
|
}
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2009-04-09 04:06:54 +00:00
|
|
|
bool Test::run() {
|
2009-02-27 16:24:51 +00:00
|
|
|
fReporter->startTest(this);
|
|
|
|
this->onRun(fReporter);
|
|
|
|
fReporter->endTest(this);
|
2009-04-09 04:06:54 +00:00
|
|
|
return fReporter->getCurrSuccess();
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
|
|
|
|
2011-08-16 15:45:58 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
GrContext* GpuTest::GetContext() {
|
|
|
|
// preserve this order, we want gGrContext destroyed after gEGLContext
|
2011-10-13 13:33:08 +00:00
|
|
|
static SkTLazy<SkGLContext> gGLContext;
|
2011-08-16 15:45:58 +00:00
|
|
|
static SkAutoTUnref<GrContext> gGrContext;
|
|
|
|
|
|
|
|
if (NULL == gGrContext.get()) {
|
2011-10-13 13:33:08 +00:00
|
|
|
gGLContext.init();
|
|
|
|
if (gGLContext.get()->init(800, 600)) {
|
2011-08-16 15:45:58 +00:00
|
|
|
gGrContext.reset(GrContext::Create(kOpenGL_Shaders_GrEngine, NULL));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return gGrContext.get();
|
|
|
|
}
|
|
|
|
|