|
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 "javastorage.h" |
|
24 #include "javastorageexception.h" |
|
25 #include "javastoragenames.h" |
|
26 #include "javauid.h" |
|
27 #include "javasymbianoslayer.h" |
|
28 |
|
29 #include "storagetestutils.h" |
|
30 #include "javaregistry.h" |
|
31 #include "javaregistryentry.h" |
|
32 #include "logger.h" |
|
33 #include "minstalledappsregistry.h" |
|
34 |
|
35 using namespace std; |
|
36 using namespace Java; |
|
37 using namespace java::storage; |
|
38 using namespace java::util; |
|
39 |
|
40 TEST_GROUP(TestInstalledAppsRegistry) |
|
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 CInstalledAppsRegistry::InstalledUidsL(TUid) method. |
|
73 * 1. Test no UIDs in registry. |
|
74 * 2. Test one application in registry. One suite and one app. |
|
75 * 3. Test two MIDlets within same Suite. |
|
76 * 4. Test two suites and MIDlets. |
|
77 */ |
|
78 TEST(TestInstalledAppsRegistry, TestInstalledUidsL) |
|
79 { |
|
80 LOG(EJavaStorage, EInfo, "+TestInstalledUidsL"); |
|
81 MInstalledAppsRegistry* appsRegistry = MInstalledAppsRegistry::CreateL(); |
|
82 CleanupReleasePushL(*appsRegistry); |
|
83 |
|
84 // 1. Test no UIDs in registry. |
|
85 RArray<TUid> uids; |
|
86 appsRegistry->InstalledUidsL(uids); |
|
87 CHECK(uids.Count() == 0); |
|
88 |
|
89 // 2. Test one application in registry. One suite and one app. |
|
90 JavaStorageApplicationEntry_t populateEntry; |
|
91 JavaStorageEntry attr; |
|
92 |
|
93 Uid suiteUid1(L"[e1111111]"); |
|
94 attr.setEntry(PACKAGE_ID, suiteUid1.toString()); |
|
95 populateEntry.insert(attr); |
|
96 |
|
97 Uid midletUid1(L"[e2222222]"); |
|
98 |
|
99 attr.setEntry(ID, midletUid1.toString()); |
|
100 populateEntry.insert(attr); |
|
101 |
|
102 string tableName = APPLICATION_TABLE; |
|
103 |
|
104 js->open(); |
|
105 js->startTransaction(); |
|
106 CHECK(jtu->populate(*js, tableName, populateEntry)); |
|
107 |
|
108 JavaStorageApplicationEntry_t suite1; |
|
109 attr.setEntry(PACKAGE_NAME, L"TestMIDletByUidL"); |
|
110 suite1.insert(attr); |
|
111 |
|
112 attr.setEntry(ID, suiteUid1.toString()); |
|
113 suite1.insert(attr); |
|
114 |
|
115 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
116 suite1.insert(attr); |
|
117 |
|
118 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
119 js->commitTransaction(); |
|
120 |
|
121 appsRegistry->InstalledUidsL(uids); |
|
122 CHECK(uids.Count() == 2); |
|
123 |
|
124 TUid suiteUid; |
|
125 uidToTUid(suiteUid1, suiteUid); |
|
126 |
|
127 CHECK(uids.Find(suiteUid) != KErrNotFound); |
|
128 |
|
129 TUid midletUid; |
|
130 uidToTUid(midletUid1, midletUid); |
|
131 |
|
132 CHECK(uids.Find(midletUid) != KErrNotFound); |
|
133 |
|
134 uids.Reset(); |
|
135 |
|
136 // 3. Two MIDlets within same Suite. |
|
137 JavaStorageApplicationEntry_t populateEntry2; |
|
138 |
|
139 attr.setEntry(PACKAGE_ID, suiteUid1.toString()); |
|
140 populateEntry2.insert(attr); |
|
141 |
|
142 Uid midletUid2(L"[e1111112]"); |
|
143 |
|
144 attr.setEntry(ID, midletUid2.toString()); |
|
145 populateEntry2.insert(attr); |
|
146 |
|
147 js->startTransaction(); |
|
148 CHECK(jtu->populate(*js, tableName, populateEntry2)); |
|
149 js->commitTransaction(); |
|
150 |
|
151 appsRegistry->InstalledUidsL(uids); |
|
152 CHECK(uids.Count() == 3); |
|
153 |
|
154 uidToTUid(suiteUid1, suiteUid); |
|
155 CHECK(uids.Find(suiteUid) != KErrNotFound); |
|
156 |
|
157 uidToTUid(midletUid1, midletUid); |
|
158 CHECK(uids.Find(midletUid) != KErrNotFound); |
|
159 |
|
160 uidToTUid(midletUid2, midletUid); |
|
161 CHECK(uids.Find(midletUid) != KErrNotFound); |
|
162 |
|
163 uids.Reset(); |
|
164 |
|
165 // 4. Two suites and MIDlets. |
|
166 JavaStorageApplicationEntry_t populateEntry3; |
|
167 |
|
168 Uid suiteUid2(L"[e1111113]"); |
|
169 attr.setEntry(PACKAGE_ID, suiteUid2.toString()); |
|
170 populateEntry3.insert(attr); |
|
171 |
|
172 Uid midletUid3(L"[e2222223]"); |
|
173 |
|
174 attr.setEntry(ID, midletUid3.toString()); |
|
175 populateEntry3.insert(attr); |
|
176 |
|
177 js->startTransaction(); |
|
178 CHECK(jtu->populate(*js, tableName, populateEntry3)); |
|
179 |
|
180 JavaStorageApplicationEntry_t suite2; |
|
181 attr.setEntry(PACKAGE_NAME, L"TestMIDletByUidL"); |
|
182 suite2.insert(attr); |
|
183 |
|
184 attr.setEntry(ID, suiteUid2.toString()); |
|
185 suite2.insert(attr); |
|
186 |
|
187 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
188 suite2.insert(attr); |
|
189 |
|
190 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite2)); |
|
191 |
|
192 js->commitTransaction(); |
|
193 |
|
194 appsRegistry->InstalledUidsL(uids); |
|
195 CHECK(uids.Count() == 5); |
|
196 |
|
197 uidToTUid(suiteUid1, suiteUid); |
|
198 CHECK(uids.Find(suiteUid) != KErrNotFound); |
|
199 uidToTUid(suiteUid2, suiteUid); |
|
200 CHECK(uids.Find(suiteUid) != KErrNotFound); |
|
201 |
|
202 uidToTUid(midletUid1, midletUid); |
|
203 CHECK(uids.Find(midletUid) != KErrNotFound); |
|
204 uidToTUid(midletUid2, midletUid); |
|
205 CHECK(uids.Find(midletUid) != KErrNotFound); |
|
206 uidToTUid(midletUid3, midletUid); |
|
207 CHECK(uids.Find(midletUid) != KErrNotFound); |
|
208 |
|
209 uids.Reset(); |
|
210 |
|
211 CHECK(jtu->remove(*js, tableName, populateEntry)); |
|
212 CHECK(jtu->remove(*js, tableName, populateEntry2)); |
|
213 CHECK(jtu->remove(*js, tableName, populateEntry3)); |
|
214 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
215 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite2)); |
|
216 |
|
217 js->close(); |
|
218 |
|
219 CleanupStack::PopAndDestroy(appsRegistry); |
|
220 LOG(EJavaStorage, EInfo, "-TestInstalledUidsL"); |
|
221 } |
|
222 |
|
223 /** |
|
224 * Test CInstalledAppsRegistry::EntryPresentL(TUid) method. |
|
225 * 1. Test no UID in registry. |
|
226 * 2. Test no matching UID on registry. |
|
227 * 3. Test suite UID found. |
|
228 * 4. Test mIDlet UID found. |
|
229 * 5. Test query twice. |
|
230 * 6. Test query with TUid::Null(). Leaves KErrArgument. |
|
231 */ |
|
232 TEST(TestInstalledAppsRegistry, TestEntryPresentL) |
|
233 { |
|
234 LOG(EJavaStorage, EInfo, "+TestEntryPresentL"); |
|
235 |
|
236 MInstalledAppsRegistry* appsRegistry = MInstalledAppsRegistry::CreateL(); |
|
237 CleanupReleasePushL(*appsRegistry); |
|
238 |
|
239 TUid uid = TUid::Uid(3777185127); // e1234567 |
|
240 |
|
241 // 1. No UID in registry |
|
242 TBool exists = appsRegistry->EntryPresentL(uid); |
|
243 CHECK(false == exists); |
|
244 |
|
245 // 2. No matching UID on registry. |
|
246 JavaStorageApplicationEntry_t populateEntry; |
|
247 JavaStorageEntry attr; |
|
248 |
|
249 attr.setEntry(PACKAGE_ID, L"[e1234577]"); |
|
250 populateEntry.insert(attr); |
|
251 |
|
252 Uid entryUid(L"[e1234588]"); |
|
253 |
|
254 attr.setEntry(ID, entryUid.toString()); |
|
255 populateEntry.insert(attr); |
|
256 |
|
257 string tableName = APPLICATION_TABLE; |
|
258 |
|
259 js->open(); |
|
260 js->startTransaction(); |
|
261 CHECK(jtu->populate(*js, tableName, populateEntry)); |
|
262 |
|
263 JavaStorageApplicationEntry_t packageEntry; |
|
264 attr.setEntry(PACKAGE_NAME, L"MySuite"); |
|
265 packageEntry.insert(attr); |
|
266 |
|
267 Uid entryUid2(L"[e1234577]"); |
|
268 attr.setEntry(ID, entryUid2.toString()); |
|
269 packageEntry.insert(attr); |
|
270 |
|
271 tableName = APPLICATION_PACKAGE_TABLE; |
|
272 |
|
273 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
274 packageEntry.insert(attr); |
|
275 |
|
276 CHECK(jtu->populate(*js, tableName, packageEntry)); |
|
277 js->commitTransaction(); |
|
278 |
|
279 exists = appsRegistry->EntryPresentL(uid); |
|
280 CHECK(false == exists); |
|
281 |
|
282 // 3. Suite UID found. |
|
283 uid = TUid::Uid(3777185143); // E1234577 aka suiteUID |
|
284 |
|
285 exists = appsRegistry->EntryPresentL(uid); |
|
286 CHECK(true == exists); |
|
287 |
|
288 // 4. MIDlet UID found. |
|
289 uid = TUid::Uid(3777185160); // E1234588 aka midletUID |
|
290 |
|
291 exists = appsRegistry->EntryPresentL(uid); |
|
292 CHECK(true == exists); |
|
293 |
|
294 // 5. Query twice. This is second query |
|
295 exists = appsRegistry->EntryPresentL(uid); |
|
296 CHECK(true == exists); |
|
297 |
|
298 // 6. Query with TUid::Null() |
|
299 uid = TUid::Null(); |
|
300 |
|
301 TRAPD(err, exists = appsRegistry->EntryPresentL(uid)); |
|
302 CHECK(KErrArgument == err); |
|
303 |
|
304 // Clean |
|
305 js->startTransaction(); |
|
306 CHECK(jtu->remove(*js, APPLICATION_TABLE, populateEntry)); |
|
307 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, packageEntry)); |
|
308 |
|
309 js->commitTransaction(); |
|
310 js->close(); |
|
311 |
|
312 CleanupStack::PopAndDestroy(appsRegistry); |
|
313 LOG(EJavaStorage, EInfo, "-TestEntryPresentL"); |
|
314 } |
|
315 |
|
316 /** |
|
317 * Test CInstalledAppsRegistry::EntryL(TUid) method. |
|
318 * 1. Test no UID in registry. |
|
319 * 2. Test no matching UID on registry. |
|
320 * 3. Test suite UID found. |
|
321 * 4. Test MIDlet UID found. |
|
322 * 5. Test query twice. |
|
323 * 6. Test query with TUid::Null(). Leaves KErrArgument. |
|
324 */ |
|
325 TEST(TestInstalledAppsRegistry, TestEntryL) |
|
326 { |
|
327 LOG(EJavaStorage, EInfo, "+TestEntryL"); |
|
328 |
|
329 MInstalledAppsRegistry* appsRegistry = MInstalledAppsRegistry::CreateL(); |
|
330 CleanupReleasePushL(*appsRegistry); |
|
331 TUid uid = TUid::Uid(3777185127); // e1234567 |
|
332 |
|
333 // 1. No UID in registry |
|
334 MInstalledAppsRegistryEntry* entry = NULL; |
|
335 TRAPD(err, appsRegistry->EntryL(uid)); |
|
336 CHECK(KErrNotFound == err); |
|
337 |
|
338 // 2. No matching UID on registry. |
|
339 JavaStorageApplicationEntry_t populateEntry; |
|
340 JavaStorageEntry attr; |
|
341 |
|
342 attr.setEntry(PACKAGE_ID, L"[e1234577]"); |
|
343 populateEntry.insert(attr); |
|
344 |
|
345 Uid entryUid(L"[e1234588]"); |
|
346 |
|
347 attr.setEntry(ID, entryUid.toString()); |
|
348 populateEntry.insert(attr); |
|
349 |
|
350 string tableName = APPLICATION_TABLE; |
|
351 |
|
352 js->open(); |
|
353 js->startTransaction(); |
|
354 CHECK(jtu->populate(*js, tableName, populateEntry)); |
|
355 |
|
356 JavaStorageApplicationEntry_t packageEntry; |
|
357 attr.setEntry(PACKAGE_NAME, L"MySuite"); |
|
358 packageEntry.insert(attr); |
|
359 |
|
360 Uid entryUid2(L"[e1234577]"); |
|
361 attr.setEntry(ID, entryUid2.toString()); |
|
362 packageEntry.insert(attr); |
|
363 |
|
364 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
365 packageEntry.insert(attr); |
|
366 |
|
367 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, packageEntry)); |
|
368 js->commitTransaction(); |
|
369 |
|
370 TRAP(err, entry = appsRegistry->EntryL(uid)); |
|
371 CHECK(KErrNotFound == err); |
|
372 |
|
373 // 3. Suite UID found. |
|
374 uid = TUid::Uid(3777185143); // E1234577 aka suiteUID |
|
375 |
|
376 entry = appsRegistry->EntryL(uid); |
|
377 CleanupReleasePushL(*entry); |
|
378 CHECK(entry != NULL); |
|
379 CleanupStack::PopAndDestroy(entry); |
|
380 |
|
381 // 4. MIDlet UID found. |
|
382 uid = TUid::Uid(3777185160); // E1234588 aka midletUID |
|
383 |
|
384 entry = appsRegistry->EntryL(uid); |
|
385 CleanupReleasePushL(*entry); |
|
386 CHECK(entry != NULL); |
|
387 CleanupStack::PopAndDestroy(entry); |
|
388 |
|
389 // 5. Query twice. This is second query |
|
390 uid = TUid::Uid(3777185160); // E1234588 aka midletUID |
|
391 |
|
392 entry = appsRegistry->EntryL(uid); |
|
393 CleanupReleasePushL(*entry); |
|
394 CHECK(entry != NULL); |
|
395 CleanupStack::PopAndDestroy(entry); |
|
396 |
|
397 // 6. Query with TUid::Null() |
|
398 uid = TUid::Null(); |
|
399 |
|
400 TRAP(err, entry = appsRegistry->EntryL(uid)); |
|
401 CHECK(KErrArgument == err); |
|
402 |
|
403 // Clean |
|
404 js->startTransaction(); |
|
405 CHECK(jtu->remove(*js, APPLICATION_TABLE, populateEntry)); |
|
406 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, packageEntry)); |
|
407 |
|
408 js->commitTransaction(); |
|
409 js->close(); |
|
410 |
|
411 CleanupStack::PopAndDestroy(appsRegistry); |
|
412 LOG(EJavaStorage, EInfo, "-TestEntryL"); |
|
413 } |
|
414 |
|
415 /** |
|
416 * Test CInstalledAppsRegistry::EntryLC(TUid) method. |
|
417 * 1. Test no UID in registry. |
|
418 * 2. Test no matching UID on registry. |
|
419 * 3. Test suite UID found. |
|
420 * 4. Test MIDlet UID found. |
|
421 * 5. Test query twice. |
|
422 * 6. Test query with TUid::Null(). Leaves KErrArgument. |
|
423 */ |
|
424 TEST(TestInstalledAppsRegistry, TestEntryLC) |
|
425 { |
|
426 LOG(EJavaStorage, EInfo, "+TestEntryLC"); |
|
427 |
|
428 MInstalledAppsRegistry* appsRegistry = MInstalledAppsRegistry::CreateL(); |
|
429 CleanupReleasePushL(*appsRegistry); |
|
430 TUid uid = TUid::Uid(3777185127); // e1234567 |
|
431 |
|
432 // 1. No UID in registry |
|
433 MInstalledAppsRegistryEntry* entry = NULL; |
|
434 TRAPD(err, appsRegistry->EntryLC(uid)); |
|
435 CHECK(KErrNotFound == err); |
|
436 |
|
437 // 2. No matching UID on registry. |
|
438 JavaStorageApplicationEntry_t populateEntry; |
|
439 JavaStorageEntry attr; |
|
440 |
|
441 attr.setEntry(PACKAGE_ID, L"[e1234577]"); |
|
442 populateEntry.insert(attr); |
|
443 |
|
444 Uid entryUid(L"[e1234588]"); |
|
445 |
|
446 attr.setEntry(ID, entryUid.toString()); |
|
447 populateEntry.insert(attr); |
|
448 |
|
449 string tableName = APPLICATION_TABLE; |
|
450 |
|
451 js->open(); |
|
452 js->startTransaction(); |
|
453 CHECK(jtu->populate(*js, tableName, populateEntry)); |
|
454 |
|
455 JavaStorageApplicationEntry_t packageEntry; |
|
456 attr.setEntry(PACKAGE_NAME, L"MySuite"); |
|
457 packageEntry.insert(attr); |
|
458 |
|
459 Uid entryUid2(L"[e1234577]"); |
|
460 attr.setEntry(ID, entryUid2.toString()); |
|
461 packageEntry.insert(attr); |
|
462 |
|
463 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
464 packageEntry.insert(attr); |
|
465 |
|
466 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, packageEntry)); |
|
467 js->commitTransaction(); |
|
468 |
|
469 TRAP(err, entry = appsRegistry->EntryLC(uid)); |
|
470 CHECK(KErrNotFound == err); |
|
471 |
|
472 // 3. Suite UID found. |
|
473 uid = TUid::Uid(3777185143); // E1234577 aka suiteUID |
|
474 |
|
475 entry = appsRegistry->EntryLC(uid); |
|
476 CHECK(entry != NULL); |
|
477 |
|
478 CleanupStack::PopAndDestroy(entry); |
|
479 |
|
480 // 4. MIDlet UID found. |
|
481 uid = TUid::Uid(3777185160); // E1234588 aka midletUID |
|
482 |
|
483 entry = appsRegistry->EntryLC(uid); |
|
484 |
|
485 CHECK(entry != NULL); |
|
486 CleanupStack::PopAndDestroy(entry); |
|
487 |
|
488 // 5. Query twice. This is second query |
|
489 uid = TUid::Uid(3777185160); // E1234588 aka midletUID |
|
490 entry = appsRegistry->EntryLC(uid); |
|
491 CHECK(entry != NULL); |
|
492 |
|
493 CleanupStack::PopAndDestroy(entry); |
|
494 |
|
495 // 6. Query with TUid::Null() |
|
496 uid = TUid::Null(); |
|
497 |
|
498 TRAP(err, entry = appsRegistry->EntryLC(uid)); |
|
499 CHECK(KErrArgument == err); |
|
500 |
|
501 // Clean |
|
502 js->startTransaction(); |
|
503 CHECK(jtu->remove(*js, APPLICATION_TABLE, populateEntry)); |
|
504 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, packageEntry)); |
|
505 js->commitTransaction(); |
|
506 js->close(); |
|
507 |
|
508 CleanupStack::PopAndDestroy(appsRegistry); |
|
509 LOG(EJavaStorage, EInfo, "-TestEntryLC"); |
|
510 } |