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:
|
|
|
|
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-01 20:26:42 +00:00
|
|
|
SkDebugf("Running [%d/%d] %s...\n", fIndex+1, fTotal, test->getName());
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
|
|
|
virtual void onReport(const char desc[], Reporter::Result result) {
|
2009-04-01 18:31:44 +00:00
|
|
|
SkDebugf("\t%s: %s\n", result2string(result), desc);
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
|
|
|
virtual void onEnd(Test* test) {}
|
2009-04-01 20:26:42 +00:00
|
|
|
private:
|
|
|
|
int fIndex, fTotal;
|
2009-02-27 16:24:51 +00:00
|
|
|
};
|
|
|
|
|
2009-03-07 03:39:23 +00:00
|
|
|
class SkAutoGraphics {
|
|
|
|
public:
|
|
|
|
SkAutoGraphics() {
|
|
|
|
SkGraphics::Init();
|
|
|
|
}
|
|
|
|
~SkAutoGraphics() {
|
|
|
|
SkGraphics::Term();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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-01 18:31:44 +00:00
|
|
|
DebugfReporter reporter;
|
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-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-02-27 16:24:51 +00:00
|
|
|
test->run();
|
|
|
|
SkDELETE(test);
|
2009-04-01 20:26:42 +00:00
|
|
|
index += 1;
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
2009-04-01 20:26:42 +00:00
|
|
|
SkDebugf("Finished %d tests.\n", count);
|
|
|
|
|
|
|
|
#if 0
|
2009-02-27 16:24:51 +00:00
|
|
|
int total = reporter.countTests();
|
|
|
|
int passed = reporter.countResults(Reporter::kPassed);
|
|
|
|
int failed = reporter.countResults(Reporter::kFailed);
|
2009-04-01 18:31:44 +00:00
|
|
|
SkDebugf("Tests=%d Passed=%d (%g%%) Failed=%d (%g%%)\n", total,
|
2009-02-27 16:24:51 +00:00
|
|
|
passed, passed * 100.f / total,
|
|
|
|
failed, failed * 100.f / total);
|
2009-04-01 20:26:42 +00:00
|
|
|
#endif
|
2009-02-27 16:24:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|