Fix binary incompatibility between openssl versions
[profile/ivi/qtbase.git] / src / testlib / qtestmouse.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 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 QTESTMOUSE_H
43 #define QTESTMOUSE_H
44
45 #if 0
46 // inform syncqt
47 #pragma qt_no_master_include
48 #endif
49
50 #include <QtTest/qtest_global.h>
51 #include <QtTest/qtestassert.h>
52 #include <QtTest/qtestsystem.h>
53 #include <QtTest/qtestspontaneevent.h>
54 #include <QtCore/qpoint.h>
55 #include <QtCore/qstring.h>
56 #include <QtGui/qevent.h>
57
58 #ifdef QT_WIDGETS_LIB
59 #include <QtWidgets/qapplication.h>
60 #include <QtWidgets/qwidget.h>
61 #endif
62
63 QT_BEGIN_HEADER
64
65 QT_BEGIN_NAMESPACE
66
67 Q_GUI_EXPORT void qt_handleMouseEvent(QWindow *w, const QPointF & local, const QPointF & global, Qt::MouseButtons b, Qt::KeyboardModifiers mods = Qt::NoModifier);
68
69 namespace QTest
70 {
71     enum MouseAction { MousePress, MouseRelease, MouseClick, MouseDClick, MouseMove };
72
73     static void waitForEvents()
74     {
75 #ifdef Q_OS_MAC
76         QTest::qWait(20);
77 #else
78         qApp->processEvents();
79 #endif
80     }
81
82     static void mouseEvent(MouseAction action, QWindow *window, Qt::MouseButton button,
83                            Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
84     {
85         QTEST_ASSERT(window);
86         extern int Q_TESTLIB_EXPORT defaultMouseDelay();
87
88          static Qt::MouseButton lastButton = Qt::NoButton;
89
90         if (delay == -1 || delay < defaultMouseDelay())
91             delay = defaultMouseDelay();
92         if (delay > 0)
93             QTest::qWait(delay);
94
95         if (pos.isNull())
96             pos = window->geometry().center();
97
98         if (action == MouseClick) {
99             mouseEvent(MousePress, window, button, stateKey, pos);
100             mouseEvent(MouseRelease, window, button, stateKey, pos);
101             return;
102         }
103         QTEST_ASSERT(stateKey == 0 || stateKey & Qt::KeyboardModifierMask);
104
105         stateKey &= static_cast<unsigned int>(Qt::KeyboardModifierMask);
106
107
108         switch (action)
109         {
110             case MousePress:
111                 qt_handleMouseEvent(window,pos,window->mapToGlobal(pos),button,stateKey);
112                 lastButton = button;
113                 break;
114             case MouseRelease:
115                 qt_handleMouseEvent(window,pos,window->mapToGlobal(pos),Qt::NoButton,stateKey);
116                 lastButton = Qt::NoButton;
117                 break;
118             case MouseDClick:
119                 qt_handleMouseEvent(window,pos,window->mapToGlobal(pos),button,stateKey);
120                 qWait(10);
121                 qt_handleMouseEvent(window,pos,window->mapToGlobal(pos),Qt::NoButton,stateKey);
122                 qWait(20);
123                 qt_handleMouseEvent(window,pos,window->mapToGlobal(pos),button,stateKey);
124                 qWait(10);
125                 qt_handleMouseEvent(window,pos,window->mapToGlobal(pos),Qt::NoButton,stateKey);
126                 break;
127             case MouseMove:
128                 qt_handleMouseEvent(window,pos,window->mapToGlobal(pos),lastButton,stateKey);
129                 // No QCursor::setPos() call here. That could potentially result in mouse events sent by the windowing system
130                 // which is highly undesired here. Tests must avoid relying on QCursor.
131                 break;
132             default:
133                 QTEST_ASSERT(false);
134         }
135         waitForEvents();
136     }
137
138     inline void mousePress(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
139                            QPoint pos = QPoint(), int delay=-1)
140     { mouseEvent(MousePress, window, button, stateKey, pos, delay); }
141     inline void mouseRelease(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
142                              QPoint pos = QPoint(), int delay=-1)
143     { mouseEvent(MouseRelease, window, button, stateKey, pos, delay); }
144     inline void mouseClick(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
145                            QPoint pos = QPoint(), int delay=-1)
146     { mouseEvent(MouseClick, window, button, stateKey, pos, delay); }
147     inline void mouseDClick(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
148                             QPoint pos = QPoint(), int delay=-1)
149     { mouseEvent(MouseDClick, window, button, stateKey, pos, delay); }
150     inline void mouseMove(QWindow *window, QPoint pos = QPoint(), int delay=-1)
151     { mouseEvent(MouseMove, window, Qt::NoButton, 0, pos, delay); }
152
153 #ifdef QT_WIDGETS_LIB
154     static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button,
155                            Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
156     {
157         QTEST_ASSERT(widget);
158         extern int Q_TESTLIB_EXPORT defaultMouseDelay();
159
160         if (delay == -1 || delay < defaultMouseDelay())
161             delay = defaultMouseDelay();
162         if (delay > 0)
163             QTest::qWait(delay);
164
165         if (pos.isNull())
166             pos = widget->rect().center();
167
168         if (action == MouseClick) {
169             mouseEvent(MousePress, widget, button, stateKey, pos);
170             mouseEvent(MouseRelease, widget, button, stateKey, pos);
171             return;
172         }
173
174         QTEST_ASSERT(stateKey == 0 || stateKey & Qt::KeyboardModifierMask);
175
176         stateKey &= static_cast<unsigned int>(Qt::KeyboardModifierMask);
177
178         QMouseEvent me(QEvent::User, QPoint(), Qt::LeftButton, button, stateKey);
179         switch (action)
180         {
181             case MousePress:
182                 me = QMouseEvent(QEvent::MouseButtonPress, pos, widget->mapToGlobal(pos), button, button, stateKey);
183                 break;
184             case MouseRelease:
185                 me = QMouseEvent(QEvent::MouseButtonRelease, pos, widget->mapToGlobal(pos), button, 0, stateKey);
186                 break;
187             case MouseDClick:
188                 me = QMouseEvent(QEvent::MouseButtonDblClick, pos, widget->mapToGlobal(pos), button, button, stateKey);
189                 break;
190             case MouseMove:
191                 QCursor::setPos(widget->mapToGlobal(pos));
192 #ifdef Q_OS_MAC
193                 QTest::qWait(20);
194 #else
195                 qApp->processEvents();
196 #endif
197                 return;
198             default:
199                 QTEST_ASSERT(false);
200         }
201         QSpontaneKeyEvent::setSpontaneous(&me);
202         if (!qApp->notify(widget, &me)) {
203             static const char *mouseActionNames[] =
204                 { "MousePress", "MouseRelease", "MouseClick", "MouseDClick", "MouseMove" };
205             QString warning = QString::fromLatin1("Mouse event \"%1\" not accepted by receiving widget");
206             QTest::qWarn(warning.arg(QString::fromLatin1(mouseActionNames[static_cast<int>(action)])).toLatin1().data());
207         }
208
209     }
210
211     inline void mousePress(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
212                            QPoint pos = QPoint(), int delay=-1)
213     { mouseEvent(MousePress, widget, button, stateKey, pos, delay); }
214     inline void mouseRelease(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
215                              QPoint pos = QPoint(), int delay=-1)
216     { mouseEvent(MouseRelease, widget, button, stateKey, pos, delay); }
217     inline void mouseClick(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
218                            QPoint pos = QPoint(), int delay=-1)
219     { mouseEvent(MouseClick, widget, button, stateKey, pos, delay); }
220     inline void mouseDClick(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
221                             QPoint pos = QPoint(), int delay=-1)
222     { mouseEvent(MouseDClick, widget, button, stateKey, pos, delay); }
223     inline void mouseMove(QWidget *widget, QPoint pos = QPoint(), int delay=-1)
224     { mouseEvent(MouseMove, widget, Qt::NoButton, 0, pos, delay); }
225 #endif // QT_WIDGETS_LIB
226 }
227
228 QT_END_NAMESPACE
229
230 QT_END_HEADER
231
232 #endif // QTESTMOUSE_H