os/kernelhwsrv/kerneltest/f32test/server/t_dirs.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/server/t_dirs.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,957 @@
     1.4 +// Copyright (c) 1995-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_dirs.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <f32file.h>
    1.22 +#include <e32test.h>
    1.23 +#include "t_server.h"
    1.24 +
    1.25 +#include "f32_test_utils.h"
    1.26 +
    1.27 +using namespace F32_Test_Utils;
    1.28 +
    1.29 +
    1.30 +RTest test(_L("T_DIRS"));
    1.31 +
    1.32 +TTime gTimeNow;
    1.33 +TBool gTestedZ = EFalse;
    1.34 +TInt gDriveNum = -1;
    1.35 +
    1.36 +static void Test1()
    1.37 +//
    1.38 +// Make a directory with lots of entries
    1.39 +//
    1.40 +	{
    1.41 +
    1.42 +	RFile f;
    1.43 +	TInt maxEntry=56;
    1.44 +	test.Next(_L("Create a directory with 55 entries"));
    1.45 +	TFileName sessionPath;
    1.46 +	TInt r=TheFs.SessionPath(sessionPath);
    1.47 +	test(r==KErrNone);
    1.48 +	r=TheFs.MkDir(_L("\\F32-TST\\"));
    1.49 +	test((r==KErrNone)||(r==KErrAlreadyExists));
    1.50 +	r=TheFs.MkDir(_L("\\F32-TST\\TDIRS\\"));
    1.51 +	test((r==KErrNone)||(r==KErrAlreadyExists));
    1.52 +	
    1.53 +	for (TInt i=0;i<maxEntry;i++)
    1.54 +		{
    1.55 +		TFileName baseName=_L("\\F32-TST\\TDIRS\\FILE");
    1.56 +		baseName.AppendNum(i);
    1.57 +		r=f.Replace(TheFs,baseName,EFileRead);
    1.58 +		test(r==KErrNone);
    1.59 +		r=f.Write(_L8("Hello World"));
    1.60 +		test(r==KErrNone);
    1.61 +		f.Close();
    1.62 +		}
    1.63 +	test.Next(_L("Test all entries have been created successfully."));
    1.64 +	for (TInt j=0;j<=maxEntry;j++)
    1.65 +		{
    1.66 +		TFileName baseName=_L("\\F32-TST\\TDIRS\\FILE");
    1.67 +		baseName.AppendNum(j);
    1.68 +		TInt r=f.Open(TheFs,baseName,EFileRead);
    1.69 +		if (r!=KErrNone)
    1.70 +			{
    1.71 +			test(r==KErrNotFound && j==maxEntry);
    1.72 +			return;
    1.73 +			}
    1.74 +		TBuf8<16> data;
    1.75 +		r=f.Read(data);
    1.76 +		test(r==KErrNone);
    1.77 +		test(data==_L8("Hello World"));
    1.78 +		f.Close();
    1.79 +		}
    1.80 +	}
    1.81 +	
    1.82 +static void Test2()
    1.83 +//
    1.84 +// List all directory entries
    1.85 +//
    1.86 +	{
    1.87 +	
    1.88 +	test.Printf(_L("List all entries in directory %S\n"),&gSessionPath);
    1.89 +	RDir d;
    1.90 +
    1.91 +	TInt r=d.Open(TheFs,gSessionPath,KEntryAttMaskSupported);
    1.92 +	if (r==KErrNone)
    1.93 +		{
    1.94 +		TEntry e;
    1.95 +		while ((r=d.Read(e))==KErrNone)
    1.96 +			{
    1.97 +			if (e.IsDir())
    1.98 +				test.Printf(_L("%- 20S <DIR>\n"),&e.iName);
    1.99 +			else
   1.100 +				test.Printf(_L("%- 20S %+ 8d\n"),&e.iName,e.iSize);
   1.101 +			}
   1.102 +		d.Close();
   1.103 +		if (r!=KErrEof)
   1.104 +			test.Printf(_L("Error %d\n"),r);
   1.105 +		}
   1.106 +	else
   1.107 +		test.Printf(_L("Error %d\n"),r);	
   1.108 +	}
   1.109 +
   1.110 +static void TestZ()
   1.111 +//
   1.112 +// Check you cannot open a directory on a file
   1.113 +//
   1.114 +	{
   1.115 +
   1.116 +	test.Next(_L("Open files and directories on Z:"));
   1.117 +	TEntry entry;
   1.118 +	RDir d;
   1.119 +	
   1.120 +	TInt r=d.Open(TheFs,PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("\\Sys\\Bin\\ESHELL.EXE\\*"):_L("\\System\\Bin\\ESHELL.EXE\\*"),KEntryAttMaskSupported);
   1.121 +	test(r==KErrPathNotFound);
   1.122 +	
   1.123 +	r=d.Open(TheFs,PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("\\Sys\\Bin\\ESHELL.EXE"):_L("\\System\\Bin\\ESHELL.EXE"),KEntryAttMaskSupported);
   1.124 +	test(r==KErrNone);
   1.125 +	
   1.126 +	r=d.Read(entry);
   1.127 +	if (r==KErrEof)
   1.128 +		{
   1.129 +		test.Printf(_L("Error: EShell.EXE not found\n"));
   1.130 +		//test.Getch();
   1.131 +		}
   1.132 +	else
   1.133 +		{
   1.134 +		test(r==KErrNone);
   1.135 +		test(entry.iName.FindF(_L("ESHELL.EXE"))>=0);
   1.136 +		r=d.Read(entry);
   1.137 +		test(r==KErrEof);
   1.138 +		}
   1.139 +	d.Close();
   1.140 +
   1.141 +	r=d.Open(TheFs,_L("\\*.XQP"),KEntryAttMaskSupported);
   1.142 +	test(r==KErrNone);
   1.143 +	r=d.Read(entry);
   1.144 +	test(r==KErrEof);
   1.145 +	d.Close();
   1.146 +
   1.147 +	r=d.Open(TheFs,PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("\\Sys\\Bin\\"):_L("\\System\\Bin\\"),KEntryAttMaskSupported);
   1.148 +	test(r==KErrNone);
   1.149 +	r=d.Read(entry);
   1.150 +	
   1.151 +	if (r==KErrEof)
   1.152 +		{
   1.153 +		test.Printf(_L("No files found\n"));
   1.154 +		d.Close();
   1.155 +		}
   1.156 +	else
   1.157 +		{
   1.158 +		test(r==KErrNone);
   1.159 +		test.Printf(_L("First Entry = %S\n"),&entry.iName);
   1.160 +		r=d.Read(entry);
   1.161 +		test(r==KErrNone);
   1.162 +		test.Printf(_L("Second Entry = %S\n"),&entry.iName);
   1.163 +		d.Close();
   1.164 +		}
   1.165 +
   1.166 +	r=d.Open(TheFs,_L("\\*"),KEntryAttMaskSupported);
   1.167 +	test(r==KErrNone);
   1.168 +	d.Close();
   1.169 +	r=d.Open(TheFs,PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("\\Sys\\Bin\\*"):_L("\\System\\Bin\\*"),KEntryAttMaskSupported);
   1.170 +	test(r==KErrNone);
   1.171 +	d.Close();
   1.172 +	}
   1.173 +
   1.174 +static void Test3()
   1.175 +//
   1.176 +// Check you cannot open a directory on a file
   1.177 +//
   1.178 +	{
   1.179 +
   1.180 +	test.Next(_L("Open files and directories"));
   1.181 +	TEntry entry;
   1.182 +	RFile f;
   1.183 +	TInt r=f.Replace(TheFs,_L("\\F32-TST\\TDIRS\\TESTFILEORISITA.DIR"),EFileWrite);
   1.184 +	test(r==KErrNone);
   1.185 +	r=f.Write(_L8("TESTDATATESTDATATESTDATATESTDATATESTDATATESTDATATESTDATATESTDATATESTDATATESTDATATESTDATATESTDATA"));
   1.186 +	test(r==KErrNone);
   1.187 +	r=TheFs.Delete(_L("\\F32-TST\\TDIRS\\TESTFILEORISITA.DIR"));
   1.188 +	test(r==KErrInUse);
   1.189 +	f.Close();
   1.190 +	RDir d;
   1.191 +	r=d.Open(TheFs,_L("\\F32-TST\\TDIRS\\TESTFILEORISITA.DIR\\*"),KEntryAttMaskSupported);
   1.192 +	test(r==KErrPathNotFound);
   1.193 +	r=d.Open(TheFs,_L("\\F32-TST\\TDIRS\\*.XQP"),KEntryAttMaskSupported);
   1.194 +	test(r==KErrNone);
   1.195 +	r=d.Read(entry);
   1.196 +	test(r==KErrEof);
   1.197 +	d.Close();
   1.198 +	r=d.Open(TheFs,_L("\\F32-TST\\TDIRS\\TESTFILEORISITA.DIR"),KEntryAttMaskSupported);
   1.199 +	test(r==KErrNone);
   1.200 +	r=d.Read(entry);
   1.201 +	test(r==KErrNone);
   1.202 +	test(entry.iName.FindF(_L("TESTFILEORISITA.DIR"))>=0);
   1.203 +	r=d.Read(entry);
   1.204 +	test(r==KErrEof);
   1.205 +	d.Close();
   1.206 +	r=d.Open(TheFs,_L("\\"),KEntryAttMaskSupported);
   1.207 +	test(r==KErrNone);
   1.208 +	d.Close();
   1.209 +	r=d.Open(TheFs,_L("\\F32-TST\\"),KEntryAttMaskSupported);
   1.210 +	test(r==KErrNone);
   1.211 +	d.Close();
   1.212 +	r=d.Open(TheFs,_L("\\*"),KEntryAttMaskSupported);
   1.213 +	test(r==KErrNone);
   1.214 +	d.Close();
   1.215 +	r=d.Open(TheFs,_L("\\F32-TST\\*"),KEntryAttMaskSupported);
   1.216 +	test(r==KErrNone);
   1.217 +	d.Close();
   1.218 +	
   1.219 +	// create a small file on the root
   1.220 +	test(f.Replace(TheFs, _L("\\TEST.FILE"), EFileWrite) == KErrNone);
   1.221 +	test(f.Write(_L8("1234567890987654321234567890")) == KErrNone);
   1.222 +	f.Close();
   1.223 +	// try some directory operations on the file
   1.224 +	test(TheFs.RmDir(_L("\\TEST.FILE\\")) == KErrPathNotFound);
   1.225 +	test(TheFs.RmDir(_L("\\TEST.FILE\\ZZZ\\")) == KErrPathNotFound);
   1.226 +	test(TheFs.MkDir(_L("\\TEST.FILE\\ZZZ\\")) == KErrPathNotFound);
   1.227 +	// cleanup
   1.228 +	TheFs.Delete(_L("\\TEST.FILE"));	
   1.229 +	
   1.230 +	
   1.231 +	r=TheFs.MkDir(_L("\\F32-TST\\EMPTY\\"));
   1.232 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.233 +	r=d.Open(TheFs,_L("\\F32-TST\\EMPTY\\*"),KEntryAttMaskSupported);
   1.234 +	test(r==KErrNone);
   1.235 +//	r=TheFs.RmDir(_L("\\F32-TST\\EMPTY\\"));
   1.236 +	r=d.Read(entry);
   1.237 +	test(r==KErrEof);
   1.238 +//	r=TheFs.RmDir(_L("\\F32-TST\\EMPTY\\"));
   1.239 +//	test(r==KErrInUse);
   1.240 +	r=d.Read(entry);
   1.241 +	r=d.Read(entry);
   1.242 +	r=d.Read(entry);
   1.243 +	d.Close();
   1.244 +	r=TheFs.RmDir(_L("\\F32-TST\\EMPTY\\"));
   1.245 +	test(r==KErrNone);
   1.246 +	}
   1.247 +
   1.248 +
   1.249 +static void CreateSortNoneTestDirectoryStructure()
   1.250 +//
   1.251 +// Create files
   1.252 +//
   1.253 +	{
   1.254 +//	Delete the directory to be tested if it already exists as a result of this
   1.255 +//	test being run previously.  It's necessary remove it and then recreate it 
   1.256 +//	because a later test relies on the time of file/directory creation to be
   1.257 +//	the time this function was run...
   1.258 +	
   1.259 +	CFileMan* fMan=CFileMan::NewL(TheFs);
   1.260 +	test(fMan!=NULL);
   1.261 +	TInt r=fMan->RmDir(_L("\\F32-TST\\TDIRS\\SORT_NONE\\"));
   1.262 +	test((r==KErrNone)||(r==KErrPathNotFound));
   1.263 +	delete fMan;	
   1.264 +
   1.265 +	gTimeNow.HomeTime();	//	Set global TTime gTimeNow to time now - for later tests
   1.266 +	r=TheFs.MkDirAll(_L("\\F32-TST\\TDIRS\\SORT_NONE\\"));
   1.267 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.268 +	MakeFile(_L("\\f32-tst\\tdirs\\sort_none\\file1.txt"));
   1.269 +	r=TheFs.MkDir(_L("\\F32-TST\\TDIRS\\SORT_NONE\\FILE_DIR1.APP\\"));
   1.270 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.271 +	MakeFile(_L("\\f32-tst\\tdirs\\sort_none\\file1.app"));
   1.272 +	r=TheFs.MkDir(_L("\\F32-TST\\TDIRS\\SORT_NONE\\FILE_DIR2.TXT\\"));
   1.273 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.274 +	MakeFile(_L("\\f32-tst\\tdirs\\sort_none\\file2.txt"));
   1.275 +	r=TheFs.MkDir(_L("\\F32-TST\\TDIRS\\SORT_NONE\\FILE_DIR3.APP\\"));
   1.276 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.277 +	MakeFile(_L("\\f32-tst\\tdirs\\sort_none\\ZZZZ"));
   1.278 +	MakeFile(_L("\\f32-tst\\tdirs\\sort_none\\AAAA"));
   1.279 +	MakeFile(_L("\\f32-tst\\tdirs\\sort_none\\WWWW"));
   1.280 +	MakeFile(_L("\\f32-tst\\tdirs\\sort_none\\file2.app"));
   1.281 +	MakeFile(_L("\\f32-tst\\tdirs\\sort_none\\file3.txt"));
   1.282 +	MakeFile(_L("\\f32-tst\\tdirs\\sort_none\\file3.app"));
   1.283 +	MakeFile(_L("\\f32-tst\\tdirs\\sort_none\\NOEXT1"));
   1.284 +	MakeFile(_L("\\f32-tst\\tdirs\\sort_none\\NOEXT2"));
   1.285 +	MakeFile(_L("\\f32-tst\\tdirs\\sort_none\\EXTMISSING"));
   1.286 +	}
   1.287 +
   1.288 +static void Test4()
   1.289 +//
   1.290 +// Test ESortNone
   1.291 +//
   1.292 +	{
   1.293 +
   1.294 +	test.Next(_L("Test ESortNone"));
   1.295 +	CreateSortNoneTestDirectoryStructure();
   1.296 +	CDir* dir;
   1.297 +	CDir* dirSorted;
   1.298 +	
   1.299 +//
   1.300 +// GetDir OOM failure passes 'callback' test from client side but not server side
   1.301 +//
   1.302 +	TheFs.SetAllocFailure(gAllocFailOff);
   1.303 +
   1.304 +	TInt r=TheFs.GetDir(_L("\\f32-tst\\tdirs\\sort_none\\*"),KEntryAttMaskSupported,ESortNone,dir);
   1.305 +	test(r==KErrNone);
   1.306 +	TInt count=dir->Count();
   1.307 +	test(count==15);
   1.308 +	r=TheFs.GetDir(_L("\\f32-tst\\tdirs\\sort_none\\*"),KEntryAttMaskSupported,ESortByName,dirSorted);
   1.309 +	test(r==KErrNone);
   1.310 +	test(dirSorted->Count()==15);
   1.311 +	delete dirSorted;
   1.312 +	delete dir;
   1.313 +
   1.314 +	r=TheFs.GetDir(_L("\\f32-tst\\tdirs\\sort_none\\*.txt"),KEntryAttNormal,ESortNone,dir);
   1.315 +	test(r==KErrNone);
   1.316 +	test(dir->Count()==3);
   1.317 +	delete dir;
   1.318 +	r=TheFs.GetDir(_L("\\f32-tst\\tdirs\\sort_none\\*.app"),KEntryAttNormal,ESortNone,dir);
   1.319 +	test(r==KErrNone);
   1.320 +	test(dir->Count()==3);
   1.321 +	delete dir;
   1.322 +	r=TheFs.GetDir(_L("\\f32-tst\\tdirs\\sort_none\\*.app"),KEntryAttNormal|KEntryAttDir,ESortNone,dir);
   1.323 +	test(r==KErrNone);
   1.324 +	test(dir->Count()==5);
   1.325 +	delete dir;
   1.326 +	r=TheFs.GetDir(_L("\\f32-tst\\tdirs\\sort_none\\*.app"),KEntryAttNormal|KEntryAttDir,ESortNone|EDirsFirst,dir);
   1.327 +	test(r==KErrNone);
   1.328 +	test(dir->Count()==5);
   1.329 +	delete dir;
   1.330 +	r=TheFs.GetDir(_L("\\f32-tst\\tdirs\\sort_none\\*.app"),KEntryAttNormal|KEntryAttDir,ESortNone|EDirsLast,dir);
   1.331 +	test(r==KErrNone);
   1.332 +	test(dir->Count()==5);
   1.333 +	delete dir;
   1.334 +
   1.335 +	TheFs.SetAllocFailure(gAllocFailOn);
   1.336 +	}
   1.337 +
   1.338 +static void Test5()
   1.339 +//
   1.340 +// Test return values
   1.341 +//
   1.342 +	{
   1.343 +
   1.344 +	test.Next(_L("Test return values"));
   1.345 +	RDir dir;
   1.346 +	TInt r=dir.Open(TheFs,_L("\\DoesNotExist\\*"),KEntryAttMaskSupported);
   1.347 +	test(r==KErrPathNotFound);
   1.348 +	r=dir.Open(TheFs,_L("\\"),KEntryAttMaskSupported);
   1.349 +	test(r==KErrNone);
   1.350 +	dir.Close();
   1.351 +	}
   1.352 +
   1.353 +
   1.354 +static void Test6()
   1.355 +//
   1.356 +// Test that "*.*" matches all files/directories
   1.357 +//
   1.358 +	{
   1.359 +
   1.360 +	test.Next(_L("Test *.* matches all files"));
   1.361 +	CDir* dirList;
   1.362 +	TInt r=TheFs.GetDir(_L("\\f32-tst\\tdirs\\sort_none\\*.*"),KEntryAttNormal|KEntryAttDir,ESortByName|EDirsLast,dirList);
   1.363 +	test(r==KErrNone);
   1.364 +	TInt count=dirList->Count();
   1.365 +	test(count==15);
   1.366 +	TEntry entry=(*dirList)[0];
   1.367 +	test(entry.iName.FindF(_L("AAAA"))>=0);
   1.368 +	entry=(*dirList)[1];
   1.369 +	test(entry.iName.FindF(_L("EXTMISSING"))>=0);
   1.370 +	entry=(*dirList)[2];
   1.371 +	test(entry.iName.FindF(_L("FILE1.APP"))>=0);
   1.372 +	entry=(*dirList)[3];
   1.373 +	test(entry.iName.FindF(_L("FILE1.TXT"))>=0);
   1.374 +	entry=(*dirList)[4];
   1.375 +	test(entry.iName.FindF(_L("FILE2.APP"))>=0);
   1.376 +	entry=(*dirList)[5];
   1.377 +	test(entry.iName.FindF(_L("FILE2.TXT"))>=0);
   1.378 +	entry=(*dirList)[6];
   1.379 +	test(entry.iName.FindF(_L("FILE3.APP"))>=0);
   1.380 +	entry=(*dirList)[7];
   1.381 +	test(entry.iName.FindF(_L("FILE3.TXT"))>=0);
   1.382 +	entry=(*dirList)[8];
   1.383 +	test(entry.iName.FindF(_L("NOEXT1"))>=0);
   1.384 +	entry=(*dirList)[9];
   1.385 +	test(entry.iName.FindF(_L("NOEXT2"))>=0);
   1.386 +	entry=(*dirList)[10];
   1.387 +	test(entry.iName.FindF(_L("WWWW"))>=0);
   1.388 +	entry=(*dirList)[11];
   1.389 +	test(entry.iName.FindF(_L("ZZZZ"))>=0);
   1.390 +	entry=(*dirList)[12];
   1.391 +	test(entry.iName.FindF(_L("FILE_DIR1.APP"))>=0);
   1.392 +	entry=(*dirList)[13];
   1.393 +	test(entry.iName.FindF(_L("FILE_DIR2.TXT"))>=0);
   1.394 +	entry=(*dirList)[14];
   1.395 +	test(entry.iName.FindF(_L("FILE_DIR3.APP"))>=0);
   1.396 +	delete dirList;
   1.397 +
   1.398 +	RDir dir;
   1.399 +	r=dir.Open(TheFs,_L("\\f32-tst\\tdirs\\sort_none\\*.*"),KEntryAttNormal|KEntryAttDir);
   1.400 +	test(r==KErrNone);
   1.401 +	
   1.402 +	TTime time;
   1.403 +	TInt64 difference;
   1.404 +	TInt64 maxOK=1000000;
   1.405 +	maxOK*=60;
   1.406 +	maxOK*=3;
   1.407 +
   1.408 +	for (TInt i=0; i<15; i++)
   1.409 +		{
   1.410 +		r=dir.Read(entry);
   1.411 +		test(r==KErrNone);
   1.412 +		time=entry.iModified;
   1.413 +		difference=time.Int64()-gTimeNow.Int64();
   1.414 +		test(difference<maxOK);
   1.415 +		}
   1.416 +
   1.417 +	r=dir.Read(entry);
   1.418 +	test(r==KErrEof);
   1.419 +	dir.Close();
   1.420 +
   1.421 +	TheFs.SetAllocFailure(gAllocFailOn);
   1.422 +	}
   1.423 +
   1.424 +
   1.425 +static void Test7()
   1.426 +//
   1.427 +// Fill up the root directory
   1.428 +//
   1.429 +	{
   1.430 +    test.Next(_L("Fill up the root directory"));
   1.431 +    
   1.432 +    if(!Is_Fat12(TheFs, gDriveNum) && !Is_Fat16(TheFs, gDriveNum))
   1.433 +        {
   1.434 +        test.Printf(_L("Skipping. Applicable for FAT12/16 only!\n"));
   1.435 +        return;
   1.436 +        }    
   1.437 +
   1.438 +    TInt r = FormatDrive(TheFs, gDriveNum, ETrue);
   1.439 +    test(r==KErrNone);
   1.440 +
   1.441 +	TBuf<32> baseName=_L("\\RD");
   1.442 +	TBuf<32> id;
   1.443 +	TBuf<32> fileName;
   1.444 +	TInt count=0;
   1.445 +
   1.446 +	RFile f;
   1.447 +	TParsePtrC parser(gSessionPath);
   1.448 +	FOREVER
   1.449 +		{
   1.450 +		id.Num(count+1);
   1.451 +		fileName=parser.Drive();
   1.452 +		fileName+=baseName;
   1.453 +		fileName+=id;
   1.454 +		TInt r=f.Replace(TheFs,fileName,EFileWrite);
   1.455 +		if(r==KErrDirFull)
   1.456 +			{
   1.457 +			break;
   1.458 +			}
   1.459 +		test(r==KErrNone);
   1.460 +		f.Close();
   1.461 +		count++;
   1.462 +		if(count >= 1000)
   1.463 +			{
   1.464 +			break;
   1.465 +			}
   1.466 +		test.Printf(_L("CreateFile	:	%d	: %S\r"),count,&fileName);
   1.467 +		}
   1.468 +	test.Printf(_L("\n"));
   1.469 +
   1.470 +	while (count)
   1.471 +		{
   1.472 +		id.Num(count);
   1.473 +		fileName=parser.Drive();
   1.474 +		fileName+=baseName;
   1.475 +		fileName+=id;
   1.476 +		TInt r=TheFs.Delete(fileName);
   1.477 +		test(r==KErrNone);
   1.478 +		test.Printf(_L("DeleteFile	:	%d	: %S\r"),count,&fileName);
   1.479 +		--count;
   1.480 +		}
   1.481 +	test.Printf(_L("\n"));
   1.482 +
   1.483 +	test.Next(_L("Long filenames in root"));
   1.484 +	TFileName longFileName;
   1.485 +	longFileName.SetLength(254);
   1.486 +//	Mem::Fill((TUint8*)longFileName.Ptr(),254,'A');
   1.487 +	Mem::Fill((TUint8*)longFileName.Ptr(),254*sizeof(TText),'A');
   1.488 +	longFileName[0]='\\';
   1.489 +	longFileName[253]='\\';
   1.490 +	r=TheFs.MkDir(longFileName);
   1.491 +	test(r==KErrNone);
   1.492 +	CDir* dirList=NULL;
   1.493 +	r=TheFs.GetDir(longFileName,KEntryAttMaskSupported,ESortByName,dirList);
   1.494 +	test(r==KErrNone);
   1.495 +	count=dirList->Count();
   1.496 +	test(count==0);
   1.497 +	delete dirList;
   1.498 +	TParse parse;
   1.499 +	r=TheFs.Parse(longFileName,parse);
   1.500 +	test(r==KErrNone);
   1.501 +	TEntry entry;
   1.502 +	r=TheFs.Entry(longFileName,entry);
   1.503 +	test(r==KErrNone);
   1.504 +	r=TheFs.SetSessionPath(longFileName);
   1.505 +	test(r==KErrNone);
   1.506 +	r=TheFs.GetDir(longFileName,KEntryAttMaskSupported,ESortByName,dirList);
   1.507 +	test(r==KErrNone);
   1.508 +	count=dirList->Count();
   1.509 +	test(count==0);
   1.510 +	delete dirList;
   1.511 +	r=TheFs.Parse(longFileName,_L("*"),parse);
   1.512 +	test(r==KErrBadName);
   1.513 +	r=f.Open(TheFs,_L("asdf.asdf"),0);
   1.514 +	test(r==KErrBadName);
   1.515 +	r=TheFs.Entry(longFileName,entry);
   1.516 +	test(r==KErrNone);
   1.517 +	r=TheFs.RmDir(longFileName);
   1.518 +	test(r==KErrNone);
   1.519 +	}
   1.520 +
   1.521 +static void Test8()
   1.522 +//
   1.523 +// Regression tests
   1.524 +//
   1.525 +	{
   1.526 +
   1.527 +	test.Next(_L("Open dir and change drives"));
   1.528 +	MakeDir(_L("C:\\MOON\\"));
   1.529 +	RDir dir;
   1.530 +	TInt r=dir.Open(TheFs,_L("C:\\MOON\\"),0);
   1.531 +	test(r==KErrNone);
   1.532 +	TFileName driveName;
   1.533 +	r=TheFs.GetDriveName(11,driveName);
   1.534 +	test(r==KErrNone);
   1.535 +	TEntryArray entryArray;
   1.536 +	r=dir.Read(entryArray);
   1.537 +	test(r==KErrEof);
   1.538 +	test(entryArray.Count()==0);
   1.539 +	dir.Close();
   1.540 +	r=TheFs.RmDir(_L("C:\\MOON\\"));
   1.541 +	test(r==KErrNone);
   1.542 +
   1.543 +	test.Next(_L("MkDir all on nonexistent drive"));
   1.544 +	r=TheFs.MkDirAll(_L("L:\\MOON"));
   1.545 +	test((r==KErrNotReady)||(r==KErrPathNotFound));
   1.546 +	}
   1.547 +
   1.548 +static void CleanupL()
   1.549 +//
   1.550 +// Clean up tests
   1.551 +//
   1.552 +	{
   1.553 +
   1.554 +	test.Next(_L("Delete test directory"));
   1.555 +	CFileMan* fMan=CFileMan::NewL(TheFs);
   1.556 +	TInt r=fMan->RmDir(gSessionPath);
   1.557 +	test(r==KErrNone);
   1.558 +	r=fMan->Delete(_L("\\Filluptherootdir*"));
   1.559 +	test(r==KErrNone || r==KErrNotFound);
   1.560 +	delete fMan;
   1.561 +	}
   1.562 +
   1.563 +static void Test9()
   1.564 +//
   1.565 +// Test directories with trailing dots (ref. DEF047684) 
   1.566 +//
   1.567 +	{
   1.568 +
   1.569 +	test.Next(_L("Testing directory names with trailing dots"));
   1.570 +	TInt r;
   1.571 +	r=TheFs.MkDir(_L("\\test9..\\"));
   1.572 +	test(r==KErrBadName);
   1.573 +	r=TheFs.MkDir(_L("\\test9\\"));
   1.574 +	test((r==KErrNone)||(r==KErrAlreadyExists));
   1.575 +	r=TheFs.Rename(_L("\\test9\\"),_L("\\test9..\\"));
   1.576 +	test(r==KErrBadName);
   1.577 +	r= TheFs.RmDir(_L("\\test9\\"));
   1.578 +	test((r==KErrNone));
   1.579 +	r=TheFs.MkDir(_L("\\t.\\"));
   1.580 +	test(r==KErrBadName);
   1.581 +	}
   1.582 +
   1.583 +
   1.584 +//
   1.585 +// Path and File names for sorting by name
   1.586 +//
   1.587 +// The correctly sorted directory listing should be:
   1.588 +//
   1.589 +//     b.doc
   1.590 +//     bb.doc
   1.591 +//     bs.doc
   1.592 +//
   1.593 +_LIT(KSortByNamePath, "\\F32-TST\\TDIRS\\SORT_NAME\\");
   1.594 +_LIT(KFileBS,         "bs.doc");
   1.595 +_LIT(KFileBB,         "bb.doc");
   1.596 +_LIT(KFileB,          "b.doc");
   1.597 +_LIT(KSortAll,        "*.*");
   1.598 +_LIT(KPrintFileName,  "%S\n");
   1.599 +
   1.600 +
   1.601 +static void DeleteTestDirectoryStructure(const TDesC& aPath)
   1.602 +//
   1.603 +//	Delete the directory to be tested if it already exists as a result of this
   1.604 +//	test being run previously.
   1.605 +//
   1.606 +	{
   1.607 +	
   1.608 +	CFileMan* fMan=CFileMan::NewL(TheFs);
   1.609 +	test(fMan!=NULL);
   1.610 +	TInt r=fMan->RmDir(aPath);
   1.611 +	test((r==KErrNone)||(r==KErrPathNotFound));
   1.612 +	delete fMan;	
   1.613 +	}
   1.614 +
   1.615 +
   1.616 +static void CreateTestDirectoryStructure(const TDesC& aPath, const TDesC** aFileArray, TInt aNumFiles)
   1.617 +//
   1.618 +// Create files
   1.619 +//
   1.620 +	{
   1.621 +	DeleteTestDirectoryStructure(aPath);	
   1.622 +
   1.623 +	gTimeNow.HomeTime();	//	Set global TTime gTimeNow to time now - for later tests
   1.624 +	TInt r=TheFs.MkDirAll(aPath);
   1.625 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.626 +
   1.627 +	TBuf<128> fileName;
   1.628 +	for (TInt i = 0; i < aNumFiles; i++)
   1.629 +		{
   1.630 +		fileName = aPath;
   1.631 +		fileName.Append(*aFileArray[i]);
   1.632 +		MakeFile(fileName);
   1.633 +		}
   1.634 +	}
   1.635 +
   1.636 +
   1.637 +static void TestSortByName()
   1.638 +//
   1.639 +// Test that sorting by name works for different length filenames.
   1.640 +//
   1.641 +	{
   1.642 +	const TDesC* theFiles[] = {&KFileBS, &KFileBB, &KFileB};
   1.643 +	TInt numFiles = sizeof(theFiles)/sizeof(theFiles[0]);
   1.644 +	CreateTestDirectoryStructure(KSortByNamePath, theFiles, numFiles);
   1.645 +
   1.646 +	test.Next(_L("Test ESortByName"));
   1.647 +	CDir* dirList;
   1.648 +	TBuf<128> sortSpec(KSortByNamePath);
   1.649 +	sortSpec.Append(KSortAll);
   1.650 +	TInt r=TheFs.GetDir(sortSpec, KEntryAttNormal | KEntryAttDir, ESortByName | EDirsLast, dirList);
   1.651 +	test(r==KErrNone);
   1.652 +	TInt count=dirList->Count();
   1.653 +	test(count==numFiles);
   1.654 +
   1.655 +
   1.656 +	TInt i;
   1.657 +	for (i = 0; i < count; i++)
   1.658 +		{
   1.659 +		test.Printf(KPrintFileName, &(*dirList)[i].iName);
   1.660 +		}
   1.661 +	
   1.662 +	TEntry entry=(*dirList)[0];
   1.663 +	test(entry.iName.FindF(KFileB)>=0);
   1.664 +	entry=(*dirList)[1];
   1.665 +	test(entry.iName.FindF(KFileBB)>=0);
   1.666 +	entry=(*dirList)[2];
   1.667 +	test(entry.iName.FindF(KFileBS)>=0);
   1.668 +	delete dirList;
   1.669 +	dirList = 0;
   1.670 +
   1.671 +
   1.672 +	test.Next(_L("Test ESortByName (descending)"));
   1.673 +
   1.674 +
   1.675 +	r=TheFs.GetDir(sortSpec, KEntryAttNormal | KEntryAttDir, ESortByName | EDirsLast | EDescending, dirList);
   1.676 +	test(r==KErrNone);
   1.677 +	count=dirList->Count();
   1.678 +	test(count==numFiles);
   1.679 +
   1.680 +
   1.681 +	for (i = 0; i < count; i++)
   1.682 +		{
   1.683 +		test.Printf(KPrintFileName, &(*dirList)[i].iName);
   1.684 +		}
   1.685 +
   1.686 +	
   1.687 +	entry=(*dirList)[0];
   1.688 +	test(entry.iName.FindF(KFileBS)>=0);
   1.689 +	entry=(*dirList)[1];
   1.690 +	test(entry.iName.FindF(KFileBB)>=0);
   1.691 +	entry=(*dirList)[2];
   1.692 +	test(entry.iName.FindF(KFileB)>=0);
   1.693 +	delete dirList;
   1.694 +	dirList = 0;
   1.695 +	
   1.696 +	
   1.697 +	DeleteTestDirectoryStructure(KSortByNamePath);
   1.698 +	}
   1.699 +
   1.700 +
   1.701 +
   1.702 +//
   1.703 +// Path and File names for sorting by extension
   1.704 +//
   1.705 +// The correctly sorted directory listing should be:
   1.706 +//
   1.707 +//     sortext.a
   1.708 +//     sortext.bbb.a
   1.709 +//     sortext1.ddd.a
   1.710 +//     sortext.aaa.b
   1.711 +//     sortext.b
   1.712 +//     sortext.c
   1.713 +//     sortext.ccc.c
   1.714 +//
   1.715 +// as we should sort by the substring after the last '.'
   1.716 +//
   1.717 +_LIT(KSortByExtPath, "\\F32-TST\\TDIRS\\SORT_EXT\\");
   1.718 +_LIT(KFile1,         "sortext.aaa.b");
   1.719 +_LIT(KFile2,         "sortext.bbb.a");
   1.720 +_LIT(KFile3,         "sortext.ccc.c");
   1.721 +_LIT(KFile4,         "sortext1.ddd.a");
   1.722 +_LIT(KFile5,         "sortext.a");
   1.723 +_LIT(KFile6,         "sortext.b");
   1.724 +_LIT(KFile7,         "sortext.c");
   1.725 +
   1.726 +
   1.727 +static void TestSortByExt()
   1.728 +//
   1.729 +// Test that sorting by extension works. This includes filenames
   1.730 +// that contain multiple .'s
   1.731 +//
   1.732 +	{
   1.733 +	const TDesC* theFiles[] = {&KFile1, &KFile2, &KFile3, &KFile4, &KFile5, &KFile6, &KFile7};
   1.734 +	TInt numFiles = sizeof(theFiles)/sizeof(theFiles[0]);
   1.735 +	CreateTestDirectoryStructure(KSortByExtPath, theFiles, numFiles);
   1.736 +
   1.737 +	test.Next(_L("Test ESortByExt"));
   1.738 +
   1.739 +	CDir* dirList;
   1.740 +	TBuf<128> sortSpec(KSortByExtPath);
   1.741 +	sortSpec.Append(KSortAll);
   1.742 +	TInt r=TheFs.GetDir(sortSpec, KEntryAttNormal | KEntryAttDir, ESortByExt | EDirsLast, dirList);
   1.743 +	test(r==KErrNone);
   1.744 +	TInt count=dirList->Count();
   1.745 +	test(count==numFiles);
   1.746 +
   1.747 +
   1.748 +	TInt i;
   1.749 +	for (i = 0; i < count; i++)
   1.750 +		{
   1.751 +		test.Printf(KPrintFileName, &(*dirList)[i].iName);
   1.752 +		}
   1.753 +	
   1.754 +	
   1.755 +	//
   1.756 +	// Verify that the files have been sorted correctly by extension
   1.757 +	//
   1.758 +	TEntry entry=(*dirList)[0];
   1.759 +	test(entry.iName.FindF(KFile5)>=0);
   1.760 +	entry=(*dirList)[1];
   1.761 +	test(entry.iName.FindF(KFile2)>=0);
   1.762 +	entry=(*dirList)[2];
   1.763 +	test(entry.iName.FindF(KFile4)>=0);
   1.764 +	entry=(*dirList)[3];
   1.765 +	test(entry.iName.FindF(KFile1)>=0);
   1.766 +	entry=(*dirList)[4];
   1.767 +	test(entry.iName.FindF(KFile6)>=0);
   1.768 +	entry=(*dirList)[5];
   1.769 +	test(entry.iName.FindF(KFile7)>=0);
   1.770 +	entry=(*dirList)[6];
   1.771 +	test(entry.iName.FindF(KFile3)>=0);
   1.772 +	delete dirList;
   1.773 +	dirList = 0;
   1.774 +
   1.775 +
   1.776 +	test.Next(_L("Test ESortByExt (descending)"));
   1.777 +
   1.778 +	r=TheFs.GetDir(sortSpec, KEntryAttNormal | KEntryAttDir, ESortByExt | EDirsLast | EDescending, dirList);
   1.779 +	test(r==KErrNone);
   1.780 +	count=dirList->Count();
   1.781 +	test(count==numFiles);
   1.782 +
   1.783 +
   1.784 +	for (i = 0; i < count; i++)
   1.785 +		{
   1.786 +		test.Printf(KPrintFileName, &(*dirList)[i].iName);
   1.787 +		}
   1.788 +	
   1.789 +	
   1.790 +	//
   1.791 +	// Verify that the files have been sorted correctly by extension
   1.792 +	// Note that this listing should be the reverse of that above.
   1.793 +	//
   1.794 +	entry=(*dirList)[0];
   1.795 +	test(entry.iName.FindF(KFile3)>=0);
   1.796 +	entry=(*dirList)[1];
   1.797 +	test(entry.iName.FindF(KFile7)>=0);
   1.798 +	entry=(*dirList)[2];
   1.799 +	test(entry.iName.FindF(KFile6)>=0);
   1.800 +	entry=(*dirList)[3];
   1.801 +	test(entry.iName.FindF(KFile1)>=0);
   1.802 +	entry=(*dirList)[4];
   1.803 +	test(entry.iName.FindF(KFile4)>=0);
   1.804 +	entry=(*dirList)[5];
   1.805 +	test(entry.iName.FindF(KFile2)>=0);
   1.806 +	entry=(*dirList)[6];
   1.807 +	test(entry.iName.FindF(KFile5)>=0);
   1.808 +	delete dirList;
   1.809 +	dirList = 0;
   1.810 +
   1.811 +	
   1.812 +	DeleteTestDirectoryStructure(KSortByExtPath);
   1.813 +	}
   1.814 +
   1.815 +//--------------------------------------------- 
   1.816 +//! @SYMTestCaseID			PBASE-T_DIRS-1310
   1.817 +//! @SYMTestType			CT 
   1.818 +//! @SYMREQ					DEF125143
   1.819 +//! @SYMTestCaseDesc		Test that directory name is handled by File Server interfaces properly.
   1.820 +//! @SYMTestActions			Uses RFs::IsValidName(), RFs::MkDir(), RDir::Open(), RFs::RmDir() to test
   1.821 +//!							various dir name handling.
   1.822 +//! @SYMTestExpectedResults	Proper error code is returned.
   1.823 +//! @SYMTestPriority		High
   1.824 +//! @SYMTestStatus			Implemented 
   1.825 +//--------------------------------------------- 	
   1.826 +void TestDirNameHandling()
   1.827 +	{	
   1.828 +	test.Next(_L("Test Dir Name Handling Interfaces"));
   1.829 +	TFileName dirTest1;
   1.830 +	dirTest1 = _L("\\F32-TST\\TDIRS\\test1\\FILE.TXT");
   1.831 +	TFileName dirTest2;
   1.832 +	dirTest2 = _L("\\F32-TST\\TDIRS\\test2.\\FILE.TXT");
   1.833 +	TFileName dirTest3;
   1.834 +	dirTest3 = _L("\\F32-TST\\TDIRS\\test3. \\FILE.TXT");
   1.835 +	TFileName dirTest4;
   1.836 +	dirTest4 = _L("\\F32-TST\\TDIRS\\test4. . \\FILE.TXT");
   1.837 +	TFileName dirTest5;
   1.838 +	dirTest5 = _L("\\F32-TST\\TDIRS\\test5.\\FILE.TXT");
   1.839 +	TFileName dirTest6;
   1.840 +	dirTest6 = _L("\\F32-TST\\TDIRS\\test6. .\\FILE.TXT");
   1.841 +
   1.842 +    TBool valid = TheFs.IsValidName( dirTest1 );
   1.843 +    test(valid);
   1.844 +    valid = TheFs.IsValidName( dirTest2 );
   1.845 +    test(!valid);
   1.846 +    valid = TheFs.IsValidName( dirTest3 );
   1.847 +    test(!valid);
   1.848 +    valid = TheFs.IsValidName( dirTest4 );
   1.849 +    test(!valid);
   1.850 +    valid = TheFs.IsValidName( dirTest5 );
   1.851 +    test(!valid);
   1.852 +    valid = TheFs.IsValidName( dirTest6 );
   1.853 +    test(!valid);
   1.854 +
   1.855 +	dirTest1 = _L("\\F32-TST\\TDIRS\\test1\\");
   1.856 +	dirTest2 = _L("\\F32-TST\\TDIRS\\test2.\\");
   1.857 +	dirTest3 = _L("\\F32-TST\\TDIRS\\test3. \\");
   1.858 +	dirTest4 = _L("\\F32-TST\\TDIRS\\test4. . \\");
   1.859 +	dirTest5 = _L("\\F32-TST\\TDIRS\\test5.\\");
   1.860 +	dirTest6 = _L("\\F32-TST\\TDIRS\\test6. .\\");
   1.861 +
   1.862 +    TInt err = TheFs.MkDir(dirTest1);
   1.863 +    test(err == KErrNone);
   1.864 +    err = TheFs.MkDir(dirTest2);
   1.865 +    test(err == KErrBadName);
   1.866 +    err = TheFs.MkDir(dirTest3);
   1.867 +    test(err == KErrBadName);
   1.868 +    err = TheFs.MkDir(dirTest4);
   1.869 +    test(err == KErrBadName);
   1.870 +    err = TheFs.MkDir(dirTest5);
   1.871 +    test(err == KErrBadName);
   1.872 +    err = TheFs.MkDir(dirTest6);
   1.873 +    test(err == KErrBadName);
   1.874 +
   1.875 +    RDir rdir;
   1.876 +    err = rdir.Open(TheFs, dirTest1, 0);
   1.877 +    rdir.Close();
   1.878 +    test(err == KErrNone);
   1.879 +
   1.880 +    err = rdir.Open(TheFs, dirTest2, 0);
   1.881 +    rdir.Close();
   1.882 +    test(err == KErrBadName);
   1.883 +
   1.884 +    err = rdir.Open(TheFs, dirTest3, 0);
   1.885 +    rdir.Close();
   1.886 +    test(err == KErrBadName);
   1.887 +
   1.888 +    err = rdir.Open(TheFs, dirTest4, 0);
   1.889 +    rdir.Close();
   1.890 +    test(err == KErrBadName);
   1.891 +
   1.892 +    err = rdir.Open(TheFs, dirTest5, 0);
   1.893 +    rdir.Close();
   1.894 +    test(err == KErrBadName);
   1.895 +
   1.896 +    err = rdir.Open(TheFs, dirTest6, 0);
   1.897 +    rdir.Close();
   1.898 +    test(err == KErrBadName);
   1.899 +
   1.900 +    err = TheFs.RmDir(dirTest1);
   1.901 +    test(err == KErrNone);
   1.902 +    err = TheFs.RmDir(dirTest2);
   1.903 +    test(err == KErrBadName);
   1.904 +    err = TheFs.RmDir(dirTest3);
   1.905 +    test(err == KErrBadName);
   1.906 +    err = TheFs.RmDir(dirTest4);
   1.907 +    test(err == KErrBadName);
   1.908 +    err = TheFs.RmDir(dirTest5);
   1.909 +    test(err == KErrBadName);
   1.910 +    err = TheFs.RmDir(dirTest6);
   1.911 +    test(err == KErrBadName);
   1.912 +	}
   1.913 +
   1.914 +void CallTestsL()
   1.915 +//
   1.916 +// Do all tests
   1.917 +//
   1.918 +	{
   1.919 +
   1.920 +    //-- set up console output 
   1.921 +    F32_Test_Utils::SetConsole(test.Console()); 
   1.922 +    
   1.923 +    TInt nRes=TheFs.CharToDrive(gDriveToTest, gDriveNum);
   1.924 +    test(nRes==KErrNone);
   1.925 +    
   1.926 +    PrintDrvInfo(TheFs, gDriveNum);
   1.927 +
   1.928 +	TurnAllocFailureOff();
   1.929 +	CreateTestDirectory(_L("\\F32-TST\\TDIRS\\"));
   1.930 +	
   1.931 +	if (!gTestedZ)
   1.932 +		{
   1.933 +		TInt r=TheFs.SetSessionPath(_L("Z:\\"));
   1.934 +		test(r==KErrNone);
   1.935 +		Test2();
   1.936 +		TestZ();
   1.937 +		r=TheFs.SetSessionPath(gSessionPath);
   1.938 +		test(r==KErrNone);
   1.939 +		test.Next(_L("Run all other tests from \\F32-TST\\TDIRS\\"));
   1.940 +		gTestedZ=ETrue;
   1.941 +		}
   1.942 +
   1.943 +	Test8();
   1.944 +	
   1.945 +	Test7(); 
   1.946 +
   1.947 +	Test1();
   1.948 +	Test2();
   1.949 +	Test3();
   1.950 +	Test4();
   1.951 +	Test5();
   1.952 +	Test6();
   1.953 +	Test9();
   1.954 +
   1.955 +	TestSortByName();
   1.956 +	TestSortByExt();
   1.957 +	TestDirNameHandling();
   1.958 +
   1.959 +	CleanupL();
   1.960 +	}