|
1 /* |
|
2 * Copyright (c) 2004-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 /** |
|
20 @file |
|
21 @test |
|
22 @internalTechnology |
|
23 */ |
|
24 |
|
25 #include "tintegrityservicesstep.h" |
|
26 #include <s32file.h> |
|
27 #include "journal.h" |
|
28 #include "journalfile.h" |
|
29 |
|
30 |
|
31 ///////////////////////////////////////////////////////////////////// |
|
32 // CIntegrityServicesStep |
|
33 ///////////////////////////////////////////////////////////////////// |
|
34 CIntegrityServicesStepBase::CIntegrityServicesStepBase(CStsTestServer &aStsTestServer):CStsBaseTestStep(aStsTestServer) |
|
35 { |
|
36 } |
|
37 void CIntegrityServicesStepBase::ImplTestStepPreambleL() |
|
38 { |
|
39 INFO_PRINTF1(_L("CIntegrityServicesStepBase::ImplTestStepPreambleL()")); |
|
40 __UHEAP_MARK; |
|
41 |
|
42 // Install an active scheduler |
|
43 CActiveScheduler* s = new (ELeave) CActiveScheduler; |
|
44 s->Install(s); |
|
45 |
|
46 User::LeaveIfError(iIntegritySession.Connect()); |
|
47 |
|
48 ReadFailureSettingsL(); |
|
49 } |
|
50 |
|
51 void CIntegrityServicesStepBase::ImplTestStepPostambleL() |
|
52 { |
|
53 INFO_PRINTF1(_L("CIntegrityServicesStepBase::ImplTestStepPostambleL()")); |
|
54 // Remove the installed active scheduler |
|
55 CActiveScheduler* s = CActiveScheduler::Current(); |
|
56 s->Install(NULL); |
|
57 delete s; |
|
58 |
|
59 iIntegritySession.Close(); |
|
60 |
|
61 __UHEAP_MARKEND; |
|
62 |
|
63 |
|
64 } |
|
65 |
|
66 void CIntegrityServicesStepBase::GetStringArrayFromConfigL(const TDesC& aSectName, const TDesC& aKeyName, RArray<TPtrC>& aArray) |
|
67 { |
|
68 INFO_PRINTF1(_L("CIntegrityServicesStepBase::GetStringArrayFromConfigL()")); |
|
69 _LIT(KKeyFormat, "-%02d"); |
|
70 HBufC* buf = HBufC::NewLC(aKeyName.Length() + KKeyFormat().Length()); |
|
71 TPtr ptr(buf->Des()); |
|
72 INFO_PRINTF2(_L("Parsing attribute: %S"), &aKeyName); |
|
73 |
|
74 TInt i = 0; |
|
75 TBool cont = ETrue; |
|
76 do |
|
77 { |
|
78 ++i; |
|
79 ptr = aKeyName; |
|
80 ptr.AppendFormat(KKeyFormat(), i); |
|
81 TPtrC val; |
|
82 |
|
83 cont = GetStringFromConfig(aSectName, ptr, val); |
|
84 if (cont) |
|
85 { |
|
86 User::LeaveIfError(aArray.Append(val)); |
|
87 } |
|
88 } while (cont); |
|
89 |
|
90 INFO_PRINTF2(_L("Element count: %d"), i-1); |
|
91 CleanupStack::PopAndDestroy(buf); |
|
92 } |
|
93 |
|
94 TBool CIntegrityServicesStepBase::CheckFilesL() |
|
95 { |
|
96 INFO_PRINTF1(_L("CIntegrityServicesStepBase::CheckFilesL()")); |
|
97 TInt result = ETrue; |
|
98 RArray<TPtrC> fileArray; |
|
99 CleanupClosePushL(fileArray); |
|
100 |
|
101 GetStringArrayFromConfigL(ConfigSection(), KPresent, fileArray); |
|
102 for (TInt file = 0; file < fileArray.Count();file++) |
|
103 { |
|
104 if(FileExistsL(fileArray[file])) |
|
105 { |
|
106 INFO_PRINTF2(_L("%S was found"), &fileArray[file]); |
|
107 } |
|
108 else |
|
109 { |
|
110 ERR_PRINTF2(_L("%S was not found"), &fileArray[file]); |
|
111 result = EFalse; |
|
112 } |
|
113 } |
|
114 fileArray.Reset(); |
|
115 |
|
116 GetStringArrayFromConfigL(ConfigSection(), KAbsent, fileArray); |
|
117 for (TInt file = 0; file < fileArray.Count();file++) |
|
118 { |
|
119 if(FileExistsL(fileArray[file])) |
|
120 { |
|
121 ERR_PRINTF2(_L("%S was found"), &fileArray[file]); |
|
122 result = EFalse; |
|
123 } |
|
124 else |
|
125 { |
|
126 INFO_PRINTF2(_L("%S was not found"), &fileArray[file]); |
|
127 } |
|
128 } |
|
129 fileArray.Reset(); |
|
130 CleanupStack::PopAndDestroy(&fileArray); |
|
131 return result; |
|
132 } |
|
133 |
|
134 void CIntegrityServicesStepBase::ReadFailureSettingsL() |
|
135 { |
|
136 INFO_PRINTF1(_L("CIntegrityServicesStepBase::ReadFailureSettings()")); |
|
137 TPtrC failType; |
|
138 if(!GetStringFromConfig(ConfigSection(), KFailType, failType)) |
|
139 { |
|
140 failType.Set(KNullDesC); |
|
141 } |
|
142 |
|
143 TPtrC failPosition; |
|
144 if(!GetStringFromConfig(ConfigSection(), KFailPosition, failPosition)) |
|
145 { |
|
146 failPosition.Set(KNullDesC); |
|
147 } |
|
148 |
|
149 TPtrC failFileName; |
|
150 if(!GetStringFromConfig(ConfigSection(), KFailFileName, failFileName)) |
|
151 { |
|
152 failFileName.Set(KNullDesC); |
|
153 } |
|
154 |
|
155 iIntegritySession.SetSimulatedFailureL(failType, failPosition, failFileName); |
|
156 } |
|
157 |
|
158 void CIntegrityServicesStepBase::doInstallL() |
|
159 { |
|
160 INFO_PRINTF1(_L("CIntegrityServicesStepBase::doInstallL()")); |
|
161 RArray<TPtrC> fileArray; |
|
162 CleanupClosePushL(fileArray); |
|
163 |
|
164 GetStringArrayFromConfigL(ConfigSection(), KRemoveFile, fileArray); |
|
165 for (TInt file = 0; file < fileArray.Count();file++) |
|
166 { |
|
167 INFO_PRINTF2(_L("RemovingFile: %S"), &fileArray[file]); |
|
168 |
|
169 iIntegritySession.RemoveL(fileArray[file]); |
|
170 } |
|
171 fileArray.Reset(); |
|
172 |
|
173 |
|
174 GetStringArrayFromConfigL(ConfigSection(), KAddFile, fileArray); |
|
175 for (TInt file = 0; file < fileArray.Count();file++) |
|
176 { |
|
177 INFO_PRINTF2(_L("AddingFile: %S"), &fileArray[file]); |
|
178 iIntegritySession.AddL(fileArray[file]); |
|
179 iIntegritySession.CreateNewTestFileL(fileArray[file]); |
|
180 } |
|
181 fileArray.Reset(); |
|
182 |
|
183 GetStringArrayFromConfigL(ConfigSection(), KTempFile, fileArray); |
|
184 for (TInt file = 0; file < fileArray.Count();file++) |
|
185 { |
|
186 INFO_PRINTF2(_L("TemporaryFile: %S"), &fileArray[file]); |
|
187 iIntegritySession.TemporaryL(fileArray[file]); |
|
188 iIntegritySession.CreateTempTestFileL(fileArray[file]); |
|
189 } |
|
190 fileArray.Reset(); |
|
191 |
|
192 RArray<TPtrC> operationArray; |
|
193 CleanupClosePushL(operationArray); |
|
194 |
|
195 GetStringArrayFromConfigL(ConfigSection(), KArbitraryOpFile, fileArray); |
|
196 GetStringArrayFromConfigL(ConfigSection(), KOperation, operationArray); |
|
197 TInt fileCount = fileArray.Count(); |
|
198 |
|
199 if (fileCount != operationArray.Count()) |
|
200 { |
|
201 ERR_PRINTF3(_L("Number of files (%d) does not match number of operations (%d)"), fileCount, operationArray.Count()); |
|
202 SetTestStepResult(EFail); |
|
203 } |
|
204 else |
|
205 { |
|
206 for (TInt file = 0; file < fileCount;file++) |
|
207 { |
|
208 if (operationArray[file].CompareF(KAddFile) == 0) |
|
209 { |
|
210 INFO_PRINTF2(_L("AddingFile: %S"), &fileArray[file]); |
|
211 iIntegritySession.AddL(fileArray[file]); |
|
212 iIntegritySession.CreateNewTestFileL(fileArray[file]); |
|
213 } |
|
214 else if (operationArray[file].CompareF(KRemoveFile) == 0) |
|
215 { |
|
216 INFO_PRINTF2(_L("RemovingFile: %S"), &fileArray[file]); |
|
217 iIntegritySession.RemoveL(fileArray[file]); |
|
218 } |
|
219 else if (operationArray[file].CompareF(KTempFile) == 0) |
|
220 { |
|
221 INFO_PRINTF2(_L("TemporaryFile: %S"), &fileArray[file]); |
|
222 iIntegritySession.TemporaryL(fileArray[file]); |
|
223 iIntegritySession.CreateTempTestFileL(fileArray[file]); |
|
224 } |
|
225 else |
|
226 { |
|
227 ERR_PRINTF3(_L("Operation %S not understood, skipping file %S"), &operationArray[file], &fileArray[file]); |
|
228 } |
|
229 } |
|
230 } |
|
231 CleanupStack::PopAndDestroy(2, &fileArray); |
|
232 |
|
233 iIntegritySession.CommitL(); |
|
234 } |
|
235 |
|
236 void CIntegrityServicesStepBase::doRecoverL() |
|
237 { |
|
238 INFO_PRINTF1(_L("CIntegrityServicesStepBase::doRecoverL()")); |
|
239 iIntegritySession.RollBackL(EFalse); |
|
240 } |
|
241 |
|
242 void CIntegrityServicesStepBase::doCleanupL() |
|
243 { |
|
244 |
|
245 INFO_PRINTF1(_L("CIntegrityServicesStepBase::doCleanupL()")); |
|
246 RArray<TPtrC> fileArray; |
|
247 CleanupClosePushL(fileArray); |
|
248 |
|
249 GetStringArrayFromConfigL(ConfigSection(), KCleanupFile, fileArray); |
|
250 for (TInt file = 0; file < fileArray.Count();file++) |
|
251 { |
|
252 TRAPD(err, DeleteFileL(fileArray[file])); |
|
253 if(err != KErrNone && err != KErrPathNotFound && err != KErrNotFound) |
|
254 { |
|
255 User::Leave(err); |
|
256 } |
|
257 } |
|
258 fileArray.Reset(); |
|
259 GetStringArrayFromConfigL(ConfigSection(), KCleanupDirectory, fileArray); |
|
260 for (TInt file = 0; file < fileArray.Count();file++) |
|
261 { |
|
262 TRAPD(err, DeleteFileL(fileArray[file])); |
|
263 if(err != KErrNone && err != KErrPathNotFound && err != KErrNotFound) |
|
264 { |
|
265 User::Leave(err); |
|
266 } |
|
267 } |
|
268 fileArray.Reset(); |
|
269 CleanupStack::PopAndDestroy(&fileArray); |
|
270 } |
|
271 |
|
272 ///////////////////////////////////////////////////////////////////// |
|
273 // CInstallStep |
|
274 ///////////////////////////////////////////////////////////////////// |
|
275 CInstallStep::CInstallStep(CStsTestServer &aStsTestServer):CIntegrityServicesStepBase(aStsTestServer) |
|
276 { |
|
277 SetTestStepName(KInstall); |
|
278 } |
|
279 |
|
280 void CInstallStep::ImplTestStepL() |
|
281 { |
|
282 INFO_PRINTF1(_L("CInstallStep::ImplTestStepL()")); |
|
283 TRAPD(err, doInstallL()); |
|
284 |
|
285 if(err == KErrNone || err == KIntegrityServicesSimulatedBatteryFailure) |
|
286 { |
|
287 if(CheckFilesL()) |
|
288 { |
|
289 SetTestStepResult(EPass); |
|
290 } |
|
291 else |
|
292 { |
|
293 SetTestStepResult(EFail); |
|
294 } |
|
295 } |
|
296 else |
|
297 { |
|
298 User::Leave(err); |
|
299 } |
|
300 |
|
301 } |
|
302 |
|
303 ///////////////////////////////////////////////////////////////////// |
|
304 // CRecoverStep |
|
305 ///////////////////////////////////////////////////////////////////// |
|
306 CRecoverStep::CRecoverStep(CStsTestServer &aStsTestServer):CIntegrityServicesStepBase(aStsTestServer) |
|
307 { |
|
308 SetTestStepName(KRecover); |
|
309 } |
|
310 |
|
311 void CRecoverStep::ImplTestStepL() |
|
312 { |
|
313 INFO_PRINTF1(_L("CRecoverStep::ImplTestStepL()")); |
|
314 // begin recovery |
|
315 TRAPD(err, doRecoverL()); |
|
316 |
|
317 if(err == KErrNone || err == KIntegrityServicesSimulatedBatteryFailure) |
|
318 { |
|
319 if(CheckFilesL()) |
|
320 { |
|
321 SetTestStepResult(EPass); |
|
322 } |
|
323 else |
|
324 { |
|
325 SetTestStepResult(EFail); |
|
326 } |
|
327 } |
|
328 else |
|
329 { |
|
330 User::Leave(err); |
|
331 } |
|
332 |
|
333 |
|
334 } |
|
335 |
|
336 ///////////////////////////////////////////////////////////////////// |
|
337 // CCleanupStep |
|
338 ///////////////////////////////////////////////////////////////////// |
|
339 CCleanupStep::CCleanupStep(CStsTestServer &aStsTestServer):CIntegrityServicesStepBase(aStsTestServer) |
|
340 { |
|
341 SetTestStepName(KCleanup); |
|
342 } |
|
343 |
|
344 void CCleanupStep::ImplTestStepL() |
|
345 { |
|
346 INFO_PRINTF1(_L("CCleanupStep::ImplTestStepL()")); |
|
347 doCleanupL(); |
|
348 |
|
349 SetTestStepResult(EPass); |
|
350 |
|
351 } |
|
352 |
|
353 ///////////////////////////////////////////////////////////////////// |
|
354 // CRecoverStep |
|
355 ///////////////////////////////////////////////////////////////////// |
|
356 CCheckStep::CCheckStep(CStsTestServer &aStsTestServer):CIntegrityServicesStepBase(aStsTestServer) |
|
357 { |
|
358 SetTestStepName(KCheck); |
|
359 } |
|
360 |
|
361 void CCheckStep::ImplTestStepL() |
|
362 { |
|
363 INFO_PRINTF1(_L("CCheckStep::ImplTestStepL()")); |
|
364 // Just check for files |
|
365 if(CheckFilesL()) |
|
366 { |
|
367 SetTestStepResult(EPass); |
|
368 } |
|
369 else |
|
370 { |
|
371 SetTestStepResult(EFail); |
|
372 } |
|
373 |
|
374 |
|
375 } |
|
376 |
|
377 |
|
378 //---------- new unit tests developed as part of the STS framework ---------- |
|
379 using namespace Usif; |
|
380 |
|
381 //define event names for logging purposes (used in journal file unit tests and journal unit tests |
|
382 _LIT(KENone, "ENone"); |
|
383 _LIT(KERemovedFile,"ERemovedFile"); |
|
384 _LIT(KEBackupFile,"EBackupFile"); |
|
385 _LIT(KETempFile,"ETempFile"); |
|
386 _LIT(KEAddedFile,"EAddedFile"); |
|
387 _LIT(KECommitted,"ECommitted"); |
|
388 _LIT(KEBackupFilesRemoved,"EBackupFilesRemoved"); |
|
389 _LIT(KEAddedFilesRemoved,"EAddedFilesRemoved"); |
|
390 _LIT(KERemovedFilesRestored,"ERemovedFilesRestored"); |
|
391 _LIT(KETempFilesRemoved, "ETempFilesRemoved"); |
|
392 |
|
393 |
|
394 const TDesC* eventNames[] = { |
|
395 &KENone, |
|
396 &KERemovedFile, |
|
397 &KEBackupFile, |
|
398 &KETempFile, |
|
399 &KEAddedFile, |
|
400 &KECommitted, |
|
401 &KEBackupFilesRemoved, |
|
402 &KEAddedFilesRemoved, |
|
403 &KERemovedFilesRestored, |
|
404 &KETempFilesRemoved |
|
405 }; |
|
406 |
|
407 |
|
408 const TFileMode defaultJournalFileMode = TFileMode (TFileMode(EFileWrite) | TFileMode(EFileShareAny)); |
|
409 |
|
410 CJournalFileUnitTest::CJournalFileUnitTest(CStsTestServer &aStsTestServer): CStsBaseTestStep(aStsTestServer) |
|
411 { |
|
412 // Call base class method to set up the human readable name for logging |
|
413 SetTestStepName(KJournalFileUnitTest); |
|
414 } |
|
415 |
|
416 CJournalFileUnitTest::~CJournalFileUnitTest() |
|
417 { |
|
418 delete testJournalFile; |
|
419 iFs.Close(); |
|
420 iLoader.Close(); |
|
421 } |
|
422 |
|
423 |
|
424 void CJournalFileUnitTest::ImplTestStepPreambleL() |
|
425 /** |
|
426 @return - void code |
|
427 Override of base class virtual |
|
428 */ |
|
429 { |
|
430 INFO_PRINTF1(_L("JournalFileUnitTest Preamble")); |
|
431 User::LeaveIfError(iFs.Connect()); |
|
432 User::LeaveIfError(iLoader.Connect()); |
|
433 testJournalFile = CTestFile::NewL(iFs); |
|
434 SetTestStepResult(EPass); |
|
435 |
|
436 } |
|
437 |
|
438 void CJournalFileUnitTest::ImplTestStepL() |
|
439 /** |
|
440 @return - void code |
|
441 Override of base class pure virtual |
|
442 */ |
|
443 { |
|
444 INFO_PRINTF1(_L("JournalFileUnitTest in test step")); |
|
445 SetTestStepResult(EPass); |
|
446 |
|
447 TPtrC journalFilePathInIni = GetTargetFilePathFromConfigL(); |
|
448 TParsePtrC journalFilePathParse(journalFilePathInIni); |
|
449 TDriveUnit journaldrive(journalFilePathParse.Drive()); |
|
450 HBufC* targetFileName = HBufC::NewLC(KMaxFileName); |
|
451 HBufC* backupFileName = HBufC::NewLC(KMaxFileName); |
|
452 |
|
453 CJournalFile* journalFile = CJournalFile::NewLC(iFs, iLoader, journalFilePathInIni, journaldrive); |
|
454 |
|
455 //feed incorrect file to the journalfile (ie: file's on other drive) |
|
456 TPtr targetFileNameBasePtr(targetFileName->Des()); |
|
457 targetFileNameBasePtr.Append(TDriveUnit(journaldrive+1).Name()); |
|
458 targetFileNameBasePtr.Append(journalFilePathParse.Path()); |
|
459 |
|
460 TPtr targetFileNamePtr(targetFileNameBasePtr); |
|
461 targetFileNamePtr.Append(_L("dummyadd.txt")); |
|
462 |
|
463 TPtr targetBackupFileNamePtr(backupFileName->Des()); |
|
464 |
|
465 TInt err(0); |
|
466 |
|
467 TInt seekPosition(0); |
|
468 TInt seekToEndPosition(0); |
|
469 TIntValue intValue = {0}; |
|
470 TIntValue extraByte = {0xFF}; |
|
471 |
|
472 TRAP(err, journalFile->AddL(targetFileNamePtr)); |
|
473 if(err!=KErrBadName) |
|
474 { |
|
475 ERR_PRINTF2(_L("<font color=red>CJournalFile::AddL() returned incorrect error code. KErrBadName is expected %d is returned!</font>"), err); |
|
476 SetTestStepResult(EFail); |
|
477 } |
|
478 targetFileNamePtr.Set(targetFileNameBasePtr); |
|
479 targetFileNamePtr.Append(_L("dummytemp.txt")); |
|
480 TRAP(err, journalFile->TemporaryL(targetFileNamePtr)); |
|
481 if(err!=KErrBadName) |
|
482 { |
|
483 ERR_PRINTF2(_L("<font color=red>CJournalFile::RemoveL() returned incorrect error code. KErrBadName is expected %d is returned!</font>"), err); |
|
484 SetTestStepResult(EFail); |
|
485 } |
|
486 |
|
487 targetFileNamePtr.Set(targetFileNameBasePtr); |
|
488 targetFileNamePtr.Append(_L("dummyremove.txt")); |
|
489 TRAP(err, journalFile->RemoveL(targetFileNamePtr, targetBackupFileNamePtr)); |
|
490 if(err!=KErrBadName) |
|
491 { |
|
492 ERR_PRINTF2(_L("<font color=red>CJournalFile::RemoveL() returned incorrect error code. KErrBadName is expected %d is returned!</font>"), err); |
|
493 SetTestStepResult(EFail); |
|
494 } |
|
495 |
|
496 *targetFileName = KEmptyString; |
|
497 targetFileNameBasePtr.Set(targetFileName->Des()); |
|
498 targetFileNameBasePtr.Append(journalFilePathParse.DriveAndPath()); |
|
499 |
|
500 CleanupStack::PopAndDestroy(journalFile); |
|
501 DeleteFileL(journalFilePathInIni); |
|
502 //------------------------------------------------------------------------------------- |
|
503 //Steps: |
|
504 // 1.) create a CJournalFile object |
|
505 // 2.) set last event by invoking CJournalFile::EventL() (this sets the iLastEvent as well as writes the event value to the journal file on disk) |
|
506 // 3.) destroy object |
|
507 // 4.) corrupt information by overwriting the event value in the file to requested invalid value |
|
508 // 5.) recreate CjournalFile object -> this will trigger CJournalFile::ReadEntryL |
|
509 // note: the purpose of this testcase to excersise the main switch-case in CJournalFile::ReadEntryL |
|
510 //------------------------------------------------------------------------------------- |
|
511 |
|
512 TIntegrityServicesEvent eventsToSet[] = {ERemovedFile, |
|
513 EBackupFile, |
|
514 ETempFile, |
|
515 EAddedFile, |
|
516 ECommitted, |
|
517 EBackupFilesRemoved, |
|
518 EAddedFilesRemoved, |
|
519 //ETempFilesRemoved, |
|
520 ERemovedFilesRestored, |
|
521 }; |
|
522 TInt numOfInvalidEvents[] = {6, //number of invalid events for ERemovedFile |
|
523 1, //number of invalid events for EBackupFile |
|
524 6, //number of invalid events for ETempFile |
|
525 6, //number of invalid events for EAddedFile |
|
526 7, //number of invalid events for ECommitted |
|
527 9, //number of invalid events for EBackupFilesRemoved |
|
528 6, //number of invalid events for EAddedFilesRemoved |
|
529 //ETempFilesRemoved |
|
530 9 //number of invalid events for ERemovedFilesRestored |
|
531 }; |
|
532 TIntegrityServicesEvent invalidEvents[][10] = {{EBackupFile, ECommitted, EBackupFilesRemoved, EAddedFilesRemoved, ERemovedFilesRestored, ETempFilesRemoved}, //invalid events for ERemovedFile |
|
533 {EBackupFile}, //invalid events for EBackupFile, this is not really invalid value for EBackupFile, actually EBackupFile itself is invalid on its own in the file |
|
534 {EBackupFile, ECommitted, EBackupFilesRemoved, EAddedFilesRemoved, ERemovedFilesRestored, ETempFilesRemoved}, //invalid events for ETempFile |
|
535 {EBackupFile, ECommitted, EBackupFilesRemoved, EAddedFilesRemoved, ERemovedFilesRestored, ETempFilesRemoved}, //invalid events for EAddedFile |
|
536 {ENone, EBackupFile, ECommitted, EBackupFilesRemoved, EAddedFilesRemoved, ERemovedFilesRestored, ETempFilesRemoved}, //invalid events for ECommitted |
|
537 {ENone, ERemovedFile, EBackupFile, ETempFile, EAddedFile, EBackupFilesRemoved, EAddedFilesRemoved, ERemovedFilesRestored, ETempFilesRemoved}, //invalid events for EBackupFilesRemoved |
|
538 {ENone, EBackupFile, EBackupFilesRemoved, EAddedFilesRemoved, ERemovedFilesRestored, ETempFilesRemoved}, //invalid events for EAddedFilesRemoved |
|
539 //{}, //invalid events for ETempFilesRemoved |
|
540 {ENone, ERemovedFile, EBackupFile, ETempFile, EAddedFile, ECommitted, EBackupFilesRemoved, ETempFilesRemoved, ERemovedFilesRestored} //invalid events for ERemovedFilesRestored |
|
541 }; |
|
542 |
|
543 ASSERT(sizeof(eventsToSet)/sizeof(TIntegrityServicesEvent) == sizeof(numOfInvalidEvents)/sizeof(TInt) == sizeof(invalidEvents)/(sizeof(TIntegrityServicesEvent)*10)); |
|
544 for (TInt i=0; i<sizeof(eventsToSet)/sizeof(TIntegrityServicesEvent); ++i) |
|
545 { |
|
546 for(TInt j=0; j<numOfInvalidEvents[i]; ++j) |
|
547 { |
|
548 journalFile=0; |
|
549 journalFile = CJournalFile::NewLC(iFs, iLoader, journalFilePathInIni, journaldrive); |
|
550 journalFile->EventL(invalidEvents[i][j]); //set last event to any of the requested invalid events (also writes it to jounral file) |
|
551 CleanupStack::PopAndDestroy(journalFile); |
|
552 intValue.int32 = static_cast<TInt32>(eventsToSet[i]); |
|
553 seekPosition=0; |
|
554 OpenJournalFileL(journalFilePathInIni, defaultJournalFileMode); |
|
555 SeekInJournalFileL(ESeekStart, seekPosition); |
|
556 WriteIntToJournalFileL(intValue, Mode32Bit); //write the requested event to journal file (overwrites last event set by EventL()) |
|
557 seekToEndPosition=0; |
|
558 SeekInJournalFileL(ESeekEnd, seekToEndPosition); |
|
559 WriteIntToJournalFileL(extraByte, Mode8Bit); |
|
560 CloseJournalFile(); |
|
561 //force a Sync and catch the error that should be KErrCorrupt |
|
562 journalFile=0; |
|
563 TRAPD(err, |
|
564 journalFile = CJournalFile::NewLC(iFs, iLoader, journalFilePathInIni, journaldrive); |
|
565 CleanupStack::PopAndDestroy(journalFile); |
|
566 ); |
|
567 if(err!=KErrCorrupt) |
|
568 { |
|
569 ERR_PRINTF4(_L("<font color=red>CJournalFile::SynchL() returned incorrect error code. KErrCorrupt is expected and %d is returned! Conditions: last event set via EventL(): %S Event written into journal file: %S</font>"), err, eventNames[invalidEvents[i][j]], eventNames[eventsToSet[i]]); |
|
570 SetTestStepResult(EFail); |
|
571 } |
|
572 DeleteFileL(journalFilePathInIni); |
|
573 } |
|
574 } |
|
575 //------------------------------------------------------------------------------------- |
|
576 //Steps: |
|
577 // 1.) create a journal file using CJournalFile::NewLC |
|
578 // 2.) add an item via AddL() or TemporaryL() |
|
579 // 2.) corrupt disk information in the filename written into the file |
|
580 // 3.) try to recreate journal object using CJournalFile::NewLC |
|
581 // 4.) expect KErrCorrupt |
|
582 //------------------------------------------------------------------------------------- |
|
583 |
|
584 targetFileNamePtr.Set(targetFileNameBasePtr); |
|
585 targetFileNamePtr.Append(_L("dummyadd_or_temp.txt")); |
|
586 for(TInt i=0; i<2; i++) |
|
587 { |
|
588 //create a journal file and add an item via AddL() or TemporaryL() |
|
589 journalFile=0; |
|
590 journalFile = CJournalFile::NewLC(iFs, iLoader, journalFilePathInIni, journaldrive); |
|
591 if(i==0) |
|
592 { |
|
593 journalFile->AddL(targetFileNamePtr); |
|
594 } |
|
595 else if(i==1) |
|
596 { |
|
597 journalFile->TemporaryL(targetFileNamePtr); |
|
598 } |
|
599 CleanupStack::PopAndDestroy(journalFile); |
|
600 //open journal file and corrupt it by overwriting the drive letter in the file's path |
|
601 seekPosition=sizeof(TInt32)+1; |
|
602 OpenJournalFileL(journalFilePathInIni, defaultJournalFileMode); |
|
603 SeekInJournalFileL(ESeekStart, seekPosition); |
|
604 intValue = ReadIntFromJournalFileL(Mode8Bit); |
|
605 intValue.int8++; //corrupt drive letter (ie: 'c' ==> 'd') |
|
606 SeekInJournalFileL(ESeekStart, seekPosition); |
|
607 WriteIntToJournalFileL(intValue, Mode8Bit); |
|
608 CloseJournalFile(); |
|
609 //check that CJournalFile recognizes corruption |
|
610 journalFile=0; |
|
611 TRAP(err, |
|
612 journalFile = CJournalFile::NewLC(iFs, iLoader, journalFilePathInIni, journaldrive); |
|
613 CleanupStack::PopAndDestroy(journalFile); |
|
614 ); |
|
615 if(err!=KErrCorrupt) |
|
616 { |
|
617 ERR_PRINTF2(_L("<font color=red>CJournalFile::NewL() returned incorrect error code. KErrCorrupt is expected and %d is returned!</font>"), err); |
|
618 SetTestStepResult(EFail); |
|
619 } |
|
620 DeleteFileL(journalFilePathInIni); |
|
621 } |
|
622 //------------------------------------------------------------------------------------- |
|
623 //Steps: |
|
624 // 1.) create a journal file using CJournalFile::NewLC |
|
625 // 2.) add an item via RemoveyL() |
|
626 // 2.) corrupt disk information in various ways in the file |
|
627 // 3.) try to recreate journal object using CJournalFile::NewL |
|
628 // 4.) expect KErrCorrupt |
|
629 //------------------------------------------------------------------------------------- |
|
630 |
|
631 journalFile=0; |
|
632 journalFile = CJournalFile::NewLC(iFs, iLoader, journalFilePathInIni, journaldrive); |
|
633 targetFileNamePtr.Set(targetFileNameBasePtr); |
|
634 targetFileNamePtr.Append(_L("dummyremove.txt")); |
|
635 journalFile->RemoveL(targetFileNamePtr, targetBackupFileNamePtr); |
|
636 CleanupStack::PopAndDestroy(journalFile); |
|
637 |
|
638 OpenJournalFileL(journalFilePathInIni, defaultJournalFileMode); |
|
639 seekPosition=sizeof(TInt32)+1+targetFileNamePtr.Length(); |
|
640 SeekInJournalFileL(ESeekStart, seekPosition); |
|
641 intValue.int32 = static_cast<TInt32>(EAddedFile); //corrupt operation: originally EBackupFile is recorded here |
|
642 WriteIntToJournalFileL(intValue, Mode32Bit); |
|
643 |
|
644 //check that CJournalFile recognizes corruption |
|
645 journalFile=0; |
|
646 TRAP(err, |
|
647 journalFile = CJournalFile::NewLC(iFs, iLoader, journalFilePathInIni, journaldrive); |
|
648 CleanupStack::PopAndDestroy(journalFile); |
|
649 ); |
|
650 if(err!=KErrCorrupt) |
|
651 { |
|
652 ERR_PRINTF2(_L("<font color=red>CJournalFile::NewL() returned incorrect error code. KErrCorrupt is expected and %d is returned!</font>"), err); |
|
653 SetTestStepResult(EFail); |
|
654 } |
|
655 |
|
656 SeekInJournalFileL(ESeekStart, seekPosition); |
|
657 intValue.int32 = static_cast<TInt32>(EBackupFile); //restore original record |
|
658 WriteIntToJournalFileL(intValue, Mode32Bit); |
|
659 |
|
660 //check that journal file is not corrupted |
|
661 journalFile=0; |
|
662 TRAP(err, |
|
663 journalFile = CJournalFile::NewLC(iFs, iLoader, journalFilePathInIni, journaldrive); |
|
664 CleanupStack::PopAndDestroy(journalFile); |
|
665 ); |
|
666 if(err!=KErrNone) |
|
667 { |
|
668 ERR_PRINTF2(_L("<font color=red>CJournalFile::NewL() returned incorrect error code. KErrNone is expected and %d is returned!</font>"), err); |
|
669 SetTestStepResult(EFail); |
|
670 } |
|
671 |
|
672 seekPosition=sizeof(TInt32)+1; |
|
673 SeekInJournalFileL(ESeekStart, seekPosition); |
|
674 intValue = ReadIntFromJournalFileL(Mode8Bit); //read first file's drive letter |
|
675 intValue.int8++; //corrupt drive letter (ie: 'c' ==> 'd') |
|
676 SeekInJournalFileL(ESeekStart, seekPosition); |
|
677 WriteIntToJournalFileL(intValue, Mode8Bit); //write corrupt drive letter to file |
|
678 |
|
679 //check that CJournalFile recognizes corruption |
|
680 journalFile=0; |
|
681 TRAP(err, |
|
682 journalFile = CJournalFile::NewLC(iFs, iLoader, journalFilePathInIni, journaldrive); |
|
683 CleanupStack::PopAndDestroy(journalFile); |
|
684 ); |
|
685 if(err!=KErrCorrupt) |
|
686 { |
|
687 ERR_PRINTF2(_L("<font color=red>CJournalFile::NewL() returned incorrect error code. KErrCorrupt is expected and %d is returned!</font>"), err); |
|
688 SetTestStepResult(EFail); |
|
689 } |
|
690 |
|
691 intValue.int8--; //restore original drive letter |
|
692 SeekInJournalFileL(ESeekStart, seekPosition); |
|
693 WriteIntToJournalFileL(intValue, Mode8Bit); //write original drive letter to file |
|
694 |
|
695 |
|
696 //check that journal file is not corrupted |
|
697 journalFile=0; |
|
698 TRAP(err, |
|
699 journalFile = CJournalFile::NewLC(iFs, iLoader, journalFilePathInIni, journaldrive); |
|
700 CleanupStack::PopAndDestroy(journalFile); |
|
701 ); |
|
702 if(err!=KErrNone) |
|
703 { |
|
704 ERR_PRINTF2(_L("<font color=red>CJournalFile::NewL() returned incorrect error code. KErrNone is expected and %d is returned!</font>"), err); |
|
705 SetTestStepResult(EFail); |
|
706 } |
|
707 |
|
708 seekPosition=sizeof(TInt32)+1+targetFileNamePtr.Length()+sizeof(TInt32)+1; |
|
709 SeekInJournalFileL(ESeekStart, seekPosition); |
|
710 intValue = ReadIntFromJournalFileL(Mode8Bit); //read second file's drive letter (backup file name) |
|
711 intValue.int8++; //corrupt drive letter (ie: 'c' ==> 'd') |
|
712 SeekInJournalFileL(ESeekStart, seekPosition); |
|
713 WriteIntToJournalFileL(intValue, Mode8Bit); //write corrupt drive letter to file |
|
714 |
|
715 |
|
716 //check that CJournalFile recognizes corruption |
|
717 journalFile=0; |
|
718 TRAP(err, |
|
719 journalFile = CJournalFile::NewLC(iFs, iLoader, journalFilePathInIni, journaldrive); |
|
720 CleanupStack::PopAndDestroy(journalFile); |
|
721 ); |
|
722 if(err!=KErrCorrupt) |
|
723 { |
|
724 ERR_PRINTF2(_L("<font color=red>CJournalFile::NewL() returned incorrect error code. KErrCorrupt is expected and %d is returned!</font>"), err); |
|
725 SetTestStepResult(EFail); |
|
726 } |
|
727 |
|
728 intValue.int8--; //restore original drive letter |
|
729 SeekInJournalFileL(ESeekStart, seekPosition); |
|
730 WriteIntToJournalFileL(intValue, Mode8Bit); //write original drive letter to file |
|
731 |
|
732 //check that journal file is not corrupted |
|
733 journalFile=0; |
|
734 TRAP(err, |
|
735 journalFile = CJournalFile::NewLC(iFs, iLoader, journalFilePathInIni, journaldrive); |
|
736 CleanupStack::PopAndDestroy(journalFile); |
|
737 ); |
|
738 if(err!=KErrNone) |
|
739 { |
|
740 ERR_PRINTF2(_L("<font color=red>CJournalFile::NewL() returned incorrect error code. KErrNone is expected and %d is returned!</font>"), err); |
|
741 SetTestStepResult(EFail); |
|
742 } |
|
743 CloseJournalFile(); |
|
744 INFO_PRINTF1(_L("Deleting journal file - Line 769")); |
|
745 DeleteFileL(journalFilePathInIni); |
|
746 |
|
747 |
|
748 CreateJournalFileL(journalFilePathInIni, TFileMode(TFileMode(EFileWrite) | TFileMode(EFileShareExclusive))); |
|
749 journalFile=0; |
|
750 TRAP(err, |
|
751 journalFile = CJournalFile::NewLC(iFs, iLoader, journalFilePathInIni, journaldrive); |
|
752 CleanupStack::PopAndDestroy(journalFile); |
|
753 ); |
|
754 if(err!=KErrInUse ) |
|
755 { |
|
756 ERR_PRINTF2(_L("<font color=red>CJournalFile::NewL() returned incorrect error code. KErrInUse is expected and %d is returned!</font>"), err); |
|
757 SetTestStepResult(EFail); |
|
758 } |
|
759 CloseJournalFile(); |
|
760 INFO_PRINTF1(_L("Deleting journal file - Line 783")); |
|
761 DeleteFileL(journalFilePathInIni); |
|
762 |
|
763 CleanupStack::PopAndDestroy(2, targetFileName); |
|
764 } |
|
765 |
|
766 void CJournalFileUnitTest::ImplTestStepPostambleL() |
|
767 /** |
|
768 @return - void code |
|
769 Override of base class virtual |
|
770 */ |
|
771 { |
|
772 INFO_PRINTF1(_L("JournalFileUnitTest Postamble")); |
|
773 delete testJournalFile; |
|
774 testJournalFile=0; |
|
775 iFs.Close(); |
|
776 iLoader.Close(); |
|
777 } |
|
778 |
|
779 void CJournalFileUnitTest::OpenJournalFileL(const TDesC& aFileName, TFileMode aMode) |
|
780 { |
|
781 testJournalFile->OpenJournalFileL(aFileName, aMode); |
|
782 } |
|
783 |
|
784 void CJournalFileUnitTest::CreateJournalFileL(const TDesC& aFileName, TFileMode aMode) |
|
785 { |
|
786 testJournalFile->CreateJournalFileL(aFileName, aMode); |
|
787 } |
|
788 |
|
789 void CJournalFileUnitTest::SeekInJournalFileL(TSeek aSeekMode, TInt &aPos) |
|
790 { |
|
791 testJournalFile->SeekInJournalFileL(aSeekMode, aPos); |
|
792 } |
|
793 |
|
794 TIntValue CJournalFileUnitTest::ReadIntFromJournalFileL(TIntMode mode) |
|
795 { |
|
796 return testJournalFile->ReadIntFromJournalFileL(mode); |
|
797 } |
|
798 |
|
799 void CJournalFileUnitTest::CloseJournalFile() |
|
800 { |
|
801 testJournalFile->CloseJournalFile(); |
|
802 } |
|
803 |
|
804 void CJournalFileUnitTest::WriteIntToJournalFileL(TIntValue value, TIntMode mode) |
|
805 { |
|
806 testJournalFile->WriteIntToJournalFileL(value, mode); |
|
807 } |
|
808 |
|
809 |
|
810 |
|
811 /*static*/ CTestFile* CTestFile::NewL(RFs& aFs) |
|
812 { |
|
813 CTestFile* self = new(ELeave) CTestFile(aFs); |
|
814 return self; |
|
815 } |
|
816 |
|
817 CTestFile::CTestFile(RFs& aFs): iFs(aFs) |
|
818 { |
|
819 |
|
820 } |
|
821 |
|
822 CTestFile::~CTestFile() |
|
823 { |
|
824 CloseJournalFile(); |
|
825 } |
|
826 |
|
827 void CTestFile::OpenJournalFileL(const TDesC& aFileName, TFileMode aMode) |
|
828 { |
|
829 TInt err = journalFile.Open(iFs, aFileName, aMode); |
|
830 User::LeaveIfError(err); |
|
831 } |
|
832 |
|
833 void CTestFile::CreateJournalFileL(const TDesC& aFileName, TFileMode aMode) |
|
834 { |
|
835 TInt err = iFs.MkDirAll(aFileName); |
|
836 if(err != KErrNone && err != KErrAlreadyExists) |
|
837 { |
|
838 User::Leave(err); |
|
839 } |
|
840 err = journalFile.Create(iFs, aFileName, aMode); |
|
841 User::LeaveIfError(err); |
|
842 } |
|
843 |
|
844 void CTestFile::CloseJournalFile() |
|
845 { |
|
846 journalFile.Close(); |
|
847 } |
|
848 |
|
849 void CTestFile::WriteIntToJournalFileL(TIntValue value, TIntMode mode) |
|
850 { |
|
851 HBufC8* fileIOBuffer = HBufC8::NewLC(10); |
|
852 TPtr8 fileIOBufferPtr(fileIOBuffer->Des()); |
|
853 TPckgC<TInt32> pckg(value.int32); |
|
854 |
|
855 switch(mode) |
|
856 { |
|
857 case Mode8Bit: |
|
858 case Mode16Bit: |
|
859 case Mode32Bit: |
|
860 fileIOBufferPtr.Append(pckg); |
|
861 User::LeaveIfError(journalFile.Write(fileIOBufferPtr, static_cast<TInt>(mode))); |
|
862 break; |
|
863 default: |
|
864 User::Leave(KErrArgument); |
|
865 break; |
|
866 } |
|
867 |
|
868 CleanupStack::PopAndDestroy(fileIOBuffer); |
|
869 } |
|
870 |
|
871 TIntValue CTestFile::ReadIntFromJournalFileL(TIntMode mode) |
|
872 { |
|
873 HBufC8* fileIOBuffer = HBufC8::NewLC(10); |
|
874 TPtr8 fileIOBufferPtr(fileIOBuffer->Des()); |
|
875 User::LeaveIfError(journalFile.Read(fileIOBufferPtr, static_cast<TInt>(mode))); |
|
876 TIntValue ret = {0}; |
|
877 |
|
878 switch(mode) |
|
879 { |
|
880 case Mode8Bit: |
|
881 case Mode16Bit: |
|
882 case Mode32Bit: |
|
883 { |
|
884 for(TInt i=0; i<static_cast<TInt>(mode); ++i) |
|
885 { |
|
886 ret.int32 |= TInt32((*fileIOBuffer)[i]) << (8*i); |
|
887 } |
|
888 break; |
|
889 } |
|
890 default: |
|
891 User::Leave(KErrArgument); |
|
892 break; |
|
893 } |
|
894 CleanupStack::PopAndDestroy(fileIOBuffer); |
|
895 return ret; |
|
896 } |
|
897 |
|
898 void CTestFile::SeekInJournalFileL(TSeek aSeekMode, TInt &aPos) |
|
899 { |
|
900 User::LeaveIfError(journalFile.Seek(aSeekMode, aPos)); |
|
901 } |
|
902 |
|
903 |
|
904 |
|
905 //------------------------------------------------------------------------------------------------------------ |
|
906 |
|
907 CJournalFileUnitTestScenarioBase::CJournalFileUnitTestScenarioBase(CStsTestServer &aStsTestServer): CStsBaseTestStep(aStsTestServer), iCleanupNeeded(ETrue) |
|
908 { |
|
909 } |
|
910 |
|
911 CJournalFileUnitTestScenarioBase::~CJournalFileUnitTestScenarioBase() |
|
912 { |
|
913 iFs.Close(); |
|
914 iLoader.Close(); |
|
915 delete iTargetFileName; |
|
916 delete iBackupFileName; |
|
917 } |
|
918 |
|
919 |
|
920 void CJournalFileUnitTestScenarioBase::ImplTestStepPreambleL() |
|
921 { |
|
922 INFO_PRINTF1(_L("CJournalFileUnitTestScenarioBase Preamble")); |
|
923 iJournalFileName.Set(GetTargetFilePathFromConfigL()); |
|
924 User::LeaveIfError(iFs.Connect()); |
|
925 User::LeaveIfError(iLoader.Connect()); |
|
926 iTargetFileName = HBufC::NewL(KMaxFileName); |
|
927 iBackupFileName = HBufC::NewL(KMaxFileName); |
|
928 TParsePtrC journalFilePathParse(iJournalFileName); |
|
929 TPtr ptr(iTargetFileName->Des()); |
|
930 ptr.Append(journalFilePathParse.DriveAndPath()); |
|
931 ptr.Append(_L("journalfile_oom_test_dummyfile.txt")); |
|
932 iJournaldrive = journalFilePathParse.Drive(); |
|
933 SetTestStepResult(EPass); |
|
934 |
|
935 } |
|
936 |
|
937 void CJournalFileUnitTestScenarioBase::ImplTestStepL() |
|
938 { |
|
939 CleanupStack::PushL(TCleanupItem(&CJournalFileUnitTestScenarioBase::InTestCleanup, this)); |
|
940 ImplTestCaseScenarioL(); |
|
941 CleanupStack::PopAndDestroy(this); |
|
942 } |
|
943 |
|
944 void CJournalFileUnitTestScenarioBase::ImplTestStepPostambleL() |
|
945 { |
|
946 INFO_PRINTF1(_L("CJournalFileUnitTestScenarioBase Postamble")); |
|
947 |
|
948 delete iTargetFileName; |
|
949 iTargetFileName=0; |
|
950 delete iBackupFileName; |
|
951 iBackupFileName=0; |
|
952 iFs.Close(); |
|
953 iLoader.Close(); |
|
954 TRAP_IGNORE(DeleteFileL(iJournalFileName)); |
|
955 } |
|
956 |
|
957 /*static*/void CJournalFileUnitTestScenarioBase::InTestCleanup(TAny* aObject) |
|
958 { |
|
959 CJournalFileUnitTestScenarioBase* object=static_cast<CJournalFileUnitTestScenarioBase*>(aObject); |
|
960 object->INFO_PRINTF1(_L("CJournalFileUnitTestScenarioBase::InTestCleanup()")); |
|
961 if(object->iCleanupNeeded) |
|
962 { |
|
963 TRAP_IGNORE(object->DeleteFileL(object->iJournalFileName)); |
|
964 } |
|
965 } |
|
966 |
|
967 //------------------------------------------------------------------------------------------------------------ |
|
968 CJournalFileUnitTestAdd::CJournalFileUnitTestAdd(CStsTestServer &aStsTestServer): CJournalFileUnitTestScenarioBase(aStsTestServer) |
|
969 { |
|
970 SetTestStepName(KJournalFileUnitTestAdd); |
|
971 } |
|
972 void CJournalFileUnitTestAdd::ImplTestCaseScenarioL() |
|
973 { |
|
974 INFO_PRINTF1(_L("CJournalFileUnitTestAdd in test step")); |
|
975 CJournalFile* journalFile = CJournalFile::NewLC(iFs, iLoader, iJournalFileName, iJournaldrive); |
|
976 journalFile->AddL(*iTargetFileName); |
|
977 CleanupStack::PopAndDestroy(journalFile); |
|
978 } |
|
979 //------------------------------------------------------------------------------------------------------------ |
|
980 CJournalFileUnitTestTemp::CJournalFileUnitTestTemp(CStsTestServer &aStsTestServer): CJournalFileUnitTestScenarioBase(aStsTestServer) |
|
981 { |
|
982 SetTestStepName(KJournalFileUnitTestTemp); |
|
983 } |
|
984 |
|
985 void CJournalFileUnitTestTemp::ImplTestCaseScenarioL() |
|
986 { |
|
987 INFO_PRINTF1(_L("CJournalFileUnitTestTemp in test step")); |
|
988 CJournalFile* journalFile = CJournalFile::NewLC(iFs, iLoader, iJournalFileName, iJournaldrive); |
|
989 journalFile->TemporaryL(*iTargetFileName); |
|
990 CleanupStack::PopAndDestroy(journalFile); |
|
991 } |
|
992 |
|
993 //------------------------------------------------------------------------------------------------------------ |
|
994 CJournalFileUnitTestRemove::CJournalFileUnitTestRemove(CStsTestServer &aStsTestServer): CJournalFileUnitTestScenarioBase(aStsTestServer) |
|
995 { |
|
996 SetTestStepName(KJournalFileUnitTestRemove); |
|
997 } |
|
998 |
|
999 void CJournalFileUnitTestRemove::ImplTestCaseScenarioL() |
|
1000 { |
|
1001 INFO_PRINTF1(_L("CJournalFileUnitTestRemove in test step")); |
|
1002 TPtr backupFileNamePtr(iBackupFileName->Des()); |
|
1003 CJournalFile* journalFile = CJournalFile::NewLC(iFs, iLoader, iJournalFileName, iJournaldrive); |
|
1004 journalFile->RemoveL(*iTargetFileName, backupFileNamePtr); |
|
1005 CleanupStack::PopAndDestroy(journalFile); |
|
1006 } |
|
1007 //------------------------------------------------------------------------------------------------------------ |
|
1008 CJournalFileUnitTestRead::CJournalFileUnitTestRead(CStsTestServer &aStsTestServer): CJournalFileUnitTestScenarioBase(aStsTestServer) |
|
1009 { |
|
1010 iCleanupNeeded=EFalse; |
|
1011 SetTestStepName(KJournalFileUnitTestRead); |
|
1012 } |
|
1013 |
|
1014 void CJournalFileUnitTestRead::ImplTestCaseScenarioL() |
|
1015 { |
|
1016 INFO_PRINTF1(_L("CJournalFileUnitTestRead in test step")); |
|
1017 CJournalFile* journalFile = CJournalFile::NewLC(iFs, iLoader, iJournalFileName, iJournaldrive); |
|
1018 CleanupStack::PopAndDestroy(journalFile); |
|
1019 } |
|
1020 //------------------------------------------------------------------------------------------------------------ |
|
1021 CJournalFileUnitTestEvent::CJournalFileUnitTestEvent(CStsTestServer &aStsTestServer): CJournalFileUnitTestScenarioBase(aStsTestServer) |
|
1022 { |
|
1023 } |
|
1024 |
|
1025 void CJournalFileUnitTestEvent::ImplTestCaseScenarioL() |
|
1026 { |
|
1027 INFO_PRINTF1(_L("CJournalFileUnitTestEvent in test step")); |
|
1028 CJournalFile* journalFile = CJournalFile::NewLC(iFs, iLoader, iJournalFileName, iJournaldrive); |
|
1029 journalFile->EventL(ECommitted); |
|
1030 CleanupStack::PopAndDestroy(journalFile); |
|
1031 } |
|
1032 //------------------------------------------------------------------------------------------------------------ |
|
1033 |
|
1034 //------------------------------------------------------------------------------------------------------------ |
|
1035 CJournalUnitTest::CJournalUnitTest(CStsTestServer &aStsTestServer): CStsBaseTestStep(aStsTestServer) |
|
1036 { |
|
1037 // Call base class method to set up the human readable name for logging |
|
1038 SetTestStepName(KJournalUnitTest); |
|
1039 } |
|
1040 |
|
1041 CJournalUnitTest::~CJournalUnitTest() |
|
1042 { |
|
1043 delete iTestFileInterface; |
|
1044 iFs.Close(); |
|
1045 iLoader.Close(); |
|
1046 } |
|
1047 |
|
1048 void CJournalUnitTest::ImplTestStepPreambleL() |
|
1049 { |
|
1050 INFO_PRINTF1(_L("JournalFileUnitTest Preamble")); |
|
1051 iJournalPathInIni.Set(GetTargetFilePathFromConfigL()); |
|
1052 iTrID = GetTransactionIdFromConfigL(); |
|
1053 User::LeaveIfError(iFs.Connect()); |
|
1054 User::LeaveIfError(iLoader.Connect()); |
|
1055 iTestFileInterface = CTestFile::NewL(iFs); |
|
1056 SetTestStepResult(EPass); |
|
1057 |
|
1058 } |
|
1059 |
|
1060 void CJournalUnitTest::ImplTestStepL() |
|
1061 { |
|
1062 INFO_PRINTF1(_L("JournalUnitTest in test step")); |
|
1063 SetTestStepResult(EPass); |
|
1064 TestCase1L(); |
|
1065 } |
|
1066 |
|
1067 void CJournalUnitTest::ImplTestStepPostambleL() |
|
1068 { |
|
1069 INFO_PRINTF1(_L("JournalFileUnitTest Postamble")); |
|
1070 delete iTestFileInterface; |
|
1071 iTestFileInterface=0; |
|
1072 iFs.Close(); |
|
1073 iLoader.Close(); |
|
1074 } |
|
1075 |
|
1076 void CJournalUnitTest::TestCase1L() |
|
1077 { |
|
1078 INFO_PRINTF1(_L("JournalFileUnitTest Test Case1")); |
|
1079 |
|
1080 //------------------------------------------------------------------------------------- |
|
1081 //Steps: |
|
1082 // 1.) create a corrupt journal file on C drive (by writing invalid event into the file /eg: with a value of EAddedFile+1000/) |
|
1083 // 2.) Create a journal |
|
1084 // 3.) Add a file to the journal on C drive by invoking CJounral::AddL() |
|
1085 // 4.) this will create a new journal file object representing journal activity on drive C, however due to the corrupt file being already on the C drive CJournalFile::NewLC will throw KErrCorrupt |
|
1086 // 5.) expect KErrCorrupt |
|
1087 // note: the purpose of this testcase to excersise the conditional branches in CJournal::PrepareToWriteL |
|
1088 //------------------------------------------------------------------------------------- |
|
1089 |
|
1090 TInt err=0; |
|
1091 TDriveUnit driveUnitC(KDriveLetterC); |
|
1092 TDriveUnit driveUnitE(KDriveLetterE); |
|
1093 |
|
1094 |
|
1095 HBufC* journalFileName = HBufC::NewLC(KMaxFileName); |
|
1096 HBufC* targetFileName = HBufC::NewLC(KMaxFileName); |
|
1097 |
|
1098 TPtr journalFileNamePtr(journalFileName->Des()); |
|
1099 journalFileNamePtr.Append(driveUnitC.Name()); |
|
1100 CJournal::CreateJournalFileNameL(iTrID, iJournalPathInIni, journalFileNamePtr); |
|
1101 |
|
1102 //create file path base (eg: drive:\path\) |
|
1103 TPtr targetFileNameBasePtr(targetFileName->Des()); |
|
1104 targetFileNameBasePtr.Append(driveUnitC.Name()); |
|
1105 targetFileNameBasePtr.Append(iJournalPathInIni); |
|
1106 |
|
1107 //open up the file via the test file interface (for writing corrupt data) |
|
1108 iTestFileInterface->CreateJournalFileL(journalFileNamePtr, defaultJournalFileMode); |
|
1109 TInt seekPosition=0; |
|
1110 TIntValue intValue = {0}; |
|
1111 intValue.int32=static_cast<TInt32>(EAddedFile)+1000; //corrupt data in file (eg: write operation value to an invalid value) |
|
1112 //corrupt data in journal file |
|
1113 iTestFileInterface->SeekInJournalFileL(ESeekStart, seekPosition); |
|
1114 iTestFileInterface->WriteIntToJournalFileL(intValue, Mode32Bit); |
|
1115 iTestFileInterface->CloseJournalFile(); |
|
1116 |
|
1117 TPtr targetFileNamePtr(targetFileNameBasePtr); |
|
1118 targetFileNamePtr.Append(_L("dummyadd.txt")); |
|
1119 |
|
1120 //create a journal and add a file on C drive: that will force CJournalFile to read in and process the |
|
1121 //previously created corrupt file. As the file contains corrupt information CJournalFile construction is expected to fail with KErrCorrupt |
|
1122 CJournal* journal = CJournal::NewLC(iFs, iLoader, iTrID, iJournalPathInIni); |
|
1123 TRAP(err, journal->AddL(targetFileNamePtr)); |
|
1124 if(err!=KErrCorrupt) |
|
1125 { |
|
1126 ERR_PRINTF2(_L("<font color=red>CJournal::AddL() returned incorrect error code. KErrCorrupt is expected and %d is returned!</font>"), err); |
|
1127 SetTestStepResult(EFail); |
|
1128 } |
|
1129 CleanupStack::PopAndDestroy(journal); journal=0; |
|
1130 |
|
1131 //clean up: delete created journal file and drive file (.drv) |
|
1132 DeleteFileL(*journalFileName); |
|
1133 //reuse targetFileName buffer to create .drv filename to delete that file |
|
1134 *targetFileName=KEmptyString; |
|
1135 targetFileNamePtr.Set(targetFileName->Des()); |
|
1136 CJournal::CreateDrvFileNameL(iTrID, iJournalPathInIni, targetFileNamePtr); |
|
1137 TRAP_IGNORE(DeleteFileL(targetFileNamePtr)); //clean up .drv file in case it's been created but avoid causing leave in case it hasn't |
|
1138 |
|
1139 CleanupStack::PopAndDestroy(targetFileName); |
|
1140 CleanupStack::PopAndDestroy(journalFileName); |
|
1141 } |
|
1142 |
|
1143 //------------------------------------------------------------------------------------------------------------ |
|
1144 |
|
1145 |
|
1146 CJournalUnitTestScenarioBase::CJournalUnitTestScenarioBase(CStsTestServer &aStsTestServer): CStsBaseTestStep(aStsTestServer) |
|
1147 { |
|
1148 iDriveUnitC = _L("c"); |
|
1149 iDriveUnitE = _L("e"); |
|
1150 } |
|
1151 |
|
1152 CJournalUnitTestScenarioBase::~CJournalUnitTestScenarioBase() |
|
1153 { |
|
1154 iFs.Close(); |
|
1155 iLoader.Close(); |
|
1156 delete iTargetFileName; |
|
1157 delete iJournalFileName; |
|
1158 delete iDrvFileName; |
|
1159 delete iBackupFileName; |
|
1160 } |
|
1161 |
|
1162 void CJournalUnitTestScenarioBase::ImplTestStepPreambleL() |
|
1163 { |
|
1164 INFO_PRINTF1(_L("CJournalUnitTestScenarioBase::ImplTestStepPreambleL()")); |
|
1165 iJournalPathInIni.Set(GetTargetFilePathFromConfigL()); |
|
1166 iTrID = GetTransactionIdFromConfigL(); |
|
1167 User::LeaveIfError(iFs.Connect()); |
|
1168 User::LeaveIfError(iLoader.Connect()); |
|
1169 iTargetFileName = HBufC::NewL(KMaxFileName); |
|
1170 iJournalFileName = HBufC::NewL(KMaxFileName); |
|
1171 iDrvFileName = HBufC::NewL(KMaxFileName); |
|
1172 iBackupFileName = HBufC::NewL(KMaxFileName); |
|
1173 |
|
1174 TPtr ptr(iJournalFileName->Des()); |
|
1175 ptr.Append(iDriveUnitC.Name()); |
|
1176 ptr.Append(iJournalPathInIni); |
|
1177 ptr.AppendNumUC(iTrID, EHex); |
|
1178 ptr.Append(KKournalFileExt); |
|
1179 |
|
1180 ptr.Set(iTargetFileName->Des()); |
|
1181 ptr.Append(iDriveUnitC.Name()); |
|
1182 ptr.Append(iJournalPathInIni); |
|
1183 |
|
1184 ptr.Set(iDrvFileName->Des()); |
|
1185 CJournal::CreateDrvFileNameL(iTrID, iJournalPathInIni, ptr); |
|
1186 |
|
1187 SetTestStepResult(EPass); |
|
1188 } |
|
1189 |
|
1190 void CJournalUnitTestScenarioBase::ImplTestStepL() |
|
1191 { |
|
1192 INFO_PRINTF1(_L("CJournalUnitTestScenarioBase::ImplTestStepL()")); |
|
1193 |
|
1194 TPtr basePathPtr(iTargetFileName->Des()); |
|
1195 TPtr fileNamePtr(basePathPtr); |
|
1196 TCleanupItem inTestCleanupItem(&CJournalUnitTestScenarioBase::InTestCleanUp, this); |
|
1197 CleanupStack::PushL(inTestCleanupItem); |
|
1198 |
|
1199 CJournal* journal = CJournal::NewLC(iFs, iLoader, iTrID, iJournalPathInIni); |
|
1200 |
|
1201 *iBackupFileName=KEmptyString; |
|
1202 TPtr backupFileNamePtr(iBackupFileName->Des()); |
|
1203 fileNamePtr.Set(basePathPtr); |
|
1204 fileNamePtr.Append(_L("journal_oom_test_dummyremovefile.txt")); |
|
1205 basePathPtr.Replace(0, 2, iDriveUnitC.Name()); |
|
1206 journal->RemoveL(fileNamePtr, backupFileNamePtr); |
|
1207 *iBackupFileName=KEmptyString; |
|
1208 backupFileNamePtr.Set(iBackupFileName->Des()); |
|
1209 basePathPtr.Replace(0, 2, iDriveUnitE.Name()); |
|
1210 journal->RemoveL(fileNamePtr, backupFileNamePtr); |
|
1211 |
|
1212 |
|
1213 fileNamePtr.Set(basePathPtr); |
|
1214 fileNamePtr.Append(_L("journal_oom_test_dummytempfile.txt")); |
|
1215 basePathPtr.Replace(0, 2, iDriveUnitC.Name()); |
|
1216 journal->TemporaryL(fileNamePtr); |
|
1217 basePathPtr.Replace(0, 2, iDriveUnitE.Name()); |
|
1218 journal->TemporaryL(fileNamePtr); |
|
1219 |
|
1220 |
|
1221 fileNamePtr.Set(basePathPtr); |
|
1222 fileNamePtr.Append(_L("journal_oom_test_dummyaddfile.txt")); |
|
1223 basePathPtr.Replace(0, 2, iDriveUnitC.Name()); |
|
1224 journal->AddL(fileNamePtr); |
|
1225 basePathPtr.Replace(0, 2, iDriveUnitE.Name()); |
|
1226 journal->AddL(fileNamePtr); |
|
1227 |
|
1228 ScenarioEndL(journal); |
|
1229 CleanupStack::PopAndDestroy(journal); |
|
1230 CleanupStack::PopAndDestroy(this); |
|
1231 } |
|
1232 |
|
1233 void CJournalUnitTestScenarioBase::ImplTestStepPostambleL() |
|
1234 { |
|
1235 INFO_PRINTF1(_L("CJournalUnitTestScenarioBase::ImplTestStepPostambleL()")); |
|
1236 delete iTargetFileName; |
|
1237 iTargetFileName=0; |
|
1238 delete iJournalFileName; |
|
1239 iJournalFileName=0; |
|
1240 delete iDrvFileName; |
|
1241 iDrvFileName=0; |
|
1242 delete iBackupFileName; |
|
1243 iBackupFileName=0; |
|
1244 iFs.Close(); |
|
1245 iLoader.Close(); |
|
1246 } |
|
1247 |
|
1248 /*static*/ void CJournalUnitTestScenarioBase::InTestCleanUp(TAny* aObject) |
|
1249 { |
|
1250 CJournalUnitTestScenarioBase* object=static_cast<CJournalUnitTestScenarioBase*>(aObject); |
|
1251 object->INFO_PRINTF1(_L("CJournalUnitTestScenarioBase::InTestCleanUp()")); |
|
1252 |
|
1253 TPtr ptr(object->iJournalFileName->Des()); |
|
1254 ptr.Replace(0, 2, object->iDriveUnitC.Name()); |
|
1255 TRAP_IGNORE(object->DeleteFileL(ptr)); //delete journal file on C drive |
|
1256 ptr.Replace(0, 2, object->iDriveUnitE.Name()); |
|
1257 TRAP_IGNORE(object->DeleteFileL(ptr)); //delete journal file on E drive |
|
1258 TRAP_IGNORE(object->DeleteFileL(*(object->iDrvFileName))); //delete drv file on system drive |
|
1259 } |
|
1260 |
|
1261 //------------------------------------------------------------------------------------------------------------ |
|
1262 |
|
1263 CJournalUnitTestInstall::CJournalUnitTestInstall(CStsTestServer &aStsTestServer): CJournalUnitTestScenarioBase(aStsTestServer) |
|
1264 { |
|
1265 // Call base class method to set up the human readable name for logging |
|
1266 SetTestStepName(KJournalUnitTestInstall); |
|
1267 } |
|
1268 |
|
1269 void CJournalUnitTestInstall::ScenarioEndL(CJournal* aJournal) |
|
1270 { |
|
1271 aJournal->CommitL(); |
|
1272 } |
|
1273 |
|
1274 //------------------------------------------------------------------------------------------------------------ |
|
1275 |
|
1276 CJournalUnitTestRollback::CJournalUnitTestRollback(CStsTestServer &aStsTestServer): CJournalUnitTestScenarioBase(aStsTestServer) |
|
1277 { |
|
1278 // Call base class method to set up the human readable name for logging |
|
1279 SetTestStepName(KJournalUnitTestRollback); |
|
1280 } |
|
1281 |
|
1282 void CJournalUnitTestRollback::ScenarioEndL(CJournal* aJournal) |
|
1283 { |
|
1284 aJournal->RollBackL(); |
|
1285 } |
|
1286 |
|
1287 //------------------------------------------------------------------------------------------------------------ |
|
1288 |
|
1289 |
|
1290 CIntegrityServicesTestScenarioBase::CIntegrityServicesTestScenarioBase(CStsTestServer &aStsTestServer): CStsBaseTestStep(aStsTestServer) |
|
1291 { |
|
1292 iDriveUnitC = _L("c"); |
|
1293 iDriveUnitE = _L("e"); |
|
1294 } |
|
1295 |
|
1296 CIntegrityServicesTestScenarioBase::~CIntegrityServicesTestScenarioBase() |
|
1297 { |
|
1298 iFs.Close(); |
|
1299 iLoader.Close(); |
|
1300 delete iTargetFileName; |
|
1301 delete iJournalFileName; |
|
1302 delete iDrvFileName; |
|
1303 delete iBackupFileName; |
|
1304 delete iTransactionBackupDirectoryPath; |
|
1305 } |
|
1306 |
|
1307 void CIntegrityServicesTestScenarioBase::ImplTestStepPreambleL() |
|
1308 { |
|
1309 INFO_PRINTF1(_L("IntegrityServicesTestOOM Preamble")); |
|
1310 iTargetPathInIni.Set(GetTargetFilePathFromConfigL()); |
|
1311 iTrID = GetTransactionIdFromConfigL(); |
|
1312 User::LeaveIfError(iFs.Connect()); |
|
1313 User::LeaveIfError(iLoader.Connect()); |
|
1314 iTargetFileName = HBufC::NewL(KMaxFileName); |
|
1315 iJournalFileName = HBufC::NewL(KMaxFileName); |
|
1316 iDrvFileName = HBufC::NewL(KMaxFileName); |
|
1317 iBackupFileName = HBufC::NewL(KMaxFileName); |
|
1318 iTransactionBackupDirectoryPath = HBufC::NewL(KMaxFileName); |
|
1319 |
|
1320 TPtr ptr(iJournalFileName->Des()); |
|
1321 ptr.Append(iDriveUnitC.Name()); |
|
1322 CJournal::CreateJournalFileNameL(iTrID, KTransactionPath, ptr); |
|
1323 |
|
1324 ptr.Set(iDrvFileName->Des()); |
|
1325 CJournal::CreateDrvFileNameL(iTrID, KTransactionPath, ptr); |
|
1326 |
|
1327 TParsePtrC parse(*iDrvFileName); |
|
1328 ptr.Set(iTransactionBackupDirectoryPath->Des()); //this is the directory that holds the backup files for the transaction |
|
1329 ptr.Append(parse.DriveAndPath()); |
|
1330 ptr.Append(parse.Name()); |
|
1331 |
|
1332 ptr.Set(iTargetFileName->Des()); |
|
1333 ptr.Append(iDriveUnitC.Name()); |
|
1334 ptr.Append(iTargetPathInIni); |
|
1335 NormalizeDirectoryName(ptr); //removes trailing slash |
|
1336 |
|
1337 SetTestStepResult(EPass); |
|
1338 } |
|
1339 |
|
1340 void CIntegrityServicesTestScenarioBase::ImplTestStepL() |
|
1341 { |
|
1342 TPtr basePathPtr(iTargetFileName->Des()); |
|
1343 TPtr fileNamePtr(basePathPtr); |
|
1344 RFile newFile; |
|
1345 TUint fileMode(EFileShareExclusive | EFileWrite); |
|
1346 |
|
1347 TCleanupItem inTestCleanupItem(&CIntegrityServicesTestScenarioBase::InTestCleanUp, this); |
|
1348 CleanupStack::PushL(inTestCleanupItem); |
|
1349 |
|
1350 CIntegrityServices* integrityServices = CIntegrityServices::NewLC(iTrID); |
|
1351 |
|
1352 fileNamePtr.Set(basePathPtr); |
|
1353 fileNamePtr.Append(_L("\\integrityservices_oom_test_dummyremovefile.txt")); |
|
1354 basePathPtr.Replace(0, 2, iDriveUnitC.Name()); |
|
1355 integrityServices->RemoveL(fileNamePtr); |
|
1356 basePathPtr.Replace(0, 2, iDriveUnitE.Name()); |
|
1357 integrityServices->RemoveL(fileNamePtr); |
|
1358 |
|
1359 fileNamePtr.Set(basePathPtr); |
|
1360 fileNamePtr.Append(_L("\\integrityservices_oom_test_dummyregistertempfile.txt")); |
|
1361 basePathPtr.Replace(0, 2, iDriveUnitC.Name()); |
|
1362 integrityServices->RegisterTemporaryL(fileNamePtr); |
|
1363 basePathPtr.Replace(0, 2, iDriveUnitE.Name()); |
|
1364 integrityServices->RegisterTemporaryL(fileNamePtr); |
|
1365 |
|
1366 fileNamePtr.Set(basePathPtr); |
|
1367 fileNamePtr.Append(_L("\\integrityservices_oom_test_dummycreatetempfile.txt")); |
|
1368 basePathPtr.Replace(0, 2, iDriveUnitC.Name()); |
|
1369 CleanupClosePushL(newFile); |
|
1370 integrityServices->CreateTemporaryL(fileNamePtr, newFile, fileMode); |
|
1371 CleanupStack::PopAndDestroy(&newFile); |
|
1372 basePathPtr.Replace(0, 2, iDriveUnitE.Name()); |
|
1373 CleanupClosePushL(newFile); |
|
1374 integrityServices->CreateTemporaryL(fileNamePtr, newFile, fileMode); |
|
1375 CleanupStack::PopAndDestroy(&newFile); |
|
1376 |
|
1377 fileNamePtr.Set(basePathPtr); |
|
1378 fileNamePtr.Append(_L("\\integrityservices_oom_test_dummyaddfile.txt")); |
|
1379 basePathPtr.Replace(0, 2, iDriveUnitC.Name()); |
|
1380 integrityServices->RegisterNewL(fileNamePtr); |
|
1381 basePathPtr.Replace(0, 2, iDriveUnitE.Name()); |
|
1382 integrityServices->RegisterNewL(fileNamePtr); |
|
1383 |
|
1384 fileNamePtr.Set(basePathPtr); |
|
1385 fileNamePtr.Append(_L("\\integrityservices_oom_test_dummycreatenewfile.txt")); |
|
1386 basePathPtr.Replace(0, 2, iDriveUnitC.Name()); |
|
1387 CleanupClosePushL(newFile); |
|
1388 integrityServices->CreateNewL(fileNamePtr, newFile, fileMode); |
|
1389 CleanupStack::PopAndDestroy(&newFile); |
|
1390 basePathPtr.Replace(0, 2, iDriveUnitE.Name()); |
|
1391 CleanupClosePushL(newFile); |
|
1392 integrityServices->CreateNewL(fileNamePtr, newFile, fileMode); |
|
1393 CleanupStack::PopAndDestroy(&newFile); |
|
1394 |
|
1395 fileNamePtr.Set(basePathPtr); |
|
1396 fileNamePtr.Append(_L("\\integrityservices_oom_test_dummyoverwritefile.txt")); |
|
1397 basePathPtr.Replace(0, 2, iDriveUnitC.Name()); |
|
1398 CleanupClosePushL(newFile); |
|
1399 integrityServices->OverwriteL(fileNamePtr, newFile, fileMode); |
|
1400 CleanupStack::PopAndDestroy(&newFile); |
|
1401 basePathPtr.Replace(0, 2, iDriveUnitE.Name()); |
|
1402 CleanupClosePushL(newFile); |
|
1403 integrityServices->OverwriteL(fileNamePtr, newFile, fileMode); |
|
1404 CleanupStack::PopAndDestroy(&newFile); |
|
1405 |
|
1406 ScenarioEndL(integrityServices); |
|
1407 CleanupStack::PopAndDestroy(integrityServices); |
|
1408 CleanupStack::PopAndDestroy(this); |
|
1409 } |
|
1410 |
|
1411 void CIntegrityServicesTestScenarioBase::ImplTestStepPostambleL() |
|
1412 { |
|
1413 INFO_PRINTF1(_L("IntegrityServicesTestOOM Postamble")); |
|
1414 delete iTargetFileName; |
|
1415 iTargetFileName=0; |
|
1416 delete iJournalFileName; |
|
1417 iJournalFileName=0; |
|
1418 delete iDrvFileName; |
|
1419 iDrvFileName=0; |
|
1420 delete iBackupFileName; |
|
1421 iBackupFileName=0; |
|
1422 delete iTransactionBackupDirectoryPath; |
|
1423 iTransactionBackupDirectoryPath=0; |
|
1424 iFs.Close(); |
|
1425 iLoader.Close(); |
|
1426 } |
|
1427 |
|
1428 /*static*/void CIntegrityServicesTestScenarioBase::InTestCleanUp(TAny* aObject) |
|
1429 { |
|
1430 CIntegrityServicesTestScenarioBase* object=static_cast<CIntegrityServicesTestScenarioBase*>(aObject); |
|
1431 //first clean up transaction related files |
|
1432 TPtr ptr(object->iJournalFileName->Des()); |
|
1433 ptr.Replace(0, 2, object->iDriveUnitC.Name()); |
|
1434 TRAP_IGNORE(object->DeleteFileL(ptr)); //delete journal file on C drive |
|
1435 ptr.Replace(0, 2, object->iDriveUnitE.Name()); |
|
1436 TRAP_IGNORE(object->DeleteFileL(ptr)); //delete journal file on E drive |
|
1437 TRAP_IGNORE(object->DeleteFileL(*(object->iDrvFileName))); //delete drv file on system drive |
|
1438 ptr.Set(object->iTransactionBackupDirectoryPath->Des()); |
|
1439 ptr.Replace(0, 2, object->iDriveUnitC.Name()); |
|
1440 TRAP_IGNORE(object->DeleteFileL(ptr)); //delete backup directory on C drive |
|
1441 ptr.Replace(0, 2, object->iDriveUnitE.Name()); |
|
1442 TRAP_IGNORE(object->DeleteFileL(ptr)); //delete backup directory on E drive |
|
1443 |
|
1444 //then clean up all the added/created/etc... files |
|
1445 ptr.Set(object->iTargetFileName->Des()); |
|
1446 ptr.Replace(0, 2, object->iDriveUnitC.Name()); |
|
1447 TRAP_IGNORE(object->DeleteFileL(ptr)); //delete target dir on C drive |
|
1448 ptr.Replace(0, 2, object->iDriveUnitE.Name()); |
|
1449 TRAP_IGNORE(object->DeleteFileL(ptr)); //delete target dir on E drive |
|
1450 |
|
1451 } |
|
1452 |
|
1453 void CIntegrityServicesTestScenarioBase::NormalizeDirectoryName(TDes& aFileName) |
|
1454 { |
|
1455 TInt lastCharPos = aFileName.Length() - 1; |
|
1456 if ( lastCharPos >= 0 && aFileName[lastCharPos] == KPathDelimiter && |
|
1457 aFileName.Locate(KPathDelimiter) != lastCharPos) // Take care not to remove slash from "c:\" and the like |
|
1458 { |
|
1459 aFileName.Delete(lastCharPos, 1); |
|
1460 } |
|
1461 } |
|
1462 |
|
1463 //------------------------------------------------------------------------------------------------------------ |
|
1464 |
|
1465 CIntegrityServicesTestInstall::CIntegrityServicesTestInstall(CStsTestServer &aStsTestServer): CIntegrityServicesTestScenarioBase(aStsTestServer) |
|
1466 { |
|
1467 // Call base class method to set up the human readable name for logging |
|
1468 SetTestStepName(KIntegrityservicesUnitTestInstall); |
|
1469 } |
|
1470 |
|
1471 void CIntegrityServicesTestInstall::ScenarioEndL(Usif::CIntegrityServices* aIntegrServ) |
|
1472 { |
|
1473 aIntegrServ->CommitL(); |
|
1474 } |
|
1475 |
|
1476 //------------------------------------------------------------------------------------------------------------ |
|
1477 |
|
1478 CIntegrityServicesTestRollback::CIntegrityServicesTestRollback(CStsTestServer &aStsTestServer): CIntegrityServicesTestScenarioBase(aStsTestServer) |
|
1479 { |
|
1480 // Call base class method to set up the human readable name for logging |
|
1481 SetTestStepName(KIntegrityservicesUnitTestRollback); |
|
1482 } |
|
1483 |
|
1484 void CIntegrityServicesTestRollback::ScenarioEndL(Usif::CIntegrityServices* aIntegrServ) |
|
1485 { |
|
1486 aIntegrServ->RollBackL(); |
|
1487 } |