Update contrib.
1 // Copyright (c) 2004-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 the License "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\server\t_corruptlog.cpp
20 //! @SYMTestCaseID FSBASE_corrupt_log
22 //! @SYMTestSuites Base tests
23 //! @SYMInitialAuthor Bob Jackman
24 //! @SYMCreationDate 1/11/04
25 //! @SYMTestCaseDesc Check trap action of CorruptFileNames.lst
28 RTest test(_L("t_corruptlog"));
30 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
35 _LIT(KTestFile1,"z:\\system\\data\\BadFile1.txt");
36 const TInt KTestFile1Error1=-6;
37 const TInt KTestFile1Error2=KErrNone;
40 _LIT(KTestFile2,"z:\\system\\data\\BadFile2.txt");
41 const TInt KTestFile2Error1=-20;
42 const TInt KTestFile2Error2=-20;
44 ////////////////////////////////////////////////////////////
49 static TInt numberOfTraps=0;
51 ////////////////////////////////////////////////////////////
53 inline TInt controlIo(RFs &fs, TInt drv, TInt fn)
55 TPtr8 pDummy(NULL,0,0);
56 TInt r = fs.ControlIo(drv, fn, pDummy);
60 inline TInt controlIo(RFs &fs, TInt drv, TInt fn, TInt &aNumRecs)
62 TPtr8 pNum((TUint8*)(&aNumRecs),sizeof(aNumRecs),sizeof(aNumRecs));
63 TInt r = fs.ControlIo(drv, fn, pNum);
67 inline TInt controlIo(RFs &fs, TInt drv, TInt fn, TDes& aFileName)
69 TBuf8<KMaxFileName> fileName8;
70 TInt r = fs.ControlIo(drv, fn, fileName8);
73 aFileName.Copy(fileName8);
79 inline TInt controlIo(RFs &fs, TInt drv, TInt fn, TFsDebugCorruptLogRecordBuf &alogRec, TInt aRecNum)
81 TInt r = fs.ControlIo(drv, fn, alogRec, *((TDes8*)aRecNum));
85 void PrintLogRecord(TFsDebugCorruptLogRecordBuf &alogRec, TInt aRecordNumber)
87 test.Printf(_L("#%d Process: %S tried to access %S errorCode=%d\n"),aRecordNumber,
88 &(alogRec().iProcessName),
89 &(alogRec().iFileName),
93 TInt ResetCorruptLogRecords()
95 // Allows the test to be run again, by resetting the record to an unused state,
96 // and destroying the trap records
97 // Enables this test to be ran again.
98 TInt r=controlIo(TheFs, EDriveC, KControlIoCorruptLogRecordReset);
102 TInt GetNumberOfTraps()
104 // fetchs the number of corrupt file trap records that exist
105 // there is a separate record for every attempted access to a nominated file
106 // Note that C: is used in the IoControl call, which requires a valid drive, but has no other relevance
107 TInt numberOfRecords;
108 TInt r=controlIo(TheFs, EDriveC, KControlIoGetNumberOfCorruptLogRecords, numberOfRecords);
110 return numberOfRecords;
113 TInt GetTrapLogRecord(TFsDebugCorruptLogRecordBuf &alogRec, TInt aRecordNumber)
115 // fetchs a trap record
116 // Note that C: is used in the IoControl call, which requires a valid drive, but has no other relevance
117 TInt r=controlIo(TheFs, EDriveC, KControlIoGetCorruptLogRecord, alogRec, aRecordNumber);
122 TInt GetCorruptFileListFile(TDes& aFileName)
124 // Retrieves the name of the file containing the list of files, nominated as corrupt, used to generate
125 // the corrupt files list.
126 // Note that C: is used in the IoControl call, which requires a valid drive, but has no other relevance
127 TInt r=controlIo(TheFs, EDriveC, KControlIoGetCorruptListFile, aFileName);
134 test.Next(_L("Access corrupt files"));
136 const TInt attribs=EFileShareExclusive|EFileStreamText|EFileRead;
138 TInt r=f.Open(TheFs,KTestFile1,attribs);
139 test(r==KTestFile1Error1);
141 numberOfTraps+=(r==KErrNone?0:1);
143 r=f.Open(TheFs,KTestFile1,attribs);
144 test(r==KTestFile1Error2);
146 numberOfTraps+=(r==KErrNone?0:1);
148 r=f.Open(TheFs,KTestFile2,attribs);
149 test(r==KTestFile2Error1);
151 numberOfTraps+=(r==KErrNone?0:1);
153 r=f.Open(TheFs,KTestFile2,attribs);
154 test(r==KTestFile2Error2);
156 numberOfTraps+=(r==KErrNone?0:1);
161 TFileName corruptFileNamesList;
162 test.Next(_L("Get name of file with list of nominated files"));
163 TInt r=GetCorruptFileListFile(corruptFileNamesList);
165 test.Printf(_L("Using %S\n"),&corruptFileNamesList);
168 test.Next(_L("Get Number of traps"));
169 TInt nRecs=GetNumberOfTraps();
170 test.Next(_L("Test Number of traps"));
171 test(nRecs==numberOfTraps);
173 TFsDebugCorruptLogRecordBuf logRec;
174 for (TInt i=1;i<=nRecs;i++)
176 TInt r=GetTrapLogRecord(logRec,i);
178 r=logRec().iProcessName.CompareF(_L("t_corruptlog.exe"));
180 PrintLogRecord(logRec,i);
186 extern TInt E32Main()
189 CTrapCleanup* cleanup;
190 cleanup=CTrapCleanup::New();
194 test.Start(_L("Corrupt File trap log"));
195 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
196 TInt r=TheFs.Connect();
199 TheFs.ResourceCountMarkStart();
203 TheFs.ResourceCountMarkEnd();
204 ResetCorruptLogRecords();