|
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 the License "Symbian Foundation License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.symbianfoundation.org/legal/sfl-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_CPosTp53.h" |
|
22 |
|
23 #include <EPos_CPosLandmarkParser.h> |
|
24 |
|
25 // CONSTANTS |
|
26 // const TInt KMaxQueueSize = 5; |
|
27 const TReal32 KCompactDbLevel = 0.75; // From ...landmarks\inernalServeices\resources\eposlmcompactdblevel.rss |
|
28 |
|
29 #ifdef __WINS__ |
|
30 _LIT(KImportFile, "z:\\system\\test\\testdata\\TP53-CategoriesNotInDb.xml"); |
|
31 _LIT(KImportFile2, "z:\\system\\test\\testdata\\TP53-OneLandmark.xml"); |
|
32 _LIT(KImportFile3, "z:\\system\\test\\testdata\\TP53-Categories.xml"); |
|
33 _LIT(KImportFile4, "z:\\system\\test\\testdata\\TP53-Category.xml"); |
|
34 _LIT(KImportFile5, "z:\\system\\test\\testdata\\TP53-GlobalCategory.xml"); |
|
35 _LIT(KImportFile6, "z:\\system\\test\\testdata\\TP53-LandmarksOneCategory.xml"); |
|
36 _LIT(KImportFile7, "z:\\system\\test\\testdata\\TP53-LandmarkCategories.xml"); |
|
37 _LIT(KImportFile8, "z:\\system\\test\\testdata\\TP53-LandmarksCategories.xml"); |
|
38 |
|
39 _LIT(KCompactImportFile, "z:\\system\\test\\testdata\\TP53-Compact.xml"); |
|
40 #else |
|
41 _LIT(KImportFile, "c:\\system\\test\\testdata\\TP53-CategoriesNotInDb.xml"); |
|
42 _LIT(KImportFile2, "c:\\system\\test\\testdata\\TP53-OneLandmark.xml"); |
|
43 _LIT(KImportFile3, "c:\\system\\test\\testdata\\TP53-Categories.xml"); |
|
44 _LIT(KImportFile4, "c:\\system\\test\\testdata\\TP53-Category.xml"); |
|
45 _LIT(KImportFile5, "c:\\system\\test\\testdata\\TP53-GlobalCategory.xml"); |
|
46 _LIT(KImportFile6, "c:\\system\\test\\testdata\\TP53-LandmarksOneCategory.xml"); |
|
47 _LIT(KImportFile7, "c:\\system\\test\\testdata\\TP53-LandmarkCategories.xml"); |
|
48 _LIT(KImportFile8, "c:\\system\\test\\testdata\\TP53-LandmarksCategories.xml"); |
|
49 |
|
50 _LIT(KCompactImportFile, "c:\\system\\test\\testdata\\TP53-Compact.xml"); |
|
51 #endif |
|
52 |
|
53 _LIT(KCategoryName, "TP53Category1"); |
|
54 _LIT(KCategoryName2, "TP53Category2"); |
|
55 _LIT(KCategoryName3, "TP53Category3"); |
|
56 |
|
57 // ================= MEMBER FUNCTIONS ======================= |
|
58 |
|
59 // --------------------------------------------------------- |
|
60 // CPosTp53::GetName |
|
61 // |
|
62 // (other items were commented in a header). |
|
63 // --------------------------------------------------------- |
|
64 // |
|
65 void CPosTp53::GetName(TDes& aName) const |
|
66 { |
|
67 _LIT(KTestName, "Tp53 - Events and compact during import"); |
|
68 aName = KTestName; |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------- |
|
72 // CPosTp53::CloseTest |
|
73 // |
|
74 // (other items were commented in a header). |
|
75 // --------------------------------------------------------- |
|
76 // |
|
77 void CPosTp53::CloseTest() |
|
78 { |
|
79 delete iDatabase; |
|
80 iDatabase = NULL; |
|
81 |
|
82 delete iActiveLmEvent; |
|
83 iActiveLmEvent = NULL; |
|
84 |
|
85 delete iParser; |
|
86 iParser = NULL; |
|
87 |
|
88 RemoveGlobalCategoriesL(); |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------- |
|
92 // CPosTp53::StartL |
|
93 // |
|
94 // (other items were commented in a header). |
|
95 // --------------------------------------------------------- |
|
96 // |
|
97 void CPosTp53::StartL() |
|
98 { |
|
99 RemoveDefaultDbL(); |
|
100 RemoveGlobalCategoriesL(); |
|
101 |
|
102 iDatabase = UseGlobalCategoriesL(); |
|
103 |
|
104 if (iDatabase->IsInitializingNeeded()) |
|
105 { |
|
106 ExecuteAndDeleteLD(iDatabase->InitializeL()); |
|
107 } |
|
108 ExecuteAndDeleteLD(iDatabase->CompactL()); |
|
109 |
|
110 AddCategoriesL(); |
|
111 |
|
112 iActiveLmEvent = CActiveLmImportEvent::NewL(iLog); |
|
113 |
|
114 iLog->Put(_L("Test events during import")); |
|
115 ExecuteAndDeleteLD(iDatabase->CompactL()); |
|
116 LandmarkImportEventTestL(); |
|
117 |
|
118 iLog->Put(_L("Test compact during import")); |
|
119 ExecuteAndDeleteLD(iDatabase->CompactL()); |
|
120 LandmarkImportCompactTestL(); |
|
121 } |
|
122 |
|
123 // --------------------------------------------------------- |
|
124 // CPosTp53::LandmarkImportEventTestL |
|
125 // |
|
126 // (other items were commented in a header). |
|
127 // --------------------------------------------------------- |
|
128 // |
|
129 void CPosTp53::LandmarkImportEventTestL() |
|
130 { |
|
131 iActiveLmEvent->Start(); |
|
132 |
|
133 iParser = CPosLandmarkParser::NewL(KMimeType); |
|
134 |
|
135 ///////////////////////////////////////////// |
|
136 // Landmark created event #1 |
|
137 ///////////////////////////////////////////// |
|
138 ImportLandmarksL(KImportFile, CPosLandmarkDatabase::EDefaultOptions); |
|
139 |
|
140 ///////////////////////////////////////////// |
|
141 // Landmark created event #2 |
|
142 ///////////////////////////////////////////// |
|
143 ImportLandmarksL(KImportFile2, CPosLandmarkDatabase::EIncludeCategories); |
|
144 |
|
145 ///////////////////////////////////////////// |
|
146 // Landmark created event #3 |
|
147 ///////////////////////////////////////////// |
|
148 ImportLandmarksL(KImportFile3, CPosLandmarkDatabase::EIncludeCategories); |
|
149 |
|
150 ///////////////////////////////////////////// |
|
151 // Landmark created event #4 and category created event #5 |
|
152 ///////////////////////////////////////////// |
|
153 ImportLandmarksL(KImportFile4, CPosLandmarkDatabase::EIncludeCategories); |
|
154 |
|
155 ///////////////////////////////////////////// |
|
156 // Landmark created event #6 and category updated event #7 |
|
157 ///////////////////////////////////////////// |
|
158 ImportLandmarksL(KImportFile5, CPosLandmarkDatabase::EIncludeCategories | CPosLandmarkDatabase::EIncludeGlobalCategoryNames); |
|
159 |
|
160 ///////////////////////////////////////////// |
|
161 // Unknown landmark changes event #8 and category created event #9 |
|
162 ///////////////////////////////////////////// |
|
163 ImportLandmarksL(KImportFile6, CPosLandmarkDatabase::EIncludeCategories); |
|
164 |
|
165 ///////////////////////////////////////////// |
|
166 // Landmark created event #10 and Unknown category changes event #11 |
|
167 ///////////////////////////////////////////// |
|
168 ImportLandmarksL(KImportFile7, CPosLandmarkDatabase::EIncludeCategories); |
|
169 |
|
170 ///////////////////////////////////////////// |
|
171 // Unknown changes event #12 |
|
172 ///////////////////////////////////////////// |
|
173 ImportLandmarksL(KImportFile8, CPosLandmarkDatabase::EIncludeCategories); |
|
174 |
|
175 |
|
176 if (iActiveLmEvent->iGlobalErr != 0) |
|
177 { |
|
178 User::Leave(KErrGeneral); |
|
179 } |
|
180 } |
|
181 |
|
182 // --------------------------------------------------------- |
|
183 // CPosTp53::ImportLandmarksL() |
|
184 // |
|
185 // (other items were commented in a header). |
|
186 // --------------------------------------------------------- |
|
187 // |
|
188 void CPosTp53::ImportLandmarksL(const TDesC& aFileName, CPosLandmarkDatabase::TTransferOptions aTransferOptions) |
|
189 { |
|
190 iParser->SetInputFileL(aFileName); |
|
191 ExecuteAndDeleteLD(iDatabase->ImportLandmarksL(*iParser, aTransferOptions)); |
|
192 CActiveScheduler::Start(); |
|
193 } |
|
194 |
|
195 // --------------------------------------------------------- |
|
196 // CPosTp53::AddCategoriesL() |
|
197 // |
|
198 // (other items were commented in a header). |
|
199 // --------------------------------------------------------- |
|
200 // |
|
201 void CPosTp53::AddCategoriesL() |
|
202 { |
|
203 CPosLmCategoryManager* cm = CPosLmCategoryManager::NewL(*iDatabase); |
|
204 CleanupStack::PushL(cm); |
|
205 |
|
206 CPosLandmarkCategory* category = CPosLandmarkCategory::NewLC(); |
|
207 category->SetCategoryNameL(KCategoryName); |
|
208 |
|
209 CPosLandmarkCategory* category2 = CPosLandmarkCategory::NewLC(); |
|
210 category2->SetCategoryNameL(KCategoryName2); |
|
211 |
|
212 CPosLandmarkCategory* category3 = CPosLandmarkCategory::NewLC(); |
|
213 category3->SetCategoryNameL(KCategoryName3); |
|
214 |
|
215 cm->AddCategoryL(*category); |
|
216 cm->AddCategoryL(*category2); |
|
217 cm->AddCategoryL(*category3); |
|
218 |
|
219 CleanupStack::PopAndDestroy(4, cm); |
|
220 } |
|
221 |
|
222 // --------------------------------------------------------- |
|
223 // CPosTp53::LandmarkImportCompactTest |
|
224 // |
|
225 // (other items were commented in a header). |
|
226 // --------------------------------------------------------- |
|
227 // |
|
228 void CPosTp53::LandmarkImportCompactTestL() |
|
229 { |
|
230 CPosLandmarkParser* parser = CPosLandmarkParser::NewL(KMimeType); |
|
231 CleanupStack::PushL(parser); |
|
232 |
|
233 User::After(200000); |
|
234 TReal32 usage = iDatabase->SizeL().iUsage; |
|
235 TInt count=0; |
|
236 |
|
237 while (usage > KCompactDbLevel) |
|
238 { |
|
239 TBuf<100> name; |
|
240 name.Format(_L("LMTP53%d"), ++count); |
|
241 |
|
242 CPosLandmark* landmark = CPosLandmark::NewLC(); |
|
243 landmark->SetLandmarkNameL(name); |
|
244 iDatabase->AddLandmarkL(*landmark); |
|
245 User::After(200000); |
|
246 |
|
247 CleanupStack::PopAndDestroy(landmark); |
|
248 |
|
249 usage = iDatabase->SizeL().iUsage; |
|
250 } |
|
251 |
|
252 parser->SetInputFileL(KCompactImportFile); |
|
253 |
|
254 iLog->Put(_L("importing...")); |
|
255 ExecuteAndDeleteLD(iDatabase->ImportLandmarksL(*parser, CPosLandmarkDatabase::EDefaultOptions)); |
|
256 iLog->Put(_L("importing...Done")); |
|
257 User::After(200000); |
|
258 |
|
259 usage = iDatabase->SizeL().iUsage; |
|
260 |
|
261 AssertTrueSecL(usage >= KCompactDbLevel, _L("Import operation haven't done compact on the database")); |
|
262 |
|
263 CleanupStack::PopAndDestroy(parser); |
|
264 } |
|
265 |
|
266 // ----------------------------------------------------------------------------- |
|
267 // CActiveLmImportEvent::NewL |
|
268 // |
|
269 //(other items were commented in a header). |
|
270 // ----------------------------------------------------------------------------- |
|
271 // |
|
272 CActiveLmImportEvent* CActiveLmImportEvent::NewL(MUtfwLog* aLog) |
|
273 { |
|
274 CActiveLmImportEvent* self = new(ELeave) CActiveLmImportEvent(aLog); |
|
275 CleanupStack::PushL(self); |
|
276 self->ConstructL(); |
|
277 CleanupStack::Pop(); |
|
278 return self; |
|
279 } |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // CActiveLmImportEvent::ConstructL |
|
283 // |
|
284 //(other items were commented in a header). |
|
285 // ----------------------------------------------------------------------------- |
|
286 // |
|
287 void CActiveLmImportEvent::ConstructL() |
|
288 { |
|
289 iDatabase = CPosLandmarkDatabase::OpenL(); |
|
290 } |
|
291 |
|
292 // ----------------------------------------------------------------------------- |
|
293 // CActiveLmImportEvent::CActiveLmImportEvent |
|
294 // C++ default constructor can NOT contain any code, that |
|
295 // might leave. |
|
296 // ----------------------------------------------------------------------------- |
|
297 // |
|
298 |
|
299 CActiveLmImportEvent::CActiveLmImportEvent(MUtfwLog* aLog) : |
|
300 CActive(EPriorityNormal), |
|
301 iLog(aLog) |
|
302 { |
|
303 CActiveScheduler::Add(this); |
|
304 } |
|
305 |
|
306 // Destructor |
|
307 CActiveLmImportEvent::~CActiveLmImportEvent() |
|
308 { |
|
309 Cancel(); |
|
310 delete iDatabase; |
|
311 iDatabase = NULL; |
|
312 } |
|
313 |
|
314 // --------------------------------------------------------- |
|
315 // CActiveLmImportEvent::StartL |
|
316 // |
|
317 // (other items were commented in a header). |
|
318 // --------------------------------------------------------- |
|
319 // |
|
320 void CActiveLmImportEvent::Start() |
|
321 { |
|
322 iDatabase->NotifyDatabaseEvent(iEvent, iStatus); |
|
323 |
|
324 SetActive(); |
|
325 } |
|
326 |
|
327 // --------------------------------------------------------- |
|
328 // CActiveLmImportEvent::RunL |
|
329 // |
|
330 // (other items were commented in a header). |
|
331 // --------------------------------------------------------- |
|
332 // |
|
333 void CActiveLmImportEvent::RunL() |
|
334 { |
|
335 VerifyEvent(); |
|
336 |
|
337 iDatabase->NotifyDatabaseEvent(iEvent, iStatus); |
|
338 SetActive(); |
|
339 } |
|
340 |
|
341 // --------------------------------------------------------- |
|
342 // CActiveLmOperation::DoCancel |
|
343 // |
|
344 // (other items were commented in a header). |
|
345 // --------------------------------------------------------- |
|
346 // |
|
347 void CActiveLmImportEvent::DoCancel() |
|
348 { |
|
349 iDatabase->CancelNotifyDatabaseEvent(); |
|
350 } |
|
351 |
|
352 // --------------------------------------------------------- |
|
353 // CActiveLmImportEvent::VerifyEvent |
|
354 // |
|
355 // (other items were commented in a header). |
|
356 // --------------------------------------------------------- |
|
357 // |
|
358 void CActiveLmImportEvent::VerifyEvent() |
|
359 { |
|
360 iEventNumber++; |
|
361 switch (iEventNumber) |
|
362 { |
|
363 case 1: |
|
364 case 2: |
|
365 case 3: |
|
366 AssertCorrectEvent(EPosLmEventLandmarkCreated, iEvent.iEventType, iEventNumber, iEvent.iLandmarkItemId); |
|
367 CActiveScheduler::Stop(); |
|
368 break; |
|
369 case 4: |
|
370 AssertCorrectEvent(EPosLmEventLandmarkCreated, iEvent.iEventType, iEventNumber, iEvent.iLandmarkItemId); |
|
371 break; |
|
372 case 5: |
|
373 AssertCorrectEvent(EPosLmEventCategoryCreated, iEvent.iEventType, 14, iEvent.iLandmarkItemId); |
|
374 CActiveScheduler::Stop(); |
|
375 break; |
|
376 case 6: |
|
377 AssertCorrectEvent(EPosLmEventLandmarkCreated, iEvent.iEventType, 5, iEvent.iLandmarkItemId); |
|
378 break; |
|
379 case 7: |
|
380 AssertCorrectEvent(EPosLmEventCategoryUpdated, iEvent.iEventType, 2, iEvent.iLandmarkItemId); |
|
381 CActiveScheduler::Stop(); |
|
382 break; |
|
383 case 8: |
|
384 AssertCorrectEvent(EPosLmEventCategoryCreated, iEvent.iEventType, 15, iEvent.iLandmarkItemId); |
|
385 break; |
|
386 case 9: |
|
387 // Two landmarks added |
|
388 AssertCorrectEvent(EPosLmEventLandmarkUnknownChanges, iEvent.iEventType, 0, iEvent.iLandmarkItemId); |
|
389 CActiveScheduler::Stop(); |
|
390 break; |
|
391 case 10: |
|
392 AssertCorrectEvent(EPosLmEventLandmarkCreated, iEvent.iEventType, 8, iEvent.iLandmarkItemId); |
|
393 break; |
|
394 case 11: |
|
395 AssertCorrectEvent(EPosLmEventCategoryUnknownChanges, iEvent.iEventType, 0, iEvent.iLandmarkItemId); |
|
396 CActiveScheduler::Stop(); |
|
397 break; |
|
398 case 12: |
|
399 AssertCorrectEvent(EPosLmEventUnknownChanges, iEvent.iEventType, 0, iEvent.iLandmarkItemId); |
|
400 CActiveScheduler::Stop(); |
|
401 break; |
|
402 default: |
|
403 iLog->Put(_L("Unexpected event received")); |
|
404 ++iGlobalErr; |
|
405 CActiveScheduler::Stop(); |
|
406 break; |
|
407 } |
|
408 } |
|
409 // --------------------------------------------------------- |
|
410 // CActiveLmImportEvent::AssertCorrectEvent |
|
411 // |
|
412 // (other items were commented in a header). |
|
413 // --------------------------------------------------------- |
|
414 // |
|
415 void CActiveLmImportEvent::AssertCorrectEvent( |
|
416 TPosLmEventType aExpectedEventType, |
|
417 TPosLmEventType aEventType, |
|
418 TPosLmItemId aExpectedLandMarkItemId, |
|
419 TPosLmItemId aLandMarkItemId) |
|
420 { |
|
421 if (aExpectedEventType != aEventType) |
|
422 { |
|
423 _LIT(KError,"Unexpected eventtype. Excpected %d got %d\r\n"); |
|
424 TBuf<200> error; |
|
425 error.Format(KError, aExpectedEventType, aEventType); |
|
426 iLog->Put(error); |
|
427 iGlobalErr++; |
|
428 } |
|
429 else |
|
430 { |
|
431 TBuf<50> debug; |
|
432 debug.Format(_L("Received event %d"), aEventType); |
|
433 iLog->Put(debug); |
|
434 } |
|
435 |
|
436 if (aExpectedLandMarkItemId != aLandMarkItemId) |
|
437 { |
|
438 _LIT(KError,"Unexpected item id. Excpected %d got %d\r\n"); |
|
439 TBuf<200> error; |
|
440 error.Format(KError, aExpectedLandMarkItemId, aLandMarkItemId); |
|
441 iLog->Put(error); |
|
442 iGlobalErr++; |
|
443 } |
|
444 else |
|
445 { |
|
446 TBuf<50> debug; |
|
447 debug.Format(_L("Received item id %d"), aLandMarkItemId); |
|
448 iLog->Put(debug); |
|
449 } |
|
450 } |
|
451 |
|
452 // End of file |