|
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 "javacommonutils.h" |
|
24 #include "javaoslayer.h" |
|
25 #include "javastorage.h" |
|
26 #include "javastorageexception.h" |
|
27 #include "javastoragenames.h" |
|
28 #include "javasymbianoslayer.h" |
|
29 #include "javauid.h" |
|
30 #include "logger.h" |
|
31 #include "mjavaregistry.h" |
|
32 #include "storagetestutils.h" |
|
33 |
|
34 using namespace std; |
|
35 using namespace java::storage; |
|
36 using namespace java::util; |
|
37 |
|
38 /** |
|
39 * NOTE: Some of MJavaRegistryMIDletEntry interface methods are already tested |
|
40 * at testlegacyregistry.cpp test case. |
|
41 */ |
|
42 TEST_GROUP(TestMIDletEntry) |
|
43 { |
|
44 JavaStorage* js; |
|
45 JavaStorageTestUtils* jtu; |
|
46 |
|
47 TEST_SETUP() |
|
48 { |
|
49 js = JavaStorage::createInstance(); |
|
50 jtu = new JavaStorageTestUtils(); |
|
51 } |
|
52 TEST_TEARDOWN() |
|
53 { |
|
54 try |
|
55 { |
|
56 js->rollbackTransaction(); |
|
57 js->close(); |
|
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 CJavaRegistryMIDletEntry::SizeL() method. |
|
73 * 1. No Size set. 0 as size. |
|
74 * 2. Test size set to 0. |
|
75 * 3. Test size set to 12345. |
|
76 */ |
|
77 TEST(TestMIDletEntry, TestSizeL) |
|
78 { |
|
79 LOG(EJavaStorage, EInfo, "+TestSizeL"); |
|
80 |
|
81 MJavaRegistry* registry = MJavaRegistry::CreateL(); |
|
82 CHECK(registry != NULL); |
|
83 |
|
84 JavaStorageApplicationEntry_t suite1; |
|
85 JavaStorageEntry attr; |
|
86 attr.setEntry(PACKAGE_NAME, L"TestMIDletByUidL"); |
|
87 suite1.insert(attr); |
|
88 |
|
89 string tableName = APPLICATION_PACKAGE_TABLE; |
|
90 Uid suite1Uid(L"[e1230043]"); |
|
91 attr.setEntry(ID, suite1Uid.toString()); |
|
92 suite1.insert(attr); |
|
93 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
94 suite1.insert(attr); |
|
95 |
|
96 js->open(); |
|
97 js->startTransaction(); |
|
98 CHECK(jtu->populate(*js, tableName, suite1)); |
|
99 js->commitTransaction(); |
|
100 |
|
101 JavaStorageApplicationEntry_t midlet1; |
|
102 attr.setEntry(NAME, L"MyMIDlet1"); |
|
103 midlet1.insert(attr); |
|
104 |
|
105 attr.setEntry(PACKAGE_ID, suite1Uid.toString()); |
|
106 midlet1.insert(attr); |
|
107 |
|
108 string appTableName = APPLICATION_TABLE; |
|
109 Uid midlet1Uid(L"[e12a0078]"); |
|
110 attr.setEntry(ID, midlet1Uid.toString()); |
|
111 midlet1.insert(attr); |
|
112 |
|
113 js->startTransaction(); |
|
114 CHECK(jtu->populate(*js, appTableName, midlet1)); |
|
115 js->commitTransaction(); |
|
116 |
|
117 // 1. No Size set. 0 as size. |
|
118 TUid suiteUid; |
|
119 uidToTUid(suite1Uid, suiteUid); |
|
120 |
|
121 // 1. Test TUid::Null() leaves KErrArgument. |
|
122 MJavaRegistrySuiteEntry* suiteEntry = registry->SuiteEntryL(suiteUid); |
|
123 CHECK(suiteEntry != NULL); |
|
124 |
|
125 TUid midletUid; |
|
126 uidToTUid(midlet1Uid, midletUid); |
|
127 |
|
128 MJavaRegistryMIDletEntry* midletEntry |
|
129 = suiteEntry->MIDletByUidL(midletUid); |
|
130 CHECK(midletEntry != NULL); |
|
131 CHECK(midletEntry->SizeL() == 0); |
|
132 |
|
133 midletEntry->Release(); |
|
134 suiteEntry->Release(); |
|
135 |
|
136 JavaStorageApplicationEntry_t updateEntry; |
|
137 attr.setEntry(INITIAL_SIZE, L"0"); |
|
138 updateEntry.insert(attr); |
|
139 js->startTransaction(); |
|
140 CHECK(jtu->update(*js, tableName, updateEntry, suite1)); |
|
141 js->commitTransaction(); |
|
142 |
|
143 suiteEntry = registry->SuiteEntryL(suiteUid); |
|
144 CHECK(suiteEntry != NULL); |
|
145 |
|
146 // 2. Test size set to 0. |
|
147 midletEntry = suiteEntry->MIDletByUidL(midletUid); |
|
148 CHECK(midletEntry != NULL); |
|
149 CHECK(midletEntry->SizeL() == 0); |
|
150 |
|
151 midletEntry->Release(); |
|
152 suiteEntry->Release(); |
|
153 |
|
154 attr.setEntry(INITIAL_SIZE, L"12345"); |
|
155 updateEntry.insert(attr); |
|
156 js->startTransaction(); |
|
157 CHECK(jtu->update(*js, tableName, updateEntry, suite1)); |
|
158 js->commitTransaction(); |
|
159 |
|
160 suiteEntry = registry->SuiteEntryL(suiteUid); |
|
161 CHECK(suiteEntry != NULL); |
|
162 |
|
163 // 3. Test size set to 12345. |
|
164 midletEntry = suiteEntry->MIDletByUidL(midletUid); |
|
165 CHECK(midletEntry != NULL); |
|
166 // CHECK(midletEntry->SizeL() == 12345); |
|
167 CHECK(midletEntry->SizeL() == 0); // Original legacyregistry |
|
168 // does not implement size. |
|
169 |
|
170 midletEntry->Release(); |
|
171 suiteEntry->Release(); |
|
172 |
|
173 // Clean |
|
174 js->startTransaction(); |
|
175 CHECK(jtu->remove(*js, tableName, suite1)); |
|
176 CHECK(jtu->remove(*js, appTableName, midlet1)); |
|
177 js->commitTransaction(); |
|
178 js->close(); |
|
179 |
|
180 registry->Release(); |
|
181 |
|
182 LOG(EJavaStorage, EInfo, "-TestSizeL"); |
|
183 } |
|
184 |