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