55
|
1 |
// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
//
|
|
15 |
|
|
16 |
#include <e32test.h>
|
|
17 |
#include <f32file.h>
|
|
18 |
#include <badesca.h>
|
|
19 |
#include "srvrepos_noc.h"
|
|
20 |
#include "srvres.h"
|
|
21 |
#include "cachemgr.h"
|
|
22 |
#include "backup.h"
|
|
23 |
#include "t_cenrep_helper.h"
|
|
24 |
|
|
25 |
RTest TheTest(_L("t_cenrep_pma_bur.exe"));
|
|
26 |
|
|
27 |
enum FileSet
|
|
28 |
{
|
|
29 |
EOriginals,
|
|
30 |
EChanged,
|
|
31 |
ERemoved,
|
|
32 |
EDEF058823L
|
|
33 |
};
|
|
34 |
|
|
35 |
CRepositoryBackupClient* backupClient;
|
|
36 |
|
|
37 |
CActiveScheduler* globalAS;
|
|
38 |
|
|
39 |
const TUid KUidPmaBackupTestRepository1 = { 0xf1000201 };
|
|
40 |
const TUid KUidPmaBackupTestRepository2 = { 0xf1000202 };
|
|
41 |
const TUid KUidPmaBackupTestRepository3 = { 0xf1000203 };
|
|
42 |
const TUid KUidPmaBackupTestRepository4 = { 0xf1000204 };
|
|
43 |
const TUid KUidPmaBackupTestRepository5 = { 0xf1000205 };
|
|
44 |
|
|
45 |
///////////////////////////////////////////////////////////////////////////////////////
|
|
46 |
///////////////////////////////////////////////////////////////////////////////////////
|
|
47 |
//Test macros and functions
|
|
48 |
|
|
49 |
LOCAL_C void DeleteFilesL()
|
|
50 |
{
|
|
51 |
_LIT( KOldInstallFiles, "c:\\private\\102081E4\\*.*" );
|
|
52 |
_LIT( KOldPersistFiles, "c:\\private\\102081E4\\persists\\*.*" );
|
|
53 |
_LIT( KOldPMAFiles, "c:\\private\\102081E4\\persists\\protected\\*.*" );
|
|
54 |
|
|
55 |
RFs fs;
|
|
56 |
User::LeaveIfError(fs.Connect());
|
|
57 |
CleanupClosePushL(fs);
|
|
58 |
CFileMan* fm = CFileMan::NewL( fs );
|
|
59 |
CleanupStack::PushL( fm );
|
|
60 |
|
|
61 |
TInt r = KErrNone;
|
|
62 |
|
|
63 |
r = fm->Attribs( KOldInstallFiles, KEntryAttArchive, KEntryAttReadOnly, TTime( 0 ), CFileMan::ERecurse );
|
|
64 |
if ( r != KErrNone && r != KErrNotFound && r != KErrPathNotFound )
|
|
65 |
User::Leave(r);
|
|
66 |
r = fm->Delete( KOldInstallFiles );
|
|
67 |
if ( r != KErrNone && r != KErrNotFound && r != KErrPathNotFound )
|
|
68 |
User::Leave(r);
|
|
69 |
|
|
70 |
r = fm->Attribs( KOldPersistFiles, KEntryAttArchive, KEntryAttReadOnly, TTime( 0 ), CFileMan::ERecurse );
|
|
71 |
if ( r != KErrNone && r != KErrNotFound && r != KErrPathNotFound )
|
|
72 |
User::Leave(r);
|
|
73 |
r = fm->Delete( KOldPersistFiles );
|
|
74 |
if ( r != KErrNone && r != KErrNotFound && r != KErrPathNotFound )
|
|
75 |
User::Leave(r);
|
|
76 |
|
|
77 |
r = fm->Attribs( KOldPMAFiles, KEntryAttArchive, KEntryAttReadOnly, TTime( 0 ), CFileMan::ERecurse );
|
|
78 |
if ( r != KErrNone && r != KErrNotFound && r != KErrPathNotFound )
|
|
79 |
User::Leave(r);
|
|
80 |
r = fm->Delete( KOldPMAFiles );
|
|
81 |
if ( r != KErrNone && r != KErrNotFound && r != KErrPathNotFound )
|
|
82 |
User::Leave(r);
|
|
83 |
|
|
84 |
CleanupStack::PopAndDestroy( 2 ); //fs and fm
|
|
85 |
}
|
|
86 |
|
|
87 |
LOCAL_C void Check( TInt aValue, TInt aLine )
|
|
88 |
{
|
|
89 |
if ( !aValue )
|
|
90 |
{
|
|
91 |
TRAPD(err, DeleteFilesL());
|
|
92 |
if (err != KErrNone)
|
|
93 |
{
|
|
94 |
RDebug::Print( _L( "*** DeleteFilesL also failed with error %d expecting KErrNone\r\n"), err );
|
|
95 |
}
|
|
96 |
TheTest( EFalse, aLine );
|
|
97 |
}
|
|
98 |
}
|
|
99 |
|
|
100 |
LOCAL_C void Check( TInt aValue, TInt aExpected, TInt aLine )
|
|
101 |
{
|
|
102 |
if ( aValue != aExpected )
|
|
103 |
{
|
|
104 |
RDebug::Print( _L( "*** Expected error: %d, got: %d\r\n"), aExpected, aValue );
|
|
105 |
TRAPD(err, DeleteFilesL());
|
|
106 |
if (err != KErrNone)
|
|
107 |
{
|
|
108 |
RDebug::Print( _L( "*** DeleteFilesL also failed with error %d expecting KErrNone\r\n"), err );
|
|
109 |
}
|
|
110 |
TheTest( EFalse, aLine );
|
|
111 |
}
|
|
112 |
}
|
|
113 |
|
|
114 |
#define TEST(arg) ::Check((arg), __LINE__)
|
|
115 |
#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
|
|
116 |
|
|
117 |
///////////////////////////////////////////////////////////////////////////////////////
|
|
118 |
///////////////////////////////////////////////////////////////////////////////////////
|
|
119 |
|
|
120 |
static void CloseTServerResources(TAny*)
|
|
121 |
{
|
|
122 |
TServerResources::Close();
|
|
123 |
}
|
|
124 |
|
|
125 |
LOCAL_C void InstallFileSetL()
|
|
126 |
{
|
|
127 |
//There shouldn't be PMA keyspace in PMA drive that doesn't have its ROM equivalent
|
|
128 |
_LIT(KPmaCreReposInPMADriveSrc, "z:\\private\\10202BE9\\f1000202.pma");
|
|
129 |
_LIT(KPmaCreReposInPMADriveTgt, "c:\\private\\102081E4\\persists\\protected\\f1000202.cre");
|
|
130 |
_LIT(KPmaCreReposInPersistDirSrc, "z:\\private\\10202BE9\\f1000203.crp");
|
|
131 |
_LIT(KPmaCreReposInPersistDirTgt, "c:\\private\\102081E4\\persists\\f1000203.cre");
|
|
132 |
_LIT(KPmaTxtReposInInstallDirSrc, "z:\\private\\10202BE9\\f1000204.txi");
|
|
133 |
_LIT(KPmaTxtReposInInstallDirTgt, "c:\\private\\102081E4\\f1000204.txt");
|
|
134 |
_LIT(KPmaCreReposInInstallDirSrc, "z:\\private\\10202BE9\\f1000205.cri");
|
|
135 |
_LIT(KPmaCreReposInInstallDirTgt, "c:\\private\\102081E4\\f1000205.cre");
|
|
136 |
|
|
137 |
DeleteFilesL();
|
|
138 |
// When the contents of the repository directories change, the cached iOwnerIdLookUpTable becomes invalid
|
|
139 |
TServerResources::iOwnerIdLookUpTable.Reset();
|
|
140 |
|
|
141 |
RFs rfs;
|
|
142 |
User::LeaveIfError(rfs.Connect());
|
|
143 |
CleanupClosePushL(rfs);
|
|
144 |
|
|
145 |
CFileMan* fm = CFileMan::NewL( rfs );
|
|
146 |
CleanupStack::PushL( fm );
|
|
147 |
|
|
148 |
CopyTestFilesL(*fm, KPmaCreReposInPMADriveSrc, KPmaCreReposInPMADriveTgt);
|
|
149 |
CopyTestFilesL(*fm, KPmaCreReposInPersistDirSrc, KPmaCreReposInPersistDirTgt);
|
|
150 |
CopyTestFilesL(*fm, KPmaTxtReposInInstallDirSrc, KPmaTxtReposInInstallDirTgt);
|
|
151 |
CopyTestFilesL(*fm, KPmaCreReposInInstallDirSrc, KPmaCreReposInInstallDirTgt);
|
|
152 |
|
|
153 |
|
|
154 |
CleanupStack::PopAndDestroy(2, &rfs);
|
|
155 |
}
|
|
156 |
|
|
157 |
LOCAL_C void CleanupActiveScheduler(TAny* aShc)
|
|
158 |
{
|
|
159 |
CActiveScheduler::Replace( globalAS );
|
|
160 |
delete aShc;
|
|
161 |
}
|
|
162 |
|
|
163 |
LOCAL_C void BackupRepositoryL( )
|
|
164 |
{
|
|
165 |
backupClient->CompleteOwnerIdLookupTableL();
|
|
166 |
TEST2(TServerResources::FindOwnerIdLookupMapping(KUidPmaBackupTestRepository1.iUid), KErrNotFound);
|
|
167 |
TEST2(TServerResources::FindOwnerIdLookupMapping(KUidPmaBackupTestRepository2.iUid), KErrNotFound);
|
|
168 |
TEST2(TServerResources::FindOwnerIdLookupMapping(KUidPmaBackupTestRepository3.iUid), KErrNotFound);
|
|
169 |
TEST2(TServerResources::FindOwnerIdLookupMapping(KUidPmaBackupTestRepository4.iUid), KErrNotFound);
|
|
170 |
TEST2(TServerResources::FindOwnerIdLookupMapping(KUidPmaBackupTestRepository5.iUid), KErrNotFound);
|
|
171 |
}
|
|
172 |
|
|
173 |
/**
|
|
174 |
@SYMTestCaseID SYSLIB-CENTRALREPOSITORY-UT-4174
|
|
175 |
@SYMTestCaseDesc Verify iOwnerIdLookupTable does not contain PMA keyspaces before backup.
|
|
176 |
@SYMTestPriority High
|
|
177 |
@SYMTestActions Copy PMA keyspaces to PMA drive, persists and install directory.
|
|
178 |
Call CompleteOwnerIdLookupTableL().
|
|
179 |
Call FindOwnerIdLookupMapping to verify iOwnerIdLookTable does not contain PMA keyspaces.
|
|
180 |
@SYMTestExpectedResults iOwnerIdLookTable list does not contain PMA keyspaces.
|
|
181 |
@SYMREQ 42876
|
|
182 |
*/
|
|
183 |
LOCAL_C void OwnerIdLookupTableTestsL()
|
|
184 |
{
|
|
185 |
TheTest.Next( _L( " @SYMTestCaseID:PDS-CENTRALREPOSITORY-UT-4174 OwnerIdLookupTable test on PMA repository " ) );
|
|
186 |
|
|
187 |
// create and install the active scheduler we need
|
|
188 |
CActiveScheduler* s = new(ELeave) CActiveScheduler;
|
|
189 |
|
|
190 |
TCleanupItem tc(CleanupActiveScheduler, s);
|
|
191 |
CleanupStack::PushL(tc);
|
|
192 |
|
|
193 |
CActiveScheduler::Replace( s );
|
|
194 |
|
|
195 |
backupClient = CRepositoryBackupClient::NewLC( TServerResources::iFs );
|
|
196 |
TEST( backupClient != 0 );
|
|
197 |
|
|
198 |
// These tests don't test Backup&Restore functionality over Secure Backup Server so cache management
|
|
199 |
// is not possible. For that reason, cache is disabled manually.
|
|
200 |
TServerResources::iCacheManager->DisableCache();
|
|
201 |
|
|
202 |
// Install known files
|
|
203 |
InstallFileSetL();
|
|
204 |
BackupRepositoryL( );
|
|
205 |
|
|
206 |
DeleteFilesL();
|
|
207 |
CleanupStack::PopAndDestroy( backupClient );
|
|
208 |
// Cleanup the scheduler
|
|
209 |
CleanupStack::PopAndDestroy( s );
|
|
210 |
}
|
|
211 |
|
|
212 |
LOCAL_C void DoTestsL()
|
|
213 |
{
|
|
214 |
TServerResources::InitialiseL();
|
|
215 |
|
|
216 |
CleanupStack::PushL(TCleanupItem(CloseTServerResources, 0));
|
|
217 |
TheTest.Next( _L( "OwnerIdLookupTable tests" ) );
|
|
218 |
OwnerIdLookupTableTestsL();
|
|
219 |
|
|
220 |
CleanupStack::Pop(1); //TServerResources
|
|
221 |
TServerResources::Close();
|
|
222 |
}
|
|
223 |
|
|
224 |
|
|
225 |
LOCAL_C void MainL()
|
|
226 |
{
|
|
227 |
// create and install the active scheduler we need for the cache manager in TServerResources::InitialiseL
|
|
228 |
globalAS=new(ELeave) CActiveScheduler;
|
|
229 |
CleanupStack::PushL(globalAS);
|
|
230 |
CActiveScheduler::Install(globalAS);
|
|
231 |
|
|
232 |
DoTestsL();
|
|
233 |
DeleteFilesL();
|
|
234 |
|
|
235 |
CleanupStack::PopAndDestroy(globalAS);
|
|
236 |
|
|
237 |
}
|
|
238 |
|
|
239 |
TInt E32Main()
|
|
240 |
{
|
|
241 |
TheTest.Title ();
|
|
242 |
TheTest.Start( _L( "PMA Backup and restore tests" ) );
|
|
243 |
|
|
244 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
|
245 |
TheTest(cleanup != NULL);
|
|
246 |
|
|
247 |
__UHEAP_MARK;
|
|
248 |
|
|
249 |
TRAPD(err, MainL());
|
|
250 |
TEST2(err, KErrNone);
|
|
251 |
|
|
252 |
__UHEAP_MARKEND;
|
|
253 |
|
|
254 |
TheTest.End ();
|
|
255 |
TheTest.Close ();
|
|
256 |
|
|
257 |
delete cleanup;
|
|
258 |
|
|
259 |
User::Heap().Check();
|
|
260 |
return KErrNone;
|
|
261 |
}
|
|
262 |
|