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: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "LocaleRepository.h" sl@0: #include "InitialiseLocale.h" sl@0: sl@0: sl@0: _LIT(KInitialiseLocaleExeName, "InitialiseLocale.exe"); sl@0: sl@0: // Symbian VendorID as specified in sl@0: // "Platform security engineering guide" Section 2.1.3.2 sl@0: const TVendorId KSymbianVendorId(0x70000001); sl@0: sl@0: RTest TheTest(_L("T_Initialise_Locale")); sl@0: sl@0: // const TInt KDefaultCountryCode = 29 ; sl@0: const TInt KNewCountryCode = 46 ; sl@0: TInt defaultCountryCode ; sl@0: sl@0: TCurrencySymbol defaultCurrencySymbol; sl@0: sl@0: _LIT(KCurrencySymbol, "ABC") ; sl@0: TBuf<8> KNewCurrencySymbol (KCurrencySymbol) ; sl@0: sl@0: _LIT(KLongDateFormat, "%F%*D%X %N %Y") ; sl@0: TBuf<20> KDefaultLongDateFormat (KLongDateFormat) ; sl@0: sl@0: _LIT(KShortDateFormat, "%F%*D/%*M/%Y") ; sl@0: TBuf<20> KDefaultShortDateFormat (KShortDateFormat) ; sl@0: sl@0: _LIT(KTimeFormat, "%F%*I:%T:%S %*A") ; sl@0: TBuf<20> KDefaultTimeFormat (KTimeFormat) ; sl@0: sl@0: TExtendedLocale initialExtendedLocale; 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: LOCAL_C void Check(TPtrC aValue, TPtrC aExpected, TInt aLine) sl@0: { sl@0: if(aValue != aExpected) sl@0: { sl@0: RDebug::Print(_L("*** Expected error: %S, got: %S\r\n"), &aExpected, &aValue); sl@0: RestoreInitialLocaleSettings(); sl@0: TheTest(EFalse, aLine); 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: #define TEST3(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-BAFL-CIT-0200 sl@0: @SYMTestCaseDesc Check that default locale values are loaded on startup. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Ensure that country code in system locale data matches value in persisted data sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ PREQ1003 sl@0: */ sl@0: void CheckDefaultLocaleCountryCode() sl@0: { sl@0: TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CIT-0200 Check default country code ")); sl@0: sl@0: TExtendedLocale myExtendedLocale; sl@0: myExtendedLocale.LoadSystemSettings() ; sl@0: TLocale* myLocale = myExtendedLocale.GetLocale() ; sl@0: TInt countryCode = myLocale->CountryCode(); sl@0: TheTest.Printf(_L("Default Country code is %d\n"), defaultCountryCode) ; sl@0: TheTest.Printf(_L("Current Country code is %d\n"), countryCode) ; sl@0: sl@0: TEST2(countryCode, defaultCountryCode) ; sl@0: TheTest.End(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-3160 sl@0: @SYMTestCaseDesc Check that default locale values i.e. Currency Symbol and long date, short date & time format. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Ensure that these values are set to the default values as defined. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ PREQ1003 sl@0: */ sl@0: void CheckDefaultLocaleValues() sl@0: { sl@0: TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-3160 Check default Locale Values ")); sl@0: TExtendedLocale myExtendedLocale; sl@0: myExtendedLocale.LoadSystemSettings() ; sl@0: sl@0: TPtrC currencySymbolPtr = myExtendedLocale.GetCurrencySymbol(); sl@0: TPtrC longDateFormatPtr = myExtendedLocale.GetLongDateFormatSpec(); sl@0: TPtrC shortDateFormatPtr = myExtendedLocale.GetShortDateFormatSpec(); sl@0: TPtrC timeFormatPtr = myExtendedLocale.GetTimeFormatSpec(); sl@0: sl@0: TheTest.Printf(_L("New Currency Symbol is %S \n"), ¤cySymbolPtr); sl@0: TheTest.Printf(_L("Default Long Date Format is %S \n"), &longDateFormatPtr); sl@0: TheTest.Printf(_L("Default Short Date Format is %S \n"), &shortDateFormatPtr); sl@0: TheTest.Printf(_L("Default Time Format is %S \n"), &timeFormatPtr); sl@0: sl@0: TPtrC expectedCurrSymPtr(KNewCurrencySymbol); sl@0: TEST3(currencySymbolPtr, expectedCurrSymPtr); sl@0: sl@0: TPtrC expectedlongDatePtr(KDefaultLongDateFormat); sl@0: TEST3(longDateFormatPtr, expectedlongDatePtr); sl@0: sl@0: TPtrC expectedShortDatePtr(KDefaultShortDateFormat); sl@0: TEST3(shortDateFormatPtr, expectedShortDatePtr); sl@0: sl@0: TPtrC expectedTimePtr(KDefaultTimeFormat); sl@0: TEST3(timeFormatPtr, expectedTimePtr); sl@0: sl@0: TheTest.End(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-BAFL-CIT-0201 sl@0: @SYMTestCaseDesc Check that locale settings can be saved to and read from system locale data through TExtendedLocale. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Change a number of locale values, write to system data, read back from data, check result sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ PREQ1003 sl@0: */ sl@0: void ChangeLocaleCountryCode() sl@0: { sl@0: TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CIT-0201 Define a TLocale ")); sl@0: TheTest.Next(_L("Setting CountryCode")); sl@0: sl@0: TExtendedLocale myExtendedLocale; sl@0: myExtendedLocale.LoadSystemSettings() ; sl@0: TLocale* myLocale = myExtendedLocale.GetLocale() ; sl@0: TheTest.Printf(_L("Setting Country code to %d\n"), KNewCountryCode) ; sl@0: myLocale->SetCountryCode(KNewCountryCode); sl@0: TheTest.Printf(_L("Saving new settings to system locale data\n")) ; sl@0: myExtendedLocale.SaveSystemSettings() ; sl@0: TheTest.Printf(_L("Loading new settings from system locale data\n")) ; sl@0: myExtendedLocale.LoadSystemSettings() ; sl@0: myLocale = myExtendedLocale.GetLocale() ; sl@0: TInt countryCode = myLocale->CountryCode() ; sl@0: TheTest.Printf(_L("New Country code is %d\n"), countryCode) ; sl@0: TEST2(countryCode, KNewCountryCode) ; sl@0: TheTest.End(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-BAFL-CIT-188 sl@0: @SYMTestCaseDesc Check that locale settings are saved into central repository. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Ensure that locale data stored in the central repository match the data in the system locale sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ PREQ1003 sl@0: */ sl@0: void CheckRepositoryLocaleCountryCode(CRepository *repository) sl@0: { sl@0: TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CIT-188 Checking persisted country code ")); sl@0: TInt datacageCountryCode; sl@0: TheTest.Printf(_L("Getting repository data cage\n")) ; sl@0: TInt err = repository->Get(KLocaleCountryCode, datacageCountryCode) ; sl@0: TEST2(err, KErrNone); sl@0: TheTest.Printf(_L("Country code from repository = %d\n"), datacageCountryCode) ; sl@0: TEST2(datacageCountryCode, KNewCountryCode) ; sl@0: TheTest.End(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-4051 sl@0: @SYMTestCaseDesc Check that the VendorID is set to 0x70000001 (Symbian's VendorID) sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions 1. Create a process for InitialiseLocale.exe sl@0: 2. Compare the processes VID against the expected VID (0x70000001) sl@0: @SYMTestExpectedResults The VIDs should be identical and so the test will pass. sl@0: @SYMDEF INC121403 sl@0: */ sl@0: void TestVendorIdINC121403(RProcess& aProcess) sl@0: { sl@0: TheTest.Next (_L ("TestVendorIDINC121403")); sl@0: sl@0: // Test that the VendorID of InitialiseLocale.exe is set to the Symbian VendorID sl@0: TEST2(KSymbianVendorId.iId, aProcess.VendorId().iId); sl@0: } sl@0: sl@0: /** sl@0: Sets up the Currency Symbol test. Outputs default values then sets the Currency Symbol sl@0: to a test value ("ABC") and stores this value in the repository, before InitialiseLocale has run. sl@0: */ sl@0: void ChangeLocaleCurrencySymbol(CRepository *repository, TCurrencySymbol & defaultCurrencySymbol) sl@0: { sl@0: TheTest.Start(_L("Setting CurrencySymbol\n")); sl@0: sl@0: TExtendedLocale myExtendedLocale; sl@0: myExtendedLocale.LoadSystemSettings() ; sl@0: sl@0: TheTest.Printf(_L("Default Currency Symbol is: %S\n"), &defaultCurrencySymbol); sl@0: sl@0: TCurrencySymbol datacageCurrencySymbol; sl@0: TInt err = repository->Get(KLocaleCurrencySymbol, datacageCurrencySymbol) ; sl@0: TEST2(err, KErrNone); sl@0: TheTest.Printf(_L("Currency Symbol from repository data cage is: %S\n"), &datacageCurrencySymbol); sl@0: sl@0: TheTest.Printf(_L("Setting Currency Symbol to: %S\n"), &KNewCurrencySymbol); sl@0: sl@0: TheTest.Printf(_L("Saving Currency Symbol to repository.\n\n")); sl@0: err = repository->Set(KLocaleCurrencySymbol, KNewCurrencySymbol); sl@0: TEST2(err, KErrNone); sl@0: User::SetCurrencySymbol(KNewCurrencySymbol); sl@0: sl@0: TheTest.End(); sl@0: } sl@0: sl@0: /** sl@0: After InitialiseLocale has run. Gets the Currency Symbol back from the repository and then sl@0: outputs it. This output should be the same value as the test value ("ABC") that was set to the sl@0: repository in the above function. sl@0: */ sl@0: void TestLocaleCurrencySymbol(CRepository *repository) sl@0: { sl@0: TheTest.Start(_L("Checking value in the repository after InitialiseLocale() has run.\n")); sl@0: sl@0: TCurrencySymbol reposCurrencySymbol; sl@0: TInt err = repository->Get(KLocaleCurrencySymbol, reposCurrencySymbol); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TheTest.Printf(_L("The Currency Symbol after InitialiseLocale() has ran is: %S\n\n"), &reposCurrencySymbol); sl@0: sl@0: TEST(KNewCurrencySymbol == reposCurrencySymbol); sl@0: sl@0: TheTest.End(); sl@0: } sl@0: sl@0: sl@0: sl@0: // sl@0: // Test new locale initialisation and persistence mechanism sl@0: void TestLocaleChanges() sl@0: { sl@0: RProcess process; sl@0: sl@0: GetInitialLocaleSettings() ; sl@0: sl@0: // Restore default contents of locale settings repository sl@0: TUid LocaleRepositoryUid ; sl@0: LocaleRepositoryUid.iUid = KLocalePersistRepositoryUid ; sl@0: CRepository* repository = CRepository::NewLC(LocaleRepositoryUid) ; sl@0: repository->Reset(); sl@0: sl@0: TInt err = repository->Get(KLocaleCountryCode, defaultCountryCode) ; sl@0: TEST2(err, KErrNone); sl@0: ChangeLocaleCurrencySymbol(repository, defaultCurrencySymbol); sl@0: sl@0: // Initialise locale data and start persistence notifier by spawning sl@0: // process - this will be done as part of system start in actual sl@0: // release code! sl@0: TInt r = process.Create(KInitialiseLocaleExeName, KNullDesC); sl@0: if(r == KErrNone) sl@0: { sl@0: TRequestStatus stat; sl@0: process.Rendezvous(stat); sl@0: process.Resume(); // Start the process going sl@0: //wait for the locale initialisation to complete first before testing sl@0: User::WaitForRequest(stat); sl@0: TEST2((stat.Int()==KErrNone)||(stat.Int()==KErrAlreadyExists),ETrue); sl@0: TInt flag; sl@0: TUid initLocaleUid=TUid::Uid(KUidLocalePersistProperties); sl@0: r=RProperty::Get(initLocaleUid,(TUint)EInitialisationState,flag); sl@0: TEST2(r,KErrNone); sl@0: //check for the P&S flag that indicates localeinitialisation complete sl@0: TEST2(flag,ELocaleInitialisationComplete); sl@0: TestLocaleCurrencySymbol(repository); sl@0: User::After(1000000); sl@0: CheckDefaultLocaleCountryCode(); sl@0: User::After(1000000); sl@0: CheckDefaultLocaleValues(); sl@0: User::After(1000000); sl@0: ChangeLocaleCountryCode(); sl@0: User::After(1000000); sl@0: CheckRepositoryLocaleCountryCode(repository); sl@0: User::After(1000000); sl@0: TestVendorIdINC121403(process); sl@0: process.Close(); sl@0: User::After(1000000); sl@0: } sl@0: CleanupStack::PopAndDestroy(repository) ; sl@0: RestoreInitialLocaleSettings() ; sl@0: } sl@0: sl@0: sl@0: sl@0: TInt E32Main() sl@0: { sl@0: CTrapCleanup* tc = CTrapCleanup::New(); sl@0: TheTest(tc != NULL); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: TheTest.Start(_L("Basic Locale initialisation TheTests")); sl@0: TheTest.Title(); sl@0: TRAPD(err, ::TestLocaleChanges()) sl@0: TEST2(err, KErrNone); sl@0: sl@0: TheTest.End(); sl@0: TheTest.Close(); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: delete tc; sl@0: sl@0: return(KErrNone); sl@0: }