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