0
|
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 |
|
|
44 |
#include "qevent.h"
|
|
45 |
#include "qdialog.h"
|
|
46 |
#include "qpushbutton.h"
|
|
47 |
#include "qdialogbuttonbox.h"
|
|
48 |
#include "private/qsoftkeymanager_p.h"
|
|
49 |
|
|
50 |
#ifdef Q_WS_S60
|
|
51 |
static const int s60CommandStart = 6000;
|
|
52 |
#endif
|
|
53 |
|
|
54 |
|
|
55 |
class tst_QSoftKeyManager : public QObject
|
|
56 |
{
|
|
57 |
Q_OBJECT
|
|
58 |
|
|
59 |
public:
|
|
60 |
tst_QSoftKeyManager();
|
|
61 |
virtual ~tst_QSoftKeyManager();
|
|
62 |
|
|
63 |
public slots:
|
|
64 |
void initTestCase();
|
|
65 |
void cleanupTestCase();
|
|
66 |
void init();
|
|
67 |
void cleanup();
|
|
68 |
private slots:
|
|
69 |
void updateSoftKeysCompressed();
|
|
70 |
void handleCommand();
|
|
71 |
void checkSoftkeyEnableStates();
|
|
72 |
};
|
|
73 |
|
|
74 |
class EventListener : public QObject
|
|
75 |
{
|
|
76 |
public:
|
|
77 |
EventListener(QObject *listenTo)
|
|
78 |
{
|
|
79 |
resetCounts();
|
|
80 |
if (listenTo)
|
|
81 |
listenTo->installEventFilter(this);
|
|
82 |
}
|
|
83 |
|
|
84 |
void resetCounts()
|
|
85 |
{
|
|
86 |
numUpdateSoftKeys = 0;
|
|
87 |
}
|
|
88 |
|
|
89 |
int numUpdateSoftKeys;
|
|
90 |
|
|
91 |
protected:
|
|
92 |
bool eventFilter(QObject * /*object*/, QEvent *event)
|
|
93 |
{
|
|
94 |
if (event->type() == QEvent::UpdateSoftKeys)
|
|
95 |
numUpdateSoftKeys++;
|
|
96 |
return false;
|
|
97 |
}
|
|
98 |
};
|
|
99 |
|
|
100 |
tst_QSoftKeyManager::tst_QSoftKeyManager() : QObject()
|
|
101 |
{
|
|
102 |
}
|
|
103 |
|
|
104 |
tst_QSoftKeyManager::~tst_QSoftKeyManager()
|
|
105 |
{
|
|
106 |
}
|
|
107 |
|
|
108 |
void tst_QSoftKeyManager::initTestCase()
|
|
109 |
{
|
|
110 |
}
|
|
111 |
|
|
112 |
void tst_QSoftKeyManager::cleanupTestCase()
|
|
113 |
{
|
|
114 |
}
|
|
115 |
|
|
116 |
void tst_QSoftKeyManager::init()
|
|
117 |
{
|
|
118 |
}
|
|
119 |
|
|
120 |
void tst_QSoftKeyManager::cleanup()
|
|
121 |
{
|
|
122 |
}
|
|
123 |
|
|
124 |
/*
|
|
125 |
This tests that we only get one UpdateSoftKeys event even though
|
|
126 |
multiple events that trigger soft keys occur.
|
|
127 |
*/
|
|
128 |
void tst_QSoftKeyManager::updateSoftKeysCompressed()
|
|
129 |
{
|
|
130 |
QWidget w;
|
|
131 |
EventListener listener(qApp);
|
|
132 |
|
|
133 |
QList<QAction *> softKeys;
|
|
134 |
for (int i = 0; i < 10; ++i) {
|
|
135 |
QAction *action = new QAction("foo", &w);
|
|
136 |
action->setSoftKeyRole(QAction::PositiveSoftKey);
|
|
137 |
softKeys << action;
|
|
138 |
}
|
|
139 |
w.addActions(softKeys);
|
|
140 |
|
|
141 |
QApplication::processEvents();
|
|
142 |
|
|
143 |
QVERIFY(listener.numUpdateSoftKeys == 1);
|
|
144 |
}
|
|
145 |
|
|
146 |
/*
|
|
147 |
This tests that when the S60 environment sends us a command
|
|
148 |
that it actually gets mapped to the correct action.
|
|
149 |
*/
|
|
150 |
void tst_QSoftKeyManager::handleCommand()
|
|
151 |
{
|
|
152 |
QDialog w;
|
|
153 |
QDialogButtonBox *buttons = new QDialogButtonBox(
|
|
154 |
QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
|
|
155 |
Qt::Horizontal,
|
|
156 |
&w);
|
|
157 |
|
|
158 |
w.show();
|
|
159 |
QApplication::processEvents();
|
|
160 |
|
|
161 |
QCOMPARE(w.actions().count(), 2);
|
|
162 |
|
|
163 |
QSignalSpy spy0(w.actions()[0], SIGNAL(triggered()));
|
|
164 |
QSignalSpy spy1(w.actions()[1], SIGNAL(triggered()));
|
|
165 |
|
|
166 |
// These should work eventually, but do not yet
|
|
167 |
// QTest::keyPress(&w, Qt::Key_Context1);
|
|
168 |
// QTest::keyPress(&w, Qt::Key_Context2);
|
|
169 |
|
|
170 |
qApp->symbianHandleCommand(6000);
|
|
171 |
qApp->symbianHandleCommand(6001);
|
|
172 |
|
|
173 |
QApplication::processEvents();
|
|
174 |
|
|
175 |
QCOMPARE(spy0.count(), 1);
|
|
176 |
QCOMPARE(spy1.count(), 1);
|
|
177 |
}
|
|
178 |
|
|
179 |
/*
|
|
180 |
This tests that the state of a widget that owns softkey action is respected when handling the softkey
|
|
181 |
command.
|
|
182 |
*/
|
|
183 |
void tst_QSoftKeyManager::checkSoftkeyEnableStates()
|
|
184 |
{
|
|
185 |
QDialog w;
|
|
186 |
QDialogButtonBox *buttons = new QDialogButtonBox(
|
|
187 |
QDialogButtonBox::RestoreDefaults | QDialogButtonBox::Help,
|
|
188 |
Qt::Horizontal,
|
|
189 |
&w);
|
|
190 |
QPushButton *pBDefaults = buttons->button(QDialogButtonBox::RestoreDefaults);
|
|
191 |
QPushButton *pBHelp = buttons->button(QDialogButtonBox::Help);
|
|
192 |
pBHelp->setEnabled(false);
|
|
193 |
w.show();
|
|
194 |
QApplication::processEvents();
|
|
195 |
|
|
196 |
QSignalSpy spy0(w.actions()[0], SIGNAL(triggered())); //restore defaults action
|
|
197 |
QSignalSpy spy1(w.actions()[1], SIGNAL(triggered())); //disabled help action
|
|
198 |
|
|
199 |
//Verify that enabled button gets all the action trigger signals and
|
|
200 |
//disabled button gets none.
|
|
201 |
for (int i = 0; i < 10; i++) {
|
|
202 |
//simulate "Restore Defaults" softkey press
|
|
203 |
qApp->symbianHandleCommand(s60CommandStart);
|
|
204 |
//simulate "help" softkey press
|
|
205 |
qApp->symbianHandleCommand(s60CommandStart + 1);
|
|
206 |
}
|
|
207 |
QApplication::processEvents();
|
|
208 |
QCOMPARE(spy0.count(), 10);
|
|
209 |
QCOMPARE(spy1.count(), 0);
|
|
210 |
spy0.clear();
|
|
211 |
spy1.clear();
|
|
212 |
|
|
213 |
for (int i = 0; i < 10; i++) {
|
|
214 |
//simulate "Restore Defaults" softkey press
|
|
215 |
qApp->symbianHandleCommand(s60CommandStart);
|
|
216 |
//simulate "help" softkey press
|
|
217 |
qApp->symbianHandleCommand(s60CommandStart + 1);
|
|
218 |
//switch enabled button to disabled and vice versa
|
|
219 |
pBHelp->setEnabled(!pBHelp->isEnabled());
|
|
220 |
pBDefaults->setEnabled(!pBDefaults->isEnabled());
|
|
221 |
}
|
|
222 |
QApplication::processEvents();
|
|
223 |
QCOMPARE(spy0.count(), 5);
|
|
224 |
QCOMPARE(spy1.count(), 5);
|
|
225 |
}
|
|
226 |
|
|
227 |
QTEST_MAIN(tst_QSoftKeyManager)
|
|
228 |
#include "tst_qsoftkeymanager.moc"
|