|
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 /** |
|
41 * Test JavaRegistryApplicationEntry. |
|
42 */ |
|
43 TEST_GROUP(TestRegistryApplicationEntry) |
|
44 { |
|
45 JavaStorage* js; |
|
46 JavaStorageTestUtils* jtu; |
|
47 |
|
48 TEST_SETUP() |
|
49 { |
|
50 js = JavaStorage::createInstance(); |
|
51 jtu = new JavaStorageTestUtils(); |
|
52 } |
|
53 TEST_TEARDOWN() |
|
54 { |
|
55 try |
|
56 { |
|
57 js->rollbackTransaction(); |
|
58 js->close(); |
|
59 delete js; |
|
60 js = NULL; |
|
61 } |
|
62 catch (...) |
|
63 { |
|
64 // No can do |
|
65 } |
|
66 |
|
67 delete js; |
|
68 js = 0; |
|
69 delete jtu; |
|
70 jtu = 0; |
|
71 } |
|
72 }; |
|
73 |
|
74 /** |
|
75 * Test CJavaRegistryApplicationEntry::IsStartable() method. |
|
76 * 1. Test return default value ETrue. |
|
77 */ |
|
78 TEST(TestRegistryApplicationEntry, TestIsStartable) |
|
79 { |
|
80 LOG(EJavaStorage, EInfo, "+TestIsStartable"); |
|
81 |
|
82 JavaStorageApplicationEntry_t midlet1; |
|
83 JavaStorageEntry attr; |
|
84 |
|
85 Uid suite1Uid(L"[e22a1111]"); |
|
86 |
|
87 attr.setEntry(PACKAGE_ID, suite1Uid.toString()); |
|
88 midlet1.insert(attr); |
|
89 |
|
90 Uid midlet1Uid(L"[e22a1111]"); |
|
91 |
|
92 attr.setEntry(ID, midlet1Uid.toString()); |
|
93 midlet1.insert(attr); |
|
94 |
|
95 js->open(); |
|
96 js->startTransaction(); |
|
97 |
|
98 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1)); |
|
99 |
|
100 JavaStorageApplicationEntry_t suite1; |
|
101 attr.setEntry(PACKAGE_NAME, L"MySuite"); |
|
102 suite1.insert(attr); |
|
103 |
|
104 wstring vendor = L"SuiteVendor"; |
|
105 attr.setEntry(VENDOR, vendor); |
|
106 suite1.insert(attr); |
|
107 |
|
108 attr.setEntry(VERSION, L"0.1"); |
|
109 suite1.insert(attr); |
|
110 |
|
111 attr.setEntry(ID, suite1Uid.toString()); |
|
112 suite1.insert(attr); |
|
113 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
114 suite1.insert(attr); |
|
115 |
|
116 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
117 |
|
118 // Session must be committed before next use of Registry otherwise |
|
119 // it is locked. |
|
120 js->commitTransaction(); |
|
121 |
|
122 auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL()); |
|
123 |
|
124 TUid midletUid; |
|
125 uidToTUid(midlet1Uid, midletUid); |
|
126 |
|
127 CJavaRegistryApplicationEntry* entry = |
|
128 (CJavaRegistryApplicationEntry*) registry->RegistryEntryL(midletUid); |
|
129 |
|
130 CHECK(entry != NULL); |
|
131 CHECK(entry->IsStartable() == true); |
|
132 |
|
133 delete entry; |
|
134 entry = NULL; |
|
135 |
|
136 // Clean |
|
137 js->startTransaction(); |
|
138 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1)); |
|
139 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
140 js->commitTransaction(); |
|
141 js->close(); |
|
142 |
|
143 LOG(EJavaStorage, EInfo, "-TestIsStartable"); |
|
144 } |
|
145 |
|
146 /** |
|
147 * Test CJavaRegistryApplicationEntry::IsVisible() method. |
|
148 * 1. Test return default value ETrue. |
|
149 */ |
|
150 TEST(TestRegistryApplicationEntry, TestIsVisible) |
|
151 { |
|
152 LOG(EJavaStorage, EInfo, "+TestIsVisible"); |
|
153 JavaStorageApplicationEntry_t midlet1; |
|
154 JavaStorageEntry attr; |
|
155 |
|
156 Uid suite1Uid(L"[e22a1111]"); |
|
157 |
|
158 attr.setEntry(PACKAGE_ID, suite1Uid.toString()); |
|
159 midlet1.insert(attr); |
|
160 |
|
161 Uid midlet1Uid(L"[e22a1111]"); |
|
162 |
|
163 attr.setEntry(ID, midlet1Uid.toString()); |
|
164 midlet1.insert(attr); |
|
165 |
|
166 js->open(); |
|
167 js->startTransaction(); |
|
168 |
|
169 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1)); |
|
170 |
|
171 JavaStorageApplicationEntry_t suite1; |
|
172 attr.setEntry(PACKAGE_NAME, L"MySuite"); |
|
173 suite1.insert(attr); |
|
174 |
|
175 wstring vendor = L"SuiteVendor"; |
|
176 attr.setEntry(VENDOR, vendor); |
|
177 suite1.insert(attr); |
|
178 |
|
179 attr.setEntry(VERSION, L"0.1"); |
|
180 suite1.insert(attr); |
|
181 |
|
182 attr.setEntry(ID, suite1Uid.toString()); |
|
183 suite1.insert(attr); |
|
184 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
185 suite1.insert(attr); |
|
186 |
|
187 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
188 |
|
189 // Session must be committed before next use of Registry otherwise |
|
190 // it is locked. |
|
191 js->commitTransaction(); |
|
192 |
|
193 auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL()); |
|
194 |
|
195 TUid midletUid; |
|
196 uidToTUid(midlet1Uid, midletUid); |
|
197 |
|
198 CJavaRegistryApplicationEntry* entry = |
|
199 (CJavaRegistryApplicationEntry*) registry->RegistryEntryL(midletUid); |
|
200 |
|
201 CHECK(entry != NULL); |
|
202 CHECK(entry->IsVisible() == true); |
|
203 |
|
204 delete entry; |
|
205 entry = NULL; |
|
206 |
|
207 // Clean |
|
208 js->startTransaction(); |
|
209 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1)); |
|
210 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
211 js->commitTransaction(); |
|
212 js->close(); |
|
213 LOG(EJavaStorage, EInfo, "-TestIsVisible"); |
|
214 } |
|
215 |
|
216 /** |
|
217 * Test CJavaRegistryApplicationEntry::IsResident() method. |
|
218 * 1. Test return default value ETrue. |
|
219 */ |
|
220 TEST(TestRegistryApplicationEntry, TestIsResident) |
|
221 { |
|
222 LOG(EJavaStorage, EInfo, "+TestIsResident"); |
|
223 JavaStorageApplicationEntry_t midlet1; |
|
224 JavaStorageEntry attr; |
|
225 |
|
226 Uid suite1Uid(L"[e22a1111]"); |
|
227 |
|
228 attr.setEntry(PACKAGE_ID, suite1Uid.toString()); |
|
229 midlet1.insert(attr); |
|
230 |
|
231 Uid midlet1Uid(L"[e22a1111]"); |
|
232 |
|
233 attr.setEntry(ID, midlet1Uid.toString()); |
|
234 midlet1.insert(attr); |
|
235 |
|
236 js->open(); |
|
237 js->startTransaction(); |
|
238 |
|
239 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1)); |
|
240 |
|
241 JavaStorageApplicationEntry_t suite1; |
|
242 attr.setEntry(PACKAGE_NAME, L"MySuite"); |
|
243 suite1.insert(attr); |
|
244 |
|
245 wstring vendor = L"SuiteVendor"; |
|
246 attr.setEntry(VENDOR, vendor); |
|
247 suite1.insert(attr); |
|
248 |
|
249 attr.setEntry(VERSION, L"0.1"); |
|
250 suite1.insert(attr); |
|
251 |
|
252 attr.setEntry(ID, suite1Uid.toString()); |
|
253 suite1.insert(attr); |
|
254 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
255 suite1.insert(attr); |
|
256 |
|
257 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
258 |
|
259 // Session must be committed before next use of Registry otherwise |
|
260 // it is locked. |
|
261 js->commitTransaction(); |
|
262 |
|
263 auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL()); |
|
264 |
|
265 TUid midletUid; |
|
266 uidToTUid(midlet1Uid, midletUid); |
|
267 |
|
268 CJavaRegistryApplicationEntry* entry = |
|
269 (CJavaRegistryApplicationEntry*) registry->RegistryEntryL(midletUid); |
|
270 |
|
271 CHECK(entry != NULL); |
|
272 CHECK(entry->IsResident() == true); |
|
273 |
|
274 delete entry; |
|
275 entry = NULL; |
|
276 |
|
277 // Clean |
|
278 js->startTransaction(); |
|
279 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1)); |
|
280 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
281 js->commitTransaction(); |
|
282 js->close(); |
|
283 LOG(EJavaStorage, EInfo, "-TestIsResident"); |
|
284 } |
|
285 |
|
286 /** |
|
287 * Test CJavaRegistryApplicationEntry::GroupName() method. |
|
288 * 1. Test return default value KNullDesC. |
|
289 */ |
|
290 TEST(TestRegistryApplicationEntry, TestGroupName) |
|
291 { |
|
292 LOG(EJavaStorage, EInfo, "+TestGroupName"); |
|
293 JavaStorageApplicationEntry_t midlet1; |
|
294 JavaStorageEntry attr; |
|
295 |
|
296 Uid suite1Uid(L"[e22a1111]"); |
|
297 |
|
298 attr.setEntry(PACKAGE_ID, suite1Uid.toString()); |
|
299 midlet1.insert(attr); |
|
300 |
|
301 Uid midlet1Uid(L"[e22a1111]"); |
|
302 |
|
303 attr.setEntry(ID, midlet1Uid.toString()); |
|
304 midlet1.insert(attr); |
|
305 |
|
306 js->open(); |
|
307 js->startTransaction(); |
|
308 |
|
309 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1)); |
|
310 |
|
311 JavaStorageApplicationEntry_t suite1; |
|
312 attr.setEntry(PACKAGE_NAME, L"MySuite"); |
|
313 suite1.insert(attr); |
|
314 |
|
315 wstring vendor = L"SuiteVendor"; |
|
316 attr.setEntry(VENDOR, vendor); |
|
317 suite1.insert(attr); |
|
318 |
|
319 attr.setEntry(VERSION, L"0.1"); |
|
320 suite1.insert(attr); |
|
321 |
|
322 attr.setEntry(ID, suite1Uid.toString()); |
|
323 suite1.insert(attr); |
|
324 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
325 suite1.insert(attr); |
|
326 |
|
327 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
328 |
|
329 // Session must be committed before next use of Registry otherwise |
|
330 // it is locked. |
|
331 js->commitTransaction(); |
|
332 |
|
333 auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL()); |
|
334 |
|
335 TUid midletUid; |
|
336 uidToTUid(midlet1Uid, midletUid); |
|
337 |
|
338 CJavaRegistryApplicationEntry* entry = |
|
339 (CJavaRegistryApplicationEntry*) registry->RegistryEntryL(midletUid); |
|
340 |
|
341 CHECK(entry != NULL); |
|
342 _LIT(KDefaultValue, "Installed"); |
|
343 // CHECK(entry->GroupName() == KNullDesC); |
|
344 CHECK(entry->GroupName() == KDefaultValue); |
|
345 |
|
346 delete entry; |
|
347 entry = NULL; |
|
348 |
|
349 // Clean |
|
350 js->startTransaction(); |
|
351 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1)); |
|
352 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
353 js->commitTransaction(); |
|
354 js->close(); |
|
355 LOG(EJavaStorage, EInfo, "-TestGroupName"); |
|
356 } |
|
357 |
|
358 /** |
|
359 * Test CJavaRegistryApplicationEntry::PackageEntryL() method. |
|
360 * 1. Test return package entry. |
|
361 */ |
|
362 TEST(TestRegistryApplicationEntry, TestPackageEntryL) |
|
363 { |
|
364 LOG(EJavaStorage, EInfo, "+TestPackageEntryL"); |
|
365 JavaStorageApplicationEntry_t midlet1; |
|
366 JavaStorageEntry attr; |
|
367 |
|
368 Uid suite1Uid(L"[e22a2111]"); |
|
369 |
|
370 attr.setEntry(PACKAGE_ID, suite1Uid.toString()); |
|
371 midlet1.insert(attr); |
|
372 |
|
373 Uid midlet1Uid(L"[e22a2211]"); |
|
374 |
|
375 attr.setEntry(ID, midlet1Uid.toString()); |
|
376 midlet1.insert(attr); |
|
377 |
|
378 js->open(); |
|
379 js->startTransaction(); |
|
380 |
|
381 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1)); |
|
382 |
|
383 JavaStorageApplicationEntry_t suite1; |
|
384 attr.setEntry(PACKAGE_NAME, L"MySuite"); |
|
385 suite1.insert(attr); |
|
386 |
|
387 wstring vendor = L"SuiteVendor"; |
|
388 attr.setEntry(VENDOR, vendor); |
|
389 suite1.insert(attr); |
|
390 |
|
391 attr.setEntry(VERSION, L"0.1"); |
|
392 suite1.insert(attr); |
|
393 |
|
394 attr.setEntry(ID, suite1Uid.toString()); |
|
395 suite1.insert(attr); |
|
396 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
397 suite1.insert(attr); |
|
398 |
|
399 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
400 js->commitTransaction(); |
|
401 |
|
402 auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL()); |
|
403 |
|
404 TUid midletUid; |
|
405 uidToTUid(midlet1Uid, midletUid); |
|
406 |
|
407 CJavaRegistryApplicationEntry* entry = |
|
408 (CJavaRegistryApplicationEntry*) registry->RegistryEntryL(midletUid); |
|
409 CHECK(entry != NULL); |
|
410 |
|
411 CJavaRegistryPackageEntry* packageEntry = entry->PackageEntryL(); |
|
412 CHECK(packageEntry != NULL); |
|
413 |
|
414 TUid suiteUid; |
|
415 uidToTUid(suite1Uid, suiteUid); |
|
416 |
|
417 CHECK(packageEntry->Uid() == suiteUid); |
|
418 |
|
419 delete packageEntry; |
|
420 entry = NULL; |
|
421 |
|
422 delete entry; |
|
423 entry = NULL; |
|
424 |
|
425 // Clean |
|
426 js->startTransaction(); |
|
427 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1)); |
|
428 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
429 js->commitTransaction(); |
|
430 js->close(); |
|
431 LOG(EJavaStorage, EInfo, "-TestPackageEntryL"); |
|
432 } |