Qt 4.8
qtestaccessible.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtTest module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QTESTACCESSIBLE_H
43 #define QTESTACCESSIBLE_H
44 
45 #if 0
46 // inform syncqt
47 #pragma qt_no_master_include
48 #endif
49 
50 #ifndef QT_NO_ACCESSIBILITY
51 
52 #define QTEST_ACCESSIBILITY
53 
54 #define QVERIFY_EVENT(object, child, event) \
55  QVERIFY(QTestAccessibility::verifyEvent(object, child, (int)event))
56 
57 #include <QtCore/qlist.h>
58 #include <QtGui/qaccessible.h>
59 #include <QtGui/qapplication.h>
60 
62 
64 
65 QT_MODULE(Test)
66 
67 class QObject;
68 
70 {
71  QTestAccessibilityEvent(QObject* o = 0, int c = 0, int e = 0)
72  : object(o), child(c), event(e) {}
73 
74  bool operator==(const QTestAccessibilityEvent &o) const
75  {
76  return o.object == object && o.child == child && o.event == event;
77  }
78 
80  int child;
81  int event;
82 };
83 
85 
87 {
88 public:
89  static void initialize()
90  {
91  if (!instance()) {
92  instance() = new QTestAccessibility;
94  }
95  }
96  static void cleanup()
97  {
98  delete instance();
99  instance() = 0;
100  }
101  static void clearEvents() { eventList().clear(); }
102  static EventList events() { return eventList(); }
103  static bool verifyEvent(const QTestAccessibilityEvent& ev)
104  {
105  if (eventList().isEmpty())
106  return FALSE;
107  return eventList().takeFirst() == ev;
108  }
109 
110  static bool verifyEvent(QObject *o, int c, int e)
111  {
112  return verifyEvent(QTestAccessibilityEvent(o, c, e));
113  }
114 
115 private:
117  {
118  QAccessible::installUpdateHandler(updateHandler);
119  QAccessible::installRootObjectHandler(rootObjectHandler);
120  }
121 
123  {
126  }
127 
128  static void rootObjectHandler(QObject *object)
129  {
130  // qDebug("rootObjectHandler called %p", object);
131  if (object) {
133  if ( !app )
134  qWarning("QTEST_ACCESSIBILITY: root Object is not a QApplication!");
135  } else {
136  qWarning("QTEST_ACCESSIBILITY: root Object called with 0 pointer");
137  }
138  }
139 
140  static void updateHandler(QObject *o, int c, QAccessible::Event e)
141  {
142  // qDebug("updateHandler called: %p %d %d", o, c, (int)e);
143  eventList().append(QTestAccessibilityEvent(o, c, (int)e));
144  }
145 
147  {
148  static EventList list;
149  return list;
150  }
151 
153  {
154  static QTestAccessibility *ta = 0;
155  return ta;
156  }
157 };
158 
159 #endif
160 
162 
164 
165 #endif
T qobject_cast(QObject *object)
Definition: qobject.h:375
static QTestAccessibility *& instance()
The QApplication class manages the GUI application&#39;s control flow and main settings.
Definition: qapplication.h:99
static EventList & eventList()
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QTestAccessibilityEvent(QObject *o=0, int c=0, int e=0)
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
void qAddPostRoutine(QtCleanUpFunction p)
QList< QTestAccessibilityEvent > EventList
static RootObjectHandler installRootObjectHandler(RootObjectHandler)
Installs the given handler as the function to be used by setRootObject(), and returns the previously ...
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
bool operator==(const QTestAccessibilityEvent &o) const
static void rootObjectHandler(QObject *object)
static void clearEvents()
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static bool isEmpty(const char *str)
Event
This enum type defines accessible event types.
Definition: qaccessible.h:67
Q_CORE_EXPORT void qWarning(const char *,...)
static void initialize()
#define FALSE
Synonym for false.
Definition: qglobal.h:1019
static void updateHandler(QObject *o, int c, QAccessible::Event e)
static bool verifyEvent(const QTestAccessibilityEvent &ev)
static void cleanup()
Definition: qpicture.cpp:1508
static void cleanup()
static UpdateHandler installUpdateHandler(UpdateHandler)
Installs the given handler as the function to be used by updateAccessibility(), and returns the previ...
#define QT_END_HEADER
Definition: qglobal.h:137
static bool verifyEvent(QObject *o, int c, int e)
static EventList events()
The QList class is a template class that provides lists.
Definition: qdatastream.h:62