reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame^] | 1 | #include <iostream> |
| 2 | |
| 3 | #include "Test.h" |
| 4 | |
| 5 | using namespace skiatest; |
| 6 | |
| 7 | class Iter { |
| 8 | public: |
| 9 | Iter(Reporter* r) : fReporter(r) { |
| 10 | r->ref(); |
| 11 | fReg = TestRegistry::Head(); |
| 12 | } |
| 13 | |
| 14 | ~Iter() { |
| 15 | fReporter->unref(); |
| 16 | } |
| 17 | |
| 18 | Test* next() { |
| 19 | if (fReg) { |
| 20 | TestRegistry::Factory fact = fReg->factory(); |
| 21 | fReg = fReg->next(); |
| 22 | Test* test = fact(NULL); |
| 23 | test->setReporter(fReporter); |
| 24 | return test; |
| 25 | } |
| 26 | return NULL; |
| 27 | } |
| 28 | |
| 29 | private: |
| 30 | Reporter* fReporter; |
| 31 | const TestRegistry* fReg; |
| 32 | }; |
| 33 | |
| 34 | static const char* result2string(Reporter::Result result) { |
| 35 | return result == Reporter::kPassed ? "passed" : "FAILED"; |
| 36 | } |
| 37 | |
| 38 | class PrintfReporter : public Reporter { |
| 39 | protected: |
| 40 | virtual void onStart(Test* test) { |
| 41 | printf("Running %s...\n", test->getName()); |
| 42 | } |
| 43 | virtual void onReport(const char desc[], Reporter::Result result) { |
| 44 | printf("\t%s: %s\n", result2string(result), desc); |
| 45 | } |
| 46 | virtual void onEnd(Test* test) {} |
| 47 | }; |
| 48 | |
| 49 | int main (int argc, char * const argv[]) { |
| 50 | PrintfReporter reporter; |
| 51 | Iter iter(&reporter); |
| 52 | Test* test; |
| 53 | |
| 54 | while ((test = iter.next()) != NULL) { |
| 55 | test->run(); |
| 56 | SkDELETE(test); |
| 57 | } |
| 58 | |
| 59 | int total = reporter.countTests(); |
| 60 | int passed = reporter.countResults(Reporter::kPassed); |
| 61 | int failed = reporter.countResults(Reporter::kFailed); |
| 62 | printf("Tests=%d Passed=%d (%g%%) Failed=%d (%g%%)\n", total, |
| 63 | passed, passed * 100.f / total, |
| 64 | failed, failed * 100.f / total); |
| 65 | |
| 66 | return 0; |
| 67 | } |