|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <QtTest/QtTest> |
|
43 #include <QtCore/QDate> |
|
44 #include <QtCore/QDebug> |
|
45 #include <QtCore/QObject> |
|
46 #include <QtGui> |
|
47 #ifdef Q_OS_WINCE_WM |
|
48 #include <windows.h> |
|
49 #include "ddhelper.h" |
|
50 #endif |
|
51 |
|
52 |
|
53 |
|
54 class tst_WindowsMobile : public QObject |
|
55 { |
|
56 Q_OBJECT |
|
57 public: |
|
58 tst_WindowsMobile() |
|
59 { |
|
60 qApp->setCursorFlashTime (24 * 3600 * 1000); // once a day |
|
61 // qApp->setCursorFlashTime (INT_MAX); |
|
62 #ifdef Q_OS_WINCE_WM |
|
63 q_initDD(); |
|
64 #endif |
|
65 } |
|
66 |
|
67 #if defined(Q_OS_WINCE_WM) && defined(_WIN32_WCE) && _WIN32_WCE <= 0x501 |
|
68 private slots: |
|
69 void testMainWindowAndMenuBar(); |
|
70 void testSimpleWidget(); |
|
71 #endif |
|
72 }; |
|
73 |
|
74 #if defined(Q_OS_WINCE_WM) && defined(_WIN32_WCE) && _WIN32_WCE <= 0x501 |
|
75 |
|
76 bool qt_wince_is_platform(const QString &platformString) { |
|
77 wchar_t tszPlatform[64]; |
|
78 if (SystemParametersInfo(SPI_GETPLATFORMTYPE, |
|
79 sizeof(tszPlatform)/sizeof(*tszPlatform),tszPlatform,0)) |
|
80 if (0 == _tcsicmp(reinterpret_cast<const wchar_t *> (platformString.utf16()), tszPlatform)) |
|
81 return true; |
|
82 return false; |
|
83 } |
|
84 |
|
85 bool qt_wince_is_smartphone() { |
|
86 return qt_wince_is_platform(QString::fromLatin1("Smartphone")); |
|
87 } |
|
88 |
|
89 void openMenu() |
|
90 { |
|
91 ::mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE,450,630,0,0); |
|
92 ::mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE,450,630,0,0); |
|
93 QTest::qWait(2000); |
|
94 ::mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE,65535,65535,0,0); |
|
95 ::mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE,65535,65535,0,0); |
|
96 QTest::qWait(2000); |
|
97 ::mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE,55535,55535,0,0); |
|
98 ::mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE,55535,55535,0,0); |
|
99 QTest::qWait(2000); |
|
100 ::mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE,55535,58535,0,0); |
|
101 ::mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE,55535,58535,0,0); |
|
102 QTest::qWait(2000); |
|
103 ::mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE,40535,55535,0,0); |
|
104 ::mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE,40535,55535,0,0); |
|
105 QTest::qWait(2000); |
|
106 ::mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE,32535,55535,0,0); |
|
107 ::mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE,32535,55535,0,0); |
|
108 QTest::qWait(2000); |
|
109 ::mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE,65535,65535,0,0); |
|
110 ::mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE,65535,65535,0,0); |
|
111 QTest::qWait(2000); |
|
112 ::mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE,55535,50535,0,0); |
|
113 ::mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE,55535,50535,0,0); |
|
114 QTest::qWait(2000); |
|
115 ::mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE,55535,40535,0,0); |
|
116 ::mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE,55535,40535,0,0); |
|
117 QTest::qWait(2000); |
|
118 ::mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE,48535,45535,0,0); |
|
119 QTest::qWait(2000); |
|
120 ::mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE,48535,45535,0,0); |
|
121 } |
|
122 |
|
123 void compareScreenshots(const QString &image1, const QString &image2) |
|
124 { |
|
125 QImage screenShot(image1); |
|
126 QImage original(image2); |
|
127 |
|
128 // cut away the title bar before comparing |
|
129 QDesktopWidget desktop; |
|
130 QRect desktopFrameRect = desktop.frameGeometry(); |
|
131 QRect desktopClientRect = desktop.availableGeometry(); |
|
132 |
|
133 QPainter p1(&screenShot); |
|
134 QPainter p2(&original); |
|
135 |
|
136 //screenShot.save("scr1.png", "PNG"); |
|
137 p1.fillRect(0, 0, desktopFrameRect.width(), desktopClientRect.y(), Qt::black); |
|
138 p2.fillRect(0, 0, desktopFrameRect.width(), desktopClientRect.y(), Qt::black); |
|
139 |
|
140 //screenShot.save("scr2.png", "PNG"); |
|
141 //original.save("orig1.png", "PNG"); |
|
142 |
|
143 QVERIFY(original == screenShot); |
|
144 } |
|
145 |
|
146 void takeScreenShot(const QString filename) |
|
147 { |
|
148 q_lock(); |
|
149 QImage image = QImage(( uchar *) q_frameBuffer(), q_screenWidth(), |
|
150 q_screenHeight(), q_screenWidth() * q_screenDepth() / 8, QImage::Format_RGB16); |
|
151 image.save(filename, "PNG"); |
|
152 q_unlock(); |
|
153 } |
|
154 |
|
155 void tst_WindowsMobile::testMainWindowAndMenuBar() |
|
156 { |
|
157 if (qt_wince_is_smartphone()) |
|
158 QSKIP("This test is only for Windows Mobile", SkipAll); |
|
159 |
|
160 QProcess process; |
|
161 process.start("testQMenuBar.exe"); |
|
162 QCOMPARE(process.state(), QProcess::Running); |
|
163 QTest::qWait(6000); |
|
164 openMenu(); |
|
165 QTest::qWait(1000); |
|
166 takeScreenShot("testQMenuBar_current.png"); |
|
167 process.close(); |
|
168 compareScreenshots("testQMenuBar_current.png", ":/testQMenuBar_current.png"); |
|
169 } |
|
170 |
|
171 void tst_WindowsMobile::testSimpleWidget() |
|
172 { |
|
173 if (qt_wince_is_smartphone()) |
|
174 QSKIP("This test is only for Windows Mobile", SkipAll); |
|
175 |
|
176 QMenuBar menubar; |
|
177 menubar.show(); |
|
178 QWidget maximized; |
|
179 QPalette pal = maximized.palette(); |
|
180 pal.setColor(QPalette::Background, Qt::red); |
|
181 maximized.setPalette(pal); |
|
182 maximized.showMaximized(); |
|
183 QWidget widget; |
|
184 widget.setGeometry(100, 100, 200, 200); |
|
185 widget.setWindowTitle("Widget"); |
|
186 widget.show(); |
|
187 qApp->processEvents(); |
|
188 QTest::qWait(1000); |
|
189 |
|
190 QWidget widget2; |
|
191 widget2.setGeometry(100, 380, 300, 200); |
|
192 widget2.setWindowTitle("Widget 2"); |
|
193 widget2.setWindowFlags(Qt::Popup); |
|
194 widget2.show(); |
|
195 |
|
196 qApp->processEvents(); |
|
197 QTest::qWait(1000); |
|
198 takeScreenShot("testSimpleWidget_current.png"); |
|
199 compareScreenshots("testSimpleWidget_current.png", ":/testSimpleWidget_current.png"); |
|
200 } |
|
201 |
|
202 |
|
203 #endif //Q_OS_WINCE_WM |
|
204 |
|
205 |
|
206 QTEST_MAIN(tst_WindowsMobile) |
|
207 #include "tst_windowsmobile.moc" |
|
208 |