|
1 // Copyright (c) 2005-2009 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 <centralrepository.h> |
|
17 #include <e32test.h> |
|
18 #include <f32file.h> |
|
19 #include <badesca.h> |
|
20 #include <connect/sbdefs.h> |
|
21 #include <connect/sbeclient.h> |
|
22 |
|
23 #include "srvrepos_noc.h" |
|
24 #include "srvres.h" |
|
25 #include "cachemgr.h" |
|
26 #include "backup.h" |
|
27 |
|
28 RTest TheTest(_L("Central Repository Backup & Restore Delete Tests")); |
|
29 |
|
30 enum FileSet |
|
31 { |
|
32 EOriginals, |
|
33 EChanged, |
|
34 ERemoved, |
|
35 EDEF058823L |
|
36 }; |
|
37 |
|
38 _LIT_SECURE_ID( SecureId1, 0x12345 ); |
|
39 |
|
40 |
|
41 |
|
42 CRepositoryBackupClient* backupClient; |
|
43 |
|
44 CDesC8ArraySeg* originalData1; |
|
45 CDesC8ArraySeg* changedData1; |
|
46 CDesC8ArraySeg* originalData2; |
|
47 CDesC8ArraySeg* changedData2; |
|
48 CDesC8ArraySeg* changedData3; |
|
49 |
|
50 CActiveScheduler* globalAS; |
|
51 const TUid KUidBackupTestRepository1 = { 0x00000100 }; |
|
52 |
|
53 const TUint32 KBackupInt1 = 0x02010100; |
|
54 const TUint32 KBackupInt2 = 0x03010200; |
|
55 const TInt KIntChangedValue2 = 200; |
|
56 const TUint32 KBackupInt3 = 0x04010300; |
|
57 const TInt KIntOrigValue3 = 30; |
|
58 |
|
59 const TUint32 KBackupString1 = 0x02010600; |
|
60 _LIT8(KStringChangedValue, "test changed"); |
|
61 const TUint32 KBackupString2 = 0x03010600; |
|
62 const TUint32 KBackupReal1 = 0x02010700; |
|
63 const TReal KRealOrigValue = 1.1; |
|
64 const TUint32 KBackupReal2 = 0x03010700; |
|
65 const TReal KRealChangedValue = 2.5; |
|
66 |
|
67 /////////////////////////////////////////////////////////////////////////////////////// |
|
68 /////////////////////////////////////////////////////////////////////////////////////// |
|
69 //Test macroses and functions |
|
70 |
|
71 |
|
72 LOCAL_C void DeleteFilesL() |
|
73 { |
|
74 _LIT( KOldInstallFiles, "c:\\private\\102081E4\\*.*" ); |
|
75 _LIT( KOldPersistFiles, "c:\\private\\102081E4\\persists\\*.*" ); |
|
76 |
|
77 CFileMan* fm = CFileMan::NewL( TServerResources::iFs ); |
|
78 CleanupStack::PushL( fm ); |
|
79 |
|
80 TInt r = fm->Delete( KOldInstallFiles ); |
|
81 if ( r != KErrNone && r != KErrNotFound && r != KErrPathNotFound ) |
|
82 User::Leave(r); |
|
83 r = fm->Delete( KOldPersistFiles ); |
|
84 if ( r != KErrNone && r != KErrNotFound && r != KErrPathNotFound ) |
|
85 User::Leave(r); |
|
86 |
|
87 CleanupStack::PopAndDestroy( fm ); |
|
88 } |
|
89 |
|
90 LOCAL_C void CheckL( TInt aValue, TInt aLine ) |
|
91 { |
|
92 if ( !aValue ) |
|
93 { |
|
94 DeleteFilesL(); |
|
95 TheTest( EFalse, aLine ); |
|
96 } |
|
97 } |
|
98 |
|
99 LOCAL_C void CheckL( TInt aValue, TInt aExpected, TInt aLine ) |
|
100 { |
|
101 if ( aValue != aExpected ) |
|
102 { |
|
103 DeleteFilesL(); |
|
104 RDebug::Print( _L( "*** Expected error: %d, got: %d\r\n"), aExpected, aValue ); |
|
105 TheTest( EFalse, aLine ); |
|
106 } |
|
107 } |
|
108 |
|
109 #define TEST(arg) ::CheckL((arg), __LINE__) |
|
110 #define TEST2(aValue, aExpected) ::CheckL(aValue, aExpected, __LINE__) |
|
111 |
|
112 /////////////////////////////////////////////////////////////////////////////////////// |
|
113 /////////////////////////////////////////////////////////////////////////////////////// |
|
114 |
|
115 LOCAL_C void InitializationL() |
|
116 { |
|
117 originalData1 = new(ELeave)CDesC8ArraySeg( 128 ); |
|
118 CleanupStack::PushL( originalData1 ); |
|
119 changedData1 = new(ELeave)CDesC8ArraySeg( 128 ); |
|
120 CleanupStack::PushL( changedData1 ); |
|
121 originalData2 = new(ELeave)CDesC8ArraySeg( 128 ); |
|
122 CleanupStack::PushL( originalData2 ); |
|
123 changedData2 = new(ELeave)CDesC8ArraySeg( 128 ); |
|
124 CleanupStack::PushL( changedData2 ); |
|
125 changedData3 = new(ELeave)CDesC8ArraySeg( 128 ); |
|
126 CleanupStack::PushL( changedData3 ); |
|
127 } |
|
128 |
|
129 LOCAL_C void Cleanup() |
|
130 { |
|
131 CleanupStack::PopAndDestroy( changedData3 ); |
|
132 CleanupStack::PopAndDestroy( changedData2 ); |
|
133 CleanupStack::PopAndDestroy( originalData2 ); |
|
134 CleanupStack::PopAndDestroy( changedData1 ); |
|
135 CleanupStack::PopAndDestroy( originalData1 ); |
|
136 } |
|
137 |
|
138 LOCAL_C void InstallFileSetL( FileSet aFileSet ) |
|
139 { |
|
140 _LIT( KFileSrcPath, "\\private\\10202BE9\\" ); |
|
141 _LIT( KInstallFileDestPath, "\\private\\102081E4\\" ); |
|
142 _LIT( KPersistFileDestPath, "\\private\\102081E4\\persists\\" ); |
|
143 _LIT( KEDEF058823LFile, "babababa.cre"); |
|
144 _LIT( KDriveC, "c:" ); |
|
145 _LIT( KDriveZ, "z:" ); |
|
146 _LIT( KCreFiles, "*.cre" ); |
|
147 _LIT( KAllFiles, "*.*" ); |
|
148 _LIT( KTxtFilesForC_V1, "*.cra" ); |
|
149 _LIT( KTxtFilesForC_V2, "*.crb" ); |
|
150 |
|
151 //Use HBufC in preference to TBuf or TFileName to save stack usage |
|
152 HBufC* src_buf1 = HBufC::NewLC(KMaxFileName); |
|
153 TPtr src1(src_buf1->Des()); |
|
154 HBufC* src_buf2 = HBufC::NewLC(KMaxFileName); |
|
155 TPtr src2(src_buf2->Des()); |
|
156 HBufC* dest_buf1 = HBufC::NewLC(KMaxFileName); |
|
157 TPtr dest1(dest_buf1->Des()); |
|
158 HBufC* dest_buf2 = HBufC::NewLC(KMaxFileName); |
|
159 TPtr dest2(dest_buf2->Des()); |
|
160 |
|
161 TInt r; |
|
162 |
|
163 DeleteFilesL(); |
|
164 |
|
165 CFileMan* fm = CFileMan::NewL( TServerResources::iFs ); |
|
166 CleanupStack::PushL( fm ); |
|
167 |
|
168 switch ( aFileSet ) |
|
169 { |
|
170 case EOriginals: |
|
171 { |
|
172 dest1.Copy( KDriveC ); |
|
173 dest1.Append( KInstallFileDestPath ); |
|
174 dest1.Append( KCreFiles ); |
|
175 r = fm->Delete( dest1 ); |
|
176 if ( r != KErrNone && r != KErrNotFound && r != KErrPathNotFound ) |
|
177 User::Leave( r ); |
|
178 r = TServerResources::iFs.MkDirAll( dest1 ); |
|
179 if ( r != KErrNone && r != KErrAlreadyExists ) |
|
180 User::Leave( r ); |
|
181 src1.Copy( KDriveZ ); |
|
182 src1.Append( KFileSrcPath ); |
|
183 src1.Append( KTxtFilesForC_V1 ); |
|
184 User::LeaveIfError( fm->Copy( src1, dest1 ) ); |
|
185 r = fm->Attribs( dest1, KEntryAttArchive, KEntryAttReadOnly, TTime( 0 ), CFileMan::ERecurse ); |
|
186 TEST2( r, KErrNone ); |
|
187 dest2.Copy( KDriveC ); |
|
188 dest2.Append( KPersistFileDestPath ); |
|
189 dest2.Append( KCreFiles ); |
|
190 r = fm->Delete( dest2 ); |
|
191 if ( r != KErrNone && r != KErrNotFound && r != KErrPathNotFound ) |
|
192 User::Leave( r ); |
|
193 r = TServerResources::iFs.MkDirAll( dest2 ); |
|
194 if ( r != KErrNone && r != KErrAlreadyExists ) |
|
195 User::Leave( r ); |
|
196 src2.Copy( KDriveZ ); |
|
197 src2.Append( KFileSrcPath ); |
|
198 src2.Append( KTxtFilesForC_V1 ); |
|
199 User::LeaveIfError( fm->Copy( src2, dest2 ) ); |
|
200 r = fm->Attribs( dest2, KEntryAttArchive, KEntryAttReadOnly, TTime( 0 ), CFileMan::ERecurse ); |
|
201 TEST2( r, KErrNone ); |
|
202 break; |
|
203 } |
|
204 case EChanged: |
|
205 { |
|
206 dest1.Copy( KDriveC ); |
|
207 dest1.Append( KInstallFileDestPath ); |
|
208 dest1.Append( KCreFiles ); |
|
209 r = fm->Delete( dest1 ); |
|
210 if ( r != KErrNone && r != KErrNotFound && r != KErrPathNotFound ) |
|
211 User::Leave( r ); |
|
212 r = TServerResources::iFs.MkDirAll( dest1 ); |
|
213 if ( r != KErrNone && r != KErrAlreadyExists ) |
|
214 User::Leave( r ); |
|
215 src1.Copy( KDriveZ ); |
|
216 src1.Append( KFileSrcPath ); |
|
217 src1.Append( KTxtFilesForC_V1 ); |
|
218 User::LeaveIfError( fm->Copy( src1, dest1 ) ); |
|
219 r = fm->Attribs( dest1, KEntryAttArchive, KEntryAttReadOnly, TTime( 0 ), CFileMan::ERecurse ); |
|
220 TEST2( r, KErrNone ); |
|
221 dest2.Copy( KDriveC ); |
|
222 dest2.Append( KPersistFileDestPath ); |
|
223 dest2.Append( KCreFiles ); |
|
224 r = fm->Delete( dest2 ); |
|
225 if ( r != KErrNone && r != KErrNotFound && r != KErrPathNotFound ) |
|
226 User::Leave( r ); |
|
227 r = TServerResources::iFs.MkDirAll( dest2 ); |
|
228 if ( r != KErrNone && r != KErrAlreadyExists ) |
|
229 User::Leave( r ); |
|
230 src2.Copy( KDriveZ ); |
|
231 src2.Append( KFileSrcPath ); |
|
232 src2.Append( KTxtFilesForC_V2 ); |
|
233 User::LeaveIfError( fm->Copy( src2, dest2 ) ); |
|
234 r = fm->Attribs( dest2, KEntryAttArchive, KEntryAttReadOnly, TTime( 0 ), CFileMan::ERecurse ); |
|
235 TEST2( r, KErrNone ); |
|
236 break; |
|
237 } |
|
238 case ERemoved: |
|
239 { |
|
240 dest1.Copy( KDriveC ); |
|
241 dest1.Append( KInstallFileDestPath ); |
|
242 dest1.Append( KCreFiles ); |
|
243 r = fm->Delete( dest1 ); |
|
244 if ( r != KErrNone && r != KErrNotFound && r != KErrPathNotFound ) |
|
245 User::Leave( r ); |
|
246 r = TServerResources::iFs.MkDirAll( dest1 ); |
|
247 if ( r != KErrNone && r != KErrAlreadyExists ) |
|
248 User::Leave( r ); |
|
249 src1.Copy( KDriveZ ); |
|
250 src1.Append( KFileSrcPath ); |
|
251 src1.Append( KTxtFilesForC_V1 ); |
|
252 User::LeaveIfError( fm->Copy( src1, dest1 ) ); |
|
253 r = fm->Attribs( dest1, KEntryAttArchive, KEntryAttReadOnly, TTime( 0 ), CFileMan::ERecurse ); |
|
254 TEST2( r, KErrNone ); |
|
255 dest2.Copy( KDriveC ); |
|
256 dest2.Append( KPersistFileDestPath ); |
|
257 dest2.Append( KCreFiles ); |
|
258 r = fm->Delete( dest2 ); |
|
259 if ( r != KErrNone && r != KErrNotFound && r != KErrPathNotFound ) |
|
260 User::Leave( r ); |
|
261 break; |
|
262 } |
|
263 case EDEF058823L: |
|
264 { |
|
265 dest2.Copy( KDriveC ); |
|
266 dest2.Append( KPersistFileDestPath ); |
|
267 dest2.Append( KAllFiles ); |
|
268 r = fm->Delete( dest2 ); |
|
269 if ( r != KErrNone && r != KErrNotFound && r != KErrPathNotFound ) |
|
270 User::Leave( r ); |
|
271 r = TServerResources::iFs.MkDirAll( dest2 ); |
|
272 if ( r != KErrNone && r != KErrAlreadyExists ) |
|
273 User::Leave( r ); |
|
274 src2.Copy( KDriveZ ); |
|
275 src2.Append( KFileSrcPath ); |
|
276 src2.Append( KEDEF058823LFile ); |
|
277 User::LeaveIfError( fm->Copy( src2, dest2 ) ); |
|
278 r = fm->Attribs( dest2, KEntryAttArchive, KEntryAttReadOnly, TTime( 0 ), CFileMan::ERecurse ); |
|
279 TEST2( r, KErrNone ); |
|
280 break; |
|
281 } |
|
282 default: |
|
283 RDebug::Print( _L( "Illegal parameter to function: %d\r\n" ), aFileSet ); |
|
284 TheTest( EFalse, __LINE__ ); |
|
285 } |
|
286 |
|
287 CleanupStack::PopAndDestroy( fm ); |
|
288 CleanupStack::PopAndDestroy( 4 ); |
|
289 } |
|
290 |
|
291 |
|
292 LOCAL_C void BackupRepositoryL( CDesC8ArraySeg* aDataStream ) |
|
293 { |
|
294 backupClient->CompleteOwnerIdLookupTableL(); |
|
295 backupClient->InitialiseGetProxyBackupDataL( SecureId1, EDriveC ); |
|
296 |
|
297 HBufC8* transferBuffer = HBufC8::NewL( 128 ); |
|
298 CleanupStack::PushL( transferBuffer ); |
|
299 TPtr8 bufferToSend = transferBuffer->Des(); |
|
300 TBool finished = EFalse; |
|
301 |
|
302 aDataStream->Reset(); |
|
303 |
|
304 do |
|
305 { |
|
306 bufferToSend.Zero(); |
|
307 backupClient->GetBackupDataSectionL( bufferToSend, finished ); |
|
308 aDataStream->AppendL( bufferToSend ); |
|
309 } while ( !finished ); |
|
310 |
|
311 CleanupStack::PopAndDestroy( transferBuffer ); |
|
312 } |
|
313 |
|
314 LOCAL_C void RestoreRepositoryL( CDesC8ArraySeg* aDataStream ) |
|
315 { |
|
316 backupClient->InitialiseRestoreProxyBaseDataL( SecureId1, EDriveC ); |
|
317 |
|
318 HBufC8* transferBuffer = HBufC8::NewL( 128 ); |
|
319 CleanupStack::PushL( transferBuffer ); |
|
320 |
|
321 TBool finished = EFalse; |
|
322 TInt count = aDataStream->Count(); |
|
323 TInt element = 0; |
|
324 |
|
325 for ( element = 0; element < count; element++ ) |
|
326 { |
|
327 TPtrC8 ptr = (*aDataStream)[ element ]; |
|
328 if (ptr.Size()>transferBuffer->Des().MaxSize()) |
|
329 { |
|
330 transferBuffer = transferBuffer->ReAlloc(ptr.Size()); |
|
331 } |
|
332 TPtr8 bufferToSend = transferBuffer->Des(); |
|
333 bufferToSend.Zero(); |
|
334 bufferToSend.Append( ptr ); |
|
335 if ( element + 1 == count ) |
|
336 finished = ETrue; |
|
337 backupClient->RestoreBaseDataSectionL( bufferToSend, finished ); |
|
338 } |
|
339 backupClient->RestoreComplete( EDriveC ); |
|
340 |
|
341 CleanupStack::PopAndDestroy( transferBuffer ); |
|
342 } |
|
343 |
|
344 |
|
345 /** |
|
346 @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-UT-1535 |
|
347 @SYMTestCaseDesc Test Backup functionality with reference to INC072238: centrep restores deleted content. |
|
348 @SYMTestPriority High |
|
349 @SYMTestActions Test Backup functionality. |
|
350 @SYMTestExpectedResults The test must not fail. |
|
351 @SYMPREQ PREQ752 |
|
352 */ |
|
353 LOCAL_C void BackupTestsL() |
|
354 { |
|
355 TheTest.Next( _L( " @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-UT-1535 Backup repository " ) ); |
|
356 |
|
357 // create and install the active scheduler we need |
|
358 CActiveScheduler* s = new(ELeave) CActiveScheduler; |
|
359 CleanupStack::PushL( s ); |
|
360 CActiveScheduler::Replace( s ); |
|
361 |
|
362 backupClient = CRepositoryBackupClient::NewLC( TServerResources::iFs ); |
|
363 TEST( backupClient != 0 ); |
|
364 |
|
365 // These tests don't test Backup&Restore functionality over Secure Backup Server so cache management |
|
366 // is not possible. For that reason, cache is disabled manually. |
|
367 TServerResources::iCacheManager->DisableCache(); |
|
368 DeleteFilesL(); |
|
369 |
|
370 |
|
371 |
|
372 TheTest.Next( _L( "Backup original version" ) ); |
|
373 // Install known files |
|
374 InstallFileSetL( EOriginals ); |
|
375 |
|
376 CServerRepository* aServerRepo=new (ELeave)CServerRepository(); |
|
377 CleanupStack::PushL(aServerRepo); |
|
378 CSessionNotifier* aSessionNotif=new (ELeave) CSessionNotifier(); |
|
379 CleanupStack::PushL(aSessionNotif); |
|
380 |
|
381 // Open repository to delete a few sessions settings |
|
382 aServerRepo->OpenL(KUidBackupTestRepository1,*aSessionNotif); |
|
383 |
|
384 TUint32 transId = aServerRepo->StartTransaction(EReadWriteTransaction) ; |
|
385 aServerRepo->TransactionDeleteL(KBackupInt1) ; |
|
386 aServerRepo->TransactionDeleteL(KBackupString1) ; |
|
387 aServerRepo->TransactionDeleteL(KBackupReal2) ; |
|
388 aServerRepo->CommitTransaction(transId); |
|
389 aServerRepo->CommitChangesL() ; |
|
390 aServerRepo->Close(); |
|
391 |
|
392 CleanupStack::PopAndDestroy(aSessionNotif); |
|
393 CleanupStack::PopAndDestroy(aServerRepo); |
|
394 |
|
395 // Backup the repository |
|
396 BackupRepositoryL( originalData1 ); |
|
397 |
|
398 CleanupStack::PopAndDestroy( backupClient ); |
|
399 // Cleanup the scheduler |
|
400 CleanupStack::PopAndDestroy( s ); |
|
401 } |
|
402 |
|
403 |
|
404 /** |
|
405 @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-UT-1536 |
|
406 @SYMTestCaseDesc Test Restore functionality with reference to INC072238: centrep restores deleted content. |
|
407 @SYMTestPriority High |
|
408 @SYMTestActions Test Restore functionality. |
|
409 @SYMTestExpectedResults The test must not fail. |
|
410 @SYMPREQ PREQ752 |
|
411 */ |
|
412 |
|
413 LOCAL_C void RestoreTestsL() |
|
414 { |
|
415 TheTest.Next( _L( " @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-UT-1536 Restore repository " ) ); |
|
416 |
|
417 // create and install the active scheduler we need |
|
418 CActiveScheduler* s = new(ELeave) CActiveScheduler; |
|
419 CleanupStack::PushL( s ); |
|
420 CActiveScheduler::Replace( s ); |
|
421 |
|
422 backupClient = CRepositoryBackupClient::NewLC(TServerResources::iFs); |
|
423 TEST( backupClient != 0 ); |
|
424 |
|
425 CServerRepository* aServerRepo=new (ELeave)CServerRepository(); |
|
426 CleanupStack::PushL(aServerRepo); |
|
427 CSessionNotifier* aSessionNotif=new (ELeave) CSessionNotifier(); |
|
428 CleanupStack::PushL(aSessionNotif); |
|
429 |
|
430 TServerResources::iCacheManager->DisableCache(); |
|
431 |
|
432 DeleteFilesL(); |
|
433 |
|
434 TheTest.Next( _L( "Restore original version over changed version" ) ); |
|
435 InstallFileSetL( EChanged ); |
|
436 RestoreRepositoryL( originalData1 ); |
|
437 |
|
438 TheTest.Next( _L( "Confirm settings restored" ) ); |
|
439 |
|
440 // Open merged repository to check for values of individual settings |
|
441 aServerRepo->OpenL(KUidBackupTestRepository1,*aSessionNotif); |
|
442 |
|
443 TInt r, a; |
|
444 |
|
445 // This setting was DELETED before backup so it shouldn't be present |
|
446 // after restore |
|
447 r = aServerRepo->Get(KBackupInt1, a); |
|
448 TEST2(r, KErrNotFound); |
|
449 |
|
450 |
|
451 r = aServerRepo->Get(KBackupInt2, a); |
|
452 TEST2(r, KErrNone); |
|
453 // This setting isn't backed up, so it must still have changed value |
|
454 TEST(a==KIntChangedValue2); |
|
455 |
|
456 r = aServerRepo->Get(KBackupInt3, a); |
|
457 TEST2(r, KErrNone); |
|
458 // This setting is backed up, so it must be restored to original |
|
459 TEST(a==KIntOrigValue3); |
|
460 |
|
461 TBuf8<KMaxBinaryLength> str; |
|
462 |
|
463 // This setting was DELETED before backup so it shouldn't be present |
|
464 // after restore |
|
465 r = aServerRepo->Get(KBackupString1, str); |
|
466 TEST(r==KErrNotFound); |
|
467 |
|
468 r = aServerRepo->Get(KBackupString2, str); |
|
469 TEST(r==KErrNone); |
|
470 // This setting isn't backed up, so it must still have changed value |
|
471 TEST(str==KStringChangedValue); |
|
472 |
|
473 TReal realval; |
|
474 |
|
475 r = aServerRepo->Get(KBackupReal1, realval); |
|
476 TEST(r==KErrNone); |
|
477 // This setting is backed up, so it must be restored to original |
|
478 TEST(realval==KRealOrigValue); |
|
479 |
|
480 r = aServerRepo->Get(KBackupReal2, realval); |
|
481 TEST(r==KErrNone); |
|
482 // This setting was deleted but isn't backed up, so it should still |
|
483 // exist and have the changed value |
|
484 TEST(realval==KRealChangedValue); |
|
485 aServerRepo->Close(); |
|
486 |
|
487 DeleteFilesL(); |
|
488 |
|
489 CleanupStack::PopAndDestroy(aSessionNotif); |
|
490 CleanupStack::PopAndDestroy(aServerRepo); |
|
491 |
|
492 CleanupStack::PopAndDestroy( backupClient ); |
|
493 // Cleanup the scheduler |
|
494 CActiveScheduler::Replace( globalAS ); |
|
495 CleanupStack::PopAndDestroy( s ); |
|
496 } |
|
497 |
|
498 |
|
499 // --------------------------------------------------- |
|
500 // OomTest |
|
501 // |
|
502 // Function to convert a test into an OOM test |
|
503 |
|
504 /** |
|
505 @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-0117-0001 |
|
506 @SYMTestCaseDesc Test functionality under OOM. |
|
507 @SYMTestPriority High |
|
508 @SYMTestActions Test functionality under OOM. |
|
509 @SYMTestExpectedResults The test must not fail. |
|
510 @SYMPREQ PREQ752 |
|
511 */ |
|
512 LOCAL_C void OomTest( void (*testFuncL)() ) |
|
513 { |
|
514 TheTest.Next( _L( " @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-0117-0001 " ) ); |
|
515 TInt error; |
|
516 TInt count = 0; |
|
517 |
|
518 do |
|
519 { |
|
520 User::__DbgMarkStart( RHeap::EUser ); |
|
521 |
|
522 // find out the number of open handles |
|
523 TInt startProcessHandleCount; |
|
524 TInt startThreadHandleCount; |
|
525 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); |
|
526 |
|
527 User::__DbgSetAllocFail( RHeap::EUser, RHeap::EFailNext, ++count ); |
|
528 |
|
529 TRAP( error, (testFuncL)() ); |
|
530 |
|
531 User::__DbgSetAllocFail( RHeap::EUser, RHeap::ENone, 1 ); |
|
532 |
|
533 // check that no handles have leaked |
|
534 TInt endProcessHandleCount; |
|
535 TInt endThreadHandleCount; |
|
536 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); |
|
537 |
|
538 TEST(startProcessHandleCount == endProcessHandleCount); |
|
539 TEST(startThreadHandleCount == endThreadHandleCount); |
|
540 |
|
541 User::__DbgMarkEnd( RHeap::EUser, 0 ); |
|
542 } while( error == KErrNoMemory ); |
|
543 |
|
544 _LIT( KTestFailed, "Out of memory test failure on iteration %d\n" ); |
|
545 __ASSERT_ALWAYS( error == KErrNone, TheTest.Panic( error, KTestFailed, count ) ); |
|
546 |
|
547 TheTest.Printf( _L( "Out of memory tests succeeded at heap failure rate of %i\n" ), count ); |
|
548 TheTest.Printf( _L( "Process handle count preserved\n" ) ); |
|
549 TheTest.Printf( _L( "Thread handle count preserved\n" ) ); |
|
550 } |
|
551 |
|
552 |
|
553 |
|
554 |
|
555 |
|
556 LOCAL_C void DoTestsL() |
|
557 { |
|
558 TheTest.Next( _L( "Do initialization" ) ); |
|
559 InitializationL(); |
|
560 |
|
561 TheTest.Next( _L( "Backup tests" ) ); |
|
562 BackupTestsL(); |
|
563 |
|
564 TheTest.Next( _L( "Restore tests" ) ); |
|
565 RestoreTestsL(); |
|
566 |
|
567 TheTest.Next( _L( "Cleanup" ) ); |
|
568 TServerResources::iOwnerIdLookUpTable.Reset(); |
|
569 Cleanup(); |
|
570 } |
|
571 |
|
572 LOCAL_C void MainL() |
|
573 { |
|
574 __UHEAP_MARK; |
|
575 |
|
576 TheTest.Start( _L( "Backup and restore tests" ) ); |
|
577 // create and install the active scheduler we need for the cache manager in TServerResources::InitialiseL |
|
578 globalAS=new(ELeave) CActiveScheduler; |
|
579 CleanupStack::PushL(globalAS); |
|
580 CActiveScheduler::Install(globalAS); |
|
581 TServerResources::InitialiseL(); |
|
582 |
|
583 DoTestsL(); |
|
584 |
|
585 TheTest.Next( _L( "Out of memory tests" ) ); |
|
586 OomTest( DoTestsL ); |
|
587 |
|
588 TServerResources::Close(); |
|
589 CleanupStack::PopAndDestroy(globalAS); |
|
590 |
|
591 TheTest.End(); |
|
592 TheTest.Close(); |
|
593 |
|
594 __UHEAP_MARKEND; |
|
595 } |
|
596 |
|
597 TInt E32Main() |
|
598 { |
|
599 #ifdef __SECURE_DATA__ |
|
600 __UHEAP_MARK; |
|
601 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
602 if ( !cleanup ) |
|
603 return KErrNoMemory; |
|
604 |
|
605 TRAPD( err, MainL() ); |
|
606 if ( err != KErrNone ) |
|
607 User::Panic( _L( "Testing failed: " ), err ); |
|
608 |
|
609 delete cleanup; |
|
610 __UHEAP_MARKEND; |
|
611 #endif |
|
612 |
|
613 return 0; |
|
614 } |
|
615 |