os/ossrv/lowlevellibsandfws/apputils/tsrc/T_BaflUtils.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/lowlevellibsandfws/apputils/tsrc/T_BaflUtils.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1411 @@
     1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <e32test.h>
    1.20 +#include <baclipb.h>
    1.21 +#include <bautils.h>
    1.22 +#include <f32file.h>
    1.23 +#include <s32strm.h>
    1.24 +#include <s32file.h>
    1.25 +#include <e32lang.h>
    1.26 +
    1.27 +#include <fbs.h>
    1.28 +
    1.29 +
    1.30 +LOCAL_D RTest theTest(_L("T_BaflUtils"));
    1.31 +
    1.32 +const TInt KMaxDisplayedFullNameLen	= 29;
    1.33 +
    1.34 +// File names for copying
    1.35 +
    1.36 +const TPtrC KSystem1Folder				=_L("C:\\System1\\");
    1.37 +const TPtrC KSystem1Data1Folder			=_L("C:\\System1\\data1\\");
    1.38 +
    1.39 +const TPtrC KSystem1Data1File1			=_L("C:\\System1\\data1\\file1.txt");
    1.40 +const TPtrC KFile1						=_L("C:\\file1.txt");
    1.41 +const TPtrC KSystem1Data1SrcFile1		=_L("C:\\System1\\data1\\src\\file1.txt");
    1.42 +const TPtrC KSystem1Data1DstFile2		=_L("C:\\System1\\data1\\dst\\file2.txt");
    1.43 +const TPtrC KSystem1Data1File123456789	=_L("C:\\System1\\data1\\file123456789.txt");
    1.44 +const TPtrC KSystem1Data1File2			=_L("C:\\System1\\data1\\file2.txt");
    1.45 +const TPtrC KSystem1Data1File5			=_L("C:\\System1\\data1\\file5.txt");
    1.46 +const TPtrC KSystem1Data1SrcFolder		=_L("C:\\System1\\data1\\src\\");
    1.47 +const TPtrC KSystem1Data1DstFolder		=_L("C:\\System1\\data1\\dst\\");
    1.48 +
    1.49 +const TPtrC KZFile1						=_L("Z:\\file1.txt");
    1.50 +
    1.51 +// Valid Paths / Folder Name
    1.52 +const TPtrC KValidPathName=_L("C:\\System1\\Data1\\");
    1.53 +const TPtrC KValidPathNameWithoutDrive=_L("\\System1\\Data1\\");
    1.54 +const TPtrC KValidPathNameWithoutDrive2=_L("\\System1\\Data1\\file1.txt");
    1.55 +const TPtrC KValidFileName=_L("C:\\file1.txt");
    1.56 +const TPtrC KValidFileNameNoExtension=_L("C:\\file1");
    1.57 +const TPtrC KValidPathAndFileName=_L("C:\\System1\\Data1\\file1.txt");
    1.58 +const TPtrC KValidFolderName=_L("C:\\System1\\Data1\\Dst\\");
    1.59 +const TPtrC KValidDrive=_L("C:\\");
    1.60 +const TPtrC KValidDrive2=_L("C:");
    1.61 +const TPtrC KValidDrive3=_L("C");
    1.62 +const TPtrC KValidDrive4=_L("Z:\\");
    1.63 +const TPtrC KCopyFileFrom=_L("C:\\System1\\Data1\\Src\\file1.txt");
    1.64 +const TPtrC KCopyFileTo=_L("C:\\System1\\Data1\\Dst\\file1.txt");
    1.65 +const TPtrC KDeleteFile=_L("C:\\System1\\Data1\\Dst\\file1.txt");
    1.66 +const TPtrC KRenameFromFile=_L("C:\\System1\\Data1\\file2.txt");
    1.67 +const TPtrC KRenameToFile=_L("C:\\System1\\Data1\\file2New.txt");
    1.68 +const TPtrC KValFolderName=_L("ValidFolderName");
    1.69 +const TPtrC KCurrentPath=_L("C:\\System1\\Data1\\");
    1.70 +const TPtrC KNoFolderName = _L("");
    1.71 +const TPtrC KSessionRoot = _L("\\");
    1.72 +
    1.73 +// KFolderNameIsTooLong is 256 chars long
    1.74 +const TPtrC KFolderNameIsTooLong = _L("C:\\ThisFolderNameIsgoingToBeTooLongToBeCreatedOnTheSystemThisFolderNameIsgoingToBeTooLongToBeCreatedOnTheSystemThisFolderNameIsgoingToBeTooLongToBeCreatedOnTheSystemThisFolderNameIsgoingToBeTooLongToBeCreatedOnTheSystemThisFolderNameIsgoingToBeTooLongToBeC\\");
    1.75 +const TPtrC KAbbreviatesFileFrom=_L("C:\\System1\\Data1\\file5.txt");
    1.76 +const TPtrC KAbbreviatesFileFrom2=_L("C:\\System1\\Data1\\file123456789.txt");
    1.77 +
    1.78 +
    1.79 +// InValid Paths / Folder Names
    1.80 +const TPtrC KNoParameters=_L("");
    1.81 +const TPtrC KInValidParameters=_L("3: \\52324424");
    1.82 +const TPtrC KInValidPathName=_L("C:\\System1\\Data1\\InvalidPathName\\");
    1.83 +const TPtrC KInvalidFileName=_L("C:\\System1\\Data1\\thefiledoesnotexistatthislocation.txt");
    1.84 +const TPtrC KIllegalFileName=_L("C:\\System1\\Data1\\Illega<>.txt");
    1.85 +const TPtrC KIllegalFolderName=_L("C:\\System1\\Data*<\\");
    1.86 +const TPtrC KFolderNameWithWildcard=_L("C:\\System1\\data*\\");
    1.87 +const TPtrC KInValidFolderName=_L("C:\\System1\\Data1\\InValid3+FollderName");
    1.88 +const TPtrC KInValidDrive=_L("P:\\");
    1.89 +const TPtrC KAppAbbName=_L("\\System1");
    1.90 +
    1.91 +
    1.92 +//-----------------------------------------------------------------------------
    1.93 +//
    1.94 +// Timing macros.
    1.95 +//
    1.96 +//-----------------------------------------------------------------------------
    1.97 +const TInt KMaxIterations     =   100;
    1.98 +#define INCLUDE_VERBOSE
    1.99 +
   1.100 +#define TIMERINSTALL \
   1.101 +	TTime start(0); \
   1.102 +	TTime end(0);   \
   1.103 +	TUint delta = 0; \
   1.104 +	TUint cummulative = 0; \
   1.105 +	TUint iterations = 0;
   1.106 +
   1.107 +
   1.108 +#define TIMERRESET \
   1.109 +	delta = 0, cummulative = 0, iterations = 0;
   1.110 +
   1.111 +
   1.112 +#define TIMERSTART \
   1.113 +	start.UniversalTime();
   1.114 +
   1.115 +
   1.116 +#define TIMERSTOP \
   1.117 +	end.UniversalTime(); \
   1.118 +	delta = I64LOW(end.MicroSecondsFrom(start).Int64()); \
   1.119 +	iterations++; \
   1.120 +	cummulative += delta;
   1.121 +
   1.122 +
   1.123 +#ifdef INCLUDE_VERBOSE
   1.124 +_LIT(KTimerResult,   "Average time = %dus over %d iterations\n");
   1.125 +_LIT(KTimingError,   "Error - no timing results to display\n");
   1.126 +
   1.127 +
   1.128 +# define TIMERRESULT \
   1.129 +	if (iterations) \
   1.130 +		{ \
   1.131 +		theTest.Printf(KTimerResult, cummulative/iterations, iterations); \
   1.132 +		} \
   1.133 +	else \
   1.134 +		{ \
   1.135 +		theTest.Printf(KTimingError); \
   1.136 +		}
   1.137 +
   1.138 +#else
   1.139 +# define TIMERRESULT
   1.140 +#endif
   1.141 +
   1.142 +
   1.143 +#define TIMERAVERAGE \
   1.144 +		(iterations ? cummulative/iterations : 0xFFFFFFFF)
   1.145 +//-----------------------------------------------------------------------------
   1.146 +
   1.147 +
   1.148 +//
   1.149 +//BaflUtils::GetEquivalentLanguageList
   1.150 +//BaflUtils::NearestLanguageFileV2 
   1.151 +//test data
   1.152 +_LIT (KNullFilename, "");
   1.153 +_LIT (KRscFilename,  "C:\\geltest.rsc");
   1.154 +_LIT (KRscFilenameNoSuffix,  "C:\\geltest.");
   1.155 +
   1.156 +_LIT (KAmericanLang, "C:\\geltest.r10");
   1.157 +_LIT (KFrenchLang,   "C:\\geltest.r02");
   1.158 +_LIT (KJapanEnglishLang, "C:\\geltest.r160");
   1.159 +_LIT (KEnglishLang, "C:\\geltest.r01");
   1.160 +_LIT (KInvalidDriveLetterV2, "q:\\geltest.rsc");
   1.161 +_LIT (KNoSuchLangFile, "c:\\geltest.r54");
   1.162 +
   1.163 +//
   1.164 +//BaflUtils::PathExist test data
   1.165 +
   1.166 +// Defines the maximum number of preconditions for each test case.
   1.167 +#define PATH_EXIST_MAX_PRECONDITIONS 1
   1.168 +
   1.169 +// Literals for PathExist testing
   1.170 +const TPtrC KPathExistValid = _L("C:\\ValidPath\\Data1\\");
   1.171 +const TPtrC KPathExistInValid = _L("C:\\ValidPath\\Data1\\InvalidPathName\\");
   1.172 +const TPtrC KPathExistFullFile = _L("C:\\ValidPath\\Data1\\file1.txt");
   1.173 +
   1.174 +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\\");
   1.175 +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\\");
   1.176 +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\\");
   1.177 +
   1.178 +const TPtrC KPathExistShort = _L("c:\\10Letters\\10Letters\\");
   1.179 +const TPtrC KPathExistShortT1 = _L("c:\\10Letters\\10Letters");
   1.180 +const TPtrC KPathExistShortT2 = _L("c:\\10Letters\\10*\\");
   1.181 +const TPtrC KPathExistShortT3 = _L("c:\\10Letters\\10Letter?\\");
   1.182 +
   1.183 +const TPtrC KPathExistSessionPath = _L("c:\\");
   1.184 +const TPtrC KPathExistRelativeT1 = _L("\\10Letters");
   1.185 +const TPtrC KPathExistRelativeT2 = _L("\\10Letters\\");
   1.186 +const TPtrC KPathExistRelativeT3 = _L("10Letters\\");
   1.187 +
   1.188 +struct TPathExistTestRecord
   1.189 +// Defines the test case structure for PathExist unit testing
   1.190 +{
   1.191 +	// precondititions, directories to create before test run
   1.192 +	const TPtrC *iInPaths[PATH_EXIST_MAX_PRECONDITIONS];
   1.193 +
   1.194 +	// the directory to test for
   1.195 +	const TPtrC  *iTestPath;
   1.196 +
   1.197 +	// expected results
   1.198 +	TBool iResult;
   1.199 +
   1.200 +	// test case line number for quick test identification
   1.201 +	TInt iLineNum;
   1.202 +};
   1.203 +
   1.204 +LOCAL_D const TPathExistTestRecord pathExistTestCases[] =
   1.205 +// Test cases for PathExist unit testing
   1.206 +{
   1.207 +	{{&KPathExistValid}, &KPathExistValid, ETrue, 		__LINE__},
   1.208 +	{{&KPathExistValid}, &KPathExistInValid, EFalse, 	__LINE__},
   1.209 +	{{&KPathExistFullFile}, &KPathExistFullFile, EFalse,__LINE__},
   1.210 +	{{}, &KInValidParameters, EFalse, 					__LINE__},
   1.211 +	{{}, &KInValidFolderName, EFalse, 					__LINE__},
   1.212 +	{{}, &KValidDrive2, EFalse, 						__LINE__},
   1.213 +	{{}, &KNoParameters, EFalse, 						__LINE__},
   1.214 +
   1.215 +	{{&KPathExistShort}, &KPathExistShort, ETrue, 		__LINE__},
   1.216 +	{{&KPathExistShort}, &KPathExistShortT1, EFalse, 	__LINE__},
   1.217 +	{{&KPathExistShort}, &KPathExistShortT2, EFalse, 	__LINE__},
   1.218 +	{{&KPathExistShort}, &KPathExistShortT3, EFalse, 	__LINE__},
   1.219 +	{{&KPathExistShort}, &KPathExistRelativeT1, EFalse, __LINE__},
   1.220 +	{{&KPathExistShort}, &KPathExistRelativeT2, EFalse, __LINE__},
   1.221 +	{{&KPathExistShort}, &KPathExistRelativeT3, EFalse, __LINE__},
   1.222 +
   1.223 +#if !defined __WINS__ && !defined __WINSCW__
   1.224 +
   1.225 +// max boundary tests - can only be tested on hardware
   1.226 +
   1.227 +	{{&KPathExist255}, &KPathExist255, ETrue, 			__LINE__},
   1.228 +	{{&KPathExist256}, &KPathExist256, ETrue, 			__LINE__},
   1.229 +	{{&KPathExist257}, &KPathExist257, EFalse, 			__LINE__},
   1.230 +
   1.231 +#endif //!defined __WINS__ && !defined __WINSCW__
   1.232 +
   1.233 +	{{}, NULL, ETrue} // mandatory, last element
   1.234 +};
   1.235 +
   1.236 +TBool DoTestPathExistsL(RFs& aFs, const struct TPathExistTestRecord& aTestRecord);
   1.237 +
   1.238 +//
   1.239 +//Create/Destroy test environment global functions
   1.240 +
   1.241 +//Delete "aFullName" file.
   1.242 +LOCAL_C void DeleteTestFile(const TDesC& aFullName)
   1.243 +	{
   1.244 +	RFs fsSession;
   1.245 +	TInt err = fsSession.Connect();
   1.246 +	if(err == KErrNone)
   1.247 +		{
   1.248 +		TEntry entry;
   1.249 +		if(fsSession.Entry(aFullName, entry) == KErrNone)
   1.250 +			{
   1.251 +			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
   1.252 +			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
   1.253 +			if(err != KErrNone)
   1.254 +				{
   1.255 +				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
   1.256 +				}
   1.257 +			err = fsSession.Delete(aFullName);
   1.258 +			if(err != KErrNone)
   1.259 +				{
   1.260 +				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
   1.261 +				}
   1.262 +			}
   1.263 +		fsSession.Close();
   1.264 +		}
   1.265 +	else
   1.266 +		{
   1.267 +		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
   1.268 +		}
   1.269 +	}
   1.270 +
   1.271 +//Delete "aFullName" dir.
   1.272 +LOCAL_C void DeleteTestDir(const TDesC& aFullName)
   1.273 +	{
   1.274 +	RFs fsSession;
   1.275 +	TInt err = fsSession.Connect();
   1.276 +	if(err == KErrNone)
   1.277 +		{
   1.278 +		TEntry entry;
   1.279 +		if(fsSession.Entry(aFullName, entry) == KErrNone)
   1.280 +			{
   1.281 +			RDebug::Print(_L("Deleting \"%S\" dir.\n"), &aFullName);
   1.282 +			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
   1.283 +			if(err != KErrNone)
   1.284 +				{
   1.285 +				RDebug::Print(_L("Error %d changing \"%S\" dir attributes.\n"), err, &aFullName);
   1.286 +				}
   1.287 +			err = fsSession.RmDir(aFullName);
   1.288 +			if(err != KErrNone)
   1.289 +				{
   1.290 +				RDebug::Print(_L("Error %d deleting \"%S\" dir.\n"), err, &aFullName);
   1.291 +				}
   1.292 +			}
   1.293 +		fsSession.Close();
   1.294 +		}
   1.295 +	else
   1.296 +		{
   1.297 +		RDebug::Print(_L("Error %d connecting file session. Dir: %S.\n"), err, &aFullName);
   1.298 +		}
   1.299 +	}
   1.300 +
   1.301 +//Delete data files used by the test
   1.302 +LOCAL_C void DeleteTestFiles()
   1.303 +	{
   1.304 +		DeleteTestFile(KSystem1Data1File1);
   1.305 +		DeleteTestFile(KFile1);
   1.306 +		DeleteTestFile(KSystem1Data1SrcFile1);
   1.307 +		DeleteTestFile(KSystem1Data1DstFile2);
   1.308 +		DeleteTestFile(KSystem1Data1File123456789);
   1.309 +		DeleteTestFile(KSystem1Data1File2);
   1.310 +		DeleteTestFile(KSystem1Data1File5);
   1.311 +		DeleteTestDir(KSystem1Data1SrcFolder);
   1.312 +		DeleteTestDir(KSystem1Data1DstFolder);
   1.313 +		DeleteTestDir(KSystem1Data1Folder);
   1.314 +		DeleteTestDir(KSystem1Folder);
   1.315 +	}
   1.316 +
   1.317 +//
   1.318 +//Test macroses and functions
   1.319 +LOCAL_C void Check(TInt aValue, TInt aLine)
   1.320 +	{
   1.321 +	if(!aValue)
   1.322 +		{
   1.323 +		::DeleteTestFiles();
   1.324 +		theTest(EFalse, aLine);
   1.325 +		}
   1.326 +	}
   1.327 +LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
   1.328 +	{
   1.329 +	if(aValue != aExpected)
   1.330 +		{
   1.331 +		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
   1.332 +		::DeleteTestFiles();
   1.333 +		theTest(EFalse, aLine);
   1.334 +		}
   1.335 +	}
   1.336 +#define TEST(arg) ::Check((arg), __LINE__)
   1.337 +#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
   1.338 +
   1.339 +
   1.340 +LOCAL_C void DeleteTestFiles2(RFs &aFs)
   1.341 +{
   1.342 +	BaflUtils::DeleteFile (aFs, KRscFilename);
   1.343 +	BaflUtils::DeleteFile (aFs, KAmericanLang);
   1.344 +	BaflUtils::DeleteFile (aFs, KFrenchLang);
   1.345 +	BaflUtils::DeleteFile (aFs, KJapanEnglishLang);
   1.346 +	BaflUtils::DeleteFile (aFs, KEnglishLang);
   1.347 +}
   1.348 +
   1.349 +LOCAL_C void CreateTestFiles2(RFs &aFs)
   1.350 +{
   1.351 +	TEST (BaflUtils::FileExists (aFs, KRscFilename) == EFalse);
   1.352 +	TEST (BaflUtils::FileExists (aFs, KAmericanLang) == EFalse);
   1.353 +	TEST (BaflUtils::FileExists (aFs, KFrenchLang) == EFalse);
   1.354 +	TEST (BaflUtils::FileExists (aFs, KJapanEnglishLang) == EFalse);
   1.355 +	TEST (BaflUtils::FileExists (aFs, KEnglishLang) == EFalse);
   1.356 +
   1.357 +	// Create the files...
   1.358 +	RFile rFile;
   1.359 +	TEST (KErrNone == rFile.Create (aFs, KRscFilename, EFileRead));
   1.360 +	rFile.Close ();
   1.361 +	TEST (KErrNone == rFile.Create (aFs, KAmericanLang, EFileRead));
   1.362 +	rFile.Close ();
   1.363 +	TEST (KErrNone == rFile.Create (aFs, KFrenchLang, EFileRead));
   1.364 +	rFile.Close ();
   1.365 +	TEST (KErrNone == rFile.Create (aFs, KEnglishLang, EFileRead));
   1.366 +	rFile.Close ();
   1.367 +}
   1.368 +//
   1.369 +//Copy test file from Z: to C: drive.
   1.370 +
   1.371 +LOCAL_C void CopyTestFiles()
   1.372 +	{
   1.373 +	RFs fsSession;
   1.374 +	TInt err = fsSession.Connect();
   1.375 +	if(err == KErrNone)
   1.376 +		{
   1.377 +		User::LeaveIfError(fsSession.MkDir(KSystem1Folder));
   1.378 +		User::LeaveIfError(fsSession.MkDir(KSystem1Data1Folder));
   1.379 +		TEST2( BaflUtils::CopyFile(fsSession, KZFile1, KSystem1Data1File1), KErrNone);
   1.380 +		TEST2( BaflUtils::CopyFile(fsSession, KZFile1, KFile1), KErrNone);
   1.381 +		TEST2( BaflUtils::CopyFile(fsSession, KZFile1, KSystem1Data1File123456789), KErrNone);
   1.382 +		TEST2( BaflUtils::CopyFile(fsSession, KZFile1, KSystem1Data1File2), KErrNone);
   1.383 +		TEST2( BaflUtils::CopyFile(fsSession, KZFile1, KSystem1Data1File5), KErrNone);
   1.384 +		User::LeaveIfError(fsSession.MkDir(KSystem1Data1SrcFolder));
   1.385 +		User::LeaveIfError(fsSession.MkDir(KSystem1Data1DstFolder));
   1.386 +		TEST2( BaflUtils::CopyFile(fsSession, KZFile1, KSystem1Data1SrcFile1), KErrNone);
   1.387 +		TEST2( BaflUtils::CopyFile(fsSession, KZFile1, KSystem1Data1DstFile2), KErrNone);
   1.388 +
   1.389 +		fsSession.Close();
   1.390 +		}
   1.391 +	else
   1.392 +		{
   1.393 +		RDebug::Print(_L("Error %d connecting file session.\n"), err);
   1.394 +		}
   1.395 +	}
   1.396 +
   1.397 +
   1.398 +
   1.399 +//
   1.400 +
   1.401 +/**
   1.402 +@SYMTestCaseID SYSLIB-BAFL-CT-1571
   1.403 +@SYMTestCaseDesc Tests BaflUtils::PersistHAL()
   1.404 +@SYMTestPriority Medium
   1.405 +@SYMTestActions It starts halsetting.exe and persist hal settings
   1.406 +@SYMTestExpectedResults The test must not fail.
   1.407 +@SYMDEF DEF083235 	Prop: HAL Attributes (eg screen calibration) lost if the battery is pulled out
   1.408 +*/
   1.409 +void TestPersistHAL()
   1.410 +	{
   1.411 +	TEST (BaflUtils::PersistHAL() == KErrNone);
   1.412 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-1571 "));
   1.413 +	theTest.Printf(_L("BaflUtils::PersistHAL() called"));
   1.414 +	}
   1.415 +
   1.416 +/**
   1.417 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0001
   1.418 +@SYMTestCaseDesc Tests Baflutils::EnsurePathExists.
   1.419 +@SYMTestPriority Medium
   1.420 +@SYMTestActions Passes in existing and non-existing pathnames and removes any directories created.
   1.421 +@SYMTestExpectedResults The test must not fail.
   1.422 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.423 +*/
   1.424 +void TestEnsurePathExistsL(RFs& aFs)
   1.425 +	{
   1.426 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0001 "));
   1.427 +	CleanupClosePushL(aFs);
   1.428 +	User::LeaveIfError(aFs.Connect());
   1.429 +
   1.430 +	// Path already exists so -11 will be returned within EnsurePathExistsL, Method Leaves with error code 0
   1.431 +	TRAPD(err, BaflUtils::EnsurePathExistsL(aFs, KValidPathName));
   1.432 +	TEST(!err);
   1.433 +	// Path does not exist so -12 will be returned within EnsurePathExistsL, The Directory will be created, Method Leaves with error code 0
   1.434 +	TRAPD(err2, BaflUtils::EnsurePathExistsL(aFs, KInValidPathName));
   1.435 +	TEST(!err2);
   1.436 +	TEST(!aFs.RmDir(KInValidPathName));
   1.437 +
   1.438 +	CleanupStack::PopAndDestroy(&aFs);
   1.439 +	}
   1.440 +
   1.441 +/**
   1.442 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0002
   1.443 +@SYMTestCaseDesc Tests Baflutils::TestFileExists.
   1.444 +@SYMTestPriority Medium
   1.445 +@SYMTestActions Passes in valid and invalid files.
   1.446 +@SYMTestExpectedResults The test must not fail.
   1.447 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.448 +*/
   1.449 +void TestFileExists(RFs& aFs)
   1.450 +	{
   1.451 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0002 "));
   1.452 +	CleanupClosePushL(aFs);
   1.453 +	User::LeaveIfError(aFs.Connect());
   1.454 +
   1.455 +	TEST (BaflUtils::FileExists(aFs,KValidPathAndFileName));
   1.456 +	TEST (!BaflUtils::FileExists(aFs,KInvalidFileName));
   1.457 +
   1.458 +	CleanupStack::PopAndDestroy(&aFs);
   1.459 +	}
   1.460 +
   1.461 +/**
   1.462 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0003
   1.463 +@SYMTestCaseDesc Tests Baflutils::TestFolderExists.
   1.464 +@SYMTestPriority Medium
   1.465 +@SYMTestActions Passes in valid and invalid folders.
   1.466 +@SYMTestExpectedResults The test must not fail.
   1.467 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.468 +*/
   1.469 +void TestFolderExists(RFs& aFs)
   1.470 +	{
   1.471 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0003 "));
   1.472 +	CleanupClosePushL(aFs);
   1.473 +	User::LeaveIfError(aFs.Connect());
   1.474 +
   1.475 +	TInt x = KMaxIterations;
   1.476 +
   1.477 +	TIMERINSTALL
   1.478 +
   1.479 +	while (x--)
   1.480 +	{
   1.481 +		TIMERSTART
   1.482 +		TEST(BaflUtils::FolderExists(aFs, KValidPathName));
   1.483 +		TEST(BaflUtils::FolderExists(aFs, KValidFileName));
   1.484 +		TEST(BaflUtils::FolderExists(aFs, KValidFileNameNoExtension));
   1.485 +	 	TEST(BaflUtils::FolderExists(aFs, KValidPathAndFileName));
   1.486 +	 	TEST(BaflUtils::FolderExists(aFs, KValidPathNameWithoutDrive));
   1.487 +	 	TEST(BaflUtils::FolderExists(aFs, KValidPathNameWithoutDrive2));
   1.488 +	 	TEST(BaflUtils::FolderExists(aFs, KValidDrive));
   1.489 +	 	TEST(BaflUtils::FolderExists(aFs, KValidDrive4));
   1.490 +	 	TEST(BaflUtils::FolderExists(aFs, KSessionRoot));
   1.491 +	 	TIMERSTOP
   1.492 +	}
   1.493 +
   1.494 +	theTest.Printf(_L("\nBenchmark results for FolderExists tests returning ETrue:\n"));
   1.495 +	TIMERRESULT
   1.496 +
   1.497 +	TIMERRESET
   1.498 +	x = KMaxIterations;
   1.499 +
   1.500 +	while (x--)
   1.501 +	{
   1.502 +		TIMERSTART
   1.503 +		TEST(!BaflUtils::FolderExists(aFs, KInValidPathName));
   1.504 +		TEST(!BaflUtils::FolderExists(aFs, KNoFolderName));
   1.505 +		TEST(!BaflUtils::FolderExists(aFs, KFolderNameIsTooLong));
   1.506 +	 	TEST(!BaflUtils::FolderExists(aFs, KIllegalFileName));
   1.507 +	 	TEST(!BaflUtils::FolderExists(aFs, KIllegalFolderName));
   1.508 +	 	TEST(!BaflUtils::FolderExists(aFs, KFolderNameWithWildcard));
   1.509 +		TIMERSTOP
   1.510 +	}
   1.511 +
   1.512 +	theTest.Printf(_L("\nBenchmark results for FolderExists tests returning EFalse:\n"));
   1.513 +	TIMERRESULT
   1.514 +	theTest.Printf(_L("\n"));
   1.515 +
   1.516 +	CleanupStack::PopAndDestroy(&aFs);
   1.517 +	}
   1.518 +
   1.519 +/**
   1.520 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0004
   1.521 +@SYMTestCaseDesc Tests Baflutils::TestPathExists.
   1.522 +@SYMTestPriority Medium
   1.523 +@SYMTestActions Passes in valid and invalid paths.
   1.524 +@SYMTestExpectedResults The test must not fail.
   1.525 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.526 +@SYMDEF INC084050 - BaflUtils::PathExists does not work for 256 long folder paths
   1.527 +*/
   1.528 +void TestPathExistsL(RFs& aFs)
   1.529 +	{
   1.530 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0004 "));
   1.531 +	CleanupClosePushL(aFs);
   1.532 +
   1.533 +	User::LeaveIfError(aFs.Connect());
   1.534 +	aFs.SetSessionPath(KPathExistSessionPath);
   1.535 +
   1.536 +	for (TInt i = 0; pathExistTestCases[i].iTestPath != NULL; i++)
   1.537 +		TEST(DoTestPathExistsL(aFs,pathExistTestCases[i]));
   1.538 +
   1.539 +	CleanupStack::PopAndDestroy(&aFs);
   1.540 +	}
   1.541 +
   1.542 +/**
   1.543 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0005
   1.544 +@SYMTestCaseDesc Tests Baflutils::TestCopyFile.
   1.545 +@SYMTestPriority Medium
   1.546 +@SYMTestActions Copy's a file from one location to another.
   1.547 +@SYMTestExpectedResults The test must not fail.
   1.548 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.549 +*/
   1.550 +void TestCopyFile(RFs& aFs)
   1.551 +	{
   1.552 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0005 "));
   1.553 +	CleanupClosePushL(aFs);
   1.554 +	User::LeaveIfError(aFs.Connect());
   1.555 +
   1.556 +	TEST(!BaflUtils::CopyFile(aFs, KCopyFileFrom, KCopyFileTo));
   1.557 +
   1.558 +	CleanupStack::PopAndDestroy(&aFs);
   1.559 +	}
   1.560 +
   1.561 +/**
   1.562 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0006
   1.563 +@SYMTestCaseDesc Tests Baflutils::TestDeleteFile.
   1.564 +@SYMTestPriority Medium
   1.565 +@SYMTestActions Attempts to delete a file after setting its atributes 'Read Only'.
   1.566 +@SYMTestExpectedResults The test must not fail.
   1.567 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.568 +*/
   1.569 +void TestDeleteFile(RFs& aFs)
   1.570 +	{
   1.571 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0006 "));
   1.572 +	CleanupClosePushL(aFs);
   1.573 +	User::LeaveIfError(aFs.Connect());
   1.574 +
   1.575 +	TEST(!aFs.SetAtt(KDeleteFile, 0, KEntryAttReadOnly));
   1.576 +	TEST(!BaflUtils::DeleteFile(aFs, KDeleteFile));
   1.577 +
   1.578 +	CleanupStack::PopAndDestroy(&aFs);
   1.579 +	}
   1.580 +
   1.581 +/**
   1.582 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0007
   1.583 +@SYMTestCaseDesc Tests Baflutils::TestRenameFile.
   1.584 +@SYMTestPriority Medium
   1.585 +@SYMTestActions Attempts to rename or move files or directories.
   1.586 +@SYMTestExpectedResults The test must not fail.
   1.587 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.588 +*/
   1.589 +void TestRenameFile(RFs& aFs)
   1.590 +	{
   1.591 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0007 "));
   1.592 +	// Pushes aFs to the stack.
   1.593 +	CleanupClosePushL(aFs);
   1.594 +	// Open Session with the File Server
   1.595 +	User::LeaveIfError(aFs.Connect());
   1.596 +
   1.597 +	TUint theSwitch = CFileMan::EOverWrite;
   1.598 +
   1.599 +	// Renames or moves one or more files or directories.
   1.600 +	TEST2(BaflUtils::RenameFile(aFs, KRenameFromFile, KRenameToFile, theSwitch), KErrNone);
   1.601 +
   1.602 +	//Rename file back to original name
   1.603 +	TEST2(BaflUtils::RenameFile(aFs, KRenameToFile, KRenameFromFile, theSwitch), KErrNone);
   1.604 +	// Pops aFs from the stack
   1.605 +	CleanupStack::PopAndDestroy(&aFs);
   1.606 +	}
   1.607 +
   1.608 +/**
   1.609 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0008
   1.610 +@SYMTestCaseDesc Tests Baflutils::TestAbbreviateFileName.
   1.611 +@SYMTestPriority Medium
   1.612 +@SYMTestActions Checks if filename is being abbreviated correctly.
   1.613 +@SYMTestExpectedResults The test must not fail.
   1.614 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.615 +*/
   1.616 +void TestAbbreviateFileName()
   1.617 +	{
   1.618 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0008 "));
   1.619 +	TFileName originalFileName(KAbbreviatesFileFrom);
   1.620 +	TBuf<KMaxDisplayedFullNameLen> abbrevName;
   1.621 +
   1.622 +	BaflUtils::AbbreviateFileName (originalFileName.Left(29), abbrevName);
   1.623 +	TEST(!originalFileName.Compare(abbrevName));
   1.624 +	originalFileName.Copy(KAbbreviatesFileFrom2);
   1.625 +	BaflUtils::AbbreviateFileName (originalFileName.Left(39), abbrevName);
   1.626 +	TEST(originalFileName.Compare(abbrevName)<0);
   1.627 +	}
   1.628 +
   1.629 +/**
   1.630 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0009
   1.631 +@SYMTestCaseDesc Tests Baflutils::TestCheckWhetherFullNameRefersToFolder.
   1.632 +@SYMTestPriority Medium
   1.633 +@SYMTestActions Passes in paths with valid and invalid folder names.
   1.634 +@SYMTestExpectedResults The test must not fail.
   1.635 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.636 +*/
   1.637 +void TestCheckWhetherFullNameRefersToFolder()
   1.638 +	{
   1.639 +	TBool folder=EFalse;
   1.640 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0009 "));
   1.641 +
   1.642 +	TEST(!BaflUtils::CheckWhetherFullNameRefersToFolder(KValidFolderName, folder));
   1.643 +    TEST(folder);
   1.644 +	folder=EFalse;
   1.645 +	TEST(!BaflUtils::CheckWhetherFullNameRefersToFolder(KInValidFolderName, folder));
   1.646 +    TEST(!folder);
   1.647 +	}
   1.648 +
   1.649 +/**
   1.650 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0010
   1.651 +@SYMTestCaseDesc Tests Baflutils::TestCopyWithTruncation.
   1.652 +@SYMTestPriority Medium
   1.653 +@SYMTestActions Passes in truncated and non-truncated descriptors and checks return codes.
   1.654 +@SYMTestExpectedResults The test must not fail.
   1.655 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.656 +*/
   1.657 +void TestCopyWithTruncation()
   1.658 +	{
   1.659 +	_LIT(KDestDataNoneTruncation,"TestCopyWithNoneTruncation");
   1.660 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0010 "));
   1.661 +	TBuf<26> dest;
   1.662 +	TBuf<30> src(KDestDataNoneTruncation);
   1.663 +	TChar truncationSymbol = KBaflCharTruncation;
   1.664 +	BaflUtils::CopyWithTruncation(dest, src, truncationSymbol);
   1.665 +	TEST(dest.Locate(KBaflCharTruncation)==KErrNotFound);
   1.666 +
   1.667 +	_LIT(KDestDataTruncation,"TestCopyWithTruncationLeftMost");
   1.668 +	src.Copy(KDestDataTruncation);
   1.669 +	BaflUtils::CopyWithTruncation(dest, src, truncationSymbol);
   1.670 +	TEST(dest.Locate(KBaflCharTruncation)==25);
   1.671 +	}
   1.672 +
   1.673 +/**
   1.674 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0011
   1.675 +@SYMTestCaseDesc Tests Baflutils::TestDriveAndPathFromFullName.
   1.676 +@SYMTestPriority Medium
   1.677 +@SYMTestActions Passes in a valid filename and compares the result.
   1.678 +@SYMTestExpectedResults The test must not fail.
   1.679 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.680 +*/
   1.681 +void TestDriveAndPathFromFullName()
   1.682 +	{
   1.683 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0011 "));
   1.684 +	TFileName fileName = BaflUtils::DriveAndPathFromFullName(KValidPathName);
   1.685 +	TEST(!KValidPathName.Compare(fileName));
   1.686 +	}
   1.687 +
   1.688 +/**
   1.689 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0012
   1.690 +@SYMTestCaseDesc Tests Baflutils::TestFolderNameFromFullName.
   1.691 +@SYMTestPriority Medium
   1.692 +@SYMTestActions Passes in various valid path, file and drive names and compares results with descriptors.
   1.693 +@SYMTestExpectedResults The test must not fail.
   1.694 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.695 +*/
   1.696 +void TestFolderNameFromFullName()
   1.697 +	{
   1.698 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0012 "));
   1.699 +	TFileName fileName =  BaflUtils::FolderNameFromFullName(KValidPathAndFileName);
   1.700 +	TEST(!fileName.Compare(_L("Data1")));
   1.701 +
   1.702 +	fileName =  BaflUtils::FolderNameFromFullName( KValidFileName);
   1.703 +	TEST(!fileName.Compare(_L("C:\\")));
   1.704 +
   1.705 +	fileName =  BaflUtils::FolderNameFromFullName(KValidDrive);
   1.706 +	TEST(!fileName.Compare(_L("C:\\")));
   1.707 +
   1.708 +	fileName =  BaflUtils::FolderNameFromFullName(KValidDrive2);
   1.709 +	TEST(!fileName.Compare(_L("C:")));
   1.710 +	}
   1.711 +
   1.712 +/**
   1.713 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0013
   1.714 +@SYMTestCaseDesc Tests Baflutils::TestMostSignificantPartOfFullName.
   1.715 +@SYMTestPriority Medium
   1.716 +@SYMTestActions Passes in valid path and file names and compares results with descriptors.
   1.717 +@SYMTestExpectedResults The test must not fail.
   1.718 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.719 +*/
   1.720 +void TestMostSignificantPartOfFullName()
   1.721 +	{
   1.722 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0013 "));
   1.723 +	TFileName mostSignificantPart;
   1.724 +
   1.725 +	TEST(!BaflUtils::MostSignificantPartOfFullName(KValidPathName, mostSignificantPart));
   1.726 +	TEST(!mostSignificantPart.Compare(_L("Data1")));
   1.727 +	TEST(!BaflUtils::MostSignificantPartOfFullName(KValidPathAndFileName, mostSignificantPart));
   1.728 +	TEST(!mostSignificantPart.Compare(_L("file1.txt")));
   1.729 +	}
   1.730 +
   1.731 +/**
   1.732 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0014
   1.733 +@SYMTestCaseDesc Tests Baflutils::TestParse.
   1.734 +@SYMTestPriority Medium
   1.735 +@SYMTestActions Passes in valid path and file name.
   1.736 +@SYMTestExpectedResults The test must not fail.
   1.737 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.738 +*/
   1.739 +void TestParse()
   1.740 +	{
   1.741 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0014 "));
   1.742 +	TEST(!BaflUtils::Parse(KValidPathAndFileName));
   1.743 +	}
   1.744 +
   1.745 +/**
   1.746 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0015
   1.747 +@SYMTestCaseDesc Tests Baflutils::TestRootFolderPath.
   1.748 +@SYMTestPriority Medium
   1.749 +@SYMTestActions Passes in valid drive and compares against expected output.
   1.750 +@SYMTestExpectedResults The test must not fail.
   1.751 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.752 +*/
   1.753 +void TestRootFolderPath()
   1.754 +	{
   1.755 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0015 "));
   1.756 +	TFileName fileName = BaflUtils::RootFolderPath(KValidDrive3);
   1.757 +	TEST(!fileName.Compare(_L("C:\\")));
   1.758 +	}
   1.759 +
   1.760 +/**
   1.761 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0016
   1.762 +@SYMTestCaseDesc Tests Baflutils::TestValidateFolderNameTypedByUserL.
   1.763 +@SYMTestPriority Medium
   1.764 +@SYMTestActions Passes in various folder names and checks return values are as expected.
   1.765 +@SYMTestExpectedResults The test must not fail.
   1.766 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.767 +*/
   1.768 +void TestValidateFolderNameTypedByUserL(RFs& aFs)
   1.769 +	{
   1.770 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0016 "));
   1.771 +	CleanupClosePushL(aFs);
   1.772 +	User::LeaveIfError(aFs.Connect());
   1.773 +
   1.774 +	TInt retCode=KErrNone;
   1.775 +	retCode=retCode;
   1.776 +	TFileName newFolderFullName = KCurrentPath;
   1.777 +
   1.778 +	TEST(User::LeaveIfError(retCode=BaflUtils::ValidateFolderNameTypedByUserL(aFs, KValFolderName, KCurrentPath, newFolderFullName)==KErrNone));
   1.779 +	TEST(User::LeaveIfError(retCode=BaflUtils::ValidateFolderNameTypedByUserL(aFs, KNoFolderName, KCurrentPath, newFolderFullName)==KErrArgument));
   1.780 +	TEST(User::LeaveIfError(retCode=BaflUtils::ValidateFolderNameTypedByUserL(aFs, KInValidFolderName, KCurrentPath, newFolderFullName)==KErrBadName));
   1.781 +
   1.782 +	CleanupStack::PopAndDestroy(&aFs);
   1.783 +	}
   1.784 +
   1.785 +/**
   1.786 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0017
   1.787 +@SYMTestCaseDesc Tests Baflutils::TestRemoveSystemDirectory.
   1.788 +@SYMTestPriority Medium
   1.789 +@SYMTestActions Delete system directory.
   1.790 +@SYMTestExpectedResults The test must not fail.
   1.791 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.792 +*/
   1.793 +void TestRemoveSystemDirectory(RFs& aFs)
   1.794 +	{
   1.795 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0017 "));
   1.796 +	CleanupClosePushL(aFs);
   1.797 +	User::LeaveIfError(aFs.Connect());
   1.798 +
   1.799 +	CDir* theDir = NULL;
   1.800 +	CDir* fileList = NULL;
   1.801 +
   1.802 +	TInt attribs=KEntryAttDir|KEntryAttSystem|KEntryAttMatchExclusive;
   1.803 +	aFs.GetDir(_L("z:\\system"),attribs,ESortNone, fileList, theDir);
   1.804 +	TInt theNumber = theDir -> Count();
   1.805 +	TEST(theNumber == 1);
   1.806 +	BaflUtils::RemoveSystemDirectory(*theDir);
   1.807 +	theNumber = theDir -> Count();
   1.808 +	TEST(!theNumber);
   1.809 +
   1.810 +	delete fileList;
   1.811 +	delete theDir;
   1.812 +	CleanupStack::PopAndDestroy(&aFs);
   1.813 +	}
   1.814 +
   1.815 +/**
   1.816 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0018
   1.817 +@SYMTestCaseDesc Tests Baflutils::TestCheckFolder.
   1.818 +@SYMTestPriority Medium
   1.819 +@SYMTestActions Pass in various path, file and drive names.
   1.820 +@SYMTestExpectedResults The test must not fail.
   1.821 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.822 +*/
   1.823 +void TestCheckFolder(RFs& aFs)
   1.824 +	{
   1.825 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0018 "));
   1.826 +	CleanupClosePushL(aFs);
   1.827 +	User::LeaveIfError(aFs.Connect());
   1.828 +
   1.829 +	TEST(!BaflUtils::CheckFolder(aFs, KValidPathName));
   1.830 +	TEST(!BaflUtils::CheckFolder(aFs, KValidPathAndFileName));
   1.831 +
   1.832 +	TEST(!BaflUtils::CheckFolder(aFs, KValidFileName));
   1.833 +
   1.834 +	TEST(!BaflUtils::CheckFolder(aFs, KValidDrive));
   1.835 +	TEST(BaflUtils::CheckFolder(aFs, KInValidPathName));
   1.836 +
   1.837 +	CleanupStack::PopAndDestroy(&aFs);
   1.838 +	}
   1.839 +
   1.840 +/**
   1.841 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0019
   1.842 +@SYMTestCaseDesc Tests Baflutils::TestDiskIsReadOnly.
   1.843 +@SYMTestPriority Medium
   1.844 +@SYMTestActions Pass in various drives and parameters and checks 'Read Only' status.
   1.845 +@SYMTestExpectedResults The test must not fail.
   1.846 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.847 +*/
   1.848 +void TestDiskIsReadOnly(RFs& aFs)
   1.849 +	{
   1.850 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0019 "));
   1.851 +	CleanupClosePushL(aFs);
   1.852 +	User::LeaveIfError(aFs.Connect());
   1.853 +
   1.854 +	TBool isReadOnly = EFalse;
   1.855 +
   1.856 +	TEST(!BaflUtils::DiskIsReadOnly(aFs, KValidPathName, isReadOnly));
   1.857 +	TEST(!isReadOnly);
   1.858 +	TEST(!BaflUtils::DiskIsReadOnly(aFs, KValidDrive4, isReadOnly));
   1.859 +	TEST(isReadOnly);
   1.860 +	TEST(BaflUtils::DiskIsReadOnly(aFs, KInValidDrive, isReadOnly));
   1.861 +	TEST(isReadOnly);
   1.862 +	TEST(BaflUtils::DiskIsReadOnly(aFs, KNoParameters, isReadOnly));
   1.863 +	TEST(isReadOnly);
   1.864 +	TEST(BaflUtils::DiskIsReadOnly(aFs, KInValidParameters, isReadOnly));
   1.865 +	TEST(isReadOnly);
   1.866 +
   1.867 +	CleanupStack::PopAndDestroy(&aFs);
   1.868 +	}
   1.869 +
   1.870 +/**
   1.871 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0020
   1.872 +@SYMTestCaseDesc Tests Baflutils::TestExtractAppNameFromFullName.
   1.873 +@SYMTestPriority Medium
   1.874 +@SYMTestActions Compares thread name to both valid and invalid application names.
   1.875 +@SYMTestExpectedResults The test must not fail.
   1.876 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.877 +*/
   1.878 +void TestExtractAppNameFromFullName()
   1.879 +	{
   1.880 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0020 "));
   1.881 +	TPtrC validAppName = BaflUtils::ExtractAppNameFromFullName(RThread().FullName());
   1.882 +	TEST(!validAppName.Compare(RThread().Name()));
   1.883 +
   1.884 +	TPtrC inValidAppName = BaflUtils::ExtractAppNameFromFullName(_L("123:56789"));
   1.885 +	TEST(inValidAppName.Compare(_L("123:56789")));
   1.886 +	}
   1.887 +
   1.888 +/**
   1.889 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0021
   1.890 +@SYMTestCaseDesc Tests Baflutils::TestIsFirstDriveForSocket.
   1.891 +@SYMTestPriority Medium
   1.892 +@SYMTestActions Passes two differant drives as arguments.
   1.893 +@SYMTestExpectedResults The test must not fail.
   1.894 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.895 +*/
   1.896 +void TestIsFirstDriveForSocket()
   1.897 +	{
   1.898 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0021 "));
   1.899 +	TDriveUnit driveUnit(_L("C"));
   1.900 +
   1.901 +	TEST(BaflUtils::IsFirstDriveForSocket(driveUnit));
   1.902 +	driveUnit =_L("Z");
   1.903 +	TEST(!BaflUtils::IsFirstDriveForSocket(driveUnit));
   1.904 +	}
   1.905 +
   1.906 +/**
   1.907 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0022
   1.908 +@SYMTestCaseDesc Tests Baflutils::TestIsFolder.
   1.909 +@SYMTestPriority Medium
   1.910 +@SYMTestActions Passes in paths, folders and drives and checks return values.
   1.911 +@SYMTestExpectedResults The test must not fail.
   1.912 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.913 +*/
   1.914 +void TestIsFolder(RFs& aFs)
   1.915 +	{
   1.916 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0022 "));
   1.917 +	CleanupClosePushL(aFs);
   1.918 +	User::LeaveIfError(aFs.Connect());
   1.919 +
   1.920 +	TBool isFolder = EFalse;
   1.921 +
   1.922 +	TEST(!BaflUtils::IsFolder(aFs, KValidPathName, isFolder));
   1.923 +	TEST(isFolder);
   1.924 +
   1.925 +	TEST(BaflUtils::IsFolder(aFs, KInValidFolderName, isFolder));
   1.926 +	TEST(isFolder);
   1.927 +
   1.928 +	TEST(!BaflUtils::IsFolder(aFs, KValidDrive4, isFolder));
   1.929 +	TEST(isFolder);
   1.930 +
   1.931 +	CleanupStack::PopAndDestroy(&aFs);
   1.932 +	}
   1.933 +
   1.934 +/**
   1.935 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0023
   1.936 +@SYMTestCaseDesc Tests Baflutils::TestUidTypeMatches.
   1.937 +@SYMTestPriority Medium
   1.938 +@SYMTestActions Compares Uid's to check equality.
   1.939 +@SYMTestExpectedResults The test must not fail.
   1.940 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.941 +*/
   1.942 +void TestUidTypeMatches()
   1.943 +	{
   1.944 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0023 "));
   1.945 +	TUid valueOne = {0x1}, valueTwo = {0x2};
   1.946 +	valueOne.Uid(1);
   1.947 +	TUidType fileUid(valueOne), matchUid(valueOne);
   1.948 +
   1.949 +	TEST(BaflUtils::UidTypeMatches(fileUid, matchUid));
   1.950 +	valueTwo.Uid(2);
   1.951 +	fileUid = valueTwo;
   1.952 +	TEST(!BaflUtils::UidTypeMatches(fileUid, matchUid));
   1.953 +	}
   1.954 +
   1.955 +/**
   1.956 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0024
   1.957 +@SYMTestCaseDesc Tests Baflutils::TestUpdateDiskListL.
   1.958 +@SYMTestPriority Medium
   1.959 +@SYMTestActions Passes values to check the presence of disks.
   1.960 +@SYMTestExpectedResults The test must not fail.
   1.961 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
   1.962 +*/
   1.963 +void TestUpdateDiskListL(RFs& aFs)
   1.964 +	{
   1.965 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0024 "));
   1.966 +	CleanupClosePushL(aFs);
   1.967 +	User::LeaveIfError(aFs.Connect());
   1.968 +
   1.969 +	CDesCArray* drives = new(ELeave) CDesCArrayFlat(1);
   1.970 +	CleanupStack::PushL(drives);
   1.971 +
   1.972 +	// According to the Base Peripherals team drive mapping differs between
   1.973 +	// targets' environment and there might be different drives other than C and Z.
   1.974 +	// For the same reason we shouldn't check the number of available disk drives.
   1.975 +
   1.976 +	// Test cases for excluding ROM
   1.977 +	TBool includeRom = EFalse;
   1.978 +	TDriveNumber driveToInclude = EDriveA;
   1.979 +	BaflUtils::UpdateDiskListL(aFs, *drives, includeRom, driveToInclude);
   1.980 +	TEST( 'A' == ((*drives)[0])[0] );
   1.981 +	TEST( 'C' == ((*drives)[1])[0] );
   1.982 +	TEST( 'Z' != ((*drives)[drives->MdcaCount() - 1])[0] );
   1.983 +
   1.984 +	driveToInclude = EDriveD;
   1.985 +	BaflUtils::UpdateDiskListL(aFs, *drives, includeRom, driveToInclude);
   1.986 +	TEST( 'C' == ((*drives)[0])[0] );
   1.987 +	TEST( 'D' == ((*drives)[1])[0] );
   1.988 +	TEST( 'Z' != ((*drives)[drives->MdcaCount() - 1])[0] );
   1.989 +
   1.990 +	// Test cases for including ROM
   1.991 +	includeRom = ETrue;
   1.992 +	driveToInclude = EDriveA;
   1.993 +	BaflUtils::UpdateDiskListL(aFs, *drives, includeRom, driveToInclude);
   1.994 +	TEST( 'A' == ((*drives)[0])[0] );
   1.995 +	TEST( 'C' == ((*drives)[1])[0] );
   1.996 +	TEST( 'Z' == ((*drives)[drives->MdcaCount() - 1])[0] );
   1.997 +
   1.998 +	driveToInclude = EDriveD;
   1.999 +	BaflUtils::UpdateDiskListL(aFs, *drives, includeRom, driveToInclude);
  1.1000 +	TEST( 'C' == ((*drives)[0])[0] );
  1.1001 +	TEST( 'D' == ((*drives)[1])[0] );
  1.1002 +	TEST( 'Z' == ((*drives)[drives->MdcaCount() - 1])[0] );
  1.1003 +
  1.1004 +	CleanupStack::PopAndDestroy(2);
  1.1005 +	}
  1.1006 +
  1.1007 +/**
  1.1008 +@SYMTestCaseID SYSLIB-BAFL-CT-0038-0025
  1.1009 +@SYMTestCaseDesc Tests Baflutils::TestGetDiskListL.
  1.1010 +@SYMTestPriority Medium
  1.1011 +@SYMTestActions Passes values to check the presence of disks.
  1.1012 +@SYMTestExpectedResults The test must not fail.
  1.1013 +@SYMDEF DEF051652 - BaflUtils::IsFirstDriveForSocket seems broken
  1.1014 +*/
  1.1015 +void TestGetDiskListL(RFs& aFs)
  1.1016 +	{
  1.1017 +	/*
  1.1018 +	(Usually) Works in the same way as UpdateDiskListL. To test the difference we have
  1.1019 +	to perform a manual test (emulator: F5,F4, h/w: removal of media cards).
  1.1020 +	For automatic tests we check the normal functionality.
  1.1021 +	*/
  1.1022 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0038-0025 "));
  1.1023 +	CleanupClosePushL(aFs);
  1.1024 +	User::LeaveIfError(aFs.Connect());
  1.1025 +
  1.1026 +	CDesCArray* drives = new(ELeave) CDesCArrayFlat(1);
  1.1027 +	CleanupStack::PushL(drives);
  1.1028 +
  1.1029 +	// According to the Base Peripherals team drive mapping differs between
  1.1030 +	// targets' environment and there might be different drives other than C and Z.
  1.1031 +	// For the same reason we shouldn't check the number of available disk drives.
  1.1032 +
  1.1033 +	// Test cases for excluding ROM
  1.1034 +	BaflUtils::GetDiskListL(aFs, *drives);
  1.1035 +	TEST( 'C' == ((*drives)[0])[0] );
  1.1036 +
  1.1037 +#if !defined(__EPOC32__)
  1.1038 +	TEST( 'X' == ((*drives)[drives->MdcaCount() - 3])[0] );
  1.1039 +#endif
  1.1040 +
  1.1041 +	TEST( 'Z' == ((*drives)[drives->MdcaCount() - 1])[0] );
  1.1042 +
  1.1043 +	CleanupStack::PopAndDestroy(2);
  1.1044 +	}
  1.1045 +
  1.1046 +/**
  1.1047 +@SYMTestCaseID SYSLIB-BAFL-CT-0095
  1.1048 +@SYMTestCaseDesc Tests Baflutils::TestDriveIsReadOnlyInternal.
  1.1049 +@SYMTestPriority Medium
  1.1050 +@SYMTestActions Pass in various drives and parameters and checks 'Read Only Internal' status.
  1.1051 +@SYMTestExpectedResults The test must not fail.
  1.1052 +@SYMPREQ 806 Eliminate scanning for plugins on startup
  1.1053 +*/
  1.1054 +void TestDriveIsReadOnlyInternal(RFs& aFs)
  1.1055 +	{
  1.1056 +	theTest.Next(_L(" @SYMTestCaseID SYSLIB-BAFL-CT-0095 "));
  1.1057 +	CleanupClosePushL(aFs);
  1.1058 +	User::LeaveIfError(aFs.Connect());
  1.1059 +
  1.1060 +	TBool isReadOnlyInternal = EFalse;
  1.1061 +
  1.1062 +	TEST(!BaflUtils::DriveIsReadOnlyInternal(aFs, KValidPathName, isReadOnlyInternal));
  1.1063 +	TEST(!isReadOnlyInternal);
  1.1064 +	TEST(!BaflUtils::DriveIsReadOnlyInternal(aFs, KValidDrive4, isReadOnlyInternal));
  1.1065 +	TEST(isReadOnlyInternal);
  1.1066 +	TEST(BaflUtils::DriveIsReadOnlyInternal(aFs, KInValidDrive, isReadOnlyInternal));
  1.1067 +	TEST(isReadOnlyInternal);
  1.1068 +	TEST(BaflUtils::DriveIsReadOnlyInternal(aFs, KNoParameters, isReadOnlyInternal));
  1.1069 +	TEST(isReadOnlyInternal);
  1.1070 +	TEST(BaflUtils::DriveIsReadOnlyInternal(aFs, KInValidParameters, isReadOnlyInternal));
  1.1071 +	TEST(isReadOnlyInternal);
  1.1072 +
  1.1073 +	CleanupStack::PopAndDestroy(&aFs);
  1.1074 +	}
  1.1075 +
  1.1076 +/**
  1.1077 +@SYMTestCaseID TI18N-BAFL-CT-4003
  1.1078 +@SYMTestCaseDesc Tests Baflutils::TestNearestLanguageFileV2.
  1.1079 +@SYMTestPriority Medium
  1.1080 +@SYMTestActions Pass in various resource file names and change system locale setting, check the return values.
  1.1081 +@SYMTestExpectedResults The test must not fail.
  1.1082 +@SYMPREQ 2525 Install device equivalent languages from SIS files
  1.1083 +*/
  1.1084 +void TestNearestLanguageFileV2(RFs& aFs)
  1.1085 +	{
  1.1086 +	/* test case ID to be added */
  1.1087 +    theTest.Next (_L (" @SYMTestCaseID TI18N-BAFL-CT-4003 "));
  1.1088 +    
  1.1089 +    __UHEAP_MARK;
  1.1090 +
  1.1091 +	CleanupClosePushL (aFs);
  1.1092 +	User::LeaveIfError (aFs.Connect ());
  1.1093 +    
  1.1094 +    DeleteTestFiles2(aFs);
  1.1095 +    CreateTestFiles2(aFs);
  1.1096 +
  1.1097 +	TBuf <256> filename;
  1.1098 +	TLanguage lang = ELangNone;
  1.1099 +	theTest.Printf (_L("lang initial value is %d\n"), lang);
  1.1100 +
  1.1101 +	// Test NearestLanguageFile with empty name
  1.1102 +	TFileName resPath;
  1.1103 +	BaflUtils::NearestLanguageFileV2(aFs, resPath, lang);
  1.1104 +	TEST(resPath.Length()==0);
  1.1105 +	theTest.Printf (_L("lang returned by NLFV2 is %d\n"), lang);
  1.1106 +	TEST(ELangNone == lang);
  1.1107 +	theTest.Printf (_L ("The NearestLanguageFile for the null file - %S - is - %S -\n"), &KNullFilename, &filename);
  1.1108 +	
  1.1109 +	// Test NearestLanguageFile with invalid drive letter
  1.1110 +	filename.Copy (KInvalidDriveLetterV2);
  1.1111 +	BaflUtils::NearestLanguageFileV2(aFs, filename, lang);
  1.1112 +	//TEST(filename==KRscFilenameNoSuffix);
  1.1113 +	theTest.Printf (_L ("The NearestLanguageFile for %S is %S, lang is %d\n"), &KInvalidDriveLetterV2, &filename, lang);
  1.1114 +	//TEST(ELangNone == lang);
  1.1115 +	
  1.1116 +	// Test NearestLanguageFile with incorrect ext
  1.1117 +	DeleteTestFiles2(aFs);
  1.1118 +	RFile rFile;
  1.1119 +	TEST (KErrNone == rFile.Create (aFs, KFrenchLang, EFileRead));
  1.1120 +	rFile.Close ();
  1.1121 +	filename.Copy (KNoSuchLangFile);
  1.1122 +	BaflUtils::NearestLanguageFileV2(aFs, filename, lang);
  1.1123 +	//TEST(filename==KRscFilenameNoSuffix);
  1.1124 +	theTest.Printf (_L ("The NearestLanguageFile for %S is %S, lang is %d\n"), &KNoSuchLangFile, &filename, lang);
  1.1125 +	//TEST(ELangNone == lang);
  1.1126 +	BaflUtils::DeleteFile (aFs, KFrenchLang);
  1.1127 +	CreateTestFiles2(aFs);
  1.1128 +		
  1.1129 +	// Test NearestLanguageFile with no suffix
  1.1130 +	filename.Copy (KRscFilenameNoSuffix);
  1.1131 +	BaflUtils::NearestLanguageFileV2(aFs, filename, lang);
  1.1132 +	TEST(filename==KRscFilenameNoSuffix);
  1.1133 +	theTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilenameNoSuffix, &filename);
  1.1134 +	TEST(ELangNone == lang);
  1.1135 +	
  1.1136 +	// change locale to American
  1.1137 +	TExtendedLocale loc;
  1.1138 +	loc.LoadSystemSettings();
  1.1139 +	TInt ret = loc.LoadLocale(_L ("elocl.10"));
  1.1140 +	theTest.Printf(_L("LoadLocale returns %d\n"), ret);
  1.1141 +	TEST(KErrNone == ret);
  1.1142 +	ret = loc.SaveSystemSettings();
  1.1143 +	TEST(KErrNone == ret);
  1.1144 +	
  1.1145 +	// Test NearestLanguageFile: AmE is supported
  1.1146 +	filename.Copy (KRscFilename);
  1.1147 +	BaflUtils::NearestLanguageFileV2(aFs, filename, lang);
  1.1148 +	theTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilename, &filename);
  1.1149 +	//TEST(filename == KEnglishLang);
  1.1150 +	TEST(filename == KAmericanLang);
  1.1151 +	TEST(lang == ELangAmerican);
  1.1152 +
  1.1153 +	// Delete geltest.r10, AmE downgrades to En_GB.
  1.1154 +	BaflUtils::DeleteFile (aFs, KAmericanLang);
  1.1155 +	filename.Copy (KRscFilename);
  1.1156 +	BaflUtils::NearestLanguageFileV2(aFs, filename, lang);
  1.1157 +	theTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilename, &filename);
  1.1158 +	TEST(filename == KEnglishLang);
  1.1159 +	TEST(lang == ELangEnglish);
  1.1160 +	
  1.1161 +	
  1.1162 +	// Delete geltest.r01, AmE downgrades to en_GB, to ELangNone.
  1.1163 +	BaflUtils::DeleteFile (aFs, KEnglishLang);
  1.1164 +	filename.Copy (KRscFilename);
  1.1165 +	BaflUtils::NearestLanguageFileV2(aFs, filename, lang);
  1.1166 +	theTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilename, &filename);
  1.1167 +	TEST(filename == KRscFilename); // filename remains unchanged.
  1.1168 +	TEST(lang == ELangNone);
  1.1169 +
  1.1170 +	// restore locale settings
  1.1171 +	theTest.Printf(_L("Restoring locale settings.\n"));
  1.1172 +	loc.LoadSystemSettings();
  1.1173 +	ret = loc.LoadLocale(_L("elocl.01"));
  1.1174 +	TEST(KErrNone == ret);
  1.1175 +	ret = loc.SaveSystemSettings();
  1.1176 +	TEST(KErrNone == ret);
  1.1177 +	
  1.1178 +	CleanupStack::PopAndDestroy (&aFs);
  1.1179 +
  1.1180 +	__UHEAP_MARKEND;
  1.1181 +	}
  1.1182 +
  1.1183 +/**
  1.1184 +@SYMTestCaseID TI18N-BAFL-CT-4004
  1.1185 +@SYMTestCaseDesc Tests Baflutils::TestGetEquivalentLanguageList.
  1.1186 +@SYMTestPriority Medium
  1.1187 +@SYMTestActions Pass in various language ID's and check the returned list.
  1.1188 +@SYMTestExpectedResults The test must not fail.
  1.1189 +@SYMPREQ 2525 Install device equivalent languages from SIS files
  1.1190 +*/
  1.1191 +void TestGetEquivalentLanguageList()
  1.1192 +	{
  1.1193 +	/* test case ID to be added */
  1.1194 +	theTest.Next (_L (" @SYMTestCaseID TI18N-BAFL-CT-4004 "));
  1.1195 +    
  1.1196 +    __UHEAP_MARK;
  1.1197 +    
  1.1198 +	TLanguagePath lp;
  1.1199 +	// Test GetNearestLanguageFile();
  1.1200 +	// 1- There is an entry in the table for the given language
  1.1201 +	BaflUtils::GetEquivalentLanguageList(ELangCyprusGreek, lp);
  1.1202 +	TEST(ELangCyprusGreek == lp[0]);
  1.1203 +	TEST(ELangGreek == lp[1]);
  1.1204 +	TEST(ELangNone == lp[2]);
  1.1205 +	
  1.1206 +	// 2- There is no entry for the given language
  1.1207 +	BaflUtils::GetEquivalentLanguageList(ELangFarsi, lp);
  1.1208 +	TEST(ELangFarsi == lp[0]);
  1.1209 +	TEST(ELangNone == lp[1]);
  1.1210 +
  1.1211 +	__UHEAP_MARKEND;
  1.1212 +	}
  1.1213 +
  1.1214 +
  1.1215 +/**
  1.1216 +@SYMTestCaseID SYSLIB-BAFL-CT-0038
  1.1217 +@SYMTestCaseDesc Tests Baflutils.
  1.1218 +@SYMTestPriority Medium
  1.1219 +@SYMTestActions Executes all T_baflutils tests.
  1.1220 +@SYMTestExpectedResults The test must not fail.
  1.1221 +@SYMDEF DEF050397 - Crimson test code improvement to be propagated into MCL
  1.1222 +*/
  1.1223 +void DoTestsL()
  1.1224 +	{
  1.1225 +	RFs fs;
  1.1226 +
  1.1227 +	::CopyTestFiles();
  1.1228 +	TestPersistHAL();
  1.1229 +	TestEnsurePathExistsL(fs);
  1.1230 +	TestFileExists(fs);
  1.1231 +	TestFolderExists(fs);
  1.1232 +	TestPathExistsL(fs);
  1.1233 +	TestCopyFile(fs);
  1.1234 +	TestDeleteFile(fs);
  1.1235 +	TestRenameFile(fs);
  1.1236 +	TestAbbreviateFileName();
  1.1237 +	TestCheckWhetherFullNameRefersToFolder();
  1.1238 +	TestCopyWithTruncation();
  1.1239 +	TestDriveAndPathFromFullName();
  1.1240 +	TestFolderNameFromFullName();
  1.1241 +	TestMostSignificantPartOfFullName();
  1.1242 +	TestParse();
  1.1243 +	TestRootFolderPath();
  1.1244 +	TestValidateFolderNameTypedByUserL(fs);
  1.1245 +	TestRemoveSystemDirectory(fs);
  1.1246 +	TestCheckFolder(fs);
  1.1247 +	TestDiskIsReadOnly(fs);
  1.1248 +	TestNearestLanguageFileV2(fs);
  1.1249 +	TestGetEquivalentLanguageList();
  1.1250 +
  1.1251 +	TestDriveIsReadOnlyInternal(fs);
  1.1252 +	#if defined __WINS__ || defined __WINSCW__
  1.1253 +
  1.1254 +		TestExtractAppNameFromFullName();
  1.1255 +	#endif //defined __WINS__ || defined __WINSCW__
  1.1256 +
  1.1257 +	TestIsFirstDriveForSocket();
  1.1258 +	TestIsFolder(fs);
  1.1259 +	TestUidTypeMatches();
  1.1260 +	TestUpdateDiskListL(fs);
  1.1261 +	TestGetDiskListL(fs);
  1.1262 +	::DeleteTestFiles();
  1.1263 +	}
  1.1264 +
  1.1265 +GLDEF_C TInt E32Main()
  1.1266 +	{
  1.1267 +    __UHEAP_MARK;
  1.1268 +    CTrapCleanup *cleanup=CTrapCleanup::New();
  1.1269 +	theTest.Title();
  1.1270 +	theTest.Start(_L("Testing T_BaflUtils "));
  1.1271 +    TRAPD(err,DoTestsL());
  1.1272 +    TEST(!err);
  1.1273 +	theTest.End();
  1.1274 +    theTest.Close();
  1.1275 +    delete cleanup;
  1.1276 +    __UHEAP_MARKEND;
  1.1277 +	return(0);
  1.1278 +    }
  1.1279 +
  1.1280 +
  1.1281 +//
  1.1282 +// Helper method to create a hierarchy of directories
  1.1283 +
  1.1284 +TInt CreateDirectoryTree(RFs& aFs, const TPtrC* aDir)
  1.1285 +	{
  1.1286 +	TParse parsedPath;
  1.1287 +	TBuf<KMaxFileName> newPath;
  1.1288 +	TInt err, pos;
  1.1289 +	TPtrC path;
  1.1290 +	TPtrC fileName;
  1.1291 +
  1.1292 +	// check for the corectness of input parameters
  1.1293 +	if (aDir == NULL )
  1.1294 +		return EFalse;
  1.1295 +
  1.1296 +	// verify the corectness of the input path
  1.1297 +	err = parsedPath.Set(*aDir, NULL, NULL);
  1.1298 +	if (err != KErrNone)
  1.1299 +	   return err;
  1.1300 +
  1.1301 +	// interatily build the path and create hierarchy of directories in file system
  1.1302 +	newPath = parsedPath.Drive();
  1.1303 +	newPath.Append('\\');
  1.1304 +	path.Set(parsedPath.Path());
  1.1305 +	path.Set(path.Mid(1));              // get rid of the first backlash
  1.1306 +	while ((pos = path.Find(_L("\\"))) != KErrNotFound)
  1.1307 +		{
  1.1308 +		newPath.Append(path.Left(pos)); //append next directory
  1.1309 +		newPath.Append('\\');
  1.1310 +		err = aFs.MkDir(newPath);
  1.1311 +		if (err != KErrNone) return err;
  1.1312 +		path.Set(path.Mid(pos + 1));
  1.1313 +		}
  1.1314 +
  1.1315 +	// directory created.
  1.1316 +	// verify if there is a need to create a file
  1.1317 +	if (parsedPath.NamePresent())
  1.1318 +		{
  1.1319 +		RFile file;
  1.1320 +		err = file.Create(aFs, *aDir, EFileWrite);
  1.1321 +		if (err != KErrNone) return err;
  1.1322 +		file.Close();
  1.1323 +		}
  1.1324 +
  1.1325 +	return KErrNone;
  1.1326 +	}
  1.1327 +
  1.1328 +
  1.1329 +//
  1.1330 +// Helper method to remove a hierarchy of directories
  1.1331 +TInt RemoveDirectoryTreeL(RFs& aFs, const TPtrC* aDir)
  1.1332 +	{
  1.1333 +	TParse parsedPath;
  1.1334 +	TBuf<KMaxFileName> newPath;
  1.1335 +	TInt err = KErrNone;
  1.1336 +	TInt pos;
  1.1337 +	TPtrC path;
  1.1338 +	CFileMan *fileMan = NULL;
  1.1339 +
  1.1340 +	// Create FileMan.
  1.1341 +	// As oposite to RFs it is able to remove a hirarchy of not empty directories
  1.1342 +	TRAPD(leaveCode, fileMan = CFileMan::NewL(aFs));
  1.1343 +	if (leaveCode != KErrNone)
  1.1344 +		return leaveCode;
  1.1345 +	CleanupStack::PushL(fileMan);
  1.1346 +
  1.1347 +	// verify the corectness of the input path
  1.1348 +	err = parsedPath.Set(*aDir, NULL, NULL);
  1.1349 +	if (err == KErrNone)
  1.1350 +		{
  1.1351 +		// build the path consisting only of the first level of directories hierarchy
  1.1352 +		newPath = parsedPath.Drive();
  1.1353 +		newPath.Append('\\');
  1.1354 +		path.Set(parsedPath.Path());
  1.1355 +		path.Set(path.Mid(1));  			// get rid of the first backlash
  1.1356 +		if((pos = path.Find(_L("\\"))) != KErrNotFound)
  1.1357 +			{
  1.1358 +			newPath.Append(path.Left(pos)); //append next directory
  1.1359 +			newPath.Append('\\');
  1.1360 +			err = fileMan->RmDir(newPath);
  1.1361 +			}
  1.1362 +
  1.1363 +		}
  1.1364 +
  1.1365 +	CleanupStack::PopAndDestroy(fileMan);
  1.1366 +
  1.1367 +	return err;;
  1.1368 +	}
  1.1369 +
  1.1370 +//
  1.1371 +// Helper method for TestPathExist test.
  1.1372 +TBool DoTestPathExistsL(RFs& aFs, const struct TPathExistTestRecord& aTestRecord)
  1.1373 +{
  1.1374 +	TBool err;
  1.1375 +	TInt i;
  1.1376 +
  1.1377 +	// 1. Create required directories (preconditions)
  1.1378 +	for ( i = 0; aTestRecord.iInPaths[i] != NULL && i < PATH_EXIST_MAX_PRECONDITIONS; i++)
  1.1379 +		{
  1.1380 +		err = CreateDirectoryTree(aFs, aTestRecord.iInPaths[i]);
  1.1381 +		if (err != KErrNone)
  1.1382 +			{
  1.1383 +			RDebug::Print(_L("TestPathExist(%d): Directory not created. Cause: %d"),
  1.1384 +							aTestRecord.iLineNum, err);
  1.1385 +
  1.1386 +			// Do not break the loop here as the path might be incorrectly shaped on purpose.
  1.1387 +			}
  1.1388 +		}
  1.1389 +
  1.1390 +	// 2. Make a directory test
  1.1391 +	TBool testOutcome = BaflUtils::PathExists(aFs, *aTestRecord.iTestPath);
  1.1392 +
  1.1393 +	// 3. Remove directories
  1.1394 +	for ( i = 0; aTestRecord.iInPaths[i] != NULL && i < PATH_EXIST_MAX_PRECONDITIONS ; i++)
  1.1395 +		{
  1.1396 +		err = RemoveDirectoryTreeL(aFs, aTestRecord.iInPaths[i]);
  1.1397 +
  1.1398 +		if (err != KErrNone)
  1.1399 +			{
  1.1400 +			RDebug::Print(_L("TestPathExist(%d): Warning: Directory not removed. Cause: %d"),
  1.1401 +							aTestRecord.iLineNum, err);
  1.1402 +			}
  1.1403 +		}
  1.1404 +
  1.1405 +	// 4. Check the results
  1.1406 +	if (aTestRecord.iResult != testOutcome)
  1.1407 +		{
  1.1408 +		RDebug::Print(_L("TestPathExist(%d): Failed."), aTestRecord.iLineNum);
  1.1409 +		return EFalse;
  1.1410 +		}
  1.1411 +
  1.1412 +	RDebug::Print(_L("TestPathExist(%d): Passed."), aTestRecord.iLineNum);
  1.1413 +	return ETrue;
  1.1414 +}