sl@0: // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32test\server\t_locate.cpp sl@0: // sl@0: // sl@0: #define __E32TEST_EXTENSION__ sl@0: #include sl@0: #include sl@0: #include "t_server.h" sl@0: sl@0: sl@0: sl@0: GLDEF_D RTest test(_L("T_LOCATE")); sl@0: sl@0: LOCAL_D TFileName gPath1; sl@0: LOCAL_D TFileName gPath2; sl@0: LOCAL_D TFileName gPath3; sl@0: LOCAL_D TFileName gPath4; sl@0: LOCAL_D TFileName gPath5; sl@0: sl@0: sl@0: LOCAL_D TFileName gRemovableDriveFile; sl@0: LOCAL_D TFileName gInternalDriveFile; sl@0: LOCAL_D TFileName gInternalDriveFile2; sl@0: sl@0: sl@0: LOCAL_D TChar removableDriveLetter; sl@0: LOCAL_D TChar internalDriveLetter; sl@0: sl@0: sl@0: LOCAL_D TInt removableFlag=0; sl@0: LOCAL_D TInt internalFlag=0; sl@0: sl@0: sl@0: sl@0: LOCAL_C void Md(const TDesC& aDirName) sl@0: // sl@0: // Make a dir sl@0: // sl@0: { sl@0: sl@0: TInt r=TheFs.MkDirAll(aDirName); sl@0: if (r == KErrCorrupt) sl@0: test.Printf(_L("Media corruption; previous test may have aborted; else, check hardware\n")); sl@0: else if (r == KErrNotReady) sl@0: test.Printf(_L("No medium present / drive not ready, previous test may have hung; else, check hardware\n")); sl@0: test_Value(r, r == KErrNone || r == KErrAlreadyExists); sl@0: } sl@0: sl@0: LOCAL_C void Mf(const TDesC& aFileName) sl@0: // sl@0: // Make a file sl@0: // sl@0: { sl@0: sl@0: RFile file; sl@0: TInt r = file.Replace(TheFs,aFileName,0); sl@0: if (r == KErrPathNotFound) sl@0: { sl@0: test.Printf(_L("Mf: Path Not Found\n")); sl@0: Md(aFileName); sl@0: r=file.Replace(TheFs,aFileName,0); sl@0: } sl@0: sl@0: if (r == KErrCorrupt) sl@0: test.Printf(_L("Media corruption; previous test may have aborted; else, check hardware\n")); sl@0: else if (r == KErrNotReady) sl@0: test.Printf(_L("No medium present / drive not ready, previous test may have hung; else, check hardware\n")); sl@0: sl@0: test_Value(r, r == KErrNone || r == KErrAlreadyExists); sl@0: file.Close(); sl@0: } sl@0: sl@0: LOCAL_C void MakeLocateTestDirectoryStructure() sl@0: // sl@0: // Create files for test sl@0: // sl@0: { sl@0: test.Next(_L("Create LOCTEST directories")); sl@0: Md(_L("\\F32-TST\\LOCTEST\\BIN1\\")); sl@0: Md(_L("\\F32-TST\\LOCTEST\\BIN2\\")); sl@0: Md(_L("\\F32-TST\\LOCTEST\\BIN3\\")); sl@0: Md(_L("\\F32-TST\\LOCTEST\\BIN1\\BIN4\\")); sl@0: sl@0: sl@0: sl@0: #if defined(_DEBUG) sl@0: TheFs.SetErrorCondition(-47,5); sl@0: TDriveInfo drive; sl@0: for (TInt i=0;i<5;i++) sl@0: { sl@0: TInt r=TheFs.Drive(drive); sl@0: test(r==KErrNone); sl@0: } sl@0: TInt r=TheFs.MkDirAll(_L("alskdjfl")); sl@0: test(r==-47); sl@0: r=TheFs.MkDirAll(_L("alskdjfl")); sl@0: test(r==-47); sl@0: TheFs.SetErrorCondition(KErrNone); sl@0: r=TheFs.Drive(drive); sl@0: test(r==KErrNone); sl@0: #endif sl@0: // sl@0: test.Next(_L("Create LOCTEST files")); sl@0: Mf(_L("\\F32-TST\\LOCTEST\\FILE1.AAA")); sl@0: Mf(_L("\\F32-TST\\LOCTEST\\FILE2.BBB")); sl@0: Mf(_L("\\F32-TST\\LOCTEST\\FILE3.CCC")); sl@0: Mf(_L("\\F32-TST\\LOCTEST\\WORK.AAA")); sl@0: Mf(_L("\\F32-TST\\LOCTEST\\HOME.CCC")); sl@0: Mf(_L("\\F32-TST\\LOCTEST\\FILE.AAA")); sl@0: Mf(_L("C:\\F32-TST\\LOCTEST\\BIN1\\FILE1.AAA")); sl@0: Mf(_L("C:\\F32-TST\\LOCTEST\\BIN1\\WORK.AAA")); sl@0: Mf(_L("C:\\F32-TST\\LOCTEST\\BIN1\\WORK.BBB")); sl@0: Mf(_L("\\F32-TST\\LOCTEST\\BIN1\\FILE1.AAA")); sl@0: Mf(_L("\\F32-TST\\LOCTEST\\BIN1\\WORK.AAA")); sl@0: Mf(_L("\\F32-TST\\LOCTEST\\BIN1\\WORK.BBB")); sl@0: Mf(_L("\\F32-TST\\LOCTEST\\BIN1\\CONFUSED.DOG")); sl@0: Mf(_L("\\F32-TST\\LOCTEST\\BIN2\\FILE1.BBB")); sl@0: Mf(_L("\\F32-TST\\LOCTEST\\BIN2\\WORK.BBB")); sl@0: Mf(_L("\\F32-TST\\LOCTEST\\BIN2\\FILE2.BBB")); sl@0: Mf(_L("\\F32-TST\\LOCTEST\\BIN2\\FILE3.BBB")); sl@0: Mf(_L("\\F32-TST\\LOCTEST\\BIN3\\FILE3.CCC")); sl@0: Mf(_L("\\F32-TST\\LOCTEST\\BIN3\\WORK.CCC")); sl@0: Mf(_L("\\F32-TST\\LOCTEST\\BIN3\\PLAY.CCC")); sl@0: Mf(_L("\\F32-TST\\LOCTEST\\BIN1\\BIN4\\FILE1.AAA")); sl@0: Mf(_L("\\F32-TST\\LOCTEST\\BIN1\\BIN4\\FILE2.BBB")); sl@0: Mf(_L("\\F32-TST\\LOCTEST\\BIN1\\BIN4\\FILE3.CCC")); sl@0: Mf(_L("\\F32-TST\\LOCTEST\\BIN1\\BIN4\\FILE4.DDD")); sl@0: sl@0: sl@0: sl@0: } sl@0: sl@0: sl@0: LOCAL_C void CreateFilesInRemovableDrive() sl@0: { sl@0: sl@0: sl@0: TInt err; sl@0: TDriveList driveList; sl@0: TDriveInfo info; sl@0: sl@0: err = TheFs.DriveList(driveList); sl@0: test( err == KErrNone ); sl@0: sl@0: for (TInt i = 0; i < KMaxDrives; i++) sl@0: { sl@0: sl@0: if (driveList[i]) sl@0: { sl@0: err = TheFs.Drive(info, i); sl@0: test( err == KErrNone ); sl@0: sl@0: if( info.iDriveAtt & KDriveAttRemovable ) sl@0: { sl@0: sl@0: if ( ( info.iType != EMediaNotPresent) && (info.iType != EMediaUnknown) && (info.iType != EMediaCdRom) ) sl@0: { sl@0: TheFs.DriveToChar(i,removableDriveLetter) ; sl@0: gRemovableDriveFile.Append (removableDriveLetter); sl@0: gRemovableDriveFile.Append (_L(":\\F32-TST\\LOCTEST\\BIN\\FINDFILE.AAA") ); sl@0: sl@0: Mf(gRemovableDriveFile); sl@0: removableFlag=1; sl@0: break; sl@0: } sl@0: else sl@0: continue; sl@0: sl@0: sl@0: } sl@0: sl@0: sl@0: } sl@0: sl@0: } sl@0: sl@0: } sl@0: sl@0: sl@0: sl@0: LOCAL_C void CreateFilesInInternalDrive() sl@0: { sl@0: sl@0: TInt err; sl@0: TDriveList driveList; sl@0: TDriveInfo info; sl@0: sl@0: err = TheFs.DriveList(driveList); sl@0: test( err == KErrNone ); sl@0: sl@0: for (TInt i = 0; i < KMaxDrives; i++) sl@0: { sl@0: sl@0: if (driveList[i]) sl@0: { sl@0: err = TheFs.Drive(info, i); sl@0: test( err == KErrNone ); sl@0: sl@0: if( info.iDriveAtt & KDriveAttInternal ) sl@0: { sl@0: sl@0: TheFs.DriveToChar(i,internalDriveLetter) ; sl@0: gInternalDriveFile.Append (internalDriveLetter); sl@0: gInternalDriveFile.Append (_L(":\\F32-TST\\LOCTEST\\BIN\\INT\\FINDINTERNALFILE.AAA") ); sl@0: sl@0: gInternalDriveFile2.Append (internalDriveLetter); sl@0: gInternalDriveFile2.Append (_L(":\\F32-TST\\LOCTEST\\BIN\\INT\\FINDINTERNALFILE_B.AAA") ); sl@0: sl@0: Mf(gInternalDriveFile); sl@0: Mf(gInternalDriveFile2); sl@0: internalFlag=1; sl@0: sl@0: break; sl@0: } sl@0: sl@0: } sl@0: sl@0: } sl@0: sl@0: sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: LOCAL_C void DeleteRemovableDirectory() sl@0: { sl@0: sl@0: //Delete the directory structure we created in the removalbe drive sl@0: if ( removableFlag == 1 ) sl@0: { sl@0: CFileMan* fMan=CFileMan::NewL(TheFs); sl@0: test(fMan!=NULL); sl@0: sl@0: TFileName gPathRem; sl@0: gPathRem.Append (removableDriveLetter); sl@0: gPathRem.Append (_L(":\\F32-TST\\") ); sl@0: TInt r=fMan->RmDir(gPathRem); sl@0: test(r==KErrNone); sl@0: sl@0: delete fMan; sl@0: } sl@0: } sl@0: sl@0: LOCAL_C void DeleteInternalDirectory() sl@0: { sl@0: sl@0: //Delete the directory structure we created in the internal drive sl@0: sl@0: sl@0: if( internalFlag == 1 ) sl@0: { sl@0: CFileMan* fMan=CFileMan::NewL(TheFs); sl@0: test(fMan!=NULL); sl@0: sl@0: TFileName gPathInt; sl@0: gPathInt.Append (internalDriveLetter); sl@0: gPathInt.Append (_L(":\\F32-TST\\") ); sl@0: TInt r=fMan->RmDir(gPathInt); sl@0: test(r==KErrNone); sl@0: sl@0: delete fMan; sl@0: } sl@0: } sl@0: sl@0: sl@0: LOCAL_C void MountRemoteFilesystem() sl@0: { sl@0: sl@0: test.Next(_L("Mount Remote Drive simulator on Q:\n")); sl@0: sl@0: sl@0: TInt r=TheFs.AddFileSystem(_L("CFAFSDLY")); sl@0: test.Printf(_L("Add remote file system\n")); sl@0: test.Printf(_L("AddFileSystem returned %d\n"),r); sl@0: test (r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: sl@0: r=TheFs.MountFileSystem(_L("DELAYFS"),EDriveQ); sl@0: sl@0: sl@0: test.Printf(_L("Mount remote file system\n")); sl@0: test.Printf(_L("MountFileSystem returned %d\n"),r); sl@0: test(r==KErrNone || r==KErrCorrupt || r==KErrNotReady || r==KErrAlreadyExists); sl@0: sl@0: sl@0: Mf(_L("Q:\\F32-TST\\LOCTEST\\BIN\\FINDFILE.AAA")); sl@0: sl@0: } sl@0: sl@0: sl@0: sl@0: LOCAL_C void DisMountRemoteFilesystem() sl@0: { sl@0: sl@0: test.Printf(_L("Dismounting the remote Drives \n")); sl@0: sl@0: TInt r=TheFs.DismountFileSystem(_L("DELAYFS"),EDriveQ); sl@0: sl@0: test.Printf(_L("Dismounting the Remote Drive returned %d\n"),r); sl@0: sl@0: test(r==KErrNone ); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: LOCAL_C void Test1() sl@0: // sl@0: // Do simple tests sl@0: // sl@0: { sl@0: test.Next(_L("Test FindByPath")); sl@0: sl@0: TAutoClose fs; sl@0: TInt r=fs.iObj.Connect(); sl@0: test(r==KErrNone); sl@0: TFindFile finder(fs.iObj); sl@0: TPtrC path=gPath1; sl@0: r=finder.FindByPath(_L("file1.aaa"),&path); sl@0: test(r==KErrNone); sl@0: TParse fileParse; sl@0: fileParse.Set(finder.File(),NULL,NULL); sl@0: test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN1\\")); sl@0: test(fileParse.NameAndExt()==_L("file1.aaa")); sl@0: r=finder.Find(); sl@0: test(r==KErrNotFound); sl@0: sl@0: sl@0: path.Set(gPath2); sl@0: r=finder.FindByPath(_L("file1.aaa"),&path); sl@0: test(r==KErrNone); sl@0: fileParse.Set(finder.File(),NULL,NULL); sl@0: test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN1\\")); sl@0: test(fileParse.NameAndExt()==_L("file1.aaa")); sl@0: r=finder.Find(); sl@0: test(r==KErrNone); sl@0: fileParse.Set(finder.File(),NULL,NULL); sl@0: test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN1\\BIN4\\")); sl@0: test(fileParse.NameAndExt()==_L("file1.aaa")); sl@0: r=finder.Find(); sl@0: test(r==KErrNotFound); sl@0: // sl@0: test.Next(_L("Test FindByDir")); sl@0: TPtrC dir=_L("\\F32-TST\\LOCTEST\\BIN2\\"); sl@0: r=finder.FindByDir(_L("file2.bbb"),dir); sl@0: test(r==KErrNone); sl@0: TFileName defaultPath; sl@0: r=TheFs.SessionPath(defaultPath); sl@0: defaultPath.SetLength(2); sl@0: test(r==KErrNone); sl@0: fileParse.Set(finder.File(),NULL,NULL); sl@0: test(fileParse.Drive()==defaultPath); sl@0: test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN2\\")); sl@0: test(_L("file2.bbb").MatchF(fileParse.NameAndExt())!=KErrNotFound); // MatchF only sees wildcards in its argument sl@0: r=finder.Find(); sl@0: if (r==KErrNone) sl@0: { sl@0: fileParse.Set(finder.File(),NULL,NULL); sl@0: if (defaultPath==_L("C:")) sl@0: test(fileParse.Drive()==_L("Y:")); sl@0: else sl@0: test(fileParse.Drive()==_L("C:")); sl@0: test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN2\\")); sl@0: test(_L("file2.bbb").MatchF(fileParse.NameAndExt())!=KErrNotFound); sl@0: r=finder.Find(); sl@0: } sl@0: test(r==KErrNotFound); sl@0: } sl@0: sl@0: LOCAL_C void Test2() sl@0: // sl@0: // Test extremes sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test extremes")); sl@0: TAutoClose fs; sl@0: TInt r=fs.iObj.Connect(); sl@0: test(r==KErrNone); sl@0: TBuf<4> temp=_L(""); sl@0: TFindFile finder(fs.iObj); sl@0: r=finder.FindByPath(_L("file1.aaa"),&temp); sl@0: test(r==KErrNotFound); sl@0: r=finder.Find(); sl@0: test(r==KErrNotFound); sl@0: // sl@0: TPtrC path=_L("blarg.7"); sl@0: r=finder.FindByPath(_L(""),&path); sl@0: test(r==KErrArgument); sl@0: r=finder.FindByPath(_L("*"),&path); sl@0: test(r==KErrNotFound); sl@0: r=finder.FindByPath(_L("xmvid"),&path); sl@0: test(r==KErrNotFound); sl@0: r=finder.Find(); sl@0: test(r==KErrNotFound); sl@0: // sl@0: path.Set(_L("C:\\F32-TST\\LOCTEST\\BIN1\\;\\F32-TST\\LOCTEST\\BIN2\\;Z:\\F32-TST\\LOCTEST\\BIN1\\BIN4\\;\\F32-TST\\LOCTEST\\BIN3\\;")); sl@0: r=finder.FindByPath(_L(""),&path); sl@0: test(r==KErrArgument); sl@0: r=finder.FindByPath(_L("xyz.abc"),&path); sl@0: test(r==KErrNotFound); sl@0: r=finder.Find(); sl@0: test(r==KErrNotFound); sl@0: sl@0: test.Next(_L("Test FindByDir with empty file spec")); sl@0: TPtrC dir2=_L("\\F32-TST\\LOCTEST\\"); sl@0: r=finder.FindByDir(_L(""),dir2); sl@0: test(r==KErrArgument); sl@0: sl@0: } sl@0: sl@0: LOCAL_C void Test3() sl@0: // sl@0: // Test FindByDrives in a path=_L("c:\xyz;z:\lmnop;\abc;\y:\help"); sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test FindInDrivesByPath")); sl@0: TPtrC path=_L("\\F32-TST\\LOCTEST\\BIN2\\"); sl@0: TFileName defaultPath; sl@0: TInt r=TheFs.SessionPath(defaultPath); sl@0: defaultPath.SetLength(2); sl@0: // sl@0: TAutoClose fs; sl@0: r=fs.iObj.Connect(); sl@0: test(r==KErrNone); sl@0: TFindFile finder(fs.iObj); sl@0: r=finder.FindByPath(_L("file1.aaa"),&path); sl@0: test(r==KErrNotFound); sl@0: r=finder.Find(); sl@0: test(r==KErrNotFound); sl@0: // sl@0: path.Set(_L("\\F32-TST\\LOCTEST\\BIN2\\")); sl@0: r=finder.FindByPath(_L("file2.bbb"),&path); sl@0: test(r==KErrNone); sl@0: TParse fileParse; sl@0: fileParse.Set(finder.File(),NULL,NULL); sl@0: test(fileParse.Drive()==defaultPath); sl@0: test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN2\\")); sl@0: test(fileParse.NameAndExt()==_L("file2.bbb")); sl@0: r=finder.Find(); sl@0: test(r==KErrNotFound || r==KErrNone); sl@0: if (r==KErrNone) sl@0: { sl@0: fileParse.Set(finder.File(),NULL,NULL); sl@0: test(fileParse.Drive()!=defaultPath); sl@0: test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN2\\")); sl@0: test(fileParse.NameAndExt()==_L("file2.bbb")); sl@0: r=finder.Find(); sl@0: test(r==KErrNotFound); sl@0: } sl@0: // sl@0: path.Set(_L("C:\\F32-TST\\LOCTEST\\BIN1\\;;\\F32-TST\\LOCTEST\\BIN2\\;Z:\\F32-TST\\LOCTEST\\BIN1\\BIN4\\;\\F32-TST\\LOCTEST\\BIN3\\;")); sl@0: r=finder.FindByPath(_L("xyz.abc"),&path); sl@0: test(r==KErrNotFound); sl@0: r=finder.Find(); sl@0: test(r==KErrNotFound); sl@0: // sl@0: r=finder.FindByPath(_L("file2.bbb"),&path); sl@0: test(r==KErrNone); sl@0: fileParse.Set(finder.File(),NULL,NULL); sl@0: test(fileParse.Drive()==defaultPath); sl@0: test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN2\\")); sl@0: test(fileParse.NameAndExt()==_L("file2.bbb")); sl@0: r=finder.Find(); sl@0: test(r==KErrNotFound || r==KErrNone); sl@0: if (r==KErrNone) sl@0: { sl@0: fileParse.Set(finder.File(),NULL,NULL); sl@0: test(fileParse.Drive()!=defaultPath); sl@0: test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN2\\")); sl@0: test(fileParse.NameAndExt()==_L("file2.bbb")); sl@0: r=finder.Find(); sl@0: test(r==KErrNotFound); sl@0: } sl@0: } sl@0: sl@0: LOCAL_C void Test4() sl@0: // sl@0: // Test wildcard findbypath sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("FindByPath with wild filenames")); sl@0: TFindFile finder(TheFs); sl@0: CDir* dir; sl@0: TInt count; sl@0: TEntry entry; sl@0: TFileName path; sl@0: sl@0: TInt r=finder.FindWildByPath(_L("*.aaa"),&gPath3,dir); sl@0: test(r==KErrNone); sl@0: count=dir->Count(); sl@0: test(count==3); sl@0: entry=(*dir)[0]; sl@0: test(entry.iName.MatchF(_L("FILE.AAA"))!=KErrNotFound); sl@0: entry=(*dir)[1]; sl@0: test(entry.iName.MatchF(_L("FILE1.AAA"))!=KErrNotFound); sl@0: entry=(*dir)[2]; sl@0: test(entry.iName.MatchF(_L("WORK.AAA"))!=KErrNotFound); sl@0: TParse fileParse; sl@0: fileParse.Set(finder.File(),NULL,NULL); sl@0: path=fileParse.FullName(); sl@0: test(path==_L("*.aaa")); sl@0: delete dir; sl@0: sl@0: r=finder.FindWild(dir); sl@0: test(r==KErrNone); sl@0: count=dir->Count(); sl@0: test(count==2); sl@0: entry=(*dir)[0]; sl@0: test(entry.iName.MatchF(_L("FILE1.AAA"))!=KErrNotFound); sl@0: entry=(*dir)[1]; sl@0: test(entry.iName.MatchF(_L("WORK.AAA"))!=KErrNotFound); sl@0: fileParse.Set(finder.File(),NULL,NULL); sl@0: path=fileParse.FullName(); sl@0: test(path==_L("C:\\F32-TST\\LOCTEST\\BIN1\\*.aaa")); sl@0: delete dir; sl@0: sl@0: r=finder.FindWild(dir); sl@0: test(r==KErrNotFound); sl@0: r=finder.FindWild(dir); sl@0: test(r==KErrNotFound); sl@0: sl@0: r=finder.FindWildByPath(_L("*FILE.AAA*"), &gPath1, dir); sl@0: test(r==KErrNone); sl@0: test(dir->Count()==1); sl@0: entry=(*dir)[0]; sl@0: test(entry.iName.MatchF(_L("FILE.AAA"))!=KErrNotFound); sl@0: delete dir; sl@0: r=finder.FindWildByPath(_L("*FILE.AAA"), &gPath1, dir); sl@0: test(r==KErrNone); sl@0: test(dir->Count()==1); sl@0: entry=(*dir)[0]; sl@0: test(entry.iName.MatchF(_L("FILE.AAA"))!=KErrNotFound); sl@0: delete dir; sl@0: r=finder.FindWildByPath(_L("FILE.AAA*"), &gPath1, dir); sl@0: test(r==KErrNone); sl@0: test(dir->Count()==1); sl@0: entry=(*dir)[0]; sl@0: test(entry.iName.MatchF(_L("FILE.AAA"))!=KErrNotFound); sl@0: delete dir; sl@0: r=finder.FindWildByPath(_L("CONFUSED.DOG"), &gPath1, dir); sl@0: test(r==KErrNone); sl@0: test(dir->Count()==1); sl@0: entry=(*dir)[0]; sl@0: test(entry.iName.MatchF(_L("CONFUSED.DOG"))!=KErrNotFound); sl@0: delete dir; sl@0: r=finder.FindWildByPath(_L("*CONFUSED.DOG"), &gPath1, dir); sl@0: test(r==KErrNone); sl@0: test(dir->Count()==1); sl@0: entry=(*dir)[0]; sl@0: test(entry.iName.MatchF(_L("CONFUSED.DOG"))!=KErrNotFound); sl@0: delete dir; sl@0: r=finder.FindWildByPath(_L("CONFUSED.DOG*"), &gPath1, dir); sl@0: test(r==KErrNone); sl@0: test(dir->Count()==1); sl@0: entry=(*dir)[0]; sl@0: test(entry.iName.MatchF(_L("CONFUSED.DOG"))!=KErrNotFound); sl@0: delete dir; sl@0: r=finder.FindWildByPath(_L("*CONFUSED.DOG*"), &gPath1, dir); sl@0: test(r==KErrNone); sl@0: test(dir->Count()==1); sl@0: entry=(*dir)[0]; sl@0: test(entry.iName.MatchF(_L("CONFUSED.DOG"))!=KErrNotFound); sl@0: delete dir; sl@0: } sl@0: sl@0: LOCAL_C void Test5() sl@0: // sl@0: // Test wildcard findbydir sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("FindByDir with wild filenames")); sl@0: TFindFile finder(TheFs); sl@0: CDir* dir; sl@0: TInt count; sl@0: TEntry entry; sl@0: TFileName path; sl@0: sl@0: TInt r=finder.FindWildByDir(_L("FILE*"),_L("\\F32-TST\\LOCTEST\\BIN3\\"),dir); sl@0: test(r==KErrNone); sl@0: count=dir->Count(); sl@0: test(count==1); sl@0: entry=(*dir)[0]; sl@0: test(entry.iName.MatchF(_L("FILE3.CCC"))!=KErrNotFound); sl@0: TParse fileParse; sl@0: fileParse.Set(finder.File(),NULL,NULL); sl@0: path=fileParse.FullName(); sl@0: TFileName tpath=_L("?:\\F32-TST\\LOCTEST\\BIN3\\FILE*"); sl@0: tpath[0]=gSessionPath[0]; sl@0: test(path.CompareF(tpath)==0); sl@0: delete dir; sl@0: sl@0: r=finder.FindWild(dir); sl@0: if (r==KErrNotFound) sl@0: return; sl@0: test(r==KErrNone); sl@0: entry=(*dir)[0]; sl@0: test(entry.iName.MatchF(_L("FILE3.CCC"))!=KErrNotFound); sl@0: fileParse.Set(finder.File(),NULL,NULL); sl@0: path=fileParse.FullName(); sl@0: test(path.CompareF(tpath)==0); sl@0: delete dir; sl@0: sl@0: r=finder.FindWild(dir); sl@0: test(r==KErrNotFound); sl@0: r=finder.FindWild(dir); sl@0: test(r==KErrNotFound); sl@0: } sl@0: sl@0: LOCAL_C void Test6() sl@0: // sl@0: // Test file not found sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test file not found")); sl@0: TFindFile ff(TheFs); sl@0: TInt r=ff.FindByDir(_L("NOEXIST.EXE"),_L("\\System\\Programs\\")); sl@0: test(r==KErrNotFound); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: // The following test has the requirement that the only remote drive is the one we mount sl@0: // during the test(DELAYFS) and which doesn't have any other attributes set. If this is not the sl@0: // case then test conditions must be changed, in order for the test to stop failing. sl@0: // Even more if a removable drive is not present in the target platform then findfile.aaa sl@0: // only exists in the remote one and this is why we have a distinction in the test results. sl@0: // sl@0: sl@0: sl@0: sl@0: //--------------------------------------------- sl@0: //! @SYMTestCaseID PBASE-T_LOCATE-0553 sl@0: //! @SYMTestType UT sl@0: //! @SYMREQ CR909 sl@0: //! @SYMTestCaseDesc When using the various Find functions of class TFindFile,by default remote drives are sl@0: //! excluded from the list of drives that are searched. Using function sl@0: //! SetFindMask(TUint aMask) it is possible to specify a combination of attributes that sl@0: //! the drives to be searched must match. sl@0: //! @SYMTestActions Call function FindByPath/Find without specifying a mask. Check that remote drives are not sl@0: //! included. Then call SetFindMask(TUint aMask) using various combinations and verify sl@0: //! that FindByPath or Find return appopriate results. sl@0: //! @SYMTestExpectedResults Test that file findfile.aaa is found or not depending on the specified mask. sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //--------------------------------------------- sl@0: sl@0: sl@0: sl@0: LOCAL_C void Test7() sl@0: sl@0: { sl@0: sl@0: TAutoClose fs; sl@0: TInt r=fs.iObj.Connect(); sl@0: test(r==KErrNone); sl@0: TFindFile finder(fs.iObj); sl@0: TPtrC path=gPath4; sl@0: r=finder.FindByPath(_L("findfile.aaa"),&path); sl@0: sl@0: TParse fileParse; sl@0: sl@0: test.Next(_L("Test FindByPath without specifying any mask")); sl@0: sl@0: if (removableFlag == 1) sl@0: { sl@0: test(r==KErrNone); sl@0: fileParse.Set(finder.File(),NULL,NULL); sl@0: test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN\\")); sl@0: test(fileParse.NameAndExt()==_L("findfile.aaa")); //The filename.aaa in the removable Drive sl@0: r=finder.Find(); sl@0: test(r==KErrNotFound); //remote drives are excluded by default sl@0: sl@0: } sl@0: else sl@0: test(r==KErrNotFound); sl@0: sl@0: sl@0: sl@0: test.Next(_L("Search for the specified file in all Drives, including remotes ones \n")); sl@0: sl@0: sl@0: r=finder.SetFindMask( KDriveAttAll) ; sl@0: test(r==KErrNone); sl@0: r=finder.FindByPath(_L("findfile.aaa"),&path); sl@0: test(r==KErrNone); sl@0: fileParse.Set(finder.File(),NULL,NULL); sl@0: test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN\\")); sl@0: test(fileParse.NameAndExt()==_L("findfile.aaa")); //either the remote or removable one. sl@0: r=finder.Find(); sl@0: sl@0: sl@0: if (removableFlag == 1) sl@0: { sl@0: test(r==KErrNone); sl@0: sl@0: fileParse.Set(finder.File(),NULL,NULL); sl@0: sl@0: test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN\\")); sl@0: test(fileParse.NameAndExt()==_L("findfile.aaa")); //either the remote or removable one. sl@0: sl@0: r=finder.Find(); sl@0: test(r==KErrNotFound); sl@0: } sl@0: else sl@0: { sl@0: test(r==KErrNotFound); sl@0: sl@0: } sl@0: sl@0: sl@0: test.Next(_L("Search exclusively in remote drives \n")); sl@0: sl@0: r=finder.SetFindMask( KDriveAttExclusive| KDriveAttRemote); sl@0: test(r==KErrNone); sl@0: r=finder.FindByPath(_L("findfile.aaa"),&path); sl@0: test(r==KErrNone); sl@0: fileParse.Set(finder.File(),NULL,NULL); sl@0: test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN\\")); sl@0: test(fileParse.NameAndExt()==_L("findfile.aaa")); sl@0: r=finder.Find(); sl@0: test(r==KErrNotFound); sl@0: sl@0: sl@0: test.Next(_L("Search excluding removables and remote \n")); sl@0: sl@0: r=finder.SetFindMask( KDriveAttExclude | KDriveAttRemovable |KDriveAttRemote ); sl@0: test(r==KErrNone); sl@0: r=finder.FindByPath(_L("findfile.aaa"),&path); sl@0: test(r==KErrNotFound); //filename.aaa exists in the remote drive and if present to the removable one sl@0: sl@0: sl@0: test.Next(_L("Search in Internal Drives \n")); sl@0: sl@0: r=finder.SetFindMask(KDriveAttInternal ) ; sl@0: test(r==KErrNone); sl@0: r=finder.FindByPath(_L("findfile.aaa"),&path); sl@0: test(r==KErrNotFound); //filename.aaa exists only in the Removable drive and the remote one. sl@0: sl@0: sl@0: } sl@0: sl@0: sl@0: //--------------------------------------------- sl@0: //! @SYMTestCaseID PBASE-T_LOCATE-0554 sl@0: //! @SYMTestType UT sl@0: //! @SYMREQ CR909 sl@0: //! @SYMTestCaseDesc Test that SetFindMask(TUint aMask) returns the correct value for all combinations of matching masks. sl@0: //! sl@0: //! @SYMTestActions Call SetFindMask for every combination of mask and check that the correct value is returned. sl@0: //! A structure is used to store the expected value for each combination. sl@0: //! @SYMTestExpectedResults For every combination either KErrNone or KErrArgument must be returned. sl@0: //! @SYMTestPriority High. sl@0: //! @SYMTestStatus Implemented sl@0: //--------------------------------------------- sl@0: sl@0: sl@0: sl@0: sl@0: LOCAL_C void Test8() sl@0: sl@0: { sl@0: sl@0: test.Next(_L("Test SetFindMask with all mask combinations \n")); sl@0: sl@0: sl@0: TAutoClose fs; sl@0: TInt r=fs.iObj.Connect(); sl@0: test(r==KErrNone); sl@0: TFindFile finder(fs.iObj); sl@0: TPtrC path=gPath4; sl@0: TParse fileParse; sl@0: sl@0: sl@0: r=finder.SetFindMask(KDriveAttAll) ; sl@0: test(r==KErrNone); sl@0: r=finder.FindByPath(_L("findfile.aaa"),&path); sl@0: test(r==KErrNone); sl@0: fileParse.Set(finder.File(),NULL,NULL); sl@0: test(fileParse.Path()==_L("\\F32-TST\\LOCTEST\\BIN\\")); sl@0: test(fileParse.NameAndExt()==_L("findfile.aaa")); sl@0: sl@0: sl@0: struct TCombinations sl@0: { sl@0: TUint iMatchMask; // The Match Mask to be combined with drive attributes sl@0: TInt iExpectedResultNoAtts; // Expected result when flag used on it's own sl@0: TInt iExpectedResultWithAtts; // Expected result when flag used in combination with drive flags sl@0: }; sl@0: sl@0: TCombinations testCombinations[] = { sl@0: { 0, KErrNone, KErrNone}, sl@0: { KDriveAttAll, KErrNone, KErrArgument }, sl@0: { KDriveAttExclude, KErrArgument, KErrNone }, sl@0: { KDriveAttExclusive, KErrArgument, KErrNone }, sl@0: { KDriveAttExclude | KDriveAttExclusive, KErrArgument, KErrNone }, sl@0: { KDriveAttAll | KDriveAttExclude, KErrArgument, KErrArgument }, sl@0: { KDriveAttAll | KDriveAttExclusive, KErrArgument, KErrArgument}, sl@0: { KDriveAttAll | KDriveAttExclude | KDriveAttExclusive, KErrArgument, KErrArgument}}; sl@0: sl@0: sl@0: sl@0: for(TUint matchIdx = 0; matchIdx < sizeof(testCombinations) / sizeof(TCombinations); matchIdx++) sl@0: { sl@0: test.Printf(_L("\nTest mask : KDriveAttAll[%c] KDriveAttExclude[%c] KDriveAttExclusive[%c]\n"), testCombinations[matchIdx].iMatchMask & KDriveAttAll ? 'X' : ' ', sl@0: testCombinations[matchIdx].iMatchMask & KDriveAttExclude ? 'X' : ' ', sl@0: testCombinations[matchIdx].iMatchMask & KDriveAttExclusive ? 'X' : ' '); sl@0: for(TUint testAtt = 0; testAtt <= KMaxTUint8; testAtt++) sl@0: { sl@0: r= finder.SetFindMask( testCombinations[matchIdx].iMatchMask | testAtt ) ; sl@0: sl@0: // test.Printf(_L(" ATT : 0x%08x \n"), testAtt); sl@0: // test.Printf(_L("Expected Result : %d \n"), testAtt == 0 ? testCombinations[matchIdx].iExpectedResultNoAtts : testCombinations[matchIdx].iExpectedResultWithAtts); sl@0: // test.Printf(_L(" Actual Result : 0x%08x \n"), err); sl@0: sl@0: // test.Printf(_L("\nTest mask : %d \n"),testCombinations[matchIdx].iMatchMask | testAtt ); sl@0: sl@0: test( r == (testAtt == 0 ? testCombinations[matchIdx].iExpectedResultNoAtts : testCombinations[matchIdx].iExpectedResultWithAtts) ); sl@0: sl@0: sl@0: if (r== KErrNone) sl@0: { sl@0: r = finder.FindByPath(_L("findfile.aaa"),&path); sl@0: test (r== KErrNone || r ==KErrNotFound); sl@0: } sl@0: sl@0: } sl@0: } sl@0: sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: LOCAL_C void Test9() sl@0: // sl@0: // Test wildcard findbydir and FindByWildPath in Removable and Internal Drives sl@0: // sl@0: sl@0: //--------------------------------------------- sl@0: //! @SYMTestCaseID PBASE-T_LOCATE-0555 sl@0: //! @SYMTestType UT sl@0: //! @SYMREQ CR909 sl@0: //! @SYMTestCaseDesc Check that FindWildByDir and FindByDir functions behave correctly when a mask has been specified sl@0: //! through SetFindMask. sl@0: //! @SYMTestActions Call FindWildByDir with a filename containing wildchars and a specific path. Then call SetFindMask sl@0: //! to exclude Removable drives and call FindWildByDir again.Even more call FindByDir for the file in sl@0: //! the removable drive and for the same directory as before. sl@0: //! @SYMTestExpectedResults The number of files found when excluding the removable drive(if a removable drive exists in the sl@0: //! target platform) must differ by one. The FinByDir must find the same results. sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //--------------------------------------------- sl@0: sl@0: sl@0: { sl@0: sl@0: TAutoClose fs; sl@0: TInt r=fs.iObj.Connect(); sl@0: test(r==KErrNone); sl@0: sl@0: TFindFile finder(fs.iObj); sl@0: sl@0: CDir* dir; sl@0: CDir* dir3; sl@0: sl@0: TInt count; sl@0: TEntry entry; sl@0: sl@0: sl@0: sl@0: if ( removableFlag == 1 ) sl@0: { sl@0: sl@0: test.Next(_L("FindByDir with wild filenames when a find mask is specified")); sl@0: sl@0: TInt r=finder.SetFindMask(KDriveAttRemovable); sl@0: test(r==KErrNone); sl@0: r=finder.FindWildByDir(_L("FIND*"),_L("\\F32-TST\\LOCTEST\\BIN\\"),dir); sl@0: test(r==KErrNone); sl@0: count=dir->Count(); sl@0: test(count==1); sl@0: entry=(*dir)[0]; sl@0: test(entry.iName.MatchF(_L("FINDFILE.AAA"))!=KErrNotFound); sl@0: delete dir; sl@0: sl@0: r=finder.FindWild(dir); sl@0: test(r==KErrNotFound); sl@0: sl@0: sl@0: r=finder.SetFindMask(KDriveAttExclude| KDriveAttRemovable); sl@0: test(r==KErrNone); sl@0: r=finder.FindWildByDir(_L("FIND*"),_L("\\F32-TST\\LOCTEST\\BIN\\"),dir); sl@0: test(r==KErrNotFound); sl@0: sl@0: sl@0: test.Next(_L("Test FindByDir when a find mask is specified")); sl@0: sl@0: sl@0: TPtrC dir2=_L("\\F32-TST\\LOCTEST\\BIN\\"); sl@0: sl@0: r=finder.SetFindMask(KDriveAttExclude | KDriveAttRemote ); sl@0: test(r==KErrNone); sl@0: r=finder.FindByDir(_L("findfile.aaa"),dir2); sl@0: test(r==KErrNone); sl@0: sl@0: r=finder.Find(); sl@0: test(r==KErrNotFound); sl@0: sl@0: sl@0: } sl@0: sl@0: sl@0: sl@0: //--------------------------------------------- sl@0: //! @SYMTestCaseID PBASE-T_LOCATE-0556 sl@0: //! @SYMTestType UT sl@0: //! @SYMREQ CR909 sl@0: //! @SYMTestCaseDesc FindByWildPath and FindByPath functions when supplied with a path that also contains sl@0: //! a Drive letter, they will not need to check other Drives. Therefore calling SetFindMask sl@0: //! does not affect the drives returned. sl@0: //! @SYMTestActions Call FindWildByPath with an appropriate path in the internal drive. Then call SetFindMask sl@0: //! to exclude Internal drives and call FindWildByPath again. sl@0: //! @SYMTestExpectedResults The number of files found in both cases must be the same since no other drive is searched. sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //--------------------------------------------- sl@0: sl@0: sl@0: sl@0: sl@0: if( internalFlag == 1 ) sl@0: { sl@0: sl@0: sl@0: test.Next(_L("Test that SetFindMask does not affect Find functions that have a drive letter specified")); sl@0: sl@0: sl@0: gPath5.Append (internalDriveLetter); sl@0: gPath5.Append (_L(":\\F32-TST\\LOCTEST\\BIN\\INT\\") ); sl@0: sl@0: sl@0: r=finder.FindWildByPath(_L("FIND*.AAA"), &gPath5, dir3); sl@0: test(r==KErrNone); sl@0: test(dir3->Count()==2); sl@0: sl@0: entry=(*dir3)[0]; sl@0: test( (entry.iName.MatchF(_L("FINDINTERNALFILE_B.AAA"))!=KErrNotFound) || (entry.iName.MatchF(_L("FINDINTERNALFILE.AAA"))!=KErrNotFound) ); sl@0: sl@0: sl@0: entry=(*dir3)[1]; sl@0: test( (entry.iName.MatchF(_L("FINDINTERNALFILE_B.AAA"))!=KErrNotFound ) || (entry.iName.MatchF(_L("FINDINTERNALFILE.AAA"))!=KErrNotFound) ); sl@0: sl@0: sl@0: delete dir3; sl@0: sl@0: sl@0: sl@0: r=finder.SetFindMask(KDriveAttExclude| KDriveAttInternal); sl@0: test(r==KErrNone); sl@0: r=finder.FindWildByPath(_L("FIND*.AAA"), &gPath5, dir3); sl@0: test(r==KErrNone); sl@0: test(dir3->Count()==2); sl@0: sl@0: delete dir3; sl@0: sl@0: sl@0: r=finder.FindWild(dir3); sl@0: test(r==KErrNotFound); sl@0: sl@0: sl@0: } sl@0: sl@0: sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: GLDEF_C void CallTestsL() sl@0: // sl@0: // Do all tests sl@0: // sl@0: { sl@0: sl@0: sl@0: gPath3=_L("C:\\F32-TST\\LOCTEST\\BIN1\\;C:\\F32-TST\\LOCTEST\\BIN2\\"); sl@0: sl@0: gPath1=_L(""); sl@0: gPath1.Append(gSessionPath[0]); sl@0: gPath1.Append(_L(":\\F32-TST\\LOCTEST\\BIN1\\;")); sl@0: gPath1.Append(gSessionPath[0]); sl@0: gPath1.Append(_L(":\\F32-TST\\LOCTEST\\BIN2\\")); sl@0: sl@0: gPath2=gPath1; sl@0: gPath2.Append(';'); sl@0: gPath2.Append(gSessionPath[0]); sl@0: gPath2.Append(_L(":\\F32-TST\\LOCTEST\\BIN1\\BIN4\\;")); sl@0: if (gSessionPath[0]!='C') sl@0: gPath2.Append(gSessionPath.Left(2)); sl@0: gPath2.Append(_L("\\F32-TST\\LOCTEST\\BIN3\\;")); sl@0: sl@0: gPath4=_L(""); sl@0: gPath4.Append(_L("\\F32-TST\\LOCTEST\\BIN\\")); sl@0: sl@0: sl@0: sl@0: CreateTestDirectory(_L("\\F32-TST\\LOCTEST\\")); sl@0: MakeLocateTestDirectoryStructure(); sl@0: Test1(); sl@0: Test2(); sl@0: Test3(); sl@0: Test4(); sl@0: Test5(); sl@0: Test6(); sl@0: sl@0: MountRemoteFilesystem(); sl@0: CreateFilesInRemovableDrive(); //used in Test7/8/9 sl@0: sl@0: Test7(); sl@0: Test8(); sl@0: sl@0: CreateFilesInInternalDrive(); //used in Test9 sl@0: Test9(); sl@0: sl@0: DisMountRemoteFilesystem(); sl@0: sl@0: DeleteTestDirectory(); sl@0: sl@0: //Explicity delete the directories created sl@0: DeleteRemovableDirectory(); sl@0: DeleteInternalDirectory(); sl@0: sl@0: sl@0: sl@0: }