1utils#include "SampleCode.h" 2#include "SkView.h" 3#include "SkCanvas.h" 4 5#include "test.h" 6 7namespace skiatest { 8 9class MyReporter : public Reporter { 10protected: 11 virtual void onStart(Test* test) {} 12 virtual void onReport(const char desc[], Reporter::Result result) { 13 SkASSERT(Reporter::kPassed == result); 14 } 15 virtual void onEnd(Test* test) {} 16}; 17 18class Iter { 19public: 20 Iter(Reporter* r) : fReporter(r) { 21 r->ref(); 22 fReg = TestRegistry::Head(); 23 } 24 25 ~Iter() { 26 fReporter->unref(); 27 } 28 29 Test* next() { 30 if (fReg) { 31 TestRegistry::Factory fact = fReg->factory(); 32 fReg = fReg->next(); 33 Test* test = fact(NULL); 34 test->setReporter(fReporter); 35 return test; 36 } 37 return NULL; 38 } 39 40 static int Count() { 41 const TestRegistry* reg = TestRegistry::Head(); 42 int count = 0; 43 while (reg) { 44 count += 1; 45 reg = reg->next(); 46 } 47 return count; 48 } 49 50private: 51 Reporter* fReporter; 52 const TestRegistry* fReg; 53}; 54} 55 56class TestsView : public SkView { 57public: 58 TestsView() {} 59 60protected: 61 // overrides from SkEventSink 62 virtual bool onQuery(SkEvent* evt) { 63 if (SampleCode::TitleQ(*evt)) { 64 SampleCode::TitleR(evt, "Tests"); 65 return true; 66 } 67 return this->INHERITED::onQuery(evt); 68 } 69 70 void drawBG(SkCanvas* canvas) { 71 canvas->drawColor(SK_ColorWHITE); 72 } 73 74 virtual void onDraw(SkCanvas* canvas) { 75 this->drawBG(canvas); 76 77 skiatest::MyReporter reporter; 78 skiatest::Iter iter(&reporter); 79 skiatest::Test* test; 80 81 while ((test = iter.next()) != NULL) { 82 test->run(); 83 SkDELETE(test); 84 } 85 } 86 87 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) { 88 this->inval(NULL); 89 90 return this->INHERITED::onFindClickHandler(x, y); 91 } 92 93 virtual bool onClick(Click* click) { 94 this->inval(NULL); 95 return this->INHERITED::onClick(click); 96 } 97 98 virtual bool handleKey(SkKey key) { 99 this->inval(NULL); 100 return true; 101 } 102 103private: 104 typedef SkView INHERITED; 105}; 106 107////////////////////////////////////////////////////////////////////////////// 108 109static SkView* MyFactory() { return new TestsView; } 110static SkViewRegister reg(MyFactory); 111 112