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 "t_cenrep_helper.h"
|
|
17 |
#include <centralrepository.h>
|
|
18 |
#include <e32test.h> // RTest
|
|
19 |
#include <e32debug.h> // RDebug::Printf
|
|
20 |
#include <f32file.h> // RFs
|
|
21 |
|
|
22 |
#include "../cenrepsrv/srvparams.h" //KServerUid3
|
|
23 |
|
|
24 |
_LIT(KSoftReset, "--SoftReset");
|
|
25 |
|
|
26 |
RTest TheTest(_L("t_cenrep_pma_rfs.exe"));
|
|
27 |
|
|
28 |
const TUid KUidPMARepROMOnly = { 0xf1000501 };
|
|
29 |
const TUid KUidPMARepInstallOnly = { 0xf1000502 };
|
|
30 |
const TUid KUidPMARepROMAndInstall = { 0xf1000503 };
|
|
31 |
const TUid KUidNonPMARep = { 0xf1000504 };
|
|
32 |
|
|
33 |
_LIT(KInstallOnlySource, "Z:\\private\\10202BE9\\f1000502.txi");
|
|
34 |
_LIT(KInstallOnlyTarget, "C:\\private\\10202BE9\\f1000502.txt");
|
|
35 |
|
|
36 |
_LIT(KInstallOnlyPmaSource, "Z:\\private\\10202BE9\\f1000502.pma");
|
|
37 |
_LIT(KInstallOnlyPmaTarget, "C:\\private\\10202BE9\\persists\\protected\\f1000502.cre");
|
|
38 |
|
|
39 |
_LIT(KRomAndInstallSource, "Z:\\private\\10202BE9\\f1000503.txi");
|
|
40 |
_LIT(KRomAndInstallTarget, "C:\\private\\10202BE9\\f1000503.txt");
|
|
41 |
|
|
42 |
typedef enum
|
|
43 |
{
|
|
44 |
EInstallOnly,
|
|
45 |
ERomAndInstall,
|
|
46 |
} TRepositoryFileState;
|
|
47 |
|
|
48 |
const TUint32 KInt1 = 1;
|
|
49 |
const TInt KInt1_UpdatedValue = 73;
|
|
50 |
|
|
51 |
const TUint32 KNewInt = 1000;
|
|
52 |
const TUint32 KNewInt2 = 0x0FFF; // outside range meta (in default meta)
|
|
53 |
const TUint32 KNewInt3 = 0x1000; // inside range meta
|
|
54 |
|
|
55 |
const TUint32 KReal1 = 2;
|
|
56 |
|
|
57 |
const TUint32 KString1 = 5;
|
|
58 |
_LIT(KString1_UpdatedValue, "another one");
|
|
59 |
|
|
60 |
const TUint32 KIntNonPMA = 1;
|
|
61 |
const TInt KIntNonPMA_InitialValue = 100;
|
|
62 |
const TInt KIntNonPMA_UpdatedValue = 102;
|
|
63 |
|
|
64 |
|
|
65 |
LOCAL_C void Check(TInt aValue, TInt aLine)
|
|
66 |
{
|
|
67 |
if(!aValue)
|
|
68 |
{
|
|
69 |
TRAPD(err, CleanupCDriveL());
|
|
70 |
if (err != KErrNone)
|
|
71 |
{
|
|
72 |
RDebug::Print( _L( "*** CleanupCDriveL also failed with error %d expecting KErrNone\r\n"), err );
|
|
73 |
}
|
|
74 |
TheTest(EFalse, aLine);
|
|
75 |
}
|
|
76 |
}
|
|
77 |
LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
|
|
78 |
{
|
|
79 |
if(aValue != aExpected)
|
|
80 |
{
|
|
81 |
RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
|
|
82 |
TRAPD(err, CleanupCDriveL());
|
|
83 |
if (err != KErrNone)
|
|
84 |
{
|
|
85 |
RDebug::Print( _L( "*** CleanupCDriveL also failed with error %d expecting KErrNone\r\n"), err );
|
|
86 |
}
|
|
87 |
TheTest(EFalse, aLine);
|
|
88 |
}
|
|
89 |
}
|
|
90 |
#define TEST(arg) ::Check((arg), __LINE__)
|
|
91 |
#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
|
|
92 |
|
|
93 |
// This function kills the C32exe.exe process. This commsdat process will
|
|
94 |
// interfere with the test if not killed. In a nutshell, some of the test cases
|
|
95 |
// will kill and then wait for 2 seconds and restart the centrep server
|
|
96 |
// with --SoftReset option. During that 2 seconds wait sometimes C32exe.exe
|
|
97 |
// will use centrep API, thus starting the server normally without --SoftReset.
|
|
98 |
LOCAL_C void KillC32Exe()
|
|
99 |
{
|
|
100 |
_LIT( KC32ServerName, "c32exe");
|
|
101 |
KillProcess(KC32ServerName); // Don't need to check the return code, it always return KErrNone anyway.
|
|
102 |
User::After(KGeneralDelay);
|
|
103 |
}
|
|
104 |
|
|
105 |
LOCAL_C void KillCentrepExe()
|
|
106 |
{
|
|
107 |
_LIT( KCentralRepositoryServerName, "Centralrepositorysrv");
|
|
108 |
KillProcess(KCentralRepositoryServerName); // Don't need to check the return code, it always return KErrNone anyway.
|
|
109 |
User::After(KGeneralDelay);
|
|
110 |
}
|
|
111 |
|
|
112 |
//This function restores the state of the files required for this test
|
|
113 |
//Existing files are deleted and then the required files are copied
|
|
114 |
//back from the Z drive to the c drive
|
|
115 |
LOCAL_C void RestoreRFSTestFilesL(TRepositoryFileState aState)
|
|
116 |
{
|
|
117 |
//Delete all files from C:\\private\\10202BE9\\persists\\ dir
|
|
118 |
//and C:\\private\\10202BE9\\ dir
|
|
119 |
CleanupCDriveL();
|
|
120 |
RFs fs;
|
|
121 |
User::LeaveIfError(fs.Connect());
|
|
122 |
CleanupClosePushL(fs);
|
|
123 |
|
|
124 |
CFileMan* fm = CFileMan::NewL(fs);
|
|
125 |
CleanupStack::PushL(fm);
|
|
126 |
|
|
127 |
switch(aState)
|
|
128 |
{
|
|
129 |
case EInstallOnly:
|
|
130 |
CopyTestFilesL(*fm,KInstallOnlySource, KInstallOnlyTarget);
|
|
131 |
//Since we can't open and modify a PMA keyspace in install directory
|
|
132 |
// we have to copy a pre-persisted version to the PMA drive.
|
|
133 |
CopyTestFilesL(*fm,KInstallOnlyPmaSource, KInstallOnlyPmaTarget);
|
|
134 |
break;
|
|
135 |
|
|
136 |
case ERomAndInstall:
|
|
137 |
CopyTestFilesL(*fm,KRomAndInstallSource, KRomAndInstallTarget);
|
|
138 |
break;
|
|
139 |
|
|
140 |
default:
|
|
141 |
break;
|
|
142 |
}
|
|
143 |
|
|
144 |
CleanupStack::PopAndDestroy(2);
|
|
145 |
|
|
146 |
}
|
|
147 |
|
|
148 |
//
|
|
149 |
// Start the server process or thread
|
|
150 |
//
|
|
151 |
LOCAL_C TInt ReStartServerInSoftResetMode()
|
|
152 |
{
|
|
153 |
const TUidType serverUid(KNullUid, KNullUid, KServerUid3);
|
|
154 |
|
|
155 |
//
|
|
156 |
// EPOC and EKA2 is easy, we just create a new server process. Simultaneous
|
|
157 |
// launching of two such processes should be detected when the second one
|
|
158 |
// attempts to create the server object, failing with KErrAlreadyExists.
|
|
159 |
//
|
|
160 |
RProcess server;
|
|
161 |
TInt r=server.Create(KServerImg,
|
|
162 |
KSoftReset,
|
|
163 |
serverUid);
|
|
164 |
|
|
165 |
if (r != KErrNone)
|
|
166 |
{
|
|
167 |
return r;
|
|
168 |
}
|
|
169 |
|
|
170 |
TRequestStatus stat;
|
|
171 |
server.Rendezvous(stat);
|
|
172 |
|
|
173 |
if (stat != KRequestPending)
|
|
174 |
{
|
|
175 |
server.Kill(0); // abort startup
|
|
176 |
}
|
|
177 |
else
|
|
178 |
{
|
|
179 |
server.Resume(); // logon OK - start the server
|
|
180 |
}
|
|
181 |
|
|
182 |
User::WaitForRequest(stat); // wait for start or death
|
|
183 |
// we can't use the 'exit reason' if the server panicked as this
|
|
184 |
// is the panic 'reason' and may be '0' which cannot be distinguished
|
|
185 |
// from KErrNone
|
|
186 |
r = (server.ExitType() == EExitPanic) ? KErrGeneral : stat.Int();
|
|
187 |
|
|
188 |
server.Close();
|
|
189 |
return r;
|
|
190 |
}
|
|
191 |
|
|
192 |
|
|
193 |
LOCAL_C void RestoreFactorySettingsTestL( TUid aRepUid )
|
|
194 |
{
|
|
195 |
TheTest.Next(_L(" RestoreFactorySettingsTestL "));
|
|
196 |
TInt r;
|
|
197 |
TInt i;
|
|
198 |
TBuf<20> str;
|
|
199 |
|
|
200 |
//Kill centrep server to pick new test files
|
|
201 |
KillCentrepExe();
|
|
202 |
|
|
203 |
TheTest.Printf(_L("Open repository to ensure server is running"));
|
|
204 |
CRepository* repository = CRepository::NewLC(aRepUid);
|
|
205 |
|
|
206 |
TheTest.Printf(_L("Add a Setting"));
|
|
207 |
const TInt KIntValue = 1234;
|
|
208 |
r = repository->Create(KNewInt, KIntValue);
|
|
209 |
TEST2(r, KErrNone);
|
|
210 |
r = repository->Create(KNewInt2, KIntValue);
|
|
211 |
TEST2(r, KErrNone);
|
|
212 |
r = repository->Create(KNewInt3, KIntValue);
|
|
213 |
TEST2(r, KErrNone);
|
|
214 |
|
|
215 |
TheTest.Printf(_L("Delete a PMA Setting"));
|
|
216 |
r = repository->Delete(KReal1);
|
|
217 |
TEST2(r, KErrNone);
|
|
218 |
|
|
219 |
TheTest.Printf(_L("Modify PMA Setting"));
|
|
220 |
r = repository->Set(KInt1, KInt1_UpdatedValue);
|
|
221 |
TEST2(r, KErrNone);
|
|
222 |
r = repository->Set(KString1, KString1_UpdatedValue);
|
|
223 |
TEST2(r, KErrNone);
|
|
224 |
|
|
225 |
// Close repository
|
|
226 |
CleanupStack::PopAndDestroy(repository);
|
|
227 |
|
|
228 |
// Open a Non-PMA rep to prove that the RFS actually did happened later
|
|
229 |
repository = CRepository::NewLC(KUidNonPMARep);
|
|
230 |
|
|
231 |
TheTest.Printf(_L("Modify a Non-PMA and RFS-enabled setting"));
|
|
232 |
r = repository->Set(KIntNonPMA, KIntNonPMA_UpdatedValue);
|
|
233 |
TEST2(r, KErrNone);
|
|
234 |
CleanupStack::PopAndDestroy(repository);
|
|
235 |
|
|
236 |
TheTest.Printf(_L("Kill the server process"));
|
|
237 |
_LIT( KCentralRepositoryServerName, "Centralrepositorysrv");
|
|
238 |
r = KillProcess(KCentralRepositoryServerName);
|
|
239 |
TEST2(r,KErrNone);
|
|
240 |
|
|
241 |
User::After(KGeneralDelay);
|
|
242 |
|
|
243 |
TheTest.Printf(_L("Manually start central respository in softreset mode"));
|
|
244 |
ReStartServerInSoftResetMode();
|
|
245 |
|
|
246 |
TheTest.Printf(_L("Re-create the repository to ensure server is running"));
|
|
247 |
repository = CRepository::NewLC(aRepUid);
|
|
248 |
|
|
249 |
TheTest.Printf(_L("Get 'Added' value"));
|
|
250 |
r = repository->Get(KNewInt, i);
|
|
251 |
TEST2(r, KErrNone);
|
|
252 |
r = repository->Get(KNewInt2, i);
|
|
253 |
TEST2(r, KErrNone);
|
|
254 |
r = repository->Get(KNewInt3, i);
|
|
255 |
TEST2(r, KErrNone);
|
|
256 |
|
|
257 |
TReal real;
|
|
258 |
TheTest.Printf(_L("Get 'Deleted' value"));
|
|
259 |
r = repository->Get(KReal1, real);
|
|
260 |
TEST2(r, KErrNotFound);
|
|
261 |
|
|
262 |
TheTest.Printf(_L("Get 'Modified' value"));
|
|
263 |
r = repository->Get(KInt1, i);
|
|
264 |
TEST2(r, KErrNone);
|
|
265 |
TEST(i == KInt1_UpdatedValue);
|
|
266 |
|
|
267 |
r = repository->Get(KString1, str);
|
|
268 |
TEST2(r, KErrNone);
|
|
269 |
TEST(str == KString1_UpdatedValue);
|
|
270 |
|
|
271 |
// Close repository
|
|
272 |
CleanupStack::PopAndDestroy(repository);
|
|
273 |
|
|
274 |
repository = CRepository::NewLC(KUidNonPMARep);
|
|
275 |
TheTest.Printf(_L("Check the Non-PMA and RFS-enabled setting"));
|
|
276 |
//If RFS did happen, this value should now be reverted back to the initial ROM value
|
|
277 |
r = repository->Get(KIntNonPMA, i);
|
|
278 |
TEST2(r, KErrNone);
|
|
279 |
TEST(i == KIntNonPMA_InitialValue);
|
|
280 |
CleanupStack::PopAndDestroy(repository);
|
|
281 |
}
|
|
282 |
|
|
283 |
/**
|
|
284 |
@SYMTestCaseID PDS-CENTRALREPOSITORY-CT-4128
|
|
285 |
@SYMTestCaseDesc Restore Factory Setting test on PMA keyspaces
|
|
286 |
@SYMTestPriority High
|
|
287 |
@SYMTestActions - Add a PMA setting.
|
|
288 |
- Delete a PMA setting.
|
|
289 |
- Modify a PMA Setting.
|
|
290 |
- Modify a Non-PMA and RFS-enabled setting.
|
|
291 |
- Kill and manually restart central respository server with --SoftReset option.
|
|
292 |
- Check the aftermath of the RFS.
|
|
293 |
@SYMTestExpectedResults - Added PMA setting should still be there.
|
|
294 |
- Delete PMA setting should still be missing.
|
|
295 |
- Modified PMA setting should have the modified value.
|
|
296 |
- Modified Non-PMA setting should have its value reverted.
|
|
297 |
@SYMREQ REQ42876
|
|
298 |
*/
|
|
299 |
LOCAL_C void MainL()
|
|
300 |
{
|
|
301 |
TheTest.Next(_L(" @SYMTestCaseID:PDS-CENTRALREPOSITORY-CT-4128 RFS Test on PMA keyspaces"));
|
|
302 |
RFs fs;
|
|
303 |
TEntry entry;
|
|
304 |
TInt err = fs.Connect();
|
|
305 |
TEST2(err, KErrNone);
|
|
306 |
CleanupClosePushL(fs);
|
|
307 |
|
|
308 |
CleanupCDriveL();
|
|
309 |
KillC32Exe(); //Need to kill C32Exe as it is interfering with the test.
|
|
310 |
KillCentrepExe();
|
|
311 |
|
|
312 |
RestoreFactorySettingsTestL(KUidPMARepROMOnly);
|
|
313 |
|
|
314 |
RestoreRFSTestFilesL(EInstallOnly);
|
|
315 |
RestoreFactorySettingsTestL(KUidPMARepInstallOnly);
|
|
316 |
err = fs.Entry(KInstallOnlyTarget,entry);//The PMA file in install dir should have been deleted during RFS
|
|
317 |
TEST2(err, KErrNotFound);
|
|
318 |
|
|
319 |
RestoreRFSTestFilesL(ERomAndInstall);
|
|
320 |
RestoreFactorySettingsTestL(KUidPMARepROMAndInstall);
|
|
321 |
err = fs.Entry(KRomAndInstallTarget,entry);//The PMA file in install dir should have been deleted during RFS
|
|
322 |
TEST2(err, KErrNotFound);
|
|
323 |
|
|
324 |
CleanupCDriveL();
|
|
325 |
|
|
326 |
CleanupStack::PopAndDestroy(); //fs
|
|
327 |
}
|
|
328 |
|
|
329 |
TInt E32Main()
|
|
330 |
{
|
|
331 |
TheTest.Title ();
|
|
332 |
TheTest.Start(_L("PMA Restore Factory Settings tests "));
|
|
333 |
|
|
334 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
|
335 |
TheTest(cleanup != NULL);
|
|
336 |
|
|
337 |
__UHEAP_MARK;
|
|
338 |
|
|
339 |
TRAPD(err, MainL());
|
|
340 |
TEST2(err, KErrNone);
|
|
341 |
|
|
342 |
__UHEAP_MARKEND;
|
|
343 |
|
|
344 |
TheTest.End ();
|
|
345 |
TheTest.Close ();
|
|
346 |
|
|
347 |
delete cleanup;
|
|
348 |
|
|
349 |
User::Heap().Check();
|
|
350 |
return KErrNone;
|
|
351 |
}
|