author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 11 Jun 2010 15:02:23 +0300 | |
changeset 152 | 657f875b013e |
parent 109 | b3a1d9898418 |
child 257 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1997-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_vfat.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
18 |
#define __E32TEST_EXTENSION__ |
0 | 19 |
#include <f32file.h> |
20 |
#include <e32test.h> |
|
21 |
#include <e32math.h> |
|
22 |
#include "t_server.h" |
|
23 |
||
24 |
RTest test(_L("T_VFAT")); |
|
25 |
||
26 |
static void Test1() |
|
27 |
// |
|
28 |
// Create 71 8.3 files |
|
29 |
// Rename each of them to vfat filenames (% order) |
|
30 |
// Chkdsk |
|
31 |
// Check entries |
|
32 |
// |
|
33 |
{ |
|
34 |
||
35 |
test.Next(_L("Test rename")); |
|
36 |
TInt totalFiles=103; |
|
37 |
TInt orderMod=61; |
|
38 |
TFileName nameshort=_L("File"); |
|
39 |
TFileName namelong=_L("File.+',;'=[]"); |
|
40 |
TInt i; |
|
41 |
TBuf8<256> data; |
|
42 |
||
43 |
for (i=0;i<totalFiles;i++) |
|
44 |
{ |
|
45 |
TBuf<32> tempName=nameshort; |
|
46 |
tempName.AppendNum(i); |
|
47 |
data.SetLength(i); |
|
48 |
MakeFile(tempName,data); |
|
49 |
} |
|
50 |
||
51 |
TInt count=totalFiles; |
|
52 |
while(count--) |
|
53 |
{ |
|
54 |
TInt fileNum=(orderMod*count)%totalFiles; |
|
55 |
TBuf<32> shortName=nameshort; |
|
56 |
shortName.AppendNum(fileNum); |
|
57 |
TBuf<32> longName=namelong; |
|
58 |
longName.AppendNum(fileNum); |
|
59 |
TInt r=TheFs.Rename(shortName,longName); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
60 |
test_KErrNone(r); |
0 | 61 |
} |
62 |
||
63 |
TInt r=TheFs.CheckDisk(gSessionPath); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
64 |
test_Value(r, r == KErrNone || r==KErrNotSupported); |
0 | 65 |
|
66 |
CDir* dirList; |
|
67 |
r=TheFs.GetDir(_L("*.*"),KEntryAttMaskSupported,ESortBySize,dirList); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
68 |
test_KErrNone(r); |
0 | 69 |
test(dirList->Count()==totalFiles); |
70 |
for (i=0;i<totalFiles;i++) |
|
71 |
{ |
|
72 |
TBuf<32> longName=namelong; |
|
73 |
longName.AppendNum(i); |
|
74 |
TEntry entry; |
|
75 |
entry=(*dirList)[i]; |
|
76 |
test(entry.iName.MatchF(longName)!=KErrNotFound); |
|
77 |
} |
|
78 |
||
79 |
delete dirList; |
|
80 |
} |
|
81 |
||
82 |
||
83 |
#ifdef __WINS__ |
|
84 |
const TInt gMaxIterations=1000; |
|
85 |
#else |
|
86 |
const TInt gMaxIterations=1000; // Have pity on a poor 18MHz CPU |
|
87 |
#endif |
|
88 |
||
89 |
const TInt gMaxFiles=256; |
|
90 |
TBuf<gMaxFiles> gDataBuf; |
|
91 |
TBuf8<gMaxFiles> buf; |
|
92 |
TFileName gFileName[gMaxFiles]; |
|
93 |
||
94 |
LOCAL_C void Test2() |
|
95 |
// |
|
96 |
// Random test |
|
97 |
// Generate random numbers fileNum, fileOp. |
|
98 |
// fileOp = 1, shortname |
|
99 |
// fileOp = 2, longName |
|
100 |
// fileOp = 3, delete file |
|
101 |
// |
|
102 |
{ |
|
103 |
||
104 |
TInt i; |
|
105 |
test.Next(_L("Random test")); |
|
106 |
TInt64 seed=51703; |
|
107 |
TInt maxIterations=gMaxIterations; |
|
108 |
TInt maxFileOps=3; |
|
109 |
TInt checkFrequency=100; // 1 in xxxx |
|
110 |
||
111 |
for(i=0;i<gMaxFiles;i++) |
|
112 |
gFileName[i]=_L(""); |
|
113 |
||
114 |
TFileName fileName; |
|
115 |
while(maxIterations--) |
|
116 |
{ |
|
117 |
TInt fileNum=Math::Rand(seed)%gMaxFiles; |
|
118 |
TInt fileOp=Math::Rand(seed)%maxFileOps; |
|
119 |
switch(fileOp) |
|
120 |
{ |
|
121 |
case 0: |
|
122 |
CreateShortName(fileName,seed); |
|
123 |
break; |
|
124 |
case 1: |
|
125 |
CreateLongName(fileName,seed); |
|
126 |
break; |
|
127 |
case 2: |
|
128 |
TInt r; |
|
129 |
fileName=gFileName[fileNum]; |
|
130 |
if (fileName==_L("")) |
|
131 |
goto End; |
|
132 |
r=TheFs.Delete(fileName); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
133 |
test_KErrNone(r); |
0 | 134 |
gFileName[fileNum]=_L(""); |
135 |
goto End; |
|
136 |
default: |
|
137 |
User::Panic(_L("IllegalVal"),KErrGeneral); |
|
138 |
}; |
|
139 |
||
140 |
if (gFileName[fileNum]==_L("")) |
|
141 |
{ |
|
142 |
/* Delete any existing file with the same name */ |
|
143 |
TInt r; |
|
144 |
RFile thing; |
|
145 |
r=thing.Open(TheFs, fileName, EFileShareAny); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
146 |
test_Value(r, r == KErrNone || r==KErrNotFound); |
0 | 147 |
if (r==KErrNone) |
148 |
{ |
|
149 |
TInt s; |
|
150 |
test (thing.Size(s) == KErrNone); |
|
151 |
thing.Close(); |
|
152 |
r=TheFs.Delete(fileName); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
153 |
test_KErrNone(r); |
0 | 154 |
gFileName[s]=_L(""); |
155 |
} |
|
156 |
else |
|
157 |
thing.Close(); |
|
158 |
||
159 |
gDataBuf.SetLength(fileNum); |
|
160 |
/* the return from the following function was being checked and the next would only be |
|
161 |
carried out if the return showed no error. But this function never returns anything so |
|
162 |
the code wasn't compiling */ |
|
163 |
buf.Copy(gDataBuf); // Unicode |
|
164 |
MakeFile(fileName,buf); |
|
165 |
gFileName[fileNum]=fileName; |
|
166 |
} |
|
167 |
else |
|
168 |
{ |
|
169 |
TInt r=TheFs.Rename(gFileName[fileNum],fileName); |
|
170 |
if (r != KErrNone && r != KErrAlreadyExists) |
|
171 |
test.Printf(_L("Rename returned %d at line %d"), r, __LINE__); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
172 |
test_Value(r, r == KErrNone || r==KErrAlreadyExists); |
0 | 173 |
if (r==KErrNone) |
174 |
gFileName[fileNum]=fileName; |
|
175 |
} |
|
176 |
End: |
|
177 |
if ((maxIterations%checkFrequency)==0) |
|
178 |
{ |
|
179 |
test.Printf(_L("Iteration %d \r"),gMaxIterations-maxIterations); |
|
180 |
TInt r=TheFs.CheckDisk(gSessionPath); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
181 |
test_Value(r, r == KErrNone || r==KErrNotSupported); |
0 | 182 |
TInt count=0; |
183 |
CDir* dirList; |
|
184 |
r=TheFs.GetDir(_L("*.*"),KEntryAttMaskSupported,ESortBySize,dirList); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
185 |
test_KErrNone(r); |
0 | 186 |
for(i=0;i<gMaxFiles;i++) |
187 |
{ |
|
188 |
if (gFileName[i]==_L("")) |
|
189 |
continue; |
|
190 |
TEntry entry; |
|
191 |
entry=(*dirList)[count]; |
|
192 |
TInt r=gFileName[i].MatchF(entry.iName); |
|
193 |
if (r==KErrNotFound) |
|
194 |
{ |
|
195 |
//-- tests a dodgy case when the name has multiple trailing dots. They must have been removed by FS implementation |
|
196 |
TUint len=gFileName[i].Length(); |
|
197 |
test(gFileName[i][len-1]=='.'); |
|
198 |
||
199 |
//-- strip all trailing dots from the original name |
|
200 |
while(len) |
|
201 |
{ |
|
202 |
if(gFileName[i][len-1]=='.') |
|
203 |
len--; |
|
204 |
else |
|
205 |
break; |
|
206 |
} |
|
207 |
||
208 |
TPtrC ptrFileName(gFileName[i].Ptr(), len); |
|
209 |
||
210 |
test(ptrFileName.CompareF(entry.iName) == 0); |
|
211 |
||
212 |
||
213 |
} |
|
214 |
count++; |
|
215 |
} |
|
216 |
delete dirList; |
|
217 |
} |
|
218 |
} |
|
219 |
test.Printf(_L("\n"),i); |
|
220 |
} |
|
221 |
||
222 |
//----------------------------------------------------------------- |
|
223 |
_LIT(KName1, "\\file1"); |
|
224 |
_LIT(KName2, "\\file1."); |
|
225 |
_LIT(KName3, "\\file1.."); |
|
226 |
_LIT(KName4, "\\file1..."); |
|
227 |
_LIT(KExpectedName, "file1"); |
|
228 |
||
229 |
void DoCheckTD_FN() |
|
230 |
{ |
|
231 |
TInt nRes; |
|
232 |
TEntry entry; |
|
233 |
||
234 |
nRes = TheFs.Entry(KName1, entry); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
235 |
test_KErrNone(nRes); |
0 | 236 |
test(entry.iName.CompareF(KExpectedName) == 0); |
237 |
||
238 |
nRes = TheFs.Entry(KName2, entry); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
239 |
test_KErrNone(nRes); |
0 | 240 |
test(entry.iName.CompareF(KExpectedName) == 0); |
241 |
||
242 |
nRes = TheFs.Entry(KName3, entry); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
243 |
test_KErrNone(nRes); |
0 | 244 |
test(entry.iName.CompareF(KExpectedName) == 0); |
245 |
||
246 |
nRes = TheFs.Entry(KName3, entry); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
247 |
test_KErrNone(nRes); |
0 | 248 |
test(entry.iName.CompareF(KExpectedName) == 0); |
249 |
} |
|
250 |
||
251 |
/** |
|
252 |
Test that ALL trailing dots are removed from the file names by filsystem implementation |
|
253 |
*/ |
|
254 |
void TestTrailingDots() |
|
255 |
{ |
|
256 |
test.Next(_L("Test trailing dots")); |
|
257 |
||
258 |
//-- actually, all these APIs shall be tested: |
|
259 |
//-- CMountCB::MkDirL() |
|
260 |
//-- CMountCB::RmDirL() |
|
261 |
//-- CMountCB::DeleteL() |
|
262 |
//-- CMountCB::RenameL() |
|
263 |
//-- CMountCB::ReplaceL() |
|
264 |
//-- CMountCB::EntryL() const |
|
265 |
//-- CMountCB::SetEntryL() |
|
266 |
//-- CMountCB::FileOpenL() |
|
267 |
//-- CMountCB::DirOpenL() |
|
268 |
//-- CMountCB::ReadSectionL() |
|
269 |
//-- CFileCB::RenameL() |
|
270 |
||
271 |
||
272 |
TInt nRes; |
|
273 |
RFile file; |
|
274 |
||
275 |
//----- create and check "\\file1" |
|
276 |
nRes = file.Replace(TheFs, KName1, EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
277 |
test_KErrNone(nRes); |
0 | 278 |
file.Close(); |
279 |
||
280 |
DoCheckTD_FN(); |
|
281 |
||
282 |
nRes = TheFs.Delete(KName1); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
283 |
test_KErrNone(nRes); |
0 | 284 |
|
285 |
||
286 |
//----- create and check "\\file1." |
|
287 |
nRes = file.Replace(TheFs, KName2, EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
288 |
test_KErrNone(nRes); |
0 | 289 |
file.Close(); |
290 |
||
291 |
DoCheckTD_FN(); |
|
292 |
||
293 |
nRes = TheFs.Delete(KName2); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
294 |
test_KErrNone(nRes); |
0 | 295 |
|
296 |
||
297 |
//----- create and check "\\file1.." |
|
298 |
nRes = file.Replace(TheFs, KName3, EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
299 |
test_KErrNone(nRes); |
0 | 300 |
file.Close(); |
301 |
||
302 |
DoCheckTD_FN(); |
|
303 |
||
304 |
nRes = TheFs.Delete(KName3); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
305 |
test_KErrNone(nRes); |
0 | 306 |
|
307 |
||
308 |
//----- create and check "\\file1..." |
|
309 |
nRes = file.Replace(TheFs, KName4, EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
310 |
test_KErrNone(nRes); |
0 | 311 |
file.Close(); |
312 |
||
313 |
DoCheckTD_FN(); |
|
314 |
||
315 |
nRes = TheFs.Delete(KName4); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
316 |
test_KErrNone(nRes); |
0 | 317 |
|
318 |
||
319 |
} |
|
320 |
||
321 |
void CallTestsL() |
|
322 |
// |
|
323 |
// Do tests relative to session path |
|
324 |
// |
|
325 |
{ |
|
326 |
||
327 |
TurnAllocFailureOff(); |
|
328 |
||
329 |
CreateTestDirectory(_L("\\F32-TST\\TVFAT\\")); |
|
330 |
||
331 |
Test1(); |
|
332 |
DeleteTestDirectory(); |
|
333 |
CreateTestDirectory(_L("\\F32-TST\\TVFAT\\")); |
|
334 |
Test2(); |
|
335 |
||
336 |
TestTrailingDots(); |
|
337 |
||
338 |
DeleteTestDirectory(); |
|
339 |
} |
|
340 |