sl@0: // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: // This file contains RTest based tests which check flexibility of Locale.
sl@0: // That are, 1. Selectable from Multiple Dlls 2. Loaded all from a single Dll
sl@0: // 
sl@0: //
sl@0: 
sl@0: #include <bautils.h>
sl@0: #include <f32file.h>
sl@0: #include <e32cmn.h>
sl@0: #include <e32test.h>
sl@0: #include <e32std.h>
sl@0: #include <e32const.h>
sl@0: #include <babackup.h>
sl@0: #include <hal.h>
sl@0: #include <centralrepository.h>
sl@0: #include "LocaleRepository.h"
sl@0: #include "InitialiseLocale.h"
sl@0: 
sl@0: 
sl@0: // Name of the exe to be called explicitly
sl@0: _LIT(KInitPersistLocaleExeName, "InitialiseLocale.exe");
sl@0: _LIT(KFrenchLocale, "elocl.02");
sl@0: 
sl@0: _LIT(KSpanishLocale, "elocl.04");
sl@0: 
sl@0: // Central Repository Data cage file-path
sl@0: _LIT(KPersistLocale, "C:\\private\\10202be9\\persists\\1020E4D3.*");
sl@0: 
sl@0: LOCAL_D RTest TheTest(_L("T_LocaleFlexiOldLocaleModel"));
sl@0: 
sl@0: RFs TheFs;
sl@0: 
sl@0: TExtendedLocale initialExtendedLocale;
sl@0: 
sl@0: 
sl@0: void GetInitialLocaleSettings()
sl@0: 	{
sl@0: 	initialExtendedLocale.LoadSystemSettings() ;
sl@0: 	}
sl@0: 
sl@0: void RestoreInitialLocaleSettings()
sl@0: 	{
sl@0: 	initialExtendedLocale.SaveSystemSettings() ;
sl@0: 	User::After(1000000);
sl@0: 	}
sl@0: 
sl@0: //Test macros and functions
sl@0: 
sl@0: LOCAL_C void Check(TInt aValue, TInt aLine)
sl@0: 	{
sl@0: 	if(!aValue)
sl@0: 		{
sl@0: 		RestoreInitialLocaleSettings();
sl@0: 		TheTest(EFalse, aLine);
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
sl@0: 	{
sl@0: 	if(aValue != aExpected)
sl@0: 		{
sl@0: 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
sl@0: 		RestoreInitialLocaleSettings();
sl@0: 		TheTest(EFalse, aLine);
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: 
sl@0: #define TEST(arg) ::Check((arg), __LINE__)
sl@0: #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
sl@0: 
sl@0: /*
sl@0: This function prepares for next test i.e, tests InitialiseLocale behaves
sl@0: when persisted file is damaged/corrupt.
sl@0: */
sl@0: void SetUpTestCorruptLocale()
sl@0: 	{
sl@0: 	TExtendedLocale myExtendedLocale;
sl@0: 	myExtendedLocale.LoadSystemSettings() ;
sl@0: 
sl@0: 	TBuf<100> DllName;
sl@0: 	DllName.Copy(KFrenchLocale);
sl@0: 
sl@0: 	TheTest.Printf(_L("\n Changing Locale to French Locale(02) so that default values are evident"));
sl@0: 
sl@0: 	// Change the locale to Default Locale, all settings from single Dll
sl@0: 	myExtendedLocale.LoadLocale(DllName);
sl@0: 
sl@0: 	// Save the changes to system settings
sl@0: 	myExtendedLocale.SaveSystemSettings();
sl@0: 
sl@0: 	// Wait so that it persists to repository
sl@0: 	User::After(1000000);
sl@0: 
sl@0: 	User::LeaveIfError(TheFs.Connect());
sl@0: 	// Delete/damage the persisted file so that InitialiseLocale.exe
sl@0: 	// detects the damage and loads default locale
sl@0: 	BaflUtils::DeleteFile(TheFs, KPersistLocale);
sl@0: 	TheFs.Close();
sl@0: 	TheTest.Printf(_L("\n Deleted persist file from C: \n"));
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID		SYSLIB-BAFL-CIT-0140
sl@0: @SYMTestCaseDesc 	Check that locale settings can be selected from several DLLs
sl@0: @SYMTestPriority 	High
sl@0: @SYMTestActions  	Ensure that locales are selected, system set and persisted
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMREQ PREQ1001
sl@0: */
sl@0: LOCAL_D	void ChangeLocaleMultiDll()
sl@0: 	{
sl@0: 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CIT-0140 \nTest to demonstrate Locale settings by multiple DLLs "));
sl@0: 
sl@0: 	TExtendedLocale myExtendedLocale;
sl@0: 	myExtendedLocale.LoadSystemSettings();
sl@0: 
sl@0: 	TBuf<100> DllName1 ;
sl@0: 	DllName1.Copy(KFrenchLocale);
sl@0: 
sl@0: 	TBuf<100> DllName2 ;
sl@0: 	DllName2.Copy(KSpanishLocale);
sl@0: 
sl@0: 	TheTest.Printf(_L("Changing Language to Spanish "));
sl@0: 
sl@0: 	// Load the language settings of French
sl@0: 	myExtendedLocale.LoadLocaleAspect(ELocaleLanguageSettings, DllName1);
sl@0: 
sl@0: 
sl@0: 	// Load system charset of French
sl@0: 	myExtendedLocale.LoadLocaleAspect(ELocaleCollateSetting, DllName1);
sl@0: 
sl@0: 	// Load TLocale settings, currency symbols of Spanish
sl@0: 	myExtendedLocale.LoadLocaleAspect(ELocaleLocaleSettings, DllName2);
sl@0: 
sl@0: 	// Load time and date display formats of Spanish
sl@0: 	myExtendedLocale.LoadLocaleAspect(ELocaleTimeDateSettings, DllName2);
sl@0: 
sl@0: 	// Save to system settings
sl@0: 	myExtendedLocale.SaveSystemSettings();
sl@0: 
sl@0: 	// Wait
sl@0: 	User::After(1000000);
sl@0: 
sl@0: 	TUid LocaleRepositoryUid ;
sl@0: 	LocaleRepositoryUid.iUid = KLocalePersistRepositoryUid ;
sl@0: 
sl@0: 	CRepository* repository = CRepository::NewLC(LocaleRepositoryUid);
sl@0: 
sl@0: 	// To get names of DLLs to be loaded
sl@0: 	TBuf<100> aDllName ;
sl@0: 
sl@0: 	// Test the language settings
sl@0: 	TInt err = repository->Get(KLocaleLanguageDll, aDllName);
sl@0: 	if (err != KErrNone)
sl@0: 		{
sl@0: 		// Oops! I hit it again
sl@0: 		CleanupStack::PopAndDestroy(repository) ;
sl@0: 		return ;
sl@0: 		}
sl@0: 
sl@0: 
sl@0: 	TheTest.Printf(_L("\nTested for language French(02): %S "), &aDllName);
sl@0: 
sl@0: 	// in this case we are only interested in the name "eloc.XX"
sl@0: 
sl@0: 	TEST(DllName1.CompareF(aDllName.Right(8)) == 0);
sl@0: 
sl@0: 
sl@0: 	// Test system charset changes
sl@0: 	err = repository->Get(KLocaleCollationDll, aDllName);
sl@0: 	if (err != KErrNone)
sl@0: 		{
sl@0: 		// Oops! I hit it again
sl@0: 		CleanupStack::PopAndDestroy(repository) ;
sl@0: 		return ;
sl@0: 		}
sl@0: 	TheTest.Printf(_L("\nTested for Char set of French(02): %S"), &aDllName);
sl@0: 	TEST(DllName1.CompareF(aDllName.Right(8))==0);
sl@0: 
sl@0: 	// Test TLocale settings, currency symbols
sl@0: 	err = repository->Get(KLocaleLocaleDll, aDllName) ;
sl@0: 		if (err != KErrNone)
sl@0: 		{
sl@0: 		// Oops! I hit it again
sl@0: 		CleanupStack::PopAndDestroy(repository) ;
sl@0: 		return ;
sl@0: 		}
sl@0: 	TheTest.Printf(_L("\nTested for Locale of Spanish(04): %S"), &aDllName);
sl@0: 	TEST(DllName2.CompareF(aDllName.Right(8))==0);
sl@0: 
sl@0: 	// Test time and date display formats
sl@0: 	err = repository->Get(KLocaleTimeDateDll, aDllName) ;
sl@0: 		if (err != KErrNone)
sl@0: 		{
sl@0: 		// Oops! I hit it again
sl@0: 		CleanupStack::PopAndDestroy(repository) ;
sl@0: 		return ;
sl@0: 		}
sl@0: 	TheTest.Printf(_L("\nTested for Time and date format of Spanish(04): %S\n"), &aDllName);
sl@0: 	TEST(DllName2.CompareF(aDllName.Right(8))==0);
sl@0: 
sl@0: 	// Free the central repository object
sl@0: 	CleanupStack::PopAndDestroy (repository);
sl@0: 	TheTest.End() ;
sl@0: 	
sl@0:     //becasue we check whether locale content can be persisted is the system in this code block , we mark this test case here.
sl@0: 	TheTest.Start(_L(" @SYMTestCaseID:TI18N-INITLOCALE-CT-4007 persist system locale content"));
sl@0: 	TheTest.End();
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID		SYSLIB-BAFL-CIT-0141
sl@0: @SYMTestCaseDesc 	Check that locale settings can be selected from single DLL
sl@0: @SYMTestPriority 	High
sl@0: @SYMTestActions  	Ensure that all settings are loaded from a DLL, system set and persisted
sl@0: @SYMTestExpectedResults The test must not fail.
sl@0: @SYMREQ PREQ1001
sl@0: */
sl@0: LOCAL_D void ChangeLocaleSingleDll()
sl@0: 	{
sl@0: 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CIT-0141 Test to demonstrate change of Locale from single DLL "));
sl@0: 
sl@0: 	TExtendedLocale myExtendedLocale;
sl@0: 	myExtendedLocale.LoadSystemSettings() ;
sl@0: 
sl@0: 	TBuf<100> DllName;
sl@0: 	DllName.Copy(KSpanishLocale);
sl@0: 
sl@0: 	TheTest.Printf(_L("Changing Locale to Spanish"));
sl@0: 
sl@0: 	// Change the locale to French Locale, all settings from single Dll
sl@0: 	myExtendedLocale.LoadLocale(DllName);
sl@0: 
sl@0: 	// Save the changes to system settings
sl@0: 	myExtendedLocale.SaveSystemSettings();
sl@0: 
sl@0: 	// Wait
sl@0: 	User::After(1000000);
sl@0: 
sl@0: 	TUid LocaleRepositoryUid ;
sl@0: 	LocaleRepositoryUid.iUid = KLocalePersistRepositoryUid;
sl@0: 	CRepository* repository = CRepository::NewLC(LocaleRepositoryUid) ;
sl@0: 
sl@0: 	// To get names of DLLs to be loaded
sl@0: 	TBuf<100> aDllName ;
sl@0: 
sl@0: 	// Test for the language settings
sl@0: 	TInt err = repository->Get(KLocaleLanguageDll, aDllName);
sl@0: 	if (err != KErrNone)
sl@0: 		{
sl@0: 		// Failed to read DLL name, bail out!
sl@0: 		CleanupStack::PopAndDestroy(repository) ;
sl@0: 		return ;
sl@0: 		}
sl@0: 	TheTest.Printf(_L("\nTested for Locale settings loaded by single Dll: %S"), &aDllName);
sl@0: 	TEST(DllName.CompareF(aDllName.Right(8))==0);
sl@0: 
sl@0: 	CleanupStack::PopAndDestroy (repository);
sl@0: 	TheTest.End();
sl@0: 	}
sl@0: 
sl@0: // Call the tests that test flexibility of Locale
sl@0: void TestLocaleFlexibility()
sl@0: 	{
sl@0: 	RProcess process;
sl@0: 
sl@0: 	GetInitialLocaleSettings() ;
sl@0: 
sl@0: 	// Kick-in InitialiseLocale.exe, This will be done as part of system start in actual
sl@0: 	// release code!
sl@0: 	TInt r = process.Create(KInitPersistLocaleExeName, KNullDesC);
sl@0: 	if(r == KErrNone)
sl@0: 		{
sl@0: 		process.Resume(); // Start the process going
sl@0: 		User::After(1000000);
sl@0: 
sl@0: 		ChangeLocaleMultiDll();
sl@0: 		ChangeLocaleSingleDll();
sl@0: 
sl@0: 		User::After(1000000);
sl@0: 		process.Close();
sl@0: 		User::After(1000000);
sl@0: 		}
sl@0: 
sl@0: 	RestoreInitialLocaleSettings() ;
sl@0: 
sl@0:     User::After(1000000);
sl@0:     // Set up for next test
sl@0:     SetUpTestCorruptLocale();
sl@0: 	}
sl@0: 
sl@0: 
sl@0: TInt E32Main()
sl@0: 	{
sl@0: 	CTrapCleanup* cleanup = CTrapCleanup::New();
sl@0: 	TEST(cleanup != NULL);
sl@0: 
sl@0: 	__UHEAP_MARK;
sl@0: 	TheTest.Start(_L("Test to demonstrate Locale flexibility in old locale model"));
sl@0: 	TheTest.Title();
sl@0: 
sl@0: 	TRAPD(err, ::TestLocaleFlexibility());
sl@0: 
sl@0: 	TEST2(err, KErrNone);
sl@0: 
sl@0: 	TheTest.End();
sl@0: 	TheTest.Close();
sl@0: 
sl@0: 	__UHEAP_MARKEND;
sl@0: 	delete cleanup;
sl@0: 
sl@0: 	return(KErrNone);
sl@0: 	}