1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/server/t_gdir.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,918 @@
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 +//
1.18 +
1.19 +#include <f32file.h>
1.20 +#include <e32test.h>
1.21 +#include "t_server.h"
1.22 +
1.23 +GLDEF_D RTest test(_L("T_GDIR"));
1.24 +
1.25 +LOCAL_D const TInt KFilesMax=9;
1.26 +LOCAL_D const TInt KUidFilesMax=7;
1.27 +LOCAL_D const TInt KDirsMax=4;
1.28 +LOCAL_D TBool gFirstRun=ETrue;
1.29 +LOCAL_D TPtrC test_dir(_L("\\F32-TST\\GDIR\\"));
1.30 +LOCAL_D TPtrC test_dir_1(_L("\\F32-TST\\GDIR\\*"));
1.31 +
1.32 +class TUidFile
1.33 + {
1.34 +public:
1.35 + TUidFile(const TText* aFileName,TUidType aUidType,const TText8* aContents);
1.36 +public:
1.37 + const TText* iFileName;
1.38 + TUidType iUidType;
1.39 + const TText8* iContents;
1.40 + };
1.41 +
1.42 +TUidFile::TUidFile(const TText* aFileName,TUidType aUidType,const TText8* aContents)
1.43 + : iFileName(aFileName), iUidType(aUidType), iContents(aContents)
1.44 + {}
1.45 +
1.46 +LOCAL_D TUidFile uidFiles[] =
1.47 + {
1.48 + TUidFile(_S("File1.TXT"), TUidType(TUid::Uid(1),TUid::Uid(2),TUid::Uid(731)),_S8("blarg blarg blarg")),
1.49 + TUidFile(_S("asdf.asdf"), TUidType(TUid::Uid(55),TUid::Uid(2),TUid::Uid(731)),_S8("blarg")),
1.50 + TUidFile(_S("another fiel"), TUidType(TUid::Uid(104),TUid::Uid(22),TUid::Uid(731)),_S8("blarg2")),
1.51 + TUidFile(_S("another fiel1"), TUidType(TUid::Uid(7),TUid::Uid(23),TUid::Uid(131)),_S8("")),
1.52 + TUidFile(_S("another fiel2"), TUidType(TUid::Uid(8),TUid::Uid(2),TUid::Uid(531)),_S8("asdf")),
1.53 + TUidFile(_S("another fiel3"), TUidType(TUid::Uid(9),TUid::Uid(22),TUid::Uid(531)),_S8("blar")),
1.54 + TUidFile(_S("another fiel4"), TUidType(TUid::Uid(10),TUid::Uid(23),TUid::Uid(231)),_S8("blarg blarg blarg asdlfjasdfasdfasdfasdfasdfadfafa"))
1.55 + };
1.56 +
1.57 +LOCAL_D const TText* fileNames[] =
1.58 + {
1.59 + _S("B1.B3"),_S("B2.B2"),_S("B3.B1"),
1.60 + _S("A1.A3"),_S("A2.A2"),_S("A3.A1"),
1.61 + _S("Z1.Z3"),_S("Z2.Z2"),_S("Z3.Z1")
1.62 + };
1.63 +
1.64 +LOCAL_D const TText* dirNames[] =
1.65 + {
1.66 + _S("DB1"),
1.67 + _S("DA1"),
1.68 + _S("DZ1"),
1.69 + _S("DD1")
1.70 + };
1.71 +
1.72 +inline TName files(TInt anIndex)
1.73 + {return(TName(fileNames[anIndex]));}
1.74 +inline TName dirs(TInt anIndex)
1.75 + {return(TName(dirNames[anIndex]));}
1.76 +
1.77 +LOCAL_C void displayDir(const CDir& aDir,TInt& aDirCount,TInt& aFileCount)
1.78 +//
1.79 +// Display the contents of a directory list.
1.80 +//
1.81 + {
1.82 +
1.83 + TInt count=aDir.Count();
1.84 + TInt i=0;
1.85 + TInt fCount=0;
1.86 + TInt dCount=0;
1.87 + while (i<count)
1.88 + {
1.89 + const TEntry& e=aDir[i++];
1.90 + if (e.IsDir())
1.91 + {
1.92 + dCount++;
1.93 + test.Printf(_L("%- 16S <DIR>\n"),&e.iName);
1.94 + }
1.95 + else
1.96 + {
1.97 + fCount++;
1.98 + test.Printf(_L("%- 16S %+ 8d\n"),&e.iName,e.iSize);
1.99 + }
1.100 + }
1.101 + test.Printf(_L("Dirs = %d Files = %d\n"),dCount,fCount);
1.102 + aFileCount=fCount;
1.103 + aDirCount=dCount;
1.104 + }
1.105 +
1.106 +LOCAL_C void createFile(const TUidFile& aFileName)
1.107 +//
1.108 +// Create a file in the test directory.
1.109 +//
1.110 + {
1.111 +
1.112 + TCheckedUid checkedUid(aFileName.iUidType);
1.113 + TPtrC fileName(aFileName.iFileName);
1.114 + TAutoClose<RFile> file;
1.115 + TInt r=file.iObj.Replace(TheFs,fileName,EFileWrite);
1.116 + test(r==KErrNone);
1.117 + TPtrC8 uidBuf((TUint8*)&checkedUid,sizeof(TCheckedUid));
1.118 + r=file.iObj.Write(uidBuf);
1.119 + test(r==KErrNone);
1.120 + TPtrC8 contents(aFileName.iContents);
1.121 + r=file.iObj.Write(contents);
1.122 + test(r==KErrNone);
1.123 + }
1.124 +
1.125 +LOCAL_C void createFile(TInt anIndex)
1.126 +//
1.127 +// Create a file in the test directory.
1.128 +//
1.129 + {
1.130 +
1.131 + TFileName fName;
1.132 + TName name=files(anIndex);
1.133 + fName.Format(_L("%S%S"),&test_dir,&name);
1.134 + TBuf<0x80> mes;
1.135 + mes.Format(_L("Create file %S"),&fName);
1.136 + test.Next(mes);
1.137 +//
1.138 + TAutoClose<RFile> file;
1.139 + TInt r=file.iObj.Replace(TheFs,fName,EFileWrite);
1.140 + test(r==KErrNone);
1.141 + TBuf8<36> b((TUint8*)"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
1.142 + b.SetLength(anIndex+1);
1.143 + r=file.iObj.Write(b);
1.144 + test(r==KErrNone);
1.145 + }
1.146 +
1.147 +LOCAL_C void createDir(TInt anIndex)
1.148 +//
1.149 +// Create a dir in the test directory.
1.150 +//
1.151 + {
1.152 +
1.153 + TFileName dName;
1.154 + TName name=dirs(anIndex);
1.155 + dName.Format(_L("%S%S\\"),&test_dir,&name);
1.156 + TBuf<0x80> mes;
1.157 + mes.Format(_L("Create dir %S"),&dName);
1.158 + test.Next(mes);
1.159 +//
1.160 + TInt r=TheFs.MkDir(dName);
1.161 + test(r==KErrNone);
1.162 + }
1.163 +
1.164 +LOCAL_C void testSetup()
1.165 +//
1.166 +// Setup the test environment.
1.167 +//
1.168 + {
1.169 +
1.170 + test.Next(_L("Remove test directory"));
1.171 + CDir* pD;
1.172 + TInt r=TheFs.GetDir(test_dir_1,KEntryAttMaskSupported,EDirsLast,pD);
1.173 + test(r==KErrNone || r==KErrNotFound || r==KErrPathNotFound);
1.174 + if (r==KErrNone)
1.175 + {
1.176 + TInt count=pD->Count();
1.177 + TInt i=0;
1.178 + while (i<count)
1.179 + {
1.180 + const TEntry& e=(*pD)[i++];
1.181 + if (e.IsDir())
1.182 + {
1.183 + TFileName name;
1.184 + name.Format(_L("%S%S\\"),&test_dir,&e.iName);
1.185 + r=TheFs.RmDir(name);
1.186 + test(r==KErrNone);
1.187 + }
1.188 + else
1.189 + {
1.190 + TFileName name;
1.191 + name.Format(_L("%S%S"),&test_dir,&e.iName);
1.192 + r=TheFs.Delete(name);
1.193 + test(r==KErrNone);
1.194 + }
1.195 + }
1.196 + }
1.197 +//
1.198 + delete pD;
1.199 +//
1.200 + test.Next(_L("Create test files"));
1.201 + TInt i=0;
1.202 + while (i<KFilesMax)
1.203 + createFile(i++);
1.204 +//
1.205 + test.Next(_L("Create test directories"));
1.206 + i=0;
1.207 + while (i<KDirsMax)
1.208 + createDir(i++);
1.209 + }
1.210 +
1.211 +LOCAL_C void testDir()
1.212 +//
1.213 +// Setup the test environment.
1.214 +//
1.215 + {
1.216 +
1.217 + TInt dCount;
1.218 + TInt fCount;
1.219 + test.Next(_L("Test directory handling"));
1.220 + CDir* pD;
1.221 + TInt r=TheFs.GetDir(test_dir_1,KEntryAttMaskSupported,EDirsLast,pD);
1.222 + test(r==KErrNone);
1.223 + displayDir(*pD,dCount,fCount);
1.224 + test(dCount==4 && fCount==9);
1.225 + delete pD;
1.226 +//
1.227 + test.Next(_L("Attributes: NULL"));
1.228 + r=TheFs.GetDir(test_dir_1,NULL,EDirsLast,pD);
1.229 + test(r==KErrNone);
1.230 + displayDir(*pD,dCount,fCount);
1.231 + test(dCount==0 && fCount==9);
1.232 + delete pD;
1.233 +//
1.234 + test.Next(_L("Attributes: KEntryAttDir & EDescending sort"));
1.235 + r=TheFs.GetDir(test_dir_1,KEntryAttDir,ESortByName|EDescending,pD);
1.236 + test(r==KErrNone);
1.237 + displayDir(*pD,dCount,fCount);
1.238 + test(dCount==4 && fCount==9);
1.239 + delete pD;
1.240 +//
1.241 + test.Next(_L("Attributes: Excl,Dir"));
1.242 + r=TheFs.GetDir(test_dir_1,KEntryAttMatchExclusive|KEntryAttDir,ESortByName|EDescending,pD);
1.243 + test(r==KErrNone);
1.244 + displayDir(*pD,dCount,fCount);
1.245 + test(dCount==4 && fCount==0);
1.246 + delete pD;
1.247 +//
1.248 + CDir* pD2;
1.249 +//
1.250 + test.Next(_L("Test split directories and files"));
1.251 + r=TheFs.GetDir(test_dir_1,KEntryAttMaskSupported,ESortByName,pD,pD2);
1.252 + test(r==KErrNone);
1.253 + test.Printf(_L("FileList:\n"));
1.254 + displayDir(*pD,dCount,fCount);
1.255 + test(dCount==4 && fCount==9);
1.256 + test.Printf(_L("DirList:\n"));
1.257 + displayDir(*pD2,dCount,fCount);
1.258 + test(dCount==4 && fCount==0);
1.259 + delete pD;
1.260 + delete pD2;
1.261 +//
1.262 + test.Next(_L("Attributes: NULL"));
1.263 + r=TheFs.GetDir(test_dir_1,NULL,ESortByName,pD,pD2);
1.264 + test(r==KErrNone);
1.265 + test.Printf(_L("FileList:\n"));
1.266 + displayDir(*pD,dCount,fCount);
1.267 + test(dCount==0 && fCount==9);
1.268 + test.Printf(_L("DirList:\n"));
1.269 + displayDir(*pD2,dCount,fCount);
1.270 + test(dCount==4 && fCount==0);
1.271 + delete pD;
1.272 + delete pD2;
1.273 +//
1.274 + test.Next(_L("Attributes: KEntryAttDir"));
1.275 + r=TheFs.GetDir(test_dir_1,KEntryAttDir,ESortByName,pD,pD2);
1.276 + test(r==KErrNone);
1.277 + test.Printf(_L("FileList:\n"));
1.278 + displayDir(*pD,dCount,fCount);
1.279 + test(dCount==4 && fCount==9);
1.280 + test.Printf(_L("DirList:\n"));
1.281 + displayDir(*pD2,dCount,fCount);
1.282 + test(dCount==4 && fCount==0);
1.283 + delete pD;
1.284 + delete pD2;
1.285 +//
1.286 + test.Next(_L("Attributes: Excl,Dir"));
1.287 + r=TheFs.GetDir(test_dir_1,KEntryAttMatchExclusive|KEntryAttDir,ESortByName,pD,pD2);
1.288 + test(r==KErrNone);
1.289 + test.Printf(_L("FileList:\n"));
1.290 + displayDir(*pD,dCount,fCount);
1.291 + test(dCount==4 && fCount==0);
1.292 + test.Printf(_L("DirList:\n"));
1.293 + displayDir(*pD2,dCount,fCount);
1.294 + test(dCount==4 && fCount==0);
1.295 + delete pD;
1.296 + delete pD2;
1.297 + }
1.298 +
1.299 +LOCAL_C void testZDirectory()
1.300 +//
1.301 +// Display Z directory
1.302 +//
1.303 + {
1.304 +
1.305 + test.Next(_L("Test Z:"));
1.306 + TInt dCount,fCount;
1.307 + CDir* pD;
1.308 + TInt r=TheFs.GetDir(_L("Z:\\*"),KEntryAttMaskSupported,EDirsFirst,pD);
1.309 + test(r==KErrNone);
1.310 + displayDir(*pD,dCount,fCount);
1.311 + delete pD;
1.312 + }
1.313 +
1.314 +LOCAL_C void testDisplayFiles()
1.315 +//
1.316 +// Display some files
1.317 +//
1.318 + {
1.319 +
1.320 + test.Next(_L("Display contents of current directory"));
1.321 + CDir* pD;
1.322 + TInt r=TheFs.GetDir(gSessionPath,KEntryAttMaskSupported,EDirsFirst,pD);
1.323 + test(r==KErrNone);
1.324 + TInt dCount,fCount;
1.325 + displayDir(*pD,dCount,fCount);
1.326 + delete pD;
1.327 +
1.328 + TParsePtrC session(gSessionPath);
1.329 + TParse parser;
1.330 + TBuf<16> noName=_L("asdf.idd");
1.331 + parser.Set(session.Drive(),&noName,NULL);
1.332 + r=TheFs.GetDir(parser.FullName(),KEntryAttMaskSupported,EDirsFirst,pD);
1.333 + test(r==KErrNone);
1.334 + test(pD->Count()==0);
1.335 + delete pD;
1.336 + }
1.337 +
1.338 +LOCAL_C void MatchUidFile(TInt aUidFile,TInt anEntryNum,const CDir* aFileList)
1.339 +//
1.340 +// Check aUidFile matches anEntryNum
1.341 +//
1.342 + {
1.343 +
1.344 + test(aUidFile<KUidFilesMax);
1.345 + TInt count=aFileList->Count();
1.346 + test(anEntryNum<count);
1.347 + TEntry entry=(*aFileList)[anEntryNum];
1.348 +
1.349 + TPtrC uidFileName(uidFiles[aUidFile].iFileName);
1.350 + test(entry.iName==uidFileName);
1.351 + test(entry.iType==uidFiles[aUidFile].iUidType);
1.352 +
1.353 + RFile f;
1.354 + TInt r=f.Open(TheFs,entry.iName,EFileRead);
1.355 + test(r==KErrNone);
1.356 + TBuf8<256> contents;
1.357 + r=f.Read(sizeof(TCheckedUid),contents);
1.358 + test(r==KErrNone);
1.359 + TPtrC8 uidFileContents(uidFiles[aUidFile].iContents);
1.360 + test(contents==uidFileContents);
1.361 + r=f.Read(contents);
1.362 + test(r==KErrNone);
1.363 + test(contents.Length()==0);
1.364 + f.Close();
1.365 + }
1.366 +
1.367 +LOCAL_C TInt PrintUid(TInt anEntryNum,const CDir* aFileList)
1.368 +//
1.369 +// Check aUidFile matches anEntryNum
1.370 +//
1.371 + {
1.372 +
1.373 + TInt count=aFileList->Count();
1.374 + test(anEntryNum<count);
1.375 + TEntry entry=(*aFileList)[anEntryNum];
1.376 + test.Printf(_L("Entry name = %S UID=%d\n"),&entry.iName,entry.iType[2]);
1.377 + return(entry.iType[2].iUid);
1.378 + }
1.379 +
1.380 +LOCAL_C void testGetDirByUid()
1.381 +//
1.382 +// Get directory contents by matching UIDs
1.383 +//
1.384 + {
1.385 +
1.386 + test.Next(_L("Get directory contents by matching UIDs"));
1.387 + TInt i=KUidFilesMax;
1.388 + while(i--)
1.389 + createFile(uidFiles[i]);
1.390 +
1.391 + TBuf<16> matchName=_L("*.txt");
1.392 + TUidType matchUid(TUid::Null(),TUid::Uid(2),TUid::Null());
1.393 + CDir* fileList;
1.394 + TInt r=TheFs.GetDir(matchName,matchUid,EAscending,fileList);
1.395 + test(r==KErrNone);
1.396 + TInt count=fileList->Count();
1.397 + test(count==1);
1.398 + MatchUidFile(0,0,fileList);
1.399 + delete fileList;
1.400 +
1.401 + matchName=_L("*.*");
1.402 + matchUid=TUidType(TUid::Uid(1),TUid::Uid(2),TUid::Uid(731));
1.403 + r=TheFs.GetDir(matchName,matchUid,EAscending,fileList);
1.404 + test(r==KErrNone);
1.405 + count=fileList->Count();
1.406 + test(count==1);
1.407 + MatchUidFile(0,0,fileList);
1.408 + delete fileList;
1.409 +
1.410 + matchName=_L("*.*");
1.411 + matchUid=TUidType(TUid::Null(),TUid::Uid(2),TUid::Null());
1.412 + r=TheFs.GetDir(matchName,matchUid,ESortByName|EAscending,fileList);
1.413 + test(r==KErrNone);
1.414 + count=fileList->Count();
1.415 + test(count==3);
1.416 + MatchUidFile(0,2,fileList);
1.417 + MatchUidFile(1,1,fileList);
1.418 + MatchUidFile(4,0,fileList);
1.419 + delete fileList;
1.420 +
1.421 + matchName=_L("*.*");
1.422 + matchUid=TUidType(TUid::Null(),TUid::Null(),TUid::Uid(731));
1.423 + r=TheFs.GetDir(matchName,matchUid,ESortByName|EAscending,fileList);
1.424 + test(r==KErrNone);
1.425 + count=fileList->Count();
1.426 + test(count==3);
1.427 + MatchUidFile(2,0,fileList);
1.428 + MatchUidFile(1,1,fileList);
1.429 + MatchUidFile(0,2,fileList);
1.430 + delete fileList;
1.431 +
1.432 + matchName=_L("*.*");
1.433 + r=TheFs.GetDir(matchName,KEntryAttNormal,ESortByUid|EAscending,fileList);
1.434 + test(r==KErrNone);
1.435 + count=fileList->Count();
1.436 + MatchUidFile(4,0,fileList);
1.437 + MatchUidFile(1,1,fileList);
1.438 + MatchUidFile(0,2,fileList);
1.439 + MatchUidFile(5,3,fileList);
1.440 + MatchUidFile(2,4,fileList);
1.441 + MatchUidFile(3,5,fileList);
1.442 + MatchUidFile(6,6,fileList);
1.443 + for (i=7;i<count;i++)
1.444 + {
1.445 + TEntry entry;
1.446 + entry=(*fileList)[i];
1.447 + test(entry.iType[2].iUid==0);
1.448 + PrintUid(i,fileList);
1.449 + }
1.450 + test(i==count);
1.451 + delete fileList;
1.452 + }
1.453 +
1.454 +LOCAL_C void testZGetDirByUid()
1.455 +//
1.456 +// Get directory contents by matching UIDs from Z:
1.457 +//
1.458 + {
1.459 +
1.460 + TUidType matchUid(TUid::Null(),TUid::Uid(0x1000008c),TUid::Null());
1.461 + CDir* fileList;
1.462 + TInt r=TheFs.GetDir(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("Z:\\SYS\\BIN\\"):_L("Z:\\SYSTEM\\BIN\\"),matchUid,EAscending,fileList);
1.463 + test(r==KErrNone);
1.464 + TInt count=fileList->Count();
1.465 +#if defined(__WINS__)
1.466 + test(count==0);
1.467 +#else
1.468 + test.Printf(_L("Count=%d\n"),count);
1.469 + while(count--)
1.470 + PrintUid(count,fileList);
1.471 +// test(count==1);
1.472 +// TEntry entry;
1.473 +// entry=(*fileList)[0];
1.474 +// test(entry.iName.MatchF(_L("EFILE.EXE"))!=KErrNotFound);
1.475 +#endif
1.476 + delete fileList;
1.477 + }
1.478 +
1.479 +LOCAL_C void testGetFilesExcept()
1.480 +//
1.481 +// Get all files except read only ...
1.482 +//
1.483 + {
1.484 +
1.485 + MakeFile(_L("\\F32-TST\\GDIR\\RONLY1.CCC"),KEntryAttReadOnly);
1.486 + MakeFile(_L("\\F32-TST\\GDIR\\RONLY2.CCC"),KEntryAttReadOnly);
1.487 + MakeFile(_L("\\F32-TST\\GDIR\\RW1.CCC"));
1.488 + MakeFile(_L("\\F32-TST\\GDIR\\RW2.CCC"));
1.489 + MakeFile(_L("\\F32-TST\\GDIR\\SYSTEM1.CCC"),KEntryAttSystem);
1.490 + MakeFile(_L("\\F32-TST\\GDIR\\SYSTEM2.CCC"),KEntryAttSystem);
1.491 +
1.492 + test.Next(_L("Can match only read only files"));
1.493 + TUint onlyRO=KEntryAttReadOnly|KEntryAttMatchExclusive;
1.494 + CDir* fileList;
1.495 + TInt r=TheFs.GetDir(_L("\\F32-TST\\GDIR\\*.CCC"),onlyRO,EAscending,fileList);
1.496 + test(r==KErrNone);
1.497 + TInt count=fileList->Count();
1.498 + test(count==2);
1.499 +
1.500 + TEntry entry;
1.501 + entry=(*fileList)[0];
1.502 + test(entry.iName.MatchF(_L("RONLY1.CCC"))!=KErrNotFound);
1.503 + entry=(*fileList)[1];
1.504 + test(entry.iName.MatchF(_L("RONLY2.CCC"))!=KErrNotFound);
1.505 + delete fileList;
1.506 +
1.507 + test.Next(_L("Can match everything except read only files"));
1.508 + TUint excludeRO=KEntryAttReadOnly|KEntryAttMatchExclude;
1.509 + r=TheFs.GetDir(_L("\\F32-TST\\GDIR\\*.CCC"),excludeRO,EAscending,fileList);
1.510 + test(r==KErrNone);
1.511 + count=fileList->Count();
1.512 + test(count==4);
1.513 +
1.514 + entry=(*fileList)[0];
1.515 + test(entry.iName.MatchF(_L("RW1.CCC"))!=KErrNotFound);
1.516 + entry=(*fileList)[1];
1.517 + test(entry.iName.MatchF(_L("RW2.CCC"))!=KErrNotFound);
1.518 + entry=(*fileList)[2];
1.519 + test(entry.iName.MatchF(_L("SYSTEM1.CCC"))!=KErrNotFound);
1.520 + entry=(*fileList)[3];
1.521 + test(entry.iName.MatchF(_L("SYSTEM2.CCC"))!=KErrNotFound);
1.522 + delete fileList;
1.523 +
1.524 + test.Next(_L("Can match everything except system and readonly files"));
1.525 + TUint excludeSystemAndRO=KEntryAttReadOnly|KEntryAttSystem|KEntryAttMatchExclude;
1.526 + r=TheFs.GetDir(_L("\\F32-TST\\GDIR\\*.CCC"),excludeSystemAndRO,EAscending,fileList);
1.527 + test(r==KErrNone);
1.528 + count=fileList->Count();
1.529 + test(count==2);
1.530 +
1.531 + entry=(*fileList)[0];
1.532 + test(entry.iName.MatchF(_L("RW1.CCC"))!=KErrNotFound);
1.533 + entry=(*fileList)[1];
1.534 + test(entry.iName.MatchF(_L("RW2.CCC"))!=KErrNotFound);
1.535 + delete fileList;
1.536 +
1.537 + r=TheFs.SetAtt(_L("\\F32-TST\\GDIR\\RONLY1.CCC"),0,KEntryAttReadOnly);
1.538 + test(r==KErrNone);
1.539 + r=TheFs.SetAtt(_L("\\F32-TST\\GDIR\\RONLY2.CCC"),0,KEntryAttReadOnly);
1.540 + test(r==KErrNone);
1.541 + }
1.542 +
1.543 +LOCAL_C void testGetHidden()
1.544 +//
1.545 +// Match hidden files and directories
1.546 +//
1.547 + {
1.548 +
1.549 + test.Next(_L("Match hidden files and directories"));
1.550 + MakeFile(_L("File.qqq"));
1.551 + MakeFile(_L("FileHidden.qqq"));
1.552 + MakeFile(_L("FileSystem.qqq"));
1.553 + MakeFile(_L("FileHiddenSystem.qqq"));
1.554 + MakeDir(_L("\\F32-TST\\GDIR\\Dir.qqq\\"));
1.555 + MakeDir(_L("\\F32-TST\\GDIR\\Dirhidden.qqq\\"));
1.556 + MakeDir(_L("\\F32-TST\\GDIR\\Dirsystem.qqq\\"));
1.557 + MakeDir(_L("\\F32-TST\\GDIR\\Dirhiddensystem.qqq\\"));
1.558 +
1.559 + TInt r=TheFs.SetAtt(_L("FileHidden.qqq"),KEntryAttHidden,0);
1.560 + test(r==KErrNone);
1.561 + r=TheFs.SetAtt(_L("Filesystem.qqq"),KEntryAttSystem,0);
1.562 + test(r==KErrNone);
1.563 + r=TheFs.SetAtt(_L("FilehiddenSystem.qqq"),KEntryAttSystem|KEntryAttHidden,0);
1.564 + test(r==KErrNone);
1.565 + r=TheFs.SetAtt(_L("dirhidden.qqq"),KEntryAttHidden,0);
1.566 + test(r==KErrNone);
1.567 + r=TheFs.SetAtt(_L("dirsystem.qqq"),KEntryAttSystem,0);
1.568 + test(r==KErrNone);
1.569 + r=TheFs.SetAtt(_L("dirhiddensystem.qqq"),KEntryAttSystem|KEntryAttHidden,0);
1.570 + test(r==KErrNone);
1.571 +
1.572 +// Files and directories not hidden or system
1.573 + CDir* dir;
1.574 + r=TheFs.GetDir(_L("*.qqq"),KEntryAttDir,ESortByName,dir);
1.575 + test(r==KErrNone);
1.576 + TInt count=dir->Count();
1.577 + test(count==2);
1.578 + TEntry entry;
1.579 + entry=(*dir)[0];
1.580 + test(entry.iName.MatchF(_L("dir.qqq"))!=KErrNotFound);
1.581 + entry=(*dir)[1];
1.582 + test(entry.iName.MatchF(_L("file.qqq"))!=KErrNotFound);
1.583 + delete dir;
1.584 +
1.585 +// Files only
1.586 + r=TheFs.GetDir(_L("*.qqq"),KEntryAttNormal,ESortByName,dir);
1.587 + test(r==KErrNone);
1.588 + count=dir->Count();
1.589 + test(count==1);
1.590 + entry=(*dir)[0];
1.591 + test(entry.iName.MatchF(_L("file.qqq"))!=KErrNotFound);
1.592 + delete dir;
1.593 +
1.594 +// Directories only
1.595 + r=TheFs.GetDir(_L("*.qqq"),KEntryAttDir|KEntryAttMatchExclusive,ESortByName,dir);
1.596 + test(r==KErrNone);
1.597 + count=dir->Count();
1.598 + test(count==1);
1.599 + entry=(*dir)[0];
1.600 + test(entry.iName.MatchF(_L("dir.qqq"))!=KErrNotFound);
1.601 + delete dir;
1.602 +
1.603 +// Files + hidden
1.604 + r=TheFs.GetDir(_L("*.qqq"),KEntryAttHidden,ESortByName,dir);
1.605 + test(r==KErrNone);
1.606 + count=dir->Count();
1.607 + test(count==2);
1.608 + entry=(*dir)[0];
1.609 + test(entry.iName.MatchF(_L("file.qqq"))!=KErrNotFound);
1.610 + entry=(*dir)[1];
1.611 + test(entry.iName.MatchF(_L("filehidden.qqq"))!=KErrNotFound);
1.612 + delete dir;
1.613 +
1.614 +// Files + system
1.615 + r=TheFs.GetDir(_L("*.qqq"),KEntryAttHidden,ESortByName,dir);
1.616 + test(r==KErrNone);
1.617 + count=dir->Count();
1.618 + test(count==2);
1.619 + entry=(*dir)[0];
1.620 + test(entry.iName.MatchF(_L("file.qqq"))!=KErrNotFound);
1.621 + entry=(*dir)[1];
1.622 + test(entry.iName.MatchF(_L("filehidden.qqq"))!=KErrNotFound);
1.623 + delete dir;
1.624 +
1.625 +// Files + hidden + system
1.626 + r=TheFs.GetDir(_L("*.qqq"),KEntryAttHidden|KEntryAttSystem,ESortByName,dir);
1.627 + test(r==KErrNone);
1.628 + count=dir->Count();
1.629 + test(count==4);
1.630 + entry=(*dir)[0];
1.631 + test(entry.iName.MatchF(_L("file.qqq"))!=KErrNotFound);
1.632 + entry=(*dir)[1];
1.633 + test(entry.iName.MatchF(_L("filehidden.qqq"))!=KErrNotFound);
1.634 + entry=(*dir)[2];
1.635 + test(entry.iName.MatchF(_L("filehiddensystem.qqq"))!=KErrNotFound);
1.636 + entry=(*dir)[3];
1.637 + test(entry.iName.MatchF(_L("filesystem.qqq"))!=KErrNotFound);
1.638 + delete dir;
1.639 +
1.640 +// Dirs + hidden
1.641 + r=TheFs.GetDir(_L("*.qqq"),KEntryAttHidden|KEntryAttDir|KEntryAttMatchExclusive,ESortByName,dir);
1.642 + test(r==KErrNone);
1.643 + count=dir->Count();
1.644 + test(count==2);
1.645 + entry=(*dir)[0];
1.646 + test(entry.iName.MatchF(_L("dir.qqq"))!=KErrNotFound);
1.647 + entry=(*dir)[1];
1.648 + test(entry.iName.MatchF(_L("dirhidden.qqq"))!=KErrNotFound);
1.649 + delete dir;
1.650 +
1.651 +// Dirs + system
1.652 + r=TheFs.GetDir(_L("*.qqq"),KEntryAttSystem|KEntryAttDir|KEntryAttMatchExclusive,ESortByName,dir);
1.653 + test(r==KErrNone);
1.654 + count=dir->Count();
1.655 + test(count==2);
1.656 + entry=(*dir)[0];
1.657 + test(entry.iName.MatchF(_L("dir.qqq"))!=KErrNotFound);
1.658 + entry=(*dir)[1];
1.659 + test(entry.iName.MatchF(_L("dirsystem.qqq"))!=KErrNotFound);
1.660 + delete dir;
1.661 +
1.662 +// Dirs + hidden + system
1.663 + r=TheFs.GetDir(_L("*.qqq"),KEntryAttHidden|KEntryAttSystem|KEntryAttDir|KEntryAttMatchExclusive,ESortByName,dir);
1.664 + test(r==KErrNone);
1.665 + count=dir->Count();
1.666 + test(count==4);
1.667 + entry=(*dir)[0];
1.668 + test(entry.iName.MatchF(_L("dir.qqq"))!=KErrNotFound);
1.669 + entry=(*dir)[1];
1.670 + test(entry.iName.MatchF(_L("dirhidden.qqq"))!=KErrNotFound);
1.671 + entry=(*dir)[2];
1.672 + test(entry.iName.MatchF(_L("dirhiddensystem.qqq"))!=KErrNotFound);
1.673 + entry=(*dir)[3];
1.674 + test(entry.iName.MatchF(_L("dirsystem.qqq"))!=KErrNotFound);
1.675 +
1.676 + delete dir;
1.677 +
1.678 +// Files + Dirs + hidden
1.679 + r=TheFs.GetDir(_L("*.qqq"),KEntryAttHidden|KEntryAttDir,ESortByName,dir);
1.680 + test(r==KErrNone);
1.681 + count=dir->Count();
1.682 + test(count==4);
1.683 + entry=(*dir)[0];
1.684 + test(entry.iName.MatchF(_L("dir.qqq"))!=KErrNotFound);
1.685 + entry=(*dir)[1];
1.686 + test(entry.iName.MatchF(_L("dirhidden.qqq"))!=KErrNotFound);
1.687 + entry=(*dir)[2];
1.688 + test(entry.iName.MatchF(_L("file.qqq"))!=KErrNotFound);
1.689 + entry=(*dir)[3];
1.690 + test(entry.iName.MatchF(_L("filehidden.qqq"))!=KErrNotFound);
1.691 + delete dir;
1.692 +
1.693 +// Files + Dirs + system
1.694 + r=TheFs.GetDir(_L("*.qqq"),KEntryAttSystem|KEntryAttDir,ESortByName,dir);
1.695 + test(r==KErrNone);
1.696 + count=dir->Count();
1.697 + test(count==4);
1.698 + entry=(*dir)[0];
1.699 + test(entry.iName.MatchF(_L("dir.qqq"))!=KErrNotFound);
1.700 + entry=(*dir)[1];
1.701 + test(entry.iName.MatchF(_L("dirsystem.qqq"))!=KErrNotFound);
1.702 + entry=(*dir)[2];
1.703 + test(entry.iName.MatchF(_L("file.qqq"))!=KErrNotFound);
1.704 + entry=(*dir)[3];
1.705 + test(entry.iName.MatchF(_L("filesystem.qqq"))!=KErrNotFound);
1.706 + delete dir;
1.707 +
1.708 +// Files + Dirs + hidden + system
1.709 + r=TheFs.GetDir(_L("*.qqq"),KEntryAttHidden|KEntryAttSystem|KEntryAttDir,ESortByName,dir);
1.710 + test(r==KErrNone);
1.711 + count=dir->Count();
1.712 + test(count==8);
1.713 + entry=(*dir)[0];
1.714 + test(entry.iName.MatchF(_L("dir.qqq"))!=KErrNotFound);
1.715 + entry=(*dir)[1];
1.716 + test(entry.iName.MatchF(_L("dirhidden.qqq"))!=KErrNotFound);
1.717 + entry=(*dir)[2];
1.718 + test(entry.iName.MatchF(_L("dirhiddensystem.qqq"))!=KErrNotFound);
1.719 + entry=(*dir)[3];
1.720 + test(entry.iName.MatchF(_L("dirsystem.qqq"))!=KErrNotFound);
1.721 + entry=(*dir)[4];
1.722 + test(entry.iName.MatchF(_L("file.qqq"))!=KErrNotFound);
1.723 + entry=(*dir)[5];
1.724 + test(entry.iName.MatchF(_L("filehidden.qqq"))!=KErrNotFound);
1.725 + entry=(*dir)[6];
1.726 + test(entry.iName.MatchF(_L("filehiddensystem.qqq"))!=KErrNotFound);
1.727 + entry=(*dir)[7];
1.728 + test(entry.iName.MatchF(_L("filesystem.qqq"))!=KErrNotFound);
1.729 + delete dir;
1.730 + }
1.731 +
1.732 +LOCAL_D TFileName gDirDescendingBaseName=_L("\\F32-TST\\GDIR\\TDIRDESCENDING\\");
1.733 +LOCAL_D TFileName gDirDescendingEntryName[6]=
1.734 + {
1.735 + _L("\\F32-TST\\GDIR\\TDIRDESCENDING\\aaaa"),
1.736 + _L("\\F32-TST\\GDIR\\TDIRDESCENDING\\ssss"),
1.737 + _L("\\F32-TST\\GDIR\\TDIRDESCENDING\\ZZZZ"),
1.738 + _L("\\F32-TST\\GDIR\\TDIRDESCENDING\\aaaa.directory\\"),
1.739 + _L("\\F32-TST\\GDIR\\TDIRDESCENDING\\SSSS.dir\\"),
1.740 + _L("\\F32-TST\\GDIR\\TDIRDESCENDING\\ZZZZDirectory\\")
1.741 + };
1.742 +
1.743 +LOCAL_C void TestDirDescendingOrder(const TDesC& aResult,const CDir& aDirList)
1.744 +//
1.745 +// Test aDirList against aResult
1.746 +//
1.747 + {
1.748 +
1.749 + TLex lex(aResult);
1.750 + TInt count=0;
1.751 + while (!lex.Eos())
1.752 + {
1.753 + lex.Mark();
1.754 + while(lex.Get().IsDigit()) {};
1.755 + TLex temp(lex.MarkedToken());
1.756 + TInt result;
1.757 + temp.Val(result);
1.758 + TFileName base=gDirDescendingBaseName;
1.759 + TEntry entry=aDirList[count];
1.760 + base+=entry.iName;
1.761 + if (entry.IsDir())
1.762 + base+=_L("\\");
1.763 + test(base==gDirDescendingEntryName[result]);
1.764 + count++;
1.765 + }
1.766 + }
1.767 +
1.768 +LOCAL_C void testDirDescending()
1.769 +//
1.770 +// Test EDirDescending
1.771 +//
1.772 + {
1.773 +
1.774 + test.Next(_L("Test EDirDescending"));
1.775 + MakeDir(gDirDescendingBaseName);
1.776 + MakeFile(gDirDescendingEntryName[0]);
1.777 + MakeFile(gDirDescendingEntryName[1]);
1.778 + MakeFile(gDirDescendingEntryName[2]);
1.779 + MakeDir(gDirDescendingEntryName[3]);
1.780 + MakeDir(gDirDescendingEntryName[4]);
1.781 + MakeDir(gDirDescendingEntryName[5]);
1.782 +
1.783 +// Test DirFirst - EDescending
1.784 + CDir* dir;
1.785 + TUint sortOrder=ESortByName|EDirsFirst|EDescending;
1.786 + TInt r=TheFs.GetDir(gDirDescendingBaseName,KEntryAttMaskSupported,sortOrder,dir);
1.787 + test(r==KErrNone);
1.788 +// TBuf8<16> result=_L("2,1,0,3,4,5");
1.789 + TBuf<16> result=_L("2,1,0,3,4,5");
1.790 +
1.791 + TestDirDescendingOrder(result,*dir);
1.792 + delete dir;
1.793 +// Test DirFirst - EAscending
1.794 + sortOrder=ESortByName|EDirsFirst;
1.795 + r=TheFs.GetDir(gDirDescendingBaseName,KEntryAttMaskSupported,sortOrder,dir);
1.796 + test(r==KErrNone);
1.797 + result=_L("3,4,5,0,1,2");
1.798 + TestDirDescendingOrder(result,*dir);
1.799 + delete dir;
1.800 +
1.801 +// Test DirLast - EDescending
1.802 + sortOrder=ESortByName|EDirsLast|EDescending;
1.803 + r=TheFs.GetDir(gDirDescendingBaseName,KEntryAttMaskSupported,sortOrder,dir);
1.804 + test(r==KErrNone);
1.805 + result=_L("3,4,5,2,1,0");
1.806 + TestDirDescendingOrder(result,*dir);
1.807 + delete dir;
1.808 +// Test DirLast - EAscending
1.809 + sortOrder=ESortByName|EDirsLast;
1.810 + r=TheFs.GetDir(gDirDescendingBaseName,KEntryAttMaskSupported,sortOrder,dir);
1.811 + test(r==KErrNone);
1.812 + result=_L("0,1,2,3,4,5");
1.813 + TestDirDescendingOrder(result,*dir);
1.814 + delete dir;
1.815 +
1.816 +// Test DirFirst - EDirDescending
1.817 + sortOrder=ESortByName|EDirsFirst|EDirDescending;
1.818 + r=TheFs.GetDir(gDirDescendingBaseName,KEntryAttMaskSupported,sortOrder,dir);
1.819 + test(r==KErrNone);
1.820 + result=_L("5,4,3,0,1,2");
1.821 + TestDirDescendingOrder(result,*dir);
1.822 + delete dir;
1.823 +// Test DirLast - EDirDescending
1.824 + sortOrder=ESortByName|EDirsLast|EDirDescending;
1.825 + r=TheFs.GetDir(gDirDescendingBaseName,KEntryAttMaskSupported,sortOrder,dir);
1.826 + test(r==KErrNone);
1.827 + result=_L("0,1,2,5,4,3");
1.828 + TestDirDescendingOrder(result,*dir);
1.829 + delete dir;
1.830 +
1.831 +// Test DirFirst - EDescending|EDirDescending
1.832 + sortOrder=ESortByName|EDirsFirst|EDescending|EDirDescending;
1.833 + r=TheFs.GetDir(gDirDescendingBaseName,KEntryAttMaskSupported,sortOrder,dir);
1.834 + test(r==KErrNone);
1.835 + result=_L("2,1,0,5,4,3");
1.836 + TestDirDescendingOrder(result,*dir);
1.837 + delete dir;
1.838 +// Test DirLast - EDescending|EDirDescending
1.839 + sortOrder=ESortByName|EDirsLast|EDirDescending|EDescending;
1.840 + r=TheFs.GetDir(gDirDescendingBaseName,KEntryAttMaskSupported,sortOrder,dir);
1.841 + test(r==KErrNone);
1.842 + result=_L("5,4,3,2,1,0");
1.843 + TestDirDescendingOrder(result,*dir);
1.844 + delete dir;
1.845 +
1.846 +// Test DirNoOrder - EDescending|EDirDescending
1.847 + sortOrder=ESortByName|EDescending|EDirDescending;
1.848 + r=TheFs.GetDir(gDirDescendingBaseName,KEntryAttMaskSupported,sortOrder,dir);
1.849 + test(r==KErrNone);
1.850 + result=_L("5,2,4,1,3,0");
1.851 + TestDirDescendingOrder(result,*dir);
1.852 + delete dir;
1.853 +// Test DirNoOrder - EDescending
1.854 + sortOrder=ESortByName|EDescending;
1.855 + r=TheFs.GetDir(gDirDescendingBaseName,KEntryAttMaskSupported,sortOrder,dir);
1.856 + test(r==KErrNone);
1.857 + result=_L("5,2,4,1,3,0");
1.858 + TestDirDescendingOrder(result,*dir);
1.859 + delete dir;
1.860 +// Test DirNoOrder - EAscending
1.861 + sortOrder=ESortByName;
1.862 + r=TheFs.GetDir(gDirDescendingBaseName,KEntryAttMaskSupported,sortOrder,dir);
1.863 + test(r==KErrNone);
1.864 + result=_L("0,3,1,4,2,5");
1.865 + TestDirDescendingOrder(result,*dir);
1.866 + delete dir;
1.867 + }
1.868 +
1.869 +//---------------------------------------------
1.870 +//! @SYMTestCaseID PBASE-T_GDIR-0815
1.871 +//! @SYMTestType UT
1.872 +//! @SYMREQ DEF122894
1.873 +//! @SYMTestCaseDesc This testcase tests the boundary condition of file name collation (8 characters).
1.874 +//! @SYMTestActions Creates file "xxxxxxxx2.dat" and "Xxxxxxxx1.dat" under same directory,
1.875 +//! retrieves dir list via GetDir(), sort list by name, check order of the file listed.
1.876 +//! @SYMTestExpectedResults File "Xxxxxxxx1.dat" should be listed before "xxxxxxxx2.dat".
1.877 +//! @SYMTestPriority High
1.878 +//! @SYMTestStatus Implemented
1.879 +//---------------------------------------------
1.880 +void TestDEF122894()
1.881 + {
1.882 + test.Next(_L("Test \"DEF122894: Defect in RFs GetDir() API\""));
1.883 + MakeFile(_L("\\F32-TST\\GDIR\\DEF122894\\xxxxxxxx2.dat"));
1.884 + MakeFile(_L("\\F32-TST\\GDIR\\DEF122894\\Xxxxxxxx1.dat"));
1.885 + CDir* dir;
1.886 + TInt r=TheFs.GetDir(_L("\\F32-TST\\GDIR\\DEF122894\\"),KEntryAttMaskSupported,ESortByName|EAscending,dir);
1.887 + test(r==KErrNone);
1.888 + test(dir->Count() == 2);
1.889 + TEntry entry1, entry2;
1.890 + entry1 = (*dir)[0];
1.891 + entry2 = (*dir)[1];
1.892 + test(entry1.iName.Compare(_L("Xxxxxxxx1.dat")) == 0);
1.893 + test(entry2.iName.Compare(_L("xxxxxxxx2.dat")) == 0);
1.894 + delete dir;
1.895 + }
1.896 +
1.897 +GLDEF_C void CallTestsL()
1.898 +//
1.899 +// Test directory handling.
1.900 +//
1.901 + {
1.902 +
1.903 + CreateTestDirectory(_L("\\F32-TST\\GDIR\\"));
1.904 + if (gFirstRun)
1.905 + {
1.906 + gFirstRun=EFalse;
1.907 + testZDirectory();
1.908 + testZGetDirByUid();
1.909 + }
1.910 +
1.911 + testSetup();
1.912 + testDir();
1.913 + testDisplayFiles();
1.914 + testGetDirByUid();
1.915 + testGetFilesExcept();
1.916 + testGetHidden();
1.917 + testDirDescending();
1.918 + TestDEF122894();
1.919 + DeleteTestDirectory();
1.920 + }
1.921 +