First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
24 #include <centralrepository.h>
25 #include "LocaleRepository.h"
26 #include "InitialiseLocale.h"
29 _LIT(KInitialiseLocaleExeName, "InitialiseLocale.exe");
31 // Symbian VendorID as specified in
32 // "Platform security engineering guide" Section 2.1.3.2
33 const TVendorId KSymbianVendorId(0x70000001);
35 RTest TheTest(_L("T_Initialise_Locale"));
37 // const TInt KDefaultCountryCode = 29 ;
38 const TInt KNewCountryCode = 46 ;
39 TInt defaultCountryCode ;
41 TCurrencySymbol defaultCurrencySymbol;
43 _LIT(KCurrencySymbol, "ABC") ;
44 TBuf<8> KNewCurrencySymbol (KCurrencySymbol) ;
46 _LIT(KLongDateFormat, "%F%*D%X %N %Y") ;
47 TBuf<20> KDefaultLongDateFormat (KLongDateFormat) ;
49 _LIT(KShortDateFormat, "%F%*D/%*M/%Y") ;
50 TBuf<20> KDefaultShortDateFormat (KShortDateFormat) ;
52 _LIT(KTimeFormat, "%F%*I:%T:%S %*A") ;
53 TBuf<20> KDefaultTimeFormat (KTimeFormat) ;
55 TExtendedLocale initialExtendedLocale;
57 void GetInitialLocaleSettings()
59 initialExtendedLocale.LoadSystemSettings() ;
62 void RestoreInitialLocaleSettings()
64 initialExtendedLocale.SaveSystemSettings() ;
68 //Test macros and functions
70 LOCAL_C void Check(TInt aValue, TInt aLine)
74 RestoreInitialLocaleSettings();
75 TheTest(EFalse, aLine);
79 LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
81 if(aValue != aExpected)
83 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
84 RestoreInitialLocaleSettings();
85 TheTest(EFalse, aLine);
89 LOCAL_C void Check(TPtrC aValue, TPtrC aExpected, TInt aLine)
91 if(aValue != aExpected)
93 RDebug::Print(_L("*** Expected error: %S, got: %S\r\n"), &aExpected, &aValue);
94 RestoreInitialLocaleSettings();
95 TheTest(EFalse, aLine);
99 #define TEST(arg) ::Check((arg), __LINE__)
100 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
101 #define TEST3(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
104 @SYMTestCaseID SYSLIB-BAFL-CIT-0200
105 @SYMTestCaseDesc Check that default locale values are loaded on startup.
106 @SYMTestPriority High
107 @SYMTestActions Ensure that country code in system locale data matches value in persisted data
108 @SYMTestExpectedResults The test must not fail.
111 void CheckDefaultLocaleCountryCode()
113 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CIT-0200 Check default country code "));
115 TExtendedLocale myExtendedLocale;
116 myExtendedLocale.LoadSystemSettings() ;
117 TLocale* myLocale = myExtendedLocale.GetLocale() ;
118 TInt countryCode = myLocale->CountryCode();
119 TheTest.Printf(_L("Default Country code is %d\n"), defaultCountryCode) ;
120 TheTest.Printf(_L("Current Country code is %d\n"), countryCode) ;
122 TEST2(countryCode, defaultCountryCode) ;
127 @SYMTestCaseID SYSLIB-BAFL-CT-3160
128 @SYMTestCaseDesc Check that default locale values i.e. Currency Symbol and long date, short date & time format.
129 @SYMTestPriority High
130 @SYMTestActions Ensure that these values are set to the default values as defined.
131 @SYMTestExpectedResults The test must not fail.
134 void CheckDefaultLocaleValues()
136 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-3160 Check default Locale Values "));
137 TExtendedLocale myExtendedLocale;
138 myExtendedLocale.LoadSystemSettings() ;
140 TPtrC currencySymbolPtr = myExtendedLocale.GetCurrencySymbol();
141 TPtrC longDateFormatPtr = myExtendedLocale.GetLongDateFormatSpec();
142 TPtrC shortDateFormatPtr = myExtendedLocale.GetShortDateFormatSpec();
143 TPtrC timeFormatPtr = myExtendedLocale.GetTimeFormatSpec();
145 TheTest.Printf(_L("New Currency Symbol is %S \n"), ¤cySymbolPtr);
146 TheTest.Printf(_L("Default Long Date Format is %S \n"), &longDateFormatPtr);
147 TheTest.Printf(_L("Default Short Date Format is %S \n"), &shortDateFormatPtr);
148 TheTest.Printf(_L("Default Time Format is %S \n"), &timeFormatPtr);
150 TPtrC expectedCurrSymPtr(KNewCurrencySymbol);
151 TEST3(currencySymbolPtr, expectedCurrSymPtr);
153 TPtrC expectedlongDatePtr(KDefaultLongDateFormat);
154 TEST3(longDateFormatPtr, expectedlongDatePtr);
156 TPtrC expectedShortDatePtr(KDefaultShortDateFormat);
157 TEST3(shortDateFormatPtr, expectedShortDatePtr);
159 TPtrC expectedTimePtr(KDefaultTimeFormat);
160 TEST3(timeFormatPtr, expectedTimePtr);
166 @SYMTestCaseID SYSLIB-BAFL-CIT-0201
167 @SYMTestCaseDesc Check that locale settings can be saved to and read from system locale data through TExtendedLocale.
168 @SYMTestPriority High
169 @SYMTestActions Change a number of locale values, write to system data, read back from data, check result
170 @SYMTestExpectedResults The test must not fail.
173 void ChangeLocaleCountryCode()
175 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CIT-0201 Define a TLocale "));
176 TheTest.Next(_L("Setting CountryCode"));
178 TExtendedLocale myExtendedLocale;
179 myExtendedLocale.LoadSystemSettings() ;
180 TLocale* myLocale = myExtendedLocale.GetLocale() ;
181 TheTest.Printf(_L("Setting Country code to %d\n"), KNewCountryCode) ;
182 myLocale->SetCountryCode(KNewCountryCode);
183 TheTest.Printf(_L("Saving new settings to system locale data\n")) ;
184 myExtendedLocale.SaveSystemSettings() ;
185 TheTest.Printf(_L("Loading new settings from system locale data\n")) ;
186 myExtendedLocale.LoadSystemSettings() ;
187 myLocale = myExtendedLocale.GetLocale() ;
188 TInt countryCode = myLocale->CountryCode() ;
189 TheTest.Printf(_L("New Country code is %d\n"), countryCode) ;
190 TEST2(countryCode, KNewCountryCode) ;
196 @SYMTestCaseID SYSLIB-BAFL-CIT-188
197 @SYMTestCaseDesc Check that locale settings are saved into central repository.
198 @SYMTestPriority High
199 @SYMTestActions Ensure that locale data stored in the central repository match the data in the system locale
200 @SYMTestExpectedResults The test must not fail.
203 void CheckRepositoryLocaleCountryCode(CRepository *repository)
205 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CIT-188 Checking persisted country code "));
206 TInt datacageCountryCode;
207 TheTest.Printf(_L("Getting repository data cage\n")) ;
208 TInt err = repository->Get(KLocaleCountryCode, datacageCountryCode) ;
209 TEST2(err, KErrNone);
210 TheTest.Printf(_L("Country code from repository = %d\n"), datacageCountryCode) ;
211 TEST2(datacageCountryCode, KNewCountryCode) ;
216 @SYMTestCaseID SYSLIB-BAFL-CT-4051
217 @SYMTestCaseDesc Check that the VendorID is set to 0x70000001 (Symbian's VendorID)
218 @SYMTestPriority Medium
219 @SYMTestActions 1. Create a process for InitialiseLocale.exe
220 2. Compare the processes VID against the expected VID (0x70000001)
221 @SYMTestExpectedResults The VIDs should be identical and so the test will pass.
224 void TestVendorIdINC121403(RProcess& aProcess)
226 TheTest.Next (_L ("TestVendorIDINC121403"));
228 // Test that the VendorID of InitialiseLocale.exe is set to the Symbian VendorID
229 TEST2(KSymbianVendorId.iId, aProcess.VendorId().iId);
233 Sets up the Currency Symbol test. Outputs default values then sets the Currency Symbol
234 to a test value ("ABC") and stores this value in the repository, before InitialiseLocale has run.
236 void ChangeLocaleCurrencySymbol(CRepository *repository, TCurrencySymbol & defaultCurrencySymbol)
238 TheTest.Start(_L("Setting CurrencySymbol\n"));
240 TExtendedLocale myExtendedLocale;
241 myExtendedLocale.LoadSystemSettings() ;
243 TheTest.Printf(_L("Default Currency Symbol is: %S\n"), &defaultCurrencySymbol);
245 TCurrencySymbol datacageCurrencySymbol;
246 TInt err = repository->Get(KLocaleCurrencySymbol, datacageCurrencySymbol) ;
247 TEST2(err, KErrNone);
248 TheTest.Printf(_L("Currency Symbol from repository data cage is: %S\n"), &datacageCurrencySymbol);
250 TheTest.Printf(_L("Setting Currency Symbol to: %S\n"), &KNewCurrencySymbol);
252 TheTest.Printf(_L("Saving Currency Symbol to repository.\n\n"));
253 err = repository->Set(KLocaleCurrencySymbol, KNewCurrencySymbol);
254 TEST2(err, KErrNone);
255 User::SetCurrencySymbol(KNewCurrencySymbol);
261 After InitialiseLocale has run. Gets the Currency Symbol back from the repository and then
262 outputs it. This output should be the same value as the test value ("ABC") that was set to the
263 repository in the above function.
265 void TestLocaleCurrencySymbol(CRepository *repository)
267 TheTest.Start(_L("Checking value in the repository after InitialiseLocale() has run.\n"));
269 TCurrencySymbol reposCurrencySymbol;
270 TInt err = repository->Get(KLocaleCurrencySymbol, reposCurrencySymbol);
271 TEST2(err, KErrNone);
273 TheTest.Printf(_L("The Currency Symbol after InitialiseLocale() has ran is: %S\n\n"), &reposCurrencySymbol);
275 TEST(KNewCurrencySymbol == reposCurrencySymbol);
283 // Test new locale initialisation and persistence mechanism
284 void TestLocaleChanges()
288 GetInitialLocaleSettings() ;
290 // Restore default contents of locale settings repository
291 TUid LocaleRepositoryUid ;
292 LocaleRepositoryUid.iUid = KLocalePersistRepositoryUid ;
293 CRepository* repository = CRepository::NewLC(LocaleRepositoryUid) ;
296 TInt err = repository->Get(KLocaleCountryCode, defaultCountryCode) ;
297 TEST2(err, KErrNone);
298 ChangeLocaleCurrencySymbol(repository, defaultCurrencySymbol);
300 // Initialise locale data and start persistence notifier by spawning
301 // process - this will be done as part of system start in actual
303 TInt r = process.Create(KInitialiseLocaleExeName, KNullDesC);
307 process.Rendezvous(stat);
308 process.Resume(); // Start the process going
309 //wait for the locale initialisation to complete first before testing
310 User::WaitForRequest(stat);
311 TEST2((stat.Int()==KErrNone)||(stat.Int()==KErrAlreadyExists),ETrue);
313 TUid initLocaleUid=TUid::Uid(KUidLocalePersistProperties);
314 r=RProperty::Get(initLocaleUid,(TUint)EInitialisationState,flag);
316 //check for the P&S flag that indicates localeinitialisation complete
317 TEST2(flag,ELocaleInitialisationComplete);
318 TestLocaleCurrencySymbol(repository);
319 User::After(1000000);
320 CheckDefaultLocaleCountryCode();
321 User::After(1000000);
322 CheckDefaultLocaleValues();
323 User::After(1000000);
324 ChangeLocaleCountryCode();
325 User::After(1000000);
326 CheckRepositoryLocaleCountryCode(repository);
327 User::After(1000000);
328 TestVendorIdINC121403(process);
330 User::After(1000000);
332 CleanupStack::PopAndDestroy(repository) ;
333 RestoreInitialLocaleSettings() ;
340 CTrapCleanup* tc = CTrapCleanup::New();
345 TheTest.Start(_L("Basic Locale initialisation TheTests"));
347 TRAPD(err, ::TestLocaleChanges())
348 TEST2(err, KErrNone);