|
1 /* |
|
2 * Copyright (c) 2010 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: Main test class for hsHomeScreenStatePlugin library. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <hbmainwindow.h> |
|
19 #include <hbinstance.h> |
|
20 #include <hbview.h> |
|
21 #include <hblistview.h> |
|
22 #include <hbaction.h> |
|
23 #include <hblistviewitem.h> |
|
24 #include <qscopedpointer> |
|
25 #include <hbmessagebox.h> |
|
26 |
|
27 #include "hsapplibrarystate.h" |
|
28 #include "hscollectionstate.h" |
|
29 #include "caentry.h" |
|
30 #include "caitemmodel.h" |
|
31 #include "hsmenuview.h" |
|
32 #include "hsmenuevent.h" |
|
33 #include "hsallcollectionsstate.h" |
|
34 #include "hsmenueventtransition.h" |
|
35 #include "hsallappsstate.h" |
|
36 #include "hsinstalledappsstate.h" |
|
37 #include "hsoperatorhandler_p.h" |
|
38 #include "hsoperatorhandler.h" |
|
39 #include "hsmenuservice.h" |
|
40 |
|
41 #include "t_hsaddtohomescreenmockstate.h" |
|
42 #include "t_hsmockmodel.h" |
|
43 #include "t_applibrarystate.h" |
|
44 |
|
45 #include "hsmenumodetransition.h" |
|
46 |
|
47 #ifdef QT_EXTENSIONS |
|
48 #include <XQSettingsManager> |
|
49 |
|
50 const int IncludeOperatorStore = 0x00000001; |
|
51 const int RemoveOviStore = 0x00000008; |
|
52 //const char *operatorStoreIconPath |
|
53 // = "z:/private/20022F35/customsvg/operatorstore.svg"; |
|
54 |
|
55 void MenuStatesTest::OperatorHandler_storesPresent() |
|
56 { |
|
57 HsOperatorHandler oviHandler; |
|
58 XQSettingsManager man; |
|
59 |
|
60 bool value = oviHandler.m_q->storeValue(&man, IncludeOperatorStore); |
|
61 oviHandler.m_q->mOperatorStorePresent = value; |
|
62 QCOMPARE(oviHandler.operatorStorePresent(), value); |
|
63 |
|
64 bool value1 = !oviHandler.m_q->storeValue(&man, RemoveOviStore); |
|
65 oviHandler.m_q->mOviStorePresent = value1; |
|
66 QCOMPARE(oviHandler.oviStorePresent(), value1); |
|
67 |
|
68 } |
|
69 |
|
70 void MenuStatesTest::OperatorHandler_first() |
|
71 { |
|
72 HsOperatorHandler oviHandler; |
|
73 XQSettingsManager man; |
|
74 |
|
75 bool value = oviHandler.m_q->operatorStoreFirst(&man); |
|
76 oviHandler.m_q->mOperatorStoreFirst = value; |
|
77 QCOMPARE(oviHandler.operatorStoreFirst(), value); |
|
78 } |
|
79 |
|
80 void MenuStatesTest::OperatorHandler_type() |
|
81 { |
|
82 HsOperatorHandler oviHandler; |
|
83 XQSettingsManager man; |
|
84 |
|
85 HsOperatorHandlerPrivate::HsStoreType value |
|
86 = oviHandler.m_q->operatorStoreType(&man); |
|
87 QVERIFY(value == HsOperatorHandlerPrivate::ApplicationType |
|
88 || value == HsOperatorHandlerPrivate::UrlType |
|
89 || value == HsOperatorHandlerPrivate::NoneType); |
|
90 } |
|
91 |
|
92 void MenuStatesTest::OperatorHandler_createAction() |
|
93 { |
|
94 HsOperatorHandler oviHandler; |
|
95 oviHandler.m_q->mIcon = HbIcon(); |
|
96 HbAction *action = oviHandler.prepareOperatorStoreAction(new HbAction); |
|
97 QVERIFY(action->icon().isNull()); |
|
98 } |
|
99 |
|
100 #endif//QT_EXTENSIONS |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 class HsMainWindowMock : public HsMainWindow |
|
106 { |
|
107 virtual void setCurrentView(HbView *view); |
|
108 |
|
109 }; |
|
110 |
|
111 void HsMainWindowMock::setCurrentView(HbView *view) |
|
112 { |
|
113 Q_UNUSED(view); |
|
114 // do nothing |
|
115 } |
|
116 |
|
117 void MenuStatesTest::cleanup() |
|
118 { |
|
119 qApp->processEvents(); |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 void MenuStatesTest::ApplicationLibraryState_construction() |
|
126 { |
|
127 #ifdef Q_OS_SYMBIAN |
|
128 User::ResetInactivityTime();//it should help for Viewserver11 panic |
|
129 #ifdef UT_MEMORY_CHECK |
|
130 __UHEAP_MARK; |
|
131 #endif//UT_MEMORY_CHECK |
|
132 #endif//Q_OS_SYMBIAN |
|
133 { |
|
134 QString qApplications(hbTrId("txt_applib_title_applications")); |
|
135 |
|
136 QScopedPointer<HsAppLibraryState > appLibraryState(new HsAppLibraryState); |
|
137 |
|
138 QCOMPARE(appLibraryState->mMenuViewBuilder.currentView()->title(), |
|
139 qApplications); |
|
140 QVERIFY(appLibraryState->mAllAppsState); |
|
141 QVERIFY(appLibraryState->mAllCollectionsState); |
|
142 } |
|
143 #ifdef Q_OS_SYMBIAN |
|
144 #ifdef UT_MEMORY_CHECK |
|
145 __UHEAP_MARKEND; |
|
146 #endif//UT_MEMORY_CHECK |
|
147 #endif//Q_OS_SYMBIAN |
|
148 } |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // --------------------------------------------------------------------------- |
|
152 // |
|
153 void MenuStatesTest::ApplicationLibraryState_historySlots() |
|
154 { |
|
155 #ifdef Q_OS_SYMBIAN |
|
156 User::ResetInactivityTime();//it should help for Viewserver11 panic |
|
157 #ifdef UT_MEMORY_CHECK |
|
158 __UHEAP_MARK; |
|
159 #endif//UT_MEMORY_CHECK |
|
160 #endif//Q_OS_SYMBIAN |
|
161 { |
|
162 HsAppLibraryState appLibrary; |
|
163 |
|
164 appLibrary.allCollectionsStateEntered(); |
|
165 QCOMPARE(qobject_cast<QAbstractState *>(appLibrary.mAllCollectionsState), |
|
166 appLibrary.mHistoryTransaction->targetState()); |
|
167 QCOMPARE(appLibrary.mInstalledAppsState->transitions().length(), 1); |
|
168 QCOMPARE(appLibrary.mInstalledAppsState->transitions()[0]->sourceState(), |
|
169 qobject_cast<QState *>(appLibrary.mInstalledAppsState)); |
|
170 QCOMPARE(appLibrary.mInstalledAppsState->transitions()[0]->targetState(), |
|
171 qobject_cast<QAbstractState *>(appLibrary.mAllCollectionsState)); |
|
172 |
|
173 appLibrary.allAppsStateEntered(); |
|
174 QCOMPARE(qobject_cast<QAbstractState *>(appLibrary.mAllAppsState), |
|
175 appLibrary.mHistoryTransaction->targetState()); |
|
176 QCOMPARE(appLibrary.mInstalledAppsState->transitions().length(), 1); |
|
177 QCOMPARE(appLibrary.mInstalledAppsState->transitions()[0]->sourceState(), |
|
178 qobject_cast<QState *>(appLibrary.mInstalledAppsState)); |
|
179 QCOMPARE(appLibrary.mInstalledAppsState->transitions()[0]->targetState(), |
|
180 qobject_cast<QAbstractState *>(appLibrary.mAllAppsState)); |
|
181 |
|
182 appLibrary.collectionStateEntered(); |
|
183 QCOMPARE(appLibrary.mInstalledAppsState->transitions().length(), 1); |
|
184 QCOMPARE(appLibrary.mInstalledAppsState->transitions()[0]->sourceState(), |
|
185 qobject_cast<QState *>(appLibrary.mInstalledAppsState)); |
|
186 QCOMPARE(appLibrary.mInstalledAppsState->transitions()[0]->targetState(), |
|
187 qobject_cast<QAbstractState *>(appLibrary.mCollectionState)); |
|
188 |
|
189 } |
|
190 #ifdef Q_OS_SYMBIAN |
|
191 #ifdef UT_MEMORY_CHECK |
|
192 __UHEAP_MARKEND; |
|
193 #endif//UT_MEMORY_CHECK |
|
194 #endif//Q_OS_SYMBIAN |
|
195 } |
|
196 |
|
197 |
|
198 // --------------------------------------------------------------------------- |
|
199 // --------------------------------------------------------------------------- |
|
200 // |
|
201 void MenuStatesTest::ApplicationLibraryState_backSteppingAction() |
|
202 { |
|
203 #ifdef Q_OS_SYMBIAN |
|
204 User::ResetInactivityTime();//it should help for Viewserver11 panic |
|
205 #ifdef UT_MEMORY_CHECK |
|
206 __UHEAP_MARK; |
|
207 #endif//UT_MEMORY_CHECK |
|
208 #endif//Q_OS_SYMBIAN |
|
209 { |
|
210 QScopedPointer<HbMainWindow> wind(new HbMainWindow); |
|
211 //create statemachine to perform transitions |
|
212 QScopedPointer<QStateMachine> machine(new QStateMachine(0)); |
|
213 |
|
214 HsAppLibraryState *appLibrary = new HsAppLibraryState(machine.data()); |
|
215 |
|
216 machine->setInitialState(appLibrary); |
|
217 |
|
218 machine->start(); |
|
219 |
|
220 qApp->sendPostedEvents(); |
|
221 //initiate transition from collection state |
|
222 appLibrary->mCollectionState->openAppLibrary(); |
|
223 |
|
224 qApp->sendPostedEvents(); |
|
225 |
|
226 QVERIFY(appLibrary->mAllAppsState->mMenuView->view()->menu()); |
|
227 machine->stop(); |
|
228 qApp->removePostedEvents(0); |
|
229 disconnect(appLibrary,SIGNAL(initialize()),this,SLOT(appLibraryEntered())); |
|
230 |
|
231 qApp->processEvents(); |
|
232 } |
|
233 #ifdef Q_OS_SYMBIAN |
|
234 #ifdef UT_MEMORY_CHECK |
|
235 __UHEAP_MARKEND; |
|
236 #endif//UT_MEMORY_CHECK |
|
237 #endif//Q_OS_SYMBIAN |
|
238 } |
|
239 |
|
240 // --------------------------------------------------------------------------- |
|
241 // --------------------------------------------------------------------------- |
|
242 // |
|
243 void MenuStatesTest::ApplicationLibraryState_clearToolbarLatch() |
|
244 { |
|
245 #ifdef Q_OS_SYMBIAN |
|
246 User::ResetInactivityTime();//it should help for Viewserver11 panic |
|
247 #ifdef UT_MEMORY_CHECK |
|
248 __UHEAP_MARK; |
|
249 #endif//UT_MEMORY_CHECK |
|
250 #endif//Q_OS_SYMBIAN |
|
251 { |
|
252 HsAppLibraryState appLibrary; |
|
253 appLibrary.mMenuViewBuilder.allAppsAction()->setChecked(true); |
|
254 appLibrary.mMenuViewBuilder.toolBarActionGroup()->checkedAction()->setChecked(true); |
|
255 appLibrary.clearToolbarLatch(); |
|
256 QVERIFY(appLibrary.mMenuViewBuilder.toolBarActionGroup()->checkedAction() == NULL); |
|
257 } |
|
258 #ifdef Q_OS_SYMBIAN |
|
259 #ifdef UT_MEMORY_CHECK |
|
260 __UHEAP_MARKEND; |
|
261 #endif//UT_MEMORY_CHECK |
|
262 #endif//Q_OS_SYMBIAN |
|
263 } |
|
264 |
|
265 // --------------------------------------------------------------------------- |
|
266 // --------------------------------------------------------------------------- |
|
267 // |
|
268 #ifdef QT_EXTENSIONS |
|
269 void MenuStatesTest::ApplicationLibraryState_oviStoreAction() |
|
270 { |
|
271 User::ResetInactivityTime();//it should help for Viewserver11 panic |
|
272 #ifdef UT_MEMORY_CHECK |
|
273 __UHEAP_MARK; |
|
274 #endif//UT_MEMORY_CHECK |
|
275 { |
|
276 HsAppLibraryState appLibrary; |
|
277 QVERIFY(appLibrary.oviStoreAction()==0); |
|
278 } |
|
279 #ifdef UT_MEMORY_CHECK |
|
280 __UHEAP_MARKEND; |
|
281 #endif//UT_MEMORY_CHECK |
|
282 } |
|
283 |
|
284 // --------------------------------------------------------------------------- |
|
285 // --------------------------------------------------------------------------- |
|
286 // |
|
287 void MenuStatesTest::OperatorHandler_icon() |
|
288 { |
|
289 User::ResetInactivityTime();//it should help for Viewserver11 panic |
|
290 #ifdef UT_MEMORY_CHECK |
|
291 __UHEAP_MARK; |
|
292 #endif//UT_MEMORY_CHECK |
|
293 { |
|
294 HsOperatorHandler oviHandler; |
|
295 XQSettingsManager man; |
|
296 HbIcon testIcon = oviHandler.m_q->createIcon(&man); |
|
297 oviHandler.m_q->mIcon = testIcon; |
|
298 QCOMPARE(oviHandler.icon(), testIcon); |
|
299 } |
|
300 #ifdef UT_MEMORY_CHECK |
|
301 __UHEAP_MARKEND; |
|
302 #endif//UT_MEMORY_CHECK |
|
303 } |
|
304 |
|
305 // --------------------------------------------------------------------------- |
|
306 // --------------------------------------------------------------------------- |
|
307 // |
|
308 void MenuStatesTest::OperatorHandler_text() |
|
309 { |
|
310 User::ResetInactivityTime();//it should help for Viewserver11 panic |
|
311 #ifdef UT_MEMORY_CHECK |
|
312 __UHEAP_MARK; |
|
313 #endif//UT_MEMORY_CHECK |
|
314 { |
|
315 HsOperatorHandler oviHandler; |
|
316 XQSettingsManager man; |
|
317 |
|
318 QString testText = oviHandler.m_q->operatorStoreTitle(&man); |
|
319 oviHandler.m_q->mOperatorStoreTitle = testText; |
|
320 QCOMPARE(oviHandler.text(), testText); |
|
321 } |
|
322 #ifdef UT_MEMORY_CHECK |
|
323 __UHEAP_MARKEND; |
|
324 #endif//UT_MEMORY_CHECK |
|
325 } |
|
326 |
|
327 // --------------------------------------------------------------------------- |
|
328 // --------------------------------------------------------------------------- |
|
329 // |
|
330 void MenuStatesTest::OperatorHandler_action() |
|
331 { |
|
332 User::ResetInactivityTime();//it should help for Viewserver11 panic |
|
333 #ifdef UT_MEMORY_CHECK |
|
334 __UHEAP_MARK; |
|
335 #endif//UT_MEMORY_CHECK |
|
336 { |
|
337 HsOperatorHandler oviHandler; |
|
338 HbIcon testIcon; |
|
339 oviHandler.m_q->mIcon = testIcon; |
|
340 oviHandler.m_q->mOperatorEntry = new CaEntry;; |
|
341 QCOMPARE(oviHandler.icon(), testIcon); |
|
342 oviHandler.action(); |
|
343 QCOMPARE(oviHandler.icon(), testIcon); |
|
344 } |
|
345 #ifdef UT_MEMORY_CHECK |
|
346 __UHEAP_MARKEND; |
|
347 #endif//UT_MEMORY_CHECK |
|
348 } |
|
349 |
|
350 // --------------------------------------------------------------------------- |
|
351 // --------------------------------------------------------------------------- |
|
352 // |
|
353 void MenuStatesTest::OperatorHandler_entry() |
|
354 { |
|
355 User::ResetInactivityTime();//it should help for Viewserver11 panic |
|
356 #ifdef UT_MEMORY_CHECK |
|
357 __UHEAP_MARK; |
|
358 #endif//UT_MEMORY_CHECK |
|
359 { |
|
360 HsOperatorHandler oviHandler; |
|
361 XQSettingsManager man; |
|
362 |
|
363 CaEntry *testAppEntry = oviHandler.m_q->createAppEntry(&man); |
|
364 oviHandler.m_q->mOperatorEntry = testAppEntry; |
|
365 //if entry is NULL then tahts because there were no key in CR |
|
366 //if it is not NULL then it must be application |
|
367 QVERIFY(!testAppEntry || testAppEntry->entryTypeName() == |
|
368 Hs::applicationTypeName); |
|
369 |
|
370 CaEntry *testUrlEntry = oviHandler.m_q->createUrlEntry(&man); |
|
371 oviHandler.m_q->mOperatorEntry = testUrlEntry; |
|
372 //similar as for application above |
|
373 QVERIFY(!testUrlEntry || testUrlEntry->entryTypeName() == |
|
374 Hs::urlTypeName); |
|
375 |
|
376 } |
|
377 #ifdef UT_MEMORY_CHECK |
|
378 __UHEAP_MARKEND; |
|
379 #endif//UT_MEMORY_CHECK |
|
380 } |
|
381 |
|
382 // --------------------------------------------------------------------------- |
|
383 // --------------------------------------------------------------------------- |
|
384 // |
|
385 void MenuStatesTest::OperatorHandler_noCrWriteAccess() |
|
386 { |
|
387 User::ResetInactivityTime();//it should help for Viewserver11 panic |
|
388 #ifdef UT_MEMORY_CHECK |
|
389 __UHEAP_MARK; |
|
390 #endif//UT_MEMORY_CHECK |
|
391 { |
|
392 // XQSettingsManager *crManager = new XQSettingsManager; |
|
393 // XQCentralRepositorySettingsKey urlKey(AppLibUid, OperatorUrl); |
|
394 // QVariant urlVarian = crManager->readItemValue( |
|
395 // urlKey, XQSettingsManager::TypeString); |
|
396 // QString dbg = urlVarian.toString(); |
|
397 // bool result = crManager->writeItemValue(urlKey, QVariant("test")); |
|
398 // QCOMPARE(result, false); |
|
399 } |
|
400 #ifdef UT_MEMORY_CHECK |
|
401 __UHEAP_MARKEND; |
|
402 #endif//UT_MEMORY_CHECK |
|
403 } |
|
404 #endif//QT_EXTENSIONS |
|
405 |
|
406 |
|
407 // --------------------------------------------------------------------------- |
|
408 // --------------------------------------------------------------------------- |
|
409 // |
|
410 void MenuStatesTest::HsBaseViewState_createApplicationLaunchFailMessage() |
|
411 { |
|
412 #ifdef Q_OS_SYMBIAN |
|
413 User::ResetInactivityTime();//it should help for Viewserver11 panic |
|
414 #ifdef UT_MEMORY_CHECK |
|
415 __UHEAP_MARK; |
|
416 #endif//UT_MEMORY_CHECK |
|
417 #endif//Q_OS_SYMBIAN |
|
418 { |
|
419 HsMenuViewBuilder menuViewBuilder; |
|
420 HsMenuModeWrapper menuMode; |
|
421 HsMainWindow mainWindow; |
|
422 |
|
423 HsAllAppsState viewState(menuViewBuilder, menuMode, mainWindow); |
|
424 |
|
425 int errCode = -333; |
|
426 int dummyItemId = 555; |
|
427 viewState.createApplicationLaunchFailMessage(errCode,dummyItemId); |
|
428 QVERIFY(!viewState.mApplicationLaunchFailMessage.isNull()); |
|
429 |
|
430 QVERIFY(viewState.mApplicationLaunchFailMessage->close()); |
|
431 QTest::qWait(2000); |
|
432 } |
|
433 #ifdef Q_OS_SYMBIAN |
|
434 #ifdef UT_MEMORY_CHECK |
|
435 __UHEAP_MARKEND; |
|
436 #endif//UT_MEMORY_CHECK |
|
437 #endif//Q_OS_SYMBIAN |
|
438 } |
|
439 |
|
440 |
|
441 QTEST_MAIN(MenuStatesTest) |