|
1 /* |
|
2 * Copyright (c) 2004 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 * ?description_line |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 |
|
22 #include "FT_CPosTp56.h" |
|
23 #include <EPos_CPosLandmarkDatabase.h> |
|
24 #include <EPos_CPosLandmarkEncoder.h> |
|
25 |
|
26 // CONSTANTS |
|
27 |
|
28 _LIT(KDbUri1, "file://c:eposlm.ldb"); |
|
29 _LIT(KDbUri2, "c:eposlm.ldb"); |
|
30 _LIT(KDbUri3, "eposlm.ldb"); |
|
31 _LIT(KDbUri4, "file://eposlm.ldb"); |
|
32 _LIT(KDbUri5, "testlm.ldb"); |
|
33 |
|
34 // Will need to be changed to the secure dbms path when security is implemented |
|
35 _LIT(KDbUri6, "c:\\system\\data\\eposlm.ldb"); |
|
36 // Will need to be changed to the secure dbms path when security is implemented |
|
37 _LIT(KDbUri7, "file://c:\\system\\data\\eposlm.ldb"); |
|
38 |
|
39 _LIT(KDbUri8, "eposlm"); |
|
40 _LIT(KDbUri9, "c:eposlm"); |
|
41 _LIT(KDbUri10, "file://c:eposlm"); |
|
42 |
|
43 _LIT(KDbUri11, "file://c:XXXX.ldb"); |
|
44 _LIT(KDbUri12, "http://c:eposlm.ldb"); |
|
45 _LIT(KDbUri13, ""); |
|
46 |
|
47 _LIT(KDbUri14, "file://\\eposlm.ldb"); // UNC |
|
48 _LIT(KDbUri15, "\\eposlm.ldb"); |
|
49 |
|
50 |
|
51 #ifdef __WINS__ |
|
52 _LIT(KTestDb, "z:\\system\\test\\TestData\\testlm.ldb"); |
|
53 #else |
|
54 _LIT(KTestDb, "c:\\system\\test\\TestData\\testlm.ldb"); |
|
55 #endif |
|
56 |
|
57 // Will need to be changed to the secure dbms path when security is implemented |
|
58 _LIT(KLocalDbLocation, "c:\\system\\data\\"); |
|
59 |
|
60 _LIT(KExportFileFullPath, "c:\\TP56-LandmarksFromThreeDatabases.xml"); |
|
61 _LIT(KExportFile, "TP56-LandmarksFromThreeDatabases.xml"); |
|
62 |
|
63 // ================= MEMBER FUNCTIONS ======================= |
|
64 |
|
65 // --------------------------------------------------------- |
|
66 // CPosTp56::GetName |
|
67 // |
|
68 // (other items were commented in a header). |
|
69 // --------------------------------------------------------- |
|
70 // |
|
71 void CPosTp56::GetName(TDes& aName) const |
|
72 { |
|
73 _LIT(KTestName, "TP56 - Open specific db and multiple db export"); |
|
74 aName = KTestName; |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------- |
|
78 // CPosTp56::StartL |
|
79 // |
|
80 // (other items were commented in a header). |
|
81 // --------------------------------------------------------- |
|
82 // |
|
83 void CPosTp56::StartL() |
|
84 { |
|
85 RemoveDefaultDbL(); |
|
86 |
|
87 CPosLandmarkDatabase* lmd = CPosLandmarkDatabase::OpenL(); |
|
88 delete lmd; |
|
89 |
|
90 TestOpenSpecificDbL(); |
|
91 |
|
92 TestMultipleExportL(); |
|
93 |
|
94 TestLockedDatabaseL(); |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------- |
|
98 // CPosTp56::TestMultipleExportL |
|
99 // |
|
100 // (other items were commented in a header). |
|
101 // --------------------------------------------------------- |
|
102 // |
|
103 void CPosTp56::TestMultipleExportL() |
|
104 { |
|
105 _LIT(KDb1, "eposlm1.ldb"); |
|
106 _LIT(KDb2, "eposlm2.ldb"); |
|
107 _LIT(KDb3, "eposlm3.ldb"); |
|
108 |
|
109 CreateDatabasesL(); |
|
110 |
|
111 CPosLandmarkDatabase* lmd1 = CPosLandmarkDatabase::OpenL(KDb1); |
|
112 CleanupStack::PushL(lmd1); |
|
113 |
|
114 CPosLandmarkDatabase* lmd2 = CPosLandmarkDatabase::OpenL(KDb2); |
|
115 CleanupStack::PushL(lmd2); |
|
116 |
|
117 CPosLandmarkDatabase* lmd3 = CPosLandmarkDatabase::OpenL(KDb3); |
|
118 CleanupStack::PushL(lmd3); |
|
119 |
|
120 CPosLandmark* lm = CreateXMLLandmarkLC(_L("TP56 - LM with all fields set")); |
|
121 AddAllXMLFieldsL(lm); |
|
122 |
|
123 lmd1->AddLandmarkL(*lm); |
|
124 CleanupStack::PopAndDestroy(lm); |
|
125 |
|
126 CPosLandmark* lm2 = CreateXMLLandmarkLC(_L("TP56 - LM2")); |
|
127 lmd2->AddLandmarkL(*lm2); |
|
128 CleanupStack::PopAndDestroy(lm2); |
|
129 |
|
130 |
|
131 CPosLandmark* lm3 = CreateXMLLandmarkLC(_L("TP56 - LM3")); |
|
132 |
|
133 CPosLmCategoryManager* cm = CPosLmCategoryManager::NewL(*lmd3); |
|
134 CleanupStack::PushL(cm); |
|
135 |
|
136 CPosLandmarkCategory* category = CPosLandmarkCategory::NewLC(); |
|
137 category->SetCategoryNameL(_L("category")); |
|
138 TPosLmItemId id = cm->AddCategoryL(*category); |
|
139 CleanupStack::PopAndDestroy(2, cm); |
|
140 |
|
141 lm3->AddCategoryL(id); |
|
142 lmd3->AddLandmarkL(*lm3); |
|
143 CleanupStack::PopAndDestroy(lm3); |
|
144 |
|
145 CPosLandmarkEncoder* encoder = CPosLandmarkEncoder::NewL(KMimeType); |
|
146 CleanupStack::PushL(encoder); |
|
147 |
|
148 encoder->SetOutputFileL(KExportFileFullPath); |
|
149 |
|
150 CPosLmItemIterator* iter = lmd1->LandmarkIteratorL(); |
|
151 CleanupStack::PushL(iter); |
|
152 |
|
153 RArray<TPosLmItemId> arrayOfIds; |
|
154 CleanupClosePushL(arrayOfIds); |
|
155 |
|
156 TInt numberOfElements = iter->NumOfItemsL(); |
|
157 iter->GetItemIdsL(arrayOfIds, 0, (numberOfElements)); |
|
158 |
|
159 ExecuteAndDeleteLD(lmd1->ExportLandmarksL(*encoder, arrayOfIds, CPosLandmarkDatabase::EDefaultOptions)); |
|
160 |
|
161 RunAsyncOperationLD(lmd2->ExportLandmarksL(*encoder, arrayOfIds, CPosLandmarkDatabase::EDefaultOptions)); |
|
162 |
|
163 ExecuteAndDeleteLD(lmd3->ExportLandmarksL(*encoder, arrayOfIds, CPosLandmarkDatabase::EIncludeCategories)); |
|
164 |
|
165 ExecuteAndDeleteLD(encoder->FinalizeEncodingL()); |
|
166 |
|
167 CleanupStack::PopAndDestroy(6, lmd1); |
|
168 |
|
169 TInt err = CompareL(KExportFile); |
|
170 AssertTrueSecL(err == KErrNone, _L("The exported file is not equal to file exported prevoius release")); |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------- |
|
174 // CPosTp56::CreateDatabasesL |
|
175 // |
|
176 // (other items were commented in a header). |
|
177 // --------------------------------------------------------- |
|
178 // |
|
179 void CPosTp56::CreateDatabasesL() |
|
180 { |
|
181 // Paths will need to be changed to the secure dbms path when security is implemented |
|
182 |
|
183 _LIT(KDefaultDbPath, "c:\\system\\data\\eposlm.ldb"); |
|
184 |
|
185 _LIT(KDb1Path, "c:\\system\\data\\eposlm1.ldb"); |
|
186 _LIT(KDb2Path, "c:\\system\\data\\eposlm2.ldb"); |
|
187 _LIT(KDb3Path, "c:\\system\\data\\eposlm3.ldb"); |
|
188 |
|
189 CPosLandmarkDatabase* lmd = CPosLandmarkDatabase::OpenL(); |
|
190 CleanupStack::PushL(lmd); |
|
191 |
|
192 if (lmd->IsInitializingNeeded()) |
|
193 { |
|
194 ExecuteAndDeleteLD(lmd->InitializeL()); |
|
195 } |
|
196 |
|
197 CleanupStack::PopAndDestroy(lmd); |
|
198 |
|
199 RFs fs; |
|
200 User::LeaveIfError(fs.Connect()); |
|
201 CleanupClosePushL(fs); |
|
202 |
|
203 fs.Delete(KExportFile); |
|
204 |
|
205 CFileMan* fileMan = CFileMan::NewL(fs); |
|
206 CleanupStack::PushL(fileMan); |
|
207 |
|
208 User::LeaveIfError(fileMan->Copy(KDefaultDbPath, KDb1Path, CFileMan::EOverWrite)); |
|
209 User::LeaveIfError(fileMan->Copy(KDefaultDbPath, KDb2Path, CFileMan::EOverWrite)); |
|
210 User::LeaveIfError(fileMan->Copy(KDefaultDbPath, KDb3Path, CFileMan::EOverWrite)); |
|
211 |
|
212 |
|
213 CleanupStack::PopAndDestroy(2, &fs); |
|
214 } |
|
215 |
|
216 // --------------------------------------------------------- |
|
217 // CPosTp56::TestOpenSpecificDbL |
|
218 // |
|
219 // (other items were commented in a header). |
|
220 // --------------------------------------------------------- |
|
221 // |
|
222 void CPosTp56::TestOpenSpecificDbL() |
|
223 { |
|
224 _LIT(KHttpErr, "http is not a supported protocol"); |
|
225 _LIT(KURIErr, "Not a valid URI"); |
|
226 _LIT(KArgumentErr, "An empty descr is not a valid URI"); |
|
227 |
|
228 TestOpenDbL(KDbUri1); |
|
229 TestOpenDbL(KDbUri2); |
|
230 TestOpenDbL(KDbUri3); |
|
231 TestOpenDbL(KDbUri4); |
|
232 |
|
233 CopyTestDbL(); |
|
234 TestOpenDbL(KDbUri5); |
|
235 |
|
236 TRAPD(err, TestOpenDbL(KDbUri6)); |
|
237 AssertTrueSecL(err == KErrArgument, KURIErr); |
|
238 |
|
239 TRAP(err, TestOpenDbL(KDbUri7)); |
|
240 AssertTrueSecL(err == KErrArgument, KURIErr); |
|
241 |
|
242 TRAP(err, TestOpenDbL(KDbUri8)); |
|
243 AssertTrueSecL(err == KErrArgument, KURIErr); |
|
244 |
|
245 TRAP(err, TestOpenDbL(KDbUri9)); |
|
246 AssertTrueSecL(err == KErrArgument, KURIErr); |
|
247 |
|
248 TRAP(err, TestOpenDbL(KDbUri10)); |
|
249 AssertTrueSecL(err == KErrArgument, KURIErr); |
|
250 |
|
251 TRAP(err, TestOpenDbL(KDbUri11)); |
|
252 AssertTrueSecL(err == KErrNotFound, KURIErr); |
|
253 |
|
254 TRAP(err, TestOpenDbL(KDbUri12)); |
|
255 AssertTrueSecL(err == KErrNotSupported, KHttpErr); |
|
256 |
|
257 TRAP(err, TestOpenDbL(KDbUri13)) |
|
258 AssertTrueSecL(err == KErrArgument, KArgumentErr); |
|
259 |
|
260 TRAP(err, TestOpenDbL(KDbUri14)); |
|
261 AssertTrueSecL(err == KErrArgument, KURIErr); |
|
262 |
|
263 TRAP(err, TestOpenDbL(KDbUri15)); |
|
264 AssertTrueSecL(err == KErrArgument, KURIErr); |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------- |
|
268 // CPosTp56::TestOpenDbL |
|
269 // |
|
270 // (other items were commented in a header). |
|
271 // --------------------------------------------------------- |
|
272 // |
|
273 void CPosTp56::TestOpenDbL(const TDesC& aDbURI) |
|
274 { |
|
275 CPosLandmarkDatabase* lmd = CPosLandmarkDatabase::OpenL(aDbURI); |
|
276 CleanupStack::PushL(lmd); |
|
277 |
|
278 if (lmd->IsInitializingNeeded()) |
|
279 { |
|
280 ExecuteAndDeleteLD(lmd->InitializeL()); |
|
281 } |
|
282 |
|
283 CleanupStack::PopAndDestroy(lmd); |
|
284 } |
|
285 |
|
286 //--------------------------------------------------------- |
|
287 // CPosTp56::CopTestDbL |
|
288 // |
|
289 // (other items were commented in a header). |
|
290 // --------------------------------------------------------- |
|
291 // |
|
292 void CPosTp56::CopyTestDbL() |
|
293 { |
|
294 |
|
295 RFs fs; |
|
296 User::LeaveIfError(fs.Connect()); |
|
297 CleanupClosePushL(fs); |
|
298 |
|
299 CFileMan* fileMan = CFileMan::NewL(fs); |
|
300 CleanupStack::PushL(fileMan); |
|
301 |
|
302 User::LeaveIfError(fileMan->Copy(KTestDb, KLocalDbLocation, CFileMan::EOverWrite)); |
|
303 |
|
304 CleanupStack::PopAndDestroy(2, &fs); |
|
305 |
|
306 } |
|
307 |
|
308 // --------------------------------------------------------- |
|
309 // CPosTp56::TestLockedDatabaseL |
|
310 // |
|
311 // (other items were commented in a header). |
|
312 // --------------------------------------------------------- |
|
313 // |
|
314 void CPosTp56::TestLockedDatabaseL() |
|
315 { |
|
316 CPosLandmarkDatabase* db1 = UseGeneratedDbFileL(); |
|
317 CleanupStack::PushL(db1); |
|
318 |
|
319 // Take read lock |
|
320 RArray<TPosLmItemId> ids; |
|
321 CleanupClosePushL(ids); |
|
322 User::LeaveIfError(ids.Append(1)); |
|
323 User::LeaveIfError(ids.Append(3)); |
|
324 User::LeaveIfError(ids.Append(4)); |
|
325 User::LeaveIfError(ids.Append(6)); |
|
326 User::LeaveIfError(ids.Append(7)); |
|
327 User::LeaveIfError(ids.Append(9)); |
|
328 User::LeaveIfError(ids.Append(24)); |
|
329 User::LeaveIfError(ids.Append(14)); |
|
330 User::LeaveIfError(ids.Append(66)); |
|
331 User::LeaveIfError(ids.Append(61)); |
|
332 User::LeaveIfError(ids.Append(14)); |
|
333 CPosLmOperation* operation = db1->PreparePartialLandmarksL(ids); |
|
334 CleanupStack::PushL(operation); |
|
335 TReal32 progress(0); |
|
336 TRequestStatus status; |
|
337 while (progress < 0.4) |
|
338 { |
|
339 operation->NextStep(status, progress); |
|
340 User::WaitForRequest(status); |
|
341 } |
|
342 |
|
343 // Try to instantiate a new db handle |
|
344 operation->NextStep(status, progress); |
|
345 CPosLandmarkDatabase* db2 = CPosLandmarkDatabase::OpenL(KDbUri1); |
|
346 delete db2; |
|
347 User::WaitForRequest(status); |
|
348 |
|
349 // Release read lock |
|
350 CleanupStack::PopAndDestroy(operation); |
|
351 |
|
352 // Take write lock |
|
353 operation = db1->RemoveAllLandmarksL(); |
|
354 CleanupStack::PushL(operation); |
|
355 progress = 0; |
|
356 while (progress < 0.4) |
|
357 { |
|
358 operation->NextStep(status, progress); |
|
359 User::WaitForRequest(status); |
|
360 } |
|
361 |
|
362 // Try to instantiate a new db handle - should result in KErrLocked |
|
363 operation->NextStep(status, progress); |
|
364 db2 = NULL; |
|
365 TRAPD(err, db2 = CPosLandmarkDatabase::OpenL(KDbUri1)); |
|
366 delete db2; |
|
367 User::WaitForRequest(status); |
|
368 AssertTrueSecL(err == KErrLocked, _L("OpenL() didn't result in KErrLocked but in %d"), err); |
|
369 |
|
370 CleanupStack::PopAndDestroy(3, db1); |
|
371 } |
|
372 |
|
373 // End of File |