|
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_CPosTp10.h" |
|
23 #include <EPos_CPosLandmarkDatabase.h> |
|
24 #include <EPos_CPosLandmarkCategory.h> |
|
25 #include <EPos_CPosLandmark.h> |
|
26 #include <EPos_CPosLMOperation.h> |
|
27 #include <e32math.h> |
|
28 |
|
29 #include "FT_LandmarkConstants.h" |
|
30 |
|
31 // CONSTANTS |
|
32 const TInt KNoCategoriesTp10 = 100; |
|
33 const TInt KNoLandmarksTp10 = 100; |
|
34 |
|
35 const TInt KAddStartIndex=5; |
|
36 const TInt KAddEndIndex=20; |
|
37 const TInt KAddCategoryIndex=8; |
|
38 |
|
39 const TInt KAddStartIndexAsync=21; |
|
40 const TInt KAddEndIndexAsync=82; |
|
41 const TInt KAddCategoryIndexAsync=10; |
|
42 |
|
43 const TInt KRemoveStartIndex=85; |
|
44 const TInt KRemoveEndIndex=95; |
|
45 |
|
46 const TInt KRemoveStartIndexAsync=75; |
|
47 const TInt KRemoveEndIndexAsync=84; |
|
48 |
|
49 const TInt KRemoveSetStartIndex=50; |
|
50 const TInt KRemoveSetEndIndex=74; |
|
51 |
|
52 const TInt KRemoveSetStartIndexAsync=0; |
|
53 const TInt KRemoveSetEndIndexAsync=49; |
|
54 |
|
55 |
|
56 |
|
57 // ================= MEMBER FUNCTIONS ======================= |
|
58 |
|
59 |
|
60 // --------------------------------------------------------- |
|
61 // CPosTp10::StartL |
|
62 // |
|
63 // (other items were commented in a header). |
|
64 // --------------------------------------------------------- |
|
65 // |
|
66 void CPosTp10::StartL() |
|
67 { |
|
68 _LIT(KLogFileName, "c:\\documents\\TP10TimeMeasurements.txt"); |
|
69 |
|
70 RemoveDefaultDbL(); |
|
71 RemoveAllLmDatabasesL(); |
|
72 // Test LMREQ121 below |
|
73 TestMissingCategories1L(); |
|
74 RemoveDefaultDbL(); |
|
75 RemoveAllLmDatabasesL(); |
|
76 TestMissingCategories2L(); |
|
77 |
|
78 RemoveDefaultDbL(); |
|
79 RemoveAllLmDatabasesL(); |
|
80 |
|
81 _LIT(KTestPath, "c:\\system\\test\\testdata\\"); |
|
82 // copy the test db to the private path |
|
83 CFileMan* fileMan = CFileMan::NewL(iFileSession); |
|
84 CleanupStack::PushL(fileMan); |
|
85 |
|
86 TBuf<150> srcPath; |
|
87 |
|
88 srcPath.Append(KTestPath); |
|
89 srcPath.Append(KTp10TestDb); |
|
90 |
|
91 TInt err = fileMan->Copy(srcPath, KLmTp10DefaultDbPath, |
|
92 CFileMan::EOverWrite); |
|
93 if (err != KErrNone) |
|
94 iLog->Log(_L("Error when copying file")); |
|
95 |
|
96 CleanupStack::PopAndDestroy(fileMan); |
|
97 CPosLmDatabaseManager* manager = CPosLmDatabaseManager::NewL(); |
|
98 CleanupStack::PushL(manager); |
|
99 |
|
100 // This db must exist |
|
101 manager->SetDefaultDatabaseUriL(KTp10TestDb); |
|
102 CleanupStack::PopAndDestroy(manager); |
|
103 |
|
104 iDatabase= CPosLandmarkDatabase::OpenL(KTp10TestDb); |
|
105 if (iDatabase->IsInitializingNeeded()) |
|
106 { |
|
107 ExecuteAndDeleteLD(iDatabase->InitializeL()); // Synchronous since no argument |
|
108 } |
|
109 |
|
110 TTime start, stop, totalStart, totalStop; |
|
111 totalStart.UniversalTime(); |
|
112 |
|
113 start.UniversalTime(); |
|
114 iCategoryManager = CPosLmCategoryManager::NewL(*iDatabase); |
|
115 stop.UniversalTime(); |
|
116 |
|
117 TInt64 msec = (stop.Int64() - start.Int64()); |
|
118 TBuf8<KMsgBufSize> msg; |
|
119 _LIT8(KTrace, "CPosLmCategoryManager::NewL = %d usec"); |
|
120 msg.Format(KTrace, msec); |
|
121 LogToFileL(KLogFileName, msg); |
|
122 |
|
123 // Add Category |
|
124 start.UniversalTime(); |
|
125 AddCategoriesL(); |
|
126 stop.UniversalTime(); |
|
127 |
|
128 msec = (stop.Int64() - start.Int64())/1000; |
|
129 _LIT8(KTrace2, "AddCategoriesL = %d msec"); |
|
130 msg.Format(KTrace2, msec); |
|
131 LogToFileL(KLogFileName, msg); |
|
132 |
|
133 // Read Category |
|
134 start.UniversalTime(); |
|
135 ReadCategoriesL(); |
|
136 stop.UniversalTime(); |
|
137 |
|
138 msec = (stop.Int64() - start.Int64())/1000; |
|
139 _LIT8(KTrace3, "ReadCategoriesL = %d msec"); |
|
140 msg.Format(KTrace3, msec); |
|
141 LogToFileL(KLogFileName, msg); |
|
142 |
|
143 // Update Category |
|
144 start.UniversalTime(); |
|
145 UpdateCategoriesL(); |
|
146 stop.UniversalTime(); |
|
147 |
|
148 msec = (stop.Int64() - start.Int64())/1000; |
|
149 _LIT8(KTrace4, "UpdateCategoriesL = %d msec"); |
|
150 msg.Format(KTrace4, msec); |
|
151 LogToFileL(KLogFileName, msg); |
|
152 |
|
153 ReadCategoriesL(); |
|
154 AddLandmarksL(); |
|
155 |
|
156 // Add Categories to LM synch |
|
157 start.UniversalTime(); |
|
158 AddCategoriesToLandmarksL(); |
|
159 stop.UniversalTime(); |
|
160 |
|
161 msec = (stop.Int64() - start.Int64())/1000; |
|
162 _LIT8(KTrace5, "AddCategoriesToLandmarksL = %d msec"); |
|
163 msg.Format(KTrace5, msec); |
|
164 LogToFileL(KLogFileName, msg); |
|
165 |
|
166 // Add Categories to LM asynch |
|
167 start.UniversalTime(); |
|
168 AddCategoriesToLandmarksAsyncL(); |
|
169 stop.UniversalTime(); |
|
170 |
|
171 msec = (stop.Int64() - start.Int64())/1000; |
|
172 _LIT8(KTrace6, "AddCategoriesToLandmarksAsyncL = %d msec"); |
|
173 msg.Format(KTrace6, msec); |
|
174 LogToFileL(KLogFileName, msg); |
|
175 |
|
176 AddCategoriesToLandmarksAsyncErrCheckL(); |
|
177 |
|
178 // Add Categories to LM using WaitForReq |
|
179 start.UniversalTime(); |
|
180 AddCategoriesToLandmarksUsingWaitForReqL(); |
|
181 stop.UniversalTime(); |
|
182 |
|
183 msec = (stop.Int64() - start.Int64())/1000; |
|
184 _LIT8(KTrace6b, "AddCategoriesToLandmarksUsingWaitForReqL = %d msec"); |
|
185 msg.Format(KTrace6b, msec); |
|
186 LogToFileL(KLogFileName, msg); |
|
187 |
|
188 AddCategoriesToLandmarksAsyncErrCheckL(); |
|
189 |
|
190 // Remove Category synchronously |
|
191 ExecuteAndDeleteLD(iDatabase->CompactL()); |
|
192 start.UniversalTime(); |
|
193 RemoveCategoryL(); |
|
194 stop.UniversalTime(); |
|
195 |
|
196 msec = (stop.Int64() - start.Int64())/1000; |
|
197 _LIT8(KTrace7, "RemoveCategoryL = %d msec"); |
|
198 msg.Format(KTrace7, msec); |
|
199 LogToFileL(KLogFileName, msg); |
|
200 |
|
201 // Remove Category asynchronously |
|
202 start.UniversalTime(); |
|
203 RemoveCategoryAsyncL(); |
|
204 stop.UniversalTime(); |
|
205 ExecuteAndDeleteLD(iDatabase->CompactL()); |
|
206 |
|
207 msec = (stop.Int64() - start.Int64())/1000; |
|
208 _LIT8(KTrace8, "RemoveCategoryAsyncL = %d msec"); |
|
209 msg.Format(KTrace8, msec); |
|
210 LogToFileL(KLogFileName, msg); |
|
211 |
|
212 // Remove Category using WaitForRequest |
|
213 start.UniversalTime(); |
|
214 RemoveCategoryUsingWaitForReqL(); |
|
215 stop.UniversalTime(); |
|
216 ExecuteAndDeleteLD(iDatabase->CompactL()); |
|
217 |
|
218 msec = (stop.Int64() - start.Int64())/1000; |
|
219 _LIT8(KTrace8b, "RemoveCategoryUsingWaitForReqL = %d msec"); |
|
220 msg.Format(KTrace8b, msec); |
|
221 LogToFileL(KLogFileName, msg); |
|
222 |
|
223 // Remove set of categories synchronously |
|
224 start.UniversalTime(); |
|
225 RemoveSetOfCategoriesL(); |
|
226 stop.UniversalTime(); |
|
227 ExecuteAndDeleteLD(iDatabase->CompactL()); |
|
228 |
|
229 msec = (stop.Int64() - start.Int64())/1000; |
|
230 _LIT8(KTrace9, "RemoveSetOfCategoriesL = %d msec"); |
|
231 msg.Format(KTrace9, msec); |
|
232 LogToFileL(KLogFileName, msg); |
|
233 |
|
234 // Remove set of categories asynchronously |
|
235 start.UniversalTime(); |
|
236 RemoveSetOfCategoriesAsyncL(); |
|
237 stop.UniversalTime(); |
|
238 ExecuteAndDeleteLD(iDatabase->CompactL()); |
|
239 |
|
240 msec = (stop.Int64() - start.Int64())/1000; |
|
241 _LIT8(KTrace10, "RemoveSetOfCategoriesAsyncL = %d msec"); |
|
242 msg.Format(KTrace10, msec); |
|
243 LogToFileL(KLogFileName, msg); |
|
244 |
|
245 // Remove set of categories using WaitForRequest |
|
246 start.UniversalTime(); |
|
247 RemoveSetOfCategoriesUsingWaitForReqL(); |
|
248 stop.UniversalTime(); |
|
249 ExecuteAndDeleteLD(iDatabase->CompactL()); |
|
250 |
|
251 msec = (stop.Int64() - start.Int64())/1000; |
|
252 _LIT8(KTrace10b, "RemoveSetOfCategoriesUsingWaitForReqL = %d msec"); |
|
253 msg.Format(KTrace10b, msec); |
|
254 LogToFileL(KLogFileName, msg); |
|
255 |
|
256 // Remove category from set of landmarks synchronously |
|
257 iCategories.ResetAndDestroy(); |
|
258 AddCategoriesL(); |
|
259 AddCategoriesToLandmarksL(); |
|
260 ExecuteAndDeleteLD(iDatabase->CompactL()); |
|
261 |
|
262 start.UniversalTime(); |
|
263 RemoveCategoryFromSetOfLandmarksL(); |
|
264 stop.UniversalTime(); |
|
265 |
|
266 msec = (stop.Int64() - start.Int64())/1000; |
|
267 _LIT8(KTrace11, "RemoveCategoryFromSetOfLandmarksL = %d msec"); |
|
268 msg.Format(KTrace11, msec); |
|
269 LogToFileL(KLogFileName, msg); |
|
270 |
|
271 // Remove category from set of landmarks asynchronously |
|
272 start.UniversalTime(); |
|
273 RemoveCategoryFromSetOfLandmarksAsyncL(); |
|
274 stop.UniversalTime(); |
|
275 ExecuteAndDeleteLD(iDatabase->CompactL()); |
|
276 |
|
277 msec = (stop.Int64() - start.Int64())/1000; |
|
278 _LIT8(KTrace12, "RemoveCategoryFromSetOfLandmarksAsyncL = %d msec"); |
|
279 msg.Format(KTrace12, msec); |
|
280 LogToFileL(KLogFileName, msg); |
|
281 |
|
282 // Remove category from set of landmarks using User::WaitForRequest() |
|
283 start.UniversalTime(); |
|
284 RemoveCategoryFromSetOfLandmarksUsingWaitForReqL(); |
|
285 stop.UniversalTime(); |
|
286 ExecuteAndDeleteLD(iDatabase->CompactL()); |
|
287 |
|
288 msec = (stop.Int64() - start.Int64())/1000; |
|
289 _LIT8(KTrace12b, "RemoveCategoryFromSetOfLandmarksUsingWaitForReqL = %d msec"); |
|
290 msg.Format(KTrace12b, msec); |
|
291 LogToFileL(KLogFileName, msg); |
|
292 |
|
293 AddCategoriesToLandmarksL(); |
|
294 delete iDatabase; |
|
295 iDatabase=NULL; |
|
296 delete iCategoryManager; |
|
297 iCategoryManager = NULL; |
|
298 |
|
299 iLog->Log(_L("BEFORE : BackupDbFileL")); |
|
300 iDatabase = BackupTp10DbFileL(); |
|
301 iLog->Log(_L("AFTER : BackupDbFileL")); |
|
302 if (iDatabase->IsInitializingNeeded()) |
|
303 { |
|
304 ExecuteAndDeleteLD(iDatabase->InitializeL()); |
|
305 } |
|
306 iCategoryManager = CPosLmCategoryManager::NewL(*iDatabase); |
|
307 |
|
308 // Cancel tests immediately |
|
309 iLog->Log(_L("TESTS BELOW ARE TESTING CANCEL")); |
|
310 AddCategoriesToLandmarksAsyncAndCancelL(); |
|
311 RemoveCategoryAsyncAndCancelL(); |
|
312 RemoveSetOfCategoriesAsyncAndCancelL(); |
|
313 RemoveCategoryFromSetOfLandmarksAsyncAndCancelL(); |
|
314 |
|
315 // Cancel tests after a while |
|
316 iLog->Log(_L("TESTS BELOW ARE CANCEL IN CALLBACK")); |
|
317 delete iDatabase; |
|
318 iDatabase=NULL; |
|
319 |
|
320 |
|
321 iLog->Log(_L("BEFORE : RestoreDbFileL")); |
|
322 iDatabase = RestoreTp10DbFileL(); |
|
323 iLog->Log(_L("AFTER : RestoreDbFileL")); |
|
324 |
|
325 |
|
326 if (iDatabase->IsInitializingNeeded()) |
|
327 { |
|
328 ExecuteAndDeleteLD(iDatabase->InitializeL()); |
|
329 } |
|
330 delete iCategoryManager; |
|
331 iCategoryManager = NULL; |
|
332 iCategoryManager = CPosLmCategoryManager::NewL(*iDatabase); |
|
333 |
|
334 ExecuteAndDeleteLD(iDatabase->CompactL()); |
|
335 AddCategoriesToLandmarksAsyncAndCancelL(ETrue); |
|
336 RemoveCategoryAsyncAndCancelL(ETrue); |
|
337 RemoveSetOfCategoriesAsyncAndCancelL(ETrue); |
|
338 delete iDatabase; |
|
339 iDatabase=NULL; |
|
340 iDatabase = RestoreTp10DbFileL(); |
|
341 |
|
342 if (iDatabase->IsInitializingNeeded()) |
|
343 { |
|
344 ExecuteAndDeleteLD(iDatabase->InitializeL()); |
|
345 } |
|
346 delete iCategoryManager; |
|
347 iCategoryManager = NULL; |
|
348 iCategoryManager = CPosLmCategoryManager::NewL(*iDatabase); |
|
349 ExecuteAndDeleteLD(iDatabase->CompactL()); |
|
350 RemoveCategoryFromSetOfLandmarksAsyncAndCancelL(ETrue); |
|
351 |
|
352 |
|
353 totalStop.UniversalTime(); |
|
354 msec = (totalStop.Int64() - totalStart.Int64())/1000; |
|
355 _LIT8(KTrace13, "Complete test case = %d msec"); |
|
356 msg.Format(KTrace13, msec); |
|
357 LogToFileL(KLogFileName, msg); |
|
358 |
|
359 } |
|
360 |
|
361 // --------------------------------------------------------- |
|
362 // CPosTp10::CloseTest |
|
363 // |
|
364 // (other items were commented in a header). |
|
365 // --------------------------------------------------------- |
|
366 // |
|
367 void CPosTp10::CloseTest() |
|
368 { |
|
369 iCategories.ResetAndDestroy(); |
|
370 iCategories.Close(); |
|
371 iLandmarks.ResetAndDestroy(); |
|
372 iLandmarks.Close(); |
|
373 delete iDatabase; |
|
374 iDatabase=NULL; |
|
375 delete iCategoryManager; |
|
376 iCategoryManager=NULL; |
|
377 } |
|
378 |
|
379 // --------------------------------------------------------- |
|
380 // CPosTp10::AddCategoriesL |
|
381 // |
|
382 // (other items were commented in a header). |
|
383 // --------------------------------------------------------- |
|
384 // |
|
385 void CPosTp10::AddCategoriesL() |
|
386 { |
|
387 iLog->Log(_L("Adding and copying categories")); |
|
388 _LIT(KAlreadyExistErr, "A category with the same name is already added so add should return KErrAlreadyExists"); |
|
389 _LIT(KNoNameErr, "The Category has no name so add should return KErrArgument"); |
|
390 |
|
391 _LIT(KCategoryName, "CategoryTP10 - %d"); |
|
392 |
|
393 TInt index=0; |
|
394 while (index < KNoCategoriesTp10) |
|
395 { |
|
396 TBuf<100> name; |
|
397 name.Format(KCategoryName, ++index); |
|
398 CPosLandmarkCategory* category = CreateCategoryLC(name); |
|
399 |
|
400 CPosLandmarkCategory* copy = CPosLandmarkCategory::NewLC(*category); |
|
401 name.Format(KCategoryName, ++index); |
|
402 copy->SetCategoryNameL(name); |
|
403 |
|
404 CPosLandmarkCategory* category2 = CPosLandmarkCategory::NewL(); |
|
405 CleanupStack::PushL(category2); |
|
406 name.Format(KCategoryName, ++index); |
|
407 category2->SetCategoryNameL(name); |
|
408 |
|
409 CPosLandmarkCategory* copy2 = CPosLandmarkCategory::NewL(*category2); |
|
410 CleanupStack::PushL(copy2); |
|
411 name.Format(KCategoryName, ++index); |
|
412 copy2->SetCategoryNameL(name); |
|
413 |
|
414 ExecuteAndDeleteLD(iDatabase->CompactL()); |
|
415 iCategoryManager->AddCategoryL(*category); |
|
416 iCategoryManager->AddCategoryL(*copy); |
|
417 iCategoryManager->AddCategoryL(*category2); |
|
418 iCategoryManager->AddCategoryL(*copy2); |
|
419 |
|
420 CPosLandmarkCategory* category3 = CPosLandmarkCategory::NewLC(); |
|
421 category3->SetCategoryNameL(name); |
|
422 |
|
423 TInt err = 0; |
|
424 TRAP(err, iCategoryManager->AddCategoryL(*category3)); |
|
425 AssertTrueSecL(err == KErrAlreadyExists, KAlreadyExistErr); |
|
426 CleanupStack::PopAndDestroy(category3); |
|
427 |
|
428 CPosLandmarkCategory* category4 = CPosLandmarkCategory::NewLC(); |
|
429 TRAP(err, iCategoryManager->AddCategoryL(*category3)); |
|
430 AssertTrueSecL(err == KErrArgument, KNoNameErr); |
|
431 CleanupStack::PopAndDestroy(category4); |
|
432 |
|
433 iCategories.Append(category); |
|
434 iCategories.Append(copy); |
|
435 iCategories.Append(category2); |
|
436 iCategories.Append(copy2); |
|
437 |
|
438 CleanupStack::Pop(4); |
|
439 } |
|
440 } |
|
441 |
|
442 // --------------------------------------------------------- |
|
443 // CPosTp10::CompareTwoCategoriesL |
|
444 // |
|
445 // (other items were commented in a header). |
|
446 // --------------------------------------------------------- |
|
447 // |
|
448 void CPosTp10::CompareTwoCategoriesL(TInt aIndex) |
|
449 { |
|
450 CPosLandmarkCategory* category = iCategoryManager->ReadCategoryLC(iCategories[aIndex]->CategoryId()); |
|
451 CompareCategoriesL(*iCategories[aIndex], *category); |
|
452 CleanupStack::PopAndDestroy(category); |
|
453 } |
|
454 |
|
455 // --------------------------------------------------------- |
|
456 // CPosTp10::ReadCategoriesL |
|
457 // |
|
458 // (other items were commented in a header). |
|
459 // --------------------------------------------------------- |
|
460 // |
|
461 void CPosTp10::ReadCategoriesL() |
|
462 { |
|
463 iLog->Log(_L("Reading categories")); |
|
464 _LIT(KReadNotFoundErr, "The category id doesn't exist so ReadCategory should return not found"); |
|
465 |
|
466 for (TInt i = 0; i<iCategories.Count(); i++) |
|
467 { |
|
468 |
|
469 TInt err = KErrLocked; |
|
470 while (err == KErrLocked) |
|
471 { |
|
472 TRAP(err, CompareTwoCategoriesL(i)); |
|
473 if (err == KErrLocked) |
|
474 { |
|
475 iLog->Log(_L("KErrLocked from CompareTwoCategoriesL, try again")); |
|
476 User::After(100000); |
|
477 } |
|
478 } |
|
479 } |
|
480 |
|
481 TPosLmItemId id = 5123321; |
|
482 |
|
483 CPosLandmarkCategory* category=NULL; |
|
484 TRAPD(err, category=iCategoryManager->ReadCategoryLC(id)); |
|
485 delete category; |
|
486 AssertTrueSecL(err == KErrNotFound, KReadNotFoundErr); |
|
487 } |
|
488 |
|
489 // --------------------------------------------------------- |
|
490 // CPosTp10::UpdateCategoriesL |
|
491 // |
|
492 // (other items were commented in a header). |
|
493 // --------------------------------------------------------- |
|
494 // |
|
495 void CPosTp10::UpdateCategoriesL() |
|
496 { |
|
497 iLog->Log(_L("Updating categories")); |
|
498 _LIT(KCategoryNameNotSetErr, "UpdateCategory does not leave with KErrArgumenet when name is not set"); |
|
499 _LIT(KCategoryExistsErr, "UpdateCategory does not leave with KErrAlreadyExist"); |
|
500 |
|
501 TInt err; |
|
502 ExecuteAndDeleteLD(iDatabase->CompactL()); |
|
503 CPosLandmarkCategory* category = CPosLandmarkCategory::NewLC(); |
|
504 TRAP(err, iCategoryManager->UpdateCategoryL(*category)); |
|
505 AssertTrueSecL(err == KErrArgument, KCategoryNameNotSetErr); |
|
506 CleanupStack::PopAndDestroy(category); |
|
507 |
|
508 CPosLandmarkCategory* category2 = CPosLandmarkCategory::NewLC(*iCategories[0]); |
|
509 |
|
510 TPtrC nameThatExist; |
|
511 User::LeaveIfError(iCategories[1]->GetCategoryName(nameThatExist)); |
|
512 category2->SetCategoryNameL(nameThatExist); |
|
513 TRAP(err, iCategoryManager->UpdateCategoryL(*category2)); |
|
514 AssertTrueSecL(err == KErrAlreadyExists, KCategoryExistsErr); |
|
515 CleanupStack::PopAndDestroy(category2); |
|
516 |
|
517 _LIT(KUpdatedCategoryName, "UpdatedCategoryTP10 - %d"); |
|
518 |
|
519 for (TInt i = 0; i<iCategories.Count(); i++) |
|
520 { |
|
521 TBuf<100> name; |
|
522 name.Format(KUpdatedCategoryName, i); |
|
523 iCategories[i]->SetCategoryNameL(name); |
|
524 iCategories[i]->SetIconL(KMbmFileName2, KIconIndex2, KPosLmIconMaskNotUsed); |
|
525 err = KErrLocked; |
|
526 while (err == KErrLocked) |
|
527 { |
|
528 TRAP(err, iCategoryManager->UpdateCategoryL(*iCategories[i])); |
|
529 } |
|
530 |
|
531 } |
|
532 } |
|
533 |
|
534 // --------------------------------------------------------- |
|
535 // CPosTp10::AddLandmarksL |
|
536 // |
|
537 // (other items were commented in a header). |
|
538 // --------------------------------------------------------- |
|
539 // |
|
540 void CPosTp10::AddLandmarksL() |
|
541 { |
|
542 iLog->Log(_L("Adding landmarks")); |
|
543 _LIT(KLmName, "LmTP10 - %d"); |
|
544 _LIT(KLmDescription, "LmTP10Description - %d"); |
|
545 |
|
546 for (TInt i=0; i<(KNoLandmarksTp10); i++) |
|
547 { |
|
548 TBuf<100> lmName; |
|
549 lmName.Format(KLmName,i); |
|
550 TBuf<100> lmDesc; |
|
551 lmDesc.Format(KLmDescription,i); |
|
552 |
|
553 CPosLandmark* landmark = CPosLandmark::NewLC(); |
|
554 landmark->SetLandmarkNameL(lmName); |
|
555 landmark->SetLandmarkDescriptionL(lmDesc); |
|
556 |
|
557 landmark->AddCategoryL(iCategories[i]->CategoryId()); |
|
558 |
|
559 TInt err=KErrLocked; |
|
560 while (err==KErrLocked) |
|
561 { |
|
562 TRAP(err, iDatabase->AddLandmarkL(*landmark)); |
|
563 } |
|
564 iLandmarks.Append(landmark); |
|
565 CleanupStack::Pop(); |
|
566 } |
|
567 } |
|
568 |
|
569 // --------------------------------------------------------- |
|
570 // CPosTp10::AddCategoriesToSetOfLandmarksL |
|
571 // |
|
572 // (other items were commented in a header). |
|
573 // --------------------------------------------------------- |
|
574 // |
|
575 void CPosTp10::AddCategoriesToLandmarksL() |
|
576 { |
|
577 iLog->Log(_L("Adding categories to landmarks")); |
|
578 |
|
579 RArray<TPosLmItemId> landmarksIds; |
|
580 CleanupClosePushL(landmarksIds); |
|
581 for(TInt i=KAddStartIndex; i<=KAddEndIndex; i++) |
|
582 { |
|
583 landmarksIds.Append(iLandmarks[i]->LandmarkId()); |
|
584 iLandmarks[i]->AddCategoryL(iCategories[KAddCategoryIndex]->CategoryId()); |
|
585 } |
|
586 |
|
587 // Add some invalid as well |
|
588 landmarksIds.Append(2000); |
|
589 landmarksIds.Append(3000); |
|
590 |
|
591 TInt err=KErrLocked; |
|
592 while (err==KErrLocked) |
|
593 { |
|
594 TRAP( err, ExecuteAndDeleteLD(iCategoryManager->AddCategoryToLandmarksL( |
|
595 iCategories[KAddCategoryIndex]->CategoryId(), |
|
596 landmarksIds)) ); |
|
597 } |
|
598 |
|
599 CleanupStack::PopAndDestroy(&landmarksIds); |
|
600 CheckLandmarksL(); |
|
601 } |
|
602 |
|
603 // --------------------------------------------------------- |
|
604 // CPosTp10::AddCategoriesToSetOfLandmarksL |
|
605 // |
|
606 // (other items were commented in a header). |
|
607 // --------------------------------------------------------- |
|
608 // |
|
609 void CPosTp10::AddCategoriesToLandmarksAsyncL() |
|
610 { |
|
611 iLog->Log(_L("Adding categories to landmarks asynchronously")); |
|
612 RArray<TPosLmItemId> landmarksIds; |
|
613 CleanupClosePushL(landmarksIds); |
|
614 |
|
615 for(TInt i=KAddStartIndexAsync; i<=KAddEndIndexAsync; i++) |
|
616 { |
|
617 landmarksIds.Append(iLandmarks[i]->LandmarkId()); |
|
618 iLandmarks[i]->AddCategoryL(iCategories[KAddCategoryIndexAsync]->CategoryId()); |
|
619 } |
|
620 |
|
621 |
|
622 RunAsyncOperationLD(iCategoryManager->AddCategoryToLandmarksL( |
|
623 iCategories[KAddCategoryIndexAsync]->CategoryId(), |
|
624 landmarksIds |
|
625 )); |
|
626 CheckLandmarksL(); |
|
627 |
|
628 CleanupStack::PopAndDestroy(&landmarksIds); |
|
629 } |
|
630 |
|
631 // --------------------------------------------------------- |
|
632 // CPosTp10::AddCategoriesToLandmarksUsingWaitForReqL |
|
633 // |
|
634 // (other items were commented in a header). |
|
635 // --------------------------------------------------------- |
|
636 // |
|
637 void CPosTp10::AddCategoriesToLandmarksUsingWaitForReqL() |
|
638 { |
|
639 iLog->Log(_L("AddCategoriesToLandmarksUsingWaitForReqL")); |
|
640 RArray<TPosLmItemId> landmarksIds; |
|
641 CleanupClosePushL(landmarksIds); |
|
642 |
|
643 for(TInt i=KAddStartIndexAsync; i<=KAddEndIndexAsync; i++) |
|
644 { |
|
645 landmarksIds.Append(iLandmarks[i]->LandmarkId()); |
|
646 iLandmarks[i]->AddCategoryL(iCategories[KAddCategoryIndexAsync]->CategoryId()); |
|
647 } |
|
648 |
|
649 CPosLmOperation* op = iCategoryManager->AddCategoryToLandmarksL( |
|
650 iCategories[KAddCategoryIndexAsync]->CategoryId(), |
|
651 landmarksIds); |
|
652 CleanupStack::PushL(op); |
|
653 RunAsyncOperationByWaitForReqL(op); |
|
654 CleanupStack::PopAndDestroy(op); |
|
655 |
|
656 CheckLandmarksL(); |
|
657 |
|
658 CleanupStack::PopAndDestroy(&landmarksIds); |
|
659 } |
|
660 |
|
661 // --------------------------------------------------------- |
|
662 // CPosTp10::AddCategoriesToSetOfLandmarksAndCancelL |
|
663 // |
|
664 // (other items were commented in a header). |
|
665 // --------------------------------------------------------- |
|
666 // |
|
667 void CPosTp10::AddCategoriesToLandmarksAsyncAndCancelL(const TBool& aInCallback) |
|
668 { |
|
669 iLog->Log(_L("Adding categories to landmarks asyncronously and cancel")); |
|
670 RArray<TPosLmItemId> landmarksIds; |
|
671 CleanupClosePushL(landmarksIds); |
|
672 |
|
673 for(TInt i=KAddStartIndexAsync; i<=KAddEndIndexAsync; i++) |
|
674 { |
|
675 landmarksIds.Append(iLandmarks[i]->LandmarkId()); |
|
676 iLandmarks[i]->AddCategoryL(iCategories[KAddCategoryIndexAsync]->CategoryId()); |
|
677 } |
|
678 |
|
679 if (aInCallback) |
|
680 { |
|
681 RunAsyncOperationAndCancelInCallbackLD(iCategoryManager->AddCategoryToLandmarksL( |
|
682 iCategories[KAddCategoryIndexAsync]->CategoryId(), |
|
683 landmarksIds |
|
684 )); |
|
685 } |
|
686 else |
|
687 { |
|
688 RunAsyncOperationAndCancelLD(iCategoryManager->AddCategoryToLandmarksL( |
|
689 iCategories[KAddCategoryIndexAsync]->CategoryId(), |
|
690 landmarksIds |
|
691 )); |
|
692 } |
|
693 |
|
694 CleanupStack::PopAndDestroy(&landmarksIds); |
|
695 } |
|
696 |
|
697 // --------------------------------------------------------- |
|
698 // CPosTp10::AddCategoriesToLandmarksAsyncErrCheckL |
|
699 // |
|
700 // (other items were commented in a header). |
|
701 // --------------------------------------------------------- |
|
702 // |
|
703 void CPosTp10::AddCategoriesToLandmarksAsyncErrCheckL() |
|
704 { |
|
705 iLog->Log(_L("Adding category not in db to landmarks async.")); |
|
706 |
|
707 _LIT(KNotFoundErr, "AddCategoryToLandmarksL is not returning -1 for a category id not in db"); |
|
708 |
|
709 TPosLmItemId idNotInDb = 5123321; |
|
710 |
|
711 RArray<TPosLmItemId> landmarksIds; |
|
712 CleanupClosePushL(landmarksIds); |
|
713 |
|
714 landmarksIds.Append(iLandmarks[0]->LandmarkId()); |
|
715 |
|
716 TRAPD(err, iOperation = iCategoryManager->AddCategoryToLandmarksL(idNotInDb, landmarksIds)); |
|
717 |
|
718 AssertTrueSecL(err == KErrNotFound, KNotFoundErr); |
|
719 |
|
720 |
|
721 iOperation = NULL; |
|
722 CleanupStack::PopAndDestroy(&landmarksIds); |
|
723 } |
|
724 |
|
725 // --------------------------------------------------------- |
|
726 // CPosTp10::CheckLandmarks |
|
727 // |
|
728 // (other items were commented in a header). |
|
729 // --------------------------------------------------------- |
|
730 // |
|
731 void CPosTp10::CheckLandmarksL() |
|
732 { |
|
733 for (TInt i = 0; i<iLandmarks.Count(); i++) |
|
734 { |
|
735 CPosLandmark* lm = iDatabase->ReadLandmarkLC(iLandmarks[i]->LandmarkId()); |
|
736 CompareLandmarksL(*iLandmarks[i], *lm); |
|
737 CleanupStack::PopAndDestroy(); // lm |
|
738 } |
|
739 } |
|
740 |
|
741 // --------------------------------------------------------- |
|
742 // CPosTp10::RemoveCategoryL |
|
743 // |
|
744 // (other items were commented in a header). |
|
745 // --------------------------------------------------------- |
|
746 // |
|
747 void CPosTp10::RemoveCategoryL() |
|
748 { |
|
749 iLog->Log(_L("Removing categories")); |
|
750 |
|
751 TInt i=0; |
|
752 for (i=0; i<iLandmarks.Count(); i++) |
|
753 { |
|
754 iLandmarks[i]->AddCategoryL(iCategories[KRemoveStartIndex]->CategoryId()); |
|
755 if (i % 2) |
|
756 { |
|
757 TInt index = 1+KRemoveStartIndex; |
|
758 iLandmarks[i]->AddCategoryL(iCategories[index]->CategoryId()); |
|
759 } |
|
760 } |
|
761 |
|
762 for (TInt j=0; j<2; j++) |
|
763 { |
|
764 for (i = KRemoveStartIndex; i <= KRemoveEndIndex; i++) |
|
765 { |
|
766 ExecuteAndDeleteLD(iCategoryManager->RemoveCategoryL(iCategories[i]->CategoryId())); |
|
767 } |
|
768 CheckRemovedL(KRemoveStartIndex, KRemoveEndIndex); |
|
769 } |
|
770 } |
|
771 |
|
772 // --------------------------------------------------------- |
|
773 // CPosTp10::RemoveCategoryAsyncL |
|
774 // |
|
775 // (other items were commented in a header). |
|
776 // --------------------------------------------------------- |
|
777 // |
|
778 void CPosTp10::RemoveCategoryAsyncL() |
|
779 { |
|
780 iLog->Log(_L("Removing categories asyncronously")); |
|
781 TInt i=0; |
|
782 for (i=0; i<iLandmarks.Count(); i++) |
|
783 { |
|
784 iLandmarks[i]->AddCategoryL(iCategories[KRemoveStartIndexAsync]->CategoryId()); |
|
785 if (i % 2) |
|
786 { |
|
787 TInt index = 1+KRemoveStartIndexAsync; |
|
788 iLandmarks[i]->AddCategoryL(iCategories[index]->CategoryId()); |
|
789 } |
|
790 } |
|
791 |
|
792 for (TInt j=0; j<2; j++) |
|
793 { |
|
794 for (i = KRemoveStartIndexAsync; i <= KRemoveEndIndexAsync; i++) |
|
795 { |
|
796 RunAsyncOperationLD(iCategoryManager->RemoveCategoryL(iCategories[i]->CategoryId())); |
|
797 } |
|
798 CheckRemovedL(KRemoveStartIndexAsync, KRemoveEndIndexAsync); |
|
799 } |
|
800 } |
|
801 |
|
802 // --------------------------------------------------------- |
|
803 // CPosTp10::RemoveCategoryUsingWaitForReqL |
|
804 // |
|
805 // (other items were commented in a header). |
|
806 // --------------------------------------------------------- |
|
807 // |
|
808 void CPosTp10::RemoveCategoryUsingWaitForReqL() |
|
809 { |
|
810 iLog->Log(_L("Removing categories using User::WaitForRequest")); |
|
811 TInt i=0; |
|
812 for (i=0; i<iLandmarks.Count(); i++) |
|
813 { |
|
814 iLandmarks[i]->AddCategoryL(iCategories[KRemoveStartIndexAsync]->CategoryId()); |
|
815 if (i % 2) |
|
816 { |
|
817 TInt index = 1+KRemoveStartIndexAsync; |
|
818 iLandmarks[i]->AddCategoryL(iCategories[index]->CategoryId()); |
|
819 } |
|
820 } |
|
821 |
|
822 for (TInt j=0; j<2; j++) |
|
823 { |
|
824 for (i = KRemoveStartIndexAsync; i <= KRemoveEndIndexAsync; i++) |
|
825 { |
|
826 CPosLmOperation* op = iCategoryManager->RemoveCategoryL(iCategories[i]->CategoryId()); |
|
827 CleanupStack::PushL(op); |
|
828 RunAsyncOperationByWaitForReqL(op); |
|
829 CleanupStack::PopAndDestroy(op); |
|
830 } |
|
831 CheckRemovedL(KRemoveStartIndexAsync, KRemoveEndIndexAsync); |
|
832 } |
|
833 } |
|
834 |
|
835 // --------------------------------------------------------- |
|
836 // CPosTp10::RemoveCategoryAsyncAndCancelL |
|
837 // |
|
838 // (other items were commented in a header). |
|
839 // --------------------------------------------------------- |
|
840 // |
|
841 void CPosTp10::RemoveCategoryAsyncAndCancelL(const TBool& aInCallback) |
|
842 { |
|
843 iLog->Log(_L("Removing categories asyncronously and cancel")); |
|
844 TInt i=0; |
|
845 for (i=0; i<iLandmarks.Count(); i++) |
|
846 { |
|
847 iLandmarks[i]->AddCategoryL(iCategories[KRemoveStartIndexAsync]->CategoryId()); |
|
848 if (i % 2) |
|
849 { |
|
850 TInt index = 1+KRemoveStartIndexAsync; |
|
851 iLandmarks[i]->AddCategoryL(iCategories[index]->CategoryId()); |
|
852 } |
|
853 } |
|
854 |
|
855 for (TInt j=0; j<2; j++) |
|
856 { |
|
857 for (i = KRemoveStartIndexAsync; i <= KRemoveEndIndexAsync; i++) |
|
858 { |
|
859 if (aInCallback) |
|
860 { |
|
861 RunAsyncOperationAndCancelInCallbackLD(iCategoryManager->RemoveCategoryL(iCategories[i]->CategoryId())); |
|
862 } |
|
863 else |
|
864 { |
|
865 RunAsyncOperationAndCancelLD(iCategoryManager->RemoveCategoryL(iCategories[i]->CategoryId())); |
|
866 } |
|
867 } |
|
868 } |
|
869 } |
|
870 |
|
871 // --------------------------------------------------------- |
|
872 // CPosTp10::RemoveSetOfCategoriesL |
|
873 // |
|
874 // (other items were commented in a header). |
|
875 // --------------------------------------------------------- |
|
876 // |
|
877 void CPosTp10::RemoveSetOfCategoriesL() |
|
878 { |
|
879 iLog->Log(_L("Removing set of categories")); |
|
880 |
|
881 RArray<TPosLmItemId> ids; |
|
882 CleanupClosePushL(ids); |
|
883 |
|
884 for (TInt i=KRemoveSetStartIndex; i<=KRemoveSetEndIndex; i++) |
|
885 { |
|
886 ids.Append(iCategories[i]->CategoryId()); |
|
887 } |
|
888 |
|
889 for (TInt j=0; j<2; j++) |
|
890 { |
|
891 ExecuteAndDeleteLD(iCategoryManager->RemoveCategoriesL(ids)); |
|
892 |
|
893 CheckRemovedL(KRemoveSetStartIndex, KRemoveSetEndIndex); |
|
894 } |
|
895 CleanupStack::PopAndDestroy(&ids); |
|
896 } |
|
897 |
|
898 // --------------------------------------------------------- |
|
899 // CPosTp10::RemoveSetOfCategoriesAsyncL |
|
900 // |
|
901 // (other items were commented in a header). |
|
902 // --------------------------------------------------------- |
|
903 // |
|
904 void CPosTp10::RemoveSetOfCategoriesAsyncL() |
|
905 { |
|
906 iLog->Log(_L("Removing set of categories asyncronously")); |
|
907 RArray<TPosLmItemId> ids; |
|
908 CleanupClosePushL(ids); |
|
909 |
|
910 TInt i=0; |
|
911 for (i=KRemoveSetStartIndexAsync; i<=KRemoveSetEndIndexAsync; i++) |
|
912 { |
|
913 ids.Append(iCategories[i]->CategoryId()); |
|
914 } |
|
915 |
|
916 for (TInt j=0; j<2; j++) |
|
917 { |
|
918 for (i = KRemoveSetStartIndexAsync; i <= KRemoveSetEndIndexAsync; i++) |
|
919 { |
|
920 TInt err = KErrLocked; |
|
921 while (err == KErrLocked) |
|
922 { |
|
923 TRAP(err, RunAsyncOperationLD(iCategoryManager->RemoveCategoriesL(ids))); |
|
924 } |
|
925 } |
|
926 CheckRemovedL(KRemoveSetStartIndexAsync, KRemoveSetEndIndexAsync); |
|
927 } |
|
928 CleanupStack::PopAndDestroy(&ids); |
|
929 } |
|
930 |
|
931 // --------------------------------------------------------- |
|
932 // CPosTp10::RemoveSetOfCategoriesUsingWaitForReqL |
|
933 // |
|
934 // (other items were commented in a header). |
|
935 // --------------------------------------------------------- |
|
936 // |
|
937 void CPosTp10::RemoveSetOfCategoriesUsingWaitForReqL() |
|
938 { |
|
939 iLog->Log(_L("Removing set of categories using User::WaitForRequest")); |
|
940 RArray<TPosLmItemId> ids; |
|
941 CleanupClosePushL(ids); |
|
942 |
|
943 TInt i=0; |
|
944 for (i=KRemoveSetStartIndexAsync; i<=KRemoveSetEndIndexAsync; i++) |
|
945 { |
|
946 ids.Append(iCategories[i]->CategoryId()); |
|
947 } |
|
948 |
|
949 // Add some unvalid ids as well |
|
950 ids.Append(222); |
|
951 ids.Append(223); |
|
952 |
|
953 for (TInt j=0; j<2; j++) |
|
954 { |
|
955 for (i = KRemoveSetStartIndexAsync; i <= KRemoveSetEndIndexAsync; i++) |
|
956 { |
|
957 CPosLmOperation* op = iCategoryManager->RemoveCategoriesL(ids); |
|
958 CleanupStack::PushL(op); |
|
959 RunAsyncOperationByWaitForReqL(op); |
|
960 CleanupStack::PopAndDestroy(op); |
|
961 } |
|
962 CheckRemovedL(KRemoveSetStartIndexAsync, KRemoveSetEndIndexAsync); |
|
963 } |
|
964 CleanupStack::PopAndDestroy(&ids); |
|
965 } |
|
966 |
|
967 // --------------------------------------------------------- |
|
968 // CPosTp10::RemoveSetOfCategoriesAsyncAndCancelL |
|
969 // |
|
970 // (other items were commented in a header). |
|
971 // --------------------------------------------------------- |
|
972 // |
|
973 void CPosTp10::RemoveSetOfCategoriesAsyncAndCancelL(const TBool& aInCallback) |
|
974 { |
|
975 iLog->Log(_L("Removing set of categories asyncronously and cancel")); |
|
976 RArray<TPosLmItemId> ids; |
|
977 CleanupClosePushL(ids); |
|
978 |
|
979 TInt i=0; |
|
980 for (i=KRemoveSetStartIndexAsync; i<=KRemoveSetEndIndexAsync; i++) |
|
981 { |
|
982 ids.Append(iCategories[i]->CategoryId()); |
|
983 } |
|
984 |
|
985 for (TInt j=0; j<2; j++) |
|
986 { |
|
987 for (i = KRemoveSetStartIndexAsync; i <= KRemoveSetEndIndexAsync; i++) |
|
988 { |
|
989 if (aInCallback) |
|
990 { |
|
991 RunAsyncOperationAndCancelInCallbackLD(iCategoryManager->RemoveCategoriesL(ids)); |
|
992 } |
|
993 else |
|
994 { |
|
995 RunAsyncOperationAndCancelLD(iCategoryManager->RemoveCategoriesL(ids)); |
|
996 } |
|
997 } |
|
998 } |
|
999 CleanupStack::PopAndDestroy(&ids); |
|
1000 } |
|
1001 |
|
1002 // --------------------------------------------------------- |
|
1003 // CPosTp10::RemoveCategoryFromSetOfLandmarksL |
|
1004 // |
|
1005 // (other items were commented in a header). |
|
1006 // --------------------------------------------------------- |
|
1007 // |
|
1008 void CPosTp10::RemoveCategoryFromSetOfLandmarksL() |
|
1009 { |
|
1010 iLog->Log(_L("Removing set of categories from landmarks")); |
|
1011 RArray<TPosLmItemId> ids; |
|
1012 CleanupClosePushL(ids); |
|
1013 |
|
1014 for (TInt i = KAddStartIndex; i<=KAddEndIndex; i++) |
|
1015 { |
|
1016 ids.Append(iLandmarks[i]->LandmarkId()); |
|
1017 |
|
1018 iLandmarks[i]->RemoveCategory(iCategories[KAddCategoryIndex]->CategoryId()); |
|
1019 } |
|
1020 // Append some non-existing as well |
|
1021 ids.Append(666); |
|
1022 ids.Append(667); |
|
1023 |
|
1024 for (TInt j=0; j<2; j++) |
|
1025 { |
|
1026 ExecuteAndDeleteLD( |
|
1027 iCategoryManager->RemoveCategoryFromLandmarksL( |
|
1028 iCategories[KAddCategoryIndex]->CategoryId(), |
|
1029 ids)); |
|
1030 |
|
1031 CheckLandmarksL(); |
|
1032 } |
|
1033 |
|
1034 // Test that RemoveCategoryFromLandmarksL leaves with KErrNotFound if |
|
1035 // category is not found |
|
1036 TRAPD(err, iCategoryManager->ReadCategoryLC(123456)); |
|
1037 if (err != KErrNotFound) |
|
1038 { |
|
1039 iLog->Log(_L("ReadCategoryLC should leave with KErrNotFound")); |
|
1040 User::Leave(err); |
|
1041 |
|
1042 } |
|
1043 TRAP(err, iOperation = iCategoryManager->RemoveCategoryFromLandmarksL(123456 ,ids)); |
|
1044 if (err == KErrNone) |
|
1045 { |
|
1046 delete iOperation; |
|
1047 iOperation = NULL; |
|
1048 iLog->Log(_L("RemoveCategoryFromLandmarksL should leave with KErrNotFound")); |
|
1049 User::Leave(err); |
|
1050 } |
|
1051 if (err != KErrNotFound) |
|
1052 { |
|
1053 iLog->Log(_L("RemoveCategoryFromLandmarksL should leave with KErrNotFound")); |
|
1054 User::Leave(err); |
|
1055 } |
|
1056 CleanupStack::PopAndDestroy(&ids); |
|
1057 } |
|
1058 |
|
1059 // --------------------------------------------------------- |
|
1060 // CPosTp10::RemoveCategoryFromSetOfLandmarksAsyncL |
|
1061 // |
|
1062 // (other items were commented in a header). |
|
1063 // --------------------------------------------------------- |
|
1064 // |
|
1065 void CPosTp10::RemoveCategoryFromSetOfLandmarksAsyncL() |
|
1066 { |
|
1067 iLog->Log(_L("Removing set of categories from landmarks asyncronously")); |
|
1068 RArray<TPosLmItemId> ids; |
|
1069 CleanupClosePushL(ids); |
|
1070 |
|
1071 TInt i=0; |
|
1072 for (i=KAddStartIndexAsync; i<=KAddEndIndexAsync; i++) |
|
1073 { |
|
1074 ids.Append(iLandmarks[i]->LandmarkId()); |
|
1075 } |
|
1076 for (TInt j=0; j<2; j++) |
|
1077 { |
|
1078 |
|
1079 for (i = KAddStartIndexAsync; i <= KAddEndIndexAsync; i++) |
|
1080 { |
|
1081 RunAsyncOperationLD(iCategoryManager->RemoveCategoryFromLandmarksL( |
|
1082 iCategories[KAddCategoryIndexAsync]->CategoryId(), |
|
1083 ids |
|
1084 )); |
|
1085 } |
|
1086 CheckLandmarksL(); |
|
1087 } |
|
1088 CleanupStack::PopAndDestroy(&ids); |
|
1089 } |
|
1090 |
|
1091 // --------------------------------------------------------- |
|
1092 // CPosTp10::RemoveCategoryFromSetOfLandmarksUsingWaitForReqL |
|
1093 // |
|
1094 // (other items were commented in a header). |
|
1095 // --------------------------------------------------------- |
|
1096 // |
|
1097 void CPosTp10::RemoveCategoryFromSetOfLandmarksUsingWaitForReqL() |
|
1098 { |
|
1099 iLog->Log(_L("Removing set of categories from landmarks using User::WaitForRequest()")); |
|
1100 RArray<TPosLmItemId> ids; |
|
1101 CleanupClosePushL(ids); |
|
1102 |
|
1103 TInt i=0; |
|
1104 for (i=KAddStartIndexAsync; i<=KAddEndIndexAsync; i++) |
|
1105 { |
|
1106 ids.Append(iLandmarks[i]->LandmarkId()); |
|
1107 } |
|
1108 for (TInt j=0; j<2; j++) |
|
1109 { |
|
1110 |
|
1111 for (i = KAddStartIndexAsync; i <= KAddEndIndexAsync; i++) |
|
1112 { |
|
1113 CPosLmOperation* op = iCategoryManager->RemoveCategoryFromLandmarksL( |
|
1114 iCategories[KAddCategoryIndexAsync]->CategoryId(), |
|
1115 ids); |
|
1116 CleanupStack::PushL(op); |
|
1117 RunAsyncOperationByWaitForReqL(op); |
|
1118 CleanupStack::PopAndDestroy(op); |
|
1119 } |
|
1120 CheckLandmarksL(); |
|
1121 } |
|
1122 CleanupStack::PopAndDestroy(&ids); |
|
1123 } |
|
1124 |
|
1125 // --------------------------------------------------------- |
|
1126 // CPosTp10::RemoveCategoryFromSetOfLandmarksAsyncAndCancelL |
|
1127 // |
|
1128 // (other items were commented in a header). |
|
1129 // --------------------------------------------------------- |
|
1130 // |
|
1131 void CPosTp10::RemoveCategoryFromSetOfLandmarksAsyncAndCancelL(const TBool& aInCallback) |
|
1132 { |
|
1133 iLog->Log(_L("Removing set of categories from landmarks asyncronously and cancel")); |
|
1134 RArray<TPosLmItemId> ids; |
|
1135 CleanupClosePushL(ids); |
|
1136 |
|
1137 TInt i=0; |
|
1138 for (i=KAddStartIndexAsync; i<=KAddEndIndexAsync; i++) |
|
1139 { |
|
1140 ids.Append(iLandmarks[i]->LandmarkId()); |
|
1141 } |
|
1142 for (TInt j=0; j<2; j++) |
|
1143 { |
|
1144 for (i = KAddStartIndexAsync; i <= KAddEndIndexAsync; i++) |
|
1145 { |
|
1146 if (aInCallback) |
|
1147 { |
|
1148 RunAsyncOperationAndCancelInCallbackLD( |
|
1149 iCategoryManager->RemoveCategoryFromLandmarksL( |
|
1150 iCategories[KAddCategoryIndexAsync]->CategoryId(), |
|
1151 ids |
|
1152 )); |
|
1153 } |
|
1154 else |
|
1155 { |
|
1156 RunAsyncOperationAndCancelLD( |
|
1157 iCategoryManager->RemoveCategoryFromLandmarksL( |
|
1158 iCategories[KAddCategoryIndexAsync]->CategoryId(), |
|
1159 ids |
|
1160 )); |
|
1161 } |
|
1162 } |
|
1163 } |
|
1164 |
|
1165 CleanupStack::PopAndDestroy(&ids); |
|
1166 } |
|
1167 |
|
1168 // --------------------------------------------------------- |
|
1169 // CPosTp10::CheckRemoved |
|
1170 // |
|
1171 // (other items were commented in a header). |
|
1172 // --------------------------------------------------------- |
|
1173 // |
|
1174 void CPosTp10::CheckRemovedL(const TInt aStartIndex, const TInt aStopIndex) |
|
1175 { |
|
1176 _LIT(KRemoveNotFoundErr, "Category has not been removed"); |
|
1177 _LIT(KRemoveFoundErr, "Category should not been removed"); |
|
1178 |
|
1179 for (TInt i = 0; i<=aStopIndex; i++) |
|
1180 { |
|
1181 TRAPD(err, ReadCategoryL(iCategories[i]->CategoryId())); |
|
1182 if (i >= aStartIndex && i <= aStopIndex) |
|
1183 { |
|
1184 AssertTrueSecL(err == KErrNotFound, KRemoveNotFoundErr); |
|
1185 RemovedFromLandmarksInternalL(iCategories[i]->CategoryId()); |
|
1186 } |
|
1187 else |
|
1188 { |
|
1189 AssertTrueSecL(err == KErrNone, KRemoveFoundErr); |
|
1190 } |
|
1191 } |
|
1192 |
|
1193 CheckLandmarksL(); |
|
1194 |
|
1195 } |
|
1196 |
|
1197 // --------------------------------------------------------- |
|
1198 // CPosTp10::RemovedFromLandmarksInternalL |
|
1199 // |
|
1200 // (other items were commented in a header). |
|
1201 // --------------------------------------------------------- |
|
1202 // |
|
1203 void CPosTp10::RemovedFromLandmarksInternalL(TPosLmItemId aCategoryId) |
|
1204 { |
|
1205 for (TInt i = 0; i < iLandmarks.Count(); i++) |
|
1206 { |
|
1207 iLandmarks[i]->RemoveCategory(aCategoryId); |
|
1208 } |
|
1209 } |
|
1210 |
|
1211 // --------------------------------------------------------- |
|
1212 // CPosTp10::ReadCategoryL |
|
1213 // |
|
1214 // (other items were commented in a header). |
|
1215 // --------------------------------------------------------- |
|
1216 // |
|
1217 void CPosTp10::ReadCategoryL(TPosLmItemId aCategoryId) |
|
1218 { |
|
1219 CPosLandmarkCategory* lmc = iCategoryManager->ReadCategoryLC(aCategoryId); |
|
1220 CleanupStack::PopAndDestroy(lmc); |
|
1221 } |
|
1222 |
|
1223 // --------------------------------------------------------- |
|
1224 // CPosTp10::TestMissingCategories1L |
|
1225 // |
|
1226 // (other items were commented in a header). |
|
1227 // --------------------------------------------------------- |
|
1228 // |
|
1229 void CPosTp10::TestMissingCategories1L() |
|
1230 { |
|
1231 iLog->Log(_L("TestMissingCategories1L")); |
|
1232 _LIT(KTestPath, "c:\\system\\test\\testdata\\"); |
|
1233 // copy the test db to the private path |
|
1234 CFileMan* fileMan = CFileMan::NewL(iFileSession); |
|
1235 CleanupStack::PushL(fileMan); |
|
1236 |
|
1237 TBuf<150> srcPath; |
|
1238 |
|
1239 srcPath.Append(KTestPath); |
|
1240 srcPath.Append(KTp10TestDb); |
|
1241 |
|
1242 TInt err = fileMan->Copy(srcPath, KLmTp10DefaultDbPath, |
|
1243 CFileMan::EOverWrite); |
|
1244 if (err != KErrNone) |
|
1245 iLog->Log(_L("Error when copying file")); |
|
1246 |
|
1247 CleanupStack::PopAndDestroy(fileMan); |
|
1248 CPosLmDatabaseManager* manager = CPosLmDatabaseManager::NewL(); |
|
1249 CleanupStack::PushL(manager); |
|
1250 |
|
1251 // This db must exist |
|
1252 manager->SetDefaultDatabaseUriL(KTp10TestDb); |
|
1253 CleanupStack::PopAndDestroy(manager); |
|
1254 |
|
1255 CPosLandmarkDatabase* lmd = CPosLandmarkDatabase::OpenL(KTp10TestDb); |
|
1256 CleanupStack::PushL(lmd); |
|
1257 |
|
1258 if (lmd->IsInitializingNeeded()) |
|
1259 { |
|
1260 ExecuteAndDeleteLD(lmd->InitializeL()); |
|
1261 } |
|
1262 |
|
1263 ExecuteAndDeleteLD(lmd->CompactL()); |
|
1264 |
|
1265 // Remove categories 1,2,3 (Pizzeria, Hamburgerbar, Kinarestaurang) |
|
1266 // Landmark with id=7 "Billigt" contains categories: 1,2,3 and 14-17 |
|
1267 CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*lmd); |
|
1268 CleanupStack::PushL(categoryManager); |
|
1269 |
|
1270 CPosLandmark* lm = lmd->ReadLandmarkLC(7); |
|
1271 |
|
1272 ExecuteAndDeleteLD(categoryManager->RemoveCategoryL(1)); |
|
1273 ExecuteAndDeleteLD(categoryManager->RemoveCategoryL(2)); |
|
1274 ExecuteAndDeleteLD(categoryManager->RemoveCategoryL(3)); |
|
1275 |
|
1276 // Change landmark name and update landmark, the server must not crash |
|
1277 lm->SetLandmarkNameL(_L("NyttBilligtNamn")); |
|
1278 |
|
1279 lmd->UpdateLandmarkL(*lm); |
|
1280 |
|
1281 CleanupStack::PopAndDestroy(lm); |
|
1282 lm = lmd->ReadLandmarkLC(7); |
|
1283 |
|
1284 RArray<TPosLmItemId> categories; |
|
1285 CleanupClosePushL(categories); |
|
1286 lm->GetCategoriesL(categories); |
|
1287 |
|
1288 // Now list all categories belonging to this landmark |
|
1289 // verify that the removed categories 1,2,3 are no longer referred from this landmark |
|
1290 // Should now only contain 14-17 |
|
1291 if (categories.Count() != 4) |
|
1292 { |
|
1293 iLog->Log(_L("Wrong number of categories")); |
|
1294 User::Leave(-1); |
|
1295 } |
|
1296 |
|
1297 for (TInt i=0;i<categories.Count();i++) |
|
1298 { |
|
1299 if (categories[i] == 1 || categories[i] == 2 || categories[i] == 3) |
|
1300 { |
|
1301 iLog->Log(_L("Wrong number of categories")); |
|
1302 User::Leave(-1); |
|
1303 } |
|
1304 } |
|
1305 |
|
1306 CleanupStack::PopAndDestroy(&categories); |
|
1307 CleanupStack::PopAndDestroy(lm); |
|
1308 CleanupStack::PopAndDestroy(categoryManager); |
|
1309 CleanupStack::PopAndDestroy(lmd); |
|
1310 } |
|
1311 |
|
1312 // --------------------------------------------------------- |
|
1313 // CPosTp10::TestMissingCategories2L |
|
1314 // |
|
1315 // (other items were commented in a header). |
|
1316 // --------------------------------------------------------- |
|
1317 // |
|
1318 void CPosTp10::TestMissingCategories2L() |
|
1319 { |
|
1320 iLog->Log(_L("TestMissingCategories2L")); |
|
1321 |
|
1322 _LIT(KTestPath, "c:\\system\\test\\testdata\\"); |
|
1323 // copy the test db to the private path |
|
1324 CFileMan* fileMan = CFileMan::NewL(iFileSession); |
|
1325 CleanupStack::PushL(fileMan); |
|
1326 |
|
1327 TBuf<150> srcPath; |
|
1328 |
|
1329 srcPath.Append(KTestPath); |
|
1330 srcPath.Append(KTp10TestDb); |
|
1331 |
|
1332 TInt err = fileMan->Copy(srcPath, KLmTp10DefaultDbPath, |
|
1333 CFileMan::EOverWrite); |
|
1334 if (err != KErrNone) |
|
1335 iLog->Log(_L("Error when copying file")); |
|
1336 |
|
1337 CleanupStack::PopAndDestroy(fileMan); |
|
1338 CPosLmDatabaseManager* manager = CPosLmDatabaseManager::NewL(); |
|
1339 CleanupStack::PushL(manager); |
|
1340 |
|
1341 // This db must exist |
|
1342 manager->SetDefaultDatabaseUriL(KTp10TestDb); |
|
1343 CleanupStack::PopAndDestroy(manager); |
|
1344 |
|
1345 CPosLandmarkDatabase* lmd = CPosLandmarkDatabase::OpenL(KTp10TestDb); |
|
1346 CleanupStack::PushL(lmd); |
|
1347 |
|
1348 if (lmd->IsInitializingNeeded()) |
|
1349 { |
|
1350 ExecuteAndDeleteLD(lmd->InitializeL()); |
|
1351 } |
|
1352 |
|
1353 ExecuteAndDeleteLD(lmd->CompactL()); |
|
1354 |
|
1355 CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*lmd); |
|
1356 CleanupStack::PushL(categoryManager); |
|
1357 |
|
1358 // Now create a landmark containing some categories, before adding this landmark to |
|
1359 // the database remove some of the categories from the landmarks database |
|
1360 CPosLandmark* lm = CreateXMLLandmarkLC(_L("PelleFantLandmark")); |
|
1361 // Add categories with id=7, id=14 and id=10 to this landmark |
|
1362 lm->AddCategoryL(7); |
|
1363 lm->AddCategoryL(14); |
|
1364 lm->AddCategoryL(10); |
|
1365 |
|
1366 //Then remove categories id=14 and id=7 from the landmark db |
|
1367 ExecuteAndDeleteLD(categoryManager->RemoveCategoryL(14)); |
|
1368 ExecuteAndDeleteLD(categoryManager->RemoveCategoryL(7)); |
|
1369 |
|
1370 TPosLmItemId id = lmd->AddLandmarkL(*lm); |
|
1371 |
|
1372 CleanupStack::PopAndDestroy(lm); |
|
1373 |
|
1374 lm = lmd->ReadLandmarkLC(id); |
|
1375 |
|
1376 RArray<TPosLmItemId> categories; |
|
1377 CleanupClosePushL(categories); |
|
1378 lm->GetCategoriesL(categories); |
|
1379 |
|
1380 // Now list all categories belonging to this landmark |
|
1381 if (categories.Count() != 1) |
|
1382 { |
|
1383 TBuf<50> buf; |
|
1384 buf.Format(_L("Wrong number of categories, was %d should be %d"), categories.Count(), 1); |
|
1385 for (TInt j=0;j<categories.Count();j++) |
|
1386 { |
|
1387 TBuf<50> buffe; |
|
1388 buffe.Format(_L("%d Category id: %d"), j, categories[j]); |
|
1389 iLog->Log(buffe); |
|
1390 } |
|
1391 iLog->Log(buf); |
|
1392 User::Leave(KErrNone); |
|
1393 } |
|
1394 |
|
1395 for (TInt i=0;i<categories.Count();i++) |
|
1396 { |
|
1397 if (categories[i] == 7 || categories[i] == 14) |
|
1398 { |
|
1399 iLog->Log(_L("Wrong number of categories")); |
|
1400 User::Leave(-1); |
|
1401 } |
|
1402 } |
|
1403 CleanupStack::PopAndDestroy(&categories); |
|
1404 CleanupStack::PopAndDestroy(lm); |
|
1405 CleanupStack::PopAndDestroy(categoryManager); |
|
1406 CleanupStack::PopAndDestroy(lmd); |
|
1407 |
|
1408 } |
|
1409 |
|
1410 // --------------------------------------------------------- |
|
1411 // CPosTp10::BackupTp10DbFileL() |
|
1412 // |
|
1413 // (other items were commented in a header). |
|
1414 // --------------------------------------------------------- |
|
1415 // |
|
1416 CPosLandmarkDatabase* CPosTp10::BackupTp10DbFileL() |
|
1417 { |
|
1418 |
|
1419 CPosLmDatabaseManager* manager = CPosLmDatabaseManager::NewL(); |
|
1420 CleanupStack::PushL(manager); |
|
1421 manager->SetDefaultDatabaseUriL(KTp10TestDb); |
|
1422 HBufC* defaultDbUri = manager->DefaultDatabaseUriLC(); |
|
1423 TBuf<255> buf; |
|
1424 // Extract URI except characters ".ldb" |
|
1425 buf.Append(defaultDbUri->Left(defaultDbUri->Length()-4)); |
|
1426 buf.Append(_L("COPY.LDB")); |
|
1427 // Delete in case it already exist |
|
1428 TRAPD(err, manager->DeleteDatabaseL(buf)); |
|
1429 if (err != KErrNone && err != KErrNotFound) iLog->Log(_L("Could not delete file")); |
|
1430 manager->CopyDatabaseL(*defaultDbUri, buf); |
|
1431 |
|
1432 CleanupStack::PopAndDestroy(defaultDbUri); |
|
1433 CleanupStack::PopAndDestroy(manager); |
|
1434 return CPosLandmarkDatabase::OpenL(); |
|
1435 } |
|
1436 |
|
1437 // --------------------------------------------------------- |
|
1438 // CPosTp10::RestoreTp10DbFileL() |
|
1439 // |
|
1440 // (other items were commented in a header). |
|
1441 // --------------------------------------------------------- |
|
1442 // |
|
1443 CPosLandmarkDatabase* CPosTp10::RestoreTp10DbFileL() |
|
1444 { |
|
1445 |
|
1446 |
|
1447 CPosLmDatabaseManager* manager = CPosLmDatabaseManager::NewL(); |
|
1448 CleanupStack::PushL(manager); |
|
1449 manager->SetDefaultDatabaseUriL(KTp10TestDb); |
|
1450 HBufC* defaultDbUri = manager->DefaultDatabaseUriLC(); |
|
1451 TBuf<255> buf; |
|
1452 // Extract URI except characters ".ldb" |
|
1453 buf.Append(defaultDbUri->Left(defaultDbUri->Length()-4)); |
|
1454 buf.Append(_L("COPY.LDB")); |
|
1455 // Delete in case it already exist |
|
1456 TRAPD(err, manager->DeleteDatabaseL(*defaultDbUri)); |
|
1457 if (err != KErrNone && err != KErrNotFound) iLog->Log(_L("Could not delete file")); |
|
1458 manager->CopyDatabaseL(buf, *defaultDbUri); |
|
1459 |
|
1460 CleanupStack::PopAndDestroy(defaultDbUri); |
|
1461 CleanupStack::PopAndDestroy(manager); |
|
1462 return CPosLandmarkDatabase::OpenL(); |
|
1463 } |
|
1464 |
|
1465 // End of File |