lowlevellibsandfws/apputils/tsrc/T_BaflDefect.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2005-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 <f32file.h>
       
    17 #include <e32test.h>
       
    18 #include <bautils.h>
       
    19 #include <hal.h>
       
    20 #include <e32std.h>
       
    21 #include <e32math.h>
       
    22 
       
    23 #include "backup_std.h"
       
    24 
       
    25 LOCAL_D CTrapCleanup*		TheTrapCleanup=NULL;
       
    26 LOCAL_D CActiveScheduler*	TheActiveScheduler=NULL;
       
    27 
       
    28 LOCAL_D RTest				TheTest (_L("T_BaflDefect"));
       
    29 LOCAL_D RFs					TheFs;
       
    30 
       
    31 _LIT(KServerLauncherProcess, "T_BackupServerLauncher");
       
    32 _LIT(KServerName, "!BackupServer");
       
    33 _LIT(KBURServerName,"baksrvs");
       
    34 
       
    35 class RIpcServerCloseTest : public RSessionBase
       
    36 {
       
    37 public: // Constructors and destructor
       
    38 
       
    39 	/**
       
    40 	* Constructor for performing 1st stage construction
       
    41 	*/
       
    42 	RIpcServerCloseTest();
       
    43 
       
    44 	/**
       
    45 	* Destructor.
       
    46 	*/
       
    47 	~RIpcServerCloseTest();
       
    48 
       
    49 	/**
       
    50 	* Performs test steps
       
    51 	*/
       
    52 	void RunTestL(const TDesC& aTargetSrvName, TInt aNumber, TInt aArgCount);
       
    53 };
       
    54 
       
    55 RIpcServerCloseTest::RIpcServerCloseTest()
       
    56 	{
       
    57 	// No implementation required
       
    58 	}
       
    59 
       
    60 RIpcServerCloseTest::~RIpcServerCloseTest()
       
    61 	{
       
    62 	Close();	
       
    63 	}
       
    64 
       
    65 void RIpcServerCloseTest::RunTestL(const TDesC& aTargetSrvName, TInt aNumber, TInt aArgCount)
       
    66 	{
       
    67 	TVersion version(0,0,0);
       
    68 	TInt err = KErrNotFound;
       
    69 	TInt numberOfAttempts = 3;
       
    70 	
       
    71 	while(err!=KErrNone && numberOfAttempts>0)
       
    72 		{
       
    73 		err = CreateSession(aTargetSrvName, version, 200);
       
    74 
       
    75 		if(err!=KErrNone)
       
    76 			{
       
    77 			// wait then try again if err!=0
       
    78 			TheTest.Printf(_L("CreateSession returned: %d"), err);
       
    79 			User::After(1000000);
       
    80 			numberOfAttempts--;
       
    81 			}
       
    82 		}
       
    83 	
       
    84 	TheTest(err == KErrNone);
       
    85 	
       
    86 	HBufC8* buf = HBufC8::NewLC(255);
       
    87 	TPtr8 ptr = buf->Des();
       
    88 	ptr.Fill(Math::Random(),255);
       
    89 		
       
    90 	TIpcArgs args;
       
    91 		
       
    92 	for(TInt i = 0; i < aArgCount ;i++)
       
    93 		{
       
    94 		args.Set(i,&ptr);
       
    95 		}
       
    96 	
       
    97 	TheTest.Printf(_L("Sending request to: %d with %d args"), aNumber, aArgCount);
       
    98 	
       
    99 	TRequestStatus status;
       
   100 	
       
   101 	SendReceive(aNumber, args, status);
       
   102 	
       
   103 	User::WaitForRequest(status);
       
   104 	
       
   105 	TheTest.Printf(_L("Status value from sending request: %d with %d args"), status.Int(), aArgCount);
       
   106 	
       
   107 	TheTest(status.Int() == KErrNotSupported);
       
   108 
       
   109 	CleanupStack::PopAndDestroy(buf);
       
   110 	}
       
   111 
       
   112 //This function is used in the test code to kill backupSrv or the backuplauncher process.
       
   113 // It creates a separate process to do this as killing a process requires
       
   114 // PwrMgmt capability which we don't want to grant to all test exes.
       
   115 TInt KillProcess(const TDesC& aProcessName)
       
   116 	{
       
   117 	_LIT(KProcessKiller, "t_processkiller");
       
   118 	TRequestStatus stat;
       
   119 	RProcess p;
       
   120 	TInt result = p.Create(KProcessKiller, aProcessName);
       
   121 	
       
   122 	if(result == KErrNone)
       
   123 		{
       
   124 		// Asynchronous logon: completes when process terminates with process exit code
       
   125 		p.Logon(stat);
       
   126 		p.Resume();
       
   127 
       
   128 		User::WaitForRequest(stat);
       
   129 		result = p.ExitReason();
       
   130 		p.Close();			
       
   131 		}
       
   132 
       
   133 	return result;
       
   134 	}
       
   135 
       
   136 TInt LaunchServer(RProcess& aServer)
       
   137 	{	
       
   138 	TheTest.Printf(_L("Launching BackupServer...\n"));
       
   139 	
       
   140 	TInt err = aServer.Create(KServerLauncherProcess, _L(""));
       
   141 	TheTest(err == KErrNone);
       
   142 	     
       
   143 	//Start server and wait until it is running
       
   144 	TRequestStatus serverStat;
       
   145 	aServer.SetJustInTime(false);   
       
   146 	aServer.Resume(); 
       
   147 		   
       
   148 	aServer.Rendezvous(serverStat);
       
   149 	User::WaitForRequest(serverStat);
       
   150 		
       
   151 	err = serverStat.Int();
       
   152 		 
       
   153 	return err;
       
   154 	}
       
   155 
       
   156 /**
       
   157 @SYMTestCaseID          SYSLIB-BAFL-UT-4052
       
   158 @SYMTestCaseDesc        Tests BackupServer crashes under IPC fuzzing and freezes phone 
       
   159 @SYMTestPriority        High
       
   160 @SYMTestActions         Calls BackupServer with EBakOpCodeCloseServer with 0-4 args. Verifies that server returns KErrNotSupported.
       
   161 @SYMTestExpectedResults Server should not process the  CloseServer message and should return KErrNotSupported
       
   162 */
       
   163 LOCAL_C void Defect_INC120743L()
       
   164     {
       
   165 	TheTest.Next (_L ("Defect_INC120743L"));
       
   166     
       
   167 	__UHEAP_MARK;
       
   168 	
       
   169     RProcess server;
       
   170     TInt messageToTest = EBakOpCodeCloseServer;
       
   171 
       
   172     //Clean up any chance of launcher or baksrvs still running
       
   173     TInt err = KillProcess(KServerLauncherProcess);
       
   174     if((err != KErrNotFound)&&(err != KErrDied))
       
   175     	{
       
   176     	User::LeaveIfError(err);	
       
   177     	}
       
   178 
       
   179     err = KillProcess(KBURServerName);
       
   180     if((err != KErrNotFound)&&(err != KErrDied))
       
   181     	{
       
   182     	User::LeaveIfError(err);	
       
   183     	}
       
   184     
       
   185     TInt startedFlag = LaunchServer(server);
       
   186     
       
   187     TheTest.Printf(_L("LaunchServer has returned: %d"), startedFlag);
       
   188     
       
   189     TheTest(startedFlag == 0 || startedFlag == KErrAlreadyExists);
       
   190     
       
   191  	CTrapCleanup* cleanup=CTrapCleanup::New();
       
   192    	err=KErrNoMemory;
       
   193 
       
   194    	if (cleanup)
       
   195    		{
       
   196 		//Carry out each test with number of arguments 1 - 4
       
   197 		for(TInt argCount = 0; argCount <= 4; argCount++)
       
   198 			{
       
   199 			RIpcServerCloseTest closeTest;
       
   200 		
       
   201 			TRAP(err,closeTest.RunTestL(KServerName, messageToTest, argCount));
       
   202 		
       
   203 			closeTest.Close();
       
   204 			}
       
   205 
       
   206    		delete cleanup;
       
   207    		}
       
   208         
       
   209 	__UHEAP_MARKEND;
       
   210     }
       
   211 
       
   212 /**
       
   213 @SYMTestCaseID          SYSLIB-BAFL-CT-1390
       
   214 @SYMTestCaseDesc        Tests BaflUtils::PersistScreenCalibration
       
   215 @SYMTestPriority        Medium
       
   216 @SYMTestActions         Deletes screen calibration file, calls PersistScreenCalibration()
       
   217 and checks that file now exists
       
   218 @SYMTestExpectedResults Test must not fail
       
   219 @SYMREQ                 REQ0000
       
   220 */
       
   221 void Defect_DEF068052L()
       
   222 	{
       
   223 	TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-BAFL-CT-1390 Defect_DEF068052L "));
       
   224 
       
   225     __UHEAP_MARK;
       
   226 
       
   227 	User::LeaveIfError (TheFs.Connect ());
       
   228 	::CleanupClosePushL (TheFs);
       
   229 
       
   230 	const TInt KDriveLength = 2;
       
   231 	const TInt KScreenPathLength = 26;
       
   232 	const TInt KScreenPathLengthTemp = 30;
       
   233 
       
   234 	_LIT (KDriveColon, ":");
       
   235 	_LIT (KScreen, "\\System\\Data\\Screen.DAT");
       
   236 	_LIT (KScreenTemp, "\\System\\Data\\ScreenTemp.DAT");
       
   237 
       
   238 	// Find the system drive
       
   239 	TDriveNumber systemDrive = TheFs.GetSystemDrive();
       
   240 
       
   241 	// Set up a full file path name incorporating the system drive
       
   242 	// (for example if system drive is EDriveC pathname will be:
       
   243 	// C:\System\Data\Screen.DAT)
       
   244 	TBuf<KDriveLength+KScreenPathLength> screenFilePath;
       
   245 	screenFilePath.Append(systemDrive + 'A');
       
   246 	screenFilePath.Append(KDriveColon);
       
   247 	screenFilePath.Append(KScreen);
       
   248 
       
   249 	// Set up a full file path name to make a copy of the screen.dat
       
   250 	// file.
       
   251 	TBuf<KDriveLength+KScreenPathLengthTemp> screenFilePathTemp;
       
   252 	screenFilePathTemp.Append(systemDrive + 'A');
       
   253 	screenFilePathTemp.Append(KDriveColon);
       
   254 	screenFilePathTemp.Append(KScreenTemp);
       
   255 
       
   256 	// Make a copy of the screen.dat file (if it exists)
       
   257 	BaflUtils::CopyFile(TheFs, screenFilePath, screenFilePathTemp);
       
   258 
       
   259 	// Delete the Screen.DAT file (if it exists)
       
   260 	BaflUtils::DeleteFile(TheFs, screenFilePath);
       
   261 
       
   262 	// Saving Screen settings - call API to write the screen
       
   263 	// calibration to file
       
   264 	TDigitizerCalibration calib;
       
   265 	BaflUtils::PersistScreenCalibration(calib);
       
   266 
       
   267 	// Check if screen.dat file now exists
       
   268 	TBool exists = BaflUtils::FileExists(TheFs, screenFilePath);
       
   269 	TheTest(exists);
       
   270 
       
   271 	TheTest.Printf(_L("Screen settings were saved in %S\n"), &screenFilePath);
       
   272 
       
   273 	// Cleaning up, restore files to original state
       
   274 	User::LeaveIfError(BaflUtils::DeleteFile(TheFs, screenFilePath));
       
   275 	BaflUtils::CopyFile(TheFs, screenFilePathTemp, screenFilePath);
       
   276 	BaflUtils::DeleteFile(TheFs, screenFilePathTemp);
       
   277 	CleanupStack::PopAndDestroy (&::TheFs);
       
   278 
       
   279 	__UHEAP_MARKEND;
       
   280 	}
       
   281 
       
   282 /**
       
   283 @SYMTestCaseID          SYSLIB-BAFL-CT-0487
       
   284 @SYMTestCaseDesc        Tests for defect number INC045169L
       
   285 @SYMTestPriority        High
       
   286 @SYMTestActions         Tests for creation of files
       
   287 @SYMTestExpectedResults Tests must not fail
       
   288 @SYMREQ                 REQ0000
       
   289 */
       
   290 void Defect_INC045169L()
       
   291 	{
       
   292 	TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-BAFL-CT-0487 Defect_INC045169L "));
       
   293 
       
   294 	__UHEAP_MARK;
       
   295 
       
   296   	// find out the number of open handles
       
   297 	TInt startProcessHandleCount;
       
   298 	TInt startThreadHandleCount;
       
   299 	RThread ().HandleCount (startProcessHandleCount, startThreadHandleCount);
       
   300 
       
   301 	//
       
   302 	// The Test Setup
       
   303 
       
   304 	User::LeaveIfError (TheFs.Connect ());
       
   305 	::CleanupClosePushL (TheFs);
       
   306 
       
   307 	//
       
   308 	// The Test Begins...
       
   309 
       
   310 
       
   311 	// Our test diectory and files...
       
   312 	_LIT (KDirectory, "C:\\System\\Data\\");
       
   313 
       
   314 	// ++++++++++++++
       
   315 
       
   316 	// When creating test file names be careful to use different
       
   317 	// combinations of charaters as you may get ambiguity!
       
   318 	// i.e. '.aaa' will find files '.a' or 'a' if on disk.
       
   319 	// similarly, 'abc158' will find files 'abc' or 'abc.'.
       
   320 	// Also, file name ending in a period will have them
       
   321 	// stripped off by the Fs, so 'abcd.' will give you 'abcd'
       
   322 	// Finally, don't have like names like 'abc.rsc' and 'abc.r'
       
   323 
       
   324 	// Failure cases
       
   325 	_LIT (KFilename1, "c:"); // not supported
       
   326 	_LIT (KFilename2, "x"); // not supported
       
   327 	_LIT (KFilename3, "C:\\System\\Data\\a"); // not supported
       
   328 	_LIT (KFilename4, "C:\\System\\Data\\ab"); // not supported
       
   329 	_LIT (KFilename5, "C:\\System\\Data\\i.j"); // no 'i.01' available
       
   330 	_LIT (KFilename6, "C:\\System\\Data\\abc.r12345678901234567890"); // suffix too large
       
   331 	_LIT (KFilename7, "C:\\System\\Data\\"); // not supported
       
   332 
       
   333 	// Successful cases
       
   334 	_LIT (KFilename10, "C:\\System\\Data\\cde");
       
   335 	_LIT (KFilename11, "C:\\System\\Data\\abc158");
       
   336 	_LIT (KFilename12, "C:\\System\\Data\\C01abc001");
       
   337 	_LIT (KFilename13, "C:\\System\\Data\\0123456789.012");
       
   338 	_LIT (KFilename14, "C:\\System\\Data\\0123");
       
   339 	_LIT (KFilename15, "C:\\System\\Data\\0123456789012");
       
   340 	_LIT (KFilename16, "C:\\System\\Data\\C.01a1");
       
   341 	_LIT (KFilename17, "C:\\System\\Data\\C.a0a1");
       
   342 	_LIT (KFilename18, "C:\\System\\Data\\.b");
       
   343 	_LIT (KFilename19, "C:\\System\\Data\\.ccc");
       
   344 	_LIT (KFilename20, "C:\\System\\Data\\rfg.3a");
       
   345 	_LIT (KFilename21, "C:\\System\\Data\\abc.r158");
       
   346 	_LIT (KFilename22, "C:\\System\\Data\\abc.rsc");
       
   347 	_LIT (KFilename23, "C:\\System\\Data\\efg.r");
       
   348 	_LIT (KFilename24, "C:\\System\\Data\\klmn.");
       
   349 	_LIT (KFilename25, "C:\\System\\Data\\jhgdfgd.123456789abc");
       
   350 	_LIT (KFilename26, "\\abc.r158");
       
   351 	_LIT (KFilename27, "abc.r158");
       
   352 	_LIT (KFilename28, "c:abc.r158");
       
   353 
       
   354 	// ++++++++++++++
       
   355 
       
   356 	// ELangAmerican
       
   357 	_LIT (KLocale, "ELOCL.10");
       
   358 	_LIT (KNearestLang, "C:\\System\\Data\\abc.r10");
       
   359 
       
   360 	// Tidy the files if there...
       
   361 	// KFilename1 can't be created
       
   362 	BaflUtils::DeleteFile (TheFs, KFilename2);
       
   363 	BaflUtils::DeleteFile (TheFs, KFilename3);
       
   364 	BaflUtils::DeleteFile (TheFs, KFilename4);
       
   365 	BaflUtils::DeleteFile (TheFs, KFilename5);
       
   366 	BaflUtils::DeleteFile (TheFs, KFilename6);
       
   367 
       
   368  	// Do not delete KFileName7, there may be other
       
   369  	// files in this directory unrelated to this test
       
   370  	// which are required by other tests.
       
   371  	// See defect DEF108808
       
   372  	// BaflUtils::DeleteFile (TheFs, KFilename7);
       
   373 
       
   374 	BaflUtils::DeleteFile (TheFs, KFilename10);
       
   375 	BaflUtils::DeleteFile (TheFs, KFilename11);
       
   376 	BaflUtils::DeleteFile (TheFs, KFilename12);
       
   377 	BaflUtils::DeleteFile (TheFs, KFilename13);
       
   378 	BaflUtils::DeleteFile (TheFs, KFilename14);
       
   379 	BaflUtils::DeleteFile (TheFs, KFilename15);
       
   380 	BaflUtils::DeleteFile (TheFs, KFilename16);
       
   381 	BaflUtils::DeleteFile (TheFs, KFilename17);
       
   382 	BaflUtils::DeleteFile (TheFs, KFilename18);
       
   383 	BaflUtils::DeleteFile (TheFs, KFilename19);
       
   384 	BaflUtils::DeleteFile (TheFs, KFilename20);
       
   385 	BaflUtils::DeleteFile (TheFs, KFilename21);
       
   386 	BaflUtils::DeleteFile (TheFs, KFilename22);
       
   387 	BaflUtils::DeleteFile (TheFs, KFilename23);
       
   388 #ifdef __EPOC32__
       
   389 	BaflUtils::DeleteFile (TheFs, KFilename24);
       
   390 #else
       
   391 	// Windows strips off trailing periods
       
   392 	BaflUtils::DeleteFile (TheFs, _L("C:\\System\\Data\\klmn"));
       
   393 #endif
       
   394 	BaflUtils::DeleteFile (TheFs, KFilename25);
       
   395 	BaflUtils::DeleteFile (TheFs, KFilename26);
       
   396 	BaflUtils::DeleteFile (TheFs, KFilename27);
       
   397 	BaflUtils::DeleteFile (TheFs, KFilename28);
       
   398 	BaflUtils::DeleteFile (TheFs, KNearestLang);
       
   399 
       
   400 	// Confirm the prerequisites for this test...
       
   401 	if (!BaflUtils::PathExists (TheFs, KDirectory))
       
   402 		{
       
   403 		BaflUtils::EnsurePathExistsL(TheFs, KDirectory);
       
   404 		}
       
   405 
       
   406 	// KFilename1 can't be created
       
   407 	TheTest (BaflUtils::FileExists (TheFs, KFilename2) == EFalse);
       
   408 	TheTest (BaflUtils::FileExists (TheFs, KFilename3) == EFalse);
       
   409 	TheTest (BaflUtils::FileExists (TheFs, KFilename4) == EFalse);
       
   410 	TheTest (BaflUtils::FileExists (TheFs, KFilename5) == EFalse);
       
   411 	TheTest (BaflUtils::FileExists (TheFs, KFilename6) == EFalse);
       
   412 	// KFilename7 can't be created, not a file
       
   413 
       
   414 	TheTest (BaflUtils::FileExists (TheFs, KFilename10) == EFalse);
       
   415 	TheTest (BaflUtils::FileExists (TheFs, KFilename11) == EFalse);
       
   416 	TheTest (BaflUtils::FileExists (TheFs, KFilename12) == EFalse);
       
   417 	TheTest (BaflUtils::FileExists (TheFs, KFilename13) == EFalse);
       
   418 	TheTest (BaflUtils::FileExists (TheFs, KFilename14) == EFalse);
       
   419 	TheTest (BaflUtils::FileExists (TheFs, KFilename15) == EFalse);
       
   420 	TheTest (BaflUtils::FileExists (TheFs, KFilename16) == EFalse);
       
   421 	TheTest (BaflUtils::FileExists (TheFs, KFilename17) == EFalse);
       
   422 	TheTest (BaflUtils::FileExists (TheFs, KFilename18) == EFalse);
       
   423 	TheTest (BaflUtils::FileExists (TheFs, KFilename19) == EFalse);
       
   424 	TheTest (BaflUtils::FileExists (TheFs, KFilename20) == EFalse);
       
   425 	TheTest (BaflUtils::FileExists (TheFs, KFilename21) == EFalse);
       
   426 	TheTest (BaflUtils::FileExists (TheFs, KFilename22) == EFalse);
       
   427 	TheTest (BaflUtils::FileExists (TheFs, KFilename23) == EFalse);
       
   428 	TheTest (BaflUtils::FileExists (TheFs, KFilename24) == EFalse);
       
   429 	TheTest (BaflUtils::FileExists (TheFs, KFilename25) == EFalse);
       
   430 	TheTest (BaflUtils::FileExists (TheFs, KFilename26) == EFalse);
       
   431 	TheTest (BaflUtils::FileExists (TheFs, KFilename27) == EFalse);
       
   432 	TheTest (BaflUtils::FileExists (TheFs, KFilename28) == EFalse);
       
   433 	TheTest (BaflUtils::FileExists (TheFs, KNearestLang) == EFalse);
       
   434 
       
   435 	// Create the files...
       
   436 	RFile rFile;
       
   437 	// KFilename1 can't be created
       
   438 	rFile.Create (TheFs, KFilename2, EFileRead);
       
   439 	rFile.Close ();
       
   440 	rFile.Create (TheFs, KFilename3, EFileRead);
       
   441 	rFile.Close ();
       
   442 	rFile.Create (TheFs, KFilename4, EFileRead);
       
   443 	rFile.Close ();
       
   444 	rFile.Create (TheFs, KFilename5, EFileRead);
       
   445 	rFile.Close ();
       
   446 	rFile.Create (TheFs, KFilename6, EFileRead);
       
   447 	rFile.Close ();
       
   448 	rFile.Create (TheFs, KFilename7, EFileRead);
       
   449 	rFile.Close ();
       
   450 
       
   451 	rFile.Create (TheFs, KFilename10, EFileRead);
       
   452 	rFile.Close ();
       
   453 	rFile.Create (TheFs, KFilename11, EFileRead);
       
   454 	rFile.Close ();
       
   455 	rFile.Create (TheFs, KFilename12, EFileRead);
       
   456 	rFile.Close ();
       
   457 	rFile.Create (TheFs, KFilename13, EFileRead);
       
   458 	rFile.Close ();
       
   459 	rFile.Create (TheFs, KFilename14, EFileRead);
       
   460 	rFile.Close ();
       
   461 	rFile.Create (TheFs, KFilename15, EFileRead);
       
   462 	rFile.Close ();
       
   463 	rFile.Create (TheFs, KFilename16, EFileRead);
       
   464 	rFile.Close ();
       
   465 	rFile.Create (TheFs, KFilename17, EFileRead);
       
   466 	rFile.Close ();
       
   467 	rFile.Create (TheFs, KFilename18, EFileRead);
       
   468 	rFile.Close ();
       
   469 	rFile.Create (TheFs, KFilename19, EFileRead);
       
   470 	rFile.Close ();
       
   471 	rFile.Create (TheFs, KFilename20, EFileRead);
       
   472 	rFile.Close ();
       
   473 	rFile.Create (TheFs, KFilename21, EFileRead);
       
   474 	rFile.Close ();
       
   475 	rFile.Create (TheFs, KFilename22, EFileRead);
       
   476 	rFile.Close ();
       
   477 	rFile.Create (TheFs, KFilename23, EFileRead);
       
   478 	rFile.Close ();
       
   479 	rFile.Create (TheFs, KFilename24, EFileRead);
       
   480 	rFile.Close ();
       
   481 	rFile.Create (TheFs, KFilename25, EFileRead);
       
   482 	rFile.Close ();
       
   483 	rFile.Create (TheFs, KFilename26, EFileRead);
       
   484 	rFile.Close ();
       
   485 	rFile.Create (TheFs, KFilename27, EFileRead);
       
   486 	rFile.Close ();
       
   487 	rFile.Create (TheFs, KFilename28, EFileRead);
       
   488 	rFile.Close ();
       
   489 	rFile.Create (TheFs, KNearestLang, EFileRead);
       
   490 	rFile.Close ();
       
   491 
       
   492 	TBuf <256> filename (KFilename1);
       
   493 
       
   494 	// Test the defect...
       
   495 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   496 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename1, &filename);
       
   497 	TheTest(filename == KFilename1);
       
   498 
       
   499 	filename.Copy (KFilename2);
       
   500 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   501 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename2, &filename);
       
   502 	TheTest(filename == _L("x"));
       
   503 
       
   504 	filename.Copy (KFilename3);
       
   505 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   506 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename3, &filename);
       
   507 	TheTest(filename == KFilename3);
       
   508 
       
   509 	filename.Copy (KFilename4);
       
   510 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   511 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename4, &filename);
       
   512 	TheTest(filename == KFilename4);
       
   513 
       
   514 	filename.Copy (KFilename5);
       
   515 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   516 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename5, &filename);
       
   517 	TheTest(filename == KFilename5);
       
   518 
       
   519 	filename.Copy (KFilename6);
       
   520 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   521 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename6, &filename);
       
   522 	TheTest(filename == KFilename6);
       
   523 
       
   524 	filename.Copy (KFilename7);
       
   525 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   526 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename7, &filename);
       
   527 	TheTest(filename == KFilename7);
       
   528 
       
   529 
       
   530 
       
   531 	filename.Copy (KFilename10);
       
   532 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   533 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename10, &filename);
       
   534 	TheTest(filename == KFilename10);
       
   535 
       
   536 	filename.Copy (KFilename11);
       
   537 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   538 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename11, &filename);
       
   539 	TheTest(filename == KFilename11);
       
   540 
       
   541 	filename.Copy (KFilename12);
       
   542 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   543 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename12, &filename);
       
   544 	TheTest(filename == KFilename12);
       
   545 
       
   546 	filename.Copy (KFilename13);
       
   547 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   548 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename13, &filename);
       
   549 	TheTest(filename == KFilename13);
       
   550 
       
   551 	filename.Copy (KFilename14);
       
   552 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   553 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename14, &filename);
       
   554 	TheTest(filename == KFilename14);
       
   555 
       
   556 	filename.Copy (KFilename15);
       
   557 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   558 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename15, &filename);
       
   559 	TheTest(filename == KFilename15);
       
   560 
       
   561 	filename.Copy (KFilename16);
       
   562 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   563 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename16, &filename);
       
   564 	TheTest(filename == KFilename16);
       
   565 
       
   566 	filename.Copy (KFilename17);
       
   567 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   568 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename17, &filename);
       
   569 	TheTest(filename == KFilename17);
       
   570 
       
   571 	filename.Copy (KFilename18);
       
   572 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   573 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename18, &filename);
       
   574 	TheTest(filename == KFilename18);
       
   575 
       
   576 	filename.Copy (KFilename19);
       
   577 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   578 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename19, &filename);
       
   579 	TheTest(filename == KFilename19);
       
   580 
       
   581 	filename.Copy (KFilename20);
       
   582 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   583 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename20, &filename);
       
   584 	TheTest(filename == KFilename20);
       
   585 
       
   586 	filename.Copy (KFilename21);
       
   587 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   588 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename21, &filename);
       
   589 	TheTest(filename == KFilename21);
       
   590 
       
   591 	filename.Copy (KFilename22);
       
   592 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   593 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename22, &filename);
       
   594 	TheTest(filename == KFilename22);
       
   595 
       
   596 	filename.Copy (KFilename23);
       
   597 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   598 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename23, &filename);
       
   599 	TheTest(filename == KFilename23);
       
   600 
       
   601 	filename.Copy (KFilename24);
       
   602 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   603 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename24, &filename);
       
   604 	TheTest(filename == KFilename24);
       
   605 
       
   606 	filename.Copy (KFilename25);
       
   607 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   608 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename25, &filename);
       
   609 	TheTest(filename == KFilename25);
       
   610 
       
   611 	filename.Copy (KFilename26);
       
   612 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   613 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename26, &filename);
       
   614 	TheTest(filename == KFilename26);
       
   615 
       
   616 	filename.Copy (KFilename27);
       
   617 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   618 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename27, &filename);
       
   619 	TheTest(filename == KFilename27);
       
   620 
       
   621 	filename.Copy (KFilename28);
       
   622 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   623 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename28, &filename);
       
   624 	TheTest(filename == KFilename28);
       
   625 
       
   626 
       
   627 	// Store the original locale settings so they can be restored at the
       
   628 	// end of the test.
       
   629 
       
   630 	TExtendedLocale originalLocale;
       
   631 	originalLocale.LoadSystemSettings();
       
   632 
       
   633 	// Change locale
       
   634 	TExtendedLocale newLocale;
       
   635 	TBuf<50> libraryName;
       
   636 
       
   637 	libraryName.Format(KLocale);
       
   638 
       
   639 	TInt err = newLocale.LoadLocale(libraryName);
       
   640 	User::LeaveIfError (err);
       
   641 
       
   642 	newLocale.SaveSystemSettings();
       
   643 	User::After (5000000);
       
   644 
       
   645 	filename.Copy (KFilename1);
       
   646 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   647 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename1, &filename);
       
   648 	TheTest(filename == KFilename1);
       
   649 
       
   650 	filename.Copy (KFilename2);
       
   651 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   652 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename2, &filename);
       
   653 	TheTest(filename == _L("x"));
       
   654 
       
   655 	filename.Copy (KFilename3);
       
   656 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   657 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename3, &filename);
       
   658 	TheTest(filename == KFilename3);
       
   659 
       
   660 	filename.Copy (KFilename4);
       
   661 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   662 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename4, &filename);
       
   663 	TheTest(filename == KFilename4);
       
   664 
       
   665 	filename.Copy (KFilename5);
       
   666 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   667 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename5, &filename);
       
   668 	TheTest(filename == KFilename5);
       
   669 
       
   670 	filename.Copy (KFilename6);
       
   671 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   672 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename6, &filename);
       
   673 	TheTest(filename == KFilename6);
       
   674 
       
   675 	filename.Copy (KFilename7);
       
   676 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   677 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename7, &filename);
       
   678 	TheTest(filename == KFilename7);
       
   679 
       
   680 
       
   681 
       
   682 	filename.Copy (KFilename10);
       
   683 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   684 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename10, &filename);
       
   685 	TheTest(filename == KFilename10);
       
   686 
       
   687 	filename.Copy (KFilename11);
       
   688 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   689 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename11, &filename);
       
   690 	TheTest(filename == KFilename11);
       
   691 
       
   692 	filename.Copy (KFilename12);
       
   693 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   694 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename12, &filename);
       
   695 	TheTest(filename == KFilename12);
       
   696 
       
   697 	filename.Copy (KFilename13);
       
   698 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   699 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename13, &filename);
       
   700 	TheTest(filename == KFilename13);
       
   701 
       
   702 	filename.Copy (KFilename14);
       
   703 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   704 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename14, &filename);
       
   705 	TheTest(filename == KFilename14);
       
   706 
       
   707 	filename.Copy (KFilename15);
       
   708 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   709 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename15, &filename);
       
   710 	TheTest(filename == KFilename15);
       
   711 
       
   712 	filename.Copy (KFilename16);
       
   713 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   714 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename16, &filename);
       
   715 	TheTest(filename == KFilename16);
       
   716 
       
   717 	filename.Copy (KFilename17);
       
   718 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   719 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename17, &filename);
       
   720 	TheTest(filename == KFilename17);
       
   721 
       
   722 	filename.Copy (KFilename18);
       
   723 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   724 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename18, &filename);
       
   725 	TheTest(filename == KFilename18);
       
   726 
       
   727 	filename.Copy (KFilename19);
       
   728 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   729 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename19, &filename);
       
   730 	TheTest(filename == KFilename19);
       
   731 
       
   732 	filename.Copy (KFilename20);
       
   733 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   734 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename20, &filename);
       
   735 	TheTest(filename == KFilename20);
       
   736 
       
   737 	filename.Copy (KFilename21);
       
   738 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   739 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename21, &filename);
       
   740 	TheTest(filename == KNearestLang);
       
   741 
       
   742 	filename.Copy (KFilename22);
       
   743 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   744 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename22, &filename);
       
   745 	TheTest(filename == KNearestLang);
       
   746 
       
   747 	filename.Copy (KFilename23);
       
   748 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   749 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename23, &filename);
       
   750 	TheTest(filename == KFilename23);
       
   751 
       
   752 	filename.Copy (KFilename24);
       
   753 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   754 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename24, &filename);
       
   755 	TheTest(filename == KFilename24);
       
   756 
       
   757 	filename.Copy (KFilename25);
       
   758 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   759 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename25, &filename);
       
   760 	TheTest(filename == KFilename25);
       
   761 
       
   762 	filename.Copy (KFilename26);
       
   763 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   764 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename26, &filename);
       
   765 	TheTest(filename == KFilename26);
       
   766 
       
   767 	filename.Copy (KFilename27);
       
   768 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   769 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename27, &filename);
       
   770 	TheTest(filename == KFilename27);
       
   771 
       
   772 	filename.Copy (KFilename28);
       
   773 	BaflUtils::NearestLanguageFile (TheFs, filename);
       
   774 	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename28, &filename);
       
   775 	TheTest(filename == KFilename28);
       
   776 
       
   777 	// Tidy the files...
       
   778 	// KFilename1 can't be created
       
   779 	BaflUtils::DeleteFile (TheFs, KFilename2);
       
   780 	BaflUtils::DeleteFile (TheFs, KFilename3);
       
   781 	BaflUtils::DeleteFile (TheFs, KFilename4);
       
   782 	BaflUtils::DeleteFile (TheFs, KFilename5);
       
   783 	BaflUtils::DeleteFile (TheFs, KFilename6);
       
   784 
       
   785 	// Do not delete KFileName7, there may be other
       
   786  	// files in this directory unrelated to this test
       
   787  	// which are required by other tests.
       
   788  	// See defect DEF108808
       
   789  	// BaflUtils::DeleteFile (TheFs, KFilename7);
       
   790 
       
   791 	BaflUtils::DeleteFile (TheFs, KFilename10);
       
   792 	BaflUtils::DeleteFile (TheFs, KFilename11);
       
   793 	BaflUtils::DeleteFile (TheFs, KFilename12);
       
   794 	BaflUtils::DeleteFile (TheFs, KFilename13);
       
   795 	BaflUtils::DeleteFile (TheFs, KFilename14);
       
   796 	BaflUtils::DeleteFile (TheFs, KFilename15);
       
   797 	BaflUtils::DeleteFile (TheFs, KFilename16);
       
   798 	BaflUtils::DeleteFile (TheFs, KFilename17);
       
   799 	BaflUtils::DeleteFile (TheFs, KFilename18);
       
   800 	BaflUtils::DeleteFile (TheFs, KFilename19);
       
   801 	BaflUtils::DeleteFile (TheFs, KFilename20);
       
   802 	BaflUtils::DeleteFile (TheFs, KFilename21);
       
   803 	BaflUtils::DeleteFile (TheFs, KFilename22);
       
   804 	BaflUtils::DeleteFile (TheFs, KFilename23);
       
   805 #ifdef __EPOC32__
       
   806 	BaflUtils::DeleteFile (TheFs, KFilename24);
       
   807 #else
       
   808 	// Windows strips off trailing periods
       
   809 	BaflUtils::DeleteFile (TheFs, _L("C:\\System\\Data\\klmn"));
       
   810 #endif
       
   811 	BaflUtils::DeleteFile (TheFs, KFilename25);
       
   812 	BaflUtils::DeleteFile (TheFs, KFilename26);
       
   813 	BaflUtils::DeleteFile (TheFs, KFilename27);
       
   814 	BaflUtils::DeleteFile (TheFs, KFilename28);
       
   815 	BaflUtils::DeleteFile (TheFs, KNearestLang);
       
   816 
       
   817 	// Restore the original locale settings.
       
   818   	originalLocale.SaveSystemSettings();
       
   819 
       
   820 	CleanupStack::PopAndDestroy (&::TheFs);
       
   821 
       
   822 	// The Test Ends...
       
   823 	//
       
   824 
       
   825 	// check that no handles have leaked
       
   826 	TInt endProcessHandleCount;
       
   827 	TInt endThreadHandleCount;
       
   828 	RThread ().HandleCount (endProcessHandleCount, endThreadHandleCount);
       
   829 
       
   830 	TheTest (startThreadHandleCount == endThreadHandleCount);
       
   831 
       
   832 	__UHEAP_MARKEND;
       
   833 	}
       
   834 
       
   835 //===============================================================================
       
   836 
       
   837 /**
       
   838 Initialise the cleanup stack and active scheduler
       
   839 */
       
   840 LOCAL_C void SetupL ()
       
   841     {
       
   842 	TheTrapCleanup = CTrapCleanup::New ();
       
   843 	User::LeaveIfNull (TheTrapCleanup);
       
   844 
       
   845 	// Construct and install the active scheduler
       
   846 	TheActiveScheduler = new (ELeave) CActiveScheduler;
       
   847 	CActiveScheduler::Install (TheActiveScheduler);
       
   848 	}
       
   849 
       
   850 /**
       
   851 Cleanup
       
   852 */
       
   853 LOCAL_C void CleanupL ()
       
   854     {
       
   855 	delete TheActiveScheduler;
       
   856 	delete TheTrapCleanup;
       
   857 	}
       
   858 
       
   859 
       
   860 /**
       
   861 Invoke the tests
       
   862 */
       
   863 LOCAL_C void DoTestsL ()
       
   864     {
       
   865 	Defect_INC045169L ();
       
   866 	Defect_DEF068052L ();
       
   867 	
       
   868 	Defect_INC120743L ();
       
   869 	}
       
   870 
       
   871 GLDEF_C TInt E32Main ()
       
   872 	{
       
   873 	__UHEAP_MARK;
       
   874 
       
   875 	TheTest.Printf (_L ("\n"));
       
   876 	TheTest.Title ();
       
   877 	TheTest.Start (_L("Defect Tests "));
       
   878 
       
   879 	TRAPD (err, SetupL ());
       
   880 	TheTest (err == KErrNone);
       
   881 
       
   882 	TRAP (err, DoTestsL ());
       
   883 	TheTest (err == KErrNone);
       
   884 
       
   885 	CleanupL ();
       
   886 
       
   887 	TheTest.End ();
       
   888 	TheTest.Close ();
       
   889 
       
   890 	__UHEAP_MARKEND;
       
   891 	return (KErrNone);
       
   892 	}