|
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_CPosTp114.h" |
|
23 #include <EPos_CPosLandmarkDatabase.h> |
|
24 #include <EPos_CPosLmDatabaseManager.h> |
|
25 #include <connect/sbdefs.h> |
|
26 |
|
27 // ================= MEMBER FUNCTIONS ======================= |
|
28 |
|
29 // --------------------------------------------------------- |
|
30 // CPosTp114::GetName |
|
31 // |
|
32 // (other items were commented in a header). |
|
33 // --------------------------------------------------------- |
|
34 // |
|
35 void CPosTp114::GetName(TDes& aName) const |
|
36 { |
|
37 _LIT(KTestName, "Tp114 - Landmark database backup/restore"); |
|
38 aName = KTestName; |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------- |
|
42 // CPosTp114::CloseTest |
|
43 // |
|
44 // (other items were commented in a header). |
|
45 // --------------------------------------------------------- |
|
46 // |
|
47 void CPosTp114::CloseTest() |
|
48 { |
|
49 iLog->Put(_L("CloseTest")); |
|
50 } |
|
51 |
|
52 /** |
|
53 * Performes the test by connecting to the landmarks server |
|
54 |
|
55 Test LMREQ152: Landmarks DB backup |
|
56 Backup and restore of all Landmarks databases using the system backup shall be possible. |
|
57 The clients are responsible for release of databases during backup/restore. |
|
58 A database directly accessed by a client will not be possible to backup/restore. |
|
59 |
|
60 */ |
|
61 // --------------------------------------------------------- |
|
62 // CPosTp114::StartL |
|
63 // |
|
64 // (other items were commented in a header). |
|
65 // --------------------------------------------------------- |
|
66 // |
|
67 void CPosTp114::StartL() |
|
68 { |
|
69 TBool backupTest = FileExistL(); |
|
70 |
|
71 iLog->Put(_L("DoTestL")); |
|
72 |
|
73 CPosTp114BackupListener* backupListener = CPosTp114BackupListener::NewL(iLog); |
|
74 CleanupStack::PushL(backupListener); |
|
75 |
|
76 if (backupTest) |
|
77 { |
|
78 iLog->Put(_L("Backup Test")); |
|
79 // Backup part |
|
80 InitBackupTestL(); |
|
81 } |
|
82 else |
|
83 { |
|
84 iLog->Put(_L("Restore Test")); |
|
85 iLog->Put(_L("Connnect to eposlmserver")); |
|
86 // Restore part |
|
87 CPosLmDatabaseManager* dbManager = CPosLmDatabaseManager::NewL(); |
|
88 CleanupStack::PushL(dbManager); |
|
89 |
|
90 CDesCArray* dbArray = dbManager->ListDatabasesLC(); |
|
91 //TInt count = dbArray->Count(); |
|
92 CleanupStack::PopAndDestroy(dbArray); |
|
93 CleanupStack::PopAndDestroy(dbManager); |
|
94 } |
|
95 |
|
96 // Check landmark server |
|
97 _LIT(KPosLandmarksServerName, "*eposlmserver*"); |
|
98 |
|
99 User::After(5000000); // XXX Add some time here |
|
100 TBool result = ETrue; |
|
101 TBool alive = ServerAlive(KPosLandmarksServerName); |
|
102 if(alive) iLog->Put(_L("ERROR: Server is stil alive")); |
|
103 |
|
104 |
|
105 if (backupTest) |
|
106 { |
|
107 _LIT(KStartBackup, "Now start backup but first press OK"); |
|
108 TUtfwUserAnswer answer = iUserInfo->ShowDialog(KStartBackup, EUtfwDialogTypeOk, EFalse); |
|
109 |
|
110 if(answer == EUtfwUserAnswerOk) |
|
111 { |
|
112 backupListener->StartCheckingL(); |
|
113 User::After(10000000); // Wait some time here so that backup is really finished |
|
114 } |
|
115 } |
|
116 else |
|
117 { |
|
118 _LIT(KStartRestore, "Now start restore, but first press OK"); |
|
119 TUtfwUserAnswer answer = iUserInfo->ShowDialog(KStartRestore, EUtfwDialogTypeOk, EFalse); |
|
120 |
|
121 if(answer == EUtfwUserAnswerOk) |
|
122 { |
|
123 backupListener->StartCheckingL(); |
|
124 User::After(10000000); // Wait some time here so that restore is really finished |
|
125 } |
|
126 } |
|
127 |
|
128 if (backupTest) |
|
129 { |
|
130 // Prepare dbs for restore part |
|
131 PrepareForRestoreTestL(); |
|
132 } |
|
133 else |
|
134 { |
|
135 // Check correct dbs and landmarks restored |
|
136 result = CheckDbAfterRestoreL(); |
|
137 } |
|
138 |
|
139 backupListener->Cancel(); |
|
140 CleanupStack::PopAndDestroy(backupListener); |
|
141 |
|
142 if (!result) LogErrorAndLeave(_L("Errors found when restoring")); |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------- |
|
146 // CPosTp114::CheckDbAfterRestoreL |
|
147 // |
|
148 // (other items were commented in a header). |
|
149 // --------------------------------------------------------- |
|
150 // |
|
151 TBool CPosTp114::CheckDbAfterRestoreL() |
|
152 { |
|
153 // Check that three landmark dbs exist |
|
154 // Check that all dbs contain three landmarks |
|
155 _LIT(DB1, "file://C:backupDb1.ldb"); |
|
156 _LIT(DB2, "file://C:backupDb2.ldb"); |
|
157 _LIT(DB3, "file://C:backupDb3.ldb"); |
|
158 |
|
159 iLog->Put(_L("CheckDbAfterRestoreL")); |
|
160 |
|
161 CPosLmDatabaseManager* dbManager = CPosLmDatabaseManager::NewL(); |
|
162 CleanupStack::PushL(dbManager); |
|
163 |
|
164 TBool result = ETrue; |
|
165 |
|
166 CDesCArray* dbArray = dbManager->ListDatabasesLC(); |
|
167 TInt count = dbArray->Count(); |
|
168 //AssertTrueL(count == 3, _L("Wrong nr of dbs after restore")); |
|
169 if (count != 3) |
|
170 { |
|
171 iLog->Put(_L("ERROR: Wrong nr of dbs after restore")); |
|
172 result = EFalse; |
|
173 } |
|
174 |
|
175 TInt pos; |
|
176 |
|
177 if (dbArray->Find(DB1, pos) != 0 || |
|
178 dbArray->Find(DB2, pos) != 0 || |
|
179 dbArray->Find(DB3, pos) != 0) |
|
180 { |
|
181 iLog->Put(_L("Could not find db")); |
|
182 result = EFalse; |
|
183 } |
|
184 |
|
185 CleanupStack::PopAndDestroy(dbArray); |
|
186 CleanupStack::PopAndDestroy(dbManager); |
|
187 |
|
188 CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL(DB1); |
|
189 CleanupStack::PushL(db); |
|
190 |
|
191 CPosLmItemIterator* iter = db->LandmarkIteratorL(); |
|
192 CleanupStack::PushL(iter); |
|
193 |
|
194 TInt numberOfElements = iter->NumOfItemsL(); |
|
195 if (numberOfElements != 3) |
|
196 { |
|
197 iLog->Put(_L("Wrong number of landmarks in DB1 ")); |
|
198 result = EFalse; |
|
199 } |
|
200 |
|
201 CleanupStack::PopAndDestroy(iter); |
|
202 CleanupStack::PopAndDestroy(db); |
|
203 |
|
204 return result; |
|
205 } |
|
206 |
|
207 // --------------------------------------------------------- |
|
208 // CPosTp114::InitBackupTestL |
|
209 // |
|
210 // (other items were commented in a header). |
|
211 // --------------------------------------------------------- |
|
212 // |
|
213 void CPosTp114::InitBackupTestL() |
|
214 { |
|
215 iLog->Put(_L("InitBackupTestL")); |
|
216 // Use this part to create three landmark dbs with some landmarks |
|
217 _LIT(DB1, "backupDb1.ldb"); |
|
218 _LIT(DB2, "backupDb2.ldb"); |
|
219 _LIT(DB3, "backupDb3.ldb"); |
|
220 |
|
221 // Firts remove all landmark dbs |
|
222 CPosLmDatabaseManager* dbManager = CPosLmDatabaseManager::NewL(); |
|
223 CleanupStack::PushL(dbManager); |
|
224 |
|
225 CDesCArray* dbArray = dbManager->ListDatabasesLC(); |
|
226 TInt count = dbArray->Count(); |
|
227 |
|
228 for (TInt i=0;i<count;i++) |
|
229 { |
|
230 dbManager->DeleteDatabaseL((*dbArray)[i]); |
|
231 } |
|
232 |
|
233 CleanupStack::PopAndDestroy(dbArray); |
|
234 |
|
235 HPosLmDatabaseInfo* dbInfo = HPosLmDatabaseInfo::NewLC(DB1); |
|
236 dbManager->CreateDatabaseL(*dbInfo); |
|
237 CleanupStack::PopAndDestroy(dbInfo); |
|
238 |
|
239 dbInfo = HPosLmDatabaseInfo::NewLC(DB2); |
|
240 dbManager->CreateDatabaseL(*dbInfo); |
|
241 CleanupStack::PopAndDestroy(dbInfo); |
|
242 |
|
243 dbInfo = HPosLmDatabaseInfo::NewLC(DB3); |
|
244 dbManager->CreateDatabaseL(*dbInfo); |
|
245 CleanupStack::PopAndDestroy(dbInfo); |
|
246 |
|
247 // Add landmarks to db1 |
|
248 CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL(DB1); |
|
249 CleanupStack::PushL(db); |
|
250 if (db->IsInitializingNeeded()) ExecuteAndDeleteLD(db->InitializeL()); |
|
251 |
|
252 CPosLandmark* lm1 = CPosLandmark::NewLC(); |
|
253 lm1->SetLandmarkNameL(_L("TP114_Db1_Lm1")); |
|
254 db->AddLandmarkL(*lm1); |
|
255 CleanupStack::PopAndDestroy(lm1); |
|
256 CPosLandmark* lm2 = CPosLandmark::NewLC(); |
|
257 lm2->SetLandmarkNameL(_L("TP114_Db1_Lm2")); |
|
258 db->AddLandmarkL(*lm2); |
|
259 CleanupStack::PopAndDestroy(lm2); |
|
260 CPosLandmark* lm3 = CPosLandmark::NewLC(); |
|
261 lm3->SetLandmarkNameL(_L("TP114_Db1_Lm3")); |
|
262 db->AddLandmarkL(*lm3); |
|
263 CleanupStack::PopAndDestroy(lm3); |
|
264 ExecuteAndDeleteLD(db->CompactL()); |
|
265 CleanupStack::PopAndDestroy(db); |
|
266 |
|
267 // Add landmarks to db2 |
|
268 db = CPosLandmarkDatabase::OpenL(DB2); |
|
269 CleanupStack::PushL(db); |
|
270 if (db->IsInitializingNeeded()) ExecuteAndDeleteLD(db->InitializeL()); |
|
271 |
|
272 lm1 = CPosLandmark::NewLC(); |
|
273 lm1->SetLandmarkNameL(_L("TP114_Db2_Lm1")); |
|
274 db->AddLandmarkL(*lm1); |
|
275 CleanupStack::PopAndDestroy(lm1); |
|
276 lm2 = CPosLandmark::NewLC(); |
|
277 lm2->SetLandmarkNameL(_L("TP114_Db2_Lm2")); |
|
278 db->AddLandmarkL(*lm2); |
|
279 CleanupStack::PopAndDestroy(lm2); |
|
280 lm3 = CPosLandmark::NewLC(); |
|
281 lm3->SetLandmarkNameL(_L("TP114_Db2_Lm3")); |
|
282 db->AddLandmarkL(*lm3); |
|
283 CleanupStack::PopAndDestroy(lm3); |
|
284 ExecuteAndDeleteLD(db->CompactL()); |
|
285 CleanupStack::PopAndDestroy(db); |
|
286 |
|
287 // Add landmarks to db3 |
|
288 db = CPosLandmarkDatabase::OpenL(DB3); |
|
289 CleanupStack::PushL(db); |
|
290 if (db->IsInitializingNeeded()) ExecuteAndDeleteLD(db->InitializeL()); |
|
291 |
|
292 lm1 = CPosLandmark::NewLC(); |
|
293 lm1->SetLandmarkNameL(_L("TP114_Db3_Lm1")); |
|
294 db->AddLandmarkL(*lm1); |
|
295 CleanupStack::PopAndDestroy(lm1); |
|
296 lm2 = CPosLandmark::NewLC(); |
|
297 lm2->SetLandmarkNameL(_L("TP114_Db3_Lm2")); |
|
298 db->AddLandmarkL(*lm2); |
|
299 CleanupStack::PopAndDestroy(lm2); |
|
300 lm3 = CPosLandmark::NewLC(); |
|
301 lm3->SetLandmarkNameL(_L("TP114_Db3_Lm3")); |
|
302 db->AddLandmarkL(*lm3); |
|
303 CleanupStack::PopAndDestroy(lm3); |
|
304 ExecuteAndDeleteLD(db->CompactL()); |
|
305 CleanupStack::PopAndDestroy(db); |
|
306 |
|
307 CleanupStack::PopAndDestroy(dbManager); |
|
308 iLog->Put(_L("InitBackupTestL Done")); |
|
309 } |
|
310 |
|
311 // --------------------------------------------------------- |
|
312 // CPosTp114::PrepareForRestoreTestL |
|
313 // |
|
314 // (other items were commented in a header). |
|
315 // --------------------------------------------------------- |
|
316 // |
|
317 void CPosTp114::PrepareForRestoreTestL() |
|
318 { |
|
319 _LIT(DB1, "backupDb1.ldb"); |
|
320 _LIT(DB2, "backupDb2.ldb"); |
|
321 |
|
322 iLog->Put(_L("PrepareForRestoreTestL")); |
|
323 |
|
324 // Remove db2 and remove some landmarks from db1 |
|
325 CPosLmDatabaseManager* dbManager = CPosLmDatabaseManager::NewL(); |
|
326 CleanupStack::PushL(dbManager); |
|
327 |
|
328 //dbManager->DeleteDatabaseL(DB2); |
|
329 DeleteFileL(_L("c:\\private\\100012a5\\DBS_101FE978_backupDb2.ldb")); |
|
330 |
|
331 CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL(DB1); |
|
332 CleanupStack::PushL(db); |
|
333 |
|
334 CPosLmItemIterator* iter = db->LandmarkIteratorL(); |
|
335 CleanupStack::PushL(iter); |
|
336 |
|
337 RArray<TPosLmItemId> arrayOfIds; |
|
338 CleanupClosePushL(arrayOfIds); |
|
339 |
|
340 TInt numberOfElements = iter->NumOfItemsL(); |
|
341 iter->GetItemIdsL(arrayOfIds, 0, (numberOfElements-1)); |
|
342 |
|
343 ExecuteAndDeleteLD(db->RemoveLandmarksL(arrayOfIds)); |
|
344 TBuf<100> buf; |
|
345 buf.Format(_L("Removing %d nr of landmarks from db1"), arrayOfIds.Count()); |
|
346 iLog->Put(buf); |
|
347 |
|
348 CleanupStack::PopAndDestroy(&arrayOfIds); |
|
349 CleanupStack::PopAndDestroy(iter); |
|
350 CleanupStack::PopAndDestroy(db); |
|
351 CleanupStack::PopAndDestroy(dbManager); |
|
352 |
|
353 iLog->Put(_L("PrepareForRestoreTestL Done")); |
|
354 } |
|
355 |
|
356 // --------------------------------------------------------- |
|
357 // CPosTp114::FileExistL |
|
358 // |
|
359 // (other items were commented in a header). |
|
360 // --------------------------------------------------------- |
|
361 // |
|
362 TBool CPosTp114::FileExistL() |
|
363 { |
|
364 _LIT(KIniFile, "c:\\TP114backupTest.ini"); |
|
365 |
|
366 RFs fileserver; |
|
367 RFile file; |
|
368 TBool exist = EFalse; |
|
369 |
|
370 User::LeaveIfError(fileserver.Connect()); |
|
371 TInt err = file.Open(fileserver, KIniFile, EFileWrite); |
|
372 if (err == KErrNotFound) |
|
373 { |
|
374 TInt err = file.Create(fileserver, KIniFile, EFileWrite); |
|
375 exist = ETrue; |
|
376 file.Close(); |
|
377 iLog->Put(_L("File has been created")); |
|
378 } |
|
379 else |
|
380 { |
|
381 file.Close(); |
|
382 TInt err = fileserver.Delete(KIniFile); |
|
383 if (err != KErrNone) |
|
384 { |
|
385 TBuf<50> buf; |
|
386 buf.Format(_L("Could not delete c:\\TP114backupTest.ini, err %d"), err); |
|
387 iLog->Put(buf); |
|
388 } |
|
389 else |
|
390 { |
|
391 iLog->Put(_L("File has been deleted")); |
|
392 } |
|
393 |
|
394 exist = EFalse; |
|
395 } |
|
396 |
|
397 fileserver.Close(); |
|
398 return exist; |
|
399 } |
|
400 |
|
401 |
|
402 // ----------------------------------------------------------------------------- |
|
403 // CPosTp114BackupListener |
|
404 // |
|
405 // ----------------------------------------------------------------------------- |
|
406 // |
|
407 CPosTp114BackupListener::CPosTp114BackupListener() |
|
408 : CActive(EPriorityLow) |
|
409 { |
|
410 } |
|
411 |
|
412 // ----------------------------------------------------------------------------- |
|
413 // CPosTp114BackupListener::ConstructL |
|
414 // Symbian 2nd phase constructor can leave. |
|
415 // ----------------------------------------------------------------------------- |
|
416 // |
|
417 void CPosTp114BackupListener::ConstructL(MUtfwLog* aLog) |
|
418 { |
|
419 TUid categoryUid; |
|
420 categoryUid.iUid = KUidSystemCategoryValue; |
|
421 User::LeaveIfError(iProperty.Attach(categoryUid, |
|
422 conn::KUidBackupRestoreKey)); |
|
423 CActiveScheduler::Add(this); |
|
424 iLog = aLog; |
|
425 iBackupIsRunning = EFalse; |
|
426 |
|
427 // initial subscription and process current property value |
|
428 RunL(); |
|
429 } |
|
430 |
|
431 // Two-phased constructor |
|
432 CPosTp114BackupListener* CPosTp114BackupListener::NewL(MUtfwLog* aLog) |
|
433 { |
|
434 CPosTp114BackupListener* self = |
|
435 new (ELeave) CPosTp114BackupListener; |
|
436 CleanupStack::PushL(self); |
|
437 self->ConstructL(aLog); |
|
438 |
|
439 CleanupStack::Pop(self); |
|
440 return self; |
|
441 } |
|
442 |
|
443 // Destructor |
|
444 CPosTp114BackupListener::~CPosTp114BackupListener() |
|
445 { |
|
446 Cancel(); |
|
447 iProperty.Close(); |
|
448 } |
|
449 |
|
450 // ----------------------------------------------------------------------------- |
|
451 // CPosTp114BackupListener::RunL |
|
452 // |
|
453 // (other items were commented in a header). |
|
454 // ----------------------------------------------------------------------------- |
|
455 // |
|
456 void CPosTp114BackupListener::RunL() |
|
457 { |
|
458 iLog->Put(_L("RunL")); |
|
459 // resubscribe before processing new value to prevent missing updates. |
|
460 iProperty.Subscribe(iStatus); |
|
461 SetActive(); |
|
462 |
|
463 if (IsBackupRunning()) |
|
464 { |
|
465 iLog->Put(_L("Backup (Restore) is Running....")); |
|
466 iBackupIsRunning = ETrue; |
|
467 } |
|
468 |
|
469 //Check if back to normal (after backup/restore) |
|
470 if (!IsBackupRunning() && iBackupIsRunning) |
|
471 { |
|
472 iLog->Put(_L("After backup/restore")); |
|
473 iBackupIsRunning = EFalse; |
|
474 CActiveScheduler::Stop(); |
|
475 } |
|
476 } |
|
477 |
|
478 // ----------------------------------------------------------------------------- |
|
479 // CPosTp114BackupListener::StartCheckingL |
|
480 // |
|
481 // (other items were commented in a header). |
|
482 // ----------------------------------------------------------------------------- |
|
483 // |
|
484 void CPosTp114BackupListener::StartCheckingL() |
|
485 { |
|
486 CActiveScheduler::Start(); |
|
487 } |
|
488 |
|
489 // ----------------------------------------------------------------------------- |
|
490 // CPosTp114BackupListener::IsBackupRunning |
|
491 // |
|
492 // (other items were commented in a header). |
|
493 // ----------------------------------------------------------------------------- |
|
494 // |
|
495 TBool CPosTp114BackupListener::IsBackupRunning() |
|
496 { |
|
497 TBool backupIsRunning = EFalse; |
|
498 TInt value = 0; |
|
499 TInt err = iProperty.Get(value); |
|
500 |
|
501 if (err == KErrNone) |
|
502 { |
|
503 // Use mask to get rid of unwanted info |
|
504 TInt partType = conn::KBURPartTypeMask & value; |
|
505 |
|
506 // The values EBURUnset or EBURNormal mean |
|
507 // that no backup/restore is ongoing. |
|
508 if (partType == conn::EBURUnset || partType == conn::EBURNormal) |
|
509 { |
|
510 backupIsRunning = EFalse; |
|
511 } |
|
512 else |
|
513 { |
|
514 backupIsRunning = ETrue; |
|
515 } |
|
516 } |
|
517 else if (err == KErrNotFound) |
|
518 { |
|
519 // If property is not found, assume that no backup is in progress |
|
520 backupIsRunning = EFalse; |
|
521 } |
|
522 else |
|
523 { |
|
524 // Some other error occured. In this case, |
|
525 // assume that backup is running. |
|
526 backupIsRunning = ETrue; |
|
527 } |
|
528 |
|
529 return backupIsRunning; |
|
530 } |
|
531 |
|
532 // ----------------------------------------------------------------------------- |
|
533 // CPosTp114BackupListener::DoCancel |
|
534 // |
|
535 // (other items were commented in a header). |
|
536 // ----------------------------------------------------------------------------- |
|
537 // |
|
538 void CPosTp114BackupListener::DoCancel() |
|
539 { |
|
540 iLog->Put(_L("DoCancel")); |
|
541 iProperty.Cancel(); |
|
542 } |
|
543 |
|
544 // End of File |