1 /* |
|
2 * Copyright (c) 2008-2009 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 "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 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "tbackuprestorestep.h" |
|
20 #include <test/testexecutelog.h> |
|
21 |
|
22 #include "swi/backuprestore.h" |
|
23 #include "cleanuputils.h" |
|
24 |
|
25 CTStepBackup::CTStepBackup() |
|
26 { |
|
27 SetTestStepName(KTStepBackup); |
|
28 } |
|
29 |
|
30 TVerdict CTStepBackup::doTestStepL() |
|
31 { |
|
32 if (TestStepResult() != EPass) |
|
33 { |
|
34 return TestStepResult(); |
|
35 } |
|
36 |
|
37 RFs fs; |
|
38 User::LeaveIfError(fs.Connect()); |
|
39 CleanupClosePushL(fs); |
|
40 |
|
41 Swi::RBackupSession session; |
|
42 User::LeaveIfError(session.Connect()); |
|
43 CleanupClosePushL(session); |
|
44 |
|
45 while (NextPackage()) |
|
46 { |
|
47 TInt cellCountBefore = User::CountAllocCells(); |
|
48 |
|
49 RPointerArray<HBufC> files; |
|
50 CleanupResetAndDestroyPushL(files); |
|
51 HBufC8* metadata = session.GetMetaDataL(PackageUID(), files); |
|
52 CleanupStack::PopAndDestroy(&files); // ignore this parameter |
|
53 CleanupStack::PushL(metadata); |
|
54 WriteMetaDataL(metadata); |
|
55 CleanupStack::PopAndDestroy(metadata); |
|
56 |
|
57 TInt cellCountAfter = User::CountAllocCells(); |
|
58 |
|
59 if ( cellCountAfter - cellCountBefore ) |
|
60 { |
|
61 ERR_PRINTF2(_L("Memory Leak is Detected in TVerdict CTStepBackup::doTestStepL(): %d cell(s)"), |
|
62 cellCountAfter - cellCountBefore); |
|
63 SetTestStepResult(EFail); |
|
64 CleanupStack::PopAndDestroy(2, &fs); // session; |
|
65 return TestStepResult(); |
|
66 } |
|
67 |
|
68 |
|
69 while (NextFile()) |
|
70 { |
|
71 CopyFileL(InstalledFileName(), BackupFileName()); |
|
72 if (ModifyFile()) |
|
73 { |
|
74 // write some note to the end of this file |
|
75 RFile backup; |
|
76 User::LeaveIfError(backup.Open(fs, BackupFileName(), EFileWrite)); |
|
77 CleanupClosePushL(backup); |
|
78 |
|
79 _LIT8(KSomeSpuriousCrap, "ALL YOUR RESTORES ARE BELONG TO US"); |
|
80 TInt pos = 0; |
|
81 User::LeaveIfError(backup.Seek(ESeekEnd, pos)); |
|
82 User::LeaveIfError(backup.Write(KSomeSpuriousCrap)); |
|
83 |
|
84 CleanupStack::PopAndDestroy(&backup); |
|
85 } |
|
86 } |
|
87 } |
|
88 |
|
89 CleanupStack::PopAndDestroy(2, &fs); // session; |
|
90 |
|
91 return TestStepResult(); |
|
92 } |
|