os/kernelhwsrv/kerneltest/f32test/server/t_gdir.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1995-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 //
    15 
    16 #include <f32file.h>
    17 #include <e32test.h>
    18 #include "t_server.h"
    19 
    20 GLDEF_D RTest test(_L("T_GDIR"));
    21 
    22 LOCAL_D const TInt KFilesMax=9;
    23 LOCAL_D const TInt KUidFilesMax=7;
    24 LOCAL_D const TInt KDirsMax=4;
    25 LOCAL_D TBool gFirstRun=ETrue;
    26 LOCAL_D TPtrC test_dir(_L("\\F32-TST\\GDIR\\"));
    27 LOCAL_D TPtrC test_dir_1(_L("\\F32-TST\\GDIR\\*"));
    28 
    29 class TUidFile
    30 	{
    31 public:
    32 	TUidFile(const TText* aFileName,TUidType aUidType,const TText8* aContents);
    33 public:
    34 	const TText* iFileName;
    35 	TUidType iUidType;
    36 	const TText8* iContents;
    37 	};
    38 
    39 TUidFile::TUidFile(const TText* aFileName,TUidType aUidType,const TText8* aContents)
    40 	: iFileName(aFileName), iUidType(aUidType), iContents(aContents)
    41 	{}
    42 
    43 LOCAL_D TUidFile uidFiles[] = 
    44 	{
    45 	TUidFile(_S("File1.TXT"), TUidType(TUid::Uid(1),TUid::Uid(2),TUid::Uid(731)),_S8("blarg blarg blarg")),
    46 	TUidFile(_S("asdf.asdf"), TUidType(TUid::Uid(55),TUid::Uid(2),TUid::Uid(731)),_S8("blarg")),
    47 	TUidFile(_S("another fiel"), TUidType(TUid::Uid(104),TUid::Uid(22),TUid::Uid(731)),_S8("blarg2")),
    48 	TUidFile(_S("another fiel1"), TUidType(TUid::Uid(7),TUid::Uid(23),TUid::Uid(131)),_S8("")),
    49 	TUidFile(_S("another fiel2"), TUidType(TUid::Uid(8),TUid::Uid(2),TUid::Uid(531)),_S8("asdf")),
    50 	TUidFile(_S("another fiel3"), TUidType(TUid::Uid(9),TUid::Uid(22),TUid::Uid(531)),_S8("blar")),
    51 	TUidFile(_S("another fiel4"), TUidType(TUid::Uid(10),TUid::Uid(23),TUid::Uid(231)),_S8("blarg blarg blarg asdlfjasdfasdfasdfasdfasdfadfafa"))
    52 	};
    53 
    54 LOCAL_D const TText* fileNames[] =
    55 	{
    56 	_S("B1.B3"),_S("B2.B2"),_S("B3.B1"),
    57 	_S("A1.A3"),_S("A2.A2"),_S("A3.A1"),
    58 	_S("Z1.Z3"),_S("Z2.Z2"),_S("Z3.Z1")
    59 	};
    60 
    61 LOCAL_D const TText* dirNames[] =
    62 	{
    63 	_S("DB1"),
    64 	_S("DA1"),
    65 	_S("DZ1"),
    66 	_S("DD1")
    67 	};
    68 
    69 inline TName files(TInt anIndex)
    70 	{return(TName(fileNames[anIndex]));}
    71 inline TName dirs(TInt anIndex)
    72 	{return(TName(dirNames[anIndex]));}
    73 
    74 LOCAL_C void displayDir(const CDir& aDir,TInt& aDirCount,TInt& aFileCount)
    75 //
    76 // Display the contents of a directory list.
    77 //
    78 	{
    79 
    80 	TInt count=aDir.Count();
    81 	TInt i=0;
    82 	TInt fCount=0;
    83 	TInt dCount=0;
    84 	while (i<count)
    85 		{
    86 		const TEntry& e=aDir[i++];
    87 		if (e.IsDir())
    88 			{
    89 			dCount++;
    90 			test.Printf(_L("%- 16S <DIR>\n"),&e.iName);
    91 			}
    92 		else
    93 			{
    94 			fCount++;
    95 			test.Printf(_L("%- 16S %+ 8d\n"),&e.iName,e.iSize);
    96 			}
    97 		}
    98 	test.Printf(_L("Dirs = %d Files = %d\n"),dCount,fCount);
    99 	aFileCount=fCount;
   100 	aDirCount=dCount;
   101 	}
   102 
   103 LOCAL_C void createFile(const TUidFile& aFileName)
   104 //
   105 // Create a file in the test directory.
   106 //
   107 	{
   108 
   109 	TCheckedUid checkedUid(aFileName.iUidType);
   110 	TPtrC fileName(aFileName.iFileName);
   111 	TAutoClose<RFile> file;
   112 	TInt r=file.iObj.Replace(TheFs,fileName,EFileWrite);
   113 	test(r==KErrNone);
   114 	TPtrC8 uidBuf((TUint8*)&checkedUid,sizeof(TCheckedUid));
   115 	r=file.iObj.Write(uidBuf);
   116 	test(r==KErrNone);
   117 	TPtrC8 contents(aFileName.iContents);
   118 	r=file.iObj.Write(contents);
   119 	test(r==KErrNone);
   120 	}
   121 
   122 LOCAL_C void createFile(TInt anIndex)
   123 //
   124 // Create a file in the test directory.
   125 //
   126 	{
   127 
   128 	TFileName fName;
   129 	TName name=files(anIndex);
   130 	fName.Format(_L("%S%S"),&test_dir,&name);
   131 	TBuf<0x80> mes;
   132 	mes.Format(_L("Create file %S"),&fName);
   133     test.Next(mes);
   134 //
   135 	TAutoClose<RFile> file;
   136 	TInt r=file.iObj.Replace(TheFs,fName,EFileWrite);
   137 	test(r==KErrNone);
   138 	TBuf8<36> b((TUint8*)"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
   139 	b.SetLength(anIndex+1);
   140 	r=file.iObj.Write(b);
   141 	test(r==KErrNone);
   142 	}
   143 
   144 LOCAL_C void createDir(TInt anIndex)
   145 //
   146 // Create a dir in the test directory.
   147 //
   148 	{
   149 
   150 	TFileName dName;
   151 	TName name=dirs(anIndex);
   152 	dName.Format(_L("%S%S\\"),&test_dir,&name);
   153 	TBuf<0x80> mes;
   154 	mes.Format(_L("Create dir %S"),&dName);
   155     test.Next(mes);
   156 //
   157 	TInt r=TheFs.MkDir(dName);
   158 	test(r==KErrNone);
   159 	}
   160 
   161 LOCAL_C void testSetup()
   162 //
   163 // Setup the test environment.
   164 //
   165 	{
   166 
   167 	test.Next(_L("Remove test directory"));
   168 	CDir* pD;
   169 	TInt r=TheFs.GetDir(test_dir_1,KEntryAttMaskSupported,EDirsLast,pD);
   170 	test(r==KErrNone || r==KErrNotFound || r==KErrPathNotFound);
   171 	if (r==KErrNone)
   172 		{
   173 		TInt count=pD->Count();
   174 		TInt i=0;
   175 		while (i<count)
   176 			{
   177 			const TEntry& e=(*pD)[i++];
   178 			if (e.IsDir())
   179 				{
   180 				TFileName name;
   181 				name.Format(_L("%S%S\\"),&test_dir,&e.iName);
   182 				r=TheFs.RmDir(name);
   183 				test(r==KErrNone);
   184 				}
   185 			else
   186 				{
   187 				TFileName name;
   188 				name.Format(_L("%S%S"),&test_dir,&e.iName);
   189 				r=TheFs.Delete(name);
   190 				test(r==KErrNone);
   191 				}
   192 			}
   193 		}
   194 //
   195 	delete pD;
   196 //
   197 	test.Next(_L("Create test files"));
   198 	TInt i=0;
   199 	while (i<KFilesMax)
   200 		createFile(i++);
   201 //
   202 	test.Next(_L("Create test directories"));
   203 	i=0;
   204 	while (i<KDirsMax)
   205 		createDir(i++);
   206 	}
   207 
   208 LOCAL_C void testDir()
   209 //
   210 // Setup the test environment.
   211 //
   212 	{
   213 
   214 	TInt dCount;
   215 	TInt fCount;
   216 	test.Next(_L("Test directory handling"));
   217 	CDir* pD;
   218 	TInt r=TheFs.GetDir(test_dir_1,KEntryAttMaskSupported,EDirsLast,pD);
   219 	test(r==KErrNone);
   220 	displayDir(*pD,dCount,fCount);
   221 	test(dCount==4 && fCount==9);
   222 	delete pD;
   223 //
   224 	test.Next(_L("Attributes: NULL"));
   225 	r=TheFs.GetDir(test_dir_1,NULL,EDirsLast,pD);
   226 	test(r==KErrNone);
   227 	displayDir(*pD,dCount,fCount);
   228 	test(dCount==0 && fCount==9);
   229 	delete pD;
   230 //
   231 	test.Next(_L("Attributes: KEntryAttDir & EDescending sort"));
   232 	r=TheFs.GetDir(test_dir_1,KEntryAttDir,ESortByName|EDescending,pD);
   233 	test(r==KErrNone);
   234 	displayDir(*pD,dCount,fCount);
   235 	test(dCount==4 && fCount==9);
   236 	delete pD;
   237 //	
   238 	test.Next(_L("Attributes: Excl,Dir"));
   239 	r=TheFs.GetDir(test_dir_1,KEntryAttMatchExclusive|KEntryAttDir,ESortByName|EDescending,pD);
   240 	test(r==KErrNone);
   241 	displayDir(*pD,dCount,fCount);
   242 	test(dCount==4 && fCount==0);
   243 	delete pD;
   244 //	
   245 	CDir* pD2;
   246 //
   247 	test.Next(_L("Test split directories and files"));
   248 	r=TheFs.GetDir(test_dir_1,KEntryAttMaskSupported,ESortByName,pD,pD2);
   249 	test(r==KErrNone);
   250 	test.Printf(_L("FileList:\n"));
   251 	displayDir(*pD,dCount,fCount);
   252 	test(dCount==4 && fCount==9);
   253 	test.Printf(_L("DirList:\n"));
   254 	displayDir(*pD2,dCount,fCount);
   255 	test(dCount==4 && fCount==0);
   256 	delete pD;
   257 	delete pD2;
   258 //
   259 	test.Next(_L("Attributes: NULL"));
   260 	r=TheFs.GetDir(test_dir_1,NULL,ESortByName,pD,pD2);
   261 	test(r==KErrNone);
   262 	test.Printf(_L("FileList:\n"));
   263 	displayDir(*pD,dCount,fCount);
   264 	test(dCount==0 && fCount==9);
   265 	test.Printf(_L("DirList:\n"));
   266 	displayDir(*pD2,dCount,fCount);
   267 	test(dCount==4 && fCount==0);
   268 	delete pD;
   269 	delete pD2;
   270 //
   271 	test.Next(_L("Attributes: KEntryAttDir"));
   272 	r=TheFs.GetDir(test_dir_1,KEntryAttDir,ESortByName,pD,pD2);
   273 	test(r==KErrNone);
   274 	test.Printf(_L("FileList:\n"));
   275 	displayDir(*pD,dCount,fCount);
   276 	test(dCount==4 && fCount==9);
   277 	test.Printf(_L("DirList:\n"));
   278 	displayDir(*pD2,dCount,fCount);
   279 	test(dCount==4 && fCount==0);
   280 	delete pD;
   281 	delete pD2;
   282 //
   283 	test.Next(_L("Attributes: Excl,Dir"));
   284 	r=TheFs.GetDir(test_dir_1,KEntryAttMatchExclusive|KEntryAttDir,ESortByName,pD,pD2);
   285 	test(r==KErrNone);
   286 	test.Printf(_L("FileList:\n"));
   287 	displayDir(*pD,dCount,fCount);
   288 	test(dCount==4 && fCount==0);
   289 	test.Printf(_L("DirList:\n"));
   290 	displayDir(*pD2,dCount,fCount);
   291 	test(dCount==4 && fCount==0);
   292 	delete pD;
   293 	delete pD2;
   294 	}
   295 
   296 LOCAL_C void testZDirectory()
   297 //
   298 // Display Z directory
   299 //
   300 	{
   301 
   302 	test.Next(_L("Test Z:"));
   303 	TInt dCount,fCount;
   304 	CDir* pD;
   305 	TInt r=TheFs.GetDir(_L("Z:\\*"),KEntryAttMaskSupported,EDirsFirst,pD);
   306 	test(r==KErrNone);
   307 	displayDir(*pD,dCount,fCount);
   308 	delete pD;
   309 	}
   310 
   311 LOCAL_C void testDisplayFiles()
   312 //
   313 // Display some files
   314 //
   315 	{
   316 
   317 	test.Next(_L("Display contents of current directory"));
   318 	CDir* pD;
   319 	TInt r=TheFs.GetDir(gSessionPath,KEntryAttMaskSupported,EDirsFirst,pD);
   320 	test(r==KErrNone);
   321 	TInt dCount,fCount;
   322 	displayDir(*pD,dCount,fCount);
   323 	delete pD;
   324 
   325 	TParsePtrC session(gSessionPath);
   326 	TParse parser;
   327 	TBuf<16> noName=_L("asdf.idd");
   328 	parser.Set(session.Drive(),&noName,NULL);
   329 	r=TheFs.GetDir(parser.FullName(),KEntryAttMaskSupported,EDirsFirst,pD);
   330 	test(r==KErrNone);
   331 	test(pD->Count()==0);
   332 	delete pD;
   333 	}
   334 
   335 LOCAL_C void MatchUidFile(TInt aUidFile,TInt anEntryNum,const CDir* aFileList)
   336 //
   337 // Check aUidFile matches anEntryNum
   338 //
   339 	{
   340 
   341 	test(aUidFile<KUidFilesMax);
   342 	TInt count=aFileList->Count();
   343 	test(anEntryNum<count);
   344 	TEntry entry=(*aFileList)[anEntryNum];
   345 
   346 	TPtrC uidFileName(uidFiles[aUidFile].iFileName);
   347 	test(entry.iName==uidFileName);
   348 	test(entry.iType==uidFiles[aUidFile].iUidType);
   349 
   350 	RFile f;
   351 	TInt r=f.Open(TheFs,entry.iName,EFileRead);
   352 	test(r==KErrNone);
   353 	TBuf8<256> contents;
   354 	r=f.Read(sizeof(TCheckedUid),contents);
   355 	test(r==KErrNone);
   356 	TPtrC8 uidFileContents(uidFiles[aUidFile].iContents);
   357 	test(contents==uidFileContents);
   358 	r=f.Read(contents);
   359 	test(r==KErrNone);
   360 	test(contents.Length()==0);
   361 	f.Close();
   362 	}
   363 
   364 LOCAL_C TInt PrintUid(TInt anEntryNum,const CDir* aFileList)
   365 //
   366 // Check aUidFile matches anEntryNum
   367 //
   368 	{
   369 
   370 	TInt count=aFileList->Count();
   371 	test(anEntryNum<count);
   372 	TEntry entry=(*aFileList)[anEntryNum];
   373 	test.Printf(_L("Entry name = %S UID=%d\n"),&entry.iName,entry.iType[2]);
   374 	return(entry.iType[2].iUid);
   375 	}
   376 
   377 LOCAL_C void testGetDirByUid()
   378 //
   379 // Get directory contents by matching UIDs
   380 //
   381 	{
   382 
   383 	test.Next(_L("Get directory contents by matching UIDs"));
   384 	TInt i=KUidFilesMax;
   385 	while(i--)
   386 		createFile(uidFiles[i]);
   387 
   388 	TBuf<16> matchName=_L("*.txt");
   389 	TUidType matchUid(TUid::Null(),TUid::Uid(2),TUid::Null());
   390 	CDir* fileList;
   391 	TInt r=TheFs.GetDir(matchName,matchUid,EAscending,fileList);
   392 	test(r==KErrNone);
   393 	TInt count=fileList->Count();
   394 	test(count==1);
   395 	MatchUidFile(0,0,fileList);
   396 	delete fileList;
   397 
   398 	matchName=_L("*.*");
   399 	matchUid=TUidType(TUid::Uid(1),TUid::Uid(2),TUid::Uid(731));
   400 	r=TheFs.GetDir(matchName,matchUid,EAscending,fileList);
   401 	test(r==KErrNone);
   402 	count=fileList->Count();
   403 	test(count==1);
   404 	MatchUidFile(0,0,fileList);
   405 	delete fileList;
   406 
   407 	matchName=_L("*.*");
   408 	matchUid=TUidType(TUid::Null(),TUid::Uid(2),TUid::Null());
   409 	r=TheFs.GetDir(matchName,matchUid,ESortByName|EAscending,fileList);
   410 	test(r==KErrNone);
   411 	count=fileList->Count();
   412 	test(count==3);
   413 	MatchUidFile(0,2,fileList);
   414 	MatchUidFile(1,1,fileList);
   415 	MatchUidFile(4,0,fileList);
   416 	delete fileList;
   417 
   418 	matchName=_L("*.*");
   419 	matchUid=TUidType(TUid::Null(),TUid::Null(),TUid::Uid(731));
   420 	r=TheFs.GetDir(matchName,matchUid,ESortByName|EAscending,fileList);
   421 	test(r==KErrNone);
   422 	count=fileList->Count();
   423 	test(count==3);
   424 	MatchUidFile(2,0,fileList);
   425 	MatchUidFile(1,1,fileList);
   426 	MatchUidFile(0,2,fileList);
   427 	delete fileList;
   428 
   429 	matchName=_L("*.*");
   430 	r=TheFs.GetDir(matchName,KEntryAttNormal,ESortByUid|EAscending,fileList);
   431 	test(r==KErrNone);
   432 	count=fileList->Count();
   433 	MatchUidFile(4,0,fileList);
   434 	MatchUidFile(1,1,fileList);
   435 	MatchUidFile(0,2,fileList);
   436 	MatchUidFile(5,3,fileList);
   437 	MatchUidFile(2,4,fileList);
   438 	MatchUidFile(3,5,fileList);
   439 	MatchUidFile(6,6,fileList);
   440 	for (i=7;i<count;i++)
   441 		{
   442 		TEntry entry;
   443 		entry=(*fileList)[i];
   444 		test(entry.iType[2].iUid==0);
   445 		PrintUid(i,fileList);
   446 		}			
   447 	test(i==count);
   448 	delete fileList;
   449 	}
   450 
   451 LOCAL_C void testZGetDirByUid()
   452 //
   453 // Get directory contents by matching UIDs from Z:
   454 //
   455 	{
   456 
   457 	TUidType matchUid(TUid::Null(),TUid::Uid(0x1000008c),TUid::Null());
   458 	CDir* fileList;
   459 	TInt r=TheFs.GetDir(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("Z:\\SYS\\BIN\\"):_L("Z:\\SYSTEM\\BIN\\"),matchUid,EAscending,fileList);
   460 	test(r==KErrNone);
   461 	TInt count=fileList->Count();
   462 #if defined(__WINS__)
   463 	test(count==0);
   464 #else
   465 	test.Printf(_L("Count=%d\n"),count);
   466 	while(count--)
   467 		PrintUid(count,fileList);
   468 //	test(count==1);
   469 //	TEntry entry;
   470 //	entry=(*fileList)[0];
   471 //	test(entry.iName.MatchF(_L("EFILE.EXE"))!=KErrNotFound);
   472 #endif
   473 	delete fileList;
   474 	}
   475 
   476 LOCAL_C void testGetFilesExcept()
   477 //
   478 // Get all files except read only ...
   479 //
   480 	{
   481 
   482 	MakeFile(_L("\\F32-TST\\GDIR\\RONLY1.CCC"),KEntryAttReadOnly);
   483 	MakeFile(_L("\\F32-TST\\GDIR\\RONLY2.CCC"),KEntryAttReadOnly);
   484 	MakeFile(_L("\\F32-TST\\GDIR\\RW1.CCC"));
   485 	MakeFile(_L("\\F32-TST\\GDIR\\RW2.CCC"));
   486 	MakeFile(_L("\\F32-TST\\GDIR\\SYSTEM1.CCC"),KEntryAttSystem);
   487 	MakeFile(_L("\\F32-TST\\GDIR\\SYSTEM2.CCC"),KEntryAttSystem);
   488 
   489 	test.Next(_L("Can match only read only files"));
   490 	TUint onlyRO=KEntryAttReadOnly|KEntryAttMatchExclusive;
   491 	CDir* fileList;
   492 	TInt r=TheFs.GetDir(_L("\\F32-TST\\GDIR\\*.CCC"),onlyRO,EAscending,fileList);
   493 	test(r==KErrNone);
   494 	TInt count=fileList->Count();
   495 	test(count==2);
   496 
   497 	TEntry entry;
   498 	entry=(*fileList)[0];
   499 	test(entry.iName.MatchF(_L("RONLY1.CCC"))!=KErrNotFound);
   500 	entry=(*fileList)[1];
   501 	test(entry.iName.MatchF(_L("RONLY2.CCC"))!=KErrNotFound);
   502 	delete fileList;
   503 
   504 	test.Next(_L("Can match everything except read only files"));
   505 	TUint excludeRO=KEntryAttReadOnly|KEntryAttMatchExclude;
   506 	r=TheFs.GetDir(_L("\\F32-TST\\GDIR\\*.CCC"),excludeRO,EAscending,fileList);
   507 	test(r==KErrNone);
   508 	count=fileList->Count();
   509 	test(count==4);
   510 
   511 	entry=(*fileList)[0];
   512 	test(entry.iName.MatchF(_L("RW1.CCC"))!=KErrNotFound);
   513 	entry=(*fileList)[1];
   514 	test(entry.iName.MatchF(_L("RW2.CCC"))!=KErrNotFound);
   515 	entry=(*fileList)[2];
   516 	test(entry.iName.MatchF(_L("SYSTEM1.CCC"))!=KErrNotFound);
   517 	entry=(*fileList)[3];
   518 	test(entry.iName.MatchF(_L("SYSTEM2.CCC"))!=KErrNotFound);
   519 	delete fileList;
   520 
   521 	test.Next(_L("Can match everything except system and readonly files"));
   522 	TUint excludeSystemAndRO=KEntryAttReadOnly|KEntryAttSystem|KEntryAttMatchExclude;
   523 	r=TheFs.GetDir(_L("\\F32-TST\\GDIR\\*.CCC"),excludeSystemAndRO,EAscending,fileList);
   524 	test(r==KErrNone);
   525 	count=fileList->Count();
   526 	test(count==2);
   527 
   528 	entry=(*fileList)[0];
   529 	test(entry.iName.MatchF(_L("RW1.CCC"))!=KErrNotFound);
   530 	entry=(*fileList)[1];
   531 	test(entry.iName.MatchF(_L("RW2.CCC"))!=KErrNotFound);
   532 	delete fileList;
   533 
   534 	r=TheFs.SetAtt(_L("\\F32-TST\\GDIR\\RONLY1.CCC"),0,KEntryAttReadOnly);
   535 	test(r==KErrNone);
   536 	r=TheFs.SetAtt(_L("\\F32-TST\\GDIR\\RONLY2.CCC"),0,KEntryAttReadOnly);
   537 	test(r==KErrNone);
   538 	}
   539 
   540 LOCAL_C void testGetHidden()
   541 //
   542 // Match hidden files and directories
   543 //
   544 	{
   545 
   546 	test.Next(_L("Match hidden files and directories"));
   547 	MakeFile(_L("File.qqq"));
   548 	MakeFile(_L("FileHidden.qqq"));
   549 	MakeFile(_L("FileSystem.qqq"));
   550 	MakeFile(_L("FileHiddenSystem.qqq"));
   551 	MakeDir(_L("\\F32-TST\\GDIR\\Dir.qqq\\"));
   552 	MakeDir(_L("\\F32-TST\\GDIR\\Dirhidden.qqq\\"));
   553 	MakeDir(_L("\\F32-TST\\GDIR\\Dirsystem.qqq\\"));
   554 	MakeDir(_L("\\F32-TST\\GDIR\\Dirhiddensystem.qqq\\"));
   555 
   556 	TInt r=TheFs.SetAtt(_L("FileHidden.qqq"),KEntryAttHidden,0);
   557 	test(r==KErrNone);
   558 	r=TheFs.SetAtt(_L("Filesystem.qqq"),KEntryAttSystem,0);
   559 	test(r==KErrNone);
   560 	r=TheFs.SetAtt(_L("FilehiddenSystem.qqq"),KEntryAttSystem|KEntryAttHidden,0);
   561 	test(r==KErrNone);
   562 	r=TheFs.SetAtt(_L("dirhidden.qqq"),KEntryAttHidden,0);
   563 	test(r==KErrNone);
   564 	r=TheFs.SetAtt(_L("dirsystem.qqq"),KEntryAttSystem,0);
   565 	test(r==KErrNone);
   566 	r=TheFs.SetAtt(_L("dirhiddensystem.qqq"),KEntryAttSystem|KEntryAttHidden,0);
   567 	test(r==KErrNone);
   568 
   569 // Files and directories not hidden or system
   570 	CDir* dir;
   571 	r=TheFs.GetDir(_L("*.qqq"),KEntryAttDir,ESortByName,dir);
   572 	test(r==KErrNone);
   573 	TInt count=dir->Count();
   574 	test(count==2);
   575 	TEntry entry;
   576 	entry=(*dir)[0];
   577 	test(entry.iName.MatchF(_L("dir.qqq"))!=KErrNotFound);
   578 	entry=(*dir)[1];
   579 	test(entry.iName.MatchF(_L("file.qqq"))!=KErrNotFound);
   580 	delete dir;
   581 	
   582 // Files only
   583 	r=TheFs.GetDir(_L("*.qqq"),KEntryAttNormal,ESortByName,dir);
   584 	test(r==KErrNone);
   585 	count=dir->Count();
   586 	test(count==1);
   587 	entry=(*dir)[0];
   588 	test(entry.iName.MatchF(_L("file.qqq"))!=KErrNotFound);
   589 	delete dir;
   590 
   591 // Directories only
   592 	r=TheFs.GetDir(_L("*.qqq"),KEntryAttDir|KEntryAttMatchExclusive,ESortByName,dir);
   593 	test(r==KErrNone);
   594 	count=dir->Count();
   595 	test(count==1);
   596 	entry=(*dir)[0];
   597 	test(entry.iName.MatchF(_L("dir.qqq"))!=KErrNotFound);
   598 	delete dir;
   599 
   600 // Files + hidden
   601 	r=TheFs.GetDir(_L("*.qqq"),KEntryAttHidden,ESortByName,dir);
   602 	test(r==KErrNone);
   603 	count=dir->Count();
   604 	test(count==2);
   605 	entry=(*dir)[0];
   606 	test(entry.iName.MatchF(_L("file.qqq"))!=KErrNotFound);
   607 	entry=(*dir)[1];
   608 	test(entry.iName.MatchF(_L("filehidden.qqq"))!=KErrNotFound);
   609 	delete dir;
   610 
   611 // Files + system
   612 	r=TheFs.GetDir(_L("*.qqq"),KEntryAttHidden,ESortByName,dir);
   613 	test(r==KErrNone);
   614 	count=dir->Count();
   615 	test(count==2);
   616 	entry=(*dir)[0];
   617 	test(entry.iName.MatchF(_L("file.qqq"))!=KErrNotFound);
   618 	entry=(*dir)[1];
   619 	test(entry.iName.MatchF(_L("filehidden.qqq"))!=KErrNotFound);
   620 	delete dir;
   621 
   622 // Files + hidden + system
   623 	r=TheFs.GetDir(_L("*.qqq"),KEntryAttHidden|KEntryAttSystem,ESortByName,dir);
   624 	test(r==KErrNone);
   625 	count=dir->Count();
   626 	test(count==4);
   627 	entry=(*dir)[0];
   628 	test(entry.iName.MatchF(_L("file.qqq"))!=KErrNotFound);
   629 	entry=(*dir)[1];
   630 	test(entry.iName.MatchF(_L("filehidden.qqq"))!=KErrNotFound);
   631 	entry=(*dir)[2];
   632 	test(entry.iName.MatchF(_L("filehiddensystem.qqq"))!=KErrNotFound);
   633 	entry=(*dir)[3];
   634 	test(entry.iName.MatchF(_L("filesystem.qqq"))!=KErrNotFound);
   635 	delete dir;
   636 
   637 // Dirs + hidden
   638 	r=TheFs.GetDir(_L("*.qqq"),KEntryAttHidden|KEntryAttDir|KEntryAttMatchExclusive,ESortByName,dir);
   639 	test(r==KErrNone);
   640 	count=dir->Count();
   641 	test(count==2);
   642 	entry=(*dir)[0];
   643 	test(entry.iName.MatchF(_L("dir.qqq"))!=KErrNotFound);
   644 	entry=(*dir)[1];
   645 	test(entry.iName.MatchF(_L("dirhidden.qqq"))!=KErrNotFound);
   646 	delete dir;
   647 
   648 // Dirs + system
   649 	r=TheFs.GetDir(_L("*.qqq"),KEntryAttSystem|KEntryAttDir|KEntryAttMatchExclusive,ESortByName,dir);
   650 	test(r==KErrNone);
   651 	count=dir->Count();
   652 	test(count==2);
   653 	entry=(*dir)[0];
   654 	test(entry.iName.MatchF(_L("dir.qqq"))!=KErrNotFound);
   655 	entry=(*dir)[1];
   656 	test(entry.iName.MatchF(_L("dirsystem.qqq"))!=KErrNotFound);
   657 	delete dir;
   658 
   659 // Dirs + hidden + system
   660 	r=TheFs.GetDir(_L("*.qqq"),KEntryAttHidden|KEntryAttSystem|KEntryAttDir|KEntryAttMatchExclusive,ESortByName,dir);
   661 	test(r==KErrNone);
   662 	count=dir->Count();
   663 	test(count==4);
   664 	entry=(*dir)[0];
   665 	test(entry.iName.MatchF(_L("dir.qqq"))!=KErrNotFound);
   666 	entry=(*dir)[1];
   667 	test(entry.iName.MatchF(_L("dirhidden.qqq"))!=KErrNotFound);
   668 	entry=(*dir)[2];
   669 	test(entry.iName.MatchF(_L("dirhiddensystem.qqq"))!=KErrNotFound);
   670 	entry=(*dir)[3];
   671 	test(entry.iName.MatchF(_L("dirsystem.qqq"))!=KErrNotFound);
   672 	
   673 	delete dir;
   674 
   675 // Files + Dirs + hidden
   676 	r=TheFs.GetDir(_L("*.qqq"),KEntryAttHidden|KEntryAttDir,ESortByName,dir);
   677 	test(r==KErrNone);
   678 	count=dir->Count();
   679 	test(count==4);
   680 	entry=(*dir)[0];
   681 	test(entry.iName.MatchF(_L("dir.qqq"))!=KErrNotFound);
   682 	entry=(*dir)[1];
   683 	test(entry.iName.MatchF(_L("dirhidden.qqq"))!=KErrNotFound);	
   684 	entry=(*dir)[2];
   685 	test(entry.iName.MatchF(_L("file.qqq"))!=KErrNotFound);
   686 	entry=(*dir)[3];
   687 	test(entry.iName.MatchF(_L("filehidden.qqq"))!=KErrNotFound);
   688 	delete dir;
   689 
   690 // Files + Dirs + system
   691 	r=TheFs.GetDir(_L("*.qqq"),KEntryAttSystem|KEntryAttDir,ESortByName,dir);
   692 	test(r==KErrNone);
   693 	count=dir->Count();
   694 	test(count==4);
   695 	entry=(*dir)[0];
   696 	test(entry.iName.MatchF(_L("dir.qqq"))!=KErrNotFound);
   697 	entry=(*dir)[1];
   698 	test(entry.iName.MatchF(_L("dirsystem.qqq"))!=KErrNotFound);
   699 	entry=(*dir)[2];
   700 	test(entry.iName.MatchF(_L("file.qqq"))!=KErrNotFound);
   701 	entry=(*dir)[3];
   702 	test(entry.iName.MatchF(_L("filesystem.qqq"))!=KErrNotFound);
   703 	delete dir;
   704 
   705 // Files + Dirs + hidden + system
   706 	r=TheFs.GetDir(_L("*.qqq"),KEntryAttHidden|KEntryAttSystem|KEntryAttDir,ESortByName,dir);
   707 	test(r==KErrNone);
   708 	count=dir->Count();
   709 	test(count==8);
   710 	entry=(*dir)[0];
   711 	test(entry.iName.MatchF(_L("dir.qqq"))!=KErrNotFound);
   712 	entry=(*dir)[1];
   713 	test(entry.iName.MatchF(_L("dirhidden.qqq"))!=KErrNotFound);
   714 	entry=(*dir)[2];
   715 	test(entry.iName.MatchF(_L("dirhiddensystem.qqq"))!=KErrNotFound);
   716 	entry=(*dir)[3];
   717 	test(entry.iName.MatchF(_L("dirsystem.qqq"))!=KErrNotFound);
   718 	entry=(*dir)[4];
   719 	test(entry.iName.MatchF(_L("file.qqq"))!=KErrNotFound);
   720 	entry=(*dir)[5];
   721 	test(entry.iName.MatchF(_L("filehidden.qqq"))!=KErrNotFound);
   722 	entry=(*dir)[6];
   723 	test(entry.iName.MatchF(_L("filehiddensystem.qqq"))!=KErrNotFound);
   724 	entry=(*dir)[7];
   725 	test(entry.iName.MatchF(_L("filesystem.qqq"))!=KErrNotFound);
   726 	delete dir;
   727 	}
   728 
   729 LOCAL_D TFileName gDirDescendingBaseName=_L("\\F32-TST\\GDIR\\TDIRDESCENDING\\");
   730 LOCAL_D TFileName gDirDescendingEntryName[6]=
   731 	{
   732 	_L("\\F32-TST\\GDIR\\TDIRDESCENDING\\aaaa"),
   733 	_L("\\F32-TST\\GDIR\\TDIRDESCENDING\\ssss"),
   734 	_L("\\F32-TST\\GDIR\\TDIRDESCENDING\\ZZZZ"),
   735 	_L("\\F32-TST\\GDIR\\TDIRDESCENDING\\aaaa.directory\\"),
   736 	_L("\\F32-TST\\GDIR\\TDIRDESCENDING\\SSSS.dir\\"),
   737 	_L("\\F32-TST\\GDIR\\TDIRDESCENDING\\ZZZZDirectory\\")
   738 	};
   739 
   740 LOCAL_C void TestDirDescendingOrder(const TDesC& aResult,const CDir& aDirList)
   741 //
   742 // Test aDirList against aResult
   743 //
   744 	{
   745 	
   746 	TLex lex(aResult);
   747 	TInt count=0;
   748 	while (!lex.Eos())
   749 		{
   750 		lex.Mark();
   751 		while(lex.Get().IsDigit()) {};
   752 		TLex temp(lex.MarkedToken());
   753 		TInt result;
   754 		temp.Val(result);
   755 		TFileName base=gDirDescendingBaseName;
   756 		TEntry entry=aDirList[count];
   757 		base+=entry.iName;
   758 		if (entry.IsDir())
   759 			base+=_L("\\");
   760 		test(base==gDirDescendingEntryName[result]);
   761 		count++;
   762 		}
   763 	}
   764 
   765 LOCAL_C void testDirDescending()
   766 //
   767 // Test EDirDescending
   768 //
   769 	{
   770 
   771 	test.Next(_L("Test EDirDescending"));
   772 	MakeDir(gDirDescendingBaseName);
   773 	MakeFile(gDirDescendingEntryName[0]);
   774 	MakeFile(gDirDescendingEntryName[1]);
   775 	MakeFile(gDirDescendingEntryName[2]);
   776 	MakeDir(gDirDescendingEntryName[3]);
   777 	MakeDir(gDirDescendingEntryName[4]);
   778 	MakeDir(gDirDescendingEntryName[5]);
   779 
   780 // Test DirFirst - EDescending
   781 	CDir* dir;
   782 	TUint sortOrder=ESortByName|EDirsFirst|EDescending;
   783 	TInt r=TheFs.GetDir(gDirDescendingBaseName,KEntryAttMaskSupported,sortOrder,dir);
   784 	test(r==KErrNone);
   785 //	TBuf8<16> result=_L("2,1,0,3,4,5");
   786 	TBuf<16> result=_L("2,1,0,3,4,5");
   787 
   788 	TestDirDescendingOrder(result,*dir);
   789 	delete dir;
   790 // Test DirFirst - EAscending
   791 	sortOrder=ESortByName|EDirsFirst;
   792 	r=TheFs.GetDir(gDirDescendingBaseName,KEntryAttMaskSupported,sortOrder,dir);
   793 	test(r==KErrNone);
   794 	result=_L("3,4,5,0,1,2");
   795 	TestDirDescendingOrder(result,*dir);
   796 	delete dir;
   797 
   798 // Test DirLast - EDescending
   799 	sortOrder=ESortByName|EDirsLast|EDescending;
   800 	r=TheFs.GetDir(gDirDescendingBaseName,KEntryAttMaskSupported,sortOrder,dir);
   801 	test(r==KErrNone);
   802 	result=_L("3,4,5,2,1,0");
   803 	TestDirDescendingOrder(result,*dir);
   804 	delete dir;
   805 // Test DirLast - EAscending
   806 	sortOrder=ESortByName|EDirsLast;
   807 	r=TheFs.GetDir(gDirDescendingBaseName,KEntryAttMaskSupported,sortOrder,dir);
   808 	test(r==KErrNone);
   809 	result=_L("0,1,2,3,4,5");
   810 	TestDirDescendingOrder(result,*dir);
   811 	delete dir;
   812 
   813 // Test DirFirst - EDirDescending
   814 	sortOrder=ESortByName|EDirsFirst|EDirDescending;
   815 	r=TheFs.GetDir(gDirDescendingBaseName,KEntryAttMaskSupported,sortOrder,dir);
   816 	test(r==KErrNone);
   817 	result=_L("5,4,3,0,1,2");
   818 	TestDirDescendingOrder(result,*dir);
   819 	delete dir;
   820 // Test DirLast - EDirDescending
   821 	sortOrder=ESortByName|EDirsLast|EDirDescending;
   822 	r=TheFs.GetDir(gDirDescendingBaseName,KEntryAttMaskSupported,sortOrder,dir);
   823 	test(r==KErrNone);
   824 	result=_L("0,1,2,5,4,3");
   825 	TestDirDescendingOrder(result,*dir);
   826 	delete dir;
   827 
   828 // Test DirFirst - EDescending|EDirDescending
   829 	sortOrder=ESortByName|EDirsFirst|EDescending|EDirDescending;
   830 	r=TheFs.GetDir(gDirDescendingBaseName,KEntryAttMaskSupported,sortOrder,dir);
   831 	test(r==KErrNone);
   832 	result=_L("2,1,0,5,4,3");
   833 	TestDirDescendingOrder(result,*dir);
   834 	delete dir;
   835 // Test DirLast - EDescending|EDirDescending
   836 	sortOrder=ESortByName|EDirsLast|EDirDescending|EDescending;
   837 	r=TheFs.GetDir(gDirDescendingBaseName,KEntryAttMaskSupported,sortOrder,dir);
   838 	test(r==KErrNone);
   839 	result=_L("5,4,3,2,1,0");
   840 	TestDirDescendingOrder(result,*dir);
   841 	delete dir;
   842 
   843 // Test DirNoOrder - EDescending|EDirDescending
   844 	sortOrder=ESortByName|EDescending|EDirDescending;
   845 	r=TheFs.GetDir(gDirDescendingBaseName,KEntryAttMaskSupported,sortOrder,dir);
   846 	test(r==KErrNone);
   847 	result=_L("5,2,4,1,3,0");
   848 	TestDirDescendingOrder(result,*dir);
   849 	delete dir;
   850 // Test DirNoOrder - EDescending
   851 	sortOrder=ESortByName|EDescending;
   852 	r=TheFs.GetDir(gDirDescendingBaseName,KEntryAttMaskSupported,sortOrder,dir);
   853 	test(r==KErrNone);
   854 	result=_L("5,2,4,1,3,0");
   855 	TestDirDescendingOrder(result,*dir);
   856 	delete dir;
   857 // Test DirNoOrder - EAscending
   858 	sortOrder=ESortByName;
   859 	r=TheFs.GetDir(gDirDescendingBaseName,KEntryAttMaskSupported,sortOrder,dir);
   860 	test(r==KErrNone);
   861 	result=_L("0,3,1,4,2,5");
   862 	TestDirDescendingOrder(result,*dir);
   863 	delete dir;
   864 	}
   865 
   866 //--------------------------------------------- 
   867 //! @SYMTestCaseID			PBASE-T_GDIR-0815
   868 //! @SYMTestType			UT
   869 //! @SYMREQ					DEF122894
   870 //! @SYMTestCaseDesc		This testcase tests the boundary condition of file name collation (8 characters).
   871 //! @SYMTestActions			Creates file "xxxxxxxx2.dat" and "Xxxxxxxx1.dat" under same directory,
   872 //! 						 retrieves dir list via GetDir(), sort list by name, check order of the file listed.  
   873 //! @SYMTestExpectedResults File "Xxxxxxxx1.dat" should be listed before "xxxxxxxx2.dat".
   874 //! @SYMTestPriority		High
   875 //! @SYMTestStatus			Implemented
   876 //--------------------------------------------- 	
   877 void TestDEF122894()
   878 	{
   879 	test.Next(_L("Test \"DEF122894: Defect in RFs GetDir() API\""));
   880 	MakeFile(_L("\\F32-TST\\GDIR\\DEF122894\\xxxxxxxx2.dat"));
   881 	MakeFile(_L("\\F32-TST\\GDIR\\DEF122894\\Xxxxxxxx1.dat"));
   882 	CDir* dir;
   883 	TInt r=TheFs.GetDir(_L("\\F32-TST\\GDIR\\DEF122894\\"),KEntryAttMaskSupported,ESortByName|EAscending,dir);
   884 	test(r==KErrNone);
   885 	test(dir->Count() == 2);
   886 	TEntry entry1, entry2;
   887 	entry1 = (*dir)[0];
   888 	entry2 = (*dir)[1];
   889 	test(entry1.iName.Compare(_L("Xxxxxxxx1.dat")) == 0);
   890 	test(entry2.iName.Compare(_L("xxxxxxxx2.dat")) == 0);
   891 	delete dir;
   892 	}
   893 
   894 GLDEF_C void CallTestsL()
   895 //
   896 // Test directory handling.
   897 //
   898     {
   899 
   900 	CreateTestDirectory(_L("\\F32-TST\\GDIR\\"));
   901 	if (gFirstRun)
   902 		{
   903 		gFirstRun=EFalse;
   904 		testZDirectory();
   905 		testZGetDirByUid();
   906 		}
   907 
   908 	testSetup();
   909 	testDir();
   910 	testDisplayFiles();
   911 	testGetDirByUid();
   912 	testGetFilesExcept();
   913 	testGetHidden();
   914 	testDirDescending();
   915 	TestDEF122894();
   916 	DeleteTestDirectory();
   917     }
   918