Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\server\t_vfat.cpp
23 RTest test(_L("T_VFAT"));
27 // Create 71 8.3 files
28 // Rename each of them to vfat filenames (% order)
34 test.Next(_L("Test rename"));
37 TFileName nameshort=_L("File");
38 TFileName namelong=_L("File.+',;'=[]");
42 for (i=0;i<totalFiles;i++)
44 TBuf<32> tempName=nameshort;
45 tempName.AppendNum(i);
47 MakeFile(tempName,data);
50 TInt count=totalFiles;
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);
62 TInt r=TheFs.CheckDisk(gSessionPath);
63 test(r==KErrNone || r==KErrNotSupported);
66 r=TheFs.GetDir(_L("*.*"),KEntryAttMaskSupported,ESortBySize,dirList);
68 test(dirList->Count()==totalFiles);
69 for (i=0;i<totalFiles;i++)
71 TBuf<32> longName=namelong;
72 longName.AppendNum(i);
75 test(entry.iName.MatchF(longName)!=KErrNotFound);
83 const TInt gMaxIterations=1000;
85 const TInt gMaxIterations=1000; // Have pity on a poor 18MHz CPU
88 const TInt gMaxFiles=256;
89 TBuf<gMaxFiles> gDataBuf;
91 TFileName gFileName[gMaxFiles];
96 // Generate random numbers fileNum, fileOp.
97 // fileOp = 1, shortname
98 // fileOp = 2, longName
99 // fileOp = 3, delete file
104 test.Next(_L("Random test"));
106 TInt maxIterations=gMaxIterations;
108 TInt checkFrequency=100; // 1 in xxxx
110 for(i=0;i<gMaxFiles;i++)
114 while(maxIterations--)
116 TInt fileNum=Math::Rand(seed)%gMaxFiles;
117 TInt fileOp=Math::Rand(seed)%maxFileOps;
121 CreateShortName(fileName,seed);
124 CreateLongName(fileName,seed);
128 fileName=gFileName[fileNum];
129 if (fileName==_L(""))
131 r=TheFs.Delete(fileName);
133 gFileName[fileNum]=_L("");
136 User::Panic(_L("IllegalVal"),KErrGeneral);
139 if (gFileName[fileNum]==_L(""))
141 /* Delete any existing file with the same name */
144 r=thing.Open(TheFs, fileName, EFileShareAny);
145 test (r==KErrNone || r==KErrNotFound);
149 test (thing.Size(s) == KErrNone);
151 r=TheFs.Delete(fileName);
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;
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);
173 gFileName[fileNum]=fileName;
176 if ((maxIterations%checkFrequency)==0)
178 test.Printf(_L("Iteration %d \r"),gMaxIterations-maxIterations);
179 TInt r=TheFs.CheckDisk(gSessionPath);
180 test(r==KErrNone || r==KErrNotSupported);
183 r=TheFs.GetDir(_L("*.*"),KEntryAttMaskSupported,ESortBySize,dirList);
185 for(i=0;i<gMaxFiles;i++)
187 if (gFileName[i]==_L(""))
190 entry=(*dirList)[count];
191 TInt r=gFileName[i].MatchF(entry.iName);
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]=='.');
198 //-- strip all trailing dots from the original name
201 if(gFileName[i][len-1]=='.')
207 TPtrC ptrFileName(gFileName[i].Ptr(), len);
209 test(ptrFileName.CompareF(entry.iName) == 0);
218 test.Printf(_L("\n"),i);
221 //-----------------------------------------------------------------
222 _LIT(KName1, "\\file1");
223 _LIT(KName2, "\\file1.");
224 _LIT(KName3, "\\file1..");
225 _LIT(KName4, "\\file1...");
226 _LIT(KExpectedName, "file1");
233 nRes = TheFs.Entry(KName1, entry);
234 test(nRes == KErrNone);
235 test(entry.iName.CompareF(KExpectedName) == 0);
237 nRes = TheFs.Entry(KName2, entry);
238 test(nRes == KErrNone);
239 test(entry.iName.CompareF(KExpectedName) == 0);
241 nRes = TheFs.Entry(KName3, entry);
242 test(nRes == KErrNone);
243 test(entry.iName.CompareF(KExpectedName) == 0);
245 nRes = TheFs.Entry(KName3, entry);
246 test(nRes == KErrNone);
247 test(entry.iName.CompareF(KExpectedName) == 0);
251 Test that ALL trailing dots are removed from the file names by filsystem implementation
253 void TestTrailingDots()
255 test.Next(_L("Test trailing dots"));
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()
274 //----- create and check "\\file1"
275 nRes = file.Replace(TheFs, KName1, EFileWrite);
276 test(nRes == KErrNone);
281 nRes = TheFs.Delete(KName1);
282 test(nRes == KErrNone);
285 //----- create and check "\\file1."
286 nRes = file.Replace(TheFs, KName2, EFileWrite);
287 test(nRes == KErrNone);
292 nRes = TheFs.Delete(KName2);
293 test(nRes == KErrNone);
296 //----- create and check "\\file1.."
297 nRes = file.Replace(TheFs, KName3, EFileWrite);
298 test(nRes == KErrNone);
303 nRes = TheFs.Delete(KName3);
304 test(nRes == KErrNone);
307 //----- create and check "\\file1..."
308 nRes = file.Replace(TheFs, KName4, EFileWrite);
309 test(nRes == KErrNone);
314 nRes = TheFs.Delete(KName4);
315 test(nRes == KErrNone);
322 // Do tests relative to session path
326 TurnAllocFailureOff();
328 CreateTestDirectory(_L("\\F32-TST\\TVFAT\\"));
331 DeleteTestDirectory();
332 CreateTestDirectory(_L("\\F32-TST\\TVFAT\\"));
337 DeleteTestDirectory();