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