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:
|
|
15 |
*
|
|
16 |
*/
|
97
|
17 |
|
90
|
18 |
#include <qcoreapplication.h>
|
|
19 |
#include <qstandarditemmodel.h>
|
|
20 |
#include "caquery.h"
|
|
21 |
#include <hstest_global.h>
|
|
22 |
#include "hsmenuservice.h"
|
|
23 |
#include "hsmenucollectionsitemmodel.h"
|
|
24 |
#include "hsmenuitemmodel.h"
|
|
25 |
#include "hsmenuserviceutils.h"
|
|
26 |
#include "t_hsmenuserviceprovider.h"
|
|
27 |
#include "hsiconsidleloader.h"
|
|
28 |
|
97
|
29 |
|
|
30 |
// ---------------------------------------------------------------------------
|
|
31 |
//
|
|
32 |
// ---------------------------------------------------------------------------
|
|
33 |
//
|
90
|
34 |
void MenuServiceTest::HsMenuItemModel_construction()
|
|
35 |
{
|
|
36 |
QScopedPointer<QObject> parent(new QObject);
|
|
37 |
CaQuery query;
|
|
38 |
query.mQueryId = "__HsMenuItemModel_construction_CaQuery";
|
|
39 |
HsMenuItemModel model(query, parent.data());
|
|
40 |
QCOMPARE(model.mCaItemModelQuery.mQueryId, query.mQueryId);
|
|
41 |
QCOMPARE(model.QObject::parent(), parent.data());
|
|
42 |
QVERIFY(model.getIconSize().isValid());
|
|
43 |
}
|
|
44 |
|
97
|
45 |
// ---------------------------------------------------------------------------
|
|
46 |
//
|
|
47 |
// ---------------------------------------------------------------------------
|
|
48 |
//
|
90
|
49 |
void MenuServiceTest::HsMenuItemModel_setSort()
|
|
50 |
{
|
|
51 |
HsMenuItemModel model(CaQuery(), this);
|
|
52 |
|
|
53 |
{
|
|
54 |
const Hs::HsSortAttribute sortAttribute = Hs::NoHsSortAttribute;
|
|
55 |
|
|
56 |
model.setSort(sortAttribute);
|
|
57 |
QCOMPARE(model.mSetSortAttribute, HsMenuServiceUtils::sortBy(sortAttribute));
|
|
58 |
QCOMPARE(model.mSetSortOrder, HsMenuServiceUtils::sortOrder(sortAttribute));
|
|
59 |
}
|
|
60 |
{
|
|
61 |
const Hs::HsSortAttribute sortAttribute = Hs::DescendingNameHsSortAttribute;
|
|
62 |
|
|
63 |
model.setSort(sortAttribute);
|
|
64 |
QCOMPARE(model.mSetSortAttribute, HsMenuServiceUtils::sortBy(sortAttribute));
|
|
65 |
QCOMPARE(model.mSetSortOrder, HsMenuServiceUtils::sortOrder(sortAttribute));
|
|
66 |
}
|
|
67 |
}
|
|
68 |
|
97
|
69 |
// ---------------------------------------------------------------------------
|
|
70 |
//
|
|
71 |
// ---------------------------------------------------------------------------
|
|
72 |
//
|
90
|
73 |
void MenuServiceTest::HsMenuItemModel_getData()
|
|
74 |
{
|
|
75 |
HsMenuItemModel model(CaQuery(), this);
|
|
76 |
|
|
77 |
Qt::ItemDataRole role = Qt::DecorationRole;
|
|
78 |
const QModelIndex index = model.index(0, 0);
|
97
|
79 |
const QVariant expectedDecoration = QVariant(HbIcon(Hs::newIconId));
|
90
|
80 |
|
|
81 |
model.mRootResult = index;
|
|
82 |
model.mEntryResult->mFlagsResult = 0;
|
|
83 |
model.mEntryResult->mEntryTypeNameResult = Hs::collectionDownloadedTypeName;
|
|
84 |
model.setSecondLineVisibility(true);
|
97
|
85 |
model.mDataResult = expectedDecoration;
|
90
|
86 |
|
|
87 |
QList<QVariant> actualResult = model.data(index, role).toList();
|
97
|
88 |
|
|
89 |
QCOMPARE(model.mDataIndex,index);
|
|
90 |
QCOMPARE(model.mDataRole,(int)role);
|
|
91 |
QCOMPARE(actualResult.empty(),false);
|
|
92 |
QCOMPARE(actualResult.at(0).value<HbIcon>().iconName(),
|
90
|
93 |
QString(Hs::newIconId));
|
97
|
94 |
|
90
|
95 |
QCOMPARE(model.data(index), model.mDataResult);
|
|
96 |
}
|
|
97 |
|
97
|
98 |
// ---------------------------------------------------------------------------
|
|
99 |
//
|
|
100 |
// ---------------------------------------------------------------------------
|
|
101 |
//
|
90
|
102 |
void MenuServiceTest::HsMenuItemModel_newIconNeeded()
|
|
103 |
{
|
|
104 |
HsMenuItemModel model(CaQuery(), this);
|
|
105 |
|
|
106 |
const QModelIndex index = model.index(0, 0);
|
|
107 |
model.mRootResult = index;
|
|
108 |
model.mEntryResult->mFlagsResult = 0;
|
|
109 |
model.mEntryResult->mEntryTypeNameResult = Hs::collectionDownloadedTypeName;
|
|
110 |
model.setSecondLineVisibility(true);
|
|
111 |
QVERIFY(model.newIconNeeded(index));
|
|
112 |
|
|
113 |
model.mRootResult = QModelIndex(); // invalid
|
|
114 |
QVERIFY(!model.root().isValid() &&
|
|
115 |
!model.newIconNeeded(index));
|
|
116 |
|
|
117 |
model.mRootResult = index;
|
|
118 |
model.mEntryResult->mFlagsResult = UsedEntryFlag;
|
|
119 |
QVERIFY((model.entry(index)->flags() & UsedEntryFlag) &&
|
|
120 |
!model.newIconNeeded(index));
|
|
121 |
|
|
122 |
model.mEntryResult->mFlagsResult = 0;
|
|
123 |
model.mEntryResult->mEntryTypeNameResult = "";
|
|
124 |
QVERIFY((model.entry(index)->entryTypeName() != Hs::collectionDownloadedTypeName ) &&
|
|
125 |
!model.newIconNeeded(index));
|
|
126 |
|
|
127 |
}
|
|
128 |
|
97
|
129 |
// ---------------------------------------------------------------------------
|
|
130 |
//
|
|
131 |
// ---------------------------------------------------------------------------
|
|
132 |
//
|
90
|
133 |
void MenuServiceTest::HsMenuItemModel_uninstallChange()
|
|
134 |
{
|
|
135 |
HsMenuItemModel model(CaQuery(), this);
|
|
136 |
const QModelIndex index = model.index(0, 0);
|
|
137 |
model.mRootResult = index;
|
|
138 |
model.mEntryResult->mFlagsResult = 0;
|
|
139 |
model.mEntryResult->setAttribute(QString("component_id"),
|
|
140 |
QString().setNum(1));
|
|
141 |
|
|
142 |
model.uninstallChange(1, 5);
|
|
143 |
QCOMPARE(model.mComponentId, 1);
|
|
144 |
QCOMPARE(model.mIds.count(), 2);
|
|
145 |
QCOMPARE(model.mEntryResult->attribute(
|
|
146 |
QString("uninstall_progress")), QString("5"));
|
|
147 |
|
|
148 |
model.uninstallChange(1, 20);
|
|
149 |
QCOMPARE(model.mEntryResult->attribute(
|
|
150 |
QString("uninstall_progress")), QString("20"));
|
|
151 |
}
|
|
152 |
|
97
|
153 |
// ---------------------------------------------------------------------------
|
|
154 |
//
|
|
155 |
// ---------------------------------------------------------------------------
|
|
156 |
//
|
90
|
157 |
void MenuServiceTest::HsMenuCollectionsItemModel_construction()
|
|
158 |
{
|
|
159 |
QScopedPointer<QObject> parent(new QObject);
|
|
160 |
CaQuery query;
|
|
161 |
query.mQueryId = "__HsMenuCollectionItemModel_construction_CaQuery";
|
|
162 |
HsMenuCollectionsItemModel model(query, parent.data());
|
|
163 |
QCOMPARE(model.mCaItemModelQuery.mQueryId, query.mQueryId);
|
|
164 |
QCOMPARE(model.QObject::parent(), parent.data());
|
|
165 |
QVERIFY(model.getIconSize().isValid());
|
|
166 |
}
|
|
167 |
|
97
|
168 |
// ---------------------------------------------------------------------------
|
|
169 |
//
|
|
170 |
// ---------------------------------------------------------------------------
|
|
171 |
//
|
90
|
172 |
void MenuServiceTest::HsMenuCollectionsItemModel_getData()
|
|
173 |
{
|
|
174 |
HsMenuCollectionsItemModel model(CaQuery(), this);
|
|
175 |
|
|
176 |
const QModelIndex index = model.index(0, 0);
|
|
177 |
const QString expectedText("entryText");
|
|
178 |
const QString expectedSecondLine(hbTrId("txt_applib_dblist_downloaded_val_empty"));
|
|
179 |
|
|
180 |
model.mRootResult = index;
|
|
181 |
model.mEntryResult->mFlagsResult = 0;
|
|
182 |
model.mEntryResult->mTextResult = expectedText;
|
|
183 |
model.setSecondLineVisibility(true);
|
|
184 |
|
|
185 |
QList<QVariant> actualResult = model.data(index).toList();
|
|
186 |
|
|
187 |
QCOMPARE(actualResult.at(0).toString(),
|
|
188 |
expectedText);
|
|
189 |
QCOMPARE(actualResult.at(1).toString(),
|
|
190 |
expectedSecondLine);
|
|
191 |
|
|
192 |
|
|
193 |
Qt::ItemDataRole role = Qt::DecorationRole;
|
|
194 |
const QVariant expectedData;
|
|
195 |
|
|
196 |
model.mDataResult = expectedData;
|
|
197 |
QCOMPARE(model.data(index, role), expectedData);
|
|
198 |
|
|
199 |
model.setSecondLineVisibility(false);
|
|
200 |
QCOMPARE(model.data(index), expectedData);
|
|
201 |
}
|
97
|
202 |
|
90
|
203 |
// ---------------------------------------------------------------------------
|
97
|
204 |
//
|
90
|
205 |
// ---------------------------------------------------------------------------
|
97
|
206 |
//
|
90
|
207 |
void MenuServiceTest::HsMenuCollectionsItemModel_getSecondLine()
|
|
208 |
{
|
|
209 |
HsMenuCollectionsItemModel model(CaQuery(), this);
|
|
210 |
Qt::ItemDataRole role = Qt::DisplayRole;
|
|
211 |
model.setSecondLineVisibility(true);
|
|
212 |
const QModelIndex index = model.index(0, 0);
|
|
213 |
|
|
214 |
// set up mock data
|
|
215 |
|
|
216 |
// make up 2 items to be stored in a collection
|
|
217 |
QSharedPointer<CaEntry> collectionItemA(new CaEntry);
|
|
218 |
QString collectionItemAName("A");
|
|
219 |
collectionItemA->mTextResult = collectionItemAName;
|
|
220 |
QSharedPointer<CaEntry> collectionItemB(new CaEntry);
|
|
221 |
QString collectionItemBName("B");
|
|
222 |
collectionItemB->mTextResult = collectionItemBName;
|
|
223 |
|
|
224 |
// make sure CaService will return the 2 entries on getEntries call
|
|
225 |
CaService::instance()->mGetEntriesResult.append(collectionItemA);
|
|
226 |
CaService::instance()->mGetEntriesResult.append(collectionItemB);
|
|
227 |
|
|
228 |
QString expectedSecondLine(hbTrId("txt_applib_dblist_val_ln_new_applications",
|
|
229 |
CaService::instance()->mGetEntriesResult.count()));
|
|
230 |
|
|
231 |
// make data() call getSecondLine for 'downloaded' collection
|
|
232 |
model.mEntryResult->setEntryTypeName(Hs::collectionDownloadedTypeName);
|
|
233 |
model.mEntryResult->mIdResult = 5; // just to have any id
|
|
234 |
|
|
235 |
QString actualSecondLine = model.data(index, role).toList().at(1).toString();
|
|
236 |
|
|
237 |
QCOMPARE(actualSecondLine, expectedSecondLine);
|
|
238 |
|
|
239 |
// check what CaQuery was prepared by getSecondLine()
|
|
240 |
CaQuery resultQuery = CaService::instance()->mGetEntriesQuery;
|
|
241 |
QCOMPARE(resultQuery.mSetParentId, model.mEntryResult->mIdResult);
|
|
242 |
QCOMPARE(resultQuery.mSetEntryRoles, ItemEntryRole);
|
|
243 |
const EntryFlags expectedCollectionDownloadedFlags =
|
|
244 |
RemovableEntryFlag | VisibleEntryFlag;
|
|
245 |
QCOMPARE(resultQuery.mSetFlagsOn, expectedCollectionDownloadedFlags);
|
|
246 |
|
|
247 |
|
|
248 |
// case for static collection
|
|
249 |
const EntryFlags expectedCollectionFlag = VisibleEntryFlag;
|
|
250 |
expectedSecondLine = collectionItemAName + "," + collectionItemBName;
|
|
251 |
|
|
252 |
model.mEntryResult->setEntryTypeName(Hs::collectionTypeName);
|
|
253 |
|
|
254 |
actualSecondLine = model.data(index, role).toList().at(1).toString();
|
|
255 |
|
|
256 |
QCOMPARE(actualSecondLine, expectedSecondLine);
|
|
257 |
|
|
258 |
resultQuery = CaService::instance()->mGetEntriesQuery;
|
|
259 |
QCOMPARE(resultQuery.mSetFlagsOn, expectedCollectionFlag);
|
|
260 |
}
|
|
261 |
|
|
262 |
// ---------------------------------------------------------------------------
|
|
263 |
//
|
|
264 |
// ---------------------------------------------------------------------------
|
|
265 |
//
|
|
266 |
void MenuServiceTest::HsMenuItemModel_preloadIcons()
|
|
267 |
{
|
|
268 |
HsMenuItemModel model(CaQuery(), this);
|
|
269 |
|
|
270 |
// set up mock data
|
|
271 |
Qt::ItemDataRole role = Qt::DecorationRole;
|
|
272 |
const QModelIndex index = model.index(0, 0);
|
97
|
273 |
const QVariant expectedDecoration = QVariant(HbIcon(Hs::newIconId));
|
90
|
274 |
model.mRootResult = index;
|
|
275 |
model.mEntryResult->mFlagsResult = 0;
|
|
276 |
model.mEntryResult->mEntryTypeNameResult = Hs::collectionDownloadedTypeName;
|
|
277 |
model.setSecondLineVisibility(true);
|
|
278 |
model.mDataResult = QVariant(expectedDecoration);
|
|
279 |
model.mRowCountResult = 1; // i.e. how many rows the mock model pretends to have
|
|
280 |
QList<QVariant> actualResult = model.data(index, role).toList();
|
|
281 |
model.mEntryResult->mMakeIconResult = HbIcon(Hs::newIconId);
|
|
282 |
|
|
283 |
// verify mock setup
|
97
|
284 |
QCOMPARE(model.mDataIndex,index);
|
|
285 |
QCOMPARE(model.mDataRole,(int)role);
|
|
286 |
QCOMPARE(actualResult.empty(),false);
|
|
287 |
QCOMPARE(actualResult.at(0).value<HbIcon>().iconName(),
|
90
|
288 |
QString(Hs::newIconId));
|
|
289 |
QCOMPARE(model.data(index), model.mDataResult);
|
|
290 |
|
|
291 |
// invoke icon preloader construction
|
|
292 |
model.preloadIcons();
|
|
293 |
QVERIFY(model.mIconsIdleLoader);
|
|
294 |
|
|
295 |
// invoke icon preloading
|
|
296 |
|
|
297 |
model.mIconsIdleLoader->processWhenIdle();
|
|
298 |
|
|
299 |
// compare what has been logged in mock object with referece data
|
|
300 |
QCOMPARE(model.mEntryResult->mMakeIconSize, model.getIconSize());
|
|
301 |
QCOMPARE(model.mEntryResult->mMakeIconResult.iconName(),
|
|
302 |
QString(Hs::newIconId));
|
|
303 |
}
|
|
304 |
|
|
305 |
// ---------------------------------------------------------------------------
|
|
306 |
//
|
|
307 |
// ---------------------------------------------------------------------------
|
|
308 |
//
|
|
309 |
void MenuServiceTest::HsIconsIdleLoader_construction()
|
|
310 |
{
|
|
311 |
// precondtitons - prepare model
|
|
312 |
HsMenuItemModel model(CaQuery(), this);
|
|
313 |
|
|
314 |
// set up mock data
|
|
315 |
Qt::ItemDataRole role = Qt::DecorationRole;
|
|
316 |
const QModelIndex index = model.index(0, 0);
|
97
|
317 |
const QVariant expectedDecoration = QVariant(HbIcon(Hs::newIconId));
|
90
|
318 |
model.mRootResult = index;
|
|
319 |
model.mEntryResult->mFlagsResult = 0;
|
|
320 |
model.mEntryResult->mEntryTypeNameResult = Hs::collectionDownloadedTypeName;
|
|
321 |
model.setSecondLineVisibility(true);
|
|
322 |
model.mDataResult = QVariant(expectedDecoration);
|
|
323 |
model.mRowCountResult = 1; // i.e. how many rows the mock model pretends to have
|
|
324 |
QList<QVariant> actualResult = model.data(index, role).toList();
|
|
325 |
model.mEntryResult->mMakeIconResult = HbIcon(Hs::newIconId);
|
97
|
326 |
|
|
327 |
QCOMPARE(model.mDataIndex,index);
|
|
328 |
QCOMPARE(model.mDataRole,(int)role);
|
|
329 |
QCOMPARE(actualResult.empty(),false);
|
|
330 |
QCOMPARE(actualResult.at(0).value<HbIcon>().iconName(),
|
90
|
331 |
QString(Hs::newIconId));
|
|
332 |
|
|
333 |
QCOMPARE(model.data(index), model.mDataResult);
|
|
334 |
|
|
335 |
// test
|
|
336 |
HsIconsIdleLoader *iconsIdleLoader = new HsIconsIdleLoader(&model);
|
|
337 |
|
|
338 |
QVERIFY(iconsIdleLoader->mModel);
|
|
339 |
QVERIFY(iconsIdleLoader->mTimer);
|
|
340 |
QVERIFY(iconsIdleLoader->mTimer->isActive());
|
|
341 |
QTest::qWait(10000);
|
|
342 |
QVERIFY(!iconsIdleLoader->mTimer->isActive());
|
|
343 |
|
|
344 |
delete iconsIdleLoader;
|
|
345 |
}
|
|
346 |
|
|
347 |
// ---------------------------------------------------------------------------
|
97
|
348 |
//
|
90
|
349 |
// ---------------------------------------------------------------------------
|
97
|
350 |
//
|
90
|
351 |
int MenuServiceTest::getId(HsMenuItemModel *model , int idx)
|
|
352 |
{
|
|
353 |
return model->data(model->index(idx), CaItemModel::IdRole).toInt();
|
|
354 |
}
|
|
355 |
|