1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
/****************************************************************************
**
** Copyright (C) 1992-$THISYEAR$ $TROLLTECH$. All rights reserved.
**
** This file is part of the $MODULE$ of the Qt Toolkit.
**
** $TROLLTECH_DUAL_LICENSE$
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#ifndef QFXTESTER_H
#define QFXTESTER_H
#include <QEvent>
#include <QMouseEvent>
#include <QKeyEvent>
#include <qmlviewer.h>
QT_BEGIN_NAMESPACE
class QFxVisualTest : public QObject
{
Q_OBJECT
Q_PROPERTY(QList<QObject *>* events READ events CONSTANT)
Q_CLASSINFO("DefaultProperty", "events")
public:
QFxVisualTest() {}
QList<QObject *> *events() { return &m_events; }
int count() const { return m_events.count(); }
QObject *event(int idx) { return m_events.at(idx); }
private:
QList<QObject *> m_events;
};
QML_DECLARE_TYPE(QFxVisualTest)
class QFxVisualTestFrame : public QObject
{
Q_OBJECT
Q_PROPERTY(int msec READ msec WRITE setMsec)
Q_PROPERTY(QString hash READ hash WRITE setHash)
Q_PROPERTY(QString image READ image WRITE setImage)
public:
QFxVisualTestFrame() : m_msec(-1) {}
int msec() const { return m_msec; }
void setMsec(int m) { m_msec = m; }
QString hash() const { return m_hash; }
void setHash(const QString &hash) { m_hash = hash; }
QString image() const { return m_image; }
void setImage(const QString &image) { m_image = image; }
private:
int m_msec;
QString m_hash;
QString m_image;
};
QML_DECLARE_TYPE(QFxVisualTestFrame)
class QFxVisualTestMouse : public QObject
{
Q_OBJECT
Q_PROPERTY(int type READ type WRITE setType)
Q_PROPERTY(int button READ button WRITE setButton)
Q_PROPERTY(int buttons READ buttons WRITE setButtons)
Q_PROPERTY(int x READ x WRITE setX)
Q_PROPERTY(int y READ y WRITE setY)
Q_PROPERTY(int modifiers READ modifiers WRITE setModifiers)
Q_PROPERTY(bool sendToViewport READ sendToViewport WRITE setSendToViewport)
public:
QFxVisualTestMouse() : m_type(0), m_button(0), m_buttons(0), m_x(0), m_y(0), m_modifiers(0), m_viewport(false) {}
int type() const { return m_type; }
void setType(int t) { m_type = t; }
int button() const { return m_button; }
void setButton(int b) { m_button = b; }
int buttons() const { return m_buttons; }
void setButtons(int b) { m_buttons = b; }
int x() const { return m_x; }
void setX(int x) { m_x = x; }
int y() const { return m_y; }
void setY(int y) { m_y = y; }
int modifiers() const { return m_modifiers; }
void setModifiers(int modifiers) { m_modifiers = modifiers; }
bool sendToViewport() const { return m_viewport; }
void setSendToViewport(bool v) { m_viewport = v; }
private:
int m_type;
int m_button;
int m_buttons;
int m_x;
int m_y;
int m_modifiers;
bool m_viewport;
};
QML_DECLARE_TYPE(QFxVisualTestMouse)
class QFxVisualTestKey : public QObject
{
Q_OBJECT
Q_PROPERTY(int type READ type WRITE setType)
Q_PROPERTY(int key READ key WRITE setKey)
Q_PROPERTY(int modifiers READ modifiers WRITE setModifiers)
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(bool autorep READ autorep WRITE setAutorep)
Q_PROPERTY(int count READ count WRITE setCount)
Q_PROPERTY(bool sendToViewport READ sendToViewport WRITE setSendToViewport)
public:
QFxVisualTestKey() : m_type(0), m_key(0), m_modifiers(0), m_autorep(false), m_count(0), m_viewport(false) {}
int type() const { return m_type; }
void setType(int t) { m_type = t; }
int key() const { return m_key; }
void setKey(int k) { m_key = k; }
int modifiers() const { return m_modifiers; }
void setModifiers(int m) { m_modifiers = m; }
QString text() const { return m_text; }
void setText(const QString &t) { m_text = t; }
bool autorep() const { return m_autorep; }
void setAutorep(bool a) { m_autorep = a; }
int count() const { return m_count; }
void setCount(int c) { m_count = c; }
bool sendToViewport() const { return m_viewport; }
void setSendToViewport(bool v) { m_viewport = v; }
private:
int m_type;
int m_key;
int m_modifiers;
QString m_text;
bool m_autorep;
int m_count;
bool m_viewport;
};
QML_DECLARE_TYPE(QFxVisualTestKey)
class QFxTester : public QAbstractAnimation
{
public:
QFxTester(const QString &script, QmlViewer::ScriptOptions options, QmlView *parent);
virtual int duration() const;
void run(const QString &);
void save(const QString &);
void executefailure();
protected:
virtual void updateCurrentTime(int msecs);
virtual bool eventFilter(QObject *, QEvent *);
private:
void imagefailure();
void complete();
enum Destination { View, ViewPort };
void addKeyEvent(Destination, QKeyEvent *);
void addMouseEvent(Destination, QMouseEvent *);
QmlView *m_view;
struct MouseEvent {
MouseEvent(QMouseEvent *e)
: type(e->type()), button(e->button()), buttons(e->buttons()),
pos(e->pos()), modifiers(e->modifiers()), destination(View) {}
QEvent::Type type;
Qt::MouseButton button;
Qt::MouseButtons buttons;
QPoint pos;
Qt::KeyboardModifiers modifiers;
Destination destination;
int msec;
};
struct KeyEvent {
KeyEvent(QKeyEvent *e)
: type(e->type()), key(e->key()), modifiers(e->modifiers()), text(e->text()),
autorep(e->isAutoRepeat()), count(e->count()), destination(View) {}
QEvent::Type type;
int key;
Qt::KeyboardModifiers modifiers;
QString text;
bool autorep;
ushort count;
Destination destination;
int msec;
};
struct FrameEvent {
QImage image;
QByteArray hash;
int msec;
};
QList<MouseEvent> m_mouseEvents;
QList<KeyEvent> m_keyEvents;
QList<MouseEvent> m_savedMouseEvents;
QList<KeyEvent> m_savedKeyEvents;
QList<FrameEvent> m_savedFrameEvents;
bool filterEvents;
QmlViewer::ScriptOptions options;
int testscriptidx;
QFxVisualTest *testscript;
bool hasFailed;
};
QT_END_NAMESPACE
#endif // QFXTESTER_H
|