blob: 5542bf6216b40fbde844b9839b3695364f4da247 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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 */
reed@google.com81e3d7f2011-06-01 12:42:36 +00008utils#include "SampleCode.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +00009#include "SkView.h"
10#include "SkCanvas.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000011
12#include "test.h"
13
reed@google.com04863fa2011-05-15 04:08:24 +000014namespace skiatest {
15
16class MyReporter : public Reporter {
17protected:
18 virtual void onStart(Test* test) {}
19 virtual void onReport(const char desc[], Reporter::Result result) {
20 SkASSERT(Reporter::kPassed == result);
21 }
22 virtual void onEnd(Test* test) {}
23};
24
25class Iter {
26public:
27 Iter(Reporter* r) : fReporter(r) {
28 r->ref();
29 fReg = TestRegistry::Head();
30 }
31
32 ~Iter() {
33 fReporter->unref();
34 }
35
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
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
57private:
58 Reporter* fReporter;
59 const TestRegistry* fReg;
60};
61}
62
reed@android.com8a1c16f2008-12-17 15:59:43 +000063class TestsView : public SkView {
64public:
reed@android.com8a1c16f2008-12-17 15:59:43 +000065 TestsView() {}
66
67protected:
68 // overrides from SkEventSink
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
77 void drawBG(SkCanvas* canvas) {
78 canvas->drawColor(SK_ColorWHITE);
79 }
80
81 virtual void onDraw(SkCanvas* canvas) {
82 this->drawBG(canvas);
reed@google.com04863fa2011-05-15 04:08:24 +000083
84 skiatest::MyReporter reporter;
85 skiatest::Iter iter(&reporter);
86 skiatest::Test* test;
reed@android.com8a1c16f2008-12-17 15:59:43 +000087
reed@google.com04863fa2011-05-15 04:08:24 +000088 while ((test = iter.next()) != NULL) {
89 test->run();
90 SkDELETE(test);
reed@android.com8a1c16f2008-12-17 15:59:43 +000091 }
reed@android.com8a1c16f2008-12-17 15:59:43 +000092 }
93
94 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) {
95 this->inval(NULL);
96
97 return this->INHERITED::onFindClickHandler(x, y);
98 }
99
100 virtual bool onClick(Click* click) {
101 this->inval(NULL);
102 return this->INHERITED::onClick(click);
103 }
104
105 virtual bool handleKey(SkKey key) {
106 this->inval(NULL);
107 return true;
108 }
109
110private:
111 typedef SkView INHERITED;
112};
113
114//////////////////////////////////////////////////////////////////////////////
115
116static SkView* MyFactory() { return new TestsView; }
117static SkViewRegister reg(MyFactory);
118