90
|
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: Main test class for hsHomeScreenStateProvider library.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <qcoreapplication.h>
|
|
19 |
#include <qstandarditemmodel.h>
|
|
20 |
#include <hbmainwindow.h>
|
|
21 |
#include <hbaction.h>
|
|
22 |
#include <hbgridview.h>
|
|
23 |
#include <hbgridviewitem.h>
|
|
24 |
#include <hstest_global.h>
|
|
25 |
#include <qvaluespacepublisher.h>
|
|
26 |
|
|
27 |
#include "caitemmodel.h"
|
|
28 |
#include "hsmenuitemmodel.h"
|
|
29 |
#include "caservice.h"
|
|
30 |
#include "hsmenuservice.h"
|
|
31 |
#include "hsmenuserviceutils.h"
|
|
32 |
#include "t_hsmenuserviceprovider.h"
|
|
33 |
|
|
34 |
QTM_USE_NAMESPACE
|
|
35 |
|
|
36 |
// ---------------------------------------------------------------------------
|
97
|
37 |
//
|
90
|
38 |
// ---------------------------------------------------------------------------
|
|
39 |
//
|
|
40 |
void MenuServiceTest::MenuService_getAllApplicationsModel()
|
|
41 |
{
|
|
42 |
#ifdef Q_OS_SYMBIAN
|
|
43 |
#ifdef UT_MEMORY_CHECK
|
|
44 |
__UHEAP_MARK;
|
|
45 |
#endif
|
|
46 |
#endif
|
|
47 |
{
|
|
48 |
const Hs::HsSortAttribute
|
|
49 |
defaultSortAttribute(Hs::DescendingNameHsSortAttribute);
|
|
50 |
|
|
51 |
QScopedPointer<HsMenuItemModel>
|
|
52 |
model(HsMenuService::getAllApplicationsModel());
|
|
53 |
|
|
54 |
CaQuery actualQuery = model->mCaItemModelQuery;
|
|
55 |
CaQuery expectedQuery;
|
|
56 |
expectedQuery.setEntryRoles(ItemEntryRole);
|
|
57 |
expectedQuery.addEntryTypeName(Hs::applicationTypeName);
|
|
58 |
expectedQuery.addEntryTypeName(Hs::urlTypeName);
|
|
59 |
expectedQuery.addEntryTypeName(Hs::widgetTypeName);
|
|
60 |
expectedQuery.addEntryTypeName(Hs::templatedApplicationTypeName);
|
|
61 |
expectedQuery.setFlagsOn(VisibleEntryFlag);
|
|
62 |
expectedQuery.setFlagsOff(MissingEntryFlag);
|
|
63 |
expectedQuery.setSort(HsMenuServiceUtils::sortBy(defaultSortAttribute),
|
|
64 |
HsMenuServiceUtils::sortOrder(defaultSortAttribute));
|
|
65 |
QCOMPARE(actualQuery.mSetEntryRoles, expectedQuery.mSetEntryRoles);
|
|
66 |
QCOMPARE(actualQuery.mAddEntryTypeNames,
|
|
67 |
expectedQuery.mAddEntryTypeNames);
|
|
68 |
QCOMPARE(actualQuery.mSetFlagsOn, expectedQuery.mSetFlagsOn);
|
|
69 |
QCOMPARE(actualQuery.mSetFlagsOff, expectedQuery.mSetFlagsOff);
|
|
70 |
QCOMPARE(actualQuery.mSetSortAttribute,
|
|
71 |
expectedQuery.mSetSortAttribute);
|
|
72 |
QCOMPARE(actualQuery.mSetSortOrder, expectedQuery.mSetSortOrder);
|
|
73 |
|
|
74 |
// check non-default sort attribute
|
|
75 |
const Hs::HsSortAttribute
|
|
76 |
ascendingSortAttribute(Hs::AscendingNameHsSortAttribute);
|
|
77 |
|
|
78 |
model.reset(
|
|
79 |
HsMenuService::getAllApplicationsModel(ascendingSortAttribute));
|
|
80 |
|
|
81 |
actualQuery = model->mCaItemModelQuery;
|
|
82 |
|
|
83 |
expectedQuery.setSort(
|
|
84 |
HsMenuServiceUtils::sortBy(ascendingSortAttribute),
|
|
85 |
HsMenuServiceUtils::sortOrder(ascendingSortAttribute));
|
|
86 |
|
|
87 |
QCOMPARE(actualQuery.mSetSortAttribute,
|
|
88 |
expectedQuery.mSetSortAttribute);
|
|
89 |
QCOMPARE(actualQuery.mSetSortOrder, expectedQuery.mSetSortOrder);
|
|
90 |
}
|
|
91 |
#ifdef Q_OS_SYMBIAN
|
|
92 |
#ifdef UT_MEMORY_CHECK
|
|
93 |
__UHEAP_MARKEND;
|
|
94 |
#endif
|
|
95 |
#endif
|
|
96 |
|
|
97 |
}
|
|
98 |
|
|
99 |
// ---------------------------------------------------------------------------
|
97
|
100 |
//
|
90
|
101 |
// ---------------------------------------------------------------------------
|
|
102 |
//
|
|
103 |
void MenuServiceTest::MenuService_getAllCollectionsModel()
|
|
104 |
{
|
|
105 |
#ifdef Q_OS_SYMBIAN
|
|
106 |
#ifdef UT_MEMORY_CHECK
|
|
107 |
__UHEAP_MARK;
|
|
108 |
#endif
|
|
109 |
#endif
|
|
110 |
{
|
|
111 |
const int allCollectionId = 8;
|
|
112 |
// ensure HsMenuService::allCollectionId will return
|
|
113 |
// non zero value, if it does not already
|
|
114 |
CaService::instance()->mGetEntryIdsResult.clear();
|
|
115 |
CaService::instance()->mGetEntryIdsResult << allCollectionId;
|
|
116 |
|
|
117 |
QScopedPointer<HsMenuItemModel>
|
|
118 |
model(HsMenuService::getAllCollectionsModel());
|
|
119 |
|
|
120 |
CaQuery actualQuery = model->mCaItemModelQuery;
|
|
121 |
|
|
122 |
CaQuery expectedQuery;
|
|
123 |
expectedQuery.setParentId(HsMenuService::allCollectionsId());
|
|
124 |
expectedQuery.setFlagsOn(VisibleEntryFlag);
|
|
125 |
expectedQuery.setFlagsOff(MissingEntryFlag);
|
|
126 |
|
|
127 |
QCOMPARE(actualQuery.mSetParentId, expectedQuery.mSetParentId);
|
|
128 |
QCOMPARE(actualQuery.mSetFlagsOn, expectedQuery.mSetFlagsOn);
|
|
129 |
QCOMPARE(actualQuery.mSetFlagsOff, expectedQuery.mSetFlagsOff);
|
|
130 |
}
|
|
131 |
#ifdef Q_OS_SYMBIAN
|
|
132 |
#ifdef UT_MEMORY_CHECK
|
|
133 |
__UHEAP_MARKEND;
|
|
134 |
#endif
|
|
135 |
#endif
|
|
136 |
}
|
|
137 |
|
|
138 |
// ---------------------------------------------------------------------------
|
97
|
139 |
//
|
90
|
140 |
// ---------------------------------------------------------------------------
|
|
141 |
//
|
|
142 |
void MenuServiceTest::MenuService_getInstalledModel()
|
|
143 |
{
|
|
144 |
#ifdef Q_OS_SYMBIAN
|
|
145 |
#ifdef UT_MEMORY_CHECK
|
|
146 |
__UHEAP_MARK;
|
|
147 |
#endif
|
|
148 |
#endif
|
|
149 |
{
|
|
150 |
const Hs::HsSortAttribute
|
|
151 |
defaultSortAttribute(Hs::DescendingNameHsSortAttribute);
|
|
152 |
|
|
153 |
QScopedPointer<HsMenuItemModel>
|
|
154 |
model(HsMenuService::getInstalledModel());
|
|
155 |
|
|
156 |
CaQuery actualQuery = model->mCaItemModelQuery;
|
|
157 |
|
|
158 |
CaQuery expectedQuery;
|
|
159 |
expectedQuery.addEntryTypeName(Hs::packageTypeName);
|
|
160 |
expectedQuery.setFlagsOn(VisibleEntryFlag | RemovableEntryFlag);
|
|
161 |
expectedQuery.setFlagsOff(MissingEntryFlag);
|
|
162 |
expectedQuery.setSort(HsMenuServiceUtils::sortBy(defaultSortAttribute),
|
|
163 |
HsMenuServiceUtils::sortOrder(defaultSortAttribute));
|
|
164 |
|
|
165 |
QCOMPARE(actualQuery.mAddEntryTypeNames,
|
|
166 |
expectedQuery.mAddEntryTypeNames);
|
|
167 |
QCOMPARE(actualQuery.mSetFlagsOn, expectedQuery.mSetFlagsOn);
|
|
168 |
QCOMPARE(actualQuery.mSetFlagsOff, expectedQuery.mSetFlagsOff);
|
|
169 |
QCOMPARE(actualQuery.mSetSortAttribute,
|
|
170 |
expectedQuery.mSetSortAttribute);
|
|
171 |
QCOMPARE(actualQuery.mSetSortOrder, expectedQuery.mSetSortOrder);
|
|
172 |
|
|
173 |
|
|
174 |
// check non-default sort attribute
|
|
175 |
model.reset(
|
|
176 |
HsMenuService::getInstalledModel(Hs::CustomHsSortAttribute));
|
|
177 |
|
|
178 |
actualQuery = model->mCaItemModelQuery;
|
|
179 |
|
|
180 |
expectedQuery.setSort(
|
|
181 |
HsMenuServiceUtils::sortBy(Hs::CustomHsSortAttribute),
|
|
182 |
HsMenuServiceUtils::sortOrder(Hs::CustomHsSortAttribute));
|
|
183 |
|
|
184 |
QCOMPARE(actualQuery.mSetSortAttribute,
|
|
185 |
expectedQuery.mSetSortAttribute);
|
|
186 |
QCOMPARE(actualQuery.mSetSortOrder, expectedQuery.mSetSortOrder);
|
|
187 |
}
|
|
188 |
#ifdef Q_OS_SYMBIAN
|
|
189 |
#ifdef UT_MEMORY_CHECK
|
|
190 |
__UHEAP_MARKEND;
|
|
191 |
#endif
|
|
192 |
#endif
|
|
193 |
}
|
|
194 |
|
|
195 |
// ---------------------------------------------------------------------------
|
97
|
196 |
//
|
90
|
197 |
// ---------------------------------------------------------------------------
|
|
198 |
//
|
|
199 |
void MenuServiceTest::MenuService_getCollectionModel()
|
|
200 |
{
|
|
201 |
#ifdef Q_OS_SYMBIAN
|
|
202 |
#ifdef UT_MEMORY_CHECK
|
|
203 |
__UHEAP_MARK;
|
|
204 |
#endif
|
|
205 |
#endif
|
|
206 |
{
|
|
207 |
const Hs::HsSortAttribute
|
|
208 |
defaultSortAttribute(Hs::LatestOnTopHsSortAttribute);
|
|
209 |
const QString defaultCollectionType(Hs::collectionTypeName);
|
|
210 |
const int collectionId = 7;
|
|
211 |
|
|
212 |
QScopedPointer<HsMenuItemModel>
|
|
213 |
model(HsMenuService::getCollectionModel(collectionId));
|
|
214 |
|
|
215 |
CaQuery actualQuery = model->mCaItemModelQuery;
|
|
216 |
|
|
217 |
CaQuery expectedQuery;
|
|
218 |
expectedQuery.setParentId(collectionId);
|
|
219 |
expectedQuery.setFlagsOn(VisibleEntryFlag);
|
|
220 |
expectedQuery.setFlagsOff(MissingEntryFlag);
|
|
221 |
expectedQuery.setSort(
|
|
222 |
HsMenuServiceUtils::sortBy(defaultSortAttribute),
|
|
223 |
HsMenuServiceUtils::sortOrder(defaultSortAttribute));
|
|
224 |
|
|
225 |
|
|
226 |
// check with non-default parameters
|
|
227 |
model.reset(HsMenuService::getCollectionModel(collectionId,
|
|
228 |
Hs::NoHsSortAttribute, Hs::collectionDownloadedTypeName));
|
|
229 |
|
|
230 |
actualQuery = model->mCaItemModelQuery;
|
|
231 |
|
|
232 |
expectedQuery.setParentId(collectionId);
|
|
233 |
expectedQuery.setFlagsOn(RemovableEntryFlag | VisibleEntryFlag);
|
|
234 |
expectedQuery.setFlagsOff(MissingEntryFlag);
|
|
235 |
expectedQuery.setSort(
|
|
236 |
HsMenuServiceUtils::sortBy(Hs::NoHsSortAttribute),
|
|
237 |
HsMenuServiceUtils::sortOrder(Hs::NoHsSortAttribute));
|
|
238 |
}
|
|
239 |
#ifdef Q_OS_SYMBIAN
|
|
240 |
#ifdef UT_MEMORY_CHECK
|
|
241 |
__UHEAP_MARKEND;
|
|
242 |
#endif
|
|
243 |
#endif
|
|
244 |
}
|
|
245 |
|
|
246 |
// ---------------------------------------------------------------------------
|
97
|
247 |
//
|
90
|
248 |
// ---------------------------------------------------------------------------
|
|
249 |
//
|
|
250 |
void MenuServiceTest::MenuService_getCollectionNames()
|
|
251 |
{
|
|
252 |
#ifdef Q_OS_SYMBIAN
|
|
253 |
#ifdef UT_MEMORY_CHECK
|
|
254 |
__UHEAP_MARK;
|
|
255 |
#endif
|
|
256 |
#endif
|
|
257 |
{
|
|
258 |
QSharedPointer<CaEntry> collectionA(new CaEntry);
|
|
259 |
collectionA->mTextResult = "A";
|
|
260 |
QSharedPointer<CaEntry> collectionB(new CaEntry);
|
|
261 |
collectionB->mTextResult = "B";
|
|
262 |
|
|
263 |
CaService::instance()->mGetEntriesResult.clear();
|
|
264 |
CaService::instance()->mGetEntriesResult << collectionA;
|
|
265 |
CaService::instance()->mGetEntriesResult << collectionB;
|
|
266 |
|
|
267 |
QStringList expectedNames;
|
|
268 |
expectedNames << collectionA->text();
|
|
269 |
expectedNames << collectionB->text();
|
|
270 |
|
|
271 |
CaQuery expectedQuery;
|
|
272 |
expectedQuery.setParentId(HsMenuService::allCollectionsId());
|
|
273 |
expectedQuery.setFlagsOn(VisibleEntryFlag);
|
|
274 |
expectedQuery.setFlagsOff(MissingEntryFlag);
|
|
275 |
|
|
276 |
QStringList actualNames = HsMenuService::getCollectionNames();
|
|
277 |
|
|
278 |
QCOMPARE(actualNames, expectedNames);
|
|
279 |
|
|
280 |
CaQuery actualQuery = CaService::instance()->mGetEntriesQuery;
|
|
281 |
QCOMPARE(actualQuery.mSetParentId, expectedQuery.mSetParentId);
|
|
282 |
QCOMPARE(actualQuery.mSetFlagsOn, expectedQuery.mSetFlagsOn);
|
|
283 |
QCOMPARE(actualQuery.mSetFlagsOff, expectedQuery.mSetFlagsOff);
|
|
284 |
}
|
|
285 |
#ifdef Q_OS_SYMBIAN
|
|
286 |
#ifdef UT_MEMORY_CHECK
|
|
287 |
__UHEAP_MARKEND;
|
|
288 |
#endif
|
|
289 |
#endif
|
|
290 |
}
|
|
291 |
|
|
292 |
// ---------------------------------------------------------------------------
|
97
|
293 |
//
|
90
|
294 |
// ---------------------------------------------------------------------------
|
|
295 |
//
|
|
296 |
void MenuServiceTest::MenuService_getName()
|
|
297 |
{
|
|
298 |
#ifdef Q_OS_SYMBIAN
|
|
299 |
#ifdef UT_MEMORY_CHECK
|
|
300 |
__UHEAP_MARK;
|
|
301 |
#endif
|
|
302 |
#endif
|
|
303 |
{
|
|
304 |
const int expectedEntryId = 5989;
|
|
305 |
|
|
306 |
QString actualName = HsMenuService::getName(expectedEntryId);
|
|
307 |
CaService::instance()->mGetEntryResult.clear();
|
|
308 |
|
|
309 |
QCOMPARE(CaService::instance()->mGetEntryId, expectedEntryId);
|
|
310 |
QCOMPARE(actualName, QString());
|
|
311 |
|
|
312 |
CaService::instance()->mGetEntryResult =
|
|
313 |
QSharedPointer<CaEntry>(new CaEntry);
|
|
314 |
const QString expectedName = "ABCD";
|
|
315 |
CaService::instance()->mGetEntryResult->mTextResult = expectedName;
|
|
316 |
|
|
317 |
actualName = HsMenuService::getName(expectedEntryId);
|
|
318 |
|
|
319 |
QCOMPARE(actualName, expectedName);
|
|
320 |
}
|
|
321 |
#ifdef Q_OS_SYMBIAN
|
|
322 |
#ifdef UT_MEMORY_CHECK
|
|
323 |
__UHEAP_MARKEND;
|
|
324 |
#endif
|
|
325 |
#endif
|
|
326 |
}
|
|
327 |
|
|
328 |
// ---------------------------------------------------------------------------
|
97
|
329 |
//
|
90
|
330 |
// ---------------------------------------------------------------------------
|
|
331 |
//
|
|
332 |
void MenuServiceTest::MenuService_executeAction()
|
|
333 |
{
|
|
334 |
#ifdef Q_OS_SYMBIAN
|
|
335 |
#ifdef UT_MEMORY_CHECK
|
|
336 |
__UHEAP_MARK;
|
|
337 |
#endif
|
|
338 |
#endif
|
|
339 |
{
|
|
340 |
QSharedPointer<CaService> service = CaService::instance();
|
|
341 |
|
|
342 |
// first case: command fails for entryId=19 and
|
|
343 |
// "invalidName" action
|
|
344 |
service->mExecuteCommandResult = -333;
|
|
345 |
QString commandName = "invalidName";
|
|
346 |
int entryId = 19;
|
|
347 |
|
|
348 |
QVERIFY(!(HsMenuService::executeAction(entryId, commandName)==0));
|
|
349 |
QCOMPARE(service->mExecuteEntryId, entryId);
|
|
350 |
QCOMPARE(service->mExecuteCommand, commandName);
|
|
351 |
|
|
352 |
// now pretend CaService accepted the command above
|
|
353 |
// so HsMenuService accepts it too
|
|
354 |
service->mExecuteCommandResult = 0;
|
|
355 |
QVERIFY(HsMenuService::executeAction(entryId, commandName)==0);
|
|
356 |
|
|
357 |
}
|
|
358 |
#ifdef Q_OS_SYMBIAN
|
|
359 |
#ifdef UT_MEMORY_CHECK
|
|
360 |
__UHEAP_MARKEND;
|
|
361 |
#endif
|
|
362 |
#endif
|
|
363 |
}
|
|
364 |
|
|
365 |
// ---------------------------------------------------------------------------
|
97
|
366 |
//
|
90
|
367 |
// ---------------------------------------------------------------------------
|
|
368 |
//
|
|
369 |
void MenuServiceTest::MenuService_executeActionEntry()
|
|
370 |
{
|
|
371 |
#ifdef Q_OS_SYMBIAN
|
|
372 |
#ifdef UT_MEMORY_CHECK
|
|
373 |
__UHEAP_MARK;
|
|
374 |
#endif
|
|
375 |
#endif
|
|
376 |
{
|
|
377 |
QSharedPointer<CaService> service = CaService::instance();
|
|
378 |
|
|
379 |
// first case: command fails for entryId=19 and
|
|
380 |
// "invalidName" action
|
|
381 |
service->mExecuteCommandResult = -333;
|
|
382 |
QString commandName = "invalidName";
|
|
383 |
CaEntry entry;
|
|
384 |
|
|
385 |
QVERIFY(!(HsMenuService::executeAction(entry, commandName)==0));
|
|
386 |
QCOMPARE(service->mExecuteCommand, commandName);
|
|
387 |
|
|
388 |
// now pretend CaService accepted the command above
|
|
389 |
// so HsMenuService accepts it too
|
|
390 |
service->mExecuteCommandResult = 0;
|
|
391 |
QVERIFY(HsMenuService::executeAction(entry, commandName)==0);
|
|
392 |
|
|
393 |
}
|
|
394 |
#ifdef Q_OS_SYMBIAN
|
|
395 |
#ifdef UT_MEMORY_CHECK
|
|
396 |
__UHEAP_MARKEND;
|
|
397 |
#endif
|
|
398 |
#endif
|
|
399 |
}
|
|
400 |
|
|
401 |
// ---------------------------------------------------------------------------
|
97
|
402 |
//
|
90
|
403 |
// ---------------------------------------------------------------------------
|
|
404 |
//
|
|
405 |
#ifdef Q_OS_SYMBIAN
|
|
406 |
void MenuServiceTest::MenuService_launchTS()
|
|
407 |
{
|
|
408 |
#ifdef UT_MEMORY_CHECK
|
|
409 |
__UHEAP_MARK;
|
|
410 |
#endif
|
|
411 |
{
|
|
412 |
QVERIFY(HsMenuService::launchTaskSwitcher());
|
|
413 |
}
|
|
414 |
#ifdef UT_MEMORY_CHECK
|
|
415 |
__UHEAP_MARKEND;
|
|
416 |
#endif
|
|
417 |
}
|
|
418 |
#endif//Q_OS_SYMBIAN
|
|
419 |
|
97
|
420 |
// ---------------------------------------------------------------------------
|
|
421 |
//
|
|
422 |
// ---------------------------------------------------------------------------
|
|
423 |
//
|
90
|
424 |
void MenuServiceTest::MenuService_createCollection()
|
|
425 |
{
|
|
426 |
#ifdef Q_OS_SYMBIAN
|
|
427 |
#ifdef UT_MEMORY_CHECK
|
|
428 |
__UHEAP_MARK;
|
|
429 |
#endif
|
|
430 |
{
|
|
431 |
QSharedPointer<CaService> service = CaService::instance();
|
|
432 |
|
|
433 |
// case 1: create collection fails
|
|
434 |
service->mCreateEntryResult.clear();
|
|
435 |
const QString createdCollectionName("collectionName");
|
|
436 |
int actualCollectionId =
|
|
437 |
HsMenuService::createCollection(createdCollectionName);
|
|
438 |
|
|
439 |
QCOMPARE(actualCollectionId, 0);
|
|
440 |
|
|
441 |
CaEntry& collectionEntry = service->mCreatedEntry;
|
|
442 |
QCOMPARE(collectionEntry.entryTypeName(),
|
|
443 |
QString(Hs::collectionTypeName));
|
|
444 |
QCOMPARE(collectionEntry.mCaEntryRole, GroupEntryRole);
|
|
445 |
QCOMPARE(collectionEntry.text(), createdCollectionName);
|
|
446 |
CaIconDescription collectionIcon =
|
|
447 |
collectionEntry.mSetCaIconDescription;
|
|
448 |
QCOMPARE(collectionIcon.mSetFileName,
|
|
449 |
QString(Hs::defaultCollectionIconId));
|
|
450 |
|
|
451 |
// case 2: collection can be created
|
|
452 |
const int createdCollectionId = 9;
|
|
453 |
QSharedPointer<CaEntry> createdEntry(new CaEntry);
|
|
454 |
createdEntry->mIdResult = createdCollectionId;
|
|
455 |
service->mCreateEntryResult = createdEntry;
|
|
456 |
|
|
457 |
actualCollectionId =
|
|
458 |
HsMenuService::createCollection(createdCollectionName);
|
|
459 |
|
|
460 |
QCOMPARE(actualCollectionId, createdCollectionId);
|
|
461 |
QCOMPARE(service->mCreatedEntry.mAttributes[Hs::groupNameAttributeName],
|
|
462 |
createdCollectionName);
|
|
463 |
QCOMPARE(service->mAppendGroupId, HsMenuService::allCollectionsId());
|
|
464 |
QCOMPARE(service->mAppenEntryId, createdCollectionId);
|
|
465 |
}
|
|
466 |
#endif
|
|
467 |
#ifdef Q_OS_SYMBIAN
|
|
468 |
#ifdef UT_MEMORY_CHECK
|
|
469 |
__UHEAP_MARKEND;
|
|
470 |
#endif
|
|
471 |
#endif
|
|
472 |
}
|
|
473 |
|
97
|
474 |
// ---------------------------------------------------------------------------
|
|
475 |
//
|
|
476 |
// ---------------------------------------------------------------------------
|
|
477 |
//
|
90
|
478 |
void MenuServiceTest::MenuService_renameCollection()
|
|
479 |
{
|
|
480 |
#ifdef Q_OS_SYMBIAN
|
|
481 |
#ifdef UT_MEMORY_CHECK
|
|
482 |
__UHEAP_MARK;
|
|
483 |
#endif
|
|
484 |
#endif
|
|
485 |
{
|
|
486 |
QSharedPointer<CaService> service = CaService::instance();
|
|
487 |
|
|
488 |
service->mGetEntryResult.clear();
|
|
489 |
|
|
490 |
const QString newCollectionName("DEFG");
|
|
491 |
const int collectionId = 8;
|
|
492 |
|
|
493 |
// case 1: no entry to rename has been found
|
|
494 |
QVERIFY(!HsMenuService::renameCollection(collectionId,
|
|
495 |
newCollectionName));
|
|
496 |
QCOMPARE(service->mGetEntryId, collectionId);
|
|
497 |
|
|
498 |
// case 2: entry to rename has been found
|
|
499 |
QSharedPointer<CaEntry> collectionEntry(new CaEntry);
|
|
500 |
service->mGetEntryResult = collectionEntry;
|
|
501 |
service->mUpdateEntryResult = true;
|
|
502 |
QVERIFY(HsMenuService::renameCollection(collectionId,
|
|
503 |
newCollectionName));
|
|
504 |
|
|
505 |
QCOMPARE(service->mUpdateEntry.text(), newCollectionName);
|
|
506 |
}
|
|
507 |
#ifdef Q_OS_SYMBIAN
|
|
508 |
#ifdef UT_MEMORY_CHECK
|
|
509 |
__UHEAP_MARKEND;
|
|
510 |
#endif
|
|
511 |
#endif
|
|
512 |
}
|
|
513 |
|
97
|
514 |
// ---------------------------------------------------------------------------
|
|
515 |
//
|
|
516 |
// ---------------------------------------------------------------------------
|
|
517 |
//
|
90
|
518 |
void MenuServiceTest::MenuService_removeCollection()
|
|
519 |
{
|
|
520 |
#ifdef Q_OS_SYMBIAN
|
|
521 |
#ifdef UT_MEMORY_CHECK
|
|
522 |
__UHEAP_MARK;
|
|
523 |
#endif
|
|
524 |
#endif
|
|
525 |
{
|
|
526 |
QSharedPointer<CaService> service = CaService::instance();
|
|
527 |
const int collectionId = 1;
|
|
528 |
|
|
529 |
// case 1: service cannot remove collection
|
|
530 |
service->mRemoveEntryForIdResult = false;
|
|
531 |
QVERIFY(!HsMenuService::removeCollection(collectionId));
|
|
532 |
QCOMPARE(service->mRemoveEntryId, collectionId);
|
|
533 |
|
|
534 |
// case 2: service can remove collection
|
|
535 |
service->mRemoveEntryForIdResult = true;
|
|
536 |
QVERIFY(HsMenuService::removeCollection(collectionId));
|
|
537 |
}
|
|
538 |
#ifdef Q_OS_SYMBIAN
|
|
539 |
#ifdef UT_MEMORY_CHECK
|
|
540 |
__UHEAP_MARKEND;
|
|
541 |
#endif
|
|
542 |
#endif
|
|
543 |
}
|
|
544 |
|
97
|
545 |
// ---------------------------------------------------------------------------
|
|
546 |
//
|
|
547 |
// ---------------------------------------------------------------------------
|
|
548 |
//
|
90
|
549 |
void MenuServiceTest::MenuService_addApplicationsToCollection()
|
|
550 |
{
|
|
551 |
#ifdef Q_OS_SYMBIAN
|
|
552 |
#ifdef UT_MEMORY_CHECK
|
|
553 |
__UHEAP_MARK;
|
|
554 |
#endif
|
|
555 |
#endif
|
|
556 |
{
|
|
557 |
QSharedPointer<CaService> service = CaService::instance();
|
|
558 |
QList<int> applicationIdList;
|
|
559 |
applicationIdList << 1 << 2 << 3;
|
|
560 |
const int collectionId = 11;
|
|
561 |
|
|
562 |
service->mAppendEntriesToGroupResult = true;
|
|
563 |
QVERIFY(HsMenuService::addApplicationsToCollection(
|
|
564 |
applicationIdList, collectionId));
|
|
565 |
|
|
566 |
QCOMPARE(service->mAppendEntryIdList, applicationIdList);
|
|
567 |
QCOMPARE(service->mAppendListGroupId , collectionId);
|
|
568 |
|
|
569 |
// pretend CaService to fail on append
|
|
570 |
service->mAppendEntriesToGroupResult = false;
|
|
571 |
QVERIFY(!HsMenuService::addApplicationsToCollection(
|
|
572 |
applicationIdList, collectionId));
|
|
573 |
}
|
|
574 |
#ifdef Q_OS_SYMBIAN
|
|
575 |
#ifdef UT_MEMORY_CHECK
|
|
576 |
__UHEAP_MARKEND;
|
|
577 |
#endif
|
|
578 |
#endif
|
|
579 |
}
|
|
580 |
|
97
|
581 |
// ---------------------------------------------------------------------------
|
|
582 |
//
|
|
583 |
// ---------------------------------------------------------------------------
|
|
584 |
//
|
90
|
585 |
void MenuServiceTest::MenuService_removeApplicationFromCollection()
|
|
586 |
{
|
|
587 |
#ifdef Q_OS_SYMBIAN
|
|
588 |
#ifdef UT_MEMORY_CHECK
|
|
589 |
__UHEAP_MARK;
|
|
590 |
#endif
|
|
591 |
#endif
|
|
592 |
{
|
|
593 |
QSharedPointer<CaService> service = CaService::instance();
|
|
594 |
|
|
595 |
const int collectionId = 4;
|
|
596 |
const int applicationId = 25;
|
|
597 |
|
|
598 |
service->mRemoveEntryFromGroupResult = true;
|
|
599 |
QVERIFY(HsMenuService::removeApplicationFromCollection(
|
|
600 |
applicationId, collectionId));
|
|
601 |
|
|
602 |
QCOMPARE(service->mRemoveGroupId, collectionId);
|
|
603 |
QCOMPARE(service->mRemoveEntryFromGroupId, applicationId);
|
|
604 |
|
|
605 |
// pretend CaService to fail on removal operation
|
|
606 |
service->mRemoveEntryFromGroupResult = true;
|
|
607 |
QVERIFY(HsMenuService::removeApplicationFromCollection(
|
|
608 |
applicationId, collectionId));
|
|
609 |
}
|
|
610 |
#ifdef Q_OS_SYMBIAN
|
|
611 |
#ifdef UT_MEMORY_CHECK
|
|
612 |
__UHEAP_MARKEND;
|
|
613 |
#endif
|
|
614 |
#endif
|
|
615 |
}
|
|
616 |
|
|
617 |
// ---------------------------------------------------------------------------
|
97
|
618 |
//
|
90
|
619 |
// ---------------------------------------------------------------------------
|
|
620 |
//
|
|
621 |
void MenuServiceTest::MenuService_organizeCollection()
|
|
622 |
{
|
|
623 |
#ifdef Q_OS_SYMBIAN
|
|
624 |
#ifdef UT_MEMORY_CHECK
|
|
625 |
__UHEAP_MARK;
|
|
626 |
#endif
|
|
627 |
#endif
|
|
628 |
{
|
|
629 |
QSharedPointer<CaService> service = CaService::instance();
|
|
630 |
QList<int> entryIdList;
|
|
631 |
entryIdList << 2 << 3 << 4;
|
|
632 |
const int groupId = 2;
|
|
633 |
|
|
634 |
service->mCustomSortResult = true;
|
|
635 |
QVERIFY(HsMenuService::organizeCollection(
|
|
636 |
groupId, entryIdList));
|
|
637 |
|
|
638 |
QCOMPARE(service->mCustomSortGroupId, groupId);
|
|
639 |
QCOMPARE(service->mCustomSortEntryIdList, entryIdList);
|
|
640 |
|
|
641 |
// pretend CaService fails on customSort
|
|
642 |
service->mCustomSortResult = false;
|
|
643 |
QVERIFY(!HsMenuService::organizeCollection(
|
|
644 |
groupId, entryIdList));
|
|
645 |
|
|
646 |
}
|
|
647 |
#ifdef Q_OS_SYMBIAN
|
|
648 |
#ifdef UT_MEMORY_CHECK
|
|
649 |
__UHEAP_MARKEND;
|
|
650 |
#endif
|
|
651 |
#endif
|
|
652 |
|
|
653 |
}
|
|
654 |
|
|
655 |
// ---------------------------------------------------------------------------
|
97
|
656 |
//
|
90
|
657 |
// ---------------------------------------------------------------------------
|
|
658 |
//
|
|
659 |
void MenuServiceTest::MenuService_touchAction()
|
|
660 |
{
|
|
661 |
#ifdef Q_OS_SYMBIAN
|
|
662 |
#ifdef UT_MEMORY_CHECK
|
|
663 |
__UHEAP_MARK;
|
|
664 |
#endif
|
|
665 |
#endif
|
|
666 |
{
|
|
667 |
QSharedPointer<CaService> service = CaService::instance();
|
|
668 |
|
|
669 |
////touch on unused entry
|
|
670 |
const int touchedEntryId = 5;
|
|
671 |
QSharedPointer<CaEntry> touchedEntry(new CaEntry);
|
|
672 |
touchedEntry->mIdResult = touchedEntryId;
|
|
673 |
touchedEntry->setText("GHI");
|
|
674 |
touchedEntry->setFlags(RemovableEntryFlag | VisibleEntryFlag);
|
|
675 |
service->mGetEntryResult = touchedEntry;
|
|
676 |
service->mTouchResult = true;
|
|
677 |
|
|
678 |
HsMenuService::touch(touchedEntryId);
|
|
679 |
QCOMPARE(service->mGetEntryId, touchedEntryId);
|
|
680 |
QCOMPARE(service->mTouchEntry.id(), touchedEntryId);
|
|
681 |
QCOMPARE(service->mTouchEntry.text(), touchedEntry->text());
|
|
682 |
|
|
683 |
////touch on already used entry
|
|
684 |
const int unTouchedEntryId = 5;
|
|
685 |
QSharedPointer<CaEntry> unTouchedEntry(new CaEntry);
|
|
686 |
unTouchedEntry->mIdResult = unTouchedEntryId;
|
|
687 |
unTouchedEntry->setText("GHI_UT");
|
|
688 |
unTouchedEntry->setFlags(0);
|
|
689 |
service->mGetEntryResult = unTouchedEntry;
|
|
690 |
service->mTouchResult = true;
|
|
691 |
|
|
692 |
HsMenuService::touch(touchedEntryId);
|
|
693 |
QCOMPARE(service->mGetEntryId, unTouchedEntryId);
|
|
694 |
QCOMPARE(service->mTouchEntry.id(), touchedEntryId);
|
|
695 |
QCOMPARE(service->mTouchEntry.text(), touchedEntry->text());
|
|
696 |
}
|
|
697 |
#ifdef Q_OS_SYMBIAN
|
|
698 |
#ifdef UT_MEMORY_CHECK
|
|
699 |
__UHEAP_MARKEND;
|
|
700 |
#endif
|
|
701 |
#endif
|
|
702 |
|
|
703 |
}
|
|
704 |
|
97
|
705 |
// ---------------------------------------------------------------------------
|
|
706 |
//
|
|
707 |
// ---------------------------------------------------------------------------
|
|
708 |
//
|
|
709 |
void MenuServiceTest::MenuService_touchAction_ByEntry()
|
|
710 |
{
|
|
711 |
#ifdef Q_OS_SYMBIAN
|
|
712 |
#ifdef UT_MEMORY_CHECK
|
|
713 |
__UHEAP_MARK;
|
|
714 |
#endif
|
|
715 |
#endif
|
|
716 |
{
|
|
717 |
QSharedPointer<CaService> service = CaService::instance();
|
|
718 |
|
|
719 |
////touch on unused entry
|
|
720 |
const int touchedEntryId = 5;
|
|
721 |
QSharedPointer<CaEntry> touchedEntry(new CaEntry);
|
|
722 |
touchedEntry->mIdResult = touchedEntryId;
|
|
723 |
touchedEntry->setText("GHI");
|
|
724 |
touchedEntry->setFlags(RemovableEntryFlag | VisibleEntryFlag);
|
|
725 |
service->mGetEntryResult = touchedEntry;
|
|
726 |
service->mTouchResult = true;
|
|
727 |
|
|
728 |
HsMenuService::touch(*touchedEntry);
|
|
729 |
QCOMPARE(service->mTouchEntry.id(), touchedEntryId);
|
|
730 |
QCOMPARE(service->mTouchEntry.text(), touchedEntry->text());
|
|
731 |
|
|
732 |
////touch on already used entry
|
|
733 |
const int unTouchedEntryId = 5;
|
|
734 |
QSharedPointer<CaEntry> unTouchedEntry(new CaEntry);
|
|
735 |
unTouchedEntry->mIdResult = unTouchedEntryId;
|
|
736 |
unTouchedEntry->setText("GHI_UT");
|
|
737 |
unTouchedEntry->setFlags(0);
|
|
738 |
service->mGetEntryResult = unTouchedEntry;
|
|
739 |
service->mTouchResult = true;
|
|
740 |
|
|
741 |
HsMenuService::touch(*touchedEntry);
|
|
742 |
QCOMPARE(service->mTouchEntry.id(), touchedEntryId);
|
|
743 |
QCOMPARE(service->mTouchEntry.text(), touchedEntry->text());
|
|
744 |
}
|
|
745 |
#ifdef Q_OS_SYMBIAN
|
|
746 |
#ifdef UT_MEMORY_CHECK
|
|
747 |
__UHEAP_MARKEND;
|
|
748 |
#endif
|
|
749 |
#endif
|
|
750 |
|
|
751 |
}
|
90
|
752 |
|
|
753 |
// ---------------------------------------------------------------------------
|
97
|
754 |
//
|
90
|
755 |
// ---------------------------------------------------------------------------
|
|
756 |
//
|
|
757 |
void MenuServiceTest::MenuService_touchListOfIdsAction()
|
|
758 |
{
|
|
759 |
#ifdef Q_OS_SYMBIAN
|
|
760 |
#ifdef UT_MEMORY_CHECK
|
|
761 |
__UHEAP_MARK;
|
|
762 |
#endif
|
|
763 |
#endif
|
|
764 |
{
|
|
765 |
QSharedPointer<CaService> service = CaService::instance();
|
|
766 |
|
|
767 |
const int touchedEntryId = 5;
|
|
768 |
QSharedPointer<CaEntry> touchedEntry(new CaEntry);
|
|
769 |
touchedEntry->mIdResult = 9999;
|
|
770 |
touchedEntry->setText("GHI");
|
|
771 |
touchedEntry->setFlags(RemovableEntryFlag | VisibleEntryFlag);
|
|
772 |
service->mGetEntryResult = touchedEntry;
|
|
773 |
service->mTouchResult = true;
|
|
774 |
service->mGetEntryIdsResult.append(touchedEntryId);
|
|
775 |
|
|
776 |
const int alreadyTouchedEntryId = 6;
|
|
777 |
//alreadyTouchedEntryId is not return by mGetEntryIds
|
|
778 |
//service->mGetEntryIdsResult.append(alreadyTouchedEntryId);
|
|
779 |
|
|
780 |
QList<int> entryIdList;
|
|
781 |
entryIdList.append(touchedEntryId);
|
|
782 |
entryIdList.append(alreadyTouchedEntryId);
|
|
783 |
|
|
784 |
HsMenuService::touch(entryIdList);
|
|
785 |
|
|
786 |
QCOMPARE((bool)service->mTouchEntriesId.contains(touchedEntryId),true);
|
|
787 |
QCOMPARE((bool)service->mTouchEntriesId.contains(alreadyTouchedEntryId),false);
|
|
788 |
|
|
789 |
QCOMPARE(service->mGetEntryIdQuery.mSetFlagsOn,RemovableEntryFlag);
|
|
790 |
QCOMPARE(service->mGetEntryIdQuery.mSetFlagsOff,UsedEntryFlag);
|
|
791 |
QCOMPARE(service->mGetEntryIdQuery.mSetEntryRoles,ItemEntryRole);
|
|
792 |
|
|
793 |
QCOMPARE(service->mGetEntryId, touchedEntryId);
|
|
794 |
QCOMPARE(service->mTouchEntry.id(), touchedEntryId);
|
|
795 |
QCOMPARE(service->mTouchEntry.text(), touchedEntry->text());
|
|
796 |
}
|
|
797 |
#ifdef Q_OS_SYMBIAN
|
|
798 |
#ifdef UT_MEMORY_CHECK
|
|
799 |
__UHEAP_MARKEND;
|
|
800 |
#endif
|
|
801 |
#endif
|
|
802 |
}
|
|
803 |
|
|
804 |
// ---------------------------------------------------------------------------
|
97
|
805 |
//
|
90
|
806 |
// ---------------------------------------------------------------------------
|
|
807 |
//
|
|
808 |
void MenuServiceTest::MenuService_launchSoftwareUpdate()
|
|
809 |
{
|
|
810 |
#ifdef Q_OS_SYMBIAN
|
|
811 |
#ifdef UT_MEMORY_CHECK
|
|
812 |
__UHEAP_MARK;
|
|
813 |
#endif
|
|
814 |
#endif
|
|
815 |
{
|
|
816 |
CaService::instance()->mExecuteCommandResult = 0;
|
|
817 |
QCOMPARE(HsMenuService::launchSoftwareUpdate(),0);
|
|
818 |
QCOMPARE(CaService::instance()->mExecuteCommand,
|
|
819 |
QString(Hs::openActionIdentifier));
|
|
820 |
QCOMPARE(CaService::instance()->mExecuteEntry.mEntryTypeNameResult,
|
|
821 |
QString(Hs::applicationTypeName));
|
|
822 |
QCOMPARE(CaService::instance()->mExecuteEntry.mAttributes.value(
|
|
823 |
Hs::applicationUidEntryKey),
|
|
824 |
QString::number(Hs::softwareUpdateApplicationUid));
|
|
825 |
|
|
826 |
CaService::instance()->mExecuteCommandResult = -333;
|
|
827 |
QCOMPARE(HsMenuService::launchSoftwareUpdate(),-333);
|
|
828 |
}
|
|
829 |
#ifdef Q_OS_SYMBIAN
|
|
830 |
#ifdef UT_MEMORY_CHECK
|
|
831 |
__UHEAP_MARKEND;
|
|
832 |
#endif
|
|
833 |
#endif
|
|
834 |
}
|
|
835 |
|
|
836 |
// ---------------------------------------------------------------------------
|
97
|
837 |
//
|
90
|
838 |
// ---------------------------------------------------------------------------
|
|
839 |
//
|
|
840 |
void MenuServiceTest::MenuService_collectionIdByType()
|
|
841 |
{
|
|
842 |
#ifdef Q_OS_SYMBIAN
|
|
843 |
#ifdef UT_MEMORY_CHECK
|
|
844 |
__UHEAP_MARK;
|
|
845 |
#endif
|
|
846 |
#endif
|
|
847 |
{
|
|
848 |
const int ourCollectionId = 123;
|
|
849 |
QSharedPointer<CaService> service = CaService::instance();
|
|
850 |
CaService::instance()->mGetEntryIdsResult.clear();
|
|
851 |
CaService::instance()->mGetEntryIdsResult << ourCollectionId;
|
|
852 |
|
|
853 |
int result = HsMenuService::collectionIdByType("collection");
|
|
854 |
|
|
855 |
QCOMPARE(result, ourCollectionId);
|
|
856 |
}
|
|
857 |
#ifdef Q_OS_SYMBIAN
|
|
858 |
#ifdef UT_MEMORY_CHECK
|
|
859 |
__UHEAP_MARKEND;
|
|
860 |
#endif
|
|
861 |
#endif
|
|
862 |
}
|
|
863 |
|
|
864 |
// ---------------------------------------------------------------------------
|
97
|
865 |
//
|
90
|
866 |
// ---------------------------------------------------------------------------
|
|
867 |
//
|
|
868 |
void MenuServiceTest::initTestCase()
|
|
869 |
{
|
|
870 |
const int allCollectionId = 8;
|
|
871 |
// ensure HsMenuService::allCollectionId will return
|
|
872 |
// non zero value, if it does not already
|
|
873 |
CaService::instance()->mGetEntryIdsResult.clear();
|
|
874 |
CaService::instance()->mGetEntryIdsResult << allCollectionId;
|
|
875 |
}
|
|
876 |
|
|
877 |
void MenuServiceTest::cleanup()
|
|
878 |
{
|
|
879 |
CaService::instance()->clear();
|
|
880 |
}
|
97
|
881 |
|
90
|
882 |
// ---------------------------------------------------------------------------
|
97
|
883 |
//
|
90
|
884 |
// ---------------------------------------------------------------------------
|
|
885 |
//
|
|
886 |
void MenuServiceTest::cleanupTestCase()
|
|
887 |
{
|
|
888 |
#ifdef Q_OS_SYMBIAN
|
|
889 |
// stopThread();
|
|
890 |
#endif //Q_OS_SYMBIAN
|
|
891 |
}
|
|
892 |
|
|
893 |
// ---------------------------------------------------------------------------
|
97
|
894 |
//
|
90
|
895 |
// ---------------------------------------------------------------------------
|
97
|
896 |
//
|
90
|
897 |
int threadFunction(void *params)
|
|
898 |
{
|
|
899 |
Q_UNUSED(params)
|
|
900 |
#ifdef Q_OS_SYMBIAN
|
|
901 |
while (ETrue) {
|
|
902 |
User::ResetInactivityTime();//it should help for Viewserver11 panic
|
|
903 |
User::After(5000000);
|
|
904 |
}
|
|
905 |
#endif //Q_OS_SYMBIAN
|
|
906 |
return 0;
|
|
907 |
}
|
|
908 |
|
|
909 |
#ifdef Q_OS_SYMBIAN
|
|
910 |
|
|
911 |
// ---------------------------------------------------------------------------
|
97
|
912 |
//
|
90
|
913 |
// ---------------------------------------------------------------------------
|
|
914 |
//
|
|
915 |
void MenuServiceTest::startThread()
|
|
916 |
{
|
|
917 |
User::LeaveIfError(iThread.Create(
|
|
918 |
_L("thread_kill_viewsrv11"),
|
|
919 |
threadFunction,
|
|
920 |
16384,
|
|
921 |
4000,
|
|
922 |
4000,
|
|
923 |
NULL));
|
|
924 |
iThread.Resume();
|
|
925 |
}
|
|
926 |
#endif //Q_OS_SYMBIAN
|
|
927 |
|
|
928 |
|
|
929 |
#ifdef Q_OS_SYMBIAN
|
|
930 |
|
97
|
931 |
|
90
|
932 |
// ---------------------------------------------------------------------------
|
97
|
933 |
//
|
90
|
934 |
// ---------------------------------------------------------------------------
|
|
935 |
//
|
|
936 |
void MenuServiceTest::stopThread()
|
|
937 |
{
|
|
938 |
iThread.Close();
|
|
939 |
}
|
|
940 |
#endif //Q_OS_SYMBIAN
|
|
941 |
|
|
942 |
QTEST_MAIN(MenuServiceTest)
|