|
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 * T_cahswidgetscanner.cpp |
|
19 * |
|
20 * Created on: 2009-09-16 |
|
21 * Author: |
|
22 */ |
|
23 |
|
24 // CLASS HEADER |
|
25 |
|
26 |
|
27 #include <ecom/ecom.h> |
|
28 #include <QScopedPointer> |
|
29 #include <utf.h> |
|
30 #include <xml/dom/xmlengdocument.h> |
|
31 #include <XQConversions> |
|
32 #include <usif/sif/sifcommon.h> |
|
33 #include <usif/sif/sif.h> |
|
34 #include <xmlengelement.h> |
|
35 #include <driveinfo.h> |
|
36 |
|
37 #include "t_cawidgetscanner.h" |
|
38 #include "cawidgetscannertestutils.h" |
|
39 #include "waitactive.h" |
|
40 #include "casrvengutils.h" |
|
41 #include "castorageproxy.h" |
|
42 #include "casrvmanager.h" |
|
43 #include "casrvplugin.h" |
|
44 #include "cainnerentry.h" |
|
45 #include "cainnerquery.h" |
|
46 #include "caarraycleanup.inl" |
|
47 #include "testconsts.h" |
|
48 #include "cadef.h" |
|
49 #include "castorage_global.h" |
|
50 |
|
51 #include "cawidgetscannerparser.h" |
|
52 #include "cawidgetstoragehandler.h" |
|
53 #include "cawidgetscannerplugin.h" |
|
54 #include "cawidgetscannerdef.h" |
|
55 #include "WidgetScannerUtils.h" |
|
56 |
|
57 |
|
58 #include "t_cainstaller.h" |
|
59 |
|
60 const TUid KHsWidgetPluginUid = {0x20026FB1}; |
|
61 const TInt installedUid = 0x20053785; |
|
62 |
|
63 _LIT8( KSisxMimeType, "x-epoc/x-sisx-app" ); |
|
64 _LIT( KTestLibrary, "C:\\private\\20022F35\\import\\widgetregistry\\20053785\\testwidget" ); |
|
65 _LIT8( KWidgetUID, "testwidgetprovider.dll" ); |
|
66 _LIT( KWidgetLibrary2, "C:\\private\\20022F35\\import\\widgetregistry\\20053785\\testwidget22" ); |
|
67 _LIT( KWidgetLibrary3, "C:\\private\\20022F35\\import\\widgetregistry\\20053785\\testwidget33" ); |
|
68 |
|
69 _LIT( KWidget1PackageName, "c:\\testing\\data\\Installs\\validwidget1.SISX" ); |
|
70 _LIT( KWidget2PackageName, "c:\\testing\\data\\Installs\\validwidget2.SISX" ); |
|
71 _LIT( KWidget3PackageName, "c:\\testing\\data\\Installs\\validwidget3.SISX" ); |
|
72 _LIT( KWidget4PackageName, "c:\\testing\\data\\Installs\\validwidget4.SISX" ); |
|
73 _LIT( KWidget1ManifestName, "C:\\private\\20022F35\\import\\widgetregistry\\20053785\\validwidget1.manifest" ); |
|
74 _LIT( KWidget2ManifestName, "C:\\private\\20022F35\\import\\widgetregistry\\20053785\\validwidget2.manifest" ); |
|
75 _LIT( KWidget3ManifestName, "C:\\private\\20022F35\\import\\widgetregistry\\20053785\\validwidget3.manifest" ); |
|
76 _LIT( KWidget4ManifestName, "C:\\private\\20022F35\\import\\widgetregistry\\20053785\\validwidget4.manifest" ); |
|
77 _LIT( KWidgetQmFolder, "c:\\resource\\qt\\translations\\" ); |
|
78 _LIT( KWidgetQmFolderAndFile, "c:\\resource\\qt\\translations\\" ); |
|
79 _LIT( KWidgetQmFile, "c:\\testing\\data\\t_cawidgetscanner\\widgettranslation_en_GB.qm" ); |
|
80 _LIT( KWidgetUri1, "testwidget" ); |
|
81 _LIT( KWidgetUri2, "testwidget22" ); |
|
82 _LIT( KWidgetUri3, "testwidget33" ); |
|
83 _LIT( KWidgetUri4, "testwidget44" ); |
|
84 _LIT( KTranslationFileNameAsInManifest, "widgettranslation" ); |
|
85 |
|
86 template <typename RClass> |
|
87 struct RClassDeleter |
|
88 { |
|
89 static inline void cleanup(RClass *ptr) |
|
90 { |
|
91 ptr->Close(); |
|
92 } |
|
93 }; |
|
94 |
|
95 typedef QScopedPointer<RBuf, |
|
96 RClassDeleter<RBuf> > RBufGuard; |
|
97 typedef QScopedPointer<RBuf8, |
|
98 RClassDeleter<RBuf8> > RBuf8Guard; |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 void T_CaWidgetScanner::WaitL(TInt aMicroSec) |
|
105 { |
|
106 CWaitActive* wait = CWaitActive::NewL(); |
|
107 wait->Wait(aMicroSec); |
|
108 delete wait; |
|
109 } |
|
110 |
|
111 void T_CaWidgetScanner::initTestCase() |
|
112 { |
|
113 const TUid KWidgetHandlerPluginUid = {0x20028707}; |
|
114 TRAPD(err, |
|
115 iTestUtils = CTestUtils::NewL(); |
|
116 iTestUtils->CopyDb(); |
|
117 |
|
118 // remove hswidget |
|
119 iStorage = CCaStorageProxy::NewL(); |
|
120 iSrvEngUtils = CCaSrvEngUtils::NewL(); |
|
121 iScr = new Usif::RSoftwareComponentRegistry; |
|
122 User::LeaveIfError(iScr->Connect()); |
|
123 |
|
124 iFs.Connect(); |
|
125 iImportPath.CreateL( KMaxPath ); |
|
126 |
|
127 createImportDirectoryL(); |
|
128 |
|
129 iInstaller = T_CaInstaller::NewL(); |
|
130 TPluginParams params; |
|
131 params.engUtils = iSrvEngUtils; |
|
132 params.storageProxy = iStorage; |
|
133 params.softwareRegistry = iScr; |
|
134 iPlugin = iTestUtils->LoadPluginL( KWidgetHandlerPluginUid, ¶ms); |
|
135 |
|
136 ); |
|
137 } |
|
138 |
|
139 void T_CaWidgetScanner::cleanupTestCase() |
|
140 { |
|
141 QTest::qWait(5000); |
|
142 |
|
143 iTestUtils->RemoveL(KTestDbDest); |
|
144 delete iPlugin; |
|
145 delete iInstaller; |
|
146 delete iStorage; |
|
147 iStorage = NULL; |
|
148 delete iTestUtils; |
|
149 iTestUtils = NULL; |
|
150 delete iSrvEngUtils; |
|
151 iSrvEngUtils = NULL; |
|
152 iScr->Close(); |
|
153 delete iScr; |
|
154 iScr = NULL; |
|
155 iFs.Close(); |
|
156 REComSession::FinalClose(); |
|
157 iImportPath.Close(); |
|
158 iWidgetScanFolder.Close(); |
|
159 |
|
160 iWidgetScanFile1.Close(); |
|
161 } |
|
162 |
|
163 |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 void T_CaWidgetScanner::init() |
|
169 { |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // |
|
174 // --------------------------------------------------------------------------- |
|
175 // |
|
176 void T_CaWidgetScanner::cleanup() |
|
177 { |
|
178 QTest::qWait(100); |
|
179 } |
|
180 |
|
181 |
|
182 |
|
183 void T_CaWidgetScanner::createImportDirectoryL() |
|
184 { |
|
185 //create "parsed" directory if it doesn't exist yet; |
|
186 // create directory on C: drive |
|
187 iWidgetScanFolder.Close(); |
|
188 iWidgetScanFile1.Close(); |
|
189 iWidgetScanFolder.CreateL(KMaxPath); |
|
190 iWidgetScanFile1.CreateL(KMaxPath); |
|
191 iWidgetScanFolder.Append( KPrivate ); |
|
192 iWidgetScanFolder.Append( KHSWidgetScanFolder ); |
|
193 iWidgetScanFile1.Append(iWidgetScanFolder); |
|
194 iWidgetScanFile1.Append(KManifestFile1); |
|
195 } |
|
196 |
|
197 // |
|
198 // TESTS -------------------------------------------------------------------- |
|
199 // |
|
200 // --------------------------------------------------------------------------- |
|
201 // |
|
202 |
|
203 void T_CaWidgetScanner::testPluginNewL() |
|
204 { |
|
205 //Check only if plugin was created correctly |
|
206 QVERIFY( iPlugin != NULL); |
|
207 } |
|
208 |
|
209 |
|
210 // --------------------------------------------------------------------------- |
|
211 // |
|
212 // --------------------------------------------------------------------------- |
|
213 // |
|
214 |
|
215 |
|
216 void T_CaWidgetScanner::testAddWidget() |
|
217 { |
|
218 bool widgetExistsInStorage(false); |
|
219 TInt err(KErrNone); |
|
220 |
|
221 |
|
222 TRAP_IGNORE(iInstaller->InstallL(KWidget1PackageName)); |
|
223 |
|
224 QTest::qWait(3000); |
|
225 |
|
226 TRAP_IGNORE(widgetExistsInStorage = ( iTestUtils->WidgetExistsInStorageL( |
|
227 KAttrWidgetLibrary, KTestLibrary, iStorage ) != EFalse )); |
|
228 |
|
229 // clean after test |
|
230 TRAP_IGNORE(iInstaller->UninstallL(KWidget1ManifestName)) |
|
231 QTest::qWait(3000); |
|
232 |
|
233 QVERIFY(widgetExistsInStorage); |
|
234 } |
|
235 |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // |
|
239 // --------------------------------------------------------------------------- |
|
240 // |
|
241 void T_CaWidgetScanner::testUpdateWidget() |
|
242 { |
|
243 TInt err(KErrNone); |
|
244 |
|
245 TRAP(err, |
|
246 testUpdateWidgetTrapped() |
|
247 ); |
|
248 } |
|
249 // --------------------------------------------------------------------------- |
|
250 // |
|
251 // --------------------------------------------------------------------------- |
|
252 // |
|
253 void T_CaWidgetScanner::testUpdateWidgetTrapped() |
|
254 { |
|
255 TInt err(KErrNone); |
|
256 |
|
257 TInt expectedCount(0); |
|
258 TInt actualCount(0); |
|
259 bool widgetAExistsInStorage(false); |
|
260 bool widgetBExistsInStorage(false); |
|
261 |
|
262 iInstaller->InstallL(KWidget2PackageName); |
|
263 |
|
264 QTest::qWait(3000); |
|
265 |
|
266 expectedCount = iTestUtils->WidgetsCountL(iStorage); |
|
267 |
|
268 widgetAExistsInStorage = (iTestUtils->WidgetExistsInStorageL( |
|
269 KAttrWidgetLibrary, KWidgetLibrary2, iStorage) != FALSE); |
|
270 |
|
271 |
|
272 iInstaller->InstallL(KWidget3PackageName); |
|
273 QTest::qWait(3000); |
|
274 |
|
275 widgetBExistsInStorage = (iTestUtils->WidgetExistsInStorageL( |
|
276 KAttrWidgetUri, KWidgetUri2, iStorage) != FALSE); |
|
277 |
|
278 actualCount = iTestUtils->WidgetsCountL(iStorage); |
|
279 TRAP_IGNORE(iInstaller->UninstallL(KWidget2ManifestName)) |
|
280 QTest::qWait(3000); |
|
281 TRAP_IGNORE(iInstaller->UninstallL(KWidget3ManifestName)) |
|
282 QTest::qWait(3000); |
|
283 |
|
284 QCOMPARE(err, KErrNone); |
|
285 QVERIFY(widgetAExistsInStorage); |
|
286 QVERIFY(widgetBExistsInStorage); |
|
287 QCOMPARE(actualCount, expectedCount); |
|
288 } |
|
289 |
|
290 |
|
291 // --------------------------------------------------------------------------- |
|
292 // |
|
293 // --------------------------------------------------------------------------- |
|
294 // |
|
295 void T_CaWidgetScanner::testRemoveMmcWidget() |
|
296 { |
|
297 TInt err(KErrNone); |
|
298 TInt id(KErrNotFound); |
|
299 bool widgetExistsInStorage(false); |
|
300 bool mmcIdAttributeSet1(false); |
|
301 bool mmcIdAttributeSet2(false); |
|
302 |
|
303 TRAP(err, |
|
304 |
|
305 //test |
|
306 iInstaller->InstallL(KWidget1PackageName); |
|
307 QTest::qWait(3000); |
|
308 |
|
309 id = AppendMmcIdL(_L("TestWidget")); |
|
310 |
|
311 mmcIdAttributeSet1 = MmcAttributeSetL(id); |
|
312 |
|
313 // after unistall mmc id should be removed |
|
314 iInstaller->UninstallL(KWidget1ManifestName); |
|
315 |
|
316 QTest::qWait(3000); |
|
317 |
|
318 mmcIdAttributeSet2 = MmcAttributeSetL(id); |
|
319 |
|
320 ); |
|
321 |
|
322 QCOMPARE(err, KErrNone); |
|
323 QVERIFY(mmcIdAttributeSet1); |
|
324 QVERIFY(!mmcIdAttributeSet2); |
|
325 } |
|
326 |
|
327 // --------------------------------------------------------------------------- |
|
328 // |
|
329 // --------------------------------------------------------------------------- |
|
330 // |
|
331 void T_CaWidgetScanner::testUpdateTheSameWidget() |
|
332 { |
|
333 TInt err(KErrNone); |
|
334 TRAP(err, |
|
335 testUpdateTheSameWidgetTrapped() |
|
336 ); |
|
337 |
|
338 } |
|
339 |
|
340 // --------------------------------------------------------------------------- |
|
341 // |
|
342 // --------------------------------------------------------------------------- |
|
343 // |
|
344 void T_CaWidgetScanner::testUpdateTheSameWidgetTrapped() |
|
345 { |
|
346 _LIT( KWText, "TestWidget" ); |
|
347 TUint flags0(0U); |
|
348 TUint flags1(0U); |
|
349 TUint flags2(0U); |
|
350 TInt err(KErrNone); |
|
351 TInt expectedCount(0); |
|
352 TInt actualCount(0); |
|
353 |
|
354 iInstaller->InstallL( KWidget1PackageName ); |
|
355 |
|
356 QTest::qWait(3000); |
|
357 |
|
358 flags0 = iTestUtils->GetWidgetFlagsL( KWText, iStorage ); |
|
359 |
|
360 expectedCount = iTestUtils->WidgetsCountL( iStorage ); |
|
361 |
|
362 CCaWidgetDescription* widget = iTestUtils->GetWidgetEntryL( KWText, iStorage ); |
|
363 |
|
364 if (widget == NULL) |
|
365 { |
|
366 User::Leave(KErrNotFound); |
|
367 } |
|
368 |
|
369 CleanupStack::PushL( widget ); |
|
370 CCaInnerEntry* innerEntry = widget->GetEntryLC(); |
|
371 iStorage->TouchL( innerEntry ); |
|
372 QTest::qWait( 500 ); |
|
373 |
|
374 flags1 = iTestUtils->GetWidgetFlagsL( KWText, iStorage ); |
|
375 |
|
376 iInstaller->InstallL( KWidget1PackageName ); |
|
377 QTest::qWait(3000); |
|
378 |
|
379 flags2 = iTestUtils->GetWidgetFlagsL( KWText, iStorage ); |
|
380 |
|
381 actualCount = iTestUtils->WidgetsCountL(iStorage); |
|
382 |
|
383 CleanupStack::PopAndDestroy( innerEntry ); |
|
384 CleanupStack::PopAndDestroy( widget ); |
|
385 |
|
386 |
|
387 // clean after test |
|
388 iInstaller->UninstallL(KWidget1ManifestName); |
|
389 QTest::qWait(3000); |
|
390 // QCOMPARE(err, KErrNone); |
|
391 QVERIFY( ~(flags0 & EUsed) ); |
|
392 QVERIFY( (flags1 & EUsed) ); |
|
393 QVERIFY( ~(flags2 & EUsed) ); |
|
394 QCOMPARE(actualCount, expectedCount); |
|
395 } |
|
396 |
|
397 |
|
398 // --------------------------------------------------------------------------- |
|
399 // |
|
400 // --------------------------------------------------------------------------- |
|
401 // |
|
402 void T_CaWidgetScanner::testUpdateMmcRemoveInsertTrapped() |
|
403 { |
|
404 _LIT( KWTextCanNotTranslate, "txt_applib_subtitle_downloads" ); |
|
405 TPluginParams params; |
|
406 params.engUtils = 0; |
|
407 params.storageProxy = iStorage; |
|
408 params.softwareRegistry = iScr; |
|
409 _LIT( KWTextTranslated, "Downloads" ); |
|
410 TUint flags0(0U); |
|
411 TUint flags1(0U); |
|
412 TUint flags2(0U); |
|
413 TUint flags3(0U); |
|
414 TInt err(KErrNone); |
|
415 |
|
416 |
|
417 |
|
418 iTestUtils->Copy( KWidgetQmFile, KWidgetQmFolder ); |
|
419 |
|
420 CCaWidgetStorageHandler* handler = CCaWidgetStorageHandler::NewL( |
|
421 iStorage, *iScr, iFs ); |
|
422 |
|
423 iInstaller->InstallL( KWidget2PackageName ); |
|
424 QTest::qWait(3000); |
|
425 //get translated widget |
|
426 RBuf widgetName; |
|
427 widgetName.CreateL( KWTextTranslated ); |
|
428 CCaWidgetDescription* widget = iTestUtils->GetWidgetEntryL( |
|
429 KWTextTranslated, iStorage ); |
|
430 if( !widget ) |
|
431 { |
|
432 widgetName.Close(); |
|
433 widgetName.CreateL( KWTextCanNotTranslate ); |
|
434 //qm file has not found |
|
435 widget = iTestUtils->GetWidgetEntryL( |
|
436 KWTextCanNotTranslate, iStorage ); |
|
437 } |
|
438 flags0 = iTestUtils->GetWidgetFlagsL( widgetName, iStorage ); |
|
439 CleanupStack::PushL( widget ); |
|
440 CCaInnerEntry* innerEntry = widget->GetEntryLC(); |
|
441 iStorage->TouchL( innerEntry ); |
|
442 QTest::qWait( 500 ); |
|
443 |
|
444 flags1 = iTestUtils->GetWidgetFlagsL( widgetName, iStorage ); |
|
445 |
|
446 CCaWidgetDescription* widget2 = iTestUtils->GetWidgetEntryL( widgetName, iStorage ); |
|
447 CleanupStack::PushL( widget2 ); |
|
448 |
|
449 // set missing |
|
450 handler->SetMissingFlagL( widget2 ); |
|
451 flags2 = iTestUtils->GetWidgetFlagsL( widgetName, iStorage ); |
|
452 |
|
453 iInstaller->InstallL( KWidget2PackageName ); |
|
454 QTest::qWait( 4000 ); |
|
455 |
|
456 flags3 = iTestUtils->GetWidgetFlagsL( widgetName, iStorage ); |
|
457 widgetName.Close(); |
|
458 CleanupStack::PopAndDestroy( widget2 ); |
|
459 CleanupStack::PopAndDestroy( innerEntry ); |
|
460 CleanupStack::PopAndDestroy( widget ); |
|
461 iTestUtils->RemoveL( KWidgetQmFolderAndFile ); |
|
462 |
|
463 |
|
464 // clean after test |
|
465 iInstaller->UninstallL(KWidget2ManifestName); |
|
466 |
|
467 QTest::qWait(3000); |
|
468 QCOMPARE(err, KErrNone); |
|
469 QVERIFY( ~(flags0 & EUsed) ); |
|
470 QVERIFY( flags1 & EUsed ); |
|
471 QVERIFY( ~(flags1 & EMissing) ); |
|
472 QVERIFY( flags2 & EUsed ); |
|
473 QVERIFY( flags2 & EMissing ); |
|
474 QVERIFY( flags3 & ~EUsed ); |
|
475 QVERIFY( flags3 & ~EMissing ); |
|
476 } |
|
477 |
|
478 void T_CaWidgetScanner::testUpdateMmcRemoveInsert() |
|
479 { |
|
480 TInt err(KErrNone); |
|
481 TRAP(err, |
|
482 testUpdateMmcRemoveInsertTrapped() |
|
483 ); |
|
484 } |
|
485 // --------------------------------------------------------------------------- |
|
486 // |
|
487 // --------------------------------------------------------------------------- |
|
488 // |
|
489 void T_CaWidgetScanner::testRemoveWidget() |
|
490 { |
|
491 TInt err(KErrNone); |
|
492 bool widgetExistedInStorage(false); |
|
493 bool widgetRemovedFromStorage(false); |
|
494 |
|
495 |
|
496 TRAP(err, |
|
497 |
|
498 iInstaller->InstallL(KWidget1PackageName); |
|
499 |
|
500 QTest::qWait(3000); |
|
501 |
|
502 widgetExistedInStorage =( iTestUtils->WidgetExistsInStorageL( |
|
503 KAttrWidgetLibrary, KTestLibrary, iStorage ) != FALSE); |
|
504 |
|
505 iInstaller->UninstallL(KWidget1ManifestName); |
|
506 |
|
507 QTest::qWait(3000); |
|
508 |
|
509 widgetRemovedFromStorage = ((iTestUtils->WidgetExistsInStorageL( |
|
510 KAttrWidgetLibrary, KTestLibrary, iStorage )) != FALSE); |
|
511 |
|
512 |
|
513 ); |
|
514 |
|
515 QCOMPARE(err, KErrNone); |
|
516 QVERIFY(widgetExistedInStorage); |
|
517 QVERIFY(widgetRemovedFromStorage); |
|
518 } |
|
519 |
|
520 |
|
521 // --------------------------------------------------------------------------- |
|
522 // |
|
523 // --------------------------------------------------------------------------- |
|
524 // |
|
525 void T_CaWidgetScanner::testSetMissingFlag() |
|
526 { |
|
527 _LIT( KWText, "TestWidget" ); |
|
528 |
|
529 TInt err(KErrNone); |
|
530 TUint flags(0U); |
|
531 |
|
532 TRAP(err, |
|
533 |
|
534 CCaWidgetStorageHandler* handler = CCaWidgetStorageHandler::NewL( |
|
535 iStorage, *iScr, iFs); |
|
536 iInstaller->InstallL(KWidget1PackageName); |
|
537 QTest::qWait(3000); |
|
538 |
|
539 CCaWidgetDescription* widget = iTestUtils->GetWidgetEntryL( KWText, iStorage); |
|
540 handler->SetMissingFlagL( widget ); |
|
541 delete widget; |
|
542 |
|
543 flags = iTestUtils->GetWidgetFlagsL(KWText, iStorage); |
|
544 |
|
545 delete handler; |
|
546 ); |
|
547 |
|
548 // clean after test |
|
549 TRAP_IGNORE(iInstaller->UninstallL(KWidget1ManifestName)); |
|
550 QTest::qWait(3000); |
|
551 QCOMPARE(err, KErrNone); |
|
552 QVERIFY( flags & EMissing ); |
|
553 QVERIFY( ~(flags & EVisible) ); |
|
554 } |
|
555 |
|
556 // --------------------------------------------------------------------------- |
|
557 // |
|
558 // --------------------------------------------------------------------------- |
|
559 // |
|
560 void T_CaWidgetScanner::testSetLocalizationsL() |
|
561 { |
|
562 CCaWidgetDescription* widget = CCaWidgetDescription::NewLC(); |
|
563 widget->SetUriL(KWidgetUri1()); |
|
564 widget->SetTranslationFileNameL(KTranslationFileNameAsInManifest()); |
|
565 widget->SetTitleL( _L("txt_applib_subtitle_downloads") ); |
|
566 |
|
567 widget->LocalizeTextsL(); |
|
568 |
|
569 QVERIFY(!widget->GetStringIdTitle().Compare(_L("txt_applib_subtitle_downloads"))); |
|
570 QVERIFY(!widget->GetStringIdDescription().Compare( KNullDesC )); |
|
571 |
|
572 RPointerArray<CCaLocalizationEntry> resultContainer; |
|
573 CleanupResetAndDestroyPushL( resultContainer ); |
|
574 iStorage->GetLocalizationsL( resultContainer ); |
|
575 int a = resultContainer.Count(); |
|
576 resultContainer.Reset(); |
|
577 |
|
578 CCaWidgetStorageHandler* handler = CCaWidgetStorageHandler::NewL( |
|
579 iStorage, *iScr, iFs ); |
|
580 |
|
581 widget->SetStringidTitleL( _L("titleId") ); |
|
582 handler->SetLocalizationsL( widget, 2000 ); |
|
583 |
|
584 iStorage->GetLocalizationsL( resultContainer ); |
|
585 int b = resultContainer.Count(); |
|
586 |
|
587 QCOMPARE( a+1, b ); |
|
588 |
|
589 delete handler; |
|
590 CleanupStack::PopAndDestroy( &resultContainer ); |
|
591 CleanupStack::PopAndDestroy( widget ); |
|
592 } |
|
593 |
|
594 // --------------------------------------------------------------------------- |
|
595 // |
|
596 // --------------------------------------------------------------------------- |
|
597 // |
|
598 void T_CaWidgetScanner::testUtils() |
|
599 { |
|
600 RBuf mmcId; |
|
601 mmcId.CleanupClosePushL(); |
|
602 mmcId.CreateL(KMassStorageIdLength); |
|
603 WidgetScannerUtils::CurrentMmcId(iFs, mmcId); |
|
604 TInt mmcDrive; |
|
605 if( DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRemovableMassStorage, |
|
606 mmcDrive ) == KErrNone ) |
|
607 { |
|
608 QVERIFY(mmcId.Length() > 0); |
|
609 } |
|
610 |
|
611 CleanupStack::PopAndDestroy( &mmcId ); |
|
612 } |
|
613 |
|
614 // --------------------------------------------------------------------------- |
|
615 // |
|
616 // --------------------------------------------------------------------------- |
|
617 // |
|
618 void T_CaWidgetScanner::testParsePreviewImageName() |
|
619 { |
|
620 TInt err(KErrNone); |
|
621 TChar drive = 'c'; |
|
622 |
|
623 RBuf expectedPreviewFileName; |
|
624 RBufGuard expectedPreviewFileNameGuard(&expectedPreviewFileName); |
|
625 |
|
626 QScopedPointer < CCaWidgetScannerParser > parser; |
|
627 QScopedPointer < CCaWidgetDescription > widgetDescriptor; |
|
628 QT_TRAP_THROWING(parser.reset(CCaWidgetScannerParser::NewL(iFs))); |
|
629 QT_TRAP_THROWING(widgetDescriptor.reset( CCaWidgetDescription::NewL()) ); |
|
630 |
|
631 _LIT8( KPreviewFileName8, "preview.png" ); |
|
632 _LIT( KPreviewFileName, "preview.png" ); |
|
633 _LIT( KWidgetPackageId, "12345678" ); |
|
634 |
|
635 TXmlEngElement element; |
|
636 |
|
637 TRAP(err, |
|
638 RXmlEngDOMImplementation domImpl; |
|
639 CleanupClosePushL(domImpl); |
|
640 domImpl.OpenL(); |
|
641 RXmlEngDocument doc; |
|
642 CleanupClosePushL(doc); |
|
643 doc.OpenL(domImpl); |
|
644 TXmlEngElement element = |
|
645 doc.CreateDocumentElementL(KPreviewImageElementName()); |
|
646 element.AddTextL(KPreviewFileName8()); |
|
647 parser->ParsePreviewImageNameL( element, KWidgetPackageId(), |
|
648 widgetDescriptor.data(), drive); |
|
649 CleanupStack::PopAndDestroy(&doc); |
|
650 CleanupStack::PopAndDestroy(&domImpl); |
|
651 ); |
|
652 |
|
653 |
|
654 QCOMPARE(err, KErrNone); |
|
655 |
|
656 TRAP(err, |
|
657 HBufC *manifestPath = parser->GetManifestDirectoryPathLC( |
|
658 KWidgetPackageId(), drive ); |
|
659 expectedPreviewFileName.CreateL(manifestPath->Length() + |
|
660 KPreviewFileName().Length()); |
|
661 expectedPreviewFileName.Append(*manifestPath); |
|
662 expectedPreviewFileName.Append(KPreviewFileName()); |
|
663 CleanupStack::PopAndDestroy( manifestPath ); |
|
664 ); |
|
665 QCOMPARE(err, KErrNone); |
|
666 { |
|
667 const QString exp = XQConversions::s60DescToQString(expectedPreviewFileName); |
|
668 const QString act = |
|
669 XQConversions::s60DescToQString( |
|
670 widgetDescriptor->GetPreviewImageName()); |
|
671 QCOMPARE(exp, act); |
|
672 } |
|
673 |
|
674 RBuf expectedPreviewSkinId; |
|
675 RBufGuard expectedPreviewSkinIdGuard(&expectedPreviewSkinId); |
|
676 |
|
677 _LIT8( KPreviewSkinId, "skin_id" ); |
|
678 |
|
679 TRAP(err, |
|
680 RXmlEngDOMImplementation domImpl; |
|
681 CleanupClosePushL(domImpl); |
|
682 domImpl.OpenL(); |
|
683 RXmlEngDocument doc; |
|
684 CleanupClosePushL(doc); |
|
685 doc.OpenL(domImpl); |
|
686 |
|
687 TXmlEngElement element = |
|
688 doc.CreateDocumentElementL(KPreviewImageElementName()); |
|
689 element.AddTextL(KPreviewSkinId()); |
|
690 parser->ParsePreviewImageNameL( element, KWidgetPackageId(), |
|
691 widgetDescriptor.data(), drive); |
|
692 CleanupStack::PopAndDestroy(&doc); |
|
693 CleanupStack::PopAndDestroy(&domImpl); |
|
694 ); |
|
695 |
|
696 QCOMPARE(err, KErrNone); |
|
697 |
|
698 TRAP(err, |
|
699 expectedPreviewSkinId.Assign( |
|
700 CnvUtfConverter::ConvertToUnicodeFromUtf8L(KPreviewSkinId())); |
|
701 ); |
|
702 QCOMPARE(err, KErrNone); |
|
703 { |
|
704 const QString exp = XQConversions::s60DescToQString(expectedPreviewSkinId); |
|
705 const QString act = |
|
706 XQConversions::s60DescToQString( |
|
707 widgetDescriptor->GetPreviewImageName()); |
|
708 |
|
709 QCOMPARE(exp, act); |
|
710 } |
|
711 |
|
712 RBuf8 attributeValueTooLong; |
|
713 RBuf8Guard attributeValueTooLongGuard(&attributeValueTooLong); |
|
714 attributeValueTooLong.CreateL(KCaMaxAttrValueLen + 1); |
|
715 |
|
716 for (int i = KCaMaxAttrValueLen; i >= 0 ; --i) |
|
717 { |
|
718 attributeValueTooLong.Append(_L8("a")); |
|
719 } |
|
720 |
|
721 TRAP(err, |
|
722 RXmlEngDOMImplementation domImpl; |
|
723 CleanupClosePushL(domImpl); |
|
724 domImpl.OpenL(); |
|
725 RXmlEngDocument doc; |
|
726 CleanupClosePushL(doc); |
|
727 doc.OpenL(domImpl); |
|
728 |
|
729 TXmlEngElement element = |
|
730 doc.CreateDocumentElementL(KPreviewImageElementName()); |
|
731 element.AddTextL(attributeValueTooLong); |
|
732 |
|
733 parser->ParsePreviewImageNameL( element, KWidgetPackageId(), |
|
734 widgetDescriptor.data(), drive); |
|
735 CleanupStack::PopAndDestroy(&doc); |
|
736 CleanupStack::PopAndDestroy(&domImpl); |
|
737 ); |
|
738 |
|
739 QCOMPARE(err, KErrNone); |
|
740 { |
|
741 QCOMPARE(widgetDescriptor->GetPreviewImageName().Length(), |
|
742 KCaMaxAttrValueLen + 1); |
|
743 } |
|
744 |
|
745 TRAP(err, |
|
746 RXmlEngDOMImplementation domImpl; |
|
747 CleanupClosePushL(domImpl); |
|
748 domImpl.OpenL(); |
|
749 RXmlEngDocument doc; |
|
750 CleanupClosePushL(doc); |
|
751 doc.OpenL(domImpl); |
|
752 |
|
753 TXmlEngElement element = |
|
754 doc.CreateDocumentElementL(KPreviewImageElementName()); |
|
755 element.AddTextL(KNullDesC8); |
|
756 |
|
757 parser->ParsePreviewImageNameL( element, KWidgetPackageId(), |
|
758 widgetDescriptor.data(), drive); |
|
759 CleanupStack::PopAndDestroy(&doc); |
|
760 CleanupStack::PopAndDestroy(&domImpl); |
|
761 ); |
|
762 |
|
763 QCOMPARE(err, KErrNone); |
|
764 { |
|
765 const QString exp = XQConversions::s60DescToQString(KNullDesC);; |
|
766 const QString act = XQConversions::s60DescToQString( |
|
767 widgetDescriptor->GetPreviewImageName()); |
|
768 QCOMPARE(exp, act); |
|
769 } |
|
770 } |
|
771 |
|
772 // --------------------------------------------------------------------------- |
|
773 // |
|
774 // --------------------------------------------------------------------------- |
|
775 // |
|
776 void T_CaWidgetScanner::testParseIconName() |
|
777 { |
|
778 TInt err(KErrNone); |
|
779 |
|
780 TChar drive = 'c'; |
|
781 |
|
782 RBuf expectedIconFileName; |
|
783 RBufGuard expectedIconFileNameGuard(&expectedIconFileName); |
|
784 |
|
785 QScopedPointer < CCaWidgetScannerParser > parser; |
|
786 QScopedPointer < CCaWidgetDescription > widgetDescriptor; |
|
787 QT_TRAP_THROWING(parser.reset(CCaWidgetScannerParser::NewL(iFs))); |
|
788 QT_TRAP_THROWING(widgetDescriptor.reset( CCaWidgetDescription::NewL()) ); |
|
789 |
|
790 _LIT8( KIconName8, "preview.png" ); |
|
791 _LIT( KIconName, "preview.png" ); |
|
792 _LIT( KWidgetPackageId, "12345678" ); |
|
793 TXmlEngElement element; |
|
794 |
|
795 TRAP(err, |
|
796 RXmlEngDOMImplementation domImpl; |
|
797 CleanupClosePushL(domImpl); |
|
798 domImpl.OpenL(); |
|
799 RXmlEngDocument doc; |
|
800 CleanupClosePushL(doc); |
|
801 doc.OpenL(domImpl); |
|
802 TXmlEngElement element = |
|
803 doc.CreateDocumentElementL(KIcon()); |
|
804 element.AddTextL(KIconName8()); |
|
805 parser->ParseIconL( element, KWidgetPackageId(), widgetDescriptor.data(), drive ); |
|
806 CleanupStack::PopAndDestroy(&doc); |
|
807 CleanupStack::PopAndDestroy(&domImpl); |
|
808 ); |
|
809 |
|
810 |
|
811 QCOMPARE(err, KErrNone); |
|
812 |
|
813 TRAP(err, |
|
814 HBufC *manifestPath = parser->GetManifestDirectoryPathLC( KWidgetPackageId(), drive ); |
|
815 expectedIconFileName.CreateL(manifestPath->Length() + KIconName().Length()); |
|
816 expectedIconFileName.Append(*manifestPath); |
|
817 expectedIconFileName.Append(KIconName()); |
|
818 CleanupStack::PopAndDestroy(manifestPath); |
|
819 ); |
|
820 QCOMPARE(err, KErrNone); |
|
821 { |
|
822 const QString exp = XQConversions::s60DescToQString(expectedIconFileName); |
|
823 const QString act = |
|
824 XQConversions::s60DescToQString( |
|
825 widgetDescriptor->GetIconUri()); |
|
826 QCOMPARE(exp, act); |
|
827 } |
|
828 |
|
829 RBuf expectedIconSkinId; |
|
830 RBufGuard expectedIconSkinIdGuard(&expectedIconSkinId); |
|
831 |
|
832 _LIT8( KIconSkinId, "skin_id" ); |
|
833 |
|
834 TRAP(err, |
|
835 RXmlEngDOMImplementation domImpl; |
|
836 CleanupClosePushL(domImpl); |
|
837 domImpl.OpenL(); |
|
838 RXmlEngDocument doc; |
|
839 CleanupClosePushL(doc); |
|
840 doc.OpenL(domImpl); |
|
841 |
|
842 TXmlEngElement element = |
|
843 doc.CreateDocumentElementL(KIcon()); |
|
844 element.AddTextL(KIconSkinId()); |
|
845 |
|
846 parser->ParseIconL(element, KWidgetPackageId(), widgetDescriptor.data(), drive); |
|
847 CleanupStack::PopAndDestroy(&doc); |
|
848 CleanupStack::PopAndDestroy(&domImpl); |
|
849 ); |
|
850 |
|
851 QCOMPARE(err, KErrNone); |
|
852 |
|
853 TRAP(err, |
|
854 expectedIconSkinId.Assign( |
|
855 CnvUtfConverter::ConvertToUnicodeFromUtf8L(KIconSkinId())); |
|
856 ); |
|
857 QCOMPARE(err, KErrNone); |
|
858 { |
|
859 const QString exp = XQConversions::s60DescToQString(expectedIconSkinId); |
|
860 const QString act = |
|
861 XQConversions::s60DescToQString( |
|
862 widgetDescriptor->GetIconUri()); |
|
863 |
|
864 QCOMPARE(exp, act); |
|
865 } |
|
866 |
|
867 RBuf8 veryLongAttributeValue; |
|
868 RBuf8Guard veryLongAttributeValueGuard(&veryLongAttributeValue); |
|
869 veryLongAttributeValue.CreateL(KCaMaxAttrValueLen + 1); |
|
870 |
|
871 for (int i = KCaMaxAttrValueLen; i >= 0 ; --i) |
|
872 { |
|
873 veryLongAttributeValue.Append(_L8("a")); |
|
874 } |
|
875 |
|
876 TRAP(err, |
|
877 RXmlEngDOMImplementation domImpl; |
|
878 CleanupClosePushL(domImpl); |
|
879 domImpl.OpenL(); |
|
880 RXmlEngDocument doc; |
|
881 CleanupClosePushL(doc); |
|
882 doc.OpenL(domImpl); |
|
883 |
|
884 TXmlEngElement element = |
|
885 doc.CreateDocumentElementL(KIcon()); |
|
886 element.AddTextL(veryLongAttributeValue); |
|
887 |
|
888 parser->ParseIconL(element, KWidgetPackageId(), widgetDescriptor.data(), drive ); |
|
889 CleanupStack::PopAndDestroy(&doc); |
|
890 CleanupStack::PopAndDestroy(&domImpl); |
|
891 ); |
|
892 |
|
893 QCOMPARE(err, KErrNone); |
|
894 |
|
895 { |
|
896 QCOMPARE(widgetDescriptor->GetIconUri().Length(), |
|
897 KCaMaxAttrValueLen + 1); |
|
898 } |
|
899 |
|
900 TRAP(err, |
|
901 RXmlEngDOMImplementation domImpl; |
|
902 CleanupClosePushL(domImpl); |
|
903 domImpl.OpenL(); |
|
904 RXmlEngDocument doc; |
|
905 CleanupClosePushL(doc); |
|
906 doc.OpenL(domImpl); |
|
907 |
|
908 TXmlEngElement element = |
|
909 doc.CreateDocumentElementL(KIcon()); |
|
910 element.AddTextL(KNullDesC8); |
|
911 |
|
912 parser->ParseIconL(element, KWidgetPackageId(), widgetDescriptor.data(), drive ); |
|
913 CleanupStack::PopAndDestroy(&doc); |
|
914 CleanupStack::PopAndDestroy(&domImpl); |
|
915 ); |
|
916 |
|
917 QCOMPARE(err, KErrNone); |
|
918 { |
|
919 const QString exp = XQConversions::s60DescToQString(KNullDesC);; |
|
920 const QString act = XQConversions::s60DescToQString( |
|
921 widgetDescriptor->GetIconUri()); |
|
922 QCOMPARE(exp, act); |
|
923 } |
|
924 } |
|
925 |
|
926 void T_CaWidgetScanner::testCloneWidgetDescriptionL() |
|
927 { |
|
928 QScopedPointer<CCaWidgetDescription> descriptionA; |
|
929 QT_TRAP_THROWING(descriptionA.reset(CCaWidgetDescription::NewL())); |
|
930 QScopedPointer<CCaWidgetDescription> descriptionB( |
|
931 descriptionA->CloneL()); |
|
932 |
|
933 QVERIFY(descriptionA->Compare(*descriptionB) |
|
934 != static_cast<TInt>(EFalse)); |
|
935 |
|
936 _LIT( KTestDescription, "GetDescription()" ); |
|
937 |
|
938 QT_TRAP_THROWING( |
|
939 descriptionA->SetDescriptionL( KTestDescription ) |
|
940 ) |
|
941 |
|
942 QVERIFY(descriptionA->Compare(*descriptionB) |
|
943 == static_cast<TInt>(EFalse)); |
|
944 |
|
945 QScopedPointer<CCaWidgetDescription> descriptionC( |
|
946 descriptionA->CloneL()); |
|
947 |
|
948 QVERIFY(descriptionA->Compare(*descriptionC) |
|
949 != static_cast<TInt>(EFalse)); |
|
950 |
|
951 QVERIFY(descriptionA->GetDescription().Compare( KTestDescription ) == 0); |
|
952 } |
|
953 |
|
954 // --------------------------------------------------------------------------- |
|
955 // |
|
956 // --------------------------------------------------------------------------- |
|
957 // |
|
958 TInt T_CaWidgetScanner::AppendMmcIdL(const TDesC& aText) |
|
959 { |
|
960 //get mmc id |
|
961 RBuf mmcId; |
|
962 mmcId.CleanupClosePushL(); |
|
963 mmcId.CreateL(_L("mass_storage")); |
|
964 |
|
965 //append mmc id to the entry |
|
966 CCaInnerQuery* query = CCaInnerQuery::NewLC(); |
|
967 CDesC16ArrayFlat* widgetType = new ( ELeave ) CDesC16ArrayFlat( |
|
968 KGranularityOne ); |
|
969 CleanupStack::PushL( widgetType ); |
|
970 widgetType->AppendL( KCaTypeWidget ); |
|
971 query->SetEntryTypeNames( widgetType );//transfers ownership to query |
|
972 CleanupStack::Pop( widgetType ); |
|
973 |
|
974 RPointerArray<CCaInnerEntry> entries; |
|
975 CleanupResetAndDestroyPushL( entries ); |
|
976 iStorage->GetEntriesL( query, entries ); |
|
977 TInt id(0); |
|
978 for( TInt i = 0; i < entries.Count(); i++ ) |
|
979 { |
|
980 if(entries[i]->GetText().Compare(aText)==0) |
|
981 { |
|
982 entries[i]->AddAttributeL(KCaAttrMmcId, mmcId); |
|
983 id = entries[i]->GetId(); |
|
984 iStorage->AddL(entries[i]); |
|
985 break; |
|
986 } |
|
987 } |
|
988 CleanupStack::PopAndDestroy( &entries ); |
|
989 CleanupStack::PopAndDestroy( query ); |
|
990 CleanupStack::PopAndDestroy( &mmcId ); |
|
991 return id; |
|
992 } |
|
993 |
|
994 // --------------------------------------------------------------------------- |
|
995 // |
|
996 // --------------------------------------------------------------------------- |
|
997 // |
|
998 TBool T_CaWidgetScanner::MmcAttributeSetL(TInt aId) |
|
999 { |
|
1000 TBool result(EFalse); |
|
1001 CCaInnerQuery* query = CCaInnerQuery::NewLC(); |
|
1002 RArray<TInt> ids; |
|
1003 CleanupClosePushL(ids); |
|
1004 ids.AppendL(aId); |
|
1005 query->SetIdsL(ids); |
|
1006 CleanupStack::PopAndDestroy(&ids); |
|
1007 RPointerArray<CCaInnerEntry> entries; |
|
1008 CleanupResetAndDestroyPushL( entries ); |
|
1009 iStorage->GetEntriesL( query, entries ); |
|
1010 if (entries.Count() == 1) |
|
1011 { |
|
1012 TPtrC temp(KNullDesC); |
|
1013 result = entries[0]->FindAttribute(KCaAttrMmcId, temp); |
|
1014 } |
|
1015 CleanupStack::PopAndDestroy( &entries ); |
|
1016 CleanupStack::PopAndDestroy( query ); |
|
1017 |
|
1018 return result; |
|
1019 } |
|
1020 |
|
1021 |
|
1022 |
|
1023 |
|
1024 |
|
1025 QTEST_MAIN(T_CaWidgetScanner); |