|
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 #include <stdio.h> |
|
19 #include <string> |
|
20 |
|
21 #include "TestHarness.h" |
|
22 |
|
23 #include "javaregistry.h" |
|
24 #include "javaregistryapplicationentry.h" |
|
25 #include "javaregistrypackageentry.h" |
|
26 #include "javastorage.h" |
|
27 #include "javastorageexception.h" |
|
28 #include "javastoragenames.h" |
|
29 #include "javasymbianoslayer.h" |
|
30 #include "javauid.h" |
|
31 #include "logger.h" |
|
32 #include "mjavaattribute.h" |
|
33 #include "storagetestutils.h" |
|
34 |
|
35 using namespace std; |
|
36 using namespace Java; |
|
37 using namespace java::storage; |
|
38 using namespace java::util; |
|
39 |
|
40 TEST_GROUP(TestRegistryPackageEntry) |
|
41 { |
|
42 JavaStorage* js; |
|
43 JavaStorageTestUtils* jtu; |
|
44 |
|
45 TEST_SETUP() |
|
46 { |
|
47 js = JavaStorage::createInstance(); |
|
48 jtu = new JavaStorageTestUtils(); |
|
49 } |
|
50 TEST_TEARDOWN() |
|
51 { |
|
52 try |
|
53 { |
|
54 js->rollbackTransaction(); |
|
55 js->close(); |
|
56 delete js; |
|
57 js = NULL; |
|
58 } |
|
59 catch (...) |
|
60 { |
|
61 // No can do |
|
62 } |
|
63 |
|
64 delete js; |
|
65 js = 0; |
|
66 delete jtu; |
|
67 jtu = 0; |
|
68 } |
|
69 }; |
|
70 |
|
71 /** |
|
72 * Test CJavaRegistryPackageEntry::Version() method. |
|
73 * 1. Test version set. |
|
74 * 2. Test version not set. |
|
75 */ |
|
76 TEST(TestRegistryPackageEntry, TestVersion) |
|
77 { |
|
78 LOG(EJavaStorage, EInfo, "+TestVersion"); |
|
79 |
|
80 JavaStorageApplicationEntry_t midlet1; |
|
81 JavaStorageEntry attr; |
|
82 |
|
83 Uid suite1Uid(L"[e22a4577]"); |
|
84 |
|
85 attr.setEntry(PACKAGE_ID, suite1Uid.toString()); |
|
86 midlet1.insert(attr); |
|
87 |
|
88 Uid midlet1Uid(L"[e22a4588]"); |
|
89 |
|
90 attr.setEntry(ID, midlet1Uid.toString()); |
|
91 midlet1.insert(attr); |
|
92 |
|
93 js->open(); |
|
94 js->startTransaction(); |
|
95 |
|
96 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1)); |
|
97 |
|
98 JavaStorageApplicationEntry_t suite1; |
|
99 attr.setEntry(PACKAGE_NAME, L"MySuite"); |
|
100 suite1.insert(attr); |
|
101 |
|
102 wstring vendor = L"SuiteVendor"; |
|
103 attr.setEntry(VENDOR, vendor); |
|
104 suite1.insert(attr); |
|
105 |
|
106 attr.setEntry(VERSION, L"0.1"); |
|
107 suite1.insert(attr); |
|
108 |
|
109 attr.setEntry(ID, suite1Uid.toString()); |
|
110 suite1.insert(attr); |
|
111 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
112 suite1.insert(attr); |
|
113 |
|
114 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
115 |
|
116 // Session must be committed before next use of Registry otherwise |
|
117 // it is locked. |
|
118 js->commitTransaction(); |
|
119 |
|
120 auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL()); |
|
121 |
|
122 // 2. Application suite uid. |
|
123 TUid suiteUid; |
|
124 uidToTUid(suite1Uid, suiteUid); |
|
125 |
|
126 CJavaRegistryPackageEntry* entry = |
|
127 (CJavaRegistryPackageEntry*) registry->RegistryEntryL(suiteUid); |
|
128 CHECK(entry != NULL); |
|
129 |
|
130 TAppVersion appVersion = entry->Version(); |
|
131 TAppVersion refVersion(0, 1, 0); |
|
132 |
|
133 CHECK(appVersion.iMajor == refVersion.iMajor); |
|
134 CHECK(appVersion.iMinor == refVersion.iMinor); |
|
135 CHECK(appVersion.iBuild == refVersion.iBuild); |
|
136 |
|
137 delete entry; |
|
138 entry = NULL; |
|
139 |
|
140 Uid suite2Uid(L"[e22b4577]"); |
|
141 |
|
142 JavaStorageApplicationEntry_t suite2; |
|
143 attr.setEntry(PACKAGE_NAME, L"MySuite2"); |
|
144 suite2.insert(attr); |
|
145 |
|
146 attr.setEntry(VENDOR, L"Inc. inc."); |
|
147 suite2.insert(attr); |
|
148 |
|
149 attr.setEntry(ID, suite2Uid.toString()); |
|
150 suite2.insert(attr); |
|
151 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
152 suite2.insert(attr); |
|
153 |
|
154 JavaStorageApplicationEntry_t midlet2; |
|
155 |
|
156 attr.setEntry(PACKAGE_ID, suite2Uid.toString()); |
|
157 midlet2.insert(attr); |
|
158 |
|
159 Uid midlet2Uid(L"[e22b4588]"); |
|
160 |
|
161 attr.setEntry(ID, midlet2Uid.toString()); |
|
162 midlet2.insert(attr); |
|
163 |
|
164 js->startTransaction(); |
|
165 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet2)); |
|
166 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite2)); |
|
167 js->commitTransaction(); |
|
168 |
|
169 uidToTUid(suite2Uid, suiteUid); |
|
170 |
|
171 // 2. Test version not set. |
|
172 entry = |
|
173 (CJavaRegistryPackageEntry*) registry->RegistryEntryL(suiteUid); |
|
174 CHECK(entry != NULL); |
|
175 |
|
176 appVersion = entry->Version(); |
|
177 TAppVersion refVersion2(0, 0, 0); |
|
178 |
|
179 CHECK(appVersion.iMajor == refVersion2.iMajor); |
|
180 CHECK(appVersion.iMinor == refVersion2.iMinor); |
|
181 CHECK(appVersion.iBuild == refVersion2.iBuild); |
|
182 |
|
183 delete entry; |
|
184 entry = NULL; |
|
185 |
|
186 // Clean |
|
187 js->startTransaction(); |
|
188 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1)); |
|
189 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet2)); |
|
190 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
191 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite2)); |
|
192 js->commitTransaction(); |
|
193 js->close(); |
|
194 LOG(EJavaStorage, EInfo, "-TestVersion"); |
|
195 } |
|
196 |
|
197 /** |
|
198 * Test CJavaRegistryPackageEntry::Version() method. |
|
199 * 1. Test version set. |
|
200 * 2. Test version not set. |
|
201 */ |
|
202 TEST(TestRegistryPackageEntry, TestVendor) |
|
203 { |
|
204 LOG(EJavaStorage, EInfo, "+TestVendor"); |
|
205 JavaStorageApplicationEntry_t midlet1; |
|
206 JavaStorageEntry attr; |
|
207 |
|
208 Uid suite1Uid(L"[e22ab577]"); |
|
209 |
|
210 attr.setEntry(PACKAGE_ID, suite1Uid.toString()); |
|
211 midlet1.insert(attr); |
|
212 |
|
213 Uid midlet1Uid(L"[e22ab588]"); |
|
214 |
|
215 attr.setEntry(ID, midlet1Uid.toString()); |
|
216 midlet1.insert(attr); |
|
217 |
|
218 js->open(); |
|
219 js->startTransaction(); |
|
220 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1)); |
|
221 |
|
222 JavaStorageApplicationEntry_t suite1; |
|
223 attr.setEntry(PACKAGE_NAME, L"MySuite"); |
|
224 suite1.insert(attr); |
|
225 |
|
226 wstring vendor = L"SuiteVendor"; |
|
227 attr.setEntry(VENDOR, vendor); |
|
228 suite1.insert(attr); |
|
229 |
|
230 attr.setEntry(VERSION, L"0.1"); |
|
231 suite1.insert(attr); |
|
232 |
|
233 attr.setEntry(ID, suite1Uid.toString()); |
|
234 suite1.insert(attr); |
|
235 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
236 suite1.insert(attr); |
|
237 |
|
238 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
239 js->commitTransaction(); |
|
240 |
|
241 auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL()); |
|
242 |
|
243 // 2. Application suite uid. |
|
244 TUid suiteUid; |
|
245 uidToTUid(suite1Uid, suiteUid); |
|
246 |
|
247 CJavaRegistryPackageEntry* entry = |
|
248 (CJavaRegistryPackageEntry*) registry->RegistryEntryL(suiteUid); |
|
249 CHECK(entry != NULL); |
|
250 |
|
251 _LIT(KSuiteVendor, "SuiteVendor"); |
|
252 CHECK(entry->Vendor() == KSuiteVendor); |
|
253 |
|
254 delete entry; |
|
255 entry = NULL; |
|
256 |
|
257 Uid suite2Uid(L"[e22bb577]"); |
|
258 |
|
259 JavaStorageApplicationEntry_t suite2; |
|
260 attr.setEntry(PACKAGE_NAME, L"MySuite2"); |
|
261 suite2.insert(attr); |
|
262 |
|
263 attr.setEntry(ID, suite2Uid.toString()); |
|
264 suite2.insert(attr); |
|
265 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
266 suite2.insert(attr); |
|
267 |
|
268 JavaStorageApplicationEntry_t midlet2; |
|
269 |
|
270 attr.setEntry(PACKAGE_ID, suite2Uid.toString()); |
|
271 midlet2.insert(attr); |
|
272 |
|
273 Uid midlet2Uid(L"[e22bb588]"); |
|
274 |
|
275 attr.setEntry(ID, midlet2Uid.toString()); |
|
276 midlet2.insert(attr); |
|
277 |
|
278 js->startTransaction(); |
|
279 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet2)); |
|
280 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite2)); |
|
281 js->commitTransaction(); |
|
282 |
|
283 uidToTUid(suite2Uid, suiteUid); |
|
284 |
|
285 // 2. Test version not set. |
|
286 entry = |
|
287 (CJavaRegistryPackageEntry*) registry->RegistryEntryL(suiteUid); |
|
288 CHECK(entry != NULL); |
|
289 |
|
290 CHECK(entry->Vendor() == KNullDesC); |
|
291 |
|
292 delete entry; |
|
293 entry = NULL; |
|
294 |
|
295 // Clean |
|
296 js->startTransaction(); |
|
297 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1)); |
|
298 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet2)); |
|
299 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
300 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite2)); |
|
301 js->commitTransaction(); |
|
302 js->close(); |
|
303 |
|
304 LOG(EJavaStorage, EInfo, "-TestVendor"); |
|
305 } |
|
306 |
|
307 // Currently not supported |
|
308 /* |
|
309 TEST(TestRegistryPackageEntry, TestIsUninstallable) |
|
310 { |
|
311 FAIL("NOT IMPLEMENTED!"); |
|
312 }*/ |
|
313 |
|
314 /** |
|
315 * Test CJavaRegistryPackageEntry::GetEmbeddedEntries() method. |
|
316 * 1. Test suite contains one application. |
|
317 * 2. Test suite contains three applications. |
|
318 * 3. Test two suites are not interfering each others. |
|
319 */ |
|
320 TEST(TestRegistryPackageEntry, TestGetEmbeddedEntries) |
|
321 { |
|
322 LOG(EJavaStorage, EInfo, "+TestGetEmbeddedEntries"); |
|
323 |
|
324 JavaStorageApplicationEntry_t midlet1; |
|
325 JavaStorageEntry attr; |
|
326 |
|
327 Uid suite1Uid(L"[e22ba577]"); |
|
328 |
|
329 attr.setEntry(PACKAGE_ID, suite1Uid.toString()); |
|
330 midlet1.insert(attr); |
|
331 |
|
332 Uid midlet1Uid(L"[e22ba588]"); |
|
333 |
|
334 attr.setEntry(ID, midlet1Uid.toString()); |
|
335 midlet1.insert(attr); |
|
336 |
|
337 JavaStorageApplicationEntry_t suite1; |
|
338 attr.setEntry(PACKAGE_NAME, L"MySuite"); |
|
339 suite1.insert(attr); |
|
340 |
|
341 attr.setEntry(ID, suite1Uid.toString()); |
|
342 suite1.insert(attr); |
|
343 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
344 suite1.insert(attr); |
|
345 |
|
346 js->open(); |
|
347 js->startTransaction(); |
|
348 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1)); |
|
349 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
350 js->commitTransaction(); |
|
351 |
|
352 // 2. Test suite contains one application. |
|
353 TUid suiteUid; |
|
354 uidToTUid(suite1Uid, suiteUid); |
|
355 |
|
356 auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL()); |
|
357 CJavaRegistryPackageEntry* entry = |
|
358 (CJavaRegistryPackageEntry*) registry->RegistryEntryL(suiteUid); |
|
359 CHECK(entry != NULL); |
|
360 |
|
361 RArray<TUid> embeddedUids; |
|
362 entry->GetEmbeddedEntries(embeddedUids); |
|
363 CHECK(embeddedUids.Count() == 1); |
|
364 |
|
365 delete entry; |
|
366 entry = NULL; |
|
367 embeddedUids.Reset(); |
|
368 |
|
369 Uid suite3Uid(L"[e22baac7]"); |
|
370 JavaStorageApplicationEntry_t suite3; |
|
371 attr.setEntry(PACKAGE_NAME, L"MySuite3"); |
|
372 suite3.insert(attr); |
|
373 |
|
374 attr.setEntry(ID, suite3Uid.toString()); |
|
375 suite3.insert(attr); |
|
376 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
377 suite3.insert(attr); |
|
378 |
|
379 JavaStorageApplicationEntry_t midlet2; |
|
380 |
|
381 attr.setEntry(PACKAGE_ID, suite3Uid.toString()); |
|
382 midlet2.insert(attr); |
|
383 |
|
384 Uid midlet2Uid(L"[e22bacc8]"); |
|
385 |
|
386 attr.setEntry(ID, midlet2Uid.toString()); |
|
387 midlet2.insert(attr); |
|
388 |
|
389 JavaStorageApplicationEntry_t midlet3; |
|
390 |
|
391 attr.setEntry(PACKAGE_ID, suite3Uid.toString()); |
|
392 midlet3.insert(attr); |
|
393 |
|
394 Uid midlet3Uid(L"[e22baa88]"); |
|
395 |
|
396 attr.setEntry(ID, midlet3Uid.toString()); |
|
397 midlet3.insert(attr); |
|
398 |
|
399 JavaStorageApplicationEntry_t midlet4; |
|
400 |
|
401 attr.setEntry(PACKAGE_ID, suite3Uid.toString()); |
|
402 midlet4.insert(attr); |
|
403 |
|
404 Uid midlet4Uid(L"[e22baaa8]"); |
|
405 |
|
406 attr.setEntry(ID, midlet4Uid.toString()); |
|
407 midlet4.insert(attr); |
|
408 |
|
409 js->startTransaction(); |
|
410 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet2)); |
|
411 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet3)); |
|
412 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet4)); |
|
413 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite3)); |
|
414 js->commitTransaction(); |
|
415 |
|
416 uidToTUid(suite3Uid, suiteUid); |
|
417 |
|
418 // 3. Test suite contains three applications. |
|
419 entry = |
|
420 (CJavaRegistryPackageEntry*) registry->RegistryEntryL(suiteUid); |
|
421 CHECK(entry != NULL); |
|
422 |
|
423 entry->GetEmbeddedEntries(embeddedUids); |
|
424 CHECK(embeddedUids.Count() == 3); |
|
425 |
|
426 delete entry; |
|
427 entry = NULL; |
|
428 embeddedUids.Reset(); |
|
429 |
|
430 // 4. Test two suites are not interfering each others. |
|
431 // Add midlet to suite1 |
|
432 JavaStorageApplicationEntry_t midlet5; |
|
433 |
|
434 attr.setEntry(PACKAGE_ID, suite1Uid.toString()); |
|
435 midlet5.insert(attr); |
|
436 |
|
437 Uid midlet5Uid(L"[e22bac88]"); |
|
438 |
|
439 attr.setEntry(ID, midlet5Uid.toString()); |
|
440 midlet5.insert(attr); |
|
441 |
|
442 js->open(); |
|
443 js->startTransaction(); |
|
444 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet5)); |
|
445 // Session must be committed before next use of Registry otherwise |
|
446 // it is locked. |
|
447 js->commitTransaction(); |
|
448 |
|
449 entry = |
|
450 (CJavaRegistryPackageEntry*) registry->RegistryEntryL(suiteUid); |
|
451 CHECK(entry != NULL); |
|
452 |
|
453 entry->GetEmbeddedEntries(embeddedUids); |
|
454 CHECK(embeddedUids.Count() == 3); |
|
455 |
|
456 delete entry; |
|
457 entry = NULL; |
|
458 embeddedUids.Reset(); |
|
459 |
|
460 // Clean |
|
461 js->startTransaction(); |
|
462 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1)); |
|
463 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet2)); |
|
464 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet3)); |
|
465 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet4)); |
|
466 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet5)); |
|
467 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
468 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite3)); |
|
469 js->commitTransaction(); |
|
470 js->close(); |
|
471 LOG(EJavaStorage, EInfo, "-TestGetEmbeddedEntries"); |
|
472 } |
|
473 /** |
|
474 * Test CJavaRegistryPackageEntry::NumberOfEmbeddedEntries() method. |
|
475 * 1. Test suite contains one application. |
|
476 * 2. Test suite contains three applications. |
|
477 * 3. Test two suites are not interfering each others. |
|
478 */ |
|
479 TEST(TestRegistryPackageEntry, TestNumberOfEmbeddedEntries) |
|
480 { |
|
481 LOG(EJavaStorage, EInfo, "+TestNumberOfEmbeddedEntries"); |
|
482 JavaStorageApplicationEntry_t midlet1; |
|
483 JavaStorageEntry attr; |
|
484 |
|
485 Uid suite1Uid(L"[e22ba577]"); |
|
486 |
|
487 attr.setEntry(PACKAGE_ID, suite1Uid.toString()); |
|
488 midlet1.insert(attr); |
|
489 |
|
490 Uid midlet1Uid(L"[e22ba588]"); |
|
491 |
|
492 attr.setEntry(ID, midlet1Uid.toString()); |
|
493 midlet1.insert(attr); |
|
494 |
|
495 JavaStorageApplicationEntry_t suite1; |
|
496 attr.setEntry(PACKAGE_NAME, L"MySuite"); |
|
497 suite1.insert(attr); |
|
498 |
|
499 attr.setEntry(ID, suite1Uid.toString()); |
|
500 suite1.insert(attr); |
|
501 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
502 suite1.insert(attr); |
|
503 |
|
504 js->open(); |
|
505 js->startTransaction(); |
|
506 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1)); |
|
507 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
508 js->commitTransaction(); |
|
509 |
|
510 // 1. Test suite contains one application. |
|
511 TUid suiteUid; |
|
512 uidToTUid(suite1Uid, suiteUid); |
|
513 |
|
514 auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL()); |
|
515 CJavaRegistryPackageEntry* entry = |
|
516 (CJavaRegistryPackageEntry*) registry->RegistryEntryL(suiteUid); |
|
517 |
|
518 CHECK(entry != NULL); |
|
519 CHECK(entry->NumberOfEmbeddedEntries() == 1); |
|
520 |
|
521 delete entry; |
|
522 entry = NULL; |
|
523 |
|
524 Uid suite3Uid(L"[e22baac7]"); |
|
525 JavaStorageApplicationEntry_t suite3; |
|
526 attr.setEntry(PACKAGE_NAME, L"MySuite3"); |
|
527 suite3.insert(attr); |
|
528 |
|
529 attr.setEntry(ID, suite3Uid.toString()); |
|
530 suite3.insert(attr); |
|
531 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
532 suite3.insert(attr); |
|
533 |
|
534 JavaStorageApplicationEntry_t midlet2; |
|
535 |
|
536 attr.setEntry(PACKAGE_ID, suite3Uid.toString()); |
|
537 midlet2.insert(attr); |
|
538 |
|
539 Uid midlet2Uid(L"[e22bacc8]"); |
|
540 |
|
541 attr.setEntry(ID, midlet2Uid.toString()); |
|
542 midlet2.insert(attr); |
|
543 |
|
544 JavaStorageApplicationEntry_t midlet3; |
|
545 |
|
546 attr.setEntry(PACKAGE_ID, suite3Uid.toString()); |
|
547 midlet3.insert(attr); |
|
548 |
|
549 Uid midlet3Uid(L"[e22baa88]"); |
|
550 |
|
551 attr.setEntry(ID, midlet3Uid.toString()); |
|
552 midlet3.insert(attr); |
|
553 |
|
554 JavaStorageApplicationEntry_t midlet4; |
|
555 |
|
556 attr.setEntry(PACKAGE_ID, suite3Uid.toString()); |
|
557 midlet4.insert(attr); |
|
558 |
|
559 Uid midlet4Uid(L"[e22baaa8]"); |
|
560 |
|
561 attr.setEntry(ID, midlet4Uid.toString()); |
|
562 midlet4.insert(attr); |
|
563 |
|
564 js->startTransaction(); |
|
565 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet2)); |
|
566 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet3)); |
|
567 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet4)); |
|
568 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite3)); |
|
569 js->commitTransaction(); |
|
570 |
|
571 uidToTUid(suite3Uid, suiteUid); |
|
572 |
|
573 // 2. Test suite contains three applications. |
|
574 entry = |
|
575 (CJavaRegistryPackageEntry*) registry->RegistryEntryL(suiteUid); |
|
576 |
|
577 CHECK(entry != NULL); |
|
578 CHECK(entry->NumberOfEmbeddedEntries() == 3); |
|
579 |
|
580 delete entry; |
|
581 entry = NULL; |
|
582 |
|
583 // 3. Test two suites are not interfering each others. |
|
584 // Add midlet to suite1 |
|
585 JavaStorageApplicationEntry_t midlet5; |
|
586 |
|
587 attr.setEntry(PACKAGE_ID, suite1Uid.toString()); |
|
588 midlet5.insert(attr); |
|
589 |
|
590 Uid midlet5Uid(L"[e22bac88]"); |
|
591 |
|
592 attr.setEntry(ID, midlet5Uid.toString()); |
|
593 midlet5.insert(attr); |
|
594 |
|
595 js->startTransaction(); |
|
596 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet5)); |
|
597 js->commitTransaction(); |
|
598 |
|
599 entry = |
|
600 (CJavaRegistryPackageEntry*) registry->RegistryEntryL(suiteUid); |
|
601 |
|
602 CHECK(entry != NULL); |
|
603 CHECK(entry->NumberOfEmbeddedEntries() == 3); |
|
604 |
|
605 delete entry; |
|
606 entry = NULL; |
|
607 |
|
608 // Clean |
|
609 js->startTransaction(); |
|
610 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1)); |
|
611 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet2)); |
|
612 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet3)); |
|
613 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet4)); |
|
614 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet5)); |
|
615 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
616 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite3)); |
|
617 js->commitTransaction(); |
|
618 js->close(); |
|
619 |
|
620 LOG(EJavaStorage, EInfo, "-TestNumberOfEmbeddedEntries"); |
|
621 } |
|
622 |
|
623 /** |
|
624 * Test CJavaRegistryPackageEntry::EmbeddedEntryByUidL() method. |
|
625 * 1. Test suite contains one application. |
|
626 * 2. Test suite contains three applications. |
|
627 * 2.1 Test get first entry. |
|
628 * 2.2 Test get second entry. |
|
629 * 2.3 Test get thrird entry. |
|
630 * 3. Test get non existing Uid. |
|
631 */ |
|
632 TEST(TestRegistryPackageEntry, TestEmbeddedEntryByUidL) |
|
633 { |
|
634 LOG(EJavaStorage, EInfo, "+TestEmbeddedEntryByUidL"); |
|
635 JavaStorageApplicationEntry_t midlet1; |
|
636 JavaStorageEntry attr; |
|
637 |
|
638 Uid suite1Uid(L"[e22bac77]"); |
|
639 |
|
640 attr.setEntry(PACKAGE_ID, suite1Uid.toString()); |
|
641 midlet1.insert(attr); |
|
642 |
|
643 Uid midlet1Uid(L"[e22bac88]"); |
|
644 |
|
645 attr.setEntry(ID, midlet1Uid.toString()); |
|
646 midlet1.insert(attr); |
|
647 |
|
648 JavaStorageApplicationEntry_t suite1; |
|
649 attr.setEntry(PACKAGE_NAME, L"MySuite"); |
|
650 suite1.insert(attr); |
|
651 |
|
652 attr.setEntry(ID, suite1Uid.toString()); |
|
653 suite1.insert(attr); |
|
654 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
655 suite1.insert(attr); |
|
656 |
|
657 js->open(); |
|
658 js->startTransaction(); |
|
659 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1)); |
|
660 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
661 js->commitTransaction(); |
|
662 |
|
663 // 1. Test suite contains one application. |
|
664 TUid suiteUid; |
|
665 uidToTUid(suite1Uid, suiteUid); |
|
666 |
|
667 auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL()); |
|
668 CJavaRegistryPackageEntry* entry = |
|
669 (CJavaRegistryPackageEntry*) registry->RegistryEntryL(suiteUid); |
|
670 CHECK(entry != NULL); |
|
671 |
|
672 TUid midletUid; |
|
673 uidToTUid(midlet1Uid, midletUid); |
|
674 |
|
675 CJavaRegistryApplicationEntry* appEntry = (CJavaRegistryApplicationEntry*) |
|
676 entry->EmbeddedEntryByUidL(midletUid); |
|
677 CHECK(appEntry != NULL); |
|
678 |
|
679 // Test correct one returned. |
|
680 CHECK(appEntry->Uid() == midletUid); |
|
681 |
|
682 delete appEntry; |
|
683 appEntry = NULL; |
|
684 |
|
685 delete entry; |
|
686 entry = NULL; |
|
687 |
|
688 Uid suite3Uid(L"[e22baad7]"); |
|
689 JavaStorageApplicationEntry_t suite3; |
|
690 attr.setEntry(PACKAGE_NAME, L"MySuite3"); |
|
691 suite3.insert(attr); |
|
692 |
|
693 attr.setEntry(ID, suite3Uid.toString()); |
|
694 suite3.insert(attr); |
|
695 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
696 suite3.insert(attr); |
|
697 |
|
698 JavaStorageApplicationEntry_t midlet2; |
|
699 |
|
700 attr.setEntry(PACKAGE_ID, suite3Uid.toString()); |
|
701 midlet2.insert(attr); |
|
702 |
|
703 Uid midlet2Uid(L"[e22bacd8]"); |
|
704 |
|
705 attr.setEntry(ID, midlet2Uid.toString()); |
|
706 midlet2.insert(attr); |
|
707 |
|
708 JavaStorageApplicationEntry_t midlet3; |
|
709 |
|
710 attr.setEntry(PACKAGE_ID, suite3Uid.toString()); |
|
711 midlet3.insert(attr); |
|
712 |
|
713 Uid midlet3Uid(L"[e22baad8]"); |
|
714 |
|
715 attr.setEntry(ID, midlet3Uid.toString()); |
|
716 midlet3.insert(attr); |
|
717 |
|
718 JavaStorageApplicationEntry_t midlet4; |
|
719 |
|
720 attr.setEntry(PACKAGE_ID, suite3Uid.toString()); |
|
721 midlet4.insert(attr); |
|
722 |
|
723 Uid midlet4Uid(L"[e22cccd8]"); |
|
724 |
|
725 attr.setEntry(ID, midlet4Uid.toString()); |
|
726 midlet4.insert(attr); |
|
727 |
|
728 js->startTransaction(); |
|
729 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet2)); |
|
730 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet3)); |
|
731 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet4)); |
|
732 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite3)); |
|
733 js->commitTransaction(); |
|
734 |
|
735 uidToTUid(suite3Uid, suiteUid); |
|
736 |
|
737 // 2. Test suite contains three applications. |
|
738 entry = |
|
739 (CJavaRegistryPackageEntry*) registry->RegistryEntryL(suiteUid); |
|
740 CHECK(entry != NULL); |
|
741 |
|
742 // 2.1. Test get first entry. |
|
743 uidToTUid(midlet2Uid, midletUid); |
|
744 |
|
745 appEntry = (CJavaRegistryApplicationEntry*) |
|
746 entry->EmbeddedEntryByUidL(midletUid); |
|
747 CHECK(appEntry != NULL); |
|
748 |
|
749 // Test correct one returned. |
|
750 CHECK(appEntry->Uid() == midletUid); |
|
751 |
|
752 delete appEntry; |
|
753 appEntry = NULL; |
|
754 |
|
755 // 2.2. Test get second entry. |
|
756 uidToTUid(midlet3Uid, midletUid); |
|
757 |
|
758 appEntry = (CJavaRegistryApplicationEntry*) |
|
759 entry->EmbeddedEntryByUidL(midletUid); |
|
760 CHECK(appEntry != NULL); |
|
761 |
|
762 // Test correct one returned. |
|
763 CHECK(appEntry->Uid() == midletUid); |
|
764 |
|
765 delete appEntry; |
|
766 appEntry = NULL; |
|
767 |
|
768 // 2.3. Test get third entry. |
|
769 uidToTUid(midlet4Uid, midletUid); |
|
770 |
|
771 appEntry = (CJavaRegistryApplicationEntry*) |
|
772 entry->EmbeddedEntryByUidL(midletUid); |
|
773 CHECK(appEntry != NULL); |
|
774 |
|
775 // Test correct one returned. |
|
776 CHECK(appEntry->Uid() == midletUid); |
|
777 |
|
778 delete appEntry; |
|
779 appEntry = NULL; |
|
780 |
|
781 // 4. Test get non existing Uid. |
|
782 Uid nonExistingUid(L"[e22baddd]"); |
|
783 uidToTUid(nonExistingUid, midletUid); |
|
784 |
|
785 appEntry = (CJavaRegistryApplicationEntry*) |
|
786 entry->EmbeddedEntryByUidL(midletUid); |
|
787 CHECK(appEntry == NULL); |
|
788 |
|
789 delete entry; |
|
790 entry = NULL; |
|
791 |
|
792 // Clean |
|
793 js->startTransaction(); |
|
794 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1)); |
|
795 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet2)); |
|
796 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet3)); |
|
797 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet4)); |
|
798 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
799 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite3)); |
|
800 js->commitTransaction(); |
|
801 js->close(); |
|
802 |
|
803 LOG(EJavaStorage, EInfo, "-TestEmbeddedEntryByUidL"); |
|
804 } |
|
805 |
|
806 /** |
|
807 * Test CJavaRegistryPackageEntry::EmbeddedEntryByNumberL() method. |
|
808 * 1. Test suite contains one application. |
|
809 * 2. Test suite contains three applications. |
|
810 * 2.1 Test get first entry. |
|
811 * 2.2 Test get second entry. |
|
812 * 2.3 Test get thrird entry. |
|
813 * 3. Test negative index. |
|
814 * 4. Test index greater than embedded entries. |
|
815 * |
|
816 * NOTE: Order is not quaranteed so it might be that test case must be |
|
817 * changed to check only entry is received but not to check its parameters. |
|
818 */ |
|
819 TEST(TestRegistryPackageEntry, TestEmbeddedEntryByNumberL) |
|
820 { |
|
821 LOG(EJavaStorage, EInfo, "+TestEmbeddedEntryByNumberL"); |
|
822 JavaStorageApplicationEntry_t midlet1; |
|
823 JavaStorageEntry attr; |
|
824 |
|
825 Uid suite1Uid(L"[ed2bac77]"); |
|
826 |
|
827 attr.setEntry(PACKAGE_ID, suite1Uid.toString()); |
|
828 midlet1.insert(attr); |
|
829 |
|
830 Uid midlet1Uid(L"[ed2bac88]"); |
|
831 |
|
832 attr.setEntry(ID, midlet1Uid.toString()); |
|
833 midlet1.insert(attr); |
|
834 |
|
835 JavaStorageApplicationEntry_t suite1; |
|
836 attr.setEntry(PACKAGE_NAME, L"MySuite"); |
|
837 suite1.insert(attr); |
|
838 |
|
839 attr.setEntry(ID, suite1Uid.toString()); |
|
840 suite1.insert(attr); |
|
841 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
842 suite1.insert(attr); |
|
843 |
|
844 js->open(); |
|
845 js->startTransaction(); |
|
846 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1)); |
|
847 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
848 js->commitTransaction(); |
|
849 |
|
850 // 1. Test suite contains one application. |
|
851 TUid suiteUid; |
|
852 uidToTUid(suite1Uid, suiteUid); |
|
853 |
|
854 auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL()); |
|
855 CJavaRegistryPackageEntry* entry = |
|
856 (CJavaRegistryPackageEntry*) registry->RegistryEntryL(suiteUid); |
|
857 CHECK(entry != NULL); |
|
858 |
|
859 TUid midletUid; |
|
860 uidToTUid(midlet1Uid, midletUid); |
|
861 |
|
862 CJavaRegistryApplicationEntry* appEntry = (CJavaRegistryApplicationEntry*) |
|
863 entry->EmbeddedEntryByNumberL(0); |
|
864 CHECK(appEntry != NULL); |
|
865 |
|
866 // Test correct one returned. |
|
867 CHECK(appEntry->Uid() == midletUid); |
|
868 |
|
869 delete appEntry; |
|
870 appEntry = NULL; |
|
871 |
|
872 delete entry; |
|
873 entry = NULL; |
|
874 |
|
875 Uid suite3Uid(L"[ed2baad7]"); |
|
876 JavaStorageApplicationEntry_t suite3; |
|
877 attr.setEntry(PACKAGE_NAME, L"MySuite3"); |
|
878 suite3.insert(attr); |
|
879 |
|
880 attr.setEntry(ID, suite3Uid.toString()); |
|
881 suite3.insert(attr); |
|
882 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
883 suite3.insert(attr); |
|
884 |
|
885 JavaStorageApplicationEntry_t midlet2; |
|
886 |
|
887 attr.setEntry(PACKAGE_ID, suite3Uid.toString()); |
|
888 midlet2.insert(attr); |
|
889 |
|
890 Uid midlet2Uid(L"[ed2bacd8]"); |
|
891 |
|
892 attr.setEntry(ID, midlet2Uid.toString()); |
|
893 midlet2.insert(attr); |
|
894 |
|
895 JavaStorageApplicationEntry_t midlet3; |
|
896 |
|
897 attr.setEntry(PACKAGE_ID, suite3Uid.toString()); |
|
898 midlet3.insert(attr); |
|
899 |
|
900 Uid midlet3Uid(L"[ed2baad8]"); |
|
901 |
|
902 attr.setEntry(ID, midlet3Uid.toString()); |
|
903 midlet3.insert(attr); |
|
904 |
|
905 JavaStorageApplicationEntry_t midlet4; |
|
906 |
|
907 attr.setEntry(PACKAGE_ID, suite3Uid.toString()); |
|
908 midlet4.insert(attr); |
|
909 |
|
910 Uid midlet4Uid(L"[ed2cccd8]"); |
|
911 |
|
912 attr.setEntry(ID, midlet4Uid.toString()); |
|
913 midlet4.insert(attr); |
|
914 |
|
915 js->startTransaction(); |
|
916 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet2)); |
|
917 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet3)); |
|
918 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet4)); |
|
919 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite3)); |
|
920 js->commitTransaction(); |
|
921 |
|
922 uidToTUid(suite3Uid, suiteUid); |
|
923 |
|
924 // 2. Test suite contains three applications. |
|
925 entry = |
|
926 (CJavaRegistryPackageEntry*) registry->RegistryEntryL(suiteUid); |
|
927 CHECK(entry != NULL); |
|
928 |
|
929 // 2.1. Test get first entry. |
|
930 uidToTUid(midlet2Uid, midletUid); |
|
931 |
|
932 appEntry = (CJavaRegistryApplicationEntry*) |
|
933 entry->EmbeddedEntryByNumberL(0); |
|
934 CHECK(appEntry != NULL); |
|
935 |
|
936 // Test correct one returned. |
|
937 CHECK(appEntry->Uid() == midletUid); |
|
938 |
|
939 delete appEntry; |
|
940 appEntry = NULL; |
|
941 |
|
942 // 2.2. Test get second entry. |
|
943 uidToTUid(midlet3Uid, midletUid); |
|
944 |
|
945 appEntry = (CJavaRegistryApplicationEntry*) |
|
946 entry->EmbeddedEntryByNumberL(1); |
|
947 CHECK(appEntry != NULL); |
|
948 |
|
949 // Test correct one returned. |
|
950 CHECK(appEntry->Uid() == midletUid); |
|
951 |
|
952 delete appEntry; |
|
953 appEntry = NULL; |
|
954 |
|
955 // 2.3. Test get third entry. |
|
956 uidToTUid(midlet4Uid, midletUid); |
|
957 |
|
958 appEntry = (CJavaRegistryApplicationEntry*) |
|
959 entry->EmbeddedEntryByNumberL(2); |
|
960 CHECK(appEntry != NULL); |
|
961 |
|
962 // Test correct one returned. |
|
963 CHECK(appEntry->Uid() == midletUid); |
|
964 |
|
965 delete appEntry; |
|
966 appEntry = NULL; |
|
967 |
|
968 // 3. Test negative index. |
|
969 TRAPD(err, appEntry = (CJavaRegistryApplicationEntry*) |
|
970 entry->EmbeddedEntryByNumberL(-1)); |
|
971 CHECK(NULL == appEntry); |
|
972 |
|
973 // 4. Test index greater than embedded entries. |
|
974 appEntry = (CJavaRegistryApplicationEntry*) |
|
975 entry->EmbeddedEntryByNumberL(3); |
|
976 CHECK(appEntry == NULL); |
|
977 |
|
978 delete entry; |
|
979 entry = NULL; |
|
980 |
|
981 // Clean |
|
982 js->startTransaction(); |
|
983 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1)); |
|
984 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet2)); |
|
985 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet3)); |
|
986 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet4)); |
|
987 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
988 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite3)); |
|
989 js->commitTransaction(); |
|
990 js->close(); |
|
991 |
|
992 LOG(EJavaStorage, EInfo, "-TestEmbeddedEntryByNumberL"); |
|
993 } |