sl@0
|
1 |
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// f32test\server\t_corruptlog.cpp
|
sl@0
|
15 |
// Includes
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
//! @file
|
sl@0
|
20 |
//! @SYMTestCaseID FSBASE_corrupt_log
|
sl@0
|
21 |
//! @SYMPREQ 908
|
sl@0
|
22 |
//! @SYMTestSuites Base tests
|
sl@0
|
23 |
//! @SYMInitialAuthor Bob Jackman
|
sl@0
|
24 |
//! @SYMCreationDate 1/11/04
|
sl@0
|
25 |
//! @SYMTestCaseDesc Check trap action of CorruptFileNames.lst
|
sl@0
|
26 |
|
sl@0
|
27 |
#include <e32test.h>
|
sl@0
|
28 |
RTest test(_L("t_corruptlog"));
|
sl@0
|
29 |
|
sl@0
|
30 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
sl@0
|
31 |
#include <f32file.h>
|
sl@0
|
32 |
#include <f32dbg.h>
|
sl@0
|
33 |
|
sl@0
|
34 |
// Error every time
|
sl@0
|
35 |
_LIT(KTestFile1,"z:\\system\\data\\BadFile1.txt");
|
sl@0
|
36 |
const TInt KTestFile1Error1=-6;
|
sl@0
|
37 |
const TInt KTestFile1Error2=KErrNone;
|
sl@0
|
38 |
//
|
sl@0
|
39 |
// Error once
|
sl@0
|
40 |
_LIT(KTestFile2,"z:\\system\\data\\BadFile2.txt");
|
sl@0
|
41 |
const TInt KTestFile2Error1=-20;
|
sl@0
|
42 |
const TInt KTestFile2Error2=-20;
|
sl@0
|
43 |
|
sl@0
|
44 |
////////////////////////////////////////////////////////////
|
sl@0
|
45 |
// Globals
|
sl@0
|
46 |
//
|
sl@0
|
47 |
static RFs TheFs;
|
sl@0
|
48 |
|
sl@0
|
49 |
static TInt numberOfTraps=0;
|
sl@0
|
50 |
|
sl@0
|
51 |
////////////////////////////////////////////////////////////
|
sl@0
|
52 |
|
sl@0
|
53 |
inline TInt controlIo(RFs &fs, TInt drv, TInt fn)
|
sl@0
|
54 |
{
|
sl@0
|
55 |
TPtr8 pDummy(NULL,0,0);
|
sl@0
|
56 |
TInt r = fs.ControlIo(drv, fn, pDummy);
|
sl@0
|
57 |
return r;
|
sl@0
|
58 |
}
|
sl@0
|
59 |
|
sl@0
|
60 |
inline TInt controlIo(RFs &fs, TInt drv, TInt fn, TInt &aNumRecs)
|
sl@0
|
61 |
{
|
sl@0
|
62 |
TPtr8 pNum((TUint8*)(&aNumRecs),sizeof(aNumRecs),sizeof(aNumRecs));
|
sl@0
|
63 |
TInt r = fs.ControlIo(drv, fn, pNum);
|
sl@0
|
64 |
return r;
|
sl@0
|
65 |
}
|
sl@0
|
66 |
|
sl@0
|
67 |
inline TInt controlIo(RFs &fs, TInt drv, TInt fn, TDes& aFileName)
|
sl@0
|
68 |
{
|
sl@0
|
69 |
TBuf8<KMaxFileName> fileName8;
|
sl@0
|
70 |
TInt r = fs.ControlIo(drv, fn, fileName8);
|
sl@0
|
71 |
if(r==KErrNone)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
aFileName.Copy(fileName8);
|
sl@0
|
74 |
}
|
sl@0
|
75 |
return r;
|
sl@0
|
76 |
}
|
sl@0
|
77 |
|
sl@0
|
78 |
|
sl@0
|
79 |
inline TInt controlIo(RFs &fs, TInt drv, TInt fn, TFsDebugCorruptLogRecordBuf &alogRec, TInt aRecNum)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
TInt r = fs.ControlIo(drv, fn, alogRec, *((TDes8*)aRecNum));
|
sl@0
|
82 |
return r;
|
sl@0
|
83 |
}
|
sl@0
|
84 |
|
sl@0
|
85 |
void PrintLogRecord(TFsDebugCorruptLogRecordBuf &alogRec, TInt aRecordNumber)
|
sl@0
|
86 |
{
|
sl@0
|
87 |
test.Printf(_L("#%d Process: %S tried to access %S errorCode=%d\n"),aRecordNumber,
|
sl@0
|
88 |
&(alogRec().iProcessName),
|
sl@0
|
89 |
&(alogRec().iFileName),
|
sl@0
|
90 |
alogRec().iError);
|
sl@0
|
91 |
}
|
sl@0
|
92 |
|
sl@0
|
93 |
TInt ResetCorruptLogRecords()
|
sl@0
|
94 |
{
|
sl@0
|
95 |
// Allows the test to be run again, by resetting the record to an unused state,
|
sl@0
|
96 |
// and destroying the trap records
|
sl@0
|
97 |
// Enables this test to be ran again.
|
sl@0
|
98 |
TInt r=controlIo(TheFs, EDriveC, KControlIoCorruptLogRecordReset);
|
sl@0
|
99 |
return r;
|
sl@0
|
100 |
}
|
sl@0
|
101 |
|
sl@0
|
102 |
TInt GetNumberOfTraps()
|
sl@0
|
103 |
{
|
sl@0
|
104 |
// fetchs the number of corrupt file trap records that exist
|
sl@0
|
105 |
// there is a separate record for every attempted access to a nominated file
|
sl@0
|
106 |
// Note that C: is used in the IoControl call, which requires a valid drive, but has no other relevance
|
sl@0
|
107 |
TInt numberOfRecords;
|
sl@0
|
108 |
TInt r=controlIo(TheFs, EDriveC, KControlIoGetNumberOfCorruptLogRecords, numberOfRecords);
|
sl@0
|
109 |
test(r==KErrNone);
|
sl@0
|
110 |
return numberOfRecords;
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
TInt GetTrapLogRecord(TFsDebugCorruptLogRecordBuf &alogRec, TInt aRecordNumber)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
// fetchs a trap record
|
sl@0
|
116 |
// Note that C: is used in the IoControl call, which requires a valid drive, but has no other relevance
|
sl@0
|
117 |
TInt r=controlIo(TheFs, EDriveC, KControlIoGetCorruptLogRecord, alogRec, aRecordNumber);
|
sl@0
|
118 |
test(r==KErrNone);
|
sl@0
|
119 |
return r;
|
sl@0
|
120 |
}
|
sl@0
|
121 |
|
sl@0
|
122 |
TInt GetCorruptFileListFile(TDes& aFileName)
|
sl@0
|
123 |
{
|
sl@0
|
124 |
// Retrieves the name of the file containing the list of files, nominated as corrupt, used to generate
|
sl@0
|
125 |
// the corrupt files list.
|
sl@0
|
126 |
// Note that C: is used in the IoControl call, which requires a valid drive, but has no other relevance
|
sl@0
|
127 |
TInt r=controlIo(TheFs, EDriveC, KControlIoGetCorruptListFile, aFileName);
|
sl@0
|
128 |
test(r==KErrNone);
|
sl@0
|
129 |
return r;
|
sl@0
|
130 |
}
|
sl@0
|
131 |
|
sl@0
|
132 |
void AccessFiles()
|
sl@0
|
133 |
{
|
sl@0
|
134 |
test.Next(_L("Access corrupt files"));
|
sl@0
|
135 |
RFile f;
|
sl@0
|
136 |
const TInt attribs=EFileShareExclusive|EFileStreamText|EFileRead;
|
sl@0
|
137 |
// File1
|
sl@0
|
138 |
TInt r=f.Open(TheFs,KTestFile1,attribs);
|
sl@0
|
139 |
test(r==KTestFile1Error1);
|
sl@0
|
140 |
f.Close();
|
sl@0
|
141 |
numberOfTraps+=(r==KErrNone?0:1);
|
sl@0
|
142 |
// try again
|
sl@0
|
143 |
r=f.Open(TheFs,KTestFile1,attribs);
|
sl@0
|
144 |
test(r==KTestFile1Error2);
|
sl@0
|
145 |
f.Close();
|
sl@0
|
146 |
numberOfTraps+=(r==KErrNone?0:1);
|
sl@0
|
147 |
// File2
|
sl@0
|
148 |
r=f.Open(TheFs,KTestFile2,attribs);
|
sl@0
|
149 |
test(r==KTestFile2Error1);
|
sl@0
|
150 |
f.Close();
|
sl@0
|
151 |
numberOfTraps+=(r==KErrNone?0:1);
|
sl@0
|
152 |
// try again
|
sl@0
|
153 |
r=f.Open(TheFs,KTestFile2,attribs);
|
sl@0
|
154 |
test(r==KTestFile2Error2);
|
sl@0
|
155 |
f.Close();
|
sl@0
|
156 |
numberOfTraps+=(r==KErrNone?0:1);
|
sl@0
|
157 |
}
|
sl@0
|
158 |
|
sl@0
|
159 |
void DoTests()
|
sl@0
|
160 |
{
|
sl@0
|
161 |
TFileName corruptFileNamesList;
|
sl@0
|
162 |
test.Next(_L("Get name of file with list of nominated files"));
|
sl@0
|
163 |
TInt r=GetCorruptFileListFile(corruptFileNamesList);
|
sl@0
|
164 |
test(r==KErrNone);
|
sl@0
|
165 |
test.Printf(_L("Using %S\n"),&corruptFileNamesList);
|
sl@0
|
166 |
|
sl@0
|
167 |
AccessFiles();
|
sl@0
|
168 |
test.Next(_L("Get Number of traps"));
|
sl@0
|
169 |
TInt nRecs=GetNumberOfTraps();
|
sl@0
|
170 |
test.Next(_L("Test Number of traps"));
|
sl@0
|
171 |
test(nRecs==numberOfTraps);
|
sl@0
|
172 |
|
sl@0
|
173 |
TFsDebugCorruptLogRecordBuf logRec;
|
sl@0
|
174 |
for (TInt i=1;i<=nRecs;i++)
|
sl@0
|
175 |
{ // fetch record #i
|
sl@0
|
176 |
TInt r=GetTrapLogRecord(logRec,i);
|
sl@0
|
177 |
test(r==KErrNone);
|
sl@0
|
178 |
r=logRec().iProcessName.CompareF(_L("t_corruptlog.exe"));
|
sl@0
|
179 |
test(r==KErrNone);
|
sl@0
|
180 |
PrintLogRecord(logRec,i);
|
sl@0
|
181 |
}
|
sl@0
|
182 |
}
|
sl@0
|
183 |
|
sl@0
|
184 |
#endif
|
sl@0
|
185 |
|
sl@0
|
186 |
extern TInt E32Main()
|
sl@0
|
187 |
{
|
sl@0
|
188 |
|
sl@0
|
189 |
CTrapCleanup* cleanup;
|
sl@0
|
190 |
cleanup=CTrapCleanup::New();
|
sl@0
|
191 |
__UHEAP_MARK;
|
sl@0
|
192 |
|
sl@0
|
193 |
test.Title();
|
sl@0
|
194 |
test.Start(_L("Corrupt File trap log"));
|
sl@0
|
195 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
sl@0
|
196 |
TInt r=TheFs.Connect();
|
sl@0
|
197 |
test(r==KErrNone);
|
sl@0
|
198 |
|
sl@0
|
199 |
TheFs.ResourceCountMarkStart();
|
sl@0
|
200 |
|
sl@0
|
201 |
DoTests();
|
sl@0
|
202 |
|
sl@0
|
203 |
TheFs.ResourceCountMarkEnd();
|
sl@0
|
204 |
ResetCorruptLogRecords();
|
sl@0
|
205 |
TheFs.Close();
|
sl@0
|
206 |
#endif
|
sl@0
|
207 |
|
sl@0
|
208 |
test.End();
|
sl@0
|
209 |
test.Close();
|
sl@0
|
210 |
__UHEAP_MARKEND;
|
sl@0
|
211 |
delete cleanup;
|
sl@0
|
212 |
|
sl@0
|
213 |
|
sl@0
|
214 |
|
sl@0
|
215 |
return KErrNone;
|
sl@0
|
216 |
}
|