1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/server/t_vfat.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,339 @@
1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// f32test\server\t_vfat.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <f32file.h>
1.22 +#include <e32test.h>
1.23 +#include <e32math.h>
1.24 +#include "t_server.h"
1.25 +
1.26 +RTest test(_L("T_VFAT"));
1.27 +
1.28 +static void Test1()
1.29 +//
1.30 +// Create 71 8.3 files
1.31 +// Rename each of them to vfat filenames (% order)
1.32 +// Chkdsk
1.33 +// Check entries
1.34 +//
1.35 + {
1.36 +
1.37 + test.Next(_L("Test rename"));
1.38 + TInt totalFiles=103;
1.39 + TInt orderMod=61;
1.40 + TFileName nameshort=_L("File");
1.41 + TFileName namelong=_L("File.+',;'=[]");
1.42 + TInt i;
1.43 + TBuf8<256> data;
1.44 +
1.45 + for (i=0;i<totalFiles;i++)
1.46 + {
1.47 + TBuf<32> tempName=nameshort;
1.48 + tempName.AppendNum(i);
1.49 + data.SetLength(i);
1.50 + MakeFile(tempName,data);
1.51 + }
1.52 +
1.53 + TInt count=totalFiles;
1.54 + while(count--)
1.55 + {
1.56 + TInt fileNum=(orderMod*count)%totalFiles;
1.57 + TBuf<32> shortName=nameshort;
1.58 + shortName.AppendNum(fileNum);
1.59 + TBuf<32> longName=namelong;
1.60 + longName.AppendNum(fileNum);
1.61 + TInt r=TheFs.Rename(shortName,longName);
1.62 + test(r==KErrNone);
1.63 + }
1.64 +
1.65 + TInt r=TheFs.CheckDisk(gSessionPath);
1.66 + test(r==KErrNone || r==KErrNotSupported);
1.67 +
1.68 + CDir* dirList;
1.69 + r=TheFs.GetDir(_L("*.*"),KEntryAttMaskSupported,ESortBySize,dirList);
1.70 + test(r==KErrNone);
1.71 + test(dirList->Count()==totalFiles);
1.72 + for (i=0;i<totalFiles;i++)
1.73 + {
1.74 + TBuf<32> longName=namelong;
1.75 + longName.AppendNum(i);
1.76 + TEntry entry;
1.77 + entry=(*dirList)[i];
1.78 + test(entry.iName.MatchF(longName)!=KErrNotFound);
1.79 + }
1.80 +
1.81 + delete dirList;
1.82 + }
1.83 +
1.84 +
1.85 +#ifdef __WINS__
1.86 +const TInt gMaxIterations=1000;
1.87 +#else
1.88 +const TInt gMaxIterations=1000; // Have pity on a poor 18MHz CPU
1.89 +#endif
1.90 +
1.91 +const TInt gMaxFiles=256;
1.92 +TBuf<gMaxFiles> gDataBuf;
1.93 +TBuf8<gMaxFiles> buf;
1.94 +TFileName gFileName[gMaxFiles];
1.95 +
1.96 +LOCAL_C void Test2()
1.97 +//
1.98 +// Random test
1.99 +// Generate random numbers fileNum, fileOp.
1.100 +// fileOp = 1, shortname
1.101 +// fileOp = 2, longName
1.102 +// fileOp = 3, delete file
1.103 +//
1.104 + {
1.105 +
1.106 + TInt i;
1.107 + test.Next(_L("Random test"));
1.108 + TInt64 seed=51703;
1.109 + TInt maxIterations=gMaxIterations;
1.110 + TInt maxFileOps=3;
1.111 + TInt checkFrequency=100; // 1 in xxxx
1.112 +
1.113 + for(i=0;i<gMaxFiles;i++)
1.114 + gFileName[i]=_L("");
1.115 +
1.116 + TFileName fileName;
1.117 + while(maxIterations--)
1.118 + {
1.119 + TInt fileNum=Math::Rand(seed)%gMaxFiles;
1.120 + TInt fileOp=Math::Rand(seed)%maxFileOps;
1.121 + switch(fileOp)
1.122 + {
1.123 + case 0:
1.124 + CreateShortName(fileName,seed);
1.125 + break;
1.126 + case 1:
1.127 + CreateLongName(fileName,seed);
1.128 + break;
1.129 + case 2:
1.130 + TInt r;
1.131 + fileName=gFileName[fileNum];
1.132 + if (fileName==_L(""))
1.133 + goto End;
1.134 + r=TheFs.Delete(fileName);
1.135 + test(r==KErrNone);
1.136 + gFileName[fileNum]=_L("");
1.137 + goto End;
1.138 + default:
1.139 + User::Panic(_L("IllegalVal"),KErrGeneral);
1.140 + };
1.141 +
1.142 + if (gFileName[fileNum]==_L(""))
1.143 + {
1.144 + /* Delete any existing file with the same name */
1.145 + TInt r;
1.146 + RFile thing;
1.147 + r=thing.Open(TheFs, fileName, EFileShareAny);
1.148 + test (r==KErrNone || r==KErrNotFound);
1.149 + if (r==KErrNone)
1.150 + {
1.151 + TInt s;
1.152 + test (thing.Size(s) == KErrNone);
1.153 + thing.Close();
1.154 + r=TheFs.Delete(fileName);
1.155 + test (r==KErrNone);
1.156 + gFileName[s]=_L("");
1.157 + }
1.158 + else
1.159 + thing.Close();
1.160 +
1.161 + gDataBuf.SetLength(fileNum);
1.162 + /* the return from the following function was being checked and the next would only be
1.163 + carried out if the return showed no error. But this function never returns anything so
1.164 + the code wasn't compiling */
1.165 + buf.Copy(gDataBuf); // Unicode
1.166 + MakeFile(fileName,buf);
1.167 + gFileName[fileNum]=fileName;
1.168 + }
1.169 + else
1.170 + {
1.171 + TInt r=TheFs.Rename(gFileName[fileNum],fileName);
1.172 + if (r != KErrNone && r != KErrAlreadyExists)
1.173 + test.Printf(_L("Rename returned %d at line %d"), r, __LINE__);
1.174 + test(r==KErrNone || r==KErrAlreadyExists);
1.175 + if (r==KErrNone)
1.176 + gFileName[fileNum]=fileName;
1.177 + }
1.178 +End:
1.179 + if ((maxIterations%checkFrequency)==0)
1.180 + {
1.181 + test.Printf(_L("Iteration %d \r"),gMaxIterations-maxIterations);
1.182 + TInt r=TheFs.CheckDisk(gSessionPath);
1.183 + test(r==KErrNone || r==KErrNotSupported);
1.184 + TInt count=0;
1.185 + CDir* dirList;
1.186 + r=TheFs.GetDir(_L("*.*"),KEntryAttMaskSupported,ESortBySize,dirList);
1.187 + test(r==KErrNone);
1.188 + for(i=0;i<gMaxFiles;i++)
1.189 + {
1.190 + if (gFileName[i]==_L(""))
1.191 + continue;
1.192 + TEntry entry;
1.193 + entry=(*dirList)[count];
1.194 + TInt r=gFileName[i].MatchF(entry.iName);
1.195 + if (r==KErrNotFound)
1.196 + {
1.197 + //-- tests a dodgy case when the name has multiple trailing dots. They must have been removed by FS implementation
1.198 + TUint len=gFileName[i].Length();
1.199 + test(gFileName[i][len-1]=='.');
1.200 +
1.201 + //-- strip all trailing dots from the original name
1.202 + while(len)
1.203 + {
1.204 + if(gFileName[i][len-1]=='.')
1.205 + len--;
1.206 + else
1.207 + break;
1.208 + }
1.209 +
1.210 + TPtrC ptrFileName(gFileName[i].Ptr(), len);
1.211 +
1.212 + test(ptrFileName.CompareF(entry.iName) == 0);
1.213 +
1.214 +
1.215 + }
1.216 + count++;
1.217 + }
1.218 + delete dirList;
1.219 + }
1.220 + }
1.221 + test.Printf(_L("\n"),i);
1.222 + }
1.223 +
1.224 +//-----------------------------------------------------------------
1.225 +_LIT(KName1, "\\file1");
1.226 +_LIT(KName2, "\\file1.");
1.227 +_LIT(KName3, "\\file1..");
1.228 +_LIT(KName4, "\\file1...");
1.229 +_LIT(KExpectedName, "file1");
1.230 +
1.231 +void DoCheckTD_FN()
1.232 +{
1.233 + TInt nRes;
1.234 + TEntry entry;
1.235 +
1.236 + nRes = TheFs.Entry(KName1, entry);
1.237 + test(nRes == KErrNone);
1.238 + test(entry.iName.CompareF(KExpectedName) == 0);
1.239 +
1.240 + nRes = TheFs.Entry(KName2, entry);
1.241 + test(nRes == KErrNone);
1.242 + test(entry.iName.CompareF(KExpectedName) == 0);
1.243 +
1.244 + nRes = TheFs.Entry(KName3, entry);
1.245 + test(nRes == KErrNone);
1.246 + test(entry.iName.CompareF(KExpectedName) == 0);
1.247 +
1.248 + nRes = TheFs.Entry(KName3, entry);
1.249 + test(nRes == KErrNone);
1.250 + test(entry.iName.CompareF(KExpectedName) == 0);
1.251 +}
1.252 +
1.253 +/**
1.254 + Test that ALL trailing dots are removed from the file names by filsystem implementation
1.255 +*/
1.256 +void TestTrailingDots()
1.257 +{
1.258 + test.Next(_L("Test trailing dots"));
1.259 +
1.260 + //-- actually, all these APIs shall be tested:
1.261 + //-- CMountCB::MkDirL()
1.262 + //-- CMountCB::RmDirL()
1.263 + //-- CMountCB::DeleteL()
1.264 + //-- CMountCB::RenameL()
1.265 + //-- CMountCB::ReplaceL()
1.266 + //-- CMountCB::EntryL() const
1.267 + //-- CMountCB::SetEntryL()
1.268 + //-- CMountCB::FileOpenL()
1.269 + //-- CMountCB::DirOpenL()
1.270 + //-- CMountCB::ReadSectionL()
1.271 + //-- CFileCB::RenameL()
1.272 +
1.273 +
1.274 + TInt nRes;
1.275 + RFile file;
1.276 +
1.277 + //----- create and check "\\file1"
1.278 + nRes = file.Replace(TheFs, KName1, EFileWrite);
1.279 + test(nRes == KErrNone);
1.280 + file.Close();
1.281 +
1.282 + DoCheckTD_FN();
1.283 +
1.284 + nRes = TheFs.Delete(KName1);
1.285 + test(nRes == KErrNone);
1.286 +
1.287 +
1.288 + //----- create and check "\\file1."
1.289 + nRes = file.Replace(TheFs, KName2, EFileWrite);
1.290 + test(nRes == KErrNone);
1.291 + file.Close();
1.292 +
1.293 + DoCheckTD_FN();
1.294 +
1.295 + nRes = TheFs.Delete(KName2);
1.296 + test(nRes == KErrNone);
1.297 +
1.298 +
1.299 + //----- create and check "\\file1.."
1.300 + nRes = file.Replace(TheFs, KName3, EFileWrite);
1.301 + test(nRes == KErrNone);
1.302 + file.Close();
1.303 +
1.304 + DoCheckTD_FN();
1.305 +
1.306 + nRes = TheFs.Delete(KName3);
1.307 + test(nRes == KErrNone);
1.308 +
1.309 +
1.310 + //----- create and check "\\file1..."
1.311 + nRes = file.Replace(TheFs, KName4, EFileWrite);
1.312 + test(nRes == KErrNone);
1.313 + file.Close();
1.314 +
1.315 + DoCheckTD_FN();
1.316 +
1.317 + nRes = TheFs.Delete(KName4);
1.318 + test(nRes == KErrNone);
1.319 +
1.320 +
1.321 +}
1.322 +
1.323 +void CallTestsL()
1.324 +//
1.325 +// Do tests relative to session path
1.326 +//
1.327 + {
1.328 +
1.329 + TurnAllocFailureOff();
1.330 +
1.331 + CreateTestDirectory(_L("\\F32-TST\\TVFAT\\"));
1.332 +
1.333 + Test1();
1.334 + DeleteTestDirectory();
1.335 + CreateTestDirectory(_L("\\F32-TST\\TVFAT\\"));
1.336 + Test2();
1.337 +
1.338 + TestTrailingDots();
1.339 +
1.340 + DeleteTestDirectory();
1.341 + }
1.342 +