|
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_CPosTp45.h" |
|
23 #include <EPos_CPosLandmarkDatabase.h> |
|
24 #include <EPos_CPosLandmarkEncoder.h> |
|
25 #include <EPos_CPosLandmarkParser.h> |
|
26 #include <bautils.h> |
|
27 |
|
28 |
|
29 // CONSTANTS |
|
30 const TInt KNoCategoriesTp45 = 100; |
|
31 // Filename with 260 characters |
|
32 _LIT(KLongFileName, "c:\\File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File12"); |
|
33 // Filename with 264 characters |
|
34 _LIT(KLongFileName2, "c:\\File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File12.txt"); |
|
35 |
|
36 _LIT(KDefaultOptions, "c:\\system\\test\\testdata\\TP45-DefOptions.xml"); |
|
37 _LIT(KInclCategories, "c:\\system\\test\\testdata\\TP45-IncCategories.xml"); |
|
38 _LIT(KExclCategories, "c:\\system\\test\\testdata\\TP45-ExcCategories.xml"); |
|
39 _LIT(KOneLandmark, "c:\\system\\test\\testdata\\TP45-OneLandmark.xml"); |
|
40 _LIT(KTwoLandmarks, "c:\\system\\test\\testdata\\TP45-TwoLandmarks.xml"); |
|
41 _LIT(KTwoLandmarksWithColData, "c:\\system\\test\\testdata\\TP45-TwoLandmarksWithCollData.xml"); |
|
42 |
|
43 _LIT(KFileSync, "c:\\documents\\TP45-DefOptions.xml"); |
|
44 _LIT(KFileInc, "c:\\documents\\TP45-DefOptionsInc.xml"); |
|
45 _LIT(KFileWait4Req, "c:\\documents\\TP45-DefOptionsWait4Req.xml"); |
|
46 _LIT(KBufferSync, "c:\\documents\\TP45-DefOptionsBuffer.xml"); |
|
47 _LIT(KBufferInc, "c:\\documents\\TP45-DefOptionsBufferInc.xml"); |
|
48 _LIT(KBufferWait4Req, "c:\\documents\\TP45-DefOptionsBufferWait4Req.xml"); |
|
49 |
|
50 _LIT(KFileSync2, "c:\\documents\\TP45-IncCategories.xml"); |
|
51 _LIT(KFileInc2, "c:\\documents\\TP45-IncCategoriesInc.xml"); |
|
52 _LIT(KFileWait4Req2, "c:\\documents\\TP45-IncCategoriesWait4Req.xml"); |
|
53 _LIT(KBufferSync2, "c:\\documents\\TP45-IncCategoriesBuffer.xml"); |
|
54 _LIT(KBufferInc2, "c:\\documents\\TP45-IncCategoriesBufferInc.xml"); |
|
55 _LIT(KBufferWait4Req2, "c:\\documents\\TP45-IncCategoriesBufferWait4Req.xml"); |
|
56 |
|
57 _LIT(KFileSync3, "c:\\documents\\TP45-ExcCategories.xml"); |
|
58 _LIT(KFileInc3, "c:\\documents\\TP45-ExcCategoriesInc.xml"); |
|
59 _LIT(KFileWait4Req3, "c:\\documents\\TP45-ExcCategoriesWait4Req.xml"); |
|
60 _LIT(KBufferSync3, "c:\\documents\\TP45-ExcCategoriesBuffer.xml"); |
|
61 _LIT(KBufferInc3, "c:\\documents\\TP45-ExcCategoriesBufferInc.xml"); |
|
62 _LIT(KBufferWait4Req3, "c:\\documents\\TP45-ExcCategoriesBufferWait4Req.xml"); |
|
63 |
|
64 _LIT(KFileSync4, "c:\\documents\\TP45-OneLandmark.xml"); |
|
65 _LIT(KFileInc4, "c:\\documents\\TP45-OneLandmarkInc.xml"); |
|
66 _LIT(KFileWait4Req4, "c:\\documents\\TP45-OneLandmarkWait4Req.xml"); |
|
67 |
|
68 _LIT(KFileSync5, "c:\\documents\\TP45-TwoLandmarks.xml"); |
|
69 _LIT(KFileInc5, "c:\\documents\\TP45-TwoLandmarksInc.xml"); |
|
70 _LIT(KFileWait4Req5, "c:\\documents\\TP45-TwoLandmarksWait4Req.xml"); |
|
71 |
|
72 _LIT(KFileSync6, "c:\\documents\\TP45-TwoLandmarksWithCollData.xml"); |
|
73 |
|
74 _LIT(KFileCancelled, "c:\\documents\\TP45-Cancelled.xml"); |
|
75 |
|
76 _LIT(KFileCancelledInCallback, "c:\\documents\\TP45-CancelledInCallback.xml"); |
|
77 |
|
78 _LIT(KTmpFile, "c:\\documents\\TMP.xml"); |
|
79 |
|
80 //const TPosLmItemId KGlobalCategoryId = 2; |
|
81 //const TPosLmItemId KGlobalCategoryId2 = 4; |
|
82 const TPosLmItemId KGlobalCategoryId = 5; |
|
83 const TPosLmItemId KGlobalCategoryId2 = 9; |
|
84 |
|
85 const TPosLmItemId KLandmarkId = 3; |
|
86 const TPosLmItemId KLandmarkId2 = 1; |
|
87 |
|
88 const TInt KMaxCancelled = 10; |
|
89 |
|
90 const TInt KMaxCancelledInCallback = 50; |
|
91 |
|
92 _LIT(KCollectionName, "TP45-CollectionName"); |
|
93 _LIT(KCollectionDes, "TP45-Description"); |
|
94 |
|
95 |
|
96 // ================= MEMBER FUNCTIONS ======================= |
|
97 |
|
98 |
|
99 // --------------------------------------------------------- |
|
100 // CPosTp45::CloseTest |
|
101 // |
|
102 // (other items were commented in a header). |
|
103 // --------------------------------------------------------- |
|
104 // |
|
105 void CPosTp45::CloseTest() |
|
106 { |
|
107 iLog->Log(_L("CloseTest")); |
|
108 |
|
109 delete iDatabase; |
|
110 delete iLandmarkEncoder; |
|
111 delete iBuffer; |
|
112 |
|
113 // Added for BC testing |
|
114 delete iCategoryManager; |
|
115 iGlobalCategoryIds.Close(); |
|
116 iGlobalCategoryNames.Close(); |
|
117 iGlobalCategoryTestNames.Close(); |
|
118 |
|
119 iCategories.ResetAndDestroy(); |
|
120 iCategories.Close(); |
|
121 RemoveGlobalCategoriesL(); |
|
122 } |
|
123 // --------------------------------------------------------- |
|
124 // CPosTp45::StartL |
|
125 // |
|
126 // (other items were commented in a header). |
|
127 // --------------------------------------------------------- |
|
128 // |
|
129 void CPosTp45::StartL() |
|
130 { |
|
131 BaflUtils::EnsurePathExistsL( iFileSession, KTmpFile ); |
|
132 |
|
133 RemoveDefaultDbL(); |
|
134 RemoveGlobalCategoriesL(); |
|
135 |
|
136 iDatabase = CPosLandmarkDatabase::OpenL(); |
|
137 |
|
138 if (iDatabase->IsInitializingNeeded()) |
|
139 { |
|
140 ExecuteAndDeleteLD(iDatabase->InitializeL()); |
|
141 } |
|
142 |
|
143 |
|
144 iCategoryManager = CPosLmCategoryManager::NewL(*iDatabase); |
|
145 ExecuteAndDeleteLD(iDatabase->CompactL()); |
|
146 |
|
147 // Setup global category info |
|
148 SetupGlobalCategoriesL(); |
|
149 |
|
150 AddLandmarksL(); |
|
151 AddCategoriesL(); |
|
152 |
|
153 iLandmarkEncoder = CPosLandmarkEncoder::NewL(KLmxMimeType); |
|
154 |
|
155 TestErrorCodesL(); |
|
156 |
|
157 RArray<TPosLmItemId> arrayOfIds; |
|
158 CleanupClosePushL(arrayOfIds); |
|
159 |
|
160 CPosLmItemIterator* iter = iDatabase->LandmarkIteratorL(); |
|
161 CleanupStack::PushL(iter); |
|
162 |
|
163 TInt numberOfElements = iter->NumOfItemsL(); |
|
164 iter->GetItemIdsL(arrayOfIds, 0, (numberOfElements)); |
|
165 |
|
166 iLogToFile = ETrue; |
|
167 TBool useWaitForRequest = ETrue; |
|
168 |
|
169 // Exporting all landmarks to file |
|
170 iLog->Log(_L("Exporting all landmarks syncronously to file")); |
|
171 ExportLandmarksL(KFileSync, arrayOfIds, CPosLandmarkDatabase::EDefaultOptions); |
|
172 |
|
173 iLog->Log(_L("Exporting all landmarks incrementally to file")); |
|
174 ExportLandmarksIncL(KFileInc, arrayOfIds, CPosLandmarkDatabase::EDefaultOptions, !useWaitForRequest); |
|
175 |
|
176 iLog->Log(_L("Exporting all landmarks incrementally using User::WaitForRequest() to file")); |
|
177 ExportLandmarksIncL(KFileWait4Req, arrayOfIds, CPosLandmarkDatabase::EDefaultOptions, useWaitForRequest); |
|
178 |
|
179 RenameGlobalCategoryL(); |
|
180 |
|
181 // Exporting with global cateogries to file |
|
182 iLog->Log(_L("Exporting all landmarks with global categories names syncronously to file")); |
|
183 ExportLandmarksL(KFileSync2, arrayOfIds, CPosLandmarkDatabase::EIncludeCategories | |
|
184 CPosLandmarkDatabase::EIncludeGlobalCategoryNames); |
|
185 |
|
186 iLog->Log(_L("Exporting all landmarks with global categories names incrementally to file")); |
|
187 ExportLandmarksIncL(KFileInc2, arrayOfIds, CPosLandmarkDatabase::EIncludeCategories | |
|
188 CPosLandmarkDatabase::EIncludeGlobalCategoryNames, |
|
189 !useWaitForRequest); |
|
190 |
|
191 iLog->Log(_L("Exporting all landmarks with global categories names incrementally using User::WaitForRequest() to file")); |
|
192 ExportLandmarksIncL(KFileWait4Req2, arrayOfIds, CPosLandmarkDatabase::EIncludeCategories | |
|
193 CPosLandmarkDatabase::EIncludeGlobalCategoryNames, |
|
194 useWaitForRequest); |
|
195 |
|
196 // Exporting without global cateogries to file |
|
197 iLog->Log(_L("Exporting all landmarks with categories exc. global categories syncronously to file")); |
|
198 ExportLandmarksL(KFileSync3, arrayOfIds, CPosLandmarkDatabase::EIncludeCategories); |
|
199 |
|
200 iLog->Log(_L("Exporting all landmarks with categories exc. global categories incrementally to file")); |
|
201 ExportLandmarksIncL(KFileInc3, arrayOfIds, CPosLandmarkDatabase::EIncludeCategories, !useWaitForRequest); |
|
202 |
|
203 iLog->Log(_L("Exporting all landmarks with categories exc. global categories incrementally using User::WaitForRequest() to file")); |
|
204 ExportLandmarksIncL(KFileWait4Req3, arrayOfIds, CPosLandmarkDatabase::EIncludeCategories, useWaitForRequest); |
|
205 |
|
206 iLogToFile = EFalse; |
|
207 |
|
208 // Exporting all landmarks to buffer |
|
209 iLog->Log(_L("Exporting all landmarks syncronously to buffer")); |
|
210 ExportLandmarksL(KBufferSync, arrayOfIds, CPosLandmarkDatabase::EDefaultOptions); |
|
211 |
|
212 iLog->Log(_L("Exporting all landmarks incrementally to buffer")); |
|
213 ExportLandmarksIncL(KBufferInc, arrayOfIds, CPosLandmarkDatabase::EDefaultOptions, !useWaitForRequest); |
|
214 |
|
215 iLog->Log(_L("Exporting all landmarks incrementally using User::WaitForRequest() to buffer")); |
|
216 ExportLandmarksIncL(KBufferWait4Req, arrayOfIds, CPosLandmarkDatabase::EDefaultOptions, useWaitForRequest); |
|
217 |
|
218 // Exporting all landmarks with global categories to buffer |
|
219 iLog->Log(_L("Exporting all landmarks with global categories names syncronously to buffer")); |
|
220 ExportLandmarksL(KBufferSync2, arrayOfIds, CPosLandmarkDatabase::EIncludeCategories | |
|
221 CPosLandmarkDatabase::EIncludeGlobalCategoryNames); |
|
222 |
|
223 iLog->Log(_L("Exporting all landmarks with global categories names incrementally to buffer")); |
|
224 ExportLandmarksIncL(KBufferInc2, arrayOfIds, CPosLandmarkDatabase::EIncludeCategories | |
|
225 CPosLandmarkDatabase::EIncludeGlobalCategoryNames, |
|
226 !useWaitForRequest); |
|
227 |
|
228 iLog->Log(_L("Exporting all landmarks with global categories names incrementally using User::WaitForRequest() to buffer")); |
|
229 ExportLandmarksIncL(KBufferWait4Req2, arrayOfIds, CPosLandmarkDatabase::EIncludeCategories | |
|
230 CPosLandmarkDatabase::EIncludeGlobalCategoryNames, |
|
231 useWaitForRequest); |
|
232 |
|
233 // Exporting all landmarks with global categories to buffer |
|
234 iLog->Log(_L("Exporting all landmarks with categories exc. global categories syncronously to buffer")); |
|
235 ExportLandmarksL(KBufferSync3, arrayOfIds, CPosLandmarkDatabase::EIncludeCategories); |
|
236 |
|
237 iLog->Log(_L("Exporting all landmarks with categories exc. global categories incrementally to buffer")); |
|
238 ExportLandmarksIncL(KBufferInc3, arrayOfIds, CPosLandmarkDatabase::EIncludeCategories, !useWaitForRequest); |
|
239 |
|
240 iLog->Log(_L("Exporting all landmarks with categories exc. global categories incrementally using User::WaitForRequest() to buffer")); |
|
241 ExportLandmarksIncL(KBufferWait4Req3, arrayOfIds, CPosLandmarkDatabase::EIncludeCategories, useWaitForRequest); |
|
242 |
|
243 iLogToFile = ETrue; |
|
244 CleanupStack::PopAndDestroy(iter); |
|
245 arrayOfIds.Reset(); |
|
246 |
|
247 // Exporting one landmark to file |
|
248 arrayOfIds.Append(KLandmarkId); |
|
249 iLog->Log(_L("Exporting one landmark syncronously to file")); |
|
250 ExportLandmarksL(KFileSync4, arrayOfIds, CPosLandmarkDatabase::EDefaultOptions); |
|
251 |
|
252 iLog->Log(_L("Exporting one landmark syncronously to file incrementally")); |
|
253 ExportLandmarksIncL(KFileInc4, arrayOfIds, CPosLandmarkDatabase::EDefaultOptions, !useWaitForRequest); |
|
254 |
|
255 iLog->Log(_L("Exporting one landmark syncronously to file incrementally using User::WaitForRequest()")); |
|
256 ExportLandmarksIncL(KFileWait4Req4, arrayOfIds, CPosLandmarkDatabase::EDefaultOptions, useWaitForRequest); |
|
257 |
|
258 // Exporting two landmarks to file |
|
259 arrayOfIds.Append(KLandmarkId2); |
|
260 iLog->Log(_L("Exporting two landmark syncronously to file")); |
|
261 ExportLandmarksL(KFileSync5, arrayOfIds, CPosLandmarkDatabase::EDefaultOptions); |
|
262 |
|
263 iLog->Log(_L("Exporting two landmark syncronously to file incrementally")); |
|
264 ExportLandmarksIncL(KFileInc5, arrayOfIds, CPosLandmarkDatabase::EDefaultOptions, !useWaitForRequest); |
|
265 |
|
266 iLog->Log(_L("Exporting two landmark syncronously to file incrementally using User::WaitForRequest()")); |
|
267 ExportLandmarksIncL(KFileWait4Req5, arrayOfIds, CPosLandmarkDatabase::EDefaultOptions, useWaitForRequest); |
|
268 |
|
269 // Exporting landmarks with collection data |
|
270 iLog->Log(_L("Exporting landmarks with collection data added to the encoder")); |
|
271 ExportWithCollectionDataL(arrayOfIds, CPosLandmarkDatabase::EDefaultOptions); |
|
272 |
|
273 iLog->Log(_L("Compares the created XML files with saved correct ones")); |
|
274 |
|
275 TInt errors = 0; |
|
276 |
|
277 errors += CompareL(KDefaultOptions, KFileSync); |
|
278 errors += CompareL(KDefaultOptions, KFileInc); |
|
279 errors += CompareL(KDefaultOptions, KFileWait4Req); |
|
280 errors += CompareL(KDefaultOptions, KBufferSync); |
|
281 errors += CompareL(KDefaultOptions, KBufferInc); |
|
282 errors += CompareL(KDefaultOptions, KBufferWait4Req); |
|
283 |
|
284 TFileName filename; |
|
285 CreateCorrectXmlFileL( KInclCategories, filename ); |
|
286 errors += CompareL(filename, KFileSync2); |
|
287 errors += CompareL(filename, KFileInc2); |
|
288 errors += CompareL(filename, KFileWait4Req2); |
|
289 errors += CompareL(filename, KFileInc2); |
|
290 errors += CompareL(filename, KBufferSync2); |
|
291 errors += CompareL(filename, KBufferInc2); |
|
292 errors += CompareL(filename, KBufferWait4Req2); |
|
293 |
|
294 CreateCorrectXmlFileL( KExclCategories, filename ); |
|
295 errors += CompareL(filename, KFileSync3); |
|
296 errors += CompareL(filename, KFileInc3); |
|
297 errors += CompareL(filename, KFileWait4Req3); |
|
298 errors += CompareL(filename, KBufferSync3); |
|
299 errors += CompareL(filename, KBufferInc3); |
|
300 errors += CompareL(filename, KBufferWait4Req3); |
|
301 |
|
302 errors += CompareL(KOneLandmark, KFileSync4); |
|
303 errors += CompareL(KOneLandmark, KFileInc4); |
|
304 errors += CompareL(KOneLandmark, KFileWait4Req4); |
|
305 |
|
306 errors += CompareL(KTwoLandmarks, KFileSync5); |
|
307 errors += CompareL(KTwoLandmarks, KFileInc5); |
|
308 errors += CompareL(KTwoLandmarks, KFileWait4Req5); |
|
309 |
|
310 errors += CompareL(KTwoLandmarksWithColData, KFileSync6); |
|
311 |
|
312 if (errors > 0) |
|
313 { |
|
314 errors = errors / KErrGeneral; |
|
315 } |
|
316 |
|
317 AssertTrueSecL(errors == 0, _L("%d file(s) are not equal"), errors); |
|
318 |
|
319 delete iDatabase; |
|
320 iDatabase = NULL; |
|
321 |
|
322 iDatabase = UseGeneratedDbFileL(); |
|
323 |
|
324 if (iDatabase->IsInitializingNeeded()) |
|
325 { |
|
326 ExecuteAndDeleteLD(iDatabase->InitializeL()); |
|
327 } |
|
328 |
|
329 iLog->Log(_L("Exports landmarks and cancels the operation")); |
|
330 ExportAndCancelL(KFileCancelled, EFalse, CPosLandmarkDatabase::EDefaultOptions); |
|
331 |
|
332 iLog->Log(_L("Exports landmarks and cancels the operation in a callback")); |
|
333 ExportAndCancelL(KFileCancelledInCallback, ETrue, CPosLandmarkDatabase::EDefaultOptions); |
|
334 |
|
335 VerifyCancelL(KFileCancelled, KMaxCancelled); |
|
336 |
|
337 VerifyCancelL(KFileCancelledInCallback, KMaxCancelledInCallback); |
|
338 |
|
339 CleanupStack::PopAndDestroy(&arrayOfIds); |
|
340 |
|
341 } |
|
342 |
|
343 // --------------------------------------------------------- |
|
344 // CPosTp45::ExportLandmarksL |
|
345 // |
|
346 // (other items were commented in a header). |
|
347 // --------------------------------------------------------- |
|
348 // |
|
349 void CPosTp45::ExportLandmarksL(const TDesC& aFileName, |
|
350 RArray<TPosLmItemId>& aArrayOfIds, |
|
351 CPosLandmarkDatabase::TTransferOptions aTransferOptions) |
|
352 { |
|
353 iLog->Log(_L("ExportLandmarksL")); |
|
354 TBuf<100> file; |
|
355 file.Append(aFileName); |
|
356 |
|
357 if (iLogToFile) |
|
358 { |
|
359 DeleteFile(file); |
|
360 iLandmarkEncoder->SetOutputFileL(file); |
|
361 } |
|
362 else |
|
363 { |
|
364 iBuffer = iLandmarkEncoder->SetUseOutputBufferL(); |
|
365 } |
|
366 |
|
367 CPosLmOperation* op = iDatabase->ExportLandmarksL(*iLandmarkEncoder, aArrayOfIds, aTransferOptions); |
|
368 CleanupStack::PushL(op); |
|
369 op->ExecuteL(); |
|
370 CleanupStack::PopAndDestroy(op); |
|
371 |
|
372 op = iLandmarkEncoder->FinalizeEncodingL(); |
|
373 CleanupStack::PushL(op); |
|
374 op->ExecuteL(); |
|
375 CleanupStack::PopAndDestroy(op); |
|
376 |
|
377 if (!iLogToFile) |
|
378 { |
|
379 WriteBufferToFileL(iBuffer, file); |
|
380 delete iBuffer; |
|
381 iBuffer = NULL; |
|
382 } |
|
383 } |
|
384 |
|
385 // --------------------------------------------------------- |
|
386 // CPosTp45::ExportLandmarksIncL |
|
387 // |
|
388 // (other items were commented in a header). |
|
389 // --------------------------------------------------------- |
|
390 // |
|
391 void CPosTp45::ExportLandmarksIncL(const TDesC& aFileName, |
|
392 RArray<TPosLmItemId>& aArrayOfIds, |
|
393 CPosLandmarkDatabase::TTransferOptions aTransferOptions, |
|
394 TBool aUseWaitForRequest) |
|
395 { |
|
396 iLog->Log(_L("ExportLandmarksIncL")); |
|
397 TBuf<100> file; |
|
398 file.Append(aFileName); |
|
399 |
|
400 if (iLogToFile) |
|
401 { |
|
402 DeleteFile(file); |
|
403 iLandmarkEncoder->SetOutputFileL(file); |
|
404 } |
|
405 else |
|
406 { |
|
407 iBuffer = iLandmarkEncoder->SetUseOutputBufferL(); |
|
408 } |
|
409 |
|
410 CPosLmOperation* op = iDatabase->ExportLandmarksL(*iLandmarkEncoder, aArrayOfIds, aTransferOptions); |
|
411 if (aUseWaitForRequest) |
|
412 { |
|
413 CleanupStack::PushL(op); |
|
414 RunAsyncOperationByWaitForReqL(op); |
|
415 CleanupStack::PopAndDestroy(op); |
|
416 } |
|
417 else |
|
418 { |
|
419 RunAsyncOperationLD(op); |
|
420 } |
|
421 |
|
422 op = iLandmarkEncoder->FinalizeEncodingL(); |
|
423 if (aUseWaitForRequest) |
|
424 { |
|
425 CleanupStack::PushL(op); |
|
426 RunAsyncOperationByWaitForReqL(op); |
|
427 CleanupStack::PopAndDestroy(op); |
|
428 } |
|
429 else |
|
430 { |
|
431 RunAsyncOperationLD(op); |
|
432 } |
|
433 |
|
434 if (!iLogToFile) |
|
435 { |
|
436 WriteBufferToFileL(iBuffer, file); |
|
437 delete iBuffer; |
|
438 iBuffer = NULL; |
|
439 } |
|
440 } |
|
441 |
|
442 // --------------------------------------------------------- |
|
443 // CPosTp45::ExportWithCollectionDataL |
|
444 // |
|
445 // (other items were commented in a header). |
|
446 // --------------------------------------------------------- |
|
447 // |
|
448 void CPosTp45::ExportWithCollectionDataL(RArray<TPosLmItemId>& aArrayOfIds, |
|
449 CPosLandmarkDatabase::TTransferOptions aTransferOptions) |
|
450 { |
|
451 iLog->Log(_L("ExportWithCollectionDataL")); |
|
452 TBuf<100> file; |
|
453 //file.Append(KTargetPath); |
|
454 file.Append(KFileSync6); |
|
455 |
|
456 DeleteFile(file); |
|
457 iLandmarkEncoder->SetOutputFileL(file); |
|
458 |
|
459 iLandmarkEncoder->AddCollectionDataL(EPosLmCollDataCollectionName, KCollectionName); |
|
460 iLandmarkEncoder->AddCollectionDataL(EPosLmCollDataCollectionDescription, KCollectionDes); |
|
461 |
|
462 CPosLmOperation* op = iDatabase->ExportLandmarksL(*iLandmarkEncoder, aArrayOfIds, aTransferOptions); |
|
463 CleanupStack::PushL(op); |
|
464 op->ExecuteL(); |
|
465 CleanupStack::PopAndDestroy(op); |
|
466 |
|
467 op = iLandmarkEncoder->FinalizeEncodingL(); |
|
468 CleanupStack::PushL(op); |
|
469 op->ExecuteL(); |
|
470 CleanupStack::PopAndDestroy(op); |
|
471 iLog->Log(_L("ExportWithCollectionDataL Done")); |
|
472 } |
|
473 |
|
474 // --------------------------------------------------------- |
|
475 // CPosTp45::ExportAndCancelL |
|
476 // |
|
477 // (other items were commented in a header). |
|
478 // --------------------------------------------------------- |
|
479 // |
|
480 void CPosTp45::ExportAndCancelL(const TDesC& aFileName, |
|
481 const TBool& aInCallback, |
|
482 CPosLandmarkDatabase::TTransferOptions aTransferOptions) |
|
483 { |
|
484 iLog->Log(_L("ExportAndCancelL")); |
|
485 TBuf<100> file; |
|
486 //file.Append(KTargetPath); |
|
487 file.Append(aFileName); |
|
488 |
|
489 DeleteFile(file); |
|
490 iLandmarkEncoder->SetOutputFileL(file); |
|
491 |
|
492 CPosLmItemIterator* iter = iDatabase->LandmarkIteratorL(); |
|
493 CleanupStack::PushL(iter); |
|
494 |
|
495 RArray<TPosLmItemId> arrayOfIds; |
|
496 CleanupClosePushL(arrayOfIds); |
|
497 |
|
498 TInt numberOfElements = iter->NumOfItemsL(); |
|
499 iter->GetItemIdsL(arrayOfIds, 0, (numberOfElements)); |
|
500 |
|
501 if (aInCallback) |
|
502 { |
|
503 RunAsyncOperationAndCancelInCallbackLD(iDatabase->ExportLandmarksL(*iLandmarkEncoder, arrayOfIds, aTransferOptions)); |
|
504 } |
|
505 else |
|
506 { |
|
507 RunAsyncOperationAndCancelLD(iDatabase->ExportLandmarksL(*iLandmarkEncoder, arrayOfIds, aTransferOptions)); |
|
508 } |
|
509 |
|
510 CPosLmOperation* op = iLandmarkEncoder->FinalizeEncodingL(); |
|
511 CleanupStack::PushL(op); |
|
512 op->ExecuteL(); |
|
513 |
|
514 CleanupStack::PopAndDestroy(3, iter); |
|
515 iLog->Log(_L("ExportAndCancelL Done")); |
|
516 } |
|
517 |
|
518 // --------------------------------------------------------- |
|
519 // CPosTp45::VerifyCancelL |
|
520 // |
|
521 // (other items were commented in a header). |
|
522 // --------------------------------------------------------- |
|
523 // |
|
524 void CPosTp45::VerifyCancelL(const TDesC& aFileName, const TInt aMaxExported) |
|
525 { |
|
526 iLog->Log(_L("VerifyCancelL")); |
|
527 TBuf<100> file; |
|
528 file.Append(aFileName); |
|
529 |
|
530 CPosLandmarkParser* parser = CPosLandmarkParser::NewL(KLmxMimeType); |
|
531 CleanupStack::PushL(parser); |
|
532 |
|
533 parser->SetInputFileL(file); |
|
534 |
|
535 CPosLmOperation* op = parser->ParseContentL(); |
|
536 CleanupStack::PushL(op); |
|
537 |
|
538 op->ExecuteL(); |
|
539 |
|
540 TInt parsed = parser->NumOfParsedLandmarks(); |
|
541 AssertTrueSecL(aMaxExported > parsed , _L("More than %d landmarks have been exported when cancelled"), aMaxExported); |
|
542 |
|
543 CleanupStack::PopAndDestroy(2, parser); |
|
544 iLog->Log(_L("VerifyCancelL Done")); |
|
545 } |
|
546 |
|
547 // --------------------------------------------------------- |
|
548 // CPosTp45::TestErrorCodesL |
|
549 // |
|
550 // (other items were commented in a header). |
|
551 // --------------------------------------------------------- |
|
552 // |
|
553 void CPosTp45::TestErrorCodesL() |
|
554 { |
|
555 iLog->Log(_L("TestErrorCodesL")); |
|
556 _LIT(KNotFoundErr, "Incorrect error code %d returned from ExecuteL when executed with Lm id not in db"); |
|
557 |
|
558 CPosLmItemIterator* iter = iDatabase->LandmarkIteratorL(); |
|
559 CleanupStack::PushL(iter); |
|
560 |
|
561 RArray<TPosLmItemId> arrayOfIds; |
|
562 CleanupClosePushL(arrayOfIds); |
|
563 |
|
564 TInt numberOfElements = iter->NumOfItemsL(); |
|
565 iter->GetItemIdsL(arrayOfIds, 0, (numberOfElements)); |
|
566 |
|
567 arrayOfIds.Append(666); |
|
568 |
|
569 DeleteFile( KTmpFile ); |
|
570 |
|
571 iLog->Log(_L("SetOutputFileL")); |
|
572 iLandmarkEncoder->SetOutputFileL( KTmpFile ); |
|
573 iLog->Log(_L("After SetOutputFileL")); |
|
574 |
|
575 CPosLmOperation* op = iDatabase->ExportLandmarksL(*iLandmarkEncoder, arrayOfIds, CPosLandmarkDatabase::EDefaultOptions); |
|
576 |
|
577 TRAPD(err, op->ExecuteL()); |
|
578 delete op; |
|
579 |
|
580 CleanupStack::PopAndDestroy(2, iter); |
|
581 |
|
582 AssertTrueSecL(err == KErrNotFound, KNotFoundErr, err); |
|
583 |
|
584 iLog->Log(_L("TestErrorCodesL Done")); |
|
585 } |
|
586 |
|
587 |
|
588 // --------------------------------------------------------- |
|
589 // CPosTp45::AddLandmarksL |
|
590 // |
|
591 // (other items were commented in a header). |
|
592 // --------------------------------------------------------- |
|
593 // |
|
594 void CPosTp45::AddLandmarksL() |
|
595 { |
|
596 iLog->Log(_L("AddLandmarksL")); |
|
597 CPosLandmark* lm = CreateXMLLandmarkLC(_L("TP45 - LM with all fields set")); |
|
598 AddAllXMLFieldsL(lm); |
|
599 iDatabase->AddLandmarkL(*lm); |
|
600 |
|
601 CPosLandmark* lm2 = CPosLandmark::NewLC(); |
|
602 lm2->SetLandmarkNameL(_L("TP45 - LM, only name set")); |
|
603 iDatabase->AddLandmarkL(*lm2); |
|
604 |
|
605 CPosLandmark* lm3 = CreateLandmarkLC(_L("TP45 - LM with categories")); |
|
606 iDatabase->AddLandmarkL(*lm3); |
|
607 |
|
608 CPosLandmark* lm4 = CPosLandmark::NewLC(); |
|
609 lm4->SetLandmarkNameL(_L("TP45 - LM with Global categories")); |
|
610 lm4->AddCategoryL(KGlobalCategoryId); |
|
611 lm4->AddCategoryL(KGlobalCategoryId2); |
|
612 iDatabase->AddLandmarkL(*lm4); |
|
613 |
|
614 CleanupStack::PopAndDestroy(4, lm); |
|
615 } |
|
616 |
|
617 // --------------------------------------------------------- |
|
618 // CPosTp45::RenameGlobalCategoryL() |
|
619 // |
|
620 // (other items were commented in a header). |
|
621 // --------------------------------------------------------- |
|
622 // |
|
623 void CPosTp45::RenameGlobalCategoryL() |
|
624 { |
|
625 /* |
|
626 * Rename a global category |
|
627 */ |
|
628 |
|
629 TBuf<150>info; |
|
630 // Get sample global category info |
|
631 TPosLmItemId catId(0); |
|
632 |
|
633 CPosLandmarkCategory* category = NULL; |
|
634 catId = iCategoryManager->GetGlobalCategoryL( KAccommodation ); |
|
635 category = iCategoryManager->ReadCategoryLC( catId ); |
|
636 category->SetCategoryNameL(_L("TP45 - Renamed global")); |
|
637 iCategoryManager->UpdateCategoryL( *category ); |
|
638 |
|
639 CleanupStack::PopAndDestroy( category ); |
|
640 } |
|
641 |
|
642 // --------------------------------------------------------- |
|
643 // CPosTp45::ExportToFileWithLongFileNameL |
|
644 // |
|
645 // (other items were commented in a header). |
|
646 // --------------------------------------------------------- |
|
647 // |
|
648 void CPosTp45::ExportToFileWithLongFileNameL() |
|
649 { |
|
650 iLog->Log(_L("ExportToFileWithLongFileNameL")); |
|
651 |
|
652 #ifndef __WINS__ |
|
653 DeleteFileL(KLongFileName); |
|
654 DeleteFileL(KLongFileName2); |
|
655 #endif |
|
656 |
|
657 // 1) Create an encoder object |
|
658 delete iLandmarkEncoder; |
|
659 iLandmarkEncoder = NULL; |
|
660 iLandmarkEncoder = CPosLandmarkEncoder::NewL(KLmxMimeType); |
|
661 |
|
662 TInt errorsFound=KErrNone; |
|
663 |
|
664 // 2) Set file with long filename (more than 255 characters) |
|
665 TRAPD(err, iLandmarkEncoder->SetOutputFileL(KLongFileName)); |
|
666 TInt expErr; |
|
667 |
|
668 #ifdef __WINS__ |
|
669 expErr = KErrBadName; |
|
670 if (err != KErrBadName) |
|
671 #else |
|
672 expErr = KErrNone; |
|
673 if (err != KErrNone) |
|
674 #endif |
|
675 { |
|
676 TBuf<100> buf; |
|
677 buf.Format(_L("SetOutputFileL should leave with %d, instead err:%d"),expErr, err); |
|
678 errorsFound++; |
|
679 iLog->Log(buf); |
|
680 } |
|
681 |
|
682 // 3) Set file with long filename (more than 255 characters) |
|
683 TRAP(err, iLandmarkEncoder->SetOutputFileL(KLongFileName2)); |
|
684 #ifdef __WINS__ |
|
685 expErr = KErrBadName; |
|
686 if (err != KErrBadName) |
|
687 #else |
|
688 expErr = KErrAlreadyExists; |
|
689 if (err != KErrAlreadyExists) |
|
690 #endif |
|
691 { |
|
692 TBuf<100> buf; |
|
693 buf.Format(_L("SetOutputFileL(2) should leave with %d, instead err:%d"), expErr, err); |
|
694 //LogErrorAndLeave(buf); |
|
695 errorsFound++; |
|
696 iLog->Log(buf); |
|
697 } |
|
698 |
|
699 if (errorsFound != KErrNone) |
|
700 { |
|
701 iLog->Log(_L("Wrong error code from SetOutputFileL")); |
|
702 User::Leave(-1); |
|
703 } |
|
704 |
|
705 iLog->Log(_L("ExportToFileWithLongFileNameL Done")); |
|
706 } |
|
707 |
|
708 // --------------------------------------------------------- |
|
709 // CPosTp45::DeleteFile |
|
710 // |
|
711 // (other items were commented in a header). |
|
712 // --------------------------------------------------------- |
|
713 // |
|
714 void CPosTp45::DeleteFile(const TDesC& aFile) |
|
715 { |
|
716 TInt err = iFileSession.Delete(aFile); |
|
717 if (err != KErrNone) |
|
718 { |
|
719 TBuf<100> buf; |
|
720 buf.Format(_L("Delete of file %S failed with error %d"), &aFile, err); |
|
721 iLog->Log(buf); |
|
722 } |
|
723 } |
|
724 |
|
725 |
|
726 void CPosTp45::MakeEmptyLmDatabaseL( CPosLandmarkDatabase& aLdb, |
|
727 CPosLmCategoryManager& aCatMgr ) |
|
728 { |
|
729 |
|
730 CPosLmOperation* operation1 = aLdb.RemoveAllLandmarksL(); |
|
731 //Remove all landmarks from default db : Sync call |
|
732 ExecuteAndDeleteLD( operation1 ); |
|
733 |
|
734 RArray<TPosLmItemId> catArray; |
|
735 CleanupClosePushL( catArray ); |
|
736 |
|
737 // Get all the categories from the database and delete them if necessary |
|
738 CPosLmItemIterator* iter = aCatMgr.CategoryIteratorL(); |
|
739 CleanupStack::PushL( iter ); |
|
740 |
|
741 TUint count = iter->NumOfItemsL(); |
|
742 if ( count > 0 ) |
|
743 { // can only be called if there are some items |
|
744 iter->GetItemIdsL( catArray, 0, count ); |
|
745 } |
|
746 |
|
747 // Remove all the categories here Sync call |
|
748 ExecuteAndDeleteLD(aCatMgr.RemoveCategoriesL( catArray )); |
|
749 CleanupStack::PopAndDestroy( 2 ); // catArray, iter |
|
750 } |
|
751 |
|
752 void CPosTp45::AddCategoriesL() |
|
753 { |
|
754 _LIT(KName, "CategoryTP45 - %d"); |
|
755 TInt err=KErrLocked; |
|
756 for (TInt i=0; i<KNoCategoriesTp45; i++) |
|
757 { |
|
758 TBuf<100> categoryName; |
|
759 categoryName.Format(KName,i); |
|
760 |
|
761 CPosLandmarkCategory* lmc = CPosLandmarkCategory::NewLC(); |
|
762 lmc->SetCategoryNameL(categoryName); |
|
763 err = KErrLocked; |
|
764 while (err == KErrLocked) |
|
765 { |
|
766 TRAP(err, iCategoryManager->AddCategoryL(*lmc)); |
|
767 } |
|
768 |
|
769 iCategories.Append(lmc); |
|
770 CleanupStack::Pop(lmc); |
|
771 } |
|
772 iLog->Log(_L("Adding categories to database done ")); |
|
773 } |
|
774 |
|
775 // --------------------------------------------------------- |
|
776 // CPosTp45::SetupGlobalCategoriesL() |
|
777 // |
|
778 // (other items were commented in a header). |
|
779 // --------------------------------------------------------- |
|
780 // |
|
781 void CPosTp45::SetupGlobalCategoriesL() |
|
782 { |
|
783 // Testing with only 3 global categories |
|
784 iGlobalCategoryNames.Append(_L("Accommodation")); |
|
785 iGlobalCategoryIds.Append(3000); |
|
786 |
|
787 /*iGlobalCategoryNames.Append(_L("Business")); |
|
788 iGlobalCategoryIds.Append(6000); |
|
789 |
|
790 iGlobalCategoryNames.Append(_L("Communication")); |
|
791 iGlobalCategoryIds.Append(9000);*/ |
|
792 |
|
793 iGlobalCategoryNames.Append(_L("Entertainment")); |
|
794 iGlobalCategoryIds.Append(15000); |
|
795 |
|
796 iGlobalCategoryNames.Append(_L("People")); |
|
797 iGlobalCategoryIds.Append(27000); |
|
798 |
|
799 iGlobalCategoryTestNames.Append(_L("Housing")); |
|
800 iGlobalCategoryTestNames.Append(_L("Movie")); |
|
801 iGlobalCategoryTestNames.Append(_L("Society")); |
|
802 } |
|
803 |
|
804 |
|
805 // End of File |