reed@google.com | 81e3d7f | 2011-06-01 12:42:36 +0000 | [diff] [blame] | 1 | utils#include "SampleCode.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | #include "SkView.h" |
| 3 | #include "SkCanvas.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 4 | |
| 5 | #include "test.h" |
| 6 | |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 7 | namespace skiatest { |
| 8 | |
| 9 | class MyReporter : public Reporter { |
| 10 | protected: |
| 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 | |
| 18 | class Iter { |
| 19 | public: |
| 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 | |
| 50 | private: |
| 51 | Reporter* fReporter; |
| 52 | const TestRegistry* fReg; |
| 53 | }; |
| 54 | } |
| 55 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 56 | class TestsView : public SkView { |
| 57 | public: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 58 | TestsView() {} |
| 59 | |
| 60 | protected: |
| 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); |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 76 | |
| 77 | skiatest::MyReporter reporter; |
| 78 | skiatest::Iter iter(&reporter); |
| 79 | skiatest::Test* test; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 80 | |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 81 | while ((test = iter.next()) != NULL) { |
| 82 | test->run(); |
| 83 | SkDELETE(test); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 84 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | |
| 103 | private: |
| 104 | typedef SkView INHERITED; |
| 105 | }; |
| 106 | |
| 107 | ////////////////////////////////////////////////////////////////////////////// |
| 108 | |
| 109 | static SkView* MyFactory() { return new TestsView; } |
| 110 | static SkViewRegister reg(MyFactory); |
| 111 | |