|
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 */ |
|
17 /* |
|
18 * castoragetestgetentries.cpp |
|
19 * |
|
20 * Created on: 2009-08-05 |
|
21 * Author: michal.czerwiec |
|
22 */ |
|
23 |
|
24 #include <e32cmn.h> |
|
25 #include <mmf/common/mmfcontrollerpluginresolver.h> |
|
26 #include <badesca.h> |
|
27 #include <e32math.h> |
|
28 #include <qglobal.h> |
|
29 |
|
30 #include "castoragetest.h" |
|
31 #include "cainnerquery.h" |
|
32 #include "castoragefactory.h" |
|
33 #include "castorage.h" |
|
34 #include "cainnerentry.h" |
|
35 #include "castoragetestsqlcommands.h" |
|
36 #include "casqlcommands.h" |
|
37 #include "casqlquery.h" |
|
38 #include "casqlitestorage.h" |
|
39 #include "cadef.h" |
|
40 |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // Test that two data arrays have opposite order. |
|
44 // |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 TInt CCAStorageTest::verifyOppositeOrder(RPointerArray<CCaInnerEntry>& aArray1, |
|
48 RPointerArray<CCaInnerEntry>& aArray2) |
|
49 { |
|
50 TInt err; |
|
51 |
|
52 __UHEAP_MARK; |
|
53 |
|
54 err = (aArray1.Count() == aArray2.Count())? KErrNone : KErrWrongData; |
|
55 if (!err) { |
|
56 TInt count(aArray1.Count()); |
|
57 for (TInt i = 0; i < aArray1.Count(); i++) { |
|
58 if (aArray1[i]->GetId() != aArray2[count-1-i]->GetId()) { |
|
59 err = KErrWrongData; |
|
60 break; |
|
61 } |
|
62 } |
|
63 } |
|
64 |
|
65 __UHEAP_MARKEND; |
|
66 |
|
67 return err; |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // Test Sorting Order giving different attributes. |
|
72 // |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 TInt CCAStorageTest::testSortingBySortOrder(CCaInnerQuery::TSortAttribute sortAttr1, |
|
76 CCaInnerQuery::TSortAttribute sortAttr2) |
|
77 { |
|
78 |
|
79 __UHEAP_MARK; |
|
80 |
|
81 TRAPD(err, |
|
82 CCaInnerQuery *innerQuery1 = CCaInnerQuery::NewLC(); |
|
83 innerQuery1->SetSort(sortAttr1); |
|
84 |
|
85 CCaInnerQuery *innerQuery2 = CCaInnerQuery::NewLC(); |
|
86 innerQuery2->SetSort(sortAttr2); |
|
87 |
|
88 err = testSortingBySortOrder(innerQuery1, innerQuery2); |
|
89 |
|
90 CleanupStack::PopAndDestroy(innerQuery2); |
|
91 CleanupStack::PopAndDestroy(innerQuery1); |
|
92 ); |
|
93 __UHEAP_MARKEND; |
|
94 |
|
95 return err; |
|
96 } |
|
97 |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // Test Sorting Order giving different attributes. |
|
101 // |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 TInt CCAStorageTest::testSortingBySortOrder(CCaInnerQuery *aInnerQuery1, |
|
105 CCaInnerQuery *aInnerQuery2) |
|
106 { |
|
107 __UHEAP_MARK; |
|
108 TInt err(KErrNone); |
|
109 RPointerArray<CCaInnerEntry> resultArray; |
|
110 TRAP(err, |
|
111 CleanupResetAndDestroyPushL(resultArray); |
|
112 mStorage->GetEntriesL(aInnerQuery1,resultArray); |
|
113 |
|
114 RPointerArray<CCaInnerEntry> resultArrayDesc; |
|
115 CleanupResetAndDestroyPushL(resultArrayDesc); |
|
116 mStorage->GetEntriesL(aInnerQuery2,resultArrayDesc); |
|
117 |
|
118 err = (resultArray.Count() > 0)? KErrNone : KErrWrongData; |
|
119 |
|
120 if (err == KErrNone) { |
|
121 err = (resultArrayDesc.Count() > 0)? KErrNone : KErrWrongData; |
|
122 } |
|
123 |
|
124 if (err == KErrNone) { |
|
125 err = verifyOppositeOrder(resultArray, resultArrayDesc); |
|
126 } |
|
127 CleanupStack::PopAndDestroy(&resultArrayDesc); |
|
128 CleanupStack::PopAndDestroy(&resultArray); |
|
129 ); |
|
130 |
|
131 |
|
132 __UHEAP_MARKEND; |
|
133 |
|
134 return err; |
|
135 } |
|
136 // --------------------------------------------------------------------------- |
|
137 // Test Select several entries by id. |
|
138 // |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 void CCAStorageTest::testGetEntriesById() |
|
142 { |
|
143 __UHEAP_MARK; |
|
144 { |
|
145 QList<TInt> expectedIdList; |
|
146 expectedIdList << 1 << 2 << 3 << 4 << 5 << 6; |
|
147 QList<TInt> actualIdList; |
|
148 |
|
149 |
|
150 TRAPD(err, |
|
151 CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC(); |
|
152 RArray<TInt> idArray; |
|
153 CleanupClosePushL(idArray); |
|
154 idArray.AppendL(expectedIdList[0]); |
|
155 idArray.AppendL(expectedIdList[1]); |
|
156 idArray.AppendL(expectedIdList[2]); |
|
157 idArray.AppendL(expectedIdList[3]); |
|
158 idArray.AppendL(expectedIdList[4]); |
|
159 idArray.AppendL(expectedIdList[5]); |
|
160 |
|
161 innerQuery->SetIdsL(idArray); |
|
162 |
|
163 RPointerArray<CCaInnerEntry> resultArray; |
|
164 CleanupResetAndDestroyPushL(resultArray); |
|
165 |
|
166 mStorage->GetEntriesL(innerQuery,resultArray); |
|
167 |
|
168 // check if the actual items were returned |
|
169 for (TInt i = 0; i < resultArray.Count(); i++) { |
|
170 actualIdList << resultArray[i]->GetId(); |
|
171 } |
|
172 |
|
173 CleanupStack::PopAndDestroy(&resultArray); |
|
174 CleanupStack::PopAndDestroy(&idArray); |
|
175 CleanupStack::PopAndDestroy(innerQuery); |
|
176 ); |
|
177 |
|
178 |
|
179 QCOMPARE(err, KErrNone); |
|
180 QCOMPARE(actualIdList, expectedIdList); |
|
181 } |
|
182 |
|
183 __UHEAP_MARKEND; |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 // Test Select entries by group id. |
|
188 // |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 void CCAStorageTest::testGetEntriesByGroupId() |
|
192 { |
|
193 TInt expectedGroupEntryCount(0); |
|
194 TInt actualGroupEntryCount(0); |
|
195 |
|
196 __UHEAP_MARK; |
|
197 |
|
198 TRAPD(err, |
|
199 CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC(); |
|
200 |
|
201 // check before test entries count in sfecific group |
|
202 CCaSqlQuery *query = CCaSqlQuery::NewLC(((CCaSqLiteStorage *)mStorage)->iSqlDb); |
|
203 query->SetQueryL(KSQLGetEntriesCountFromSpecificGroup); |
|
204 query->PrepareL(); |
|
205 query->BindIntL(query->iStatement.ParameterIndex(KSQLGEIdGroup), KAllCollectionsGroupId); |
|
206 |
|
207 query->ExecuteL(expectedGroupEntryCount); |
|
208 |
|
209 CleanupStack::PopAndDestroy(query); |
|
210 |
|
211 innerQuery->SetParentId(KAllCollectionsGroupId); |
|
212 |
|
213 // get entries from specific group |
|
214 RPointerArray<CCaInnerEntry> resultArray; |
|
215 CleanupResetAndDestroyPushL(resultArray); |
|
216 |
|
217 mStorage->GetEntriesL(innerQuery, resultArray); |
|
218 |
|
219 actualGroupEntryCount = resultArray.Count(); |
|
220 |
|
221 CleanupStack::PopAndDestroy(&resultArray); |
|
222 CleanupStack::PopAndDestroy(innerQuery); |
|
223 ); |
|
224 |
|
225 __UHEAP_MARKEND; |
|
226 |
|
227 QCOMPARE(err, KErrNone); |
|
228 QCOMPARE(actualGroupEntryCount, expectedGroupEntryCount); |
|
229 } |
|
230 |
|
231 // --------------------------------------------------------------------------- |
|
232 // Test Select entries by group id. |
|
233 // |
|
234 // --------------------------------------------------------------------------- |
|
235 // |
|
236 void CCAStorageTest::testGetEntriesByTypeName() |
|
237 { |
|
238 bool nonWidgetEntryFound(false); |
|
239 const int expectedNumberOfWidgets(2); |
|
240 int numberOfWidgetsFound(0); |
|
241 |
|
242 __UHEAP_MARK; |
|
243 |
|
244 _LIT(KTypeNameWidget, "Widget"); |
|
245 |
|
246 TRAPD(err, |
|
247 // add 2 new entries - typename widget |
|
248 CCaInnerEntry *innerEntry = CCaInnerEntry::NewLC(); |
|
249 innerEntry->SetTextL(KTestName1); |
|
250 innerEntry->SetEntryTypeNameL(KTypeNameWidget); |
|
251 innerEntry->SetFlags(flag); |
|
252 innerEntry->SetRole(CCaInnerQuery::Item); |
|
253 mStorage->AddL(innerEntry); |
|
254 CleanupStack::PopAndDestroy(innerEntry); |
|
255 |
|
256 innerEntry = CCaInnerEntry::NewLC(); |
|
257 innerEntry->SetTextL(KTestName2); |
|
258 innerEntry->SetEntryTypeNameL(KTypeNameWidget); |
|
259 innerEntry->SetFlags(flag); |
|
260 innerEntry->SetRole(CCaInnerQuery::Item); |
|
261 mStorage->AddL(innerEntry); |
|
262 CleanupStack::PopAndDestroy(innerEntry); |
|
263 |
|
264 |
|
265 CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC(); |
|
266 CDesC16ArrayFlat *typenameArray = new(ELeave) CDesC16ArrayFlat(KDefaultGranularity); |
|
267 CleanupStack::PushL(typenameArray); |
|
268 |
|
269 TBufC<20> typeName(KTypeNameWidget); |
|
270 typenameArray->AppendL(typeName); |
|
271 |
|
272 innerQuery->SetEntryTypeNames(typenameArray); |
|
273 CleanupStack::Pop(typenameArray); |
|
274 |
|
275 // get entries from specific group |
|
276 RPointerArray<CCaInnerEntry> resultArray; |
|
277 CleanupResetAndDestroyPushL(resultArray); |
|
278 |
|
279 |
|
280 // get entries - widgets |
|
281 mStorage->GetEntriesL(innerQuery,resultArray); |
|
282 |
|
283 numberOfWidgetsFound = resultArray.Count(); |
|
284 // check results |
|
285 for (TInt i = 0; i < numberOfWidgetsFound; ++i) { |
|
286 if ((resultArray[i]->GetEntryTypeName()).Compare( |
|
287 KTypeNameWidget) != 0) { |
|
288 nonWidgetEntryFound = true; |
|
289 } |
|
290 } |
|
291 |
|
292 CleanupStack::PopAndDestroy(&resultArray); |
|
293 CleanupStack::PopAndDestroy(innerQuery); |
|
294 ); |
|
295 __UHEAP_MARKEND; |
|
296 |
|
297 QCOMPARE(err, KErrNone); |
|
298 QCOMPARE(numberOfWidgetsFound, expectedNumberOfWidgets); |
|
299 QVERIFY(!nonWidgetEntryFound); |
|
300 } |
|
301 |
|
302 // --------------------------------------------------------------------------- |
|
303 // Test Select entries sorted by name alphabetically. |
|
304 // |
|
305 // --------------------------------------------------------------------------- |
|
306 // |
|
307 void CCAStorageTest::testGetEntriesSortByName() |
|
308 { |
|
309 __UHEAP_MARK; |
|
310 { |
|
311 TInt entriesACount(0); |
|
312 QMap<QString, bool> comparisonAResults; |
|
313 TInt entriesBCount(0); |
|
314 QMap<QString, bool> comparisonBResults; |
|
315 bool orderCheckPassed(false); |
|
316 |
|
317 TRAPD(err, |
|
318 // test ascending |
|
319 CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC(); |
|
320 innerQuery->SetSort(CCaInnerQuery::Name); |
|
321 RPointerArray<CCaInnerEntry> resultArray; |
|
322 CleanupResetAndDestroyPushL(resultArray); |
|
323 mStorage->GetEntriesL(innerQuery,resultArray); |
|
324 |
|
325 // change all odd entries texts to be lower case |
|
326 for (TInt i = 0; i < resultArray.Count(); ++i) { |
|
327 if (resultArray[i]->GetId() % 2 == 1) { |
|
328 RBuf tempBuf; |
|
329 tempBuf.CleanupClosePushL(); |
|
330 tempBuf.CreateL(resultArray[i]->GetText()); |
|
331 tempBuf.LowerCase(); |
|
332 resultArray[i]->SetTextL(tempBuf); |
|
333 CleanupStack::PopAndDestroy(&tempBuf); |
|
334 mStorage->AddL(resultArray[i]); |
|
335 } |
|
336 } |
|
337 // fetch the table again |
|
338 resultArray.ResetAndDestroy(); |
|
339 mStorage->GetEntriesL(innerQuery,resultArray); |
|
340 |
|
341 entriesACount = resultArray.Count(); |
|
342 |
|
343 RBuf previousText; |
|
344 previousText.CleanupClosePushL(); |
|
345 RBuf currentText; |
|
346 currentText.CleanupClosePushL(); |
|
347 if (!err) { |
|
348 for (TInt i = 0; i < resultArray.Count(); i++) { |
|
349 currentText.CreateL(resultArray[i]->GetText()); |
|
350 currentText.LowerCase(); |
|
351 |
|
352 comparisonAResults[descToQString(currentText)] = true; |
|
353 |
|
354 if (i!=0 && currentText.Compare(previousText) < 0) { |
|
355 comparisonAResults[descToQString(currentText)] = false; |
|
356 err = KErrWrongData; |
|
357 break; |
|
358 } |
|
359 currentText.Close(); |
|
360 previousText.Close(); |
|
361 previousText.CreateL(resultArray[i]->GetText()); |
|
362 previousText.LowerCase(); |
|
363 } |
|
364 } |
|
365 // test descending |
|
366 CCaInnerQuery *innerQuery2 = CCaInnerQuery::NewLC(); |
|
367 innerQuery2->SetSort(CCaInnerQuery::NameDesc); |
|
368 RPointerArray<CCaInnerEntry> resultArrayDesc; |
|
369 CleanupResetAndDestroyPushL(resultArrayDesc); |
|
370 mStorage->GetEntriesL(innerQuery2,resultArrayDesc); |
|
371 |
|
372 entriesBCount = resultArrayDesc.Count(); |
|
373 |
|
374 previousText.Close(); |
|
375 currentText.Close(); |
|
376 |
|
377 if (!err) { |
|
378 for (TInt i = 0; i < resultArrayDesc.Count(); i++) { |
|
379 currentText.CreateL(resultArrayDesc[i]->GetText()); |
|
380 currentText.LowerCase(); |
|
381 |
|
382 comparisonBResults[descToQString(currentText)] = true; |
|
383 |
|
384 if (i!=0 && resultArrayDesc[i]->GetText().Compare(previousText) > 0) { |
|
385 comparisonBResults[descToQString(currentText)] = false; |
|
386 break; |
|
387 } |
|
388 currentText.Close(); |
|
389 previousText.Close(); |
|
390 previousText.CreateL(resultArrayDesc[i]->GetText()); |
|
391 previousText.LowerCase(); |
|
392 } |
|
393 } |
|
394 |
|
395 if (!err) { |
|
396 orderCheckPassed = verifyOppositeOrder(resultArray, resultArrayDesc) == 0; |
|
397 } |
|
398 |
|
399 CleanupStack::PopAndDestroy(&resultArrayDesc); |
|
400 CleanupStack::PopAndDestroy(innerQuery2); |
|
401 CleanupStack::PopAndDestroy(¤tText); |
|
402 CleanupStack::PopAndDestroy(&previousText); |
|
403 CleanupStack::PopAndDestroy(&resultArray); |
|
404 CleanupStack::PopAndDestroy(innerQuery); |
|
405 ); |
|
406 |
|
407 QCOMPARE(err, KErrNone); |
|
408 foreach(QString str, comparisonAResults.keys()) { |
|
409 QVERIFY2(comparisonAResults[str], str.toUtf8()); |
|
410 }; |
|
411 QCOMPARE(comparisonAResults.size(), entriesACount); |
|
412 |
|
413 |
|
414 foreach(QString str, comparisonAResults.keys()) { |
|
415 QVERIFY2(comparisonBResults[str], str.toUtf8()); |
|
416 }; |
|
417 QCOMPARE(comparisonBResults.size(), entriesBCount); |
|
418 |
|
419 QVERIFY(orderCheckPassed); |
|
420 } |
|
421 __UHEAP_MARKEND; |
|
422 } |
|
423 |
|
424 // --------------------------------------------------------------------------- |
|
425 // tests getentries sorted by created timestamp ascending. |
|
426 // |
|
427 // --------------------------------------------------------------------------- |
|
428 // |
|
429 void CCAStorageTest::testGetEntriesSortByCreatedTimestamp() |
|
430 { |
|
431 |
|
432 __UHEAP_MARK; |
|
433 { |
|
434 QMap<int, bool> ascendingOrderCheckResults; |
|
435 QMap<int, bool> descendingOrderCheckResults; |
|
436 |
|
437 TRAPD(err, |
|
438 // check ascending |
|
439 RPointerArray<CCaInnerEntry> resultArray; |
|
440 CleanupResetAndDestroyPushL(resultArray); |
|
441 CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC(); |
|
442 innerQuery->SetSort(CCaInnerQuery::CreatedTimestamp); |
|
443 mStorage->GetEntriesL(innerQuery,resultArray); |
|
444 CleanupStack::PopAndDestroy(innerQuery); |
|
445 |
|
446 TInt64 previousTimestamp(0); |
|
447 for (TInt i = 0; i<resultArray.Count() ; i++) { |
|
448 innerQuery = CCaInnerQuery::NewLC(); |
|
449 RArray<TInt> ids; |
|
450 CleanupClosePushL(ids); |
|
451 const TInt id = resultArray[i]->GetId(); |
|
452 ids.AppendL(id); |
|
453 innerQuery->SetIdsL(ids); |
|
454 |
|
455 TInt64 timestamp(0); |
|
456 CCaSqlQuery *query = CCaSqlQuery::NewLC(STATIC_CAST(CCaSqLiteStorage *,mStorage)->iSqlDb); |
|
457 query->SetQueryL(KSQLGetEntryTimestamp); |
|
458 query->PrepareL(); |
|
459 query->BindIdsL(ids, KSQLEntryId); |
|
460 query->ExecuteL(timestamp); |
|
461 |
|
462 if (i != 0 && timestamp < previousTimestamp) { |
|
463 ascendingOrderCheckResults[id] = false; |
|
464 break; |
|
465 } |
|
466 previousTimestamp = timestamp; |
|
467 CleanupStack::PopAndDestroy(query); |
|
468 CleanupStack::PopAndDestroy(&ids); |
|
469 CleanupStack::PopAndDestroy(innerQuery); |
|
470 } |
|
471 |
|
472 CleanupStack::PopAndDestroy(&resultArray); |
|
473 |
|
474 // check descending |
|
475 CleanupResetAndDestroyPushL(resultArray); |
|
476 innerQuery = CCaInnerQuery::NewLC(); |
|
477 innerQuery->SetSort(CCaInnerQuery::CreatedTimestampDesc); |
|
478 mStorage->GetEntriesL(innerQuery,resultArray); |
|
479 CleanupStack::PopAndDestroy(innerQuery); |
|
480 |
|
481 previousTimestamp = 0; |
|
482 for (TInt i = 0; i<resultArray.Count() ; i++) { |
|
483 innerQuery = CCaInnerQuery::NewLC(); |
|
484 RArray<TInt> ids; |
|
485 CleanupClosePushL(ids); |
|
486 ids.AppendL(resultArray[i]->GetId()); |
|
487 const TInt id = ids[0]; |
|
488 innerQuery->SetIdsL(ids); |
|
489 |
|
490 TInt64 timestamp(0); |
|
491 CCaSqlQuery *query = CCaSqlQuery::NewLC(STATIC_CAST(CCaSqLiteStorage *,mStorage)->iSqlDb); |
|
492 query->SetQueryL(KSQLGetEntryTimestamp); |
|
493 query->PrepareL(); |
|
494 query->BindIdsL(ids, KSQLEntryId); |
|
495 query->ExecuteL(timestamp); |
|
496 if (i != 0 && timestamp > previousTimestamp) { |
|
497 descendingOrderCheckResults[id] = false; |
|
498 break; |
|
499 } |
|
500 previousTimestamp = timestamp; |
|
501 CleanupStack::PopAndDestroy(query); |
|
502 CleanupStack::PopAndDestroy(&ids); |
|
503 CleanupStack::PopAndDestroy(innerQuery); |
|
504 } |
|
505 |
|
506 CleanupStack::PopAndDestroy(&resultArray); |
|
507 ); |
|
508 |
|
509 |
|
510 QCOMPARE(err, KErrNone); |
|
511 QCOMPARE(ascendingOrderCheckResults.size(), 0); |
|
512 QCOMPARE(descendingOrderCheckResults.size(), 0); |
|
513 } |
|
514 __UHEAP_MARKEND; |
|
515 } |
|
516 |
|
517 // --------------------------------------------------------------------------- |
|
518 // tests getentries sorted by used timestamp. |
|
519 // |
|
520 // --------------------------------------------------------------------------- |
|
521 // |
|
522 void CCAStorageTest::testGetEntriesSortByMostUsedTimestamp() |
|
523 { |
|
524 __UHEAP_MARK; |
|
525 |
|
526 const TInt mostUsedIds[3] = {14, 9, 2}; |
|
527 |
|
528 const TInt mostUsedIdsSize = sizeof(mostUsedIds) / sizeof(TInt); |
|
529 |
|
530 TInt err(KErrNone); |
|
531 |
|
532 TRAP(err, |
|
533 |
|
534 for (TInt i = 0; i < mostUsedIdsSize; ++i) { |
|
535 for (TInt j = mostUsedIdsSize - i; j >= 0; --j) { |
|
536 mStorage->TouchL(mostUsedIds[i], ETrue); |
|
537 } |
|
538 } |
|
539 |
|
540 CCaInnerQuery *innerQuery1 = CCaInnerQuery::NewLC(); |
|
541 innerQuery1->SetSort(CCaInnerQuery::MostUsedDesc); |
|
542 RPointerArray<CCaInnerEntry> resultArray; |
|
543 CleanupResetAndDestroyPushL(resultArray); |
|
544 |
|
545 |
|
546 // get entries - most used desscending |
|
547 mStorage->GetEntriesL(innerQuery1, resultArray); |
|
548 |
|
549 if (resultArray.Count() < mostUsedIdsSize) { |
|
550 err = KErrNotFound; |
|
551 } else { |
|
552 for (TInt i = 0; i < mostUsedIdsSize; ++i) { |
|
553 if (resultArray[i]->GetId() != mostUsedIds[i]) { |
|
554 err = KErrGeneral; |
|
555 break; |
|
556 } |
|
557 } |
|
558 } |
|
559 |
|
560 CleanupStack::PopAndDestroy(&resultArray); |
|
561 CleanupStack::PopAndDestroy(innerQuery1); |
|
562 ); |
|
563 |
|
564 QCOMPARE(err, KErrNone); |
|
565 |
|
566 |
|
567 TRAP(err, |
|
568 CCaInnerQuery *innerQuery1 = CCaInnerQuery::NewLC(); |
|
569 innerQuery1->SetSort(CCaInnerQuery::MostUsed); |
|
570 RPointerArray<CCaInnerEntry> resultArray; |
|
571 CleanupResetAndDestroyPushL(resultArray); |
|
572 |
|
573 |
|
574 // get entries - most used desscending |
|
575 mStorage->GetEntriesL(innerQuery1, resultArray); |
|
576 |
|
577 const TInt resultCount = resultArray.Count(); |
|
578 |
|
579 if (resultCount < mostUsedIdsSize) { |
|
580 err = KErrNotFound; |
|
581 } else { |
|
582 for (TInt i = 0; i < mostUsedIdsSize; ++i) { |
|
583 if (resultArray[resultCount - i - 1]->GetId() != mostUsedIds[i]) { |
|
584 err = KErrGeneral; |
|
585 break; |
|
586 } |
|
587 } |
|
588 } |
|
589 CleanupStack::PopAndDestroy(&resultArray); |
|
590 CleanupStack::PopAndDestroy(innerQuery1); |
|
591 ); |
|
592 __UHEAP_MARKEND; |
|
593 |
|
594 |
|
595 } |
|
596 |
|
597 |
|
598 // --------------------------------------------------------------------------- |
|
599 // tests getentries sorted by used timestamp ascending. |
|
600 // |
|
601 // --------------------------------------------------------------------------- |
|
602 // |
|
603 void CCAStorageTest::testGetEntriesSortByLastUsedTimestamp() |
|
604 { |
|
605 __UHEAP_MARK; |
|
606 |
|
607 const TInt lastUsedIds[3] = {14, 9, 2}; |
|
608 |
|
609 const TInt lastUsedIdsSize = sizeof(lastUsedIds) / sizeof(TInt); |
|
610 |
|
611 TInt err(KErrNone); |
|
612 |
|
613 TRAP(err, |
|
614 |
|
615 for (TInt i = lastUsedIdsSize - 1; i >= 0 ; --i) { |
|
616 mStorage->TouchL(lastUsedIds[i], EFalse); |
|
617 } |
|
618 |
|
619 CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC(); |
|
620 innerQuery->SetSort(CCaInnerQuery::LastUsedDesc); |
|
621 RPointerArray<CCaInnerEntry> resultArray; |
|
622 CleanupResetAndDestroyPushL(resultArray); |
|
623 |
|
624 |
|
625 // get entries - last used descending |
|
626 mStorage->GetEntriesL(innerQuery, resultArray); |
|
627 |
|
628 |
|
629 if (resultArray.Count() < lastUsedIdsSize) { |
|
630 err = KErrNotFound; |
|
631 } else { |
|
632 for (TInt i = 0; i < lastUsedIdsSize; ++i) { |
|
633 if (resultArray[i]->GetId() != lastUsedIds[i]) { |
|
634 err = KErrGeneral; |
|
635 break; |
|
636 } |
|
637 } |
|
638 } |
|
639 |
|
640 CleanupStack::PopAndDestroy(&resultArray); |
|
641 CleanupStack::PopAndDestroy(innerQuery); |
|
642 ); |
|
643 |
|
644 |
|
645 QCOMPARE(err, KErrNone); |
|
646 |
|
647 TRAP(err, |
|
648 CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC(); |
|
649 innerQuery->SetSort(CCaInnerQuery::LastUsed); |
|
650 RPointerArray<CCaInnerEntry> resultArray; |
|
651 CleanupResetAndDestroyPushL(resultArray); |
|
652 |
|
653 |
|
654 // get entries - last used descending |
|
655 mStorage->GetEntriesL(innerQuery, resultArray); |
|
656 |
|
657 const TInt resultCount = resultArray.Count(); |
|
658 |
|
659 if (resultCount < lastUsedIdsSize) { |
|
660 err = KErrNotFound; |
|
661 } else { |
|
662 for (TInt i = 0; i < lastUsedIdsSize; ++i) { |
|
663 if (resultArray[resultCount - 1 - i]->GetId() != |
|
664 lastUsedIds[i]) { |
|
665 err = KErrGeneral; |
|
666 break; |
|
667 } |
|
668 } |
|
669 } |
|
670 |
|
671 |
|
672 CleanupStack::PopAndDestroy(&resultArray); |
|
673 CleanupStack::PopAndDestroy(innerQuery); |
|
674 ); |
|
675 |
|
676 __UHEAP_MARKEND; |
|
677 } |
|
678 |
|
679 // --------------------------------------------------------------------------- |
|
680 // tests getentries sorted by default ascending. |
|
681 // |
|
682 // --------------------------------------------------------------------------- |
|
683 // |
|
684 void CCAStorageTest::testGetEntriesSortByDefault() |
|
685 { |
|
686 |
|
687 __UHEAP_MARK; |
|
688 |
|
689 TRAPD(err, |
|
690 |
|
691 CCaSqlQuery *query = CCaSqlQuery::NewLC(((CCaSqLiteStorage *)mStorage)->iSqlDb); |
|
692 query->SetQueryL(KSQLGetIdEntryFromSpecificGroup); |
|
693 query->PrepareL(); |
|
694 query->BindIntL(query->iStatement.ParameterIndex(KSQLGEIdGroup), KAllCollectionsGroupId); |
|
695 RArray<TInt> resultHelpArray; |
|
696 CleanupClosePushL(resultHelpArray); |
|
697 query->ExecuteL(resultHelpArray, CCaSqlQuery::EEntryTable); |
|
698 query->CloseStatement(); |
|
699 |
|
700 CCaInnerQuery *innerQuery1 = CCaInnerQuery::NewLC(); |
|
701 innerQuery1->SetSort(CCaInnerQuery::Default); |
|
702 innerQuery1->SetParentId(KAllCollectionsGroupId); |
|
703 |
|
704 CCaInnerQuery *innerQuery2 = CCaInnerQuery::NewLC(); |
|
705 innerQuery2->SetSort(CCaInnerQuery::DefaultDesc); |
|
706 innerQuery2->SetParentId(KAllCollectionsGroupId); |
|
707 |
|
708 RPointerArray<CCaInnerEntry> resultArray; |
|
709 CleanupResetAndDestroyPushL(resultArray); |
|
710 |
|
711 // get entries - bu default from group |
|
712 mStorage->GetEntriesL(innerQuery1, resultArray); |
|
713 |
|
714 // check results - compare Entry_Id |
|
715 for (TInt i=0; i<resultArray.Count(); i++) { |
|
716 if (resultArray[i]->GetId() != resultHelpArray[i]) { |
|
717 err = KErrWrongData; |
|
718 } |
|
719 } |
|
720 |
|
721 if (!err) { |
|
722 err = testSortingBySortOrder(innerQuery1, innerQuery2); |
|
723 } |
|
724 |
|
725 // clear after test |
|
726 CleanupStack::PopAndDestroy(&resultArray); |
|
727 CleanupStack::PopAndDestroy(innerQuery2); |
|
728 CleanupStack::PopAndDestroy(innerQuery1); |
|
729 CleanupStack::PopAndDestroy(&resultHelpArray); |
|
730 CleanupStack::PopAndDestroy(query); |
|
731 ); |
|
732 |
|
733 __UHEAP_MARKEND; |
|
734 |
|
735 QCOMPARE(err, KErrNone); |
|
736 } |
|
737 |
|
738 |
|
739 // --------------------------------------------------------------------------- |
|
740 // tests getentries sorted by used timestamp ascending. |
|
741 // |
|
742 // --------------------------------------------------------------------------- |
|
743 // |
|
744 void CCAStorageTest::testGetEntriesByFlags() |
|
745 { |
|
746 |
|
747 __UHEAP_MARK; |
|
748 |
|
749 TRAPD(err, |
|
750 |
|
751 CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC(); |
|
752 // test all flags on in KMaxFlagsMask range |
|
753 for (TUint flagsOnMask = 0; flagsOnMask <= KMaxFlagsMask; flagsOnMask++) { |
|
754 RPointerArray<CCaInnerEntry> resultArray; |
|
755 CleanupResetAndDestroyPushL(resultArray); |
|
756 innerQuery->SetFlagsOn(flagsOnMask); |
|
757 mStorage->GetEntriesL(innerQuery,resultArray); |
|
758 TInt entryCount = resultArray.Count(); |
|
759 if (entryCount > 0) { |
|
760 for (TInt j = 0; j < entryCount; j++) { |
|
761 if (resultArray[j]->GetFlags() & flagsOnMask != flagsOnMask) { |
|
762 err = KErrWrongData; |
|
763 } |
|
764 } |
|
765 } |
|
766 innerQuery->SetFlagsOn(0); |
|
767 CleanupStack::PopAndDestroy(&resultArray); |
|
768 } |
|
769 |
|
770 // test all flags off in KMaxFlagsMask range |
|
771 for (TUint flagsOffMask = 0; flagsOffMask <= KMaxFlagsMask; flagsOffMask++) { |
|
772 RPointerArray<CCaInnerEntry> resultArray; |
|
773 CleanupResetAndDestroyPushL(resultArray); |
|
774 innerQuery->SetFlagsOff(flagsOffMask); |
|
775 mStorage->GetEntriesL(innerQuery,resultArray); |
|
776 TInt entryCount = resultArray.Count(); |
|
777 if (entryCount > 0) { |
|
778 for (TInt j = 0; j < entryCount; j++) { |
|
779 if ((!resultArray[j]->GetFlags()) & flagsOffMask != flagsOffMask) { |
|
780 err = KErrWrongData; |
|
781 } |
|
782 } |
|
783 } |
|
784 innerQuery->SetFlagsOff(0); |
|
785 CleanupStack::PopAndDestroy(&resultArray); |
|
786 } |
|
787 |
|
788 // test combination of flags on flags off |
|
789 for (TUint flagsOnMask = 0; flagsOnMask <= KMaxFlagsMaskForCombinedTest; flagsOnMask++) { |
|
790 for (TUint flagsOffMask = 0; flagsOffMask |
|
791 <= KMaxFlagsMaskForCombinedTest; flagsOffMask++) { |
|
792 RPointerArray<CCaInnerEntry> resultArray; |
|
793 CleanupResetAndDestroyPushL(resultArray); |
|
794 innerQuery->SetFlagsOff(flagsOffMask); |
|
795 innerQuery->SetFlagsOn(flagsOnMask); |
|
796 mStorage->GetEntriesL(innerQuery,resultArray); |
|
797 TInt entryCount = resultArray.Count(); |
|
798 if (entryCount > 0) { |
|
799 for (TInt j = 0; j < entryCount; j++) { |
|
800 if ((!resultArray[j]->GetFlags()) & flagsOffMask != flagsOffMask |
|
801 && resultArray[j]->GetFlags() & flagsOnMask != flagsOnMask) { |
|
802 err = KErrWrongData; |
|
803 } |
|
804 } |
|
805 } |
|
806 innerQuery->SetFlagsOff(0); |
|
807 innerQuery->SetFlagsOn(0); |
|
808 CleanupStack::PopAndDestroy(&resultArray); |
|
809 } |
|
810 } |
|
811 |
|
812 CleanupStack::PopAndDestroy(innerQuery); |
|
813 ); |
|
814 |
|
815 __UHEAP_MARKEND; |
|
816 |
|
817 QCOMPARE(err, KErrNone); |
|
818 } |
|
819 |
|
820 // --------------------------------------------------------------------------- |
|
821 // tests getentries with flags which are on |
|
822 // |
|
823 // --------------------------------------------------------------------------- |
|
824 // |
|
825 void CCAStorageTest::testGetEntriesByFlagsOn() |
|
826 { |
|
827 |
|
828 __UHEAP_MARK; |
|
829 TRAPD(err, |
|
830 CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC(); |
|
831 RPointerArray<CCaInnerEntry> resultArrayTemp; |
|
832 CleanupResetAndDestroyPushL(resultArrayTemp); |
|
833 RArray<TInt> testEntries; |
|
834 CleanupClosePushL(testEntries); |
|
835 |
|
836 mStorage->GetEntriesL(innerQuery,resultArrayTemp); |
|
837 |
|
838 TInt entryCount = resultArrayTemp.Count(); |
|
839 |
|
840 // Change five random elements' flags |
|
841 err = (entryCount >= 5) ? err : KErrNoData; |
|
842 // Set all flags on to test flags on. |
|
843 for (TInt i = 0; i < entryCount; i++) { |
|
844 resultArrayTemp[i]->SetFlags(0); |
|
845 mStorage->AddL(resultArrayTemp[i]); |
|
846 } |
|
847 |
|
848 // get random entries to test on |
|
849 TInt testIdCount(0); |
|
850 while (testEntries.Count() < 5) { |
|
851 TInt randomEntryInArray = Math::Random() % entryCount; |
|
852 TBool exists(EFalse); |
|
853 for (TInt i = 0; i < testEntries.Count(); i++) { |
|
854 if (testEntries[i]== randomEntryInArray) { |
|
855 exists = ETrue; |
|
856 break; |
|
857 } |
|
858 } |
|
859 if (!exists) { |
|
860 testEntries.AppendL(randomEntryInArray); |
|
861 } |
|
862 } |
|
863 |
|
864 // test flags on with flags from KFlagsOnTable |
|
865 |
|
866 CCaInnerQuery *innerQueryFlagsOn = CCaInnerQuery::NewLC(); |
|
867 for (TInt j = 0; j < 5; j++) { |
|
868 // fill database with flag |
|
869 for (TInt i = 0; i < 5; i++) { |
|
870 TInt x = testEntries[i]; |
|
871 resultArrayTemp[x]->SetFlags(KFlagsOnTable[j]); |
|
872 mStorage->AddL(resultArrayTemp[x]); |
|
873 } |
|
874 |
|
875 // check filled database |
|
876 RPointerArray<CCaInnerEntry> resultArrayFlagsOn; |
|
877 CleanupResetAndDestroyPushL(resultArrayFlagsOn); |
|
878 innerQueryFlagsOn->SetFlagsOn(KFlagsOnTable[j]); |
|
879 mStorage->GetEntriesL(innerQueryFlagsOn,resultArrayFlagsOn); |
|
880 TInt count = resultArrayFlagsOn.Count(); |
|
881 err = (resultArrayFlagsOn.Count() >= 5) ? err : KErrWrongData; |
|
882 |
|
883 // check that the right entries were fetched |
|
884 for (TInt i = 0; i < 5; i++) { |
|
885 for (TInt j = 0; j < resultArrayFlagsOn.Count(); j++) { |
|
886 if (resultArrayFlagsOn[j]->GetId() == |
|
887 resultArrayTemp[testEntries[i]]->GetId()) { |
|
888 break; |
|
889 } else if (j == resultArrayFlagsOn.Count()-1) { |
|
890 err = KErrWrongData; |
|
891 } |
|
892 } |
|
893 } |
|
894 |
|
895 CleanupStack::PopAndDestroy(&resultArrayFlagsOn); |
|
896 } |
|
897 CleanupStack::PopAndDestroy(innerQueryFlagsOn); |
|
898 CleanupStack::PopAndDestroy(&testEntries); |
|
899 CleanupStack::PopAndDestroy(&resultArrayTemp); |
|
900 CleanupStack::PopAndDestroy(innerQuery); |
|
901 ); |
|
902 __UHEAP_MARKEND; |
|
903 |
|
904 QCOMPARE(err, KErrNone); |
|
905 } |
|
906 |
|
907 |
|
908 // --------------------------------------------------------------------------- |
|
909 // tests getentries with flags which are off |
|
910 // |
|
911 // --------------------------------------------------------------------------- |
|
912 // |
|
913 void CCAStorageTest::testGetEntriesByFlagsOff() |
|
914 { |
|
915 __UHEAP_MARK; |
|
916 TRAPD(err, |
|
917 CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC(); |
|
918 RPointerArray<CCaInnerEntry> resultArrayTemp; |
|
919 CleanupResetAndDestroyPushL(resultArrayTemp); |
|
920 RArray<TInt> testEntries; |
|
921 CleanupClosePushL(testEntries); |
|
922 |
|
923 mStorage->GetEntriesL(innerQuery,resultArrayTemp); |
|
924 |
|
925 TInt entryCount = resultArrayTemp.Count(); |
|
926 |
|
927 // Change five random elements' flags |
|
928 err = (entryCount >= 5) ? err : KErrNoData; |
|
929 // Set all flags off to test flags off assuming that there are 5 flags (63 bitwise) |
|
930 for (TInt i = 0; i < entryCount; i++) { |
|
931 resultArrayTemp[i]->SetFlags(63); |
|
932 mStorage->AddL(resultArrayTemp[i]); |
|
933 } |
|
934 |
|
935 // get random entries to test on |
|
936 TInt testIdCount(0); |
|
937 while (testEntries.Count() < 5) { |
|
938 TInt randomEntryInArray = Math::Random() % entryCount; |
|
939 TBool exists(EFalse); |
|
940 for (TInt i = 0; i < testEntries.Count(); i++) { |
|
941 if (testEntries[i]== randomEntryInArray) { |
|
942 exists = ETrue; |
|
943 break; |
|
944 } |
|
945 } |
|
946 if (!exists) { |
|
947 testEntries.AppendL(randomEntryInArray); |
|
948 } |
|
949 } |
|
950 |
|
951 // test flags on with flags from KFlagsOffTable |
|
952 |
|
953 CCaInnerQuery *innerQueryFlagsOff = CCaInnerQuery::NewLC(); |
|
954 for (TInt j = 0; j < 5; j++) { |
|
955 // fill database with flag |
|
956 for (TInt i = 0; i < 5; i++) { |
|
957 TInt x = testEntries[i]; |
|
958 resultArrayTemp[x]->SetFlags(KFlagsOffTable[j]); |
|
959 mStorage->AddL(resultArrayTemp[x]); |
|
960 } |
|
961 |
|
962 // check filled database |
|
963 RPointerArray<CCaInnerEntry> resultArrayFlagsOff; |
|
964 CleanupResetAndDestroyPushL(resultArrayFlagsOff); |
|
965 innerQueryFlagsOff->SetFlagsOff(KFlagsOffTableMasks[j]); |
|
966 mStorage->GetEntriesL(innerQueryFlagsOff,resultArrayFlagsOff); |
|
967 TInt count = resultArrayFlagsOff.Count(); |
|
968 err = (resultArrayFlagsOff.Count() >= 5) ? err : KErrWrongData; |
|
969 |
|
970 // check that the right entries were fetched |
|
971 for (TInt i = 0; i < 5; i++) { |
|
972 for (TInt j = 0; j < resultArrayFlagsOff.Count(); j++) { |
|
973 if (resultArrayFlagsOff[j]->GetId() == |
|
974 resultArrayTemp[testEntries[i]]->GetId()) { |
|
975 break; |
|
976 } else if (j == resultArrayFlagsOff.Count()-1) { |
|
977 err = KErrWrongData; |
|
978 } |
|
979 } |
|
980 } |
|
981 |
|
982 CleanupStack::PopAndDestroy(&resultArrayFlagsOff); |
|
983 } |
|
984 CleanupStack::PopAndDestroy(innerQueryFlagsOff); |
|
985 CleanupStack::PopAndDestroy(&testEntries); |
|
986 CleanupStack::PopAndDestroy(&resultArrayTemp); |
|
987 CleanupStack::PopAndDestroy(innerQuery); |
|
988 ); |
|
989 __UHEAP_MARKEND; |
|
990 QCOMPARE(err, KErrNone); |
|
991 } |
|
992 |
|
993 |
|
994 // --------------------------------------------------------------------------- |
|
995 // tests getentries by uid. |
|
996 // |
|
997 // --------------------------------------------------------------------------- |
|
998 // |
|
999 void CCAStorageTest::testGetEntriesByUid() |
|
1000 { |
|
1001 __UHEAP_MARK; |
|
1002 TRAPD(err, |
|
1003 CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC(); |
|
1004 innerQuery->SetUid(KCalendarAppUid); |
|
1005 |
|
1006 RPointerArray<CCaInnerEntry> resultArray; |
|
1007 CleanupResetAndDestroyPushL(resultArray); |
|
1008 |
|
1009 mStorage->GetEntriesL(innerQuery,resultArray); |
|
1010 |
|
1011 TInt entryCount = resultArray.Count(); |
|
1012 |
|
1013 err = (entryCount == 1 && resultArray[0]->GetUid() == KCalendarAppUid) |
|
1014 ? err : KErrWrongData; |
|
1015 |
|
1016 CleanupStack::PopAndDestroy(&resultArray); |
|
1017 CleanupStack::PopAndDestroy(innerQuery); |
|
1018 ); |
|
1019 __UHEAP_MARKEND; |
|
1020 |
|
1021 QCOMPARE(err, KErrNone); |
|
1022 } |
|
1023 |
|
1024 // --------------------------------------------------------------------------- |
|
1025 // tests getentries by uid. |
|
1026 // |
|
1027 // --------------------------------------------------------------------------- |
|
1028 // |
|
1029 void CCAStorageTest::testGetEntriesIds() |
|
1030 { |
|
1031 __UHEAP_MARK; |
|
1032 |
|
1033 TRAPD(err, |
|
1034 CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC(); |
|
1035 RArray<TInt> idArray; |
|
1036 CleanupClosePushL(idArray); |
|
1037 |
|
1038 mStorage->GetEntriesIdsL(innerQuery,idArray); |
|
1039 |
|
1040 RPointerArray<CCaInnerEntry> resultArray; |
|
1041 CleanupResetAndDestroyPushL(resultArray); |
|
1042 |
|
1043 mStorage->GetEntriesL(innerQuery,resultArray); |
|
1044 |
|
1045 err = (idArray.Count() > 0) ? err : KErrNoData; |
|
1046 if (!err) { |
|
1047 err = (idArray.Count() == resultArray.Count()) ? err : KErrWrongData; |
|
1048 } |
|
1049 |
|
1050 CleanupStack::PopAndDestroy(&resultArray); |
|
1051 CleanupStack::PopAndDestroy(&idArray); |
|
1052 CleanupStack::PopAndDestroy(innerQuery); |
|
1053 ); |
|
1054 __UHEAP_MARKEND; |
|
1055 |
|
1056 QCOMPARE(err, KErrNone); |
|
1057 } |
|
1058 |
|
1059 // --------------------------------------------------------------------------- |
|
1060 // |
|
1061 // |
|
1062 // --------------------------------------------------------------------------- |
|
1063 // |
|
1064 void CCAStorageTest::testGetNewEntryWithAttributes() |
|
1065 { |
|
1066 __UHEAP_MARK; |
|
1067 TInt err(KErrGeneral); |
|
1068 TRAP(err, |
|
1069 // Check database entries count |
|
1070 CCaSqlQuery *query = CCaSqlQuery::NewLC(((CCaSqLiteStorage *)mStorage)->iSqlDb); |
|
1071 query->SetQueryL(KSQLGetIdCountFromEntryTable); |
|
1072 query->PrepareL(); |
|
1073 TInt entriesCount(0); |
|
1074 query->ExecuteL(entriesCount); |
|
1075 CleanupStack::PopAndDestroy(query); |
|
1076 |
|
1077 |
|
1078 // add new entry with attributes |
|
1079 CCaInnerEntry *innerEntry = CCaInnerEntry::NewL(); |
|
1080 RPointerArray<CCaInnerEntry> innerEntryArray; |
|
1081 CleanupResetAndDestroyPushL(innerEntryArray); |
|
1082 innerEntryArray.AppendL(innerEntry); |
|
1083 |
|
1084 innerEntry->SetTextL(KTestName); |
|
1085 innerEntry->SetEntryTypeNameL(KTypeName); |
|
1086 innerEntry->SetFlags(flag); |
|
1087 innerEntry->SetRole(CCaInnerQuery::Item); |
|
1088 innerEntry->SetIconDataL(_L("filename"), _L("skinId"), _L("268458321")); |
|
1089 |
|
1090 innerEntry->AddAttributeL(KAttrName_1, KAttrValue_1); |
|
1091 innerEntry->AddAttributeL(KAttrName_2, KAttrValue_2); |
|
1092 innerEntry->AddAttributeL(KAttrName_3, KAttrValue_3); |
|
1093 |
|
1094 mStorage->AddL(innerEntry); |
|
1095 CleanupStack::PopAndDestroy(&innerEntryArray); |
|
1096 |
|
1097 |
|
1098 // get new entry with attributes |
|
1099 RPointerArray<CCaInnerEntry> resultArray; |
|
1100 CleanupResetAndDestroyPushL(resultArray); |
|
1101 RArray<TInt> idArray; |
|
1102 CleanupClosePushL(idArray); |
|
1103 idArray.AppendL(entriesCount + 1); // new entry |
|
1104 |
|
1105 CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC(); |
|
1106 innerQuery->SetIdsL(idArray); |
|
1107 |
|
1108 mStorage->GetEntriesL(innerQuery, resultArray); |
|
1109 |
|
1110 // check results |
|
1111 TInt attributesCount = resultArray[0]->GetAttributes().Count(); |
|
1112 |
|
1113 if (attributesCount == 3) { |
|
1114 err = KErrNone; |
|
1115 } else { |
|
1116 err = KErrGeneral; |
|
1117 } |
|
1118 |
|
1119 // clear after test |
|
1120 CleanupStack::PopAndDestroy(innerQuery); |
|
1121 CleanupStack::PopAndDestroy(&idArray); |
|
1122 CleanupStack::PopAndDestroy(&resultArray); |
|
1123 ); |
|
1124 |
|
1125 __UHEAP_MARKEND; |
|
1126 |
|
1127 QCOMPARE(err, KErrNone); |
|
1128 } |
|
1129 |
|
1130 // --------------------------------------------------------------------------- |
|
1131 // |
|
1132 // |
|
1133 // --------------------------------------------------------------------------- |
|
1134 // |
|
1135 void CCAStorageTest::testGetNewEntryWithAttributesByUid() |
|
1136 { |
|
1137 __UHEAP_MARK; |
|
1138 |
|
1139 TInt err(KErrGeneral); |
|
1140 |
|
1141 TRAP(err, |
|
1142 // add new entry with attributes |
|
1143 CCaInnerEntry *innerEntry = CCaInnerEntry::NewL(); |
|
1144 RPointerArray<CCaInnerEntry> innerEntryArray; |
|
1145 CleanupResetAndDestroyPushL(innerEntryArray); |
|
1146 innerEntryArray.AppendL(innerEntry); |
|
1147 |
|
1148 innerEntry->SetTextL(KTestName); |
|
1149 innerEntry->SetEntryTypeNameL(KTypeName2); |
|
1150 innerEntry->SetFlags(flag); |
|
1151 innerEntry->SetRole(CCaInnerQuery::Item); |
|
1152 innerEntry->SetUid(KTestAppUid); |
|
1153 innerEntry->SetIconDataL(_L("filename"), _L("skinId"), _L("268458321")); |
|
1154 |
|
1155 innerEntry->AddAttributeL(KAttrName_1, KAttrValue_1); |
|
1156 innerEntry->AddAttributeL(KAttrName_2, KAttrValue_2); |
|
1157 innerEntry->AddAttributeL(KAttrName_3, KAttrValue_3); |
|
1158 |
|
1159 mStorage->AddL(innerEntry); |
|
1160 CleanupStack::PopAndDestroy(&innerEntryArray); |
|
1161 |
|
1162 |
|
1163 // get new entry with attributes by uid |
|
1164 RPointerArray<CCaInnerEntry> resultArray; |
|
1165 CleanupResetAndDestroyPushL(resultArray); |
|
1166 CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC(); |
|
1167 innerQuery->SetUid(KTestAppUid); |
|
1168 |
|
1169 mStorage->GetEntriesL(innerQuery, resultArray); |
|
1170 |
|
1171 // check results |
|
1172 TInt attributesCount = resultArray[0]->GetAttributes().Count(); |
|
1173 |
|
1174 if (attributesCount == 3) { |
|
1175 err = KErrNone; |
|
1176 } else { |
|
1177 err = KErrGeneral; |
|
1178 } |
|
1179 |
|
1180 // clear after test |
|
1181 CleanupStack::PopAndDestroy(innerQuery); |
|
1182 CleanupStack::PopAndDestroy(&resultArray); |
|
1183 ); |
|
1184 __UHEAP_MARKEND; |
|
1185 |
|
1186 QCOMPARE(err, KErrNone); |
|
1187 } |
|
1188 |
|
1189 // --------------------------------------------------------------------------- |
|
1190 // Test Select entries with limit. |
|
1191 // |
|
1192 // --------------------------------------------------------------------------- |
|
1193 // |
|
1194 void CCAStorageTest::testGetEntriesWhenLimitSetTo() |
|
1195 { |
|
1196 |
|
1197 |
|
1198 QList<int> entryCountList; |
|
1199 entryCountList << 5 << -15 << 0 << 50; |
|
1200 __UHEAP_MARK; |
|
1201 |
|
1202 int limit(0); |
|
1203 foreach(limit, entryCountList) { |
|
1204 // Check database entries count |
|
1205 TRAPD(err, |
|
1206 CCaSqlQuery *query = CCaSqlQuery::NewLC(((CCaSqLiteStorage *)mStorage)->iSqlDb); |
|
1207 query->SetQueryL(KSQLGetIdCountFromEntryTable); |
|
1208 query->PrepareL(); |
|
1209 TInt entriesCount(0); |
|
1210 query->ExecuteL(entriesCount); |
|
1211 CleanupStack::PopAndDestroy(query); |
|
1212 |
|
1213 RPointerArray<CCaInnerEntry> resultArray; |
|
1214 CleanupResetAndDestroyPushL(resultArray); |
|
1215 CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC(); |
|
1216 |
|
1217 innerQuery->SetCount(limit); |
|
1218 |
|
1219 // limit is set to stif parser param |
|
1220 mStorage->GetEntriesL(innerQuery, resultArray); |
|
1221 |
|
1222 |
|
1223 // check results |
|
1224 if ((0 < limit) && (limit <= entriesCount)) { |
|
1225 if (resultArray.Count() == innerQuery->GetCount()) { |
|
1226 err = KErrNone; |
|
1227 } else { |
|
1228 err = KErrGeneral; |
|
1229 } |
|
1230 } else { |
|
1231 if (resultArray.Count() == entriesCount) { |
|
1232 err = KErrNone; |
|
1233 } else { |
|
1234 err = KErrGeneral; |
|
1235 } |
|
1236 } |
|
1237 |
|
1238 // clear after test |
|
1239 CleanupStack::PopAndDestroy(innerQuery); |
|
1240 CleanupStack::PopAndDestroy(&resultArray); |
|
1241 ); |
|
1242 // limit added to make easier to identify where failure occured |
|
1243 QCOMPARE(err + limit, KErrNone + limit); |
|
1244 } |
|
1245 __UHEAP_MARKEND; |
|
1246 } |
|
1247 |
|
1248 // --------------------------------------------------------------------------- |
|
1249 // Test Select entries by role. |
|
1250 // |
|
1251 // --------------------------------------------------------------------------- |
|
1252 // |
|
1253 void CCAStorageTest::testGetEntriesByRole() |
|
1254 { |
|
1255 |
|
1256 |
|
1257 __UHEAP_MARK; |
|
1258 TRAPD(err, |
|
1259 CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC(); |
|
1260 |
|
1261 RPointerArray<CCaInnerEntry> resultArrayGroups; |
|
1262 CleanupResetAndDestroyPushL(resultArrayGroups); |
|
1263 innerQuery->SetRole(CCaInnerQuery::Group); |
|
1264 mStorage->GetEntriesL(innerQuery, resultArrayGroups); |
|
1265 TInt groupsCount = resultArrayGroups.Count(); |
|
1266 CleanupStack::PopAndDestroy(&resultArrayGroups); |
|
1267 |
|
1268 RPointerArray<CCaInnerEntry> resultArrayItems; |
|
1269 CleanupResetAndDestroyPushL(resultArrayItems); |
|
1270 innerQuery->SetRole(CCaInnerQuery::Item); |
|
1271 mStorage->GetEntriesL(innerQuery, resultArrayItems); |
|
1272 TInt itemsCount = resultArrayItems.Count(); |
|
1273 // changes the role of two items to be groups |
|
1274 |
|
1275 resultArrayItems[0]->SetRole(CCaInnerQuery::Group); |
|
1276 resultArrayItems[1]->SetRole(CCaInnerQuery::Group); |
|
1277 TInt entry1Id = resultArrayItems[0]->GetId(); |
|
1278 TInt entry2Id = resultArrayItems[1]->GetId(); |
|
1279 mStorage->AddL(resultArrayItems[0]); |
|
1280 mStorage->AddL(resultArrayItems[1]); |
|
1281 CleanupStack::PopAndDestroy(&resultArrayItems); |
|
1282 |
|
1283 RPointerArray<CCaInnerEntry> resultArrayGroups2; |
|
1284 CleanupResetAndDestroyPushL(resultArrayGroups2); |
|
1285 innerQuery->SetRole(CCaInnerQuery::Group); |
|
1286 mStorage->GetEntriesL(innerQuery, resultArrayGroups2); |
|
1287 TInt groupsCountAfterModifyRole = resultArrayGroups2.Count(); |
|
1288 err = (groupsCountAfterModifyRole == groupsCount + 2)? err : KErrWrongData; |
|
1289 |
|
1290 // Check that entry 1 is now group |
|
1291 for (TInt i = 0; i < groupsCountAfterModifyRole; i++) { |
|
1292 if (resultArrayGroups2[i]->GetId() == entry1Id) { |
|
1293 break; |
|
1294 } else if (i == groupsCountAfterModifyRole - 1) { |
|
1295 err = KErrWrongData; |
|
1296 } |
|
1297 } |
|
1298 |
|
1299 // Check that entry 2 is now group |
|
1300 for (TInt i = 0; i < groupsCountAfterModifyRole; i++) { |
|
1301 if (resultArrayGroups2[i]->GetId() == entry2Id) { |
|
1302 break; |
|
1303 } else if (i == groupsCountAfterModifyRole - 1) { |
|
1304 err = KErrWrongData; |
|
1305 } |
|
1306 } |
|
1307 |
|
1308 CleanupStack::PopAndDestroy(&resultArrayGroups2); |
|
1309 |
|
1310 RPointerArray<CCaInnerEntry> resultArrayItems2; |
|
1311 CleanupResetAndDestroyPushL(resultArrayItems2); |
|
1312 innerQuery->SetRole(CCaInnerQuery::Item); |
|
1313 mStorage->GetEntriesL(innerQuery, resultArrayItems2); |
|
1314 TInt itemsCountAfterModifyRole = resultArrayItems2.Count(); |
|
1315 err = (itemsCountAfterModifyRole == itemsCount - 2)? err : KErrWrongData; |
|
1316 CleanupStack::PopAndDestroy(&resultArrayItems2); |
|
1317 |
|
1318 CleanupStack::PopAndDestroy(innerQuery); |
|
1319 ); |
|
1320 __UHEAP_MARKEND; |
|
1321 |
|
1322 QCOMPARE(err, KErrNone); |
|
1323 } |
|
1324 |
|
1325 void CCAStorageTest::testGetEntriesByAttributes() |
|
1326 { |
|
1327 __UHEAP_MARK; |
|
1328 int uid; |
|
1329 TInt attributesCount; |
|
1330 TInt attributesCountFromQuery; |
|
1331 TRAPD(err, |
|
1332 |
|
1333 // add new entry with attributes |
|
1334 CCaInnerEntry *innerEntry = CCaInnerEntry::NewLC(); |
|
1335 |
|
1336 innerEntry->SetTextL(KTestName); |
|
1337 innerEntry->SetEntryTypeNameL(KTypeName2); |
|
1338 innerEntry->SetFlags(flag); |
|
1339 innerEntry->SetRole(CCaInnerQuery::Item); |
|
1340 innerEntry->SetUid(KTestAppUid); |
|
1341 innerEntry->SetIconDataL(_L("filename"), _L("skinId"), _L("268458321")); |
|
1342 |
|
1343 innerEntry->AddAttributeL(KAttrName_1, KAttrValue_1); |
|
1344 innerEntry->AddAttributeL(KAttrName_2, KAttrValue_2); |
|
1345 innerEntry->AddAttributeL(KAttrName_3, KAttrValue_3); |
|
1346 |
|
1347 mStorage->AddL(innerEntry); |
|
1348 |
|
1349 CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC(); |
|
1350 innerQuery->AddAttributeL(KAttrName_2, KAttrValue_2); |
|
1351 innerQuery->AddAttributeL(KAttrName_3, KAttrValue_3); |
|
1352 attributesCountFromQuery = innerQuery->GetAttributes().Count(); |
|
1353 |
|
1354 // get entries by attributes |
|
1355 RPointerArray<CCaInnerEntry> resultArrayItems; |
|
1356 CleanupResetAndDestroyPushL(resultArrayItems); |
|
1357 mStorage->GetEntriesL(innerQuery, resultArrayItems); |
|
1358 |
|
1359 if( resultArrayItems.Count() ) |
|
1360 { |
|
1361 uid = resultArrayItems[0]->GetUid(); |
|
1362 attributesCount = resultArrayItems[0]->GetAttributes().Count(); |
|
1363 } |
|
1364 |
|
1365 CleanupStack::PopAndDestroy(&resultArrayItems); |
|
1366 CleanupStack::PopAndDestroy(innerQuery); |
|
1367 CleanupStack::PopAndDestroy(innerEntry); |
|
1368 ); |
|
1369 __UHEAP_MARKEND; |
|
1370 |
|
1371 QCOMPARE(uid, KTestAppUid); |
|
1372 QCOMPARE((attributesCount-1), attributesCountFromQuery); |
|
1373 QCOMPARE(err, KErrNone); |
|
1374 } |
|
1375 |
|
1376 void CCAStorageTest::testGetEntriesByAttributes2() |
|
1377 { |
|
1378 __UHEAP_MARK; |
|
1379 int getEntriesCount; |
|
1380 TRAPD(err, |
|
1381 |
|
1382 // add new entry with attributes |
|
1383 CCaInnerEntry *innerEntry = CCaInnerEntry::NewLC(); |
|
1384 |
|
1385 innerEntry->SetTextL(KTestName); |
|
1386 innerEntry->SetEntryTypeNameL(KTypeName2); |
|
1387 innerEntry->SetFlags(flag); |
|
1388 innerEntry->SetRole(CCaInnerQuery::Item); |
|
1389 innerEntry->SetUid(KTestAppUid); |
|
1390 innerEntry->SetIconDataL(_L("filename"), _L("skinId"), _L("268458321")); |
|
1391 |
|
1392 innerEntry->AddAttributeL(KAttrName_1, KAttrValue_1); |
|
1393 innerEntry->AddAttributeL(KAttrName_2, KAttrValue_2); |
|
1394 innerEntry->AddAttributeL(KAttrName_3, KAttrValue_3); |
|
1395 |
|
1396 mStorage->AddL(innerEntry); |
|
1397 |
|
1398 // add new entry with attributes |
|
1399 CCaInnerEntry *innerEntry2 = CCaInnerEntry::NewLC(); |
|
1400 |
|
1401 innerEntry2->SetTextL(KTestName2); |
|
1402 innerEntry2->SetEntryTypeNameL(KTypeName2); |
|
1403 innerEntry2->SetFlags(flag); |
|
1404 innerEntry2->SetRole(CCaInnerQuery::Item); |
|
1405 innerEntry2->SetUid(KTestAppUid2); |
|
1406 |
|
1407 // add new entry with attributes |
|
1408 innerEntry2->AddAttributeL(KAttrName_1, KAttrValue_1); |
|
1409 innerEntry2->AddAttributeL(KAttrName_2, KAttrValue_2); |
|
1410 |
|
1411 mStorage->AddL(innerEntry2); |
|
1412 |
|
1413 CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC(); |
|
1414 innerQuery->AddAttributeL(KAttrName_1, KAttrValue_1); |
|
1415 innerQuery->AddAttributeL(KAttrName_2, KAttrValue_2); |
|
1416 |
|
1417 // get entries by attributes |
|
1418 RPointerArray<CCaInnerEntry> resultArrayItems; |
|
1419 CleanupResetAndDestroyPushL(resultArrayItems); |
|
1420 mStorage->GetEntriesL(innerQuery, resultArrayItems); |
|
1421 |
|
1422 TInt attributesCount = resultArrayItems[0]->GetAttributes().Count(); |
|
1423 getEntriesCount = resultArrayItems.Count(); |
|
1424 |
|
1425 CleanupStack::PopAndDestroy(&resultArrayItems); |
|
1426 CleanupStack::PopAndDestroy(innerQuery); |
|
1427 CleanupStack::PopAndDestroy(innerEntry2); |
|
1428 CleanupStack::PopAndDestroy(innerEntry); |
|
1429 ); |
|
1430 __UHEAP_MARKEND; |
|
1431 |
|
1432 QCOMPARE(getEntriesCount, 2); |
|
1433 QCOMPARE(err, KErrNone); |
|
1434 } |
|
1435 |
|
1436 // --------------------------------------------------------------------------- |
|
1437 // Test Select entries by child id. |
|
1438 // |
|
1439 // --------------------------------------------------------------------------- |
|
1440 // |
|
1441 void CCAStorageTest::testGetEntriesByChildId() |
|
1442 { |
|
1443 TInt expectedGroupEntryCount(0); |
|
1444 TInt actualGroupEntryCount(0); |
|
1445 |
|
1446 __UHEAP_MARK; |
|
1447 |
|
1448 TRAPD(err, |
|
1449 CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC(); |
|
1450 |
|
1451 // check before test entries count in sfecific group |
|
1452 CCaSqlQuery *query = CCaSqlQuery::NewLC(((CCaSqLiteStorage *)mStorage)->iSqlDb); |
|
1453 query->SetQueryL(KSQLGetEntriesCountAsParentsForSpecificEntry); |
|
1454 query->PrepareL(); |
|
1455 query->BindIntL(query->iStatement.ParameterIndex(KSQLGEEntryId), 7); |
|
1456 |
|
1457 query->ExecuteL(expectedGroupEntryCount); |
|
1458 |
|
1459 CleanupStack::PopAndDestroy(query); |
|
1460 |
|
1461 innerQuery->SetChildId(7); |
|
1462 |
|
1463 // get entries from specific group |
|
1464 RPointerArray<CCaInnerEntry> resultArray; |
|
1465 CleanupResetAndDestroyPushL(resultArray); |
|
1466 |
|
1467 mStorage->GetEntriesL(innerQuery, resultArray); |
|
1468 |
|
1469 actualGroupEntryCount = resultArray.Count(); |
|
1470 |
|
1471 CleanupStack::PopAndDestroy(&resultArray); |
|
1472 CleanupStack::PopAndDestroy(innerQuery); |
|
1473 ); |
|
1474 |
|
1475 __UHEAP_MARKEND; |
|
1476 |
|
1477 QCOMPARE(err, KErrNone); |
|
1478 QCOMPARE(actualGroupEntryCount, expectedGroupEntryCount); |
|
1479 } |
|
1480 |