sl@0: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32test\server\t_corruptlog.cpp sl@0: // Includes sl@0: // sl@0: // sl@0: sl@0: //! @file sl@0: //! @SYMTestCaseID FSBASE_corrupt_log sl@0: //! @SYMPREQ 908 sl@0: //! @SYMTestSuites Base tests sl@0: //! @SYMInitialAuthor Bob Jackman sl@0: //! @SYMCreationDate 1/11/04 sl@0: //! @SYMTestCaseDesc Check trap action of CorruptFileNames.lst sl@0: sl@0: #include sl@0: RTest test(_L("t_corruptlog")); sl@0: sl@0: #if defined(_DEBUG) || defined(_DEBUG_RELEASE) sl@0: #include sl@0: #include sl@0: sl@0: // Error every time sl@0: _LIT(KTestFile1,"z:\\system\\data\\BadFile1.txt"); sl@0: const TInt KTestFile1Error1=-6; sl@0: const TInt KTestFile1Error2=KErrNone; sl@0: // sl@0: // Error once sl@0: _LIT(KTestFile2,"z:\\system\\data\\BadFile2.txt"); sl@0: const TInt KTestFile2Error1=-20; sl@0: const TInt KTestFile2Error2=-20; sl@0: sl@0: //////////////////////////////////////////////////////////// sl@0: // Globals sl@0: // sl@0: static RFs TheFs; sl@0: sl@0: static TInt numberOfTraps=0; sl@0: sl@0: //////////////////////////////////////////////////////////// sl@0: sl@0: inline TInt controlIo(RFs &fs, TInt drv, TInt fn) sl@0: { sl@0: TPtr8 pDummy(NULL,0,0); sl@0: TInt r = fs.ControlIo(drv, fn, pDummy); sl@0: return r; sl@0: } sl@0: sl@0: inline TInt controlIo(RFs &fs, TInt drv, TInt fn, TInt &aNumRecs) sl@0: { sl@0: TPtr8 pNum((TUint8*)(&aNumRecs),sizeof(aNumRecs),sizeof(aNumRecs)); sl@0: TInt r = fs.ControlIo(drv, fn, pNum); sl@0: return r; sl@0: } sl@0: sl@0: inline TInt controlIo(RFs &fs, TInt drv, TInt fn, TDes& aFileName) sl@0: { sl@0: TBuf8 fileName8; sl@0: TInt r = fs.ControlIo(drv, fn, fileName8); sl@0: if(r==KErrNone) sl@0: { sl@0: aFileName.Copy(fileName8); sl@0: } sl@0: return r; sl@0: } sl@0: sl@0: sl@0: inline TInt controlIo(RFs &fs, TInt drv, TInt fn, TFsDebugCorruptLogRecordBuf &alogRec, TInt aRecNum) sl@0: { sl@0: TInt r = fs.ControlIo(drv, fn, alogRec, *((TDes8*)aRecNum)); sl@0: return r; sl@0: } sl@0: sl@0: void PrintLogRecord(TFsDebugCorruptLogRecordBuf &alogRec, TInt aRecordNumber) sl@0: { sl@0: test.Printf(_L("#%d Process: %S tried to access %S errorCode=%d\n"),aRecordNumber, sl@0: &(alogRec().iProcessName), sl@0: &(alogRec().iFileName), sl@0: alogRec().iError); sl@0: } sl@0: sl@0: TInt ResetCorruptLogRecords() sl@0: { sl@0: // Allows the test to be run again, by resetting the record to an unused state, sl@0: // and destroying the trap records sl@0: // Enables this test to be ran again. sl@0: TInt r=controlIo(TheFs, EDriveC, KControlIoCorruptLogRecordReset); sl@0: return r; sl@0: } sl@0: sl@0: TInt GetNumberOfTraps() sl@0: { sl@0: // fetchs the number of corrupt file trap records that exist sl@0: // there is a separate record for every attempted access to a nominated file sl@0: // Note that C: is used in the IoControl call, which requires a valid drive, but has no other relevance sl@0: TInt numberOfRecords; sl@0: TInt r=controlIo(TheFs, EDriveC, KControlIoGetNumberOfCorruptLogRecords, numberOfRecords); sl@0: test(r==KErrNone); sl@0: return numberOfRecords; sl@0: } sl@0: sl@0: TInt GetTrapLogRecord(TFsDebugCorruptLogRecordBuf &alogRec, TInt aRecordNumber) sl@0: { sl@0: // fetchs a trap record sl@0: // Note that C: is used in the IoControl call, which requires a valid drive, but has no other relevance sl@0: TInt r=controlIo(TheFs, EDriveC, KControlIoGetCorruptLogRecord, alogRec, aRecordNumber); sl@0: test(r==KErrNone); sl@0: return r; sl@0: } sl@0: sl@0: TInt GetCorruptFileListFile(TDes& aFileName) sl@0: { sl@0: // Retrieves the name of the file containing the list of files, nominated as corrupt, used to generate sl@0: // the corrupt files list. sl@0: // Note that C: is used in the IoControl call, which requires a valid drive, but has no other relevance sl@0: TInt r=controlIo(TheFs, EDriveC, KControlIoGetCorruptListFile, aFileName); sl@0: test(r==KErrNone); sl@0: return r; sl@0: } sl@0: sl@0: void AccessFiles() sl@0: { sl@0: test.Next(_L("Access corrupt files")); sl@0: RFile f; sl@0: const TInt attribs=EFileShareExclusive|EFileStreamText|EFileRead; sl@0: // File1 sl@0: TInt r=f.Open(TheFs,KTestFile1,attribs); sl@0: test(r==KTestFile1Error1); sl@0: f.Close(); sl@0: numberOfTraps+=(r==KErrNone?0:1); sl@0: // try again sl@0: r=f.Open(TheFs,KTestFile1,attribs); sl@0: test(r==KTestFile1Error2); sl@0: f.Close(); sl@0: numberOfTraps+=(r==KErrNone?0:1); sl@0: // File2 sl@0: r=f.Open(TheFs,KTestFile2,attribs); sl@0: test(r==KTestFile2Error1); sl@0: f.Close(); sl@0: numberOfTraps+=(r==KErrNone?0:1); sl@0: // try again sl@0: r=f.Open(TheFs,KTestFile2,attribs); sl@0: test(r==KTestFile2Error2); sl@0: f.Close(); sl@0: numberOfTraps+=(r==KErrNone?0:1); sl@0: } sl@0: sl@0: void DoTests() sl@0: { sl@0: TFileName corruptFileNamesList; sl@0: test.Next(_L("Get name of file with list of nominated files")); sl@0: TInt r=GetCorruptFileListFile(corruptFileNamesList); sl@0: test(r==KErrNone); sl@0: test.Printf(_L("Using %S\n"),&corruptFileNamesList); sl@0: sl@0: AccessFiles(); sl@0: test.Next(_L("Get Number of traps")); sl@0: TInt nRecs=GetNumberOfTraps(); sl@0: test.Next(_L("Test Number of traps")); sl@0: test(nRecs==numberOfTraps); sl@0: sl@0: TFsDebugCorruptLogRecordBuf logRec; sl@0: for (TInt i=1;i<=nRecs;i++) sl@0: { // fetch record #i sl@0: TInt r=GetTrapLogRecord(logRec,i); sl@0: test(r==KErrNone); sl@0: r=logRec().iProcessName.CompareF(_L("t_corruptlog.exe")); sl@0: test(r==KErrNone); sl@0: PrintLogRecord(logRec,i); sl@0: } sl@0: } sl@0: sl@0: #endif sl@0: sl@0: extern TInt E32Main() sl@0: { sl@0: sl@0: CTrapCleanup* cleanup; sl@0: cleanup=CTrapCleanup::New(); sl@0: __UHEAP_MARK; sl@0: sl@0: test.Title(); sl@0: test.Start(_L("Corrupt File trap log")); sl@0: #if defined(_DEBUG) || defined(_DEBUG_RELEASE) sl@0: TInt r=TheFs.Connect(); sl@0: test(r==KErrNone); sl@0: sl@0: TheFs.ResourceCountMarkStart(); sl@0: sl@0: DoTests(); sl@0: sl@0: TheFs.ResourceCountMarkEnd(); sl@0: ResetCorruptLogRecords(); sl@0: TheFs.Close(); sl@0: #endif sl@0: sl@0: test.End(); sl@0: test.Close(); sl@0: __UHEAP_MARKEND; sl@0: delete cleanup; sl@0: sl@0: sl@0: sl@0: return KErrNone; sl@0: }