lowlevellibsandfws/apputils/tsrc/T_BaflUtils.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32test.h>
       
    17 #include <baclipb.h>
       
    18 #include <bautils.h>
       
    19 #include <f32file.h>
       
    20 #include <s32strm.h>
       
    21 #include <s32file.h>
       
    22 #include <e32lang.h>
       
    23 
       
    24 #include <fbs.h>
       
    25 
       
    26 
       
    27 LOCAL_D RTest theTest(_L("T_BaflUtils"));
       
    28 
       
    29 const TInt KMaxDisplayedFullNameLen	= 29;
       
    30 
       
    31 // File names for copying
       
    32 
       
    33 const TPtrC KSystem1Folder				=_L("C:\\System1\\");
       
    34 const TPtrC KSystem1Data1Folder			=_L("C:\\System1\\data1\\");
       
    35 
       
    36 const TPtrC KSystem1Data1File1			=_L("C:\\System1\\data1\\file1.txt");
       
    37 const TPtrC KFile1						=_L("C:\\file1.txt");
       
    38 const TPtrC KSystem1Data1SrcFile1		=_L("C:\\System1\\data1\\src\\file1.txt");
       
    39 const TPtrC KSystem1Data1DstFile2		=_L("C:\\System1\\data1\\dst\\file2.txt");
       
    40 const TPtrC KSystem1Data1File123456789	=_L("C:\\System1\\data1\\file123456789.txt");
       
    41 const TPtrC KSystem1Data1File2			=_L("C:\\System1\\data1\\file2.txt");
       
    42 const TPtrC KSystem1Data1File5			=_L("C:\\System1\\data1\\file5.txt");
       
    43 const TPtrC KSystem1Data1SrcFolder		=_L("C:\\System1\\data1\\src\\");
       
    44 const TPtrC KSystem1Data1DstFolder		=_L("C:\\System1\\data1\\dst\\");
       
    45 
       
    46 const TPtrC KZFile1						=_L("Z:\\file1.txt");
       
    47 
       
    48 // Valid Paths / Folder Name
       
    49 const TPtrC KValidPathName=_L("C:\\System1\\Data1\\");
       
    50 const TPtrC KValidPathNameWithoutDrive=_L("\\System1\\Data1\\");
       
    51 const TPtrC KValidPathNameWithoutDrive2=_L("\\System1\\Data1\\file1.txt");
       
    52 const TPtrC KValidFileName=_L("C:\\file1.txt");
       
    53 const TPtrC KValidFileNameNoExtension=_L("C:\\file1");
       
    54 const TPtrC KValidPathAndFileName=_L("C:\\System1\\Data1\\file1.txt");
       
    55 const TPtrC KValidFolderName=_L("C:\\System1\\Data1\\Dst\\");
       
    56 const TPtrC KValidDrive=_L("C:\\");
       
    57 const TPtrC KValidDrive2=_L("C:");
       
    58 const TPtrC KValidDrive3=_L("C");
       
    59 const TPtrC KValidDrive4=_L("Z:\\");
       
    60 const TPtrC KCopyFileFrom=_L("C:\\System1\\Data1\\Src\\file1.txt");
       
    61 const TPtrC KCopyFileTo=_L("C:\\System1\\Data1\\Dst\\file1.txt");
       
    62 const TPtrC KDeleteFile=_L("C:\\System1\\Data1\\Dst\\file1.txt");
       
    63 const TPtrC KRenameFromFile=_L("C:\\System1\\Data1\\file2.txt");
       
    64 const TPtrC KRenameToFile=_L("C:\\System1\\Data1\\file2New.txt");
       
    65 const TPtrC KValFolderName=_L("ValidFolderName");
       
    66 const TPtrC KCurrentPath=_L("C:\\System1\\Data1\\");
       
    67 const TPtrC KNoFolderName = _L("");
       
    68 const TPtrC KSessionRoot = _L("\\");
       
    69 
       
    70 // KFolderNameIsTooLong is 256 chars long
       
    71 const TPtrC KFolderNameIsTooLong = _L("C:\\ThisFolderNameIsgoingToBeTooLongToBeCreatedOnTheSystemThisFolderNameIsgoingToBeTooLongToBeCreatedOnTheSystemThisFolderNameIsgoingToBeTooLongToBeCreatedOnTheSystemThisFolderNameIsgoingToBeTooLongToBeCreatedOnTheSystemThisFolderNameIsgoingToBeTooLongToBeC\\");
       
    72 const TPtrC KAbbreviatesFileFrom=_L("C:\\System1\\Data1\\file5.txt");
       
    73 const TPtrC KAbbreviatesFileFrom2=_L("C:\\System1\\Data1\\file123456789.txt");
       
    74 
       
    75 
       
    76 // InValid Paths / Folder Names
       
    77 const TPtrC KNoParameters=_L("");
       
    78 const TPtrC KInValidParameters=_L("3: \\52324424");
       
    79 const TPtrC KInValidPathName=_L("C:\\System1\\Data1\\InvalidPathName\\");
       
    80 const TPtrC KInvalidFileName=_L("C:\\System1\\Data1\\thefiledoesnotexistatthislocation.txt");
       
    81 const TPtrC KIllegalFileName=_L("C:\\System1\\Data1\\Illega<>.txt");
       
    82 const TPtrC KIllegalFolderName=_L("C:\\System1\\Data*<\\");
       
    83 const TPtrC KFolderNameWithWildcard=_L("C:\\System1\\data*\\");
       
    84 const TPtrC KInValidFolderName=_L("C:\\System1\\Data1\\InValid3+FollderName");
       
    85 const TPtrC KInValidDrive=_L("P:\\");
       
    86 const TPtrC KAppAbbName=_L("\\System1");
       
    87 
       
    88 
       
    89 //-----------------------------------------------------------------------------
       
    90 //
       
    91 // Timing macros.
       
    92 //
       
    93 //-----------------------------------------------------------------------------
       
    94 const TInt KMaxIterations     =   100;
       
    95 #define INCLUDE_VERBOSE
       
    96 
       
    97 #define TIMERINSTALL \
       
    98 	TTime start(0); \
       
    99 	TTime end(0);   \
       
   100 	TUint delta = 0; \
       
   101 	TUint cummulative = 0; \
       
   102 	TUint iterations = 0;
       
   103 
       
   104 
       
   105 #define TIMERRESET \
       
   106 	delta = 0, cummulative = 0, iterations = 0;
       
   107 
       
   108 
       
   109 #define TIMERSTART \
       
   110 	start.UniversalTime();
       
   111 
       
   112 
       
   113 #define TIMERSTOP \
       
   114 	end.UniversalTime(); \
       
   115 	delta = I64LOW(end.MicroSecondsFrom(start).Int64()); \
       
   116 	iterations++; \
       
   117 	cummulative += delta;
       
   118 
       
   119 
       
   120 #ifdef INCLUDE_VERBOSE
       
   121 _LIT(KTimerResult,   "Average time = %dus over %d iterations\n");
       
   122 _LIT(KTimingError,   "Error - no timing results to display\n");
       
   123 
       
   124 
       
   125 # define TIMERRESULT \
       
   126 	if (iterations) \
       
   127 		{ \
       
   128 		theTest.Printf(KTimerResult, cummulative/iterations, iterations); \
       
   129 		} \
       
   130 	else \
       
   131 		{ \
       
   132 		theTest.Printf(KTimingError); \
       
   133 		}
       
   134 
       
   135 #else
       
   136 # define TIMERRESULT
       
   137 #endif
       
   138 
       
   139 
       
   140 #define TIMERAVERAGE \
       
   141 		(iterations ? cummulative/iterations : 0xFFFFFFFF)
       
   142 //-----------------------------------------------------------------------------
       
   143 
       
   144 
       
   145 //
       
   146 //BaflUtils::GetEquivalentLanguageList
       
   147 //BaflUtils::NearestLanguageFileV2 
       
   148 //test data
       
   149 _LIT (KNullFilename, "");
       
   150 _LIT (KRscFilename,  "C:\\geltest.rsc");
       
   151 _LIT (KRscFilenameNoSuffix,  "C:\\geltest.");
       
   152 
       
   153 _LIT (KAmericanLang, "C:\\geltest.r10");
       
   154 _LIT (KFrenchLang,   "C:\\geltest.r02");
       
   155 _LIT (KJapanEnglishLang, "C:\\geltest.r160");
       
   156 _LIT (KEnglishLang, "C:\\geltest.r01");
       
   157 _LIT (KInvalidDriveLetterV2, "q:\\geltest.rsc");
       
   158 _LIT (KNoSuchLangFile, "c:\\geltest.r54");
       
   159 
       
   160 //
       
   161 //BaflUtils::PathExist test data
       
   162 
       
   163 // Defines the maximum number of preconditions for each test case.
       
   164 #define PATH_EXIST_MAX_PRECONDITIONS 1
       
   165 
       
   166 // Literals for PathExist testing
       
   167 const TPtrC KPathExistValid = _L("C:\\ValidPath\\Data1\\");
       
   168 const TPtrC KPathExistInValid = _L("C:\\ValidPath\\Data1\\InvalidPathName\\");
       
   169 const TPtrC KPathExistFullFile = _L("C:\\ValidPath\\Data1\\file1.txt");
       
   170 
       
   171 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\\");
       
   172 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\\");
       
   173 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\\");
       
   174 
       
   175 const TPtrC KPathExistShort = _L("c:\\10Letters\\10Letters\\");
       
   176 const TPtrC KPathExistShortT1 = _L("c:\\10Letters\\10Letters");
       
   177 const TPtrC KPathExistShortT2 = _L("c:\\10Letters\\10*\\");
       
   178 const TPtrC KPathExistShortT3 = _L("c:\\10Letters\\10Letter?\\");
       
   179 
       
   180 const TPtrC KPathExistSessionPath = _L("c:\\");
       
   181 const TPtrC KPathExistRelativeT1 = _L("\\10Letters");
       
   182 const TPtrC KPathExistRelativeT2 = _L("\\10Letters\\");
       
   183 const TPtrC KPathExistRelativeT3 = _L("10Letters\\");
       
   184 
       
   185 struct TPathExistTestRecord
       
   186 // Defines the test case structure for PathExist unit testing
       
   187 {
       
   188 	// precondititions, directories to create before test run
       
   189 	const TPtrC *iInPaths[PATH_EXIST_MAX_PRECONDITIONS];
       
   190 
       
   191 	// the directory to test for
       
   192 	const TPtrC  *iTestPath;
       
   193 
       
   194 	// expected results
       
   195 	TBool iResult;
       
   196 
       
   197 	// test case line number for quick test identification
       
   198 	TInt iLineNum;
       
   199 };
       
   200 
       
   201 LOCAL_D const TPathExistTestRecord pathExistTestCases[] =
       
   202 // Test cases for PathExist unit testing
       
   203 {
       
   204 	{{&KPathExistValid}, &KPathExistValid, ETrue, 		__LINE__},
       
   205 	{{&KPathExistValid}, &KPathExistInValid, EFalse, 	__LINE__},
       
   206 	{{&KPathExistFullFile}, &KPathExistFullFile, EFalse,__LINE__},
       
   207 	{{}, &KInValidParameters, EFalse, 					__LINE__},
       
   208 	{{}, &KInValidFolderName, EFalse, 					__LINE__},
       
   209 	{{}, &KValidDrive2, EFalse, 						__LINE__},
       
   210 	{{}, &KNoParameters, EFalse, 						__LINE__},
       
   211 
       
   212 	{{&KPathExistShort}, &KPathExistShort, ETrue, 		__LINE__},
       
   213 	{{&KPathExistShort}, &KPathExistShortT1, EFalse, 	__LINE__},
       
   214 	{{&KPathExistShort}, &KPathExistShortT2, EFalse, 	__LINE__},
       
   215 	{{&KPathExistShort}, &KPathExistShortT3, EFalse, 	__LINE__},
       
   216 	{{&KPathExistShort}, &KPathExistRelativeT1, EFalse, __LINE__},
       
   217 	{{&KPathExistShort}, &KPathExistRelativeT2, EFalse, __LINE__},
       
   218 	{{&KPathExistShort}, &KPathExistRelativeT3, EFalse, __LINE__},
       
   219 
       
   220 #if !defined __WINS__ && !defined __WINSCW__
       
   221 
       
   222 // max boundary tests - can only be tested on hardware
       
   223 
       
   224 	{{&KPathExist255}, &KPathExist255, ETrue, 			__LINE__},
       
   225 	{{&KPathExist256}, &KPathExist256, ETrue, 			__LINE__},
       
   226 	{{&KPathExist257}, &KPathExist257, EFalse, 			__LINE__},
       
   227 
       
   228 #endif //!defined __WINS__ && !defined __WINSCW__
       
   229 
       
   230 	{{}, NULL, ETrue} // mandatory, last element
       
   231 };
       
   232 
       
   233 TBool DoTestPathExistsL(RFs& aFs, const struct TPathExistTestRecord& aTestRecord);
       
   234 
       
   235 //
       
   236 //Create/Destroy test environment global functions
       
   237 
       
   238 //Delete "aFullName" file.
       
   239 LOCAL_C void DeleteTestFile(const TDesC& aFullName)
       
   240 	{
       
   241 	RFs fsSession;
       
   242 	TInt err = fsSession.Connect();
       
   243 	if(err == KErrNone)
       
   244 		{
       
   245 		TEntry entry;
       
   246 		if(fsSession.Entry(aFullName, entry) == KErrNone)
       
   247 			{
       
   248 			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
       
   249 			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
       
   250 			if(err != KErrNone)
       
   251 				{
       
   252 				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
       
   253 				}
       
   254 			err = fsSession.Delete(aFullName);
       
   255 			if(err != KErrNone)
       
   256 				{
       
   257 				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
       
   258 				}
       
   259 			}
       
   260 		fsSession.Close();
       
   261 		}
       
   262 	else
       
   263 		{
       
   264 		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
       
   265 		}
       
   266 	}
       
   267 
       
   268 //Delete "aFullName" dir.
       
   269 LOCAL_C void DeleteTestDir(const TDesC& aFullName)
       
   270 	{
       
   271 	RFs fsSession;
       
   272 	TInt err = fsSession.Connect();
       
   273 	if(err == KErrNone)
       
   274 		{
       
   275 		TEntry entry;
       
   276 		if(fsSession.Entry(aFullName, entry) == KErrNone)
       
   277 			{
       
   278 			RDebug::Print(_L("Deleting \"%S\" dir.\n"), &aFullName);
       
   279 			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
       
   280 			if(err != KErrNone)
       
   281 				{
       
   282 				RDebug::Print(_L("Error %d changing \"%S\" dir attributes.\n"), err, &aFullName);
       
   283 				}
       
   284 			err = fsSession.RmDir(aFullName);
       
   285 			if(err != KErrNone)
       
   286 				{
       
   287 				RDebug::Print(_L("Error %d deleting \"%S\" dir.\n"), err, &aFullName);
       
   288 				}
       
   289 			}
       
   290 		fsSession.Close();
       
   291 		}
       
   292 	else
       
   293 		{
       
   294 		RDebug::Print(_L("Error %d connecting file session. Dir: %S.\n"), err, &aFullName);
       
   295 		}
       
   296 	}
       
   297 
       
   298 //Delete data files used by the test
       
   299 LOCAL_C void DeleteTestFiles()
       
   300 	{
       
   301 		DeleteTestFile(KSystem1Data1File1);
       
   302 		DeleteTestFile(KFile1);
       
   303 		DeleteTestFile(KSystem1Data1SrcFile1);
       
   304 		DeleteTestFile(KSystem1Data1DstFile2);
       
   305 		DeleteTestFile(KSystem1Data1File123456789);
       
   306 		DeleteTestFile(KSystem1Data1File2);
       
   307 		DeleteTestFile(KSystem1Data1File5);
       
   308 		DeleteTestDir(KSystem1Data1SrcFolder);
       
   309 		DeleteTestDir(KSystem1Data1DstFolder);
       
   310 		DeleteTestDir(KSystem1Data1Folder);
       
   311 		DeleteTestDir(KSystem1Folder);
       
   312 	}
       
   313 
       
   314 //
       
   315 //Test macroses and functions
       
   316 LOCAL_C void Check(TInt aValue, TInt aLine)
       
   317 	{
       
   318 	if(!aValue)
       
   319 		{
       
   320 		::DeleteTestFiles();
       
   321 		theTest(EFalse, aLine);
       
   322 		}
       
   323 	}
       
   324 LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
       
   325 	{
       
   326 	if(aValue != aExpected)
       
   327 		{
       
   328 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
       
   329 		::DeleteTestFiles();
       
   330 		theTest(EFalse, aLine);
       
   331 		}
       
   332 	}
       
   333 #define TEST(arg) ::Check((arg), __LINE__)
       
   334 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
       
   335 
       
   336 
       
   337 LOCAL_C void DeleteTestFiles2(RFs &aFs)
       
   338 {
       
   339 	BaflUtils::DeleteFile (aFs, KRscFilename);
       
   340 	BaflUtils::DeleteFile (aFs, KAmericanLang);
       
   341 	BaflUtils::DeleteFile (aFs, KFrenchLang);
       
   342 	BaflUtils::DeleteFile (aFs, KJapanEnglishLang);
       
   343 	BaflUtils::DeleteFile (aFs, KEnglishLang);
       
   344 }
       
   345 
       
   346 LOCAL_C void CreateTestFiles2(RFs &aFs)
       
   347 {
       
   348 	TEST (BaflUtils::FileExists (aFs, KRscFilename) == EFalse);
       
   349 	TEST (BaflUtils::FileExists (aFs, KAmericanLang) == EFalse);
       
   350 	TEST (BaflUtils::FileExists (aFs, KFrenchLang) == EFalse);
       
   351 	TEST (BaflUtils::FileExists (aFs, KJapanEnglishLang) == EFalse);
       
   352 	TEST (BaflUtils::FileExists (aFs, KEnglishLang) == EFalse);
       
   353 
       
   354 	// Create the files...
       
   355 	RFile rFile;
       
   356 	TEST (KErrNone == rFile.Create (aFs, KRscFilename, EFileRead));
       
   357 	rFile.Close ();
       
   358 	TEST (KErrNone == rFile.Create (aFs, KAmericanLang, EFileRead));
       
   359 	rFile.Close ();
       
   360 	TEST (KErrNone == rFile.Create (aFs, KFrenchLang, EFileRead));
       
   361 	rFile.Close ();
       
   362 	TEST (KErrNone == rFile.Create (aFs, KEnglishLang, EFileRead));
       
   363 	rFile.Close ();
       
   364 }
       
   365 //
       
   366 //Copy test file from Z: to C: drive.
       
   367 
       
   368 LOCAL_C void CopyTestFiles()
       
   369 	{
       
   370 	RFs fsSession;
       
   371 	TInt err = fsSession.Connect();
       
   372 	if(err == KErrNone)
       
   373 		{
       
   374 		User::LeaveIfError(fsSession.MkDir(KSystem1Folder));
       
   375 		User::LeaveIfError(fsSession.MkDir(KSystem1Data1Folder));
       
   376 		TEST2( BaflUtils::CopyFile(fsSession, KZFile1, KSystem1Data1File1), KErrNone);
       
   377 		TEST2( BaflUtils::CopyFile(fsSession, KZFile1, KFile1), KErrNone);
       
   378 		TEST2( BaflUtils::CopyFile(fsSession, KZFile1, KSystem1Data1File123456789), KErrNone);
       
   379 		TEST2( BaflUtils::CopyFile(fsSession, KZFile1, KSystem1Data1File2), KErrNone);
       
   380 		TEST2( BaflUtils::CopyFile(fsSession, KZFile1, KSystem1Data1File5), KErrNone);
       
   381 		User::LeaveIfError(fsSession.MkDir(KSystem1Data1SrcFolder));
       
   382 		User::LeaveIfError(fsSession.MkDir(KSystem1Data1DstFolder));
       
   383 		TEST2( BaflUtils::CopyFile(fsSession, KZFile1, KSystem1Data1SrcFile1), KErrNone);
       
   384 		TEST2( BaflUtils::CopyFile(fsSession, KZFile1, KSystem1Data1DstFile2), KErrNone);
       
   385 
       
   386 		fsSession.Close();
       
   387 		}
       
   388 	else
       
   389 		{
       
   390 		RDebug::Print(_L("Error %d connecting file session.\n"), err);
       
   391 		}
       
   392 	}
       
   393 
       
   394 
       
   395 
       
   396 //
       
   397 
       
   398 /**
       
   399 @SYMTestCaseID SYSLIB-BAFL-CT-1571
       
   400 @SYMTestCaseDesc Tests BaflUtils::PersistHAL()
       
   401 @SYMTestPriority Medium
       
   402 @SYMTestActions It starts halsetting.exe and persist hal settings
       
   403 @SYMTestExpectedResults The test must not fail.
       
   404 @SYMDEF DEF083235 	Prop: HAL Attributes (eg screen calibration) lost if the battery is pulled out
       
   405 */
       
   406 void TestPersistHAL()
       
   407 	{
       
   408 	TEST (BaflUtils::PersistHAL() == KErrNone);
       
   409 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-1571 "));
       
   410 	theTest.Printf(_L("BaflUtils::PersistHAL() called"));
       
   411 	}
       
   412 
       
   413 /**
       
   414 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0001
       
   415 @SYMTestCaseDesc Tests Baflutils::EnsurePathExists.
       
   416 @SYMTestPriority Medium
       
   417 @SYMTestActions Passes in existing and non-existing pathnames and removes any directories created.
       
   418 @SYMTestExpectedResults The test must not fail.
       
   419 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   420 */
       
   421 void TestEnsurePathExistsL(RFs& aFs)
       
   422 	{
       
   423 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0001 "));
       
   424 	CleanupClosePushL(aFs);
       
   425 	User::LeaveIfError(aFs.Connect());
       
   426 
       
   427 	// Path already exists so -11 will be returned within EnsurePathExistsL, Method Leaves with error code 0
       
   428 	TRAPD(err, BaflUtils::EnsurePathExistsL(aFs, KValidPathName));
       
   429 	TEST(!err);
       
   430 	// Path does not exist so -12 will be returned within EnsurePathExistsL, The Directory will be created, Method Leaves with error code 0
       
   431 	TRAPD(err2, BaflUtils::EnsurePathExistsL(aFs, KInValidPathName));
       
   432 	TEST(!err2);
       
   433 	TEST(!aFs.RmDir(KInValidPathName));
       
   434 
       
   435 	CleanupStack::PopAndDestroy(&aFs);
       
   436 	}
       
   437 
       
   438 /**
       
   439 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0002
       
   440 @SYMTestCaseDesc Tests Baflutils::TestFileExists.
       
   441 @SYMTestPriority Medium
       
   442 @SYMTestActions Passes in valid and invalid files.
       
   443 @SYMTestExpectedResults The test must not fail.
       
   444 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   445 */
       
   446 void TestFileExists(RFs& aFs)
       
   447 	{
       
   448 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0002 "));
       
   449 	CleanupClosePushL(aFs);
       
   450 	User::LeaveIfError(aFs.Connect());
       
   451 
       
   452 	TEST (BaflUtils::FileExists(aFs,KValidPathAndFileName));
       
   453 	TEST (!BaflUtils::FileExists(aFs,KInvalidFileName));
       
   454 
       
   455 	CleanupStack::PopAndDestroy(&aFs);
       
   456 	}
       
   457 
       
   458 /**
       
   459 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0003
       
   460 @SYMTestCaseDesc Tests Baflutils::TestFolderExists.
       
   461 @SYMTestPriority Medium
       
   462 @SYMTestActions Passes in valid and invalid folders.
       
   463 @SYMTestExpectedResults The test must not fail.
       
   464 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   465 */
       
   466 void TestFolderExists(RFs& aFs)
       
   467 	{
       
   468 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0003 "));
       
   469 	CleanupClosePushL(aFs);
       
   470 	User::LeaveIfError(aFs.Connect());
       
   471 
       
   472 	TInt x = KMaxIterations;
       
   473 
       
   474 	TIMERINSTALL
       
   475 
       
   476 	while (x--)
       
   477 	{
       
   478 		TIMERSTART
       
   479 		TEST(BaflUtils::FolderExists(aFs, KValidPathName));
       
   480 		TEST(BaflUtils::FolderExists(aFs, KValidFileName));
       
   481 		TEST(BaflUtils::FolderExists(aFs, KValidFileNameNoExtension));
       
   482 	 	TEST(BaflUtils::FolderExists(aFs, KValidPathAndFileName));
       
   483 	 	TEST(BaflUtils::FolderExists(aFs, KValidPathNameWithoutDrive));
       
   484 	 	TEST(BaflUtils::FolderExists(aFs, KValidPathNameWithoutDrive2));
       
   485 	 	TEST(BaflUtils::FolderExists(aFs, KValidDrive));
       
   486 	 	TEST(BaflUtils::FolderExists(aFs, KValidDrive4));
       
   487 	 	TEST(BaflUtils::FolderExists(aFs, KSessionRoot));
       
   488 	 	TIMERSTOP
       
   489 	}
       
   490 
       
   491 	theTest.Printf(_L("\nBenchmark results for FolderExists tests returning ETrue:\n"));
       
   492 	TIMERRESULT
       
   493 
       
   494 	TIMERRESET
       
   495 	x = KMaxIterations;
       
   496 
       
   497 	while (x--)
       
   498 	{
       
   499 		TIMERSTART
       
   500 		TEST(!BaflUtils::FolderExists(aFs, KInValidPathName));
       
   501 		TEST(!BaflUtils::FolderExists(aFs, KNoFolderName));
       
   502 		TEST(!BaflUtils::FolderExists(aFs, KFolderNameIsTooLong));
       
   503 	 	TEST(!BaflUtils::FolderExists(aFs, KIllegalFileName));
       
   504 	 	TEST(!BaflUtils::FolderExists(aFs, KIllegalFolderName));
       
   505 	 	TEST(!BaflUtils::FolderExists(aFs, KFolderNameWithWildcard));
       
   506 		TIMERSTOP
       
   507 	}
       
   508 
       
   509 	theTest.Printf(_L("\nBenchmark results for FolderExists tests returning EFalse:\n"));
       
   510 	TIMERRESULT
       
   511 	theTest.Printf(_L("\n"));
       
   512 
       
   513 	CleanupStack::PopAndDestroy(&aFs);
       
   514 	}
       
   515 
       
   516 /**
       
   517 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0004
       
   518 @SYMTestCaseDesc Tests Baflutils::TestPathExists.
       
   519 @SYMTestPriority Medium
       
   520 @SYMTestActions Passes in valid and invalid paths.
       
   521 @SYMTestExpectedResults The test must not fail.
       
   522 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   523 @SYMDEF INC084050 - BaflUtils::PathExists does not work for 256 long folder paths
       
   524 */
       
   525 void TestPathExistsL(RFs& aFs)
       
   526 	{
       
   527 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0004 "));
       
   528 	CleanupClosePushL(aFs);
       
   529 
       
   530 	User::LeaveIfError(aFs.Connect());
       
   531 	aFs.SetSessionPath(KPathExistSessionPath);
       
   532 
       
   533 	for (TInt i = 0; pathExistTestCases[i].iTestPath != NULL; i++)
       
   534 		TEST(DoTestPathExistsL(aFs,pathExistTestCases[i]));
       
   535 
       
   536 	CleanupStack::PopAndDestroy(&aFs);
       
   537 	}
       
   538 
       
   539 /**
       
   540 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0005
       
   541 @SYMTestCaseDesc Tests Baflutils::TestCopyFile.
       
   542 @SYMTestPriority Medium
       
   543 @SYMTestActions Copy's a file from one location to another.
       
   544 @SYMTestExpectedResults The test must not fail.
       
   545 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   546 */
       
   547 void TestCopyFile(RFs& aFs)
       
   548 	{
       
   549 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0005 "));
       
   550 	CleanupClosePushL(aFs);
       
   551 	User::LeaveIfError(aFs.Connect());
       
   552 
       
   553 	TEST(!BaflUtils::CopyFile(aFs, KCopyFileFrom, KCopyFileTo));
       
   554 
       
   555 	CleanupStack::PopAndDestroy(&aFs);
       
   556 	}
       
   557 
       
   558 /**
       
   559 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0006
       
   560 @SYMTestCaseDesc Tests Baflutils::TestDeleteFile.
       
   561 @SYMTestPriority Medium
       
   562 @SYMTestActions Attempts to delete a file after setting its atributes 'Read Only'.
       
   563 @SYMTestExpectedResults The test must not fail.
       
   564 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   565 */
       
   566 void TestDeleteFile(RFs& aFs)
       
   567 	{
       
   568 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0006 "));
       
   569 	CleanupClosePushL(aFs);
       
   570 	User::LeaveIfError(aFs.Connect());
       
   571 
       
   572 	TEST(!aFs.SetAtt(KDeleteFile, 0, KEntryAttReadOnly));
       
   573 	TEST(!BaflUtils::DeleteFile(aFs, KDeleteFile));
       
   574 
       
   575 	CleanupStack::PopAndDestroy(&aFs);
       
   576 	}
       
   577 
       
   578 /**
       
   579 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0007
       
   580 @SYMTestCaseDesc Tests Baflutils::TestRenameFile.
       
   581 @SYMTestPriority Medium
       
   582 @SYMTestActions Attempts to rename or move files or directories.
       
   583 @SYMTestExpectedResults The test must not fail.
       
   584 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   585 */
       
   586 void TestRenameFile(RFs& aFs)
       
   587 	{
       
   588 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0007 "));
       
   589 	// Pushes aFs to the stack.
       
   590 	CleanupClosePushL(aFs);
       
   591 	// Open Session with the File Server
       
   592 	User::LeaveIfError(aFs.Connect());
       
   593 
       
   594 	TUint theSwitch = CFileMan::EOverWrite;
       
   595 
       
   596 	// Renames or moves one or more files or directories.
       
   597 	TEST2(BaflUtils::RenameFile(aFs, KRenameFromFile, KRenameToFile, theSwitch), KErrNone);
       
   598 
       
   599 	//Rename file back to original name
       
   600 	TEST2(BaflUtils::RenameFile(aFs, KRenameToFile, KRenameFromFile, theSwitch), KErrNone);
       
   601 	// Pops aFs from the stack
       
   602 	CleanupStack::PopAndDestroy(&aFs);
       
   603 	}
       
   604 
       
   605 /**
       
   606 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0008
       
   607 @SYMTestCaseDesc Tests Baflutils::TestAbbreviateFileName.
       
   608 @SYMTestPriority Medium
       
   609 @SYMTestActions Checks if filename is being abbreviated correctly.
       
   610 @SYMTestExpectedResults The test must not fail.
       
   611 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   612 */
       
   613 void TestAbbreviateFileName()
       
   614 	{
       
   615 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0008 "));
       
   616 	TFileName originalFileName(KAbbreviatesFileFrom);
       
   617 	TBuf<KMaxDisplayedFullNameLen> abbrevName;
       
   618 
       
   619 	BaflUtils::AbbreviateFileName (originalFileName.Left(29), abbrevName);
       
   620 	TEST(!originalFileName.Compare(abbrevName));
       
   621 	originalFileName.Copy(KAbbreviatesFileFrom2);
       
   622 	BaflUtils::AbbreviateFileName (originalFileName.Left(39), abbrevName);
       
   623 	TEST(originalFileName.Compare(abbrevName)<0);
       
   624 	}
       
   625 
       
   626 /**
       
   627 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0009
       
   628 @SYMTestCaseDesc Tests Baflutils::TestCheckWhetherFullNameRefersToFolder.
       
   629 @SYMTestPriority Medium
       
   630 @SYMTestActions Passes in paths with valid and invalid folder names.
       
   631 @SYMTestExpectedResults The test must not fail.
       
   632 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   633 */
       
   634 void TestCheckWhetherFullNameRefersToFolder()
       
   635 	{
       
   636 	TBool folder=EFalse;
       
   637 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0009 "));
       
   638 
       
   639 	TEST(!BaflUtils::CheckWhetherFullNameRefersToFolder(KValidFolderName, folder));
       
   640     TEST(folder);
       
   641 	folder=EFalse;
       
   642 	TEST(!BaflUtils::CheckWhetherFullNameRefersToFolder(KInValidFolderName, folder));
       
   643     TEST(!folder);
       
   644 	}
       
   645 
       
   646 /**
       
   647 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0010
       
   648 @SYMTestCaseDesc Tests Baflutils::TestCopyWithTruncation.
       
   649 @SYMTestPriority Medium
       
   650 @SYMTestActions Passes in truncated and non-truncated descriptors and checks return codes.
       
   651 @SYMTestExpectedResults The test must not fail.
       
   652 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   653 */
       
   654 void TestCopyWithTruncation()
       
   655 	{
       
   656 	_LIT(KDestDataNoneTruncation,"TestCopyWithNoneTruncation");
       
   657 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0010 "));
       
   658 	TBuf<26> dest;
       
   659 	TBuf<30> src(KDestDataNoneTruncation);
       
   660 	TChar truncationSymbol = KBaflCharTruncation;
       
   661 	BaflUtils::CopyWithTruncation(dest, src, truncationSymbol);
       
   662 	TEST(dest.Locate(KBaflCharTruncation)==KErrNotFound);
       
   663 
       
   664 	_LIT(KDestDataTruncation,"TestCopyWithTruncationLeftMost");
       
   665 	src.Copy(KDestDataTruncation);
       
   666 	BaflUtils::CopyWithTruncation(dest, src, truncationSymbol);
       
   667 	TEST(dest.Locate(KBaflCharTruncation)==25);
       
   668 	}
       
   669 
       
   670 /**
       
   671 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0011
       
   672 @SYMTestCaseDesc Tests Baflutils::TestDriveAndPathFromFullName.
       
   673 @SYMTestPriority Medium
       
   674 @SYMTestActions Passes in a valid filename and compares the result.
       
   675 @SYMTestExpectedResults The test must not fail.
       
   676 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   677 */
       
   678 void TestDriveAndPathFromFullName()
       
   679 	{
       
   680 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0011 "));
       
   681 	TFileName fileName = BaflUtils::DriveAndPathFromFullName(KValidPathName);
       
   682 	TEST(!KValidPathName.Compare(fileName));
       
   683 	}
       
   684 
       
   685 /**
       
   686 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0012
       
   687 @SYMTestCaseDesc Tests Baflutils::TestFolderNameFromFullName.
       
   688 @SYMTestPriority Medium
       
   689 @SYMTestActions Passes in various valid path, file and drive names and compares results with descriptors.
       
   690 @SYMTestExpectedResults The test must not fail.
       
   691 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   692 */
       
   693 void TestFolderNameFromFullName()
       
   694 	{
       
   695 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0012 "));
       
   696 	TFileName fileName =  BaflUtils::FolderNameFromFullName(KValidPathAndFileName);
       
   697 	TEST(!fileName.Compare(_L("Data1")));
       
   698 
       
   699 	fileName =  BaflUtils::FolderNameFromFullName( KValidFileName);
       
   700 	TEST(!fileName.Compare(_L("C:\\")));
       
   701 
       
   702 	fileName =  BaflUtils::FolderNameFromFullName(KValidDrive);
       
   703 	TEST(!fileName.Compare(_L("C:\\")));
       
   704 
       
   705 	fileName =  BaflUtils::FolderNameFromFullName(KValidDrive2);
       
   706 	TEST(!fileName.Compare(_L("C:")));
       
   707 	}
       
   708 
       
   709 /**
       
   710 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0013
       
   711 @SYMTestCaseDesc Tests Baflutils::TestMostSignificantPartOfFullName.
       
   712 @SYMTestPriority Medium
       
   713 @SYMTestActions Passes in valid path and file names and compares results with descriptors.
       
   714 @SYMTestExpectedResults The test must not fail.
       
   715 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   716 */
       
   717 void TestMostSignificantPartOfFullName()
       
   718 	{
       
   719 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0013 "));
       
   720 	TFileName mostSignificantPart;
       
   721 
       
   722 	TEST(!BaflUtils::MostSignificantPartOfFullName(KValidPathName, mostSignificantPart));
       
   723 	TEST(!mostSignificantPart.Compare(_L("Data1")));
       
   724 	TEST(!BaflUtils::MostSignificantPartOfFullName(KValidPathAndFileName, mostSignificantPart));
       
   725 	TEST(!mostSignificantPart.Compare(_L("file1.txt")));
       
   726 	}
       
   727 
       
   728 /**
       
   729 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0014
       
   730 @SYMTestCaseDesc Tests Baflutils::TestParse.
       
   731 @SYMTestPriority Medium
       
   732 @SYMTestActions Passes in valid path and file name.
       
   733 @SYMTestExpectedResults The test must not fail.
       
   734 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   735 */
       
   736 void TestParse()
       
   737 	{
       
   738 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0014 "));
       
   739 	TEST(!BaflUtils::Parse(KValidPathAndFileName));
       
   740 	}
       
   741 
       
   742 /**
       
   743 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0015
       
   744 @SYMTestCaseDesc Tests Baflutils::TestRootFolderPath.
       
   745 @SYMTestPriority Medium
       
   746 @SYMTestActions Passes in valid drive and compares against expected output.
       
   747 @SYMTestExpectedResults The test must not fail.
       
   748 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   749 */
       
   750 void TestRootFolderPath()
       
   751 	{
       
   752 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0015 "));
       
   753 	TFileName fileName = BaflUtils::RootFolderPath(KValidDrive3);
       
   754 	TEST(!fileName.Compare(_L("C:\\")));
       
   755 	}
       
   756 
       
   757 /**
       
   758 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0016
       
   759 @SYMTestCaseDesc Tests Baflutils::TestValidateFolderNameTypedByUserL.
       
   760 @SYMTestPriority Medium
       
   761 @SYMTestActions Passes in various folder names and checks return values are as expected.
       
   762 @SYMTestExpectedResults The test must not fail.
       
   763 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   764 */
       
   765 void TestValidateFolderNameTypedByUserL(RFs& aFs)
       
   766 	{
       
   767 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0016 "));
       
   768 	CleanupClosePushL(aFs);
       
   769 	User::LeaveIfError(aFs.Connect());
       
   770 
       
   771 	TInt retCode=KErrNone;
       
   772 	retCode=retCode;
       
   773 	TFileName newFolderFullName = KCurrentPath;
       
   774 
       
   775 	TEST(User::LeaveIfError(retCode=BaflUtils::ValidateFolderNameTypedByUserL(aFs, KValFolderName, KCurrentPath, newFolderFullName)==KErrNone));
       
   776 	TEST(User::LeaveIfError(retCode=BaflUtils::ValidateFolderNameTypedByUserL(aFs, KNoFolderName, KCurrentPath, newFolderFullName)==KErrArgument));
       
   777 	TEST(User::LeaveIfError(retCode=BaflUtils::ValidateFolderNameTypedByUserL(aFs, KInValidFolderName, KCurrentPath, newFolderFullName)==KErrBadName));
       
   778 
       
   779 	CleanupStack::PopAndDestroy(&aFs);
       
   780 	}
       
   781 
       
   782 /**
       
   783 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0017
       
   784 @SYMTestCaseDesc Tests Baflutils::TestRemoveSystemDirectory.
       
   785 @SYMTestPriority Medium
       
   786 @SYMTestActions Delete system directory.
       
   787 @SYMTestExpectedResults The test must not fail.
       
   788 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   789 */
       
   790 void TestRemoveSystemDirectory(RFs& aFs)
       
   791 	{
       
   792 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0017 "));
       
   793 	CleanupClosePushL(aFs);
       
   794 	User::LeaveIfError(aFs.Connect());
       
   795 
       
   796 	CDir* theDir = NULL;
       
   797 	CDir* fileList = NULL;
       
   798 
       
   799 	TInt attribs=KEntryAttDir|KEntryAttSystem|KEntryAttMatchExclusive;
       
   800 	aFs.GetDir(_L("z:\\system"),attribs,ESortNone, fileList, theDir);
       
   801 	TInt theNumber = theDir -> Count();
       
   802 	TEST(theNumber == 1);
       
   803 	BaflUtils::RemoveSystemDirectory(*theDir);
       
   804 	theNumber = theDir -> Count();
       
   805 	TEST(!theNumber);
       
   806 
       
   807 	delete fileList;
       
   808 	delete theDir;
       
   809 	CleanupStack::PopAndDestroy(&aFs);
       
   810 	}
       
   811 
       
   812 /**
       
   813 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0018
       
   814 @SYMTestCaseDesc Tests Baflutils::TestCheckFolder.
       
   815 @SYMTestPriority Medium
       
   816 @SYMTestActions Pass in various path, file and drive names.
       
   817 @SYMTestExpectedResults The test must not fail.
       
   818 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   819 */
       
   820 void TestCheckFolder(RFs& aFs)
       
   821 	{
       
   822 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0018 "));
       
   823 	CleanupClosePushL(aFs);
       
   824 	User::LeaveIfError(aFs.Connect());
       
   825 
       
   826 	TEST(!BaflUtils::CheckFolder(aFs, KValidPathName));
       
   827 	TEST(!BaflUtils::CheckFolder(aFs, KValidPathAndFileName));
       
   828 
       
   829 	TEST(!BaflUtils::CheckFolder(aFs, KValidFileName));
       
   830 
       
   831 	TEST(!BaflUtils::CheckFolder(aFs, KValidDrive));
       
   832 	TEST(BaflUtils::CheckFolder(aFs, KInValidPathName));
       
   833 
       
   834 	CleanupStack::PopAndDestroy(&aFs);
       
   835 	}
       
   836 
       
   837 /**
       
   838 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0019
       
   839 @SYMTestCaseDesc Tests Baflutils::TestDiskIsReadOnly.
       
   840 @SYMTestPriority Medium
       
   841 @SYMTestActions Pass in various drives and parameters and checks 'Read Only' status.
       
   842 @SYMTestExpectedResults The test must not fail.
       
   843 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   844 */
       
   845 void TestDiskIsReadOnly(RFs& aFs)
       
   846 	{
       
   847 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0019 "));
       
   848 	CleanupClosePushL(aFs);
       
   849 	User::LeaveIfError(aFs.Connect());
       
   850 
       
   851 	TBool isReadOnly = EFalse;
       
   852 
       
   853 	TEST(!BaflUtils::DiskIsReadOnly(aFs, KValidPathName, isReadOnly));
       
   854 	TEST(!isReadOnly);
       
   855 	TEST(!BaflUtils::DiskIsReadOnly(aFs, KValidDrive4, isReadOnly));
       
   856 	TEST(isReadOnly);
       
   857 	TEST(BaflUtils::DiskIsReadOnly(aFs, KInValidDrive, isReadOnly));
       
   858 	TEST(isReadOnly);
       
   859 	TEST(BaflUtils::DiskIsReadOnly(aFs, KNoParameters, isReadOnly));
       
   860 	TEST(isReadOnly);
       
   861 	TEST(BaflUtils::DiskIsReadOnly(aFs, KInValidParameters, isReadOnly));
       
   862 	TEST(isReadOnly);
       
   863 
       
   864 	CleanupStack::PopAndDestroy(&aFs);
       
   865 	}
       
   866 
       
   867 /**
       
   868 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0020
       
   869 @SYMTestCaseDesc Tests Baflutils::TestExtractAppNameFromFullName.
       
   870 @SYMTestPriority Medium
       
   871 @SYMTestActions Compares thread name to both valid and invalid application names.
       
   872 @SYMTestExpectedResults The test must not fail.
       
   873 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   874 */
       
   875 void TestExtractAppNameFromFullName()
       
   876 	{
       
   877 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0020 "));
       
   878 	TPtrC validAppName = BaflUtils::ExtractAppNameFromFullName(RThread().FullName());
       
   879 	TEST(!validAppName.Compare(RThread().Name()));
       
   880 
       
   881 	TPtrC inValidAppName = BaflUtils::ExtractAppNameFromFullName(_L("123:56789"));
       
   882 	TEST(inValidAppName.Compare(_L("123:56789")));
       
   883 	}
       
   884 
       
   885 /**
       
   886 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0021
       
   887 @SYMTestCaseDesc Tests Baflutils::TestIsFirstDriveForSocket.
       
   888 @SYMTestPriority Medium
       
   889 @SYMTestActions Passes two differant drives as arguments.
       
   890 @SYMTestExpectedResults The test must not fail.
       
   891 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   892 */
       
   893 void TestIsFirstDriveForSocket()
       
   894 	{
       
   895 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0021 "));
       
   896 	TDriveUnit driveUnit(_L("C"));
       
   897 
       
   898 	TEST(BaflUtils::IsFirstDriveForSocket(driveUnit));
       
   899 	driveUnit =_L("Z");
       
   900 	TEST(!BaflUtils::IsFirstDriveForSocket(driveUnit));
       
   901 	}
       
   902 
       
   903 /**
       
   904 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0022
       
   905 @SYMTestCaseDesc Tests Baflutils::TestIsFolder.
       
   906 @SYMTestPriority Medium
       
   907 @SYMTestActions Passes in paths, folders and drives and checks return values.
       
   908 @SYMTestExpectedResults The test must not fail.
       
   909 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   910 */
       
   911 void TestIsFolder(RFs& aFs)
       
   912 	{
       
   913 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0022 "));
       
   914 	CleanupClosePushL(aFs);
       
   915 	User::LeaveIfError(aFs.Connect());
       
   916 
       
   917 	TBool isFolder = EFalse;
       
   918 
       
   919 	TEST(!BaflUtils::IsFolder(aFs, KValidPathName, isFolder));
       
   920 	TEST(isFolder);
       
   921 
       
   922 	TEST(BaflUtils::IsFolder(aFs, KInValidFolderName, isFolder));
       
   923 	TEST(isFolder);
       
   924 
       
   925 	TEST(!BaflUtils::IsFolder(aFs, KValidDrive4, isFolder));
       
   926 	TEST(isFolder);
       
   927 
       
   928 	CleanupStack::PopAndDestroy(&aFs);
       
   929 	}
       
   930 
       
   931 /**
       
   932 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0023
       
   933 @SYMTestCaseDesc Tests Baflutils::TestUidTypeMatches.
       
   934 @SYMTestPriority Medium
       
   935 @SYMTestActions Compares Uid's to check equality.
       
   936 @SYMTestExpectedResults The test must not fail.
       
   937 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   938 */
       
   939 void TestUidTypeMatches()
       
   940 	{
       
   941 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0023 "));
       
   942 	TUid valueOne = {0x1}, valueTwo = {0x2};
       
   943 	valueOne.Uid(1);
       
   944 	TUidType fileUid(valueOne), matchUid(valueOne);
       
   945 
       
   946 	TEST(BaflUtils::UidTypeMatches(fileUid, matchUid));
       
   947 	valueTwo.Uid(2);
       
   948 	fileUid = valueTwo;
       
   949 	TEST(!BaflUtils::UidTypeMatches(fileUid, matchUid));
       
   950 	}
       
   951 
       
   952 /**
       
   953 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0024
       
   954 @SYMTestCaseDesc Tests Baflutils::TestUpdateDiskListL.
       
   955 @SYMTestPriority Medium
       
   956 @SYMTestActions Passes values to check the presence of disks.
       
   957 @SYMTestExpectedResults The test must not fail.
       
   958 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
   959 */
       
   960 void TestUpdateDiskListL(RFs& aFs)
       
   961 	{
       
   962 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0024 "));
       
   963 	CleanupClosePushL(aFs);
       
   964 	User::LeaveIfError(aFs.Connect());
       
   965 
       
   966 	CDesCArray* drives = new(ELeave) CDesCArrayFlat(1);
       
   967 	CleanupStack::PushL(drives);
       
   968 
       
   969 	// According to the Base Peripherals team drive mapping differs between
       
   970 	// targets' environment and there might be different drives other than C and Z.
       
   971 	// For the same reason we shouldn't check the number of available disk drives.
       
   972 
       
   973 	// Test cases for excluding ROM
       
   974 	TBool includeRom = EFalse;
       
   975 	TDriveNumber driveToInclude = EDriveA;
       
   976 	BaflUtils::UpdateDiskListL(aFs, *drives, includeRom, driveToInclude);
       
   977 	TEST( 'A' == ((*drives)[0])[0] );
       
   978 	TEST( 'C' == ((*drives)[1])[0] );
       
   979 	TEST( 'Z' != ((*drives)[drives->MdcaCount() - 1])[0] );
       
   980 
       
   981 	driveToInclude = EDriveD;
       
   982 	BaflUtils::UpdateDiskListL(aFs, *drives, includeRom, driveToInclude);
       
   983 	TEST( 'C' == ((*drives)[0])[0] );
       
   984 	TEST( 'D' == ((*drives)[1])[0] );
       
   985 	TEST( 'Z' != ((*drives)[drives->MdcaCount() - 1])[0] );
       
   986 
       
   987 	// Test cases for including ROM
       
   988 	includeRom = ETrue;
       
   989 	driveToInclude = EDriveA;
       
   990 	BaflUtils::UpdateDiskListL(aFs, *drives, includeRom, driveToInclude);
       
   991 	TEST( 'A' == ((*drives)[0])[0] );
       
   992 	TEST( 'C' == ((*drives)[1])[0] );
       
   993 	TEST( 'Z' == ((*drives)[drives->MdcaCount() - 1])[0] );
       
   994 
       
   995 	driveToInclude = EDriveD;
       
   996 	BaflUtils::UpdateDiskListL(aFs, *drives, includeRom, driveToInclude);
       
   997 	TEST( 'C' == ((*drives)[0])[0] );
       
   998 	TEST( 'D' == ((*drives)[1])[0] );
       
   999 	TEST( 'Z' == ((*drives)[drives->MdcaCount() - 1])[0] );
       
  1000 
       
  1001 	CleanupStack::PopAndDestroy(2);
       
  1002 	}
       
  1003 
       
  1004 /**
       
  1005 @SYMTestCaseID SYSLIB-BAFL-CT-0038-0025
       
  1006 @SYMTestCaseDesc Tests Baflutils::TestGetDiskListL.
       
  1007 @SYMTestPriority Medium
       
  1008 @SYMTestActions Passes values to check the presence of disks.
       
  1009 @SYMTestExpectedResults The test must not fail.
       
  1010 @SYMDEF DEF051652 - BaflUtils::IsFirstDriveForSocket seems broken
       
  1011 */
       
  1012 void TestGetDiskListL(RFs& aFs)
       
  1013 	{
       
  1014 	/*
       
  1015 	(Usually) Works in the same way as UpdateDiskListL. To test the difference we have
       
  1016 	to perform a manual test (emulator: F5,F4, h/w: removal of media cards).
       
  1017 	For automatic tests we check the normal functionality.
       
  1018 	*/
       
  1019 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0025 "));
       
  1020 	CleanupClosePushL(aFs);
       
  1021 	User::LeaveIfError(aFs.Connect());
       
  1022 
       
  1023 	CDesCArray* drives = new(ELeave) CDesCArrayFlat(1);
       
  1024 	CleanupStack::PushL(drives);
       
  1025 
       
  1026 	// According to the Base Peripherals team drive mapping differs between
       
  1027 	// targets' environment and there might be different drives other than C and Z.
       
  1028 	// For the same reason we shouldn't check the number of available disk drives.
       
  1029 
       
  1030 	// Test cases for excluding ROM
       
  1031 	BaflUtils::GetDiskListL(aFs, *drives);
       
  1032 	TEST( 'C' == ((*drives)[0])[0] );
       
  1033 
       
  1034 #if !defined(__EPOC32__)
       
  1035 	TEST( 'X' == ((*drives)[drives->MdcaCount() - 3])[0] );
       
  1036 #endif
       
  1037 
       
  1038 	TEST( 'Z' == ((*drives)[drives->MdcaCount() - 1])[0] );
       
  1039 
       
  1040 	CleanupStack::PopAndDestroy(2);
       
  1041 	}
       
  1042 
       
  1043 /**
       
  1044 @SYMTestCaseID SYSLIB-BAFL-CT-0095
       
  1045 @SYMTestCaseDesc Tests Baflutils::TestDriveIsReadOnlyInternal.
       
  1046 @SYMTestPriority Medium
       
  1047 @SYMTestActions Pass in various drives and parameters and checks 'Read Only Internal' status.
       
  1048 @SYMTestExpectedResults The test must not fail.
       
  1049 @SYMPREQ 806 Eliminate scanning for plugins on startup
       
  1050 */
       
  1051 void TestDriveIsReadOnlyInternal(RFs& aFs)
       
  1052 	{
       
  1053 	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0095 "));
       
  1054 	CleanupClosePushL(aFs);
       
  1055 	User::LeaveIfError(aFs.Connect());
       
  1056 
       
  1057 	TBool isReadOnlyInternal = EFalse;
       
  1058 
       
  1059 	TEST(!BaflUtils::DriveIsReadOnlyInternal(aFs, KValidPathName, isReadOnlyInternal));
       
  1060 	TEST(!isReadOnlyInternal);
       
  1061 	TEST(!BaflUtils::DriveIsReadOnlyInternal(aFs, KValidDrive4, isReadOnlyInternal));
       
  1062 	TEST(isReadOnlyInternal);
       
  1063 	TEST(BaflUtils::DriveIsReadOnlyInternal(aFs, KInValidDrive, isReadOnlyInternal));
       
  1064 	TEST(isReadOnlyInternal);
       
  1065 	TEST(BaflUtils::DriveIsReadOnlyInternal(aFs, KNoParameters, isReadOnlyInternal));
       
  1066 	TEST(isReadOnlyInternal);
       
  1067 	TEST(BaflUtils::DriveIsReadOnlyInternal(aFs, KInValidParameters, isReadOnlyInternal));
       
  1068 	TEST(isReadOnlyInternal);
       
  1069 
       
  1070 	CleanupStack::PopAndDestroy(&aFs);
       
  1071 	}
       
  1072 
       
  1073 /**
       
  1074 @SYMTestCaseID TI18N-BAFL-CT-4003
       
  1075 @SYMTestCaseDesc Tests Baflutils::TestNearestLanguageFileV2.
       
  1076 @SYMTestPriority Medium
       
  1077 @SYMTestActions Pass in various resource file names and change system locale setting, check the return values.
       
  1078 @SYMTestExpectedResults The test must not fail.
       
  1079 @SYMPREQ 2525 Install device equivalent languages from SIS files
       
  1080 */
       
  1081 void TestNearestLanguageFileV2(RFs& aFs)
       
  1082 	{
       
  1083 	/* test case ID to be added */
       
  1084     theTest.Next (_L (" @SYMTestCaseID TI18N-BAFL-CT-4003 "));
       
  1085     
       
  1086     __UHEAP_MARK;
       
  1087 
       
  1088 	CleanupClosePushL (aFs);
       
  1089 	User::LeaveIfError (aFs.Connect ());
       
  1090     
       
  1091     DeleteTestFiles2(aFs);
       
  1092     CreateTestFiles2(aFs);
       
  1093 
       
  1094 	TBuf <256> filename;
       
  1095 	TLanguage lang = ELangNone;
       
  1096 	theTest.Printf (_L("lang initial value is %d\n"), lang);
       
  1097 
       
  1098 	// Test NearestLanguageFile with empty name
       
  1099 	TFileName resPath;
       
  1100 	BaflUtils::NearestLanguageFileV2(aFs, resPath, lang);
       
  1101 	TEST(resPath.Length()==0);
       
  1102 	theTest.Printf (_L("lang returned by NLFV2 is %d\n"), lang);
       
  1103 	TEST(ELangNone == lang);
       
  1104 	theTest.Printf (_L ("The NearestLanguageFile for the null file - %S - is - %S -\n"), &KNullFilename, &filename);
       
  1105 	
       
  1106 	// Test NearestLanguageFile with invalid drive letter
       
  1107 	filename.Copy (KInvalidDriveLetterV2);
       
  1108 	BaflUtils::NearestLanguageFileV2(aFs, filename, lang);
       
  1109 	//TEST(filename==KRscFilenameNoSuffix);
       
  1110 	theTest.Printf (_L ("The NearestLanguageFile for %S is %S, lang is %d\n"), &KInvalidDriveLetterV2, &filename, lang);
       
  1111 	//TEST(ELangNone == lang);
       
  1112 	
       
  1113 	// Test NearestLanguageFile with incorrect ext
       
  1114 	DeleteTestFiles2(aFs);
       
  1115 	RFile rFile;
       
  1116 	TEST (KErrNone == rFile.Create (aFs, KFrenchLang, EFileRead));
       
  1117 	rFile.Close ();
       
  1118 	filename.Copy (KNoSuchLangFile);
       
  1119 	BaflUtils::NearestLanguageFileV2(aFs, filename, lang);
       
  1120 	//TEST(filename==KRscFilenameNoSuffix);
       
  1121 	theTest.Printf (_L ("The NearestLanguageFile for %S is %S, lang is %d\n"), &KNoSuchLangFile, &filename, lang);
       
  1122 	//TEST(ELangNone == lang);
       
  1123 	BaflUtils::DeleteFile (aFs, KFrenchLang);
       
  1124 	CreateTestFiles2(aFs);
       
  1125 		
       
  1126 	// Test NearestLanguageFile with no suffix
       
  1127 	filename.Copy (KRscFilenameNoSuffix);
       
  1128 	BaflUtils::NearestLanguageFileV2(aFs, filename, lang);
       
  1129 	TEST(filename==KRscFilenameNoSuffix);
       
  1130 	theTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilenameNoSuffix, &filename);
       
  1131 	TEST(ELangNone == lang);
       
  1132 	
       
  1133 	// change locale to American
       
  1134 	TExtendedLocale loc;
       
  1135 	loc.LoadSystemSettings();
       
  1136 	TInt ret = loc.LoadLocale(_L ("elocl.10"));
       
  1137 	theTest.Printf(_L("LoadLocale returns %d\n"), ret);
       
  1138 	TEST(KErrNone == ret);
       
  1139 	ret = loc.SaveSystemSettings();
       
  1140 	TEST(KErrNone == ret);
       
  1141 	
       
  1142 	// Test NearestLanguageFile: AmE is supported
       
  1143 	filename.Copy (KRscFilename);
       
  1144 	BaflUtils::NearestLanguageFileV2(aFs, filename, lang);
       
  1145 	theTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilename, &filename);
       
  1146 	//TEST(filename == KEnglishLang);
       
  1147 	TEST(filename == KAmericanLang);
       
  1148 	TEST(lang == ELangAmerican);
       
  1149 
       
  1150 	// Delete geltest.r10, AmE downgrades to En_GB.
       
  1151 	BaflUtils::DeleteFile (aFs, KAmericanLang);
       
  1152 	filename.Copy (KRscFilename);
       
  1153 	BaflUtils::NearestLanguageFileV2(aFs, filename, lang);
       
  1154 	theTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilename, &filename);
       
  1155 	TEST(filename == KEnglishLang);
       
  1156 	TEST(lang == ELangEnglish);
       
  1157 	
       
  1158 	
       
  1159 	// Delete geltest.r01, AmE downgrades to en_GB, to ELangNone.
       
  1160 	BaflUtils::DeleteFile (aFs, KEnglishLang);
       
  1161 	filename.Copy (KRscFilename);
       
  1162 	BaflUtils::NearestLanguageFileV2(aFs, filename, lang);
       
  1163 	theTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilename, &filename);
       
  1164 	TEST(filename == KRscFilename); // filename remains unchanged.
       
  1165 	TEST(lang == ELangNone);
       
  1166 
       
  1167 	// restore locale settings
       
  1168 	theTest.Printf(_L("Restoring locale settings.\n"));
       
  1169 	loc.LoadSystemSettings();
       
  1170 	ret = loc.LoadLocale(_L("elocl.01"));
       
  1171 	TEST(KErrNone == ret);
       
  1172 	ret = loc.SaveSystemSettings();
       
  1173 	TEST(KErrNone == ret);
       
  1174 	
       
  1175 	CleanupStack::PopAndDestroy (&aFs);
       
  1176 
       
  1177 	__UHEAP_MARKEND;
       
  1178 	}
       
  1179 
       
  1180 /**
       
  1181 @SYMTestCaseID TI18N-BAFL-CT-4004
       
  1182 @SYMTestCaseDesc Tests Baflutils::TestGetEquivalentLanguageList.
       
  1183 @SYMTestPriority Medium
       
  1184 @SYMTestActions Pass in various language ID's and check the returned list.
       
  1185 @SYMTestExpectedResults The test must not fail.
       
  1186 @SYMPREQ 2525 Install device equivalent languages from SIS files
       
  1187 */
       
  1188 void TestGetEquivalentLanguageList()
       
  1189 	{
       
  1190 	/* test case ID to be added */
       
  1191 	theTest.Next (_L (" @SYMTestCaseID TI18N-BAFL-CT-4004 "));
       
  1192     
       
  1193     __UHEAP_MARK;
       
  1194     
       
  1195 	TLanguagePath lp;
       
  1196 	// Test GetNearestLanguageFile();
       
  1197 	// 1- There is an entry in the table for the given language
       
  1198 	BaflUtils::GetEquivalentLanguageList(ELangCyprusGreek, lp);
       
  1199 	TEST(ELangCyprusGreek == lp[0]);
       
  1200 	TEST(ELangGreek == lp[1]);
       
  1201 	TEST(ELangNone == lp[2]);
       
  1202 	
       
  1203 	// 2- There is no entry for the given language
       
  1204 	BaflUtils::GetEquivalentLanguageList(ELangFarsi, lp);
       
  1205 	TEST(ELangFarsi == lp[0]);
       
  1206 	TEST(ELangNone == lp[1]);
       
  1207 
       
  1208 	__UHEAP_MARKEND;
       
  1209 	}
       
  1210 
       
  1211 
       
  1212 /**
       
  1213 @SYMTestCaseID SYSLIB-BAFL-CT-0038
       
  1214 @SYMTestCaseDesc Tests Baflutils.
       
  1215 @SYMTestPriority Medium
       
  1216 @SYMTestActions Executes all T_baflutils tests.
       
  1217 @SYMTestExpectedResults The test must not fail.
       
  1218 @SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
       
  1219 */
       
  1220 void DoTestsL()
       
  1221 	{
       
  1222 	RFs fs;
       
  1223 
       
  1224 	::CopyTestFiles();
       
  1225 	TestPersistHAL();
       
  1226 	TestEnsurePathExistsL(fs);
       
  1227 	TestFileExists(fs);
       
  1228 	TestFolderExists(fs);
       
  1229 	TestPathExistsL(fs);
       
  1230 	TestCopyFile(fs);
       
  1231 	TestDeleteFile(fs);
       
  1232 	TestRenameFile(fs);
       
  1233 	TestAbbreviateFileName();
       
  1234 	TestCheckWhetherFullNameRefersToFolder();
       
  1235 	TestCopyWithTruncation();
       
  1236 	TestDriveAndPathFromFullName();
       
  1237 	TestFolderNameFromFullName();
       
  1238 	TestMostSignificantPartOfFullName();
       
  1239 	TestParse();
       
  1240 	TestRootFolderPath();
       
  1241 	TestValidateFolderNameTypedByUserL(fs);
       
  1242 	TestRemoveSystemDirectory(fs);
       
  1243 	TestCheckFolder(fs);
       
  1244 	TestDiskIsReadOnly(fs);
       
  1245 	TestNearestLanguageFileV2(fs);
       
  1246 	TestGetEquivalentLanguageList();
       
  1247 
       
  1248 	TestDriveIsReadOnlyInternal(fs);
       
  1249 	#if defined __WINS__ || defined __WINSCW__
       
  1250 
       
  1251 		TestExtractAppNameFromFullName();
       
  1252 	#endif //defined __WINS__ || defined __WINSCW__
       
  1253 
       
  1254 	TestIsFirstDriveForSocket();
       
  1255 	TestIsFolder(fs);
       
  1256 	TestUidTypeMatches();
       
  1257 	TestUpdateDiskListL(fs);
       
  1258 	TestGetDiskListL(fs);
       
  1259 	::DeleteTestFiles();
       
  1260 	}
       
  1261 
       
  1262 GLDEF_C TInt E32Main()
       
  1263 	{
       
  1264     __UHEAP_MARK;
       
  1265     CTrapCleanup *cleanup=CTrapCleanup::New();
       
  1266 	theTest.Title();
       
  1267 	theTest.Start(_L("Testing T_BaflUtils "));
       
  1268     TRAPD(err,DoTestsL());
       
  1269     TEST(!err);
       
  1270 	theTest.End();
       
  1271     theTest.Close();
       
  1272     delete cleanup;
       
  1273     __UHEAP_MARKEND;
       
  1274 	return(0);
       
  1275     }
       
  1276 
       
  1277 
       
  1278 //
       
  1279 // Helper method to create a hierarchy of directories
       
  1280 
       
  1281 TInt CreateDirectoryTree(RFs& aFs, const TPtrC* aDir)
       
  1282 	{
       
  1283 	TParse parsedPath;
       
  1284 	TBuf<KMaxFileName> newPath;
       
  1285 	TInt err, pos;
       
  1286 	TPtrC path;
       
  1287 	TPtrC fileName;
       
  1288 
       
  1289 	// check for the corectness of input parameters
       
  1290 	if (aDir == NULL )
       
  1291 		return EFalse;
       
  1292 
       
  1293 	// verify the corectness of the input path
       
  1294 	err = parsedPath.Set(*aDir, NULL, NULL);
       
  1295 	if (err != KErrNone)
       
  1296 	   return err;
       
  1297 
       
  1298 	// interatily build the path and create hierarchy of directories in file system
       
  1299 	newPath = parsedPath.Drive();
       
  1300 	newPath.Append('\\');
       
  1301 	path.Set(parsedPath.Path());
       
  1302 	path.Set(path.Mid(1));              // get rid of the first backlash
       
  1303 	while ((pos = path.Find(_L("\\"))) != KErrNotFound)
       
  1304 		{
       
  1305 		newPath.Append(path.Left(pos)); //append next directory
       
  1306 		newPath.Append('\\');
       
  1307 		err = aFs.MkDir(newPath);
       
  1308 		if (err != KErrNone) return err;
       
  1309 		path.Set(path.Mid(pos + 1));
       
  1310 		}
       
  1311 
       
  1312 	// directory created.
       
  1313 	// verify if there is a need to create a file
       
  1314 	if (parsedPath.NamePresent())
       
  1315 		{
       
  1316 		RFile file;
       
  1317 		err = file.Create(aFs, *aDir, EFileWrite);
       
  1318 		if (err != KErrNone) return err;
       
  1319 		file.Close();
       
  1320 		}
       
  1321 
       
  1322 	return KErrNone;
       
  1323 	}
       
  1324 
       
  1325 
       
  1326 //
       
  1327 // Helper method to remove a hierarchy of directories
       
  1328 TInt RemoveDirectoryTreeL(RFs& aFs, const TPtrC* aDir)
       
  1329 	{
       
  1330 	TParse parsedPath;
       
  1331 	TBuf<KMaxFileName> newPath;
       
  1332 	TInt err = KErrNone;
       
  1333 	TInt pos;
       
  1334 	TPtrC path;
       
  1335 	CFileMan *fileMan = NULL;
       
  1336 
       
  1337 	// Create FileMan.
       
  1338 	// As oposite to RFs it is able to remove a hirarchy of not empty directories
       
  1339 	TRAPD(leaveCode, fileMan = CFileMan::NewL(aFs));
       
  1340 	if (leaveCode != KErrNone)
       
  1341 		return leaveCode;
       
  1342 	CleanupStack::PushL(fileMan);
       
  1343 
       
  1344 	// verify the corectness of the input path
       
  1345 	err = parsedPath.Set(*aDir, NULL, NULL);
       
  1346 	if (err == KErrNone)
       
  1347 		{
       
  1348 		// build the path consisting only of the first level of directories hierarchy
       
  1349 		newPath = parsedPath.Drive();
       
  1350 		newPath.Append('\\');
       
  1351 		path.Set(parsedPath.Path());
       
  1352 		path.Set(path.Mid(1));  			// get rid of the first backlash
       
  1353 		if((pos = path.Find(_L("\\"))) != KErrNotFound)
       
  1354 			{
       
  1355 			newPath.Append(path.Left(pos)); //append next directory
       
  1356 			newPath.Append('\\');
       
  1357 			err = fileMan->RmDir(newPath);
       
  1358 			}
       
  1359 
       
  1360 		}
       
  1361 
       
  1362 	CleanupStack::PopAndDestroy(fileMan);
       
  1363 
       
  1364 	return err;;
       
  1365 	}
       
  1366 
       
  1367 //
       
  1368 // Helper method for TestPathExist test.
       
  1369 TBool DoTestPathExistsL(RFs& aFs, const struct TPathExistTestRecord& aTestRecord)
       
  1370 {
       
  1371 	TBool err;
       
  1372 	TInt i;
       
  1373 
       
  1374 	// 1. Create required directories (preconditions)
       
  1375 	for ( i = 0; aTestRecord.iInPaths[i] != NULL && i < PATH_EXIST_MAX_PRECONDITIONS; i++)
       
  1376 		{
       
  1377 		err = CreateDirectoryTree(aFs, aTestRecord.iInPaths[i]);
       
  1378 		if (err != KErrNone)
       
  1379 			{
       
  1380 			RDebug::Print(_L("TestPathExist(%d): Directory not created. Cause: %d"),
       
  1381 							aTestRecord.iLineNum, err);
       
  1382 
       
  1383 			// Do not break the loop here as the path might be incorrectly shaped on purpose.
       
  1384 			}
       
  1385 		}
       
  1386 
       
  1387 	// 2. Make a directory test
       
  1388 	TBool testOutcome = BaflUtils::PathExists(aFs, *aTestRecord.iTestPath);
       
  1389 
       
  1390 	// 3. Remove directories
       
  1391 	for ( i = 0; aTestRecord.iInPaths[i] != NULL && i < PATH_EXIST_MAX_PRECONDITIONS ; i++)
       
  1392 		{
       
  1393 		err = RemoveDirectoryTreeL(aFs, aTestRecord.iInPaths[i]);
       
  1394 
       
  1395 		if (err != KErrNone)
       
  1396 			{
       
  1397 			RDebug::Print(_L("TestPathExist(%d): Warning: Directory not removed. Cause: %d"),
       
  1398 							aTestRecord.iLineNum, err);
       
  1399 			}
       
  1400 		}
       
  1401 
       
  1402 	// 4. Check the results
       
  1403 	if (aTestRecord.iResult != testOutcome)
       
  1404 		{
       
  1405 		RDebug::Print(_L("TestPathExist(%d): Failed."), aTestRecord.iLineNum);
       
  1406 		return EFalse;
       
  1407 		}
       
  1408 
       
  1409 	RDebug::Print(_L("TestPathExist(%d): Passed."), aTestRecord.iLineNum);
       
  1410 	return ETrue;
       
  1411 }