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-03-07 03:39:23 +00:00
|
|
|
#include "SkGraphics.h"
|
2009-02-27 16:24:51 +00:00
|
|
|
#include "Test.h"
|
|
|
|
|
|
|
|
using namespace skiatest;
|
|
|
|
|
2009-04-01 18:31:44 +00:00
|
|
|
// need to explicitly declare this, or we get some weird infinite loop llist
|
|
|
|
template TestRegistry* TestRegistry::gHead;
|
|
|
|
|
2009-02-27 16:24:51 +00:00
|
|
|
class Iter {
|
|
|
|
public:
|
|
|
|
Iter(Reporter* r) : fReporter(r) {
|
|
|
|
r->ref();
|
|
|
|
fReg = TestRegistry::Head();
|
|
|
|
}
|
2009-04-02 16:59:40 +00:00
|
|
|
|
2009-02-27 16:24:51 +00:00
|
|
|
~Iter() {
|
|
|
|
fReporter->unref();
|
|
|
|
}
|
2009-04-02 16:59:40 +00:00
|
|
|
|
2009-02-27 16:24:51 +00:00
|
|
|
Test* next() {
|
|
|
|
if (fReg) {
|
|
|
|
TestRegistry::Factory fact = fReg->factory();
|
|
|
|
fReg = fReg->next();
|
|
|
|
Test* test = fact(NULL);
|
|
|
|
test->setReporter(fReporter);
|
|
|
|
return test;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-04-02 16:59:40 +00:00
|
|
|
|
2009-04-01 20:26:42 +00:00
|
|
|
static int Count() {
|
|
|
|
const TestRegistry* reg = TestRegistry::Head();
|
|
|
|
int count = 0;
|
|
|
|
while (reg) {
|
|
|
|
count += 1;
|
|
|
|
reg = reg->next();
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
2009-04-02 16:59:40 +00:00
|
|
|
|
2009-02-27 16:24:51 +00:00
|
|
|
private:
|
|
|
|
Reporter* fReporter;
|
|
|
|
const TestRegistry* fReg;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* result2string(Reporter::Result result) {
|
|
|
|
return result == Reporter::kPassed ? "passed" : "FAILED";
|
|
|
|
}
|
|
|
|
|
2009-04-01 18:31:44 +00:00
|
|
|
class DebugfReporter : public Reporter {
|
2009-04-01 20:26:42 +00:00
|
|
|
public:
|
2009-04-09 04:06:54 +00:00
|
|
|
DebugfReporter(bool androidMode) : fAndroidMode(androidMode) {}
|
|
|
|
|
2009-04-01 20:26:42 +00:00
|
|
|
void setIndexOfTotal(int index, int total) {
|
|
|
|
fIndex = index;
|
|
|
|
fTotal = total;
|
|
|
|
}
|
2009-02-27 16:24:51 +00:00
|
|
|
protected:
|
|
|
|
virtual void onStart(Test* test) {
|
2009-04-09 04:06:54 +00:00
|
|
|
this->dumpState(test, kStarting_State);
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
|
|
|
virtual void onReport(const char desc[], Reporter::Result result) {
|
2009-04-09 04:06:54 +00:00
|
|
|
if (!fAndroidMode) {
|
|
|
|
SkDebugf("\t%s: %s\n", result2string(result), desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virtual void onEnd(Test* test) {
|
|
|
|
this->dumpState(test, this->getCurrSuccess() ?
|
|
|
|
kSucceeded_State : kFailed_State);
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
2009-04-01 20:26:42 +00:00
|
|
|
private:
|
2009-04-09 04:06:54 +00:00
|
|
|
enum State {
|
|
|
|
kStarting_State = 1,
|
|
|
|
kSucceeded_State = 0,
|
|
|
|
kFailed_State = -2
|
|
|
|
};
|
|
|
|
|
|
|
|
void dumpState(Test* test, State state) {
|
|
|
|
if (fAndroidMode) {
|
|
|
|
SkDebugf("INSTRUMENTATION_STATUS: test=%s\n", test->getName());
|
|
|
|
SkDebugf("INSTRUMENTATION_STATUS: class=com.skia\n");
|
|
|
|
SkDebugf("INSTRUMENTATION_STATUS: current=%d\n", fIndex+1);
|
|
|
|
SkDebugf("INSTRUMENTATION_STATUS: numtests=%d\n", fTotal);
|
|
|
|
SkDebugf("INSTRUMENTATION_STATUS_CODE: %d\n", state);
|
|
|
|
} else {
|
|
|
|
if (kStarting_State == state) {
|
|
|
|
SkDebugf("[%d/%d] %s...\n", fIndex+1, fTotal, test->getName());
|
|
|
|
} else if (kFailed_State == state) {
|
|
|
|
SkDebugf("---- FAILED\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-01 20:26:42 +00:00
|
|
|
int fIndex, fTotal;
|
2009-04-09 04:06:54 +00:00
|
|
|
bool fAndroidMode;
|
2009-02-27 16:24:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int main (int argc, char * const argv[]) {
|
2009-03-07 03:39:23 +00:00
|
|
|
SkAutoGraphics ag;
|
2009-04-09 04:06:54 +00:00
|
|
|
|
|
|
|
bool androidMode = false;
|
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
if (!strcmp(argv[i], "-android")) {
|
|
|
|
androidMode = true;
|
|
|
|
}
|
|
|
|
}
|
2009-03-07 03:39:23 +00:00
|
|
|
|
2009-04-09 04:06:54 +00:00
|
|
|
DebugfReporter reporter(androidMode);
|
2009-02-27 16:24:51 +00:00
|
|
|
Iter iter(&reporter);
|
|
|
|
Test* test;
|
2009-04-02 16:59:40 +00:00
|
|
|
|
2009-04-01 20:26:42 +00:00
|
|
|
const int count = Iter::Count();
|
|
|
|
int index = 0;
|
2009-04-09 04:06:54 +00:00
|
|
|
int successCount = 0;
|
2009-02-27 16:24:51 +00:00
|
|
|
while ((test = iter.next()) != NULL) {
|
2009-04-01 20:26:42 +00:00
|
|
|
reporter.setIndexOfTotal(index, count);
|
2009-04-09 04:06:54 +00:00
|
|
|
successCount += test->run();
|
2009-02-27 16:24:51 +00:00
|
|
|
SkDELETE(test);
|
2009-04-01 20:26:42 +00:00
|
|
|
index += 1;
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
2009-04-09 04:06:54 +00:00
|
|
|
|
|
|
|
if (!androidMode) {
|
|
|
|
SkDebugf("Finished %d tests, %d failures.\n", count,
|
|
|
|
count - successCount);
|
|
|
|
}
|
2011-05-13 19:26:48 +00:00
|
|
|
return (count == successCount) ? 0 : 1;
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|