|
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 #include "FT_CPosTp79.h" |
|
22 #include "FT_CPosTp78.h" |
|
23 #include <Lbs.h> |
|
24 #include <EPos_CPosLandmarkDatabase.h> |
|
25 #include <EPos_CPosLmCategoryManager.h> |
|
26 #include <EPos_CPosLmTextCriteria.h> |
|
27 #include <EPos_CPosLandmarkCategory.h> |
|
28 #include <EPos_CPosLmCatNameCriteria.h> |
|
29 |
|
30 // CONSTANTS |
|
31 const TInt KExectionTimeInMinutes = 60 * 10; // 10 hours |
|
32 |
|
33 // ================= LOCAL FUNCTIONS ======================= |
|
34 |
|
35 // --------------------------------------------------------- |
|
36 // LOCAL_C ThreadFunction |
|
37 // |
|
38 // (other items were commented in a header). |
|
39 // --------------------------------------------------------- |
|
40 // |
|
41 LOCAL_C TInt ThreadFunction(TAny* aData) |
|
42 { |
|
43 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
44 CActiveScheduler* actSch = new (ELeave) CActiveScheduler; |
|
45 CActiveScheduler::Install(actSch); |
|
46 |
|
47 TThreadParam* params = reinterpret_cast<TThreadParam*> (aData); |
|
48 TRAPD(err, (*params->iTestFunction)(params->iMessage)); |
|
49 |
|
50 delete actSch; |
|
51 delete cleanup; |
|
52 return err; |
|
53 } |
|
54 |
|
55 LOCAL_C void AddCategoriesL( |
|
56 TInt aNrOfLmsToAdd, |
|
57 const TDesC& aName, |
|
58 CPosLmCategoryManager* aCatMan, |
|
59 RArray<TPosLmItemId>& aIdArray) |
|
60 { |
|
61 for (TInt i = 0; i < aNrOfLmsToAdd; i++) |
|
62 { |
|
63 CPosLandmarkCategory* category = CPosLandmarkCategory::NewLC(); |
|
64 HBufC* name = HBufC::NewLC(aName.Length() + 5); |
|
65 TPtr namePtr = name->Des(); |
|
66 namePtr.Format(aName, i); |
|
67 category->SetCategoryNameL(namePtr); |
|
68 category->SetIconL(_L("Icon"), 23, KPosLmIconMaskNotUsed); |
|
69 TPosLmItemId id; |
|
70 TRAPD(err, id = aCatMan->AddCategoryL(*category)); |
|
71 if (err != KErrNone && err != KErrAlreadyExists) |
|
72 { |
|
73 User::Leave(err); |
|
74 } |
|
75 else |
|
76 { |
|
77 if (err == KErrAlreadyExists) |
|
78 { |
|
79 id = aCatMan->GetCategoryL(namePtr); |
|
80 } |
|
81 User::LeaveIfError(aIdArray.Append(id)); |
|
82 } |
|
83 CleanupStack::PopAndDestroy(2, category); |
|
84 } |
|
85 } |
|
86 |
|
87 LOCAL_C void VerifyErrorL(const TDesC& aFormat, TInt aErr, TDes* aMessage) |
|
88 { |
|
89 if (aErr != KErrNone && aErr != KErrLocked) |
|
90 { |
|
91 aMessage->Format(aFormat, aErr); |
|
92 |
|
93 // Append time |
|
94 _LIT(KTimeFormat, " %F%Y-%M-%D at %H.%T:%S"); |
|
95 TTime now; |
|
96 now.HomeTime(); |
|
97 TBuf<50> time; |
|
98 now.FormatL(time, KTimeFormat); |
|
99 aMessage->Append(time); |
|
100 |
|
101 User::Leave(aErr); |
|
102 } |
|
103 } |
|
104 |
|
105 // ================= MEMBER FUNCTIONS ======================= |
|
106 |
|
107 // --------------------------------------------------------- |
|
108 // CPosTp79::GetName |
|
109 // |
|
110 // (other items were commented in a header). |
|
111 // --------------------------------------------------------- |
|
112 // |
|
113 void CPosTp79::GetName(TDes& aName) const |
|
114 { |
|
115 _LIT(KTestName, "TP79 - Category and search duration tests"); |
|
116 aName = KTestName; |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------- |
|
120 // CPosTp79::InitTestL |
|
121 // |
|
122 // (other items were commented in a header). |
|
123 // --------------------------------------------------------- |
|
124 // |
|
125 void CPosTp79::InitTestL() |
|
126 { |
|
127 MakeSurePanicDebugFileExistsL(); |
|
128 InitDbL(); |
|
129 } |
|
130 |
|
131 // --------------------------------------------------------- |
|
132 // CPosTp79::CloseTest |
|
133 // |
|
134 // (other items were commented in a header). |
|
135 // --------------------------------------------------------- |
|
136 // |
|
137 void CPosTp79::CloseTest() |
|
138 { |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------- |
|
142 // CPosTp79::StartL |
|
143 // |
|
144 // (other items were commented in a header). |
|
145 // --------------------------------------------------------- |
|
146 // |
|
147 void CPosTp79::StartL() |
|
148 { |
|
149 // Test Open database duration test |
|
150 ResumeThreadsAndVerifyExitL(); |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------- |
|
154 // CPosTp79::InitDbL |
|
155 // |
|
156 // (other items were commented in a header). |
|
157 // --------------------------------------------------------- |
|
158 // |
|
159 void CPosTp79::InitDbL() |
|
160 { |
|
161 RemoveDefaultDbL(); |
|
162 CPosLandmarkDatabase* database = CPosLandmarkDatabase::OpenL(); |
|
163 CleanupStack::PushL(database); |
|
164 |
|
165 if (database->IsInitializingNeeded()) |
|
166 { |
|
167 ExecuteAndDeleteLD(database->InitializeL()); |
|
168 } |
|
169 |
|
170 CleanupStack::PopAndDestroy(database); |
|
171 |
|
172 // Wait for LM server to die |
|
173 User::After(2000000); |
|
174 } |
|
175 |
|
176 // --------------------------------------------------------- |
|
177 // CPosTp79::ResumeThreadsAndVerifyExitL |
|
178 // |
|
179 // (other items were commented in a header). |
|
180 // --------------------------------------------------------- |
|
181 // |
|
182 void CPosTp79::ResumeThreadsAndVerifyExitL() |
|
183 { |
|
184 _LIT(KCreateThreadErr, "Creating thread failed with %d"); |
|
185 TInt nrOfThreads = 0; |
|
186 RThread searchThread, readAndUpdateThread, addRemoveCatsThread; |
|
187 TThreadParam params1, params2, params3; |
|
188 TBuf<200> threadMsg1, threadMsg2, threadMsg3; |
|
189 |
|
190 // Create search thread |
|
191 _LIT(KSearch, "TP79 - Search duration thread"); |
|
192 params1.iMessage = &threadMsg1; |
|
193 params1.iTestFunction = RunSearchTestL; |
|
194 TInt err = searchThread.Create(KSearch, ThreadFunction, |
|
195 KDefaultStackSize, KMinHeapSize, KDefaultHeapSize, ¶ms1); |
|
196 AssertTrueSecL(err == KErrNone, KCreateThreadErr, err); |
|
197 CleanupClosePushL(searchThread); |
|
198 nrOfThreads++; |
|
199 |
|
200 // Create read and update thread |
|
201 _LIT(KReadAndUpdateThread, "TP79 - Read and update categories duration thread"); |
|
202 params2.iMessage = &threadMsg2; |
|
203 params2.iTestFunction = RunReadAndUpdateTestL; |
|
204 err = readAndUpdateThread.Create(KReadAndUpdateThread, ThreadFunction, |
|
205 KDefaultStackSize, KMinHeapSize, KDefaultHeapSize, ¶ms2); |
|
206 AssertTrueSecL(err == KErrNone, KCreateThreadErr, err); |
|
207 CleanupClosePushL(readAndUpdateThread); |
|
208 nrOfThreads++; |
|
209 |
|
210 // Create add remove categories thread |
|
211 _LIT(KAddRemoveCategories, "TP79 - Add remove categories duration thread"); |
|
212 params3.iMessage = &threadMsg3; |
|
213 params3.iTestFunction = RunAddRemoveCatsTestL; |
|
214 err = addRemoveCatsThread.Create(KAddRemoveCategories, ThreadFunction, |
|
215 KDefaultStackSize, KMinHeapSize, KDefaultHeapSize, ¶ms3); |
|
216 AssertTrueSecL(err == KErrNone, KCreateThreadErr, err); |
|
217 CleanupClosePushL(addRemoveCatsThread); |
|
218 nrOfThreads++; |
|
219 |
|
220 // Start threads. |
|
221 RThread* threads[] = {&searchThread, &readAndUpdateThread, &addRemoveCatsThread}; |
|
222 RPointerArray<CThreadMonitor> threadMonitors; |
|
223 for (TInt j = 0; j < nrOfThreads; j++) |
|
224 { |
|
225 threadMonitors.Append(CThreadMonitor::NewL(threads[j])); |
|
226 } |
|
227 |
|
228 // Log time stamp |
|
229 _LIT(KTimeFormat, "Threads started on %F%Y-%M-%D at %H.%T:%S"); |
|
230 TTime now; |
|
231 now.HomeTime(); |
|
232 now.FormatL(iBuf, KTimeFormat); |
|
233 iLog->Put(iBuf); |
|
234 |
|
235 // Wait until any of the threads exits. |
|
236 TDes* messages[] = {&threadMsg1, &threadMsg2, &threadMsg3}; |
|
237 TInt errors = KErrNone; |
|
238 TBool allThreadsTerminated = EFalse; |
|
239 while (!allThreadsTerminated && errors == KErrNone) |
|
240 { |
|
241 CActiveScheduler::Start(); |
|
242 |
|
243 // Assume all threads are terminated |
|
244 allThreadsTerminated = ETrue; |
|
245 for (TInt i = 0; i < nrOfThreads && errors == KErrNone; i++) |
|
246 { |
|
247 if (threadMonitors[i]->IsActive()) |
|
248 { |
|
249 // Thread is still alive |
|
250 allThreadsTerminated = EFalse; |
|
251 } |
|
252 else |
|
253 { |
|
254 // Thread is terminated, check exit codes |
|
255 if (*messages[i] != KNullDesC) |
|
256 { |
|
257 iLog->Put(*(messages[i])); |
|
258 } |
|
259 if (threads[i]->ExitType() != EExitKill) |
|
260 { |
|
261 iBuf.Format(_L("Thread %i was not killed!"), i); |
|
262 iLog->PutError(iBuf); |
|
263 TExitCategoryName category = threads[i]->ExitCategory(); |
|
264 iBuf.Format(_L("Exit Category = %S %d"), &category, threads[i]->ExitReason()); |
|
265 iLog->Put(iBuf); |
|
266 errors = KErrGeneral; |
|
267 } |
|
268 else |
|
269 { |
|
270 TInt exitReason = threads[i]->ExitReason(); |
|
271 if (exitReason != 0) |
|
272 { |
|
273 iBuf.Format(_L("Thread's exit reason wasn't 0 but %d."), exitReason); |
|
274 iLog->PutError(iBuf); |
|
275 errors = exitReason; |
|
276 } |
|
277 } |
|
278 } |
|
279 } |
|
280 } |
|
281 |
|
282 // Terminate all remaining threads |
|
283 threadMonitors.ResetAndDestroy(); |
|
284 |
|
285 // Log time stamp |
|
286 _LIT(KTimeFormat2, "Threads terminated on %F%Y-%M-%D at %H.%T:%S"); |
|
287 now.HomeTime(); |
|
288 now.FormatL(iBuf, KTimeFormat2); |
|
289 iLog->Put(iBuf); |
|
290 |
|
291 |
|
292 User::LeaveIfError(errors); |
|
293 |
|
294 CleanupStack::PopAndDestroy(nrOfThreads, &searchThread); |
|
295 } |
|
296 |
|
297 // --------------------------------------------------------- |
|
298 // CPosTp79::RunSearchTestL |
|
299 // |
|
300 // (other items were commented in a header). |
|
301 // --------------------------------------------------------- |
|
302 // |
|
303 void CPosTp79::RunSearchTestL(TDes* aMessage) |
|
304 { |
|
305 _LIT(KName, "SearchThread %d"); |
|
306 |
|
307 // Execute thread for a number of hours |
|
308 TTime startTime, stopTime; |
|
309 startTime.HomeTime(); |
|
310 stopTime.HomeTime(); |
|
311 TTimeIntervalMinutes executionTime; |
|
312 User::LeaveIfError(stopTime.MinutesFrom(startTime, executionTime)); |
|
313 |
|
314 CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL(); |
|
315 CleanupStack::PushL(db); |
|
316 CPosLmCategoryManager* catMan = CPosLmCategoryManager::NewL(*db); |
|
317 CleanupStack::PushL(catMan); |
|
318 |
|
319 while (executionTime.Int() < KExectionTimeInMinutes) |
|
320 { |
|
321 CPosLandmarkSearch* searcher = NULL; |
|
322 TRAPD(err, searcher = CPosLandmarkSearch::NewL(*db)); |
|
323 CleanupStack::PushL(searcher); |
|
324 VerifyErrorL(_L("<-- SearchThread: CPosLandmarkSearch::NewL() left with %d -->"), err, aMessage); |
|
325 |
|
326 RArray<TPosLmItemId> dbItems; |
|
327 CleanupClosePushL(dbItems); |
|
328 |
|
329 const TInt KNrOfCats = 3; |
|
330 TRAP(err, AddCategoriesL(KNrOfCats, KName, catMan, dbItems)); |
|
331 VerifyErrorL(_L("<-- SearchThread: AddCategoriesL() left with %d -->"), err, aMessage); |
|
332 if (err == KErrNone) |
|
333 { |
|
334 // StartLandmarkSearchL |
|
335 CPosLmTextCriteria* textCriteria = NULL; |
|
336 TRAP(err, CleanupStack::Pop(textCriteria = CPosLmTextCriteria::NewLC())); |
|
337 CleanupStack::PushL(textCriteria); |
|
338 VerifyErrorL(_L("<-- SearchThread: CPosLmTextCriteria::NewLC() left with %d -->"), err, aMessage); |
|
339 TRAP(err, textCriteria->SetTextL(KName().Left(5))); |
|
340 VerifyErrorL(_L("<-- SearchThread: SetTextL() left with %d -->"), err, aMessage); |
|
341 textCriteria->SetAttributesToSearch(CPosLandmark::EDescription & CPosLandmark::ELandmarkName); |
|
342 TPosLmSortPref sortPref(CPosLandmark::ELandmarkName, TPosLmSortPref::EDescending); |
|
343 |
|
344 CPosLmOperation* operation = NULL; |
|
345 TRAPD(err, operation = searcher->StartLandmarkSearchL(*textCriteria, sortPref)); |
|
346 CleanupStack::PushL(operation); |
|
347 VerifyErrorL(_L("<-- SearchThread: StartLandmarkSearchL() left with %d -->"), err, aMessage); |
|
348 if (operation) |
|
349 { |
|
350 TRAP(err, operation->ExecuteL()); |
|
351 VerifyErrorL(_L("<-- SearchThread: ExecuteLD(StartLandmarkSearchL()) left with %d -->"), err, aMessage); |
|
352 } |
|
353 CleanupStack::PopAndDestroy(operation); |
|
354 |
|
355 // StartCategorySearchL |
|
356 CPosLmCatNameCriteria* nameCriteria = NULL; |
|
357 TRAP(err, CleanupStack::Pop(nameCriteria = CPosLmCatNameCriteria::NewLC())); |
|
358 CleanupStack::PushL(nameCriteria); |
|
359 VerifyErrorL(_L("<-- SearchThread: CPosLmCatNameCriteria::NewLC() left with %d -->"), err, aMessage); |
|
360 TRAP(err, nameCriteria->SetSearchPatternL(KName().Left(5))); |
|
361 VerifyErrorL(_L("<-- SearchThread: SetSearchPatternL() left with %d -->"), err, aMessage); |
|
362 operation = NULL; |
|
363 TRAP(err, operation = searcher->StartCategorySearchL(*nameCriteria, CPosLmCategoryManager::ECategorySortOrderNameAscending)); |
|
364 CleanupStack::PushL(operation); |
|
365 VerifyErrorL(_L("<-- SearchThread: StartCategorySearchL() left with %d -->"), err, aMessage); |
|
366 if (operation) |
|
367 { |
|
368 TRAP(err, operation->ExecuteL()); |
|
369 VerifyErrorL(_L("<-- SearchThread: ExecuteLD(StartCategorySearchL()) left with %d -->"), err, aMessage); |
|
370 } |
|
371 CleanupStack::PopAndDestroy(3, textCriteria); |
|
372 } |
|
373 |
|
374 // Let other threads get access to the database |
|
375 User::After(300000); |
|
376 |
|
377 stopTime.HomeTime(); |
|
378 User::LeaveIfError(stopTime.MinutesFrom(startTime, executionTime)); |
|
379 |
|
380 CleanupStack::PopAndDestroy(2, searcher); |
|
381 } |
|
382 |
|
383 CleanupStack::PopAndDestroy(2, db); |
|
384 } |
|
385 |
|
386 // --------------------------------------------------------- |
|
387 // CPosTp79::RunAddRemoveCatsTestL |
|
388 // |
|
389 // (other items were commented in a header). |
|
390 // --------------------------------------------------------- |
|
391 // |
|
392 void CPosTp79::RunAddRemoveCatsTestL(TDes* aMessage) |
|
393 { |
|
394 // Execute thread for a number of hours |
|
395 TTime startTime, stopTime; |
|
396 startTime.HomeTime(); |
|
397 stopTime.HomeTime(); |
|
398 TTimeIntervalMinutes executionTime; |
|
399 User::LeaveIfError(stopTime.MinutesFrom(startTime, executionTime)); |
|
400 |
|
401 // Open db |
|
402 CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL(); |
|
403 CleanupStack::PushL(db); |
|
404 |
|
405 while (executionTime.Int() < KExectionTimeInMinutes) |
|
406 { |
|
407 CPosLmOperation* operation = NULL; |
|
408 CPosLmCategoryManager* catMan = NULL; |
|
409 TRAPD(err, catMan = CPosLmCategoryManager::NewL(*db)); |
|
410 CleanupStack::PushL(catMan); |
|
411 VerifyErrorL(_L("<-- AddRemoveCatsThread: CPosLmCategoryManager::NewL() left with %d -->"), err, aMessage); |
|
412 |
|
413 RArray<TPosLmItemId> dbItems; |
|
414 CleanupClosePushL(dbItems); |
|
415 |
|
416 // RemoveCategoriesL / remove all categories |
|
417 CPosLmItemIterator* iterator = NULL; |
|
418 TRAP(err, iterator = catMan->CategoryIteratorL()); |
|
419 CleanupStack::PushL(iterator); |
|
420 VerifyErrorL(_L("<-- AddRemoveCatsThread: CategoryIteratorL() left with %d -->"), err, aMessage); |
|
421 if (iterator) |
|
422 { |
|
423 TRAP(err, iterator->GetItemIdsL(dbItems, 0, iterator->NumOfItemsL())); |
|
424 VerifyErrorL(_L("<-- AddRemoveCatsThread: GetItemIdsL() left with %d -->"), err, aMessage); |
|
425 |
|
426 if (err == KErrNone) |
|
427 { |
|
428 operation = NULL; |
|
429 TRAP(err, operation = catMan->RemoveCategoriesL(dbItems)); |
|
430 CleanupStack::PushL(operation); |
|
431 VerifyErrorL(_L("<-- AddRemoveCatsThread: RemoveCategoriesL() left with %d -->"), err, aMessage); |
|
432 if (operation) |
|
433 { |
|
434 TRAP(err, operation->ExecuteL()); |
|
435 VerifyErrorL(_L("<-- AddRemoveCatsThread: ExecuteLD(RemoveCategoriesL()) left with %d -->"), err, aMessage); |
|
436 } |
|
437 CleanupStack::PopAndDestroy(operation); |
|
438 } |
|
439 dbItems.Reset(); |
|
440 } |
|
441 CleanupStack::PopAndDestroy(iterator); |
|
442 |
|
443 // ResetGlobalCategoriesL |
|
444 operation = NULL; |
|
445 TRAP(err, operation = catMan->ResetGlobalCategoriesL()); |
|
446 VerifyErrorL(_L("<-- ReadAndUpdateThread: ResetGlobalCategoriesL() left with %d -->"), err, aMessage); |
|
447 if (operation) |
|
448 { |
|
449 CleanupStack::PushL(operation); |
|
450 TRAP(err, operation->ExecuteL()); |
|
451 VerifyErrorL(_L("<-- ReadAndUpdateThread: ExecuteLD(ResetGlobalCategoriesL()) left with %d -->"), err, aMessage); |
|
452 CleanupStack::PopAndDestroy(operation); |
|
453 } |
|
454 |
|
455 const TInt KNrOfCats = 3; |
|
456 TRAP(err, AddCategoriesL(KNrOfCats, _L("AddRemoveCatsThread %d"), catMan, dbItems)); |
|
457 VerifyErrorL(_L("<-- AddRemoveCatsThread: AddCategoriesL() left with %d -->"), err, aMessage); |
|
458 if (err == KErrNone) |
|
459 { |
|
460 // AddCategoryToLandmarksL |
|
461 operation = NULL; |
|
462 TRAP(err, operation = catMan->AddCategoryToLandmarksL(dbItems[0], dbItems)); |
|
463 CleanupStack::PushL(operation); |
|
464 VerifyErrorL(_L("<-- AddRemoveCatsThread: AddCategoryToLandmarksL() left with %d -->"), err, aMessage); |
|
465 if (operation) |
|
466 { |
|
467 TRAP(err, operation->ExecuteL()); |
|
468 VerifyErrorL(_L("<-- AddRemoveCatsThread: ExecuteLD(AddCategoryToLandmarksL()) left with %d -->"), err, aMessage); |
|
469 } |
|
470 CleanupStack::PopAndDestroy(operation); |
|
471 |
|
472 // RemoveCategoryFromLandmarksL |
|
473 operation = NULL; |
|
474 TRAP(err, operation = catMan->RemoveCategoryFromLandmarksL(dbItems[0], dbItems)); |
|
475 CleanupStack::PushL(operation); |
|
476 VerifyErrorL(_L("<-- AddRemoveCatsThread: RemoveCategoryFromLandmarksL() left with %d -->"), err, aMessage); |
|
477 if (operation) |
|
478 { |
|
479 TRAP(err, operation->ExecuteL()); |
|
480 VerifyErrorL(_L("<-- AddRemoveCatsThread: ExecuteLD(RemoveCategoryFromLandmarksL()) left with %d -->"), err, aMessage); |
|
481 } |
|
482 CleanupStack::PopAndDestroy(operation); |
|
483 |
|
484 // RemoveCategoryL |
|
485 operation = NULL; |
|
486 TRAP(err, operation = catMan->RemoveCategoryL(dbItems[0])); |
|
487 CleanupStack::PushL(operation); |
|
488 VerifyErrorL(_L("<-- AddRemoveCatsThread: RemoveCategoryL() left with %d -->"), err, aMessage); |
|
489 if (operation) |
|
490 { |
|
491 TRAP(err, operation->ExecuteL()); |
|
492 VerifyErrorL(_L("<-- AddRemoveCatsThread: ExecuteLD(RemoveCategoryL()) left with %d -->"), err, aMessage); |
|
493 } |
|
494 CleanupStack::PopAndDestroy(operation); |
|
495 dbItems.Remove(0); |
|
496 } |
|
497 |
|
498 // Let other threads get access to the database |
|
499 User::After(300000); |
|
500 |
|
501 stopTime.HomeTime(); |
|
502 User::LeaveIfError(stopTime.MinutesFrom(startTime, executionTime)); |
|
503 |
|
504 CleanupStack::PopAndDestroy(2, catMan); |
|
505 } |
|
506 |
|
507 CleanupStack::PopAndDestroy(db); |
|
508 } |
|
509 |
|
510 // --------------------------------------------------------- |
|
511 // CPosTp79::RunReadAndUpdateTestL |
|
512 // |
|
513 // (other items were commented in a header). |
|
514 // --------------------------------------------------------- |
|
515 // |
|
516 void CPosTp79::RunReadAndUpdateTestL(TDes* aMessage) |
|
517 { |
|
518 // Execute thread for a number of hours |
|
519 TTime startTime, stopTime; |
|
520 startTime.HomeTime(); |
|
521 stopTime.HomeTime(); |
|
522 TTimeIntervalMinutes executionTime; |
|
523 User::LeaveIfError(stopTime.MinutesFrom(startTime, executionTime)); |
|
524 |
|
525 // Open db |
|
526 CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL(); |
|
527 CleanupStack::PushL(db); |
|
528 CPosLmCategoryManager* catMan = CPosLmCategoryManager::NewL(*db); |
|
529 CleanupStack::PushL(catMan); |
|
530 |
|
531 while (executionTime.Int() < KExectionTimeInMinutes) |
|
532 { |
|
533 RArray<TPosLmItemId> dbItems; |
|
534 CleanupClosePushL(dbItems); |
|
535 |
|
536 const TInt KNrOfCats = 3; |
|
537 TRAPD(err, AddCategoriesL(KNrOfCats, _L("ReadAndUpdateThread %d"), catMan, dbItems)); |
|
538 VerifyErrorL(_L("<-- ReadAndUpdateThread: AddCategoriesL() left with %d -->"), err, aMessage); |
|
539 if (err == KErrNone) |
|
540 { |
|
541 // Read and update |
|
542 for (TInt i = 0; i < KNrOfCats; i++) |
|
543 { |
|
544 CPosLandmarkCategory* category = NULL; |
|
545 TRAP(err, CleanupStack::Pop(category = catMan->ReadCategoryLC(dbItems[i]))); |
|
546 CleanupStack::PushL(category); |
|
547 VerifyErrorL(_L("<-- ReadAndUpdateThread: ReadCategoryLC() left with %d -->"), err, aMessage); |
|
548 if (category) |
|
549 { |
|
550 TPtrC namePtr; |
|
551 err = category->GetCategoryName(namePtr); |
|
552 VerifyErrorL(_L("<-- ReadAndUpdateThread: GetCategoryName() returned %d -->"), err, aMessage); |
|
553 if (err == KErrNone) |
|
554 { |
|
555 TBuf<KPosLmMaxCategoryNameLength> name(namePtr); |
|
556 name.Insert(0, name.Left(1)); |
|
557 TRAP(err, category->SetCategoryNameL(name)); |
|
558 VerifyErrorL(_L("<-- ReadAndUpdateThread: SetCategoryNameL() left with %d -->"), err, aMessage); |
|
559 TRAP(err, catMan->UpdateCategoryL(*category)); |
|
560 if (err != KErrAlreadyExists) |
|
561 { |
|
562 VerifyErrorL(_L("<-- ReadAndUpdateThread: UpdateCategoryL() left with %d -->"), err, aMessage); |
|
563 } |
|
564 } |
|
565 } |
|
566 CleanupStack::PopAndDestroy(category); |
|
567 } |
|
568 |
|
569 // GetCategoryL |
|
570 if (err != KErrInUse) |
|
571 { |
|
572 TRAP(err, catMan->GetCategoryL(_L("RReadAndUpdateThread 3"))); |
|
573 VerifyErrorL(_L("<-- ReadAndUpdateThread: GetCategoryL() left with %d -->"), err, aMessage); |
|
574 } |
|
575 } |
|
576 CleanupStack::PopAndDestroy(&dbItems); |
|
577 |
|
578 // CategoryIteratorL |
|
579 CPosLmItemIterator* iterator = NULL; |
|
580 TRAP(err, iterator = catMan->CategoryIteratorL(CPosLmCategoryManager::ECategorySortOrderNameAscending)); |
|
581 delete iterator; |
|
582 VerifyErrorL(_L("<-- ReadAndUpdateThread: CategoryIteratorL() left with %d -->"), err, aMessage); |
|
583 |
|
584 // ReferencedCategoryIteratorL |
|
585 iterator = NULL; |
|
586 TRAP(err, iterator = catMan->ReferencedCategoryIteratorL(CPosLmCategoryManager::ECategorySortOrderNameDescending)); |
|
587 delete iterator; |
|
588 VerifyErrorL(_L("<-- ReadAndUpdateThread: ReferencedCategoryIteratorL() left with %d -->"), err, aMessage); |
|
589 |
|
590 // GetGlobalCategoryL |
|
591 TRAP(err, catMan->GetGlobalCategoryL(3000)); |
|
592 VerifyErrorL(_L("<-- ReadAndUpdateThread: GetGlobalCategoryL() left with %d -->"), err, aMessage); |
|
593 |
|
594 // GlobalCategoryNameL |
|
595 HBufC* name = NULL; |
|
596 TRAP(err, name = catMan->GlobalCategoryNameL(3000)); |
|
597 delete name; |
|
598 VerifyErrorL(_L("<-- ReadAndUpdateThread: GlobalCategoryNameL() left with %d -->"), err, aMessage); |
|
599 |
|
600 // Let other threads get access to the database |
|
601 User::After(110000); |
|
602 |
|
603 stopTime.HomeTime(); |
|
604 User::LeaveIfError(stopTime.MinutesFrom(startTime, executionTime)); |
|
605 } |
|
606 |
|
607 CleanupStack::PopAndDestroy(2, db); |
|
608 } |
|
609 |
|
610 // End of File |