sl@0: // Copyright (c) 1997-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 "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: //
sl@0: 
sl@0: #include <e32test.h>
sl@0: #include <baclipb.h>
sl@0: #include <bautils.h>
sl@0: #include <f32file.h>
sl@0: #include <s32strm.h>
sl@0: #include <s32file.h>
sl@0: #include <e32lang.h>
sl@0: 
sl@0: #include <fbs.h>
sl@0: 
sl@0: 
sl@0: LOCAL_D RTest theTest(_L("T_BaflUtils"));
sl@0: 
sl@0: const TInt KMaxDisplayedFullNameLen	= 29;
sl@0: 
sl@0: // File names for copying
sl@0: 
sl@0: const TPtrC KSystem1Folder				=_L("C:\\System1\\");
sl@0: const TPtrC KSystem1Data1Folder			=_L("C:\\System1\\data1\\");
sl@0: 
sl@0: const TPtrC KSystem1Data1File1			=_L("C:\\System1\\data1\\file1.txt");
sl@0: const TPtrC KFile1						=_L("C:\\file1.txt");
sl@0: const TPtrC KSystem1Data1SrcFile1		=_L("C:\\System1\\data1\\src\\file1.txt");
sl@0: const TPtrC KSystem1Data1DstFile2		=_L("C:\\System1\\data1\\dst\\file2.txt");
sl@0: const TPtrC KSystem1Data1File123456789	=_L("C:\\System1\\data1\\file123456789.txt");
sl@0: const TPtrC KSystem1Data1File2			=_L("C:\\System1\\data1\\file2.txt");
sl@0: const TPtrC KSystem1Data1File5			=_L("C:\\System1\\data1\\file5.txt");
sl@0: const TPtrC KSystem1Data1SrcFolder		=_L("C:\\System1\\data1\\src\\");
sl@0: const TPtrC KSystem1Data1DstFolder		=_L("C:\\System1\\data1\\dst\\");
sl@0: 
sl@0: const TPtrC KZFile1						=_L("Z:\\file1.txt");
sl@0: 
sl@0: // Valid Paths / Folder Name
sl@0: const TPtrC KValidPathName=_L("C:\\System1\\Data1\\");
sl@0: const TPtrC KValidPathNameWithoutDrive=_L("\\System1\\Data1\\");
sl@0: const TPtrC KValidPathNameWithoutDrive2=_L("\\System1\\Data1\\file1.txt");
sl@0: const TPtrC KValidFileName=_L("C:\\file1.txt");
sl@0: const TPtrC KValidFileNameNoExtension=_L("C:\\file1");
sl@0: const TPtrC KValidPathAndFileName=_L("C:\\System1\\Data1\\file1.txt");
sl@0: const TPtrC KValidFolderName=_L("C:\\System1\\Data1\\Dst\\");
sl@0: const TPtrC KValidDrive=_L("C:\\");
sl@0: const TPtrC KValidDrive2=_L("C:");
sl@0: const TPtrC KValidDrive3=_L("C");
sl@0: const TPtrC KValidDrive4=_L("Z:\\");
sl@0: const TPtrC KCopyFileFrom=_L("C:\\System1\\Data1\\Src\\file1.txt");
sl@0: const TPtrC KCopyFileTo=_L("C:\\System1\\Data1\\Dst\\file1.txt");
sl@0: const TPtrC KDeleteFile=_L("C:\\System1\\Data1\\Dst\\file1.txt");
sl@0: const TPtrC KRenameFromFile=_L("C:\\System1\\Data1\\file2.txt");
sl@0: const TPtrC KRenameToFile=_L("C:\\System1\\Data1\\file2New.txt");
sl@0: const TPtrC KValFolderName=_L("ValidFolderName");
sl@0: const TPtrC KCurrentPath=_L("C:\\System1\\Data1\\");
sl@0: const TPtrC KNoFolderName = _L("");
sl@0: const TPtrC KSessionRoot = _L("\\");
sl@0: 
sl@0: // KFolderNameIsTooLong is 256 chars long
sl@0: const TPtrC KFolderNameIsTooLong = _L("C:\\ThisFolderNameIsgoingToBeTooLongToBeCreatedOnTheSystemThisFolderNameIsgoingToBeTooLongToBeCreatedOnTheSystemThisFolderNameIsgoingToBeTooLongToBeCreatedOnTheSystemThisFolderNameIsgoingToBeTooLongToBeCreatedOnTheSystemThisFolderNameIsgoingToBeTooLongToBeC\\");
sl@0: const TPtrC KAbbreviatesFileFrom=_L("C:\\System1\\Data1\\file5.txt");
sl@0: const TPtrC KAbbreviatesFileFrom2=_L("C:\\System1\\Data1\\file123456789.txt");
sl@0: 
sl@0: 
sl@0: // InValid Paths / Folder Names
sl@0: const TPtrC KNoParameters=_L("");
sl@0: const TPtrC KInValidParameters=_L("3: \\52324424");
sl@0: const TPtrC KInValidPathName=_L("C:\\System1\\Data1\\InvalidPathName\\");
sl@0: const TPtrC KInvalidFileName=_L("C:\\System1\\Data1\\thefiledoesnotexistatthislocation.txt");
sl@0: const TPtrC KIllegalFileName=_L("C:\\System1\\Data1\\Illega<>.txt");
sl@0: const TPtrC KIllegalFolderName=_L("C:\\System1\\Data*<\\");
sl@0: const TPtrC KFolderNameWithWildcard=_L("C:\\System1\\data*\\");
sl@0: const TPtrC KInValidFolderName=_L("C:\\System1\\Data1\\InValid3+FollderName");
sl@0: const TPtrC KInValidDrive=_L("P:\\");
sl@0: const TPtrC KAppAbbName=_L("\\System1");
sl@0: 
sl@0: 
sl@0: //-----------------------------------------------------------------------------
sl@0: //
sl@0: // Timing macros.
sl@0: //
sl@0: //-----------------------------------------------------------------------------
sl@0: const TInt KMaxIterations     =   100;
sl@0: #define INCLUDE_VERBOSE
sl@0: 
sl@0: #define TIMERINSTALL \
sl@0: 	TTime start(0); \
sl@0: 	TTime end(0);   \
sl@0: 	TUint delta = 0; \
sl@0: 	TUint cummulative = 0; \
sl@0: 	TUint iterations = 0;
sl@0: 
sl@0: 
sl@0: #define TIMERRESET \
sl@0: 	delta = 0, cummulative = 0, iterations = 0;
sl@0: 
sl@0: 
sl@0: #define TIMERSTART \
sl@0: 	start.UniversalTime();
sl@0: 
sl@0: 
sl@0: #define TIMERSTOP \
sl@0: 	end.UniversalTime(); \
sl@0: 	delta = I64LOW(end.MicroSecondsFrom(start).Int64()); \
sl@0: 	iterations++; \
sl@0: 	cummulative += delta;
sl@0: 
sl@0: 
sl@0: #ifdef INCLUDE_VERBOSE
sl@0: _LIT(KTimerResult,   "Average time = %dus over %d iterations\n");
sl@0: _LIT(KTimingError,   "Error - no timing results to display\n");
sl@0: 
sl@0: 
sl@0: # define TIMERRESULT \
sl@0: 	if (iterations) \
sl@0: 		{ \
sl@0: 		theTest.Printf(KTimerResult, cummulative/iterations, iterations); \
sl@0: 		} \
sl@0: 	else \
sl@0: 		{ \
sl@0: 		theTest.Printf(KTimingError); \
sl@0: 		}
sl@0: 
sl@0: #else
sl@0: # define TIMERRESULT
sl@0: #endif
sl@0: 
sl@0: 
sl@0: #define TIMERAVERAGE \
sl@0: 		(iterations ? cummulative/iterations : 0xFFFFFFFF)
sl@0: //-----------------------------------------------------------------------------
sl@0: 
sl@0: 
sl@0: //
sl@0: //BaflUtils::GetEquivalentLanguageList
sl@0: //BaflUtils::NearestLanguageFileV2 
sl@0: //test data
sl@0: _LIT (KNullFilename, "");
sl@0: _LIT (KRscFilename,  "C:\\geltest.rsc");
sl@0: _LIT (KRscFilenameNoSuffix,  "C:\\geltest.");
sl@0: 
sl@0: _LIT (KAmericanLang, "C:\\geltest.r10");
sl@0: _LIT (KFrenchLang,   "C:\\geltest.r02");
sl@0: _LIT (KJapanEnglishLang, "C:\\geltest.r160");
sl@0: _LIT (KEnglishLang, "C:\\geltest.r01");
sl@0: _LIT (KInvalidDriveLetterV2, "q:\\geltest.rsc");
sl@0: _LIT (KNoSuchLangFile, "c:\\geltest.r54");
sl@0: 
sl@0: //
sl@0: //BaflUtils::PathExist test data
sl@0: 
sl@0: // Defines the maximum number of preconditions for each test case.
sl@0: #define PATH_EXIST_MAX_PRECONDITIONS 1
sl@0: 
sl@0: // Literals for PathExist testing
sl@0: const TPtrC KPathExistValid = _L("C:\\ValidPath\\Data1\\");
sl@0: const TPtrC KPathExistInValid = _L("C:\\ValidPath\\Data1\\InvalidPathName\\");
sl@0: const TPtrC KPathExistFullFile = _L("C:\\ValidPath\\Data1\\file1.txt");
sl@0: 
sl@0: const TPtrC KPathExist257 = _L("c:\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\256\\");
sl@0: const TPtrC KPathExist256 = _L("c:\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\56\\");
sl@0: const TPtrC KPathExist255 = _L("c:\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\10Letters\\6\\");
sl@0: 
sl@0: const TPtrC KPathExistShort = _L("c:\\10Letters\\10Letters\\");
sl@0: const TPtrC KPathExistShortT1 = _L("c:\\10Letters\\10Letters");
sl@0: const TPtrC KPathExistShortT2 = _L("c:\\10Letters\\10*\\");
sl@0: const TPtrC KPathExistShortT3 = _L("c:\\10Letters\\10Letter?\\");
sl@0: 
sl@0: const TPtrC KPathExistSessionPath = _L("c:\\");
sl@0: const TPtrC KPathExistRelativeT1 = _L("\\10Letters");
sl@0: const TPtrC KPathExistRelativeT2 = _L("\\10Letters\\");
sl@0: const TPtrC KPathExistRelativeT3 = _L("10Letters\\");
sl@0: 
sl@0: struct TPathExistTestRecord
sl@0: // Defines the test case structure for PathExist unit testing
sl@0: {
sl@0: 	// precondititions, directories to create before test run
sl@0: 	const TPtrC *iInPaths[PATH_EXIST_MAX_PRECONDITIONS];
sl@0: 
sl@0: 	// the directory to test for
sl@0: 	const TPtrC  *iTestPath;
sl@0: 
sl@0: 	// expected results
sl@0: 	TBool iResult;
sl@0: 
sl@0: 	// test case line number for quick test identification
sl@0: 	TInt iLineNum;
sl@0: };
sl@0: 
sl@0: LOCAL_D const TPathExistTestRecord pathExistTestCases[] =
sl@0: // Test cases for PathExist unit testing
sl@0: {
sl@0: 	{{&KPathExistValid}, &KPathExistValid, ETrue, 		__LINE__},
sl@0: 	{{&KPathExistValid}, &KPathExistInValid, EFalse, 	__LINE__},
sl@0: 	{{&KPathExistFullFile}, &KPathExistFullFile, EFalse,__LINE__},
sl@0: 	{{}, &KInValidParameters, EFalse, 					__LINE__},
sl@0: 	{{}, &KInValidFolderName, EFalse, 					__LINE__},
sl@0: 	{{}, &KValidDrive2, EFalse, 						__LINE__},
sl@0: 	{{}, &KNoParameters, EFalse, 						__LINE__},
sl@0: 
sl@0: 	{{&KPathExistShort}, &KPathExistShort, ETrue, 		__LINE__},
sl@0: 	{{&KPathExistShort}, &KPathExistShortT1, EFalse, 	__LINE__},
sl@0: 	{{&KPathExistShort}, &KPathExistShortT2, EFalse, 	__LINE__},
sl@0: 	{{&KPathExistShort}, &KPathExistShortT3, EFalse, 	__LINE__},
sl@0: 	{{&KPathExistShort}, &KPathExistRelativeT1, EFalse, __LINE__},
sl@0: 	{{&KPathExistShort}, &KPathExistRelativeT2, EFalse, __LINE__},
sl@0: 	{{&KPathExistShort}, &KPathExistRelativeT3, EFalse, __LINE__},
sl@0: 
sl@0: #if !defined __WINS__ && !defined __WINSCW__
sl@0: 
sl@0: // max boundary tests - can only be tested on hardware
sl@0: 
sl@0: 	{{&KPathExist255}, &KPathExist255, ETrue, 			__LINE__},
sl@0: 	{{&KPathExist256}, &KPathExist256, ETrue, 			__LINE__},
sl@0: 	{{&KPathExist257}, &KPathExist257, EFalse, 			__LINE__},
sl@0: 
sl@0: #endif //!defined __WINS__ && !defined __WINSCW__
sl@0: 
sl@0: 	{{}, NULL, ETrue} // mandatory, last element
sl@0: };
sl@0: 
sl@0: TBool DoTestPathExistsL(RFs& aFs, const struct TPathExistTestRecord& aTestRecord);
sl@0: 
sl@0: //
sl@0: //Create/Destroy test environment global functions
sl@0: 
sl@0: //Delete "aFullName" file.
sl@0: LOCAL_C void DeleteTestFile(const TDesC& aFullName)
sl@0: 	{
sl@0: 	RFs fsSession;
sl@0: 	TInt err = fsSession.Connect();
sl@0: 	if(err == KErrNone)
sl@0: 		{
sl@0: 		TEntry entry;
sl@0: 		if(fsSession.Entry(aFullName, entry) == KErrNone)
sl@0: 			{
sl@0: 			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
sl@0: 			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
sl@0: 			if(err != KErrNone)
sl@0: 				{
sl@0: 				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
sl@0: 				}
sl@0: 			err = fsSession.Delete(aFullName);
sl@0: 			if(err != KErrNone)
sl@0: 				{
sl@0: 				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
sl@0: 				}
sl@0: 			}
sl@0: 		fsSession.Close();
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: //Delete "aFullName" dir.
sl@0: LOCAL_C void DeleteTestDir(const TDesC& aFullName)
sl@0: 	{
sl@0: 	RFs fsSession;
sl@0: 	TInt err = fsSession.Connect();
sl@0: 	if(err == KErrNone)
sl@0: 		{
sl@0: 		TEntry entry;
sl@0: 		if(fsSession.Entry(aFullName, entry) == KErrNone)
sl@0: 			{
sl@0: 			RDebug::Print(_L("Deleting \"%S\" dir.\n"), &aFullName);
sl@0: 			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
sl@0: 			if(err != KErrNone)
sl@0: 				{
sl@0: 				RDebug::Print(_L("Error %d changing \"%S\" dir attributes.\n"), err, &aFullName);
sl@0: 				}
sl@0: 			err = fsSession.RmDir(aFullName);
sl@0: 			if(err != KErrNone)
sl@0: 				{
sl@0: 				RDebug::Print(_L("Error %d deleting \"%S\" dir.\n"), err, &aFullName);
sl@0: 				}
sl@0: 			}
sl@0: 		fsSession.Close();
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		RDebug::Print(_L("Error %d connecting file session. Dir: %S.\n"), err, &aFullName);
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: //Delete data files used by the test
sl@0: LOCAL_C void DeleteTestFiles()
sl@0: 	{
sl@0: 		DeleteTestFile(KSystem1Data1File1);
sl@0: 		DeleteTestFile(KFile1);
sl@0: 		DeleteTestFile(KSystem1Data1SrcFile1);
sl@0: 		DeleteTestFile(KSystem1Data1DstFile2);
sl@0: 		DeleteTestFile(KSystem1Data1File123456789);
sl@0: 		DeleteTestFile(KSystem1Data1File2);
sl@0: 		DeleteTestFile(KSystem1Data1File5);
sl@0: 		DeleteTestDir(KSystem1Data1SrcFolder);
sl@0: 		DeleteTestDir(KSystem1Data1DstFolder);
sl@0: 		DeleteTestDir(KSystem1Data1Folder);
sl@0: 		DeleteTestDir(KSystem1Folder);
sl@0: 	}
sl@0: 
sl@0: //
sl@0: //Test macroses and functions
sl@0: LOCAL_C void Check(TInt aValue, TInt aLine)
sl@0: 	{
sl@0: 	if(!aValue)
sl@0: 		{
sl@0: 		::DeleteTestFiles();
sl@0: 		theTest(EFalse, aLine);
sl@0: 		}
sl@0: 	}
sl@0: LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
sl@0: 	{
sl@0: 	if(aValue != aExpected)
sl@0: 		{
sl@0: 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
sl@0: 		::DeleteTestFiles();
sl@0: 		theTest(EFalse, aLine);
sl@0: 		}
sl@0: 	}
sl@0: #define TEST(arg) ::Check((arg), __LINE__)
sl@0: #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
sl@0: 
sl@0: 
sl@0: LOCAL_C void DeleteTestFiles2(RFs &aFs)
sl@0: {
sl@0: 	BaflUtils::DeleteFile (aFs, KRscFilename);
sl@0: 	BaflUtils::DeleteFile (aFs, KAmericanLang);
sl@0: 	BaflUtils::DeleteFile (aFs, KFrenchLang);
sl@0: 	BaflUtils::DeleteFile (aFs, KJapanEnglishLang);
sl@0: 	BaflUtils::DeleteFile (aFs, KEnglishLang);
sl@0: }
sl@0: 
sl@0: LOCAL_C void CreateTestFiles2(RFs &aFs)
sl@0: {
sl@0: 	TEST (BaflUtils::FileExists (aFs, KRscFilename) == EFalse);
sl@0: 	TEST (BaflUtils::FileExists (aFs, KAmericanLang) == EFalse);
sl@0: 	TEST (BaflUtils::FileExists (aFs, KFrenchLang) == EFalse);
sl@0: 	TEST (BaflUtils::FileExists (aFs, KJapanEnglishLang) == EFalse);
sl@0: 	TEST (BaflUtils::FileExists (aFs, KEnglishLang) == EFalse);
sl@0: 
sl@0: 	// Create the files...
sl@0: 	RFile rFile;
sl@0: 	TEST (KErrNone == rFile.Create (aFs, KRscFilename, EFileRead));
sl@0: 	rFile.Close ();
sl@0: 	TEST (KErrNone == rFile.Create (aFs, KAmericanLang, EFileRead));
sl@0: 	rFile.Close ();
sl@0: 	TEST (KErrNone == rFile.Create (aFs, KFrenchLang, EFileRead));
sl@0: 	rFile.Close ();
sl@0: 	TEST (KErrNone == rFile.Create (aFs, KEnglishLang, EFileRead));
sl@0: 	rFile.Close ();
sl@0: }
sl@0: //
sl@0: //Copy test file from Z: to C: drive.
sl@0: 
sl@0: LOCAL_C void CopyTestFiles()
sl@0: 	{
sl@0: 	RFs fsSession;
sl@0: 	TInt err = fsSession.Connect();
sl@0: 	if(err == KErrNone)
sl@0: 		{
sl@0: 		User::LeaveIfError(fsSession.MkDir(KSystem1Folder));
sl@0: 		User::LeaveIfError(fsSession.MkDir(KSystem1Data1Folder));
sl@0: 		TEST2( BaflUtils::CopyFile(fsSession, KZFile1, KSystem1Data1File1), KErrNone);
sl@0: 		TEST2( BaflUtils::CopyFile(fsSession, KZFile1, KFile1), KErrNone);
sl@0: 		TEST2( BaflUtils::CopyFile(fsSession, KZFile1, KSystem1Data1File123456789), KErrNone);
sl@0: 		TEST2( BaflUtils::CopyFile(fsSession, KZFile1, KSystem1Data1File2), KErrNone);
sl@0: 		TEST2( BaflUtils::CopyFile(fsSession, KZFile1, KSystem1Data1File5), KErrNone);
sl@0: 		User::LeaveIfError(fsSession.MkDir(KSystem1Data1SrcFolder));
sl@0: 		User::LeaveIfError(fsSession.MkDir(KSystem1Data1DstFolder));
sl@0: 		TEST2( BaflUtils::CopyFile(fsSession, KZFile1, KSystem1Data1SrcFile1), KErrNone);
sl@0: 		TEST2( BaflUtils::CopyFile(fsSession, KZFile1, KSystem1Data1DstFile2), KErrNone);
sl@0: 
sl@0: 		fsSession.Close();
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		RDebug::Print(_L("Error %d connecting file session.\n"), err);
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: 
sl@0: 
sl@0: //
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-1571
sl@0: @SYMTestCaseDesc Tests BaflUtils::PersistHAL()
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions It starts halsetting.exe and persist hal settings
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF083235 	Prop: HAL Attributes (eg screen calibration) lost if the battery is pulled out
sl@0: */
sl@0: void TestPersistHAL()
sl@0: 	{
sl@0: 	TEST (BaflUtils::PersistHAL() == KErrNone);
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-1571 "));
sl@0: 	theTest.Printf(_L("BaflUtils::PersistHAL() called"));
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0001
sl@0: @SYMTestCaseDesc Tests Baflutils::EnsurePathExists.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Passes in existing and non-existing pathnames and removes any directories created.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void TestEnsurePathExistsL(RFs& aFs)
sl@0: 	{
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0001 "));
sl@0: 	CleanupClosePushL(aFs);
sl@0: 	User::LeaveIfError(aFs.Connect());
sl@0: 
sl@0: 	// Path already exists so -11 will be returned within EnsurePathExistsL, Method Leaves with error code 0
sl@0: 	TRAPD(err, BaflUtils::EnsurePathExistsL(aFs, KValidPathName));
sl@0: 	TEST(!err);
sl@0: 	// Path does not exist so -12 will be returned within EnsurePathExistsL, The Directory will be created, Method Leaves with error code 0
sl@0: 	TRAPD(err2, BaflUtils::EnsurePathExistsL(aFs, KInValidPathName));
sl@0: 	TEST(!err2);
sl@0: 	TEST(!aFs.RmDir(KInValidPathName));
sl@0: 
sl@0: 	CleanupStack::PopAndDestroy(&aFs);
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0002
sl@0: @SYMTestCaseDesc Tests Baflutils::TestFileExists.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Passes in valid and invalid files.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void TestFileExists(RFs& aFs)
sl@0: 	{
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0002 "));
sl@0: 	CleanupClosePushL(aFs);
sl@0: 	User::LeaveIfError(aFs.Connect());
sl@0: 
sl@0: 	TEST (BaflUtils::FileExists(aFs,KValidPathAndFileName));
sl@0: 	TEST (!BaflUtils::FileExists(aFs,KInvalidFileName));
sl@0: 
sl@0: 	CleanupStack::PopAndDestroy(&aFs);
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0003
sl@0: @SYMTestCaseDesc Tests Baflutils::TestFolderExists.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Passes in valid and invalid folders.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void TestFolderExists(RFs& aFs)
sl@0: 	{
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0003 "));
sl@0: 	CleanupClosePushL(aFs);
sl@0: 	User::LeaveIfError(aFs.Connect());
sl@0: 
sl@0: 	TInt x = KMaxIterations;
sl@0: 
sl@0: 	TIMERINSTALL
sl@0: 
sl@0: 	while (x--)
sl@0: 	{
sl@0: 		TIMERSTART
sl@0: 		TEST(BaflUtils::FolderExists(aFs, KValidPathName));
sl@0: 		TEST(BaflUtils::FolderExists(aFs, KValidFileName));
sl@0: 		TEST(BaflUtils::FolderExists(aFs, KValidFileNameNoExtension));
sl@0: 	 	TEST(BaflUtils::FolderExists(aFs, KValidPathAndFileName));
sl@0: 	 	TEST(BaflUtils::FolderExists(aFs, KValidPathNameWithoutDrive));
sl@0: 	 	TEST(BaflUtils::FolderExists(aFs, KValidPathNameWithoutDrive2));
sl@0: 	 	TEST(BaflUtils::FolderExists(aFs, KValidDrive));
sl@0: 	 	TEST(BaflUtils::FolderExists(aFs, KValidDrive4));
sl@0: 	 	TEST(BaflUtils::FolderExists(aFs, KSessionRoot));
sl@0: 	 	TIMERSTOP
sl@0: 	}
sl@0: 
sl@0: 	theTest.Printf(_L("\nBenchmark results for FolderExists tests returning ETrue:\n"));
sl@0: 	TIMERRESULT
sl@0: 
sl@0: 	TIMERRESET
sl@0: 	x = KMaxIterations;
sl@0: 
sl@0: 	while (x--)
sl@0: 	{
sl@0: 		TIMERSTART
sl@0: 		TEST(!BaflUtils::FolderExists(aFs, KInValidPathName));
sl@0: 		TEST(!BaflUtils::FolderExists(aFs, KNoFolderName));
sl@0: 		TEST(!BaflUtils::FolderExists(aFs, KFolderNameIsTooLong));
sl@0: 	 	TEST(!BaflUtils::FolderExists(aFs, KIllegalFileName));
sl@0: 	 	TEST(!BaflUtils::FolderExists(aFs, KIllegalFolderName));
sl@0: 	 	TEST(!BaflUtils::FolderExists(aFs, KFolderNameWithWildcard));
sl@0: 		TIMERSTOP
sl@0: 	}
sl@0: 
sl@0: 	theTest.Printf(_L("\nBenchmark results for FolderExists tests returning EFalse:\n"));
sl@0: 	TIMERRESULT
sl@0: 	theTest.Printf(_L("\n"));
sl@0: 
sl@0: 	CleanupStack::PopAndDestroy(&aFs);
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0004
sl@0: @SYMTestCaseDesc Tests Baflutils::TestPathExists.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Passes in valid and invalid paths.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: @SYMDEF INC084050 - BaflUtils::PathExists does not work for 256 long folder paths
sl@0: */
sl@0: void TestPathExistsL(RFs& aFs)
sl@0: 	{
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0004 "));
sl@0: 	CleanupClosePushL(aFs);
sl@0: 
sl@0: 	User::LeaveIfError(aFs.Connect());
sl@0: 	aFs.SetSessionPath(KPathExistSessionPath);
sl@0: 
sl@0: 	for (TInt i = 0; pathExistTestCases[i].iTestPath != NULL; i++)
sl@0: 		TEST(DoTestPathExistsL(aFs,pathExistTestCases[i]));
sl@0: 
sl@0: 	CleanupStack::PopAndDestroy(&aFs);
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0005
sl@0: @SYMTestCaseDesc Tests Baflutils::TestCopyFile.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Copy's a file from one location to another.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void TestCopyFile(RFs& aFs)
sl@0: 	{
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0005 "));
sl@0: 	CleanupClosePushL(aFs);
sl@0: 	User::LeaveIfError(aFs.Connect());
sl@0: 
sl@0: 	TEST(!BaflUtils::CopyFile(aFs, KCopyFileFrom, KCopyFileTo));
sl@0: 
sl@0: 	CleanupStack::PopAndDestroy(&aFs);
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0006
sl@0: @SYMTestCaseDesc Tests Baflutils::TestDeleteFile.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Attempts to delete a file after setting its atributes 'Read Only'.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void TestDeleteFile(RFs& aFs)
sl@0: 	{
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0006 "));
sl@0: 	CleanupClosePushL(aFs);
sl@0: 	User::LeaveIfError(aFs.Connect());
sl@0: 
sl@0: 	TEST(!aFs.SetAtt(KDeleteFile, 0, KEntryAttReadOnly));
sl@0: 	TEST(!BaflUtils::DeleteFile(aFs, KDeleteFile));
sl@0: 
sl@0: 	CleanupStack::PopAndDestroy(&aFs);
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0007
sl@0: @SYMTestCaseDesc Tests Baflutils::TestRenameFile.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Attempts to rename or move files or directories.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void TestRenameFile(RFs& aFs)
sl@0: 	{
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0007 "));
sl@0: 	// Pushes aFs to the stack.
sl@0: 	CleanupClosePushL(aFs);
sl@0: 	// Open Session with the File Server
sl@0: 	User::LeaveIfError(aFs.Connect());
sl@0: 
sl@0: 	TUint theSwitch = CFileMan::EOverWrite;
sl@0: 
sl@0: 	// Renames or moves one or more files or directories.
sl@0: 	TEST2(BaflUtils::RenameFile(aFs, KRenameFromFile, KRenameToFile, theSwitch), KErrNone);
sl@0: 
sl@0: 	//Rename file back to original name
sl@0: 	TEST2(BaflUtils::RenameFile(aFs, KRenameToFile, KRenameFromFile, theSwitch), KErrNone);
sl@0: 	// Pops aFs from the stack
sl@0: 	CleanupStack::PopAndDestroy(&aFs);
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0008
sl@0: @SYMTestCaseDesc Tests Baflutils::TestAbbreviateFileName.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Checks if filename is being abbreviated correctly.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void TestAbbreviateFileName()
sl@0: 	{
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0008 "));
sl@0: 	TFileName originalFileName(KAbbreviatesFileFrom);
sl@0: 	TBuf<KMaxDisplayedFullNameLen> abbrevName;
sl@0: 
sl@0: 	BaflUtils::AbbreviateFileName (originalFileName.Left(29), abbrevName);
sl@0: 	TEST(!originalFileName.Compare(abbrevName));
sl@0: 	originalFileName.Copy(KAbbreviatesFileFrom2);
sl@0: 	BaflUtils::AbbreviateFileName (originalFileName.Left(39), abbrevName);
sl@0: 	TEST(originalFileName.Compare(abbrevName)<0);
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0009
sl@0: @SYMTestCaseDesc Tests Baflutils::TestCheckWhetherFullNameRefersToFolder.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Passes in paths with valid and invalid folder names.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void TestCheckWhetherFullNameRefersToFolder()
sl@0: 	{
sl@0: 	TBool folder=EFalse;
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0009 "));
sl@0: 
sl@0: 	TEST(!BaflUtils::CheckWhetherFullNameRefersToFolder(KValidFolderName, folder));
sl@0:     TEST(folder);
sl@0: 	folder=EFalse;
sl@0: 	TEST(!BaflUtils::CheckWhetherFullNameRefersToFolder(KInValidFolderName, folder));
sl@0:     TEST(!folder);
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0010
sl@0: @SYMTestCaseDesc Tests Baflutils::TestCopyWithTruncation.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Passes in truncated and non-truncated descriptors and checks return codes.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void TestCopyWithTruncation()
sl@0: 	{
sl@0: 	_LIT(KDestDataNoneTruncation,"TestCopyWithNoneTruncation");
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0010 "));
sl@0: 	TBuf<26> dest;
sl@0: 	TBuf<30> src(KDestDataNoneTruncation);
sl@0: 	TChar truncationSymbol = KBaflCharTruncation;
sl@0: 	BaflUtils::CopyWithTruncation(dest, src, truncationSymbol);
sl@0: 	TEST(dest.Locate(KBaflCharTruncation)==KErrNotFound);
sl@0: 
sl@0: 	_LIT(KDestDataTruncation,"TestCopyWithTruncationLeftMost");
sl@0: 	src.Copy(KDestDataTruncation);
sl@0: 	BaflUtils::CopyWithTruncation(dest, src, truncationSymbol);
sl@0: 	TEST(dest.Locate(KBaflCharTruncation)==25);
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0011
sl@0: @SYMTestCaseDesc Tests Baflutils::TestDriveAndPathFromFullName.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Passes in a valid filename and compares the result.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void TestDriveAndPathFromFullName()
sl@0: 	{
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0011 "));
sl@0: 	TFileName fileName = BaflUtils::DriveAndPathFromFullName(KValidPathName);
sl@0: 	TEST(!KValidPathName.Compare(fileName));
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0012
sl@0: @SYMTestCaseDesc Tests Baflutils::TestFolderNameFromFullName.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Passes in various valid path, file and drive names and compares results with descriptors.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void TestFolderNameFromFullName()
sl@0: 	{
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0012 "));
sl@0: 	TFileName fileName =  BaflUtils::FolderNameFromFullName(KValidPathAndFileName);
sl@0: 	TEST(!fileName.Compare(_L("Data1")));
sl@0: 
sl@0: 	fileName =  BaflUtils::FolderNameFromFullName( KValidFileName);
sl@0: 	TEST(!fileName.Compare(_L("C:\\")));
sl@0: 
sl@0: 	fileName =  BaflUtils::FolderNameFromFullName(KValidDrive);
sl@0: 	TEST(!fileName.Compare(_L("C:\\")));
sl@0: 
sl@0: 	fileName =  BaflUtils::FolderNameFromFullName(KValidDrive2);
sl@0: 	TEST(!fileName.Compare(_L("C:")));
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0013
sl@0: @SYMTestCaseDesc Tests Baflutils::TestMostSignificantPartOfFullName.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Passes in valid path and file names and compares results with descriptors.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void TestMostSignificantPartOfFullName()
sl@0: 	{
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0013 "));
sl@0: 	TFileName mostSignificantPart;
sl@0: 
sl@0: 	TEST(!BaflUtils::MostSignificantPartOfFullName(KValidPathName, mostSignificantPart));
sl@0: 	TEST(!mostSignificantPart.Compare(_L("Data1")));
sl@0: 	TEST(!BaflUtils::MostSignificantPartOfFullName(KValidPathAndFileName, mostSignificantPart));
sl@0: 	TEST(!mostSignificantPart.Compare(_L("file1.txt")));
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0014
sl@0: @SYMTestCaseDesc Tests Baflutils::TestParse.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Passes in valid path and file name.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void TestParse()
sl@0: 	{
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0014 "));
sl@0: 	TEST(!BaflUtils::Parse(KValidPathAndFileName));
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0015
sl@0: @SYMTestCaseDesc Tests Baflutils::TestRootFolderPath.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Passes in valid drive and compares against expected output.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void TestRootFolderPath()
sl@0: 	{
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0015 "));
sl@0: 	TFileName fileName = BaflUtils::RootFolderPath(KValidDrive3);
sl@0: 	TEST(!fileName.Compare(_L("C:\\")));
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0016
sl@0: @SYMTestCaseDesc Tests Baflutils::TestValidateFolderNameTypedByUserL.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Passes in various folder names and checks return values are as expected.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void TestValidateFolderNameTypedByUserL(RFs& aFs)
sl@0: 	{
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0016 "));
sl@0: 	CleanupClosePushL(aFs);
sl@0: 	User::LeaveIfError(aFs.Connect());
sl@0: 
sl@0: 	TInt retCode=KErrNone;
sl@0: 	retCode=retCode;
sl@0: 	TFileName newFolderFullName = KCurrentPath;
sl@0: 
sl@0: 	TEST(User::LeaveIfError(retCode=BaflUtils::ValidateFolderNameTypedByUserL(aFs, KValFolderName, KCurrentPath, newFolderFullName)==KErrNone));
sl@0: 	TEST(User::LeaveIfError(retCode=BaflUtils::ValidateFolderNameTypedByUserL(aFs, KNoFolderName, KCurrentPath, newFolderFullName)==KErrArgument));
sl@0: 	TEST(User::LeaveIfError(retCode=BaflUtils::ValidateFolderNameTypedByUserL(aFs, KInValidFolderName, KCurrentPath, newFolderFullName)==KErrBadName));
sl@0: 
sl@0: 	CleanupStack::PopAndDestroy(&aFs);
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0017
sl@0: @SYMTestCaseDesc Tests Baflutils::TestRemoveSystemDirectory.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Delete system directory.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void TestRemoveSystemDirectory(RFs& aFs)
sl@0: 	{
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0017 "));
sl@0: 	CleanupClosePushL(aFs);
sl@0: 	User::LeaveIfError(aFs.Connect());
sl@0: 
sl@0: 	CDir* theDir = NULL;
sl@0: 	CDir* fileList = NULL;
sl@0: 
sl@0: 	TInt attribs=KEntryAttDir|KEntryAttSystem|KEntryAttMatchExclusive;
sl@0: 	aFs.GetDir(_L("z:\\system"),attribs,ESortNone, fileList, theDir);
sl@0: 	TInt theNumber = theDir -> Count();
sl@0: 	TEST(theNumber == 1);
sl@0: 	BaflUtils::RemoveSystemDirectory(*theDir);
sl@0: 	theNumber = theDir -> Count();
sl@0: 	TEST(!theNumber);
sl@0: 
sl@0: 	delete fileList;
sl@0: 	delete theDir;
sl@0: 	CleanupStack::PopAndDestroy(&aFs);
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0018
sl@0: @SYMTestCaseDesc Tests Baflutils::TestCheckFolder.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Pass in various path, file and drive names.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void TestCheckFolder(RFs& aFs)
sl@0: 	{
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0018 "));
sl@0: 	CleanupClosePushL(aFs);
sl@0: 	User::LeaveIfError(aFs.Connect());
sl@0: 
sl@0: 	TEST(!BaflUtils::CheckFolder(aFs, KValidPathName));
sl@0: 	TEST(!BaflUtils::CheckFolder(aFs, KValidPathAndFileName));
sl@0: 
sl@0: 	TEST(!BaflUtils::CheckFolder(aFs, KValidFileName));
sl@0: 
sl@0: 	TEST(!BaflUtils::CheckFolder(aFs, KValidDrive));
sl@0: 	TEST(BaflUtils::CheckFolder(aFs, KInValidPathName));
sl@0: 
sl@0: 	CleanupStack::PopAndDestroy(&aFs);
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0019
sl@0: @SYMTestCaseDesc Tests Baflutils::TestDiskIsReadOnly.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Pass in various drives and parameters and checks 'Read Only' status.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void TestDiskIsReadOnly(RFs& aFs)
sl@0: 	{
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0019 "));
sl@0: 	CleanupClosePushL(aFs);
sl@0: 	User::LeaveIfError(aFs.Connect());
sl@0: 
sl@0: 	TBool isReadOnly = EFalse;
sl@0: 
sl@0: 	TEST(!BaflUtils::DiskIsReadOnly(aFs, KValidPathName, isReadOnly));
sl@0: 	TEST(!isReadOnly);
sl@0: 	TEST(!BaflUtils::DiskIsReadOnly(aFs, KValidDrive4, isReadOnly));
sl@0: 	TEST(isReadOnly);
sl@0: 	TEST(BaflUtils::DiskIsReadOnly(aFs, KInValidDrive, isReadOnly));
sl@0: 	TEST(isReadOnly);
sl@0: 	TEST(BaflUtils::DiskIsReadOnly(aFs, KNoParameters, isReadOnly));
sl@0: 	TEST(isReadOnly);
sl@0: 	TEST(BaflUtils::DiskIsReadOnly(aFs, KInValidParameters, isReadOnly));
sl@0: 	TEST(isReadOnly);
sl@0: 
sl@0: 	CleanupStack::PopAndDestroy(&aFs);
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0020
sl@0: @SYMTestCaseDesc Tests Baflutils::TestExtractAppNameFromFullName.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Compares thread name to both valid and invalid application names.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void TestExtractAppNameFromFullName()
sl@0: 	{
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0020 "));
sl@0: 	TPtrC validAppName = BaflUtils::ExtractAppNameFromFullName(RThread().FullName());
sl@0: 	TEST(!validAppName.Compare(RThread().Name()));
sl@0: 
sl@0: 	TPtrC inValidAppName = BaflUtils::ExtractAppNameFromFullName(_L("123:56789"));
sl@0: 	TEST(inValidAppName.Compare(_L("123:56789")));
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0021
sl@0: @SYMTestCaseDesc Tests Baflutils::TestIsFirstDriveForSocket.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Passes two differant drives as arguments.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void TestIsFirstDriveForSocket()
sl@0: 	{
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0021 "));
sl@0: 	TDriveUnit driveUnit(_L("C"));
sl@0: 
sl@0: 	TEST(BaflUtils::IsFirstDriveForSocket(driveUnit));
sl@0: 	driveUnit =_L("Z");
sl@0: 	TEST(!BaflUtils::IsFirstDriveForSocket(driveUnit));
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0022
sl@0: @SYMTestCaseDesc Tests Baflutils::TestIsFolder.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Passes in paths, folders and drives and checks return values.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void TestIsFolder(RFs& aFs)
sl@0: 	{
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0022 "));
sl@0: 	CleanupClosePushL(aFs);
sl@0: 	User::LeaveIfError(aFs.Connect());
sl@0: 
sl@0: 	TBool isFolder = EFalse;
sl@0: 
sl@0: 	TEST(!BaflUtils::IsFolder(aFs, KValidPathName, isFolder));
sl@0: 	TEST(isFolder);
sl@0: 
sl@0: 	TEST(BaflUtils::IsFolder(aFs, KInValidFolderName, isFolder));
sl@0: 	TEST(isFolder);
sl@0: 
sl@0: 	TEST(!BaflUtils::IsFolder(aFs, KValidDrive4, isFolder));
sl@0: 	TEST(isFolder);
sl@0: 
sl@0: 	CleanupStack::PopAndDestroy(&aFs);
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0023
sl@0: @SYMTestCaseDesc Tests Baflutils::TestUidTypeMatches.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Compares Uid's to check equality.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void TestUidTypeMatches()
sl@0: 	{
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0023 "));
sl@0: 	TUid valueOne = {0x1}, valueTwo = {0x2};
sl@0: 	valueOne.Uid(1);
sl@0: 	TUidType fileUid(valueOne), matchUid(valueOne);
sl@0: 
sl@0: 	TEST(BaflUtils::UidTypeMatches(fileUid, matchUid));
sl@0: 	valueTwo.Uid(2);
sl@0: 	fileUid = valueTwo;
sl@0: 	TEST(!BaflUtils::UidTypeMatches(fileUid, matchUid));
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0024
sl@0: @SYMTestCaseDesc Tests Baflutils::TestUpdateDiskListL.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Passes values to check the presence of disks.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void TestUpdateDiskListL(RFs& aFs)
sl@0: 	{
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0024 "));
sl@0: 	CleanupClosePushL(aFs);
sl@0: 	User::LeaveIfError(aFs.Connect());
sl@0: 
sl@0: 	CDesCArray* drives = new(ELeave) CDesCArrayFlat(1);
sl@0: 	CleanupStack::PushL(drives);
sl@0: 
sl@0: 	// According to the Base Peripherals team drive mapping differs between
sl@0: 	// targets' environment and there might be different drives other than C and Z.
sl@0: 	// For the same reason we shouldn't check the number of available disk drives.
sl@0: 
sl@0: 	// Test cases for excluding ROM
sl@0: 	TBool includeRom = EFalse;
sl@0: 	TDriveNumber driveToInclude = EDriveA;
sl@0: 	BaflUtils::UpdateDiskListL(aFs, *drives, includeRom, driveToInclude);
sl@0: 	TEST( 'A' == ((*drives)[0])[0] );
sl@0: 	TEST( 'C' == ((*drives)[1])[0] );
sl@0: 	TEST( 'Z' != ((*drives)[drives->MdcaCount() - 1])[0] );
sl@0: 
sl@0: 	driveToInclude = EDriveD;
sl@0: 	BaflUtils::UpdateDiskListL(aFs, *drives, includeRom, driveToInclude);
sl@0: 	TEST( 'C' == ((*drives)[0])[0] );
sl@0: 	TEST( 'D' == ((*drives)[1])[0] );
sl@0: 	TEST( 'Z' != ((*drives)[drives->MdcaCount() - 1])[0] );
sl@0: 
sl@0: 	// Test cases for including ROM
sl@0: 	includeRom = ETrue;
sl@0: 	driveToInclude = EDriveA;
sl@0: 	BaflUtils::UpdateDiskListL(aFs, *drives, includeRom, driveToInclude);
sl@0: 	TEST( 'A' == ((*drives)[0])[0] );
sl@0: 	TEST( 'C' == ((*drives)[1])[0] );
sl@0: 	TEST( 'Z' == ((*drives)[drives->MdcaCount() - 1])[0] );
sl@0: 
sl@0: 	driveToInclude = EDriveD;
sl@0: 	BaflUtils::UpdateDiskListL(aFs, *drives, includeRom, driveToInclude);
sl@0: 	TEST( 'C' == ((*drives)[0])[0] );
sl@0: 	TEST( 'D' == ((*drives)[1])[0] );
sl@0: 	TEST( 'Z' == ((*drives)[drives->MdcaCount() - 1])[0] );
sl@0: 
sl@0: 	CleanupStack::PopAndDestroy(2);
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038-0025
sl@0: @SYMTestCaseDesc Tests Baflutils::TestGetDiskListL.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Passes values to check the presence of disks.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF051652 - BaflUtils::IsFirstDriveForSocket seems broken
sl@0: */
sl@0: void TestGetDiskListL(RFs& aFs)
sl@0: 	{
sl@0: 	/*
sl@0: 	(Usually) Works in the same way as UpdateDiskListL. To test the difference we have
sl@0: 	to perform a manual test (emulator: F5,F4, h/w: removal of media cards).
sl@0: 	For automatic tests we check the normal functionality.
sl@0: 	*/
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0025 "));
sl@0: 	CleanupClosePushL(aFs);
sl@0: 	User::LeaveIfError(aFs.Connect());
sl@0: 
sl@0: 	CDesCArray* drives = new(ELeave) CDesCArrayFlat(1);
sl@0: 	CleanupStack::PushL(drives);
sl@0: 
sl@0: 	// According to the Base Peripherals team drive mapping differs between
sl@0: 	// targets' environment and there might be different drives other than C and Z.
sl@0: 	// For the same reason we shouldn't check the number of available disk drives.
sl@0: 
sl@0: 	// Test cases for excluding ROM
sl@0: 	BaflUtils::GetDiskListL(aFs, *drives);
sl@0: 	TEST( 'C' == ((*drives)[0])[0] );
sl@0: 
sl@0: #if !defined(__EPOC32__)
sl@0: 	TEST( 'X' == ((*drives)[drives->MdcaCount() - 3])[0] );
sl@0: #endif
sl@0: 
sl@0: 	TEST( 'Z' == ((*drives)[drives->MdcaCount() - 1])[0] );
sl@0: 
sl@0: 	CleanupStack::PopAndDestroy(2);
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0095
sl@0: @SYMTestCaseDesc Tests Baflutils::TestDriveIsReadOnlyInternal.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Pass in various drives and parameters and checks 'Read Only Internal' status.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMPREQ 806 Eliminate scanning for plugins on startup
sl@0: */
sl@0: void TestDriveIsReadOnlyInternal(RFs& aFs)
sl@0: 	{
sl@0: 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0095 "));
sl@0: 	CleanupClosePushL(aFs);
sl@0: 	User::LeaveIfError(aFs.Connect());
sl@0: 
sl@0: 	TBool isReadOnlyInternal = EFalse;
sl@0: 
sl@0: 	TEST(!BaflUtils::DriveIsReadOnlyInternal(aFs, KValidPathName, isReadOnlyInternal));
sl@0: 	TEST(!isReadOnlyInternal);
sl@0: 	TEST(!BaflUtils::DriveIsReadOnlyInternal(aFs, KValidDrive4, isReadOnlyInternal));
sl@0: 	TEST(isReadOnlyInternal);
sl@0: 	TEST(BaflUtils::DriveIsReadOnlyInternal(aFs, KInValidDrive, isReadOnlyInternal));
sl@0: 	TEST(isReadOnlyInternal);
sl@0: 	TEST(BaflUtils::DriveIsReadOnlyInternal(aFs, KNoParameters, isReadOnlyInternal));
sl@0: 	TEST(isReadOnlyInternal);
sl@0: 	TEST(BaflUtils::DriveIsReadOnlyInternal(aFs, KInValidParameters, isReadOnlyInternal));
sl@0: 	TEST(isReadOnlyInternal);
sl@0: 
sl@0: 	CleanupStack::PopAndDestroy(&aFs);
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID TI18N-BAFL-CT-4003
sl@0: @SYMTestCaseDesc Tests Baflutils::TestNearestLanguageFileV2.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Pass in various resource file names and change system locale setting, check the return values.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMPREQ 2525 Install device equivalent languages from SIS files
sl@0: */
sl@0: void TestNearestLanguageFileV2(RFs& aFs)
sl@0: 	{
sl@0: 	/* test case ID to be added */
sl@0:     theTest.Next (_L (" @SYMTestCaseID TI18N-BAFL-CT-4003 "));
sl@0:     
sl@0:     __UHEAP_MARK;
sl@0: 
sl@0: 	CleanupClosePushL (aFs);
sl@0: 	User::LeaveIfError (aFs.Connect ());
sl@0:     
sl@0:     DeleteTestFiles2(aFs);
sl@0:     CreateTestFiles2(aFs);
sl@0: 
sl@0: 	TBuf <256> filename;
sl@0: 	TLanguage lang = ELangNone;
sl@0: 	theTest.Printf (_L("lang initial value is %d\n"), lang);
sl@0: 
sl@0: 	// Test NearestLanguageFile with empty name
sl@0: 	TFileName resPath;
sl@0: 	BaflUtils::NearestLanguageFileV2(aFs, resPath, lang);
sl@0: 	TEST(resPath.Length()==0);
sl@0: 	theTest.Printf (_L("lang returned by NLFV2 is %d\n"), lang);
sl@0: 	TEST(ELangNone == lang);
sl@0: 	theTest.Printf (_L ("The NearestLanguageFile for the null file - %S - is - %S -\n"), &KNullFilename, &filename);
sl@0: 	
sl@0: 	// Test NearestLanguageFile with invalid drive letter
sl@0: 	filename.Copy (KInvalidDriveLetterV2);
sl@0: 	BaflUtils::NearestLanguageFileV2(aFs, filename, lang);
sl@0: 	//TEST(filename==KRscFilenameNoSuffix);
sl@0: 	theTest.Printf (_L ("The NearestLanguageFile for %S is %S, lang is %d\n"), &KInvalidDriveLetterV2, &filename, lang);
sl@0: 	//TEST(ELangNone == lang);
sl@0: 	
sl@0: 	// Test NearestLanguageFile with incorrect ext
sl@0: 	DeleteTestFiles2(aFs);
sl@0: 	RFile rFile;
sl@0: 	TEST (KErrNone == rFile.Create (aFs, KFrenchLang, EFileRead));
sl@0: 	rFile.Close ();
sl@0: 	filename.Copy (KNoSuchLangFile);
sl@0: 	BaflUtils::NearestLanguageFileV2(aFs, filename, lang);
sl@0: 	//TEST(filename==KRscFilenameNoSuffix);
sl@0: 	theTest.Printf (_L ("The NearestLanguageFile for %S is %S, lang is %d\n"), &KNoSuchLangFile, &filename, lang);
sl@0: 	//TEST(ELangNone == lang);
sl@0: 	BaflUtils::DeleteFile (aFs, KFrenchLang);
sl@0: 	CreateTestFiles2(aFs);
sl@0: 		
sl@0: 	// Test NearestLanguageFile with no suffix
sl@0: 	filename.Copy (KRscFilenameNoSuffix);
sl@0: 	BaflUtils::NearestLanguageFileV2(aFs, filename, lang);
sl@0: 	TEST(filename==KRscFilenameNoSuffix);
sl@0: 	theTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilenameNoSuffix, &filename);
sl@0: 	TEST(ELangNone == lang);
sl@0: 	
sl@0: 	// change locale to American
sl@0: 	TExtendedLocale loc;
sl@0: 	loc.LoadSystemSettings();
sl@0: 	TInt ret = loc.LoadLocale(_L ("elocl.10"));
sl@0: 	theTest.Printf(_L("LoadLocale returns %d\n"), ret);
sl@0: 	TEST(KErrNone == ret);
sl@0: 	ret = loc.SaveSystemSettings();
sl@0: 	TEST(KErrNone == ret);
sl@0: 	
sl@0: 	// Test NearestLanguageFile: AmE is supported
sl@0: 	filename.Copy (KRscFilename);
sl@0: 	BaflUtils::NearestLanguageFileV2(aFs, filename, lang);
sl@0: 	theTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilename, &filename);
sl@0: 	//TEST(filename == KEnglishLang);
sl@0: 	TEST(filename == KAmericanLang);
sl@0: 	TEST(lang == ELangAmerican);
sl@0: 
sl@0: 	// Delete geltest.r10, AmE downgrades to En_GB.
sl@0: 	BaflUtils::DeleteFile (aFs, KAmericanLang);
sl@0: 	filename.Copy (KRscFilename);
sl@0: 	BaflUtils::NearestLanguageFileV2(aFs, filename, lang);
sl@0: 	theTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilename, &filename);
sl@0: 	TEST(filename == KEnglishLang);
sl@0: 	TEST(lang == ELangEnglish);
sl@0: 	
sl@0: 	
sl@0: 	// Delete geltest.r01, AmE downgrades to en_GB, to ELangNone.
sl@0: 	BaflUtils::DeleteFile (aFs, KEnglishLang);
sl@0: 	filename.Copy (KRscFilename);
sl@0: 	BaflUtils::NearestLanguageFileV2(aFs, filename, lang);
sl@0: 	theTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilename, &filename);
sl@0: 	TEST(filename == KRscFilename); // filename remains unchanged.
sl@0: 	TEST(lang == ELangNone);
sl@0: 
sl@0: 	// restore locale settings
sl@0: 	theTest.Printf(_L("Restoring locale settings.\n"));
sl@0: 	loc.LoadSystemSettings();
sl@0: 	ret = loc.LoadLocale(_L("elocl.01"));
sl@0: 	TEST(KErrNone == ret);
sl@0: 	ret = loc.SaveSystemSettings();
sl@0: 	TEST(KErrNone == ret);
sl@0: 	
sl@0: 	CleanupStack::PopAndDestroy (&aFs);
sl@0: 
sl@0: 	__UHEAP_MARKEND;
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID TI18N-BAFL-CT-4004
sl@0: @SYMTestCaseDesc Tests Baflutils::TestGetEquivalentLanguageList.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Pass in various language ID's and check the returned list.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMPREQ 2525 Install device equivalent languages from SIS files
sl@0: */
sl@0: void TestGetEquivalentLanguageList()
sl@0: 	{
sl@0: 	/* test case ID to be added */
sl@0: 	theTest.Next (_L (" @SYMTestCaseID TI18N-BAFL-CT-4004 "));
sl@0:     
sl@0:     __UHEAP_MARK;
sl@0:     
sl@0: 	TLanguagePath lp;
sl@0: 	// Test GetNearestLanguageFile();
sl@0: 	// 1- There is an entry in the table for the given language
sl@0: 	BaflUtils::GetEquivalentLanguageList(ELangCyprusGreek, lp);
sl@0: 	TEST(ELangCyprusGreek == lp[0]);
sl@0: 	TEST(ELangGreek == lp[1]);
sl@0: 	TEST(ELangNone == lp[2]);
sl@0: 	
sl@0: 	// 2- There is no entry for the given language
sl@0: 	BaflUtils::GetEquivalentLanguageList(ELangFarsi, lp);
sl@0: 	TEST(ELangFarsi == lp[0]);
sl@0: 	TEST(ELangNone == lp[1]);
sl@0: 
sl@0: 	__UHEAP_MARKEND;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0038
sl@0: @SYMTestCaseDesc Tests Baflutils.
sl@0: @SYMTestPriority Medium
sl@0: @SYMTestActions Executes all T_baflutils tests.
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
sl@0: */
sl@0: void DoTestsL()
sl@0: 	{
sl@0: 	RFs fs;
sl@0: 
sl@0: 	::CopyTestFiles();
sl@0: 	TestPersistHAL();
sl@0: 	TestEnsurePathExistsL(fs);
sl@0: 	TestFileExists(fs);
sl@0: 	TestFolderExists(fs);
sl@0: 	TestPathExistsL(fs);
sl@0: 	TestCopyFile(fs);
sl@0: 	TestDeleteFile(fs);
sl@0: 	TestRenameFile(fs);
sl@0: 	TestAbbreviateFileName();
sl@0: 	TestCheckWhetherFullNameRefersToFolder();
sl@0: 	TestCopyWithTruncation();
sl@0: 	TestDriveAndPathFromFullName();
sl@0: 	TestFolderNameFromFullName();
sl@0: 	TestMostSignificantPartOfFullName();
sl@0: 	TestParse();
sl@0: 	TestRootFolderPath();
sl@0: 	TestValidateFolderNameTypedByUserL(fs);
sl@0: 	TestRemoveSystemDirectory(fs);
sl@0: 	TestCheckFolder(fs);
sl@0: 	TestDiskIsReadOnly(fs);
sl@0: 	TestNearestLanguageFileV2(fs);
sl@0: 	TestGetEquivalentLanguageList();
sl@0: 
sl@0: 	TestDriveIsReadOnlyInternal(fs);
sl@0: 	#if defined __WINS__ || defined __WINSCW__
sl@0: 
sl@0: 		TestExtractAppNameFromFullName();
sl@0: 	#endif //defined __WINS__ || defined __WINSCW__
sl@0: 
sl@0: 	TestIsFirstDriveForSocket();
sl@0: 	TestIsFolder(fs);
sl@0: 	TestUidTypeMatches();
sl@0: 	TestUpdateDiskListL(fs);
sl@0: 	TestGetDiskListL(fs);
sl@0: 	::DeleteTestFiles();
sl@0: 	}
sl@0: 
sl@0: GLDEF_C TInt E32Main()
sl@0: 	{
sl@0:     __UHEAP_MARK;
sl@0:     CTrapCleanup *cleanup=CTrapCleanup::New();
sl@0: 	theTest.Title();
sl@0: 	theTest.Start(_L("Testing T_BaflUtils "));
sl@0:     TRAPD(err,DoTestsL());
sl@0:     TEST(!err);
sl@0: 	theTest.End();
sl@0:     theTest.Close();
sl@0:     delete cleanup;
sl@0:     __UHEAP_MARKEND;
sl@0: 	return(0);
sl@0:     }
sl@0: 
sl@0: 
sl@0: //
sl@0: // Helper method to create a hierarchy of directories
sl@0: 
sl@0: TInt CreateDirectoryTree(RFs& aFs, const TPtrC* aDir)
sl@0: 	{
sl@0: 	TParse parsedPath;
sl@0: 	TBuf<KMaxFileName> newPath;
sl@0: 	TInt err, pos;
sl@0: 	TPtrC path;
sl@0: 	TPtrC fileName;
sl@0: 
sl@0: 	// check for the corectness of input parameters
sl@0: 	if (aDir == NULL )
sl@0: 		return EFalse;
sl@0: 
sl@0: 	// verify the corectness of the input path
sl@0: 	err = parsedPath.Set(*aDir, NULL, NULL);
sl@0: 	if (err != KErrNone)
sl@0: 	   return err;
sl@0: 
sl@0: 	// interatily build the path and create hierarchy of directories in file system
sl@0: 	newPath = parsedPath.Drive();
sl@0: 	newPath.Append('\\');
sl@0: 	path.Set(parsedPath.Path());
sl@0: 	path.Set(path.Mid(1));              // get rid of the first backlash
sl@0: 	while ((pos = path.Find(_L("\\"))) != KErrNotFound)
sl@0: 		{
sl@0: 		newPath.Append(path.Left(pos)); //append next directory
sl@0: 		newPath.Append('\\');
sl@0: 		err = aFs.MkDir(newPath);
sl@0: 		if (err != KErrNone) return err;
sl@0: 		path.Set(path.Mid(pos + 1));
sl@0: 		}
sl@0: 
sl@0: 	// directory created.
sl@0: 	// verify if there is a need to create a file
sl@0: 	if (parsedPath.NamePresent())
sl@0: 		{
sl@0: 		RFile file;
sl@0: 		err = file.Create(aFs, *aDir, EFileWrite);
sl@0: 		if (err != KErrNone) return err;
sl@0: 		file.Close();
sl@0: 		}
sl@0: 
sl@0: 	return KErrNone;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: //
sl@0: // Helper method to remove a hierarchy of directories
sl@0: TInt RemoveDirectoryTreeL(RFs& aFs, const TPtrC* aDir)
sl@0: 	{
sl@0: 	TParse parsedPath;
sl@0: 	TBuf<KMaxFileName> newPath;
sl@0: 	TInt err = KErrNone;
sl@0: 	TInt pos;
sl@0: 	TPtrC path;
sl@0: 	CFileMan *fileMan = NULL;
sl@0: 
sl@0: 	// Create FileMan.
sl@0: 	// As oposite to RFs it is able to remove a hirarchy of not empty directories
sl@0: 	TRAPD(leaveCode, fileMan = CFileMan::NewL(aFs));
sl@0: 	if (leaveCode != KErrNone)
sl@0: 		return leaveCode;
sl@0: 	CleanupStack::PushL(fileMan);
sl@0: 
sl@0: 	// verify the corectness of the input path
sl@0: 	err = parsedPath.Set(*aDir, NULL, NULL);
sl@0: 	if (err == KErrNone)
sl@0: 		{
sl@0: 		// build the path consisting only of the first level of directories hierarchy
sl@0: 		newPath = parsedPath.Drive();
sl@0: 		newPath.Append('\\');
sl@0: 		path.Set(parsedPath.Path());
sl@0: 		path.Set(path.Mid(1));  			// get rid of the first backlash
sl@0: 		if((pos = path.Find(_L("\\"))) != KErrNotFound)
sl@0: 			{
sl@0: 			newPath.Append(path.Left(pos)); //append next directory
sl@0: 			newPath.Append('\\');
sl@0: 			err = fileMan->RmDir(newPath);
sl@0: 			}
sl@0: 
sl@0: 		}
sl@0: 
sl@0: 	CleanupStack::PopAndDestroy(fileMan);
sl@0: 
sl@0: 	return err;;
sl@0: 	}
sl@0: 
sl@0: //
sl@0: // Helper method for TestPathExist test.
sl@0: TBool DoTestPathExistsL(RFs& aFs, const struct TPathExistTestRecord& aTestRecord)
sl@0: {
sl@0: 	TBool err;
sl@0: 	TInt i;
sl@0: 
sl@0: 	// 1. Create required directories (preconditions)
sl@0: 	for ( i = 0; aTestRecord.iInPaths[i] != NULL && i < PATH_EXIST_MAX_PRECONDITIONS; i++)
sl@0: 		{
sl@0: 		err = CreateDirectoryTree(aFs, aTestRecord.iInPaths[i]);
sl@0: 		if (err != KErrNone)
sl@0: 			{
sl@0: 			RDebug::Print(_L("TestPathExist(%d): Directory not created. Cause: %d"),
sl@0: 							aTestRecord.iLineNum, err);
sl@0: 
sl@0: 			// Do not break the loop here as the path might be incorrectly shaped on purpose.
sl@0: 			}
sl@0: 		}
sl@0: 
sl@0: 	// 2. Make a directory test
sl@0: 	TBool testOutcome = BaflUtils::PathExists(aFs, *aTestRecord.iTestPath);
sl@0: 
sl@0: 	// 3. Remove directories
sl@0: 	for ( i = 0; aTestRecord.iInPaths[i] != NULL && i < PATH_EXIST_MAX_PRECONDITIONS ; i++)
sl@0: 		{
sl@0: 		err = RemoveDirectoryTreeL(aFs, aTestRecord.iInPaths[i]);
sl@0: 
sl@0: 		if (err != KErrNone)
sl@0: 			{
sl@0: 			RDebug::Print(_L("TestPathExist(%d): Warning: Directory not removed. Cause: %d"),
sl@0: 							aTestRecord.iLineNum, err);
sl@0: 			}
sl@0: 		}
sl@0: 
sl@0: 	// 4. Check the results
sl@0: 	if (aTestRecord.iResult != testOutcome)
sl@0: 		{
sl@0: 		RDebug::Print(_L("TestPathExist(%d): Failed."), aTestRecord.iLineNum);
sl@0: 		return EFalse;
sl@0: 		}
sl@0: 
sl@0: 	RDebug::Print(_L("TestPathExist(%d): Passed."), aTestRecord.iLineNum);
sl@0: 	return ETrue;
sl@0: }