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