37
|
1 |
/*!
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Unit tests for PhoneUIQtView.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <QtTest/QtTest>
|
|
19 |
#include <QtGui>
|
|
20 |
#include <QVariant>
|
|
21 |
#include <QKeyEvent>
|
|
22 |
#include <QTimer>
|
|
23 |
#include <QShortcutEvent>
|
|
24 |
#include <QSignalSpy>
|
|
25 |
#include <hbapplication.h>
|
|
26 |
#include <hbmainwindow.h>
|
|
27 |
#include <hbinstance.h>
|
|
28 |
#include <hbmainwindow.h>
|
|
29 |
#include <bubblemanagerif.h>
|
|
30 |
#define protected public
|
|
31 |
#include "phoneuiqtview.h"
|
|
32 |
#undef public
|
|
33 |
#include "phoneaction.h"
|
|
34 |
#include <hbtoolbar.h>
|
|
35 |
#include <hbvolumesliderpopup.h>
|
|
36 |
#include <hbaction.h>
|
|
37 |
#include "xqserviceutil.h"
|
|
38 |
#include "phoneaction.h"
|
|
39 |
|
|
40 |
//CONSTANTS
|
|
41 |
static const int KMAXVOLUME = 10;
|
|
42 |
static const int KMINVOLUME = 0;
|
|
43 |
static const int KVOLUMECOMMAND = 5;
|
|
44 |
|
|
45 |
bool m_qtimer_stop_called;
|
|
46 |
QString m_networkName;
|
|
47 |
|
|
48 |
#define PHONE_QT_VIEW_TEST_MAIN(TestObject) \
|
|
49 |
int main(int argc, char *argv[]) \
|
|
50 |
{ \
|
|
51 |
HbApplication app(argc, argv); \
|
|
52 |
TestObject tc; \
|
|
53 |
QResource::registerResource("../hbcore.rcc"); \
|
|
54 |
int ret = QTest::qExec(&tc, argc, argv); \
|
|
55 |
/* Core dump if HbIconLoader instance is not destroyed before the application instance. */ \
|
|
56 |
/* HbIconLoader uses QCoreApplication::aboutToQuit() signal to destroy itself. */ \
|
|
57 |
/* app.exec() where the signal is normally emitted is not called here. */ \
|
|
58 |
/* So, invoking the signal explicitly. */ \
|
|
59 |
QMetaObject::invokeMethod(&app, "aboutToQuit", Qt::DirectConnection); \
|
|
60 |
return ret; \
|
|
61 |
}
|
|
62 |
|
|
63 |
class TestPhoneUIQtView : public QObject
|
|
64 |
{
|
|
65 |
Q_OBJECT
|
|
66 |
|
|
67 |
public:
|
|
68 |
TestPhoneUIQtView ();
|
|
69 |
~TestPhoneUIQtView ();
|
|
70 |
|
|
71 |
|
|
72 |
public slots:
|
|
73 |
void initTestCase ();
|
|
74 |
void cleanupTestCase ();
|
|
75 |
void init ();
|
|
76 |
void cleanup ();
|
|
77 |
|
|
78 |
private slots:
|
|
79 |
void testAddBubbleCommand ();
|
|
80 |
void testHideToolbar ();
|
|
81 |
void testShowToolbar ();
|
|
82 |
void testAddToolbarActions ();
|
|
83 |
void testSetVolumeSliderValue ();
|
|
84 |
void testRemoveVolumeSlider ();
|
|
85 |
void testVolumeSliderValue ();
|
|
86 |
void testVolumeSliderChanged ();
|
|
87 |
void testParticipantListAction ();
|
|
88 |
void testSetExpandAction ();
|
|
89 |
void testPhoneAction ();
|
|
90 |
void testSetOrientation ();
|
|
91 |
void testBackButtonClicked();
|
|
92 |
void testShowDialpad();
|
|
93 |
void testDialpadText();
|
|
94 |
void testSetMenuActions();
|
|
95 |
void testLongEndKeyPressEventOutsideTelephony();
|
|
96 |
void testNetworkNameChanged();
|
|
97 |
|
|
98 |
private:
|
|
99 |
int createCallHeader();
|
|
100 |
|
|
101 |
private:
|
|
102 |
PhoneUIQtView *m_view; // class under test
|
|
103 |
HbMainWindow *m_main_window;
|
|
104 |
|
|
105 |
};
|
|
106 |
|
|
107 |
void QTimer::stop()
|
|
108 |
{
|
|
109 |
m_qtimer_stop_called = true;
|
|
110 |
}
|
|
111 |
|
|
112 |
TestPhoneUIQtView::TestPhoneUIQtView ()
|
|
113 |
{
|
|
114 |
}
|
|
115 |
|
|
116 |
TestPhoneUIQtView::~TestPhoneUIQtView ()
|
|
117 |
{
|
|
118 |
}
|
|
119 |
|
|
120 |
void TestPhoneUIQtView::initTestCase ()
|
|
121 |
{
|
|
122 |
m_main_window = new HbMainWindow();
|
|
123 |
m_view = new PhoneUIQtView(*m_main_window);
|
|
124 |
QCOMPARE(m_networkName, QString("Unit test network"));
|
|
125 |
}
|
|
126 |
|
|
127 |
void TestPhoneUIQtView::cleanupTestCase ()
|
|
128 |
{
|
|
129 |
delete m_view;
|
|
130 |
}
|
|
131 |
|
|
132 |
void TestPhoneUIQtView::init ()
|
|
133 |
{
|
|
134 |
m_qtimer_stop_called = false;
|
|
135 |
}
|
|
136 |
|
|
137 |
void TestPhoneUIQtView::cleanup ()
|
|
138 |
{
|
|
139 |
}
|
|
140 |
|
|
141 |
void TestPhoneUIQtView::testAddBubbleCommand ()
|
|
142 |
{
|
|
143 |
m_view->bubbleManager ().startChanges ();
|
|
144 |
int bubbleId = createCallHeader();
|
|
145 |
int bubbleId2 = createCallHeader();
|
|
146 |
|
|
147 |
PhoneAction action1;
|
|
148 |
action1.setText("Command 1");
|
|
149 |
action1.setCommand(1);
|
|
150 |
action1.setActionRole(PhoneAction::None);
|
|
151 |
|
|
152 |
PhoneAction action2;
|
|
153 |
action2.setText("Command 2");
|
|
154 |
action2.setCommand(2);
|
|
155 |
action2.setActionRole(PhoneAction::Accept);
|
|
156 |
|
|
157 |
PhoneAction action3;
|
|
158 |
action3.setText("Command 3");
|
|
159 |
action3.setCommand(3);
|
|
160 |
action3.setActionRole(PhoneAction::Decline);
|
|
161 |
|
|
162 |
m_view->addBubbleCommand (bubbleId, action1);
|
|
163 |
m_view->addBubbleCommand (bubbleId, action2);
|
|
164 |
m_view->addBubbleCommand (bubbleId2, action3);
|
|
165 |
m_view->bubbleManager ().endChanges ();
|
|
166 |
|
|
167 |
m_view->bubbleManager ().startChanges ();
|
|
168 |
m_view->clearBubbleCommands (bubbleId);
|
|
169 |
m_view->clearBubbleCommands (bubbleId2);
|
|
170 |
m_view->clearBubbleCommands (bubbleId2);
|
|
171 |
m_view->bubbleManager ().endChanges ();
|
|
172 |
}
|
|
173 |
|
|
174 |
void TestPhoneUIQtView::testHideToolbar ()
|
|
175 |
{
|
|
176 |
m_view->hideToolbar ();
|
|
177 |
QCOMPARE (m_hideCalled, true);
|
|
178 |
}
|
|
179 |
|
|
180 |
void TestPhoneUIQtView::testShowToolbar ()
|
|
181 |
{
|
|
182 |
m_view->showToolbar ();
|
|
183 |
QCOMPARE (m_showCalled, true);
|
|
184 |
}
|
|
185 |
|
|
186 |
void TestPhoneUIQtView::testAddToolbarActions ()
|
|
187 |
{
|
|
188 |
m_actions.clear();
|
|
189 |
HbIcon icon ("foo.jpg");
|
|
190 |
PhoneAction *testAction = new PhoneAction ();
|
|
191 |
testAction->setIcon(icon);
|
|
192 |
testAction->setText("foo");
|
|
193 |
testAction->setCommand(20);
|
|
194 |
QList<PhoneAction*> actions;
|
|
195 |
actions.append(testAction);
|
|
196 |
|
|
197 |
m_view->setToolbarActions(actions);
|
|
198 |
QCOMPARE (m_action->icon(), icon);
|
|
199 |
QCOMPARE(true, m_toolBarUpdateCalled);
|
|
200 |
|
|
201 |
m_view->setToolbarActions(actions);
|
|
202 |
|
|
203 |
m_toolBarUpdateCalled = false;
|
|
204 |
PhoneAction *testAction2 = new PhoneAction ();
|
|
205 |
testAction2->setIcon(icon);
|
|
206 |
testAction2->setText("foo2");
|
|
207 |
testAction2->setCommand(21);
|
|
208 |
actions.append(testAction2);
|
|
209 |
|
|
210 |
m_view->setToolbarActions(actions);
|
|
211 |
QCOMPARE(true, m_toolBarUpdateCalled);
|
|
212 |
actions.removeOne(testAction2);
|
|
213 |
|
|
214 |
m_toolBarUpdateCalled = false;
|
|
215 |
m_view->setToolbarActions(actions);
|
|
216 |
QCOMPARE(true, m_toolBarUpdateCalled);
|
|
217 |
|
|
218 |
actions.clear();
|
|
219 |
delete testAction;
|
|
220 |
delete testAction2;
|
|
221 |
}
|
|
222 |
|
|
223 |
void TestPhoneUIQtView::testSetVolumeSliderValue ()
|
|
224 |
{
|
|
225 |
m_view->setVolumeSliderValue (1, KVOLUMECOMMAND, KMAXVOLUME, KMINVOLUME);
|
|
226 |
QCOMPARE (m_volumeSliderContructorCalled, true);
|
|
227 |
QCOMPARE (m_sliderRangeMin, KMINVOLUME);
|
|
228 |
QCOMPARE (m_sliderRangeMax, KMAXVOLUME);
|
|
229 |
QCOMPARE (m_volumeSliderSetTimeoutCalled, true);
|
|
230 |
QCOMPARE (m_sliderTimeout, 10000);
|
|
231 |
QCOMPARE (m_volumeSliderSetValueCalled, true);
|
|
232 |
QCOMPARE (m_sliderValue, 1);
|
|
233 |
QCOMPARE (m_volumeSliderShowCalled, true);
|
|
234 |
|
|
235 |
// reset values
|
|
236 |
m_volumeSliderContructorCalled = false;
|
|
237 |
m_volumeSliderSetValueCalled = false;
|
|
238 |
m_sliderRangeMin = -1;
|
|
239 |
m_sliderRangeMax = -1;
|
|
240 |
m_volumeSliderSetTimeoutCalled = false;
|
|
241 |
m_sliderTimeout = -1;
|
|
242 |
m_volumeSliderSetValueCalled = false;
|
|
243 |
m_sliderValue = -1;
|
|
244 |
m_volumeSliderShowCalled = false;
|
|
245 |
|
|
246 |
// The second call shouldn't create a new instance
|
|
247 |
m_view->setVolumeSliderValue (2, KVOLUMECOMMAND, KMAXVOLUME, KMINVOLUME);
|
|
248 |
QCOMPARE (m_volumeSliderContructorCalled, false);
|
|
249 |
QCOMPARE (m_sliderRangeMin, KMINVOLUME);
|
|
250 |
QCOMPARE (m_sliderRangeMax, KMAXVOLUME);
|
|
251 |
QCOMPARE (m_volumeSliderSetTimeoutCalled, false);
|
|
252 |
QCOMPARE (m_sliderTimeout, -1);
|
|
253 |
QCOMPARE (m_volumeSliderSetValueCalled, true);
|
|
254 |
QCOMPARE (m_sliderValue, 2);
|
|
255 |
QCOMPARE (m_volumeSliderShowCalled, false);
|
|
256 |
}
|
|
257 |
|
|
258 |
void TestPhoneUIQtView::testRemoveVolumeSlider ()
|
|
259 |
{
|
|
260 |
m_view->setVolumeSliderValue (1, KVOLUMECOMMAND, KMAXVOLUME, KMINVOLUME);
|
|
261 |
m_view->removeVolumeSlider ();
|
|
262 |
QCOMPARE (m_volumeSliderHideCalled, true);
|
|
263 |
}
|
|
264 |
|
|
265 |
void TestPhoneUIQtView::testVolumeSliderValue ()
|
|
266 |
{
|
|
267 |
m_sliderValue = -1;
|
|
268 |
int value = m_view->volumeSliderValue ();
|
|
269 |
QCOMPARE (m_sliderValue, -1);
|
|
270 |
m_view->setVolumeSliderValue (3, KVOLUMECOMMAND, KMAXVOLUME, KMINVOLUME);
|
|
271 |
value = m_view->volumeSliderValue ();
|
|
272 |
QCOMPARE (m_volumeSliderValueCalled, true);
|
|
273 |
QCOMPARE (value, 3);
|
|
274 |
}
|
|
275 |
|
|
276 |
void TestPhoneUIQtView::testVolumeSliderChanged ()
|
|
277 |
{
|
|
278 |
m_view->setVolumeSliderValue (3, KVOLUMECOMMAND, KMAXVOLUME, KMINVOLUME);
|
|
279 |
QSignalSpy spy (m_view, SIGNAL(command(int)));
|
|
280 |
m_view->volumeSliderChanged (1);
|
|
281 |
QCOMPARE (spy.count(), 1);
|
|
282 |
int command = qvariant_cast<int>(spy.at (0).at (0));
|
|
283 |
QCOMPARE (command, (int)KVOLUMECOMMAND);
|
|
284 |
}
|
|
285 |
|
|
286 |
void TestPhoneUIQtView::testParticipantListAction ()
|
|
287 |
{
|
|
288 |
m_view->bubbleManager ().startChanges ();
|
|
289 |
m_view->addParticipantListAction (1,"Command 1", HbIcon ());
|
|
290 |
m_view->addParticipantListAction (2,"Command 2", HbIcon ());
|
|
291 |
m_view->bubbleManager ().endChanges ();
|
|
292 |
|
|
293 |
m_view->bubbleManager ().startChanges ();
|
|
294 |
m_view->clearParticipantListActions ();
|
|
295 |
m_view->clearParticipantListActions ();
|
|
296 |
m_view->bubbleManager ().endChanges ();
|
|
297 |
}
|
|
298 |
|
|
299 |
void TestPhoneUIQtView::testSetExpandAction ()
|
|
300 |
{
|
|
301 |
m_view->bubbleManager ().startChanges ();
|
|
302 |
int bubbleId = createCallHeader();
|
|
303 |
int bubbleId2 = createCallHeader();
|
|
304 |
|
|
305 |
m_view->setExpandAction(bubbleId, 1);
|
|
306 |
m_view->setExpandAction(bubbleId2, 2);
|
|
307 |
m_view->bubbleManager ().endChanges ();
|
|
308 |
|
|
309 |
m_view->bubbleManager ().startChanges ();
|
|
310 |
m_view->removeExpandAction(bubbleId);
|
|
311 |
m_view->removeExpandAction(bubbleId2);
|
|
312 |
m_view->bubbleManager().removeCallHeader(bubbleId);
|
|
313 |
m_view->bubbleManager().removeCallHeader(bubbleId2);
|
|
314 |
m_view->bubbleManager ().endChanges ();
|
|
315 |
}
|
|
316 |
|
|
317 |
void TestPhoneUIQtView::testPhoneAction ()
|
|
318 |
{
|
|
319 |
PhoneAction *action = new PhoneAction ();
|
|
320 |
QString string("Action");
|
|
321 |
action->setText(string);
|
|
322 |
HbIcon icon;
|
|
323 |
action->setIcon(icon);
|
|
324 |
int commandId(1);
|
|
325 |
action->setCommand(commandId);
|
|
326 |
action->setDisabled(true);
|
|
327 |
QCOMPARE( string, action->text() );
|
|
328 |
QCOMPARE( icon, action->icon() );
|
|
329 |
QCOMPARE( commandId, action->command() );
|
|
330 |
QCOMPARE( true, action->isDisabled() );
|
|
331 |
delete action;
|
|
332 |
}
|
|
333 |
|
|
334 |
void TestPhoneUIQtView::testSetOrientation ()
|
|
335 |
{
|
|
336 |
|
|
337 |
m_setOrientationCalled = false;
|
|
338 |
|
|
339 |
m_view->handleOrientationChange(Qt::Vertical);
|
|
340 |
QVERIFY( false == m_setOrientationCalled );
|
|
341 |
|
|
342 |
m_view->handleOrientationChange(Qt::Horizontal);
|
|
343 |
QVERIFY( true == m_setOrientationCalled );
|
|
344 |
|
|
345 |
}
|
|
346 |
|
|
347 |
void TestPhoneUIQtView::testBackButtonClicked()
|
|
348 |
{
|
|
349 |
// not possible to mock xqservice because it is in \epoc32\include
|
|
350 |
// calling backButtonClicked would send this test background.
|
|
351 |
// m_view->backButtonClicked();
|
|
352 |
}
|
|
353 |
|
|
354 |
void TestPhoneUIQtView::testShowDialpad()
|
|
355 |
{
|
|
356 |
m_view->hideDialpad();
|
|
357 |
m_view->showDialpad();
|
|
358 |
m_view->showDialpad();
|
|
359 |
QVERIFY(true == m_view->isDialpadVisible());
|
|
360 |
m_view->hideDialpad();
|
|
361 |
}
|
|
362 |
|
|
363 |
void TestPhoneUIQtView::testDialpadText()
|
|
364 |
{
|
|
365 |
m_view->showDialpad();
|
|
366 |
QVERIFY(QString("") == m_view->dialpadText());
|
|
367 |
m_view->clearAndHideDialpad();
|
|
368 |
}
|
|
369 |
|
|
370 |
void TestPhoneUIQtView::testSetMenuActions()
|
|
371 |
{
|
|
372 |
QList<PhoneAction*> actions;
|
|
373 |
m_view->setMenuActions(actions);
|
|
374 |
|
|
375 |
PhoneAction* phoneAction = new PhoneAction;
|
|
376 |
phoneAction->setText(QString("test"));
|
|
377 |
phoneAction->setCommand(1);
|
|
378 |
actions.append(phoneAction);
|
|
379 |
|
|
380 |
m_view->setMenuActions(actions);
|
|
381 |
qDeleteAll(actions);
|
|
382 |
actions.clear();
|
|
383 |
|
|
384 |
m_view->setMenuActions(actions);
|
|
385 |
}
|
|
386 |
|
|
387 |
//Private methods
|
|
388 |
int TestPhoneUIQtView::createCallHeader ()
|
|
389 |
{
|
|
390 |
int bubble = m_view->bubbleManager().createCallHeader ();
|
|
391 |
|
|
392 |
return bubble;
|
|
393 |
}
|
|
394 |
|
|
395 |
void TestPhoneUIQtView::testLongEndKeyPressEventOutsideTelephony()
|
|
396 |
{
|
|
397 |
/*QSignalSpy spy(m_view, SIGNAL(endKeyLongPress()));
|
|
398 |
QKeyEvent* event = new QKeyEvent(QEvent::ShortcutOverride, Qt::Key_No, Qt::NoModifier);
|
|
399 |
|
|
400 |
bool returnValue = m_view->eventFilter(new QObject(), event);
|
|
401 |
|
|
402 |
QVERIFY(returnValue == true);
|
|
403 |
QCOMPARE(spy.count(), 1);*/
|
|
404 |
}
|
|
405 |
|
|
406 |
void TestPhoneUIQtView::testNetworkNameChanged()
|
|
407 |
{
|
|
408 |
// Title is changed only for GmsMode
|
|
409 |
m_view->networkNameChanged(QSystemNetworkInfo::GsmMode, QString("test"));
|
|
410 |
QCOMPARE(m_networkName, QString("test"));
|
|
411 |
|
|
412 |
// Other modes shouldn't affect the title
|
|
413 |
m_view->networkNameChanged(QSystemNetworkInfo::CdmaMode, QString("another operator"));
|
|
414 |
QCOMPARE(m_networkName, QString("test"));
|
|
415 |
}
|
|
416 |
|
|
417 |
void HbView::setTitle (const QString &title)
|
|
418 |
{
|
|
419 |
m_networkName = title;
|
|
420 |
}
|
|
421 |
|
|
422 |
PHONE_QT_VIEW_TEST_MAIN(TestPhoneUIQtView)
|
|
423 |
Q_DECLARE_METATYPE(QKeyEvent *)
|
|
424 |
#include "unit_tests.moc"
|