1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/server/t_locate.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1055 @@
1.4 +// Copyright (c) 1996-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_locate.cpp
1.18 +//
1.19 +//
1.20 +#define __E32TEST_EXTENSION__
1.21 +#include <f32file.h>
1.22 +#include <e32test.h>
1.23 +#include "t_server.h"
1.24 +
1.25 +
1.26 +
1.27 +GLDEF_D RTest test(_L("T_LOCATE"));
1.28 +
1.29 +LOCAL_D TFileName gPath1;
1.30 +LOCAL_D TFileName gPath2;
1.31 +LOCAL_D TFileName gPath3;
1.32 +LOCAL_D TFileName gPath4;
1.33 +LOCAL_D TFileName gPath5;
1.34 +
1.35 +
1.36 +LOCAL_D TFileName gRemovableDriveFile;
1.37 +LOCAL_D TFileName gInternalDriveFile;
1.38 +LOCAL_D TFileName gInternalDriveFile2;
1.39 +
1.40 +
1.41 +LOCAL_D TChar removableDriveLetter;
1.42 +LOCAL_D TChar internalDriveLetter;
1.43 +
1.44 +
1.45 +LOCAL_D TInt removableFlag=0;
1.46 +LOCAL_D TInt internalFlag=0;
1.47 +
1.48 +
1.49 +
1.50 +LOCAL_C void Md(const TDesC& aDirName)
1.51 +//
1.52 +// Make a dir
1.53 +//
1.54 + {
1.55 +
1.56 + TInt r=TheFs.MkDirAll(aDirName);
1.57 + if (r == KErrCorrupt)
1.58 + test.Printf(_L("Media corruption; previous test may have aborted; else, check hardware\n"));
1.59 + else if (r == KErrNotReady)
1.60 + test.Printf(_L("No medium present / drive not ready, previous test may have hung; else, check hardware\n"));
1.61 + test_Value(r, r == KErrNone || r == KErrAlreadyExists);
1.62 + }
1.63 +
1.64 +LOCAL_C void Mf(const TDesC& aFileName)
1.65 +//
1.66 +// Make a file
1.67 +//
1.68 + {
1.69 +
1.70 + RFile file;
1.71 + TInt r = file.Replace(TheFs,aFileName,0);
1.72 + if (r == KErrPathNotFound)
1.73 + {
1.74 + test.Printf(_L("Mf: Path Not Found\n"));
1.75 + Md(aFileName);
1.76 + r=file.Replace(TheFs,aFileName,0);
1.77 + }
1.78 +
1.79 + if (r == KErrCorrupt)
1.80 + test.Printf(_L("Media corruption; previous test may have aborted; else, check hardware\n"));
1.81 + else if (r == KErrNotReady)
1.82 + test.Printf(_L("No medium present / drive not ready, previous test may have hung; else, check hardware\n"));
1.83 +
1.84 + test_Value(r, r == KErrNone || r == KErrAlreadyExists);
1.85 + file.Close();
1.86 + }
1.87 +
1.88 +LOCAL_C void MakeLocateTestDirectoryStructure()
1.89 +//
1.90 +// Create files for test
1.91 +//
1.92 + {
1.93 + test.Next(_L("Create LOCTEST directories"));
1.94 + Md(_L("\\F32-TST\\LOCTEST\\BIN1\\"));
1.95 + Md(_L("\\F32-TST\\LOCTEST\\BIN2\\"));
1.96 + Md(_L("\\F32-TST\\LOCTEST\\BIN3\\"));
1.97 + Md(_L("\\F32-TST\\LOCTEST\\BIN1\\BIN4\\"));
1.98 +
1.99 +
1.100 +
1.101 +#if defined(_DEBUG)
1.102 + TheFs.SetErrorCondition(-47,5);
1.103 + TDriveInfo drive;
1.104 + for (TInt i=0;i<5;i++)
1.105 + {
1.106 + TInt r=TheFs.Drive(drive);
1.107 + test(r==KErrNone);
1.108 + }
1.109 + TInt r=TheFs.MkDirAll(_L("alskdjfl"));
1.110 + test(r==-47);
1.111 + r=TheFs.MkDirAll(_L("alskdjfl"));
1.112 + test(r==-47);
1.113 + TheFs.SetErrorCondition(KErrNone);
1.114 + r=TheFs.Drive(drive);
1.115 + test(r==KErrNone);
1.116 +#endif
1.117 +//
1.118 + test.Next(_L("Create LOCTEST files"));
1.119 + Mf(_L("\\F32-TST\\LOCTEST\\FILE1.AAA"));
1.120 + Mf(_L("\\F32-TST\\LOCTEST\\FILE2.BBB"));
1.121 + Mf(_L("\\F32-TST\\LOCTEST\\FILE3.CCC"));
1.122 + Mf(_L("\\F32-TST\\LOCTEST\\WORK.AAA"));
1.123 + Mf(_L("\\F32-TST\\LOCTEST\\HOME.CCC"));
1.124 + Mf(_L("\\F32-TST\\LOCTEST\\FILE.AAA"));
1.125 + Mf(_L("C:\\F32-TST\\LOCTEST\\BIN1\\FILE1.AAA"));
1.126 + Mf(_L("C:\\F32-TST\\LOCTEST\\BIN1\\WORK.AAA"));
1.127 + Mf(_L("C:\\F32-TST\\LOCTEST\\BIN1\\WORK.BBB"));
1.128 + Mf(_L("\\F32-TST\\LOCTEST\\BIN1\\FILE1.AAA"));
1.129 + Mf(_L("\\F32-TST\\LOCTEST\\BIN1\\WORK.AAA"));
1.130 + Mf(_L("\\F32-TST\\LOCTEST\\BIN1\\WORK.BBB"));
1.131 + Mf(_L("\\F32-TST\\LOCTEST\\BIN1\\CONFUSED.DOG"));
1.132 + Mf(_L("\\F32-TST\\LOCTEST\\BIN2\\FILE1.BBB"));
1.133 + Mf(_L("\\F32-TST\\LOCTEST\\BIN2\\WORK.BBB"));
1.134 + Mf(_L("\\F32-TST\\LOCTEST\\BIN2\\FILE2.BBB"));
1.135 + Mf(_L("\\F32-TST\\LOCTEST\\BIN2\\FILE3.BBB"));
1.136 + Mf(_L("\\F32-TST\\LOCTEST\\BIN3\\FILE3.CCC"));
1.137 + Mf(_L("\\F32-TST\\LOCTEST\\BIN3\\WORK.CCC"));
1.138 + Mf(_L("\\F32-TST\\LOCTEST\\BIN3\\PLAY.CCC"));
1.139 + Mf(_L("\\F32-TST\\LOCTEST\\BIN1\\BIN4\\FILE1.AAA"));
1.140 + Mf(_L("\\F32-TST\\LOCTEST\\BIN1\\BIN4\\FILE2.BBB"));
1.141 + Mf(_L("\\F32-TST\\LOCTEST\\BIN1\\BIN4\\FILE3.CCC"));
1.142 + Mf(_L("\\F32-TST\\LOCTEST\\BIN1\\BIN4\\FILE4.DDD"));
1.143 +
1.144 +
1.145 +
1.146 + }
1.147 +
1.148 +
1.149 +LOCAL_C void CreateFilesInRemovableDrive()
1.150 + {
1.151 +
1.152 +
1.153 + TInt err;
1.154 + TDriveList driveList;
1.155 + TDriveInfo info;
1.156 +
1.157 + err = TheFs.DriveList(driveList);
1.158 + test( err == KErrNone );
1.159 +
1.160 + for (TInt i = 0; i < KMaxDrives; i++)
1.161 + {
1.162 +
1.163 + if (driveList[i])
1.164 + {
1.165 + err = TheFs.Drive(info, i);
1.166 + test( err == KErrNone );
1.167 +
1.168 + if( info.iDriveAtt & KDriveAttRemovable )
1.169 + {
1.170 +
1.171 + if ( ( info.iType != EMediaNotPresent) && (info.iType != EMediaUnknown) && (info.iType != EMediaCdRom) )
1.172 + {
1.173 + TheFs.DriveToChar(i,removableDriveLetter) ;
1.174 + gRemovableDriveFile.Append (removableDriveLetter);
1.175 + gRemovableDriveFile.Append (_L(":\\F32-TST\\LOCTEST\\BIN\\FINDFILE.AAA") );
1.176 +
1.177 + Mf(gRemovableDriveFile);
1.178 + removableFlag=1;
1.179 + break;
1.180 + }
1.181 + else
1.182 + continue;
1.183 +
1.184 +
1.185 + }
1.186 +
1.187 +
1.188 + }
1.189 +
1.190 + }
1.191 +
1.192 + }
1.193 +
1.194 +
1.195 +
1.196 +LOCAL_C void CreateFilesInInternalDrive()
1.197 + {
1.198 +
1.199 + TInt err;
1.200 + TDriveList driveList;
1.201 + TDriveInfo info;
1.202 +
1.203 + err = TheFs.DriveList(driveList);
1.204 + test( err == KErrNone );
1.205 +
1.206 + for (TInt i = 0; i < KMaxDrives; i++)
1.207 + {
1.208 +
1.209 + if (driveList[i])
1.210 + {
1.211 + err = TheFs.Drive(info, i);
1.212 + test( err == KErrNone );
1.213 +
1.214 + if( info.iDriveAtt & KDriveAttInternal )
1.215 + {
1.216 +
1.217 + TheFs.DriveToChar(i,internalDriveLetter) ;
1.218 + gInternalDriveFile.Append (internalDriveLetter);
1.219 + gInternalDriveFile.Append (_L(":\\F32-TST\\LOCTEST\\BIN\\INT\\FINDINTERNALFILE.AAA") );
1.220 +
1.221 + gInternalDriveFile2.Append (internalDriveLetter);
1.222 + gInternalDriveFile2.Append (_L(":\\F32-TST\\LOCTEST\\BIN\\INT\\FINDINTERNALFILE_B.AAA") );
1.223 +
1.224 + Mf(gInternalDriveFile);
1.225 + Mf(gInternalDriveFile2);
1.226 + internalFlag=1;
1.227 +
1.228 + break;
1.229 + }
1.230 +
1.231 + }
1.232 +
1.233 + }
1.234 +
1.235 +
1.236 + }
1.237 +
1.238 +
1.239 +
1.240 +
1.241 +LOCAL_C void DeleteRemovableDirectory()
1.242 + {
1.243 +
1.244 + //Delete the directory structure we created in the removalbe drive
1.245 + if ( removableFlag == 1 )
1.246 + {
1.247 + CFileMan* fMan=CFileMan::NewL(TheFs);
1.248 + test(fMan!=NULL);
1.249 +
1.250 + TFileName gPathRem;
1.251 + gPathRem.Append (removableDriveLetter);
1.252 + gPathRem.Append (_L(":\\F32-TST\\") );
1.253 + TInt r=fMan->RmDir(gPathRem);
1.254 + test(r==KErrNone);
1.255 +
1.256 + delete fMan;
1.257 + }
1.258 + }
1.259 +
1.260 +LOCAL_C void DeleteInternalDirectory()
1.261 + {
1.262 +
1.263 + //Delete the directory structure we created in the internal drive
1.264 +
1.265 +
1.266 + if( internalFlag == 1 )
1.267 + {
1.268 + CFileMan* fMan=CFileMan::NewL(TheFs);
1.269 + test(fMan!=NULL);
1.270 +
1.271 + TFileName gPathInt;
1.272 + gPathInt.Append (internalDriveLetter);
1.273 + gPathInt.Append (_L(":\\F32-TST\\") );
1.274 + TInt r=fMan->RmDir(gPathInt);
1.275 + test(r==KErrNone);
1.276 +
1.277 + delete fMan;
1.278 + }
1.279 + }
1.280 +
1.281 +
1.282 +LOCAL_C void MountRemoteFilesystem()
1.283 + {
1.284 +
1.285 + test.Next(_L("Mount Remote Drive simulator on Q:\n"));
1.286 +
1.287 +
1.288 + TInt r=TheFs.AddFileSystem(_L("CFAFSDLY"));
1.289 + test.Printf(_L("Add remote file system\n"));
1.290 + test.Printf(_L("AddFileSystem returned %d\n"),r);
1.291 + test (r==KErrNone || r==KErrAlreadyExists);
1.292 +
1.293 +
1.294 + r=TheFs.MountFileSystem(_L("DELAYFS"),EDriveQ);
1.295 +
1.296 +
1.297 + test.Printf(_L("Mount remote file system\n"));
1.298 + test.Printf(_L("MountFileSystem returned %d\n"),r);
1.299 + test(r==KErrNone || r==KErrCorrupt || r==KErrNotReady || r==KErrAlreadyExists);
1.300 +
1.301 +
1.302 + Mf(_L("Q:\\F32-TST\\LOCTEST\\BIN\\FINDFILE.AAA"));
1.303 +
1.304 + }
1.305 +
1.306 +
1.307 +
1.308 +LOCAL_C void DisMountRemoteFilesystem()
1.309 + {
1.310 +
1.311 + test.Printf(_L("Dismounting the remote Drives \n"));
1.312 +
1.313 + TInt r=TheFs.DismountFileSystem(_L("DELAYFS"),EDriveQ);
1.314 +
1.315 + test.Printf(_L("Dismounting the Remote Drive returned %d\n"),r);
1.316 +
1.317 + test(r==KErrNone );
1.318 + }
1.319 +
1.320 +
1.321 +
1.322 +
1.323 +LOCAL_C void Test1()
1.324 +//
1.325 +// Do simple tests
1.326 +//
1.327 + {
1.328 + test.Next(_L("Test FindByPath"));
1.329 +
1.330 + TAutoClose<RFs> fs;
1.331 + TInt r=fs.iObj.Connect();
1.332 + test(r==KErrNone);
1.333 + TFindFile finder(fs.iObj);
1.334 + TPtrC path=gPath1;
1.335 + r=finder.FindByPath(_L("file1.aaa"),&path);
1.336 + test(r==KErrNone);
1.337 + TParse fileParse;
1.338 + fileParse.Set(finder.File(),NULL,NULL);
1.339 + test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN1\\"));
1.340 + test(fileParse.NameAndExt()==_L("file1.aaa"));
1.341 + r=finder.Find();
1.342 + test(r==KErrNotFound);
1.343 +
1.344 +
1.345 + path.Set(gPath2);
1.346 + r=finder.FindByPath(_L("file1.aaa"),&path);
1.347 + test(r==KErrNone);
1.348 + fileParse.Set(finder.File(),NULL,NULL);
1.349 + test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN1\\"));
1.350 + test(fileParse.NameAndExt()==_L("file1.aaa"));
1.351 + r=finder.Find();
1.352 + test(r==KErrNone);
1.353 + fileParse.Set(finder.File(),NULL,NULL);
1.354 + test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN1\\BIN4\\"));
1.355 + test(fileParse.NameAndExt()==_L("file1.aaa"));
1.356 + r=finder.Find();
1.357 + test(r==KErrNotFound);
1.358 +//
1.359 + test.Next(_L("Test FindByDir"));
1.360 + TPtrC dir=_L("\\F32-TST\\LOCTEST\\BIN2\\");
1.361 + r=finder.FindByDir(_L("file2.bbb"),dir);
1.362 + test(r==KErrNone);
1.363 + TFileName defaultPath;
1.364 + r=TheFs.SessionPath(defaultPath);
1.365 + defaultPath.SetLength(2);
1.366 + test(r==KErrNone);
1.367 + fileParse.Set(finder.File(),NULL,NULL);
1.368 + test(fileParse.Drive()==defaultPath);
1.369 + test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN2\\"));
1.370 + test(_L("file2.bbb").MatchF(fileParse.NameAndExt())!=KErrNotFound); // MatchF only sees wildcards in its argument
1.371 + r=finder.Find();
1.372 + if (r==KErrNone)
1.373 + {
1.374 + fileParse.Set(finder.File(),NULL,NULL);
1.375 + if (defaultPath==_L("C:"))
1.376 + test(fileParse.Drive()==_L("Y:"));
1.377 + else
1.378 + test(fileParse.Drive()==_L("C:"));
1.379 + test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN2\\"));
1.380 + test(_L("file2.bbb").MatchF(fileParse.NameAndExt())!=KErrNotFound);
1.381 + r=finder.Find();
1.382 + }
1.383 + test(r==KErrNotFound);
1.384 + }
1.385 +
1.386 +LOCAL_C void Test2()
1.387 +//
1.388 +// Test extremes
1.389 +//
1.390 + {
1.391 +
1.392 + test.Next(_L("Test extremes"));
1.393 + TAutoClose<RFs> fs;
1.394 + TInt r=fs.iObj.Connect();
1.395 + test(r==KErrNone);
1.396 + TBuf<4> temp=_L("");
1.397 + TFindFile finder(fs.iObj);
1.398 + r=finder.FindByPath(_L("file1.aaa"),&temp);
1.399 + test(r==KErrNotFound);
1.400 + r=finder.Find();
1.401 + test(r==KErrNotFound);
1.402 +//
1.403 + TPtrC path=_L("blarg.7");
1.404 + r=finder.FindByPath(_L(""),&path);
1.405 + test(r==KErrArgument);
1.406 + r=finder.FindByPath(_L("*"),&path);
1.407 + test(r==KErrNotFound);
1.408 + r=finder.FindByPath(_L("xmvid"),&path);
1.409 + test(r==KErrNotFound);
1.410 + r=finder.Find();
1.411 + test(r==KErrNotFound);
1.412 +//
1.413 + path.Set(_L("C:\\F32-TST\\LOCTEST\\BIN1\\;\\F32-TST\\LOCTEST\\BIN2\\;Z:\\F32-TST\\LOCTEST\\BIN1\\BIN4\\;\\F32-TST\\LOCTEST\\BIN3\\;"));
1.414 + r=finder.FindByPath(_L(""),&path);
1.415 + test(r==KErrArgument);
1.416 + r=finder.FindByPath(_L("xyz.abc"),&path);
1.417 + test(r==KErrNotFound);
1.418 + r=finder.Find();
1.419 + test(r==KErrNotFound);
1.420 +
1.421 + test.Next(_L("Test FindByDir with empty file spec"));
1.422 + TPtrC dir2=_L("\\F32-TST\\LOCTEST\\");
1.423 + r=finder.FindByDir(_L(""),dir2);
1.424 + test(r==KErrArgument);
1.425 +
1.426 + }
1.427 +
1.428 +LOCAL_C void Test3()
1.429 +//
1.430 +// Test FindByDrives in a path=_L("c:\xyz;z:\lmnop;\abc;\y:\help");
1.431 +//
1.432 + {
1.433 +
1.434 + test.Next(_L("Test FindInDrivesByPath"));
1.435 + TPtrC path=_L("\\F32-TST\\LOCTEST\\BIN2\\");
1.436 + TFileName defaultPath;
1.437 + TInt r=TheFs.SessionPath(defaultPath);
1.438 + defaultPath.SetLength(2);
1.439 +//
1.440 + TAutoClose<RFs> fs;
1.441 + r=fs.iObj.Connect();
1.442 + test(r==KErrNone);
1.443 + TFindFile finder(fs.iObj);
1.444 + r=finder.FindByPath(_L("file1.aaa"),&path);
1.445 + test(r==KErrNotFound);
1.446 + r=finder.Find();
1.447 + test(r==KErrNotFound);
1.448 +//
1.449 + path.Set(_L("\\F32-TST\\LOCTEST\\BIN2\\"));
1.450 + r=finder.FindByPath(_L("file2.bbb"),&path);
1.451 + test(r==KErrNone);
1.452 + TParse fileParse;
1.453 + fileParse.Set(finder.File(),NULL,NULL);
1.454 + test(fileParse.Drive()==defaultPath);
1.455 + test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN2\\"));
1.456 + test(fileParse.NameAndExt()==_L("file2.bbb"));
1.457 + r=finder.Find();
1.458 + test(r==KErrNotFound || r==KErrNone);
1.459 + if (r==KErrNone)
1.460 + {
1.461 + fileParse.Set(finder.File(),NULL,NULL);
1.462 + test(fileParse.Drive()!=defaultPath);
1.463 + test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN2\\"));
1.464 + test(fileParse.NameAndExt()==_L("file2.bbb"));
1.465 + r=finder.Find();
1.466 + test(r==KErrNotFound);
1.467 + }
1.468 +//
1.469 + path.Set(_L("C:\\F32-TST\\LOCTEST\\BIN1\\;;\\F32-TST\\LOCTEST\\BIN2\\;Z:\\F32-TST\\LOCTEST\\BIN1\\BIN4\\;\\F32-TST\\LOCTEST\\BIN3\\;"));
1.470 + r=finder.FindByPath(_L("xyz.abc"),&path);
1.471 + test(r==KErrNotFound);
1.472 + r=finder.Find();
1.473 + test(r==KErrNotFound);
1.474 +//
1.475 + r=finder.FindByPath(_L("file2.bbb"),&path);
1.476 + test(r==KErrNone);
1.477 + fileParse.Set(finder.File(),NULL,NULL);
1.478 + test(fileParse.Drive()==defaultPath);
1.479 + test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN2\\"));
1.480 + test(fileParse.NameAndExt()==_L("file2.bbb"));
1.481 + r=finder.Find();
1.482 + test(r==KErrNotFound || r==KErrNone);
1.483 + if (r==KErrNone)
1.484 + {
1.485 + fileParse.Set(finder.File(),NULL,NULL);
1.486 + test(fileParse.Drive()!=defaultPath);
1.487 + test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN2\\"));
1.488 + test(fileParse.NameAndExt()==_L("file2.bbb"));
1.489 + r=finder.Find();
1.490 + test(r==KErrNotFound);
1.491 + }
1.492 + }
1.493 +
1.494 +LOCAL_C void Test4()
1.495 +//
1.496 +// Test wildcard findbypath
1.497 +//
1.498 + {
1.499 +
1.500 + test.Next(_L("FindByPath with wild filenames"));
1.501 + TFindFile finder(TheFs);
1.502 + CDir* dir;
1.503 + TInt count;
1.504 + TEntry entry;
1.505 + TFileName path;
1.506 +
1.507 + TInt r=finder.FindWildByPath(_L("*.aaa"),&gPath3,dir);
1.508 + test(r==KErrNone);
1.509 + count=dir->Count();
1.510 + test(count==3);
1.511 + entry=(*dir)[0];
1.512 + test(entry.iName.MatchF(_L("FILE.AAA"))!=KErrNotFound);
1.513 + entry=(*dir)[1];
1.514 + test(entry.iName.MatchF(_L("FILE1.AAA"))!=KErrNotFound);
1.515 + entry=(*dir)[2];
1.516 + test(entry.iName.MatchF(_L("WORK.AAA"))!=KErrNotFound);
1.517 + TParse fileParse;
1.518 + fileParse.Set(finder.File(),NULL,NULL);
1.519 + path=fileParse.FullName();
1.520 + test(path==_L("*.aaa"));
1.521 + delete dir;
1.522 +
1.523 + r=finder.FindWild(dir);
1.524 + test(r==KErrNone);
1.525 + count=dir->Count();
1.526 + test(count==2);
1.527 + entry=(*dir)[0];
1.528 + test(entry.iName.MatchF(_L("FILE1.AAA"))!=KErrNotFound);
1.529 + entry=(*dir)[1];
1.530 + test(entry.iName.MatchF(_L("WORK.AAA"))!=KErrNotFound);
1.531 + fileParse.Set(finder.File(),NULL,NULL);
1.532 + path=fileParse.FullName();
1.533 + test(path==_L("C:\\F32-TST\\LOCTEST\\BIN1\\*.aaa"));
1.534 + delete dir;
1.535 +
1.536 + r=finder.FindWild(dir);
1.537 + test(r==KErrNotFound);
1.538 + r=finder.FindWild(dir);
1.539 + test(r==KErrNotFound);
1.540 +
1.541 + r=finder.FindWildByPath(_L("*FILE.AAA*"), &gPath1, dir);
1.542 + test(r==KErrNone);
1.543 + test(dir->Count()==1);
1.544 + entry=(*dir)[0];
1.545 + test(entry.iName.MatchF(_L("FILE.AAA"))!=KErrNotFound);
1.546 + delete dir;
1.547 + r=finder.FindWildByPath(_L("*FILE.AAA"), &gPath1, dir);
1.548 + test(r==KErrNone);
1.549 + test(dir->Count()==1);
1.550 + entry=(*dir)[0];
1.551 + test(entry.iName.MatchF(_L("FILE.AAA"))!=KErrNotFound);
1.552 + delete dir;
1.553 + r=finder.FindWildByPath(_L("FILE.AAA*"), &gPath1, dir);
1.554 + test(r==KErrNone);
1.555 + test(dir->Count()==1);
1.556 + entry=(*dir)[0];
1.557 + test(entry.iName.MatchF(_L("FILE.AAA"))!=KErrNotFound);
1.558 + delete dir;
1.559 + r=finder.FindWildByPath(_L("CONFUSED.DOG"), &gPath1, dir);
1.560 + test(r==KErrNone);
1.561 + test(dir->Count()==1);
1.562 + entry=(*dir)[0];
1.563 + test(entry.iName.MatchF(_L("CONFUSED.DOG"))!=KErrNotFound);
1.564 + delete dir;
1.565 + r=finder.FindWildByPath(_L("*CONFUSED.DOG"), &gPath1, dir);
1.566 + test(r==KErrNone);
1.567 + test(dir->Count()==1);
1.568 + entry=(*dir)[0];
1.569 + test(entry.iName.MatchF(_L("CONFUSED.DOG"))!=KErrNotFound);
1.570 + delete dir;
1.571 + r=finder.FindWildByPath(_L("CONFUSED.DOG*"), &gPath1, dir);
1.572 + test(r==KErrNone);
1.573 + test(dir->Count()==1);
1.574 + entry=(*dir)[0];
1.575 + test(entry.iName.MatchF(_L("CONFUSED.DOG"))!=KErrNotFound);
1.576 + delete dir;
1.577 + r=finder.FindWildByPath(_L("*CONFUSED.DOG*"), &gPath1, dir);
1.578 + test(r==KErrNone);
1.579 + test(dir->Count()==1);
1.580 + entry=(*dir)[0];
1.581 + test(entry.iName.MatchF(_L("CONFUSED.DOG"))!=KErrNotFound);
1.582 + delete dir;
1.583 + }
1.584 +
1.585 +LOCAL_C void Test5()
1.586 +//
1.587 +// Test wildcard findbydir
1.588 +//
1.589 + {
1.590 +
1.591 + test.Next(_L("FindByDir with wild filenames"));
1.592 + TFindFile finder(TheFs);
1.593 + CDir* dir;
1.594 + TInt count;
1.595 + TEntry entry;
1.596 + TFileName path;
1.597 +
1.598 + TInt r=finder.FindWildByDir(_L("FILE*"),_L("\\F32-TST\\LOCTEST\\BIN3\\"),dir);
1.599 + test(r==KErrNone);
1.600 + count=dir->Count();
1.601 + test(count==1);
1.602 + entry=(*dir)[0];
1.603 + test(entry.iName.MatchF(_L("FILE3.CCC"))!=KErrNotFound);
1.604 + TParse fileParse;
1.605 + fileParse.Set(finder.File(),NULL,NULL);
1.606 + path=fileParse.FullName();
1.607 + TFileName tpath=_L("?:\\F32-TST\\LOCTEST\\BIN3\\FILE*");
1.608 + tpath[0]=gSessionPath[0];
1.609 + test(path.CompareF(tpath)==0);
1.610 + delete dir;
1.611 +
1.612 + r=finder.FindWild(dir);
1.613 + if (r==KErrNotFound)
1.614 + return;
1.615 + test(r==KErrNone);
1.616 + entry=(*dir)[0];
1.617 + test(entry.iName.MatchF(_L("FILE3.CCC"))!=KErrNotFound);
1.618 + fileParse.Set(finder.File(),NULL,NULL);
1.619 + path=fileParse.FullName();
1.620 + test(path.CompareF(tpath)==0);
1.621 + delete dir;
1.622 +
1.623 + r=finder.FindWild(dir);
1.624 + test(r==KErrNotFound);
1.625 + r=finder.FindWild(dir);
1.626 + test(r==KErrNotFound);
1.627 + }
1.628 +
1.629 +LOCAL_C void Test6()
1.630 +//
1.631 +// Test file not found
1.632 +//
1.633 + {
1.634 +
1.635 + test.Next(_L("Test file not found"));
1.636 + TFindFile ff(TheFs);
1.637 + TInt r=ff.FindByDir(_L("NOEXIST.EXE"),_L("\\System\\Programs\\"));
1.638 + test(r==KErrNotFound);
1.639 + }
1.640 +
1.641 +
1.642 +
1.643 +
1.644 +// The following test has the requirement that the only remote drive is the one we mount
1.645 +// during the test(DELAYFS) and which doesn't have any other attributes set. If this is not the
1.646 +// case then test conditions must be changed, in order for the test to stop failing.
1.647 +// Even more if a removable drive is not present in the target platform then findfile.aaa
1.648 +// only exists in the remote one and this is why we have a distinction in the test results.
1.649 +//
1.650 +
1.651 +
1.652 +
1.653 + //---------------------------------------------
1.654 + //! @SYMTestCaseID PBASE-T_LOCATE-0553
1.655 + //! @SYMTestType UT
1.656 + //! @SYMREQ CR909
1.657 + //! @SYMTestCaseDesc When using the various Find functions of class TFindFile,by default remote drives are
1.658 + //! excluded from the list of drives that are searched. Using function
1.659 + //! SetFindMask(TUint aMask) it is possible to specify a combination of attributes that
1.660 + //! the drives to be searched must match.
1.661 + //! @SYMTestActions Call function FindByPath/Find without specifying a mask. Check that remote drives are not
1.662 + //! included. Then call SetFindMask(TUint aMask) using various combinations and verify
1.663 + //! that FindByPath or Find return appopriate results.
1.664 + //! @SYMTestExpectedResults Test that file findfile.aaa is found or not depending on the specified mask.
1.665 + //! @SYMTestPriority High
1.666 + //! @SYMTestStatus Implemented
1.667 + //---------------------------------------------
1.668 +
1.669 +
1.670 +
1.671 +LOCAL_C void Test7()
1.672 +
1.673 + {
1.674 +
1.675 + TAutoClose<RFs> fs;
1.676 + TInt r=fs.iObj.Connect();
1.677 + test(r==KErrNone);
1.678 + TFindFile finder(fs.iObj);
1.679 + TPtrC path=gPath4;
1.680 + r=finder.FindByPath(_L("findfile.aaa"),&path);
1.681 +
1.682 + TParse fileParse;
1.683 +
1.684 + test.Next(_L("Test FindByPath without specifying any mask"));
1.685 +
1.686 + if (removableFlag == 1)
1.687 + {
1.688 + test(r==KErrNone);
1.689 + fileParse.Set(finder.File(),NULL,NULL);
1.690 + test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN\\"));
1.691 + test(fileParse.NameAndExt()==_L("findfile.aaa")); //The filename.aaa in the removable Drive
1.692 + r=finder.Find();
1.693 + test(r==KErrNotFound); //remote drives are excluded by default
1.694 +
1.695 + }
1.696 + else
1.697 + test(r==KErrNotFound);
1.698 +
1.699 +
1.700 +
1.701 + test.Next(_L("Search for the specified file in all Drives, including remotes ones \n"));
1.702 +
1.703 +
1.704 + r=finder.SetFindMask( KDriveAttAll) ;
1.705 + test(r==KErrNone);
1.706 + r=finder.FindByPath(_L("findfile.aaa"),&path);
1.707 + test(r==KErrNone);
1.708 + fileParse.Set(finder.File(),NULL,NULL);
1.709 + test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN\\"));
1.710 + test(fileParse.NameAndExt()==_L("findfile.aaa")); //either the remote or removable one.
1.711 + r=finder.Find();
1.712 +
1.713 +
1.714 + if (removableFlag == 1)
1.715 + {
1.716 + test(r==KErrNone);
1.717 +
1.718 + fileParse.Set(finder.File(),NULL,NULL);
1.719 +
1.720 + test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN\\"));
1.721 + test(fileParse.NameAndExt()==_L("findfile.aaa")); //either the remote or removable one.
1.722 +
1.723 + r=finder.Find();
1.724 + test(r==KErrNotFound);
1.725 + }
1.726 + else
1.727 + {
1.728 + test(r==KErrNotFound);
1.729 +
1.730 + }
1.731 +
1.732 +
1.733 + test.Next(_L("Search exclusively in remote drives \n"));
1.734 +
1.735 + r=finder.SetFindMask( KDriveAttExclusive| KDriveAttRemote);
1.736 + test(r==KErrNone);
1.737 + r=finder.FindByPath(_L("findfile.aaa"),&path);
1.738 + test(r==KErrNone);
1.739 + fileParse.Set(finder.File(),NULL,NULL);
1.740 + test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN\\"));
1.741 + test(fileParse.NameAndExt()==_L("findfile.aaa"));
1.742 + r=finder.Find();
1.743 + test(r==KErrNotFound);
1.744 +
1.745 +
1.746 + test.Next(_L("Search excluding removables and remote \n"));
1.747 +
1.748 + r=finder.SetFindMask( KDriveAttExclude | KDriveAttRemovable |KDriveAttRemote );
1.749 + test(r==KErrNone);
1.750 + r=finder.FindByPath(_L("findfile.aaa"),&path);
1.751 + test(r==KErrNotFound); //filename.aaa exists in the remote drive and if present to the removable one
1.752 +
1.753 +
1.754 + test.Next(_L("Search in Internal Drives \n"));
1.755 +
1.756 + r=finder.SetFindMask(KDriveAttInternal ) ;
1.757 + test(r==KErrNone);
1.758 + r=finder.FindByPath(_L("findfile.aaa"),&path);
1.759 + test(r==KErrNotFound); //filename.aaa exists only in the Removable drive and the remote one.
1.760 +
1.761 +
1.762 + }
1.763 +
1.764 +
1.765 + //---------------------------------------------
1.766 + //! @SYMTestCaseID PBASE-T_LOCATE-0554
1.767 + //! @SYMTestType UT
1.768 + //! @SYMREQ CR909
1.769 + //! @SYMTestCaseDesc Test that SetFindMask(TUint aMask) returns the correct value for all combinations of matching masks.
1.770 + //!
1.771 + //! @SYMTestActions Call SetFindMask for every combination of mask and check that the correct value is returned.
1.772 + //! A structure is used to store the expected value for each combination.
1.773 + //! @SYMTestExpectedResults For every combination either KErrNone or KErrArgument must be returned.
1.774 + //! @SYMTestPriority High.
1.775 + //! @SYMTestStatus Implemented
1.776 + //---------------------------------------------
1.777 +
1.778 +
1.779 +
1.780 +
1.781 +LOCAL_C void Test8()
1.782 +
1.783 + {
1.784 +
1.785 + test.Next(_L("Test SetFindMask with all mask combinations \n"));
1.786 +
1.787 +
1.788 + TAutoClose<RFs> fs;
1.789 + TInt r=fs.iObj.Connect();
1.790 + test(r==KErrNone);
1.791 + TFindFile finder(fs.iObj);
1.792 + TPtrC path=gPath4;
1.793 + TParse fileParse;
1.794 +
1.795 +
1.796 + r=finder.SetFindMask(KDriveAttAll) ;
1.797 + test(r==KErrNone);
1.798 + r=finder.FindByPath(_L("findfile.aaa"),&path);
1.799 + test(r==KErrNone);
1.800 + fileParse.Set(finder.File(),NULL,NULL);
1.801 + test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN\\"));
1.802 + test(fileParse.NameAndExt()==_L("findfile.aaa"));
1.803 +
1.804 +
1.805 + struct TCombinations
1.806 + {
1.807 + TUint iMatchMask; // The Match Mask to be combined with drive attributes
1.808 + TInt iExpectedResultNoAtts; // Expected result when flag used on it's own
1.809 + TInt iExpectedResultWithAtts; // Expected result when flag used in combination with drive flags
1.810 + };
1.811 +
1.812 + TCombinations testCombinations[] = {
1.813 + { 0, KErrNone, KErrNone},
1.814 + { KDriveAttAll, KErrNone, KErrArgument },
1.815 + { KDriveAttExclude, KErrArgument, KErrNone },
1.816 + { KDriveAttExclusive, KErrArgument, KErrNone },
1.817 + { KDriveAttExclude | KDriveAttExclusive, KErrArgument, KErrNone },
1.818 + { KDriveAttAll | KDriveAttExclude, KErrArgument, KErrArgument },
1.819 + { KDriveAttAll | KDriveAttExclusive, KErrArgument, KErrArgument},
1.820 + { KDriveAttAll | KDriveAttExclude | KDriveAttExclusive, KErrArgument, KErrArgument}};
1.821 +
1.822 +
1.823 +
1.824 + for(TUint matchIdx = 0; matchIdx < sizeof(testCombinations) / sizeof(TCombinations); matchIdx++)
1.825 + {
1.826 + test.Printf(_L("\nTest mask : KDriveAttAll[%c] KDriveAttExclude[%c] KDriveAttExclusive[%c]\n"), testCombinations[matchIdx].iMatchMask & KDriveAttAll ? 'X' : ' ',
1.827 + testCombinations[matchIdx].iMatchMask & KDriveAttExclude ? 'X' : ' ',
1.828 + testCombinations[matchIdx].iMatchMask & KDriveAttExclusive ? 'X' : ' ');
1.829 + for(TUint testAtt = 0; testAtt <= KMaxTUint8; testAtt++)
1.830 + {
1.831 + r= finder.SetFindMask( testCombinations[matchIdx].iMatchMask | testAtt ) ;
1.832 +
1.833 + // test.Printf(_L(" ATT : 0x%08x \n"), testAtt);
1.834 + // test.Printf(_L("Expected Result : %d \n"), testAtt == 0 ? testCombinations[matchIdx].iExpectedResultNoAtts : testCombinations[matchIdx].iExpectedResultWithAtts);
1.835 + // test.Printf(_L(" Actual Result : 0x%08x \n"), err);
1.836 +
1.837 + // test.Printf(_L("\nTest mask : %d \n"),testCombinations[matchIdx].iMatchMask | testAtt );
1.838 +
1.839 + test( r == (testAtt == 0 ? testCombinations[matchIdx].iExpectedResultNoAtts : testCombinations[matchIdx].iExpectedResultWithAtts) );
1.840 +
1.841 +
1.842 + if (r== KErrNone)
1.843 + {
1.844 + r = finder.FindByPath(_L("findfile.aaa"),&path);
1.845 + test (r== KErrNone || r ==KErrNotFound);
1.846 + }
1.847 +
1.848 + }
1.849 + }
1.850 +
1.851 + }
1.852 +
1.853 +
1.854 +
1.855 +
1.856 +
1.857 +LOCAL_C void Test9()
1.858 +//
1.859 +// Test wildcard findbydir and FindByWildPath in Removable and Internal Drives
1.860 +//
1.861 +
1.862 + //---------------------------------------------
1.863 + //! @SYMTestCaseID PBASE-T_LOCATE-0555
1.864 + //! @SYMTestType UT
1.865 + //! @SYMREQ CR909
1.866 + //! @SYMTestCaseDesc Check that FindWildByDir and FindByDir functions behave correctly when a mask has been specified
1.867 + //! through SetFindMask.
1.868 + //! @SYMTestActions Call FindWildByDir with a filename containing wildchars and a specific path. Then call SetFindMask
1.869 + //! to exclude Removable drives and call FindWildByDir again.Even more call FindByDir for the file in
1.870 + //! the removable drive and for the same directory as before.
1.871 + //! @SYMTestExpectedResults The number of files found when excluding the removable drive(if a removable drive exists in the
1.872 + //! target platform) must differ by one. The FinByDir must find the same results.
1.873 + //! @SYMTestPriority High
1.874 + //! @SYMTestStatus Implemented
1.875 + //---------------------------------------------
1.876 +
1.877 +
1.878 + {
1.879 +
1.880 + TAutoClose<RFs> fs;
1.881 + TInt r=fs.iObj.Connect();
1.882 + test(r==KErrNone);
1.883 +
1.884 + TFindFile finder(fs.iObj);
1.885 +
1.886 + CDir* dir;
1.887 + CDir* dir3;
1.888 +
1.889 + TInt count;
1.890 + TEntry entry;
1.891 +
1.892 +
1.893 +
1.894 + if ( removableFlag == 1 )
1.895 + {
1.896 +
1.897 + test.Next(_L("FindByDir with wild filenames when a find mask is specified"));
1.898 +
1.899 + TInt r=finder.SetFindMask(KDriveAttRemovable);
1.900 + test(r==KErrNone);
1.901 + r=finder.FindWildByDir(_L("FIND*"),_L("\\F32-TST\\LOCTEST\\BIN\\"),dir);
1.902 + test(r==KErrNone);
1.903 + count=dir->Count();
1.904 + test(count==1);
1.905 + entry=(*dir)[0];
1.906 + test(entry.iName.MatchF(_L("FINDFILE.AAA"))!=KErrNotFound);
1.907 + delete dir;
1.908 +
1.909 + r=finder.FindWild(dir);
1.910 + test(r==KErrNotFound);
1.911 +
1.912 +
1.913 + r=finder.SetFindMask(KDriveAttExclude| KDriveAttRemovable);
1.914 + test(r==KErrNone);
1.915 + r=finder.FindWildByDir(_L("FIND*"),_L("\\F32-TST\\LOCTEST\\BIN\\"),dir);
1.916 + test(r==KErrNotFound);
1.917 +
1.918 +
1.919 + test.Next(_L("Test FindByDir when a find mask is specified"));
1.920 +
1.921 +
1.922 + TPtrC dir2=_L("\\F32-TST\\LOCTEST\\BIN\\");
1.923 +
1.924 + r=finder.SetFindMask(KDriveAttExclude | KDriveAttRemote );
1.925 + test(r==KErrNone);
1.926 + r=finder.FindByDir(_L("findfile.aaa"),dir2);
1.927 + test(r==KErrNone);
1.928 +
1.929 + r=finder.Find();
1.930 + test(r==KErrNotFound);
1.931 +
1.932 +
1.933 + }
1.934 +
1.935 +
1.936 +
1.937 + //---------------------------------------------
1.938 + //! @SYMTestCaseID PBASE-T_LOCATE-0556
1.939 + //! @SYMTestType UT
1.940 + //! @SYMREQ CR909
1.941 + //! @SYMTestCaseDesc FindByWildPath and FindByPath functions when supplied with a path that also contains
1.942 + //! a Drive letter, they will not need to check other Drives. Therefore calling SetFindMask
1.943 + //! does not affect the drives returned.
1.944 + //! @SYMTestActions Call FindWildByPath with an appropriate path in the internal drive. Then call SetFindMask
1.945 + //! to exclude Internal drives and call FindWildByPath again.
1.946 + //! @SYMTestExpectedResults The number of files found in both cases must be the same since no other drive is searched.
1.947 + //! @SYMTestPriority High
1.948 + //! @SYMTestStatus Implemented
1.949 + //---------------------------------------------
1.950 +
1.951 +
1.952 +
1.953 +
1.954 + if( internalFlag == 1 )
1.955 + {
1.956 +
1.957 +
1.958 + test.Next(_L("Test that SetFindMask does not affect Find functions that have a drive letter specified"));
1.959 +
1.960 +
1.961 + gPath5.Append (internalDriveLetter);
1.962 + gPath5.Append (_L(":\\F32-TST\\LOCTEST\\BIN\\INT\\") );
1.963 +
1.964 +
1.965 + r=finder.FindWildByPath(_L("FIND*.AAA"), &gPath5, dir3);
1.966 + test(r==KErrNone);
1.967 + test(dir3->Count()==2);
1.968 +
1.969 + entry=(*dir3)[0];
1.970 + test( (entry.iName.MatchF(_L("FINDINTERNALFILE_B.AAA"))!=KErrNotFound) || (entry.iName.MatchF(_L("FINDINTERNALFILE.AAA"))!=KErrNotFound) );
1.971 +
1.972 +
1.973 + entry=(*dir3)[1];
1.974 + test( (entry.iName.MatchF(_L("FINDINTERNALFILE_B.AAA"))!=KErrNotFound ) || (entry.iName.MatchF(_L("FINDINTERNALFILE.AAA"))!=KErrNotFound) );
1.975 +
1.976 +
1.977 + delete dir3;
1.978 +
1.979 +
1.980 +
1.981 + r=finder.SetFindMask(KDriveAttExclude| KDriveAttInternal);
1.982 + test(r==KErrNone);
1.983 + r=finder.FindWildByPath(_L("FIND*.AAA"), &gPath5, dir3);
1.984 + test(r==KErrNone);
1.985 + test(dir3->Count()==2);
1.986 +
1.987 + delete dir3;
1.988 +
1.989 +
1.990 + r=finder.FindWild(dir3);
1.991 + test(r==KErrNotFound);
1.992 +
1.993 +
1.994 + }
1.995 +
1.996 +
1.997 + }
1.998 +
1.999 +
1.1000 +
1.1001 +
1.1002 +GLDEF_C void CallTestsL()
1.1003 +//
1.1004 +// Do all tests
1.1005 +//
1.1006 + {
1.1007 +
1.1008 +
1.1009 + gPath3=_L("C:\\F32-TST\\LOCTEST\\BIN1\\;C:\\F32-TST\\LOCTEST\\BIN2\\");
1.1010 +
1.1011 + gPath1=_L("");
1.1012 + gPath1.Append(gSessionPath[0]);
1.1013 + gPath1.Append(_L(":\\F32-TST\\LOCTEST\\BIN1\\;"));
1.1014 + gPath1.Append(gSessionPath[0]);
1.1015 + gPath1.Append(_L(":\\F32-TST\\LOCTEST\\BIN2\\"));
1.1016 +
1.1017 + gPath2=gPath1;
1.1018 + gPath2.Append(';');
1.1019 + gPath2.Append(gSessionPath[0]);
1.1020 + gPath2.Append(_L(":\\F32-TST\\LOCTEST\\BIN1\\BIN4\\;"));
1.1021 + if (gSessionPath[0]!='C')
1.1022 + gPath2.Append(gSessionPath.Left(2));
1.1023 + gPath2.Append(_L("\\F32-TST\\LOCTEST\\BIN3\\;"));
1.1024 +
1.1025 + gPath4=_L("");
1.1026 + gPath4.Append(_L("\\F32-TST\\LOCTEST\\BIN\\"));
1.1027 +
1.1028 +
1.1029 +
1.1030 + CreateTestDirectory(_L("\\F32-TST\\LOCTEST\\"));
1.1031 + MakeLocateTestDirectoryStructure();
1.1032 + Test1();
1.1033 + Test2();
1.1034 + Test3();
1.1035 + Test4();
1.1036 + Test5();
1.1037 + Test6();
1.1038 +
1.1039 + MountRemoteFilesystem();
1.1040 + CreateFilesInRemovableDrive(); //used in Test7/8/9
1.1041 +
1.1042 + Test7();
1.1043 + Test8();
1.1044 +
1.1045 + CreateFilesInInternalDrive(); //used in Test9
1.1046 + Test9();
1.1047 +
1.1048 + DisMountRemoteFilesystem();
1.1049 +
1.1050 + DeleteTestDirectory();
1.1051 +
1.1052 + //Explicity delete the directories created
1.1053 + DeleteRemovableDirectory();
1.1054 + DeleteInternalDirectory();
1.1055 +
1.1056 +
1.1057 +
1.1058 + }