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.
14 // This file contains RTest based tests which check flexibility of Locale.
15 // That are, 1. Selectable from Multiple Dlls 2. Loaded all from a single Dll
27 #include <centralrepository.h>
28 #include "LocaleRepository.h"
29 #include "InitialiseLocale.h"
31 // Name of the exe to be called explicitly
32 _LIT(KInitPersistLocaleExeName, "InitialiseLocale.exe");
33 _LIT(KFrenchLocale, "elocl.02");
35 _LIT(KSpanishLocale, "elocl.04");
37 // Central Repository Data cage file-path
38 _LIT(KPersistLocale, "C:\\private\\10202be9\\persists\\1020E4D3.*");
40 LOCAL_D RTest TheTest(_L("T_LocaleFlexi"));
44 TExtendedLocale initialExtendedLocale;
47 void GetInitialLocaleSettings()
49 initialExtendedLocale.LoadSystemSettings() ;
52 void RestoreInitialLocaleSettings()
54 initialExtendedLocale.SaveSystemSettings() ;
58 //Test macros and functions
60 LOCAL_C void Check(TInt aValue, TInt aLine)
64 RestoreInitialLocaleSettings();
65 TheTest(EFalse, aLine);
69 LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
71 if(aValue != aExpected)
73 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
74 RestoreInitialLocaleSettings();
75 TheTest(EFalse, aLine);
80 #define TEST(arg) ::Check((arg), __LINE__)
81 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
85 This function prepares for next test i.e, tests InitialiseLocale behaves
86 when persisted file is damaged/corrupt.
88 void SetUpTestCorruptLocale()
90 TExtendedLocale myExtendedLocale;
91 myExtendedLocale.LoadSystemSettings() ;
94 DllName.Copy(KFrenchLocale);
96 TheTest.Printf(_L("\n Changing Locale to French Locale(02) so that default values are evident"));
98 // Change the locale to Default Locale, all settings from single Dll
99 myExtendedLocale.LoadLocale(DllName);
101 // Save the changes to system settings
102 myExtendedLocale.SaveSystemSettings();
104 // Wait so that it persists to repository
105 User::After(1000000);
107 User::LeaveIfError(TheFs.Connect());
108 // Delete/damage the persisted file so that InitialiseLocale.exe
109 // detects the damage and loads default locale
110 BaflUtils::DeleteFile(TheFs, KPersistLocale);
112 TheTest.Printf(_L("\n Deleted persist file from C: \n"));
116 @SYMTestCaseID SYSLIB-BAFL-CIT-0140
117 @SYMTestCaseDesc Check that locale settings can be selected from several DLLs
118 @SYMTestPriority High
119 @SYMTestActions Ensure that locales are selected, system set and persisted
120 @SYMTestExpectedResults The test must not fail.
123 LOCAL_D void ChangeLocaleMultiDll()
125 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CIT-0140 \nTest to demonstrate Locale settings by multiple DLLs "));
127 TExtendedLocale myExtendedLocale;
128 myExtendedLocale.LoadSystemSettings();
131 DllName1.Copy(KFrenchLocale);
134 DllName2.Copy(KSpanishLocale);
136 TheTest.Printf(_L("Changing Language to French "));
138 // Load the language settings of French
139 myExtendedLocale.LoadLocaleAspect(ELocaleLanguageSettings, DllName1);
142 // Load system charset of French
143 myExtendedLocale.LoadLocaleAspect(ELocaleCollateSetting, DllName1);
145 // Load TLocale settings, currency symbols of Spanish
146 myExtendedLocale.LoadLocaleAspect(ELocaleLocaleSettings, DllName2);
148 // Load time and date display formats of Spanish
149 myExtendedLocale.LoadLocaleAspect(ELocaleTimeDateSettings, DllName2);
151 // Save to system settings
152 myExtendedLocale.SaveSystemSettings();
155 User::After(1000000);
157 TUid LocaleRepositoryUid ;
158 LocaleRepositoryUid.iUid = KLocalePersistRepositoryUid ;
160 CRepository* repository = CRepository::NewLC(LocaleRepositoryUid);
162 // To get names of DLLs to be loaded
165 // Test the language settings
166 TInt err = repository->Get(KLocaleLanguageDll, aDllName);
169 // Oops! I hit it again
170 CleanupStack::PopAndDestroy(repository) ;
175 TheTest.Printf(_L("\nTested for language French(02): %S "), &aDllName);
177 // in this case we are only interested in the name "eloc.XX"
179 TEST(DllName1.CompareF(aDllName.Right(8)) == 0);
182 // Test system charset changes
183 err = repository->Get(KLocaleCollationDll, aDllName);
186 // Oops! I hit it again
187 CleanupStack::PopAndDestroy(repository) ;
190 TheTest.Printf(_L("\nTested for Char set of French(02): %S"), &aDllName);
191 TEST(DllName1.CompareF(aDllName.Right(8))==0);
193 // Test TLocale settings, currency symbols
194 err = repository->Get(KLocaleLocaleDll, aDllName) ;
197 // Oops! I hit it again
198 CleanupStack::PopAndDestroy(repository) ;
201 TheTest.Printf(_L("\nTested for Locale of Spanish(04): %S"), &aDllName);
202 TEST(DllName2.CompareF(aDllName.Right(8))==0);
204 // Test time and date display formats
205 err = repository->Get(KLocaleTimeDateDll, aDllName) ;
208 // Oops! I hit it again
209 CleanupStack::PopAndDestroy(repository) ;
212 TheTest.Printf(_L("\nTested for Time and date format of Spanish(04): %S\n"), &aDllName);
213 TEST(DllName2.CompareF(aDllName.Right(8))==0);
215 // Free the central repository object
216 CleanupStack::PopAndDestroy (repository);
221 @SYMTestCaseID SYSLIB-BAFL-CIT-0141
222 @SYMTestCaseDesc Check that locale settings can be selected from single DLL
223 @SYMTestPriority High
224 @SYMTestActions Ensure that all settings are loaded from a DLL, system set and persisted
225 @SYMTestExpectedResults The test must not fail.
228 LOCAL_D void ChangeLocaleSingleDll()
230 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CIT-0141 Test to demonstrate change of Locale from single DLL "));
232 TExtendedLocale myExtendedLocale;
233 myExtendedLocale.LoadSystemSettings() ;
236 DllName.Copy(KSpanishLocale);
238 TheTest.Printf(_L("Changing Locale to Spanish"));
240 // Change the locale to French Locale, all settings from single Dll
241 myExtendedLocale.LoadLocale(DllName);
243 // Save the changes to system settings
244 myExtendedLocale.SaveSystemSettings();
247 User::After(1000000);
249 TUid LocaleRepositoryUid ;
250 LocaleRepositoryUid.iUid = KLocalePersistRepositoryUid;
251 CRepository* repository = CRepository::NewLC(LocaleRepositoryUid) ;
253 // To get names of DLLs to be loaded
256 // Test for the language settings
257 TInt err = repository->Get(KLocaleLanguageDll, aDllName);
260 // Failed to read DLL name, bail out!
261 CleanupStack::PopAndDestroy(repository) ;
264 TheTest.Printf(_L("\nTested for Locale settings loaded by single Dll: %S"), &aDllName);
265 TEST(DllName.CompareF(aDllName.Right(8))==0);
267 CleanupStack::PopAndDestroy (repository);
271 // Call the tests that test flexibility of Locale
272 void TestLocaleFlexibility()
276 GetInitialLocaleSettings() ;
278 // Kick-in InitialiseLocale.exe, This will be done as part of system start in actual
280 TInt r = process.Create(KInitPersistLocaleExeName, KNullDesC);
283 process.Resume(); // Start the process going
284 User::After(1000000);
286 ChangeLocaleMultiDll();
287 ChangeLocaleSingleDll();
289 User::After(1000000);
290 // Set up for next test
291 SetUpTestCorruptLocale();
292 User::After(1000000);
294 User::After(1000000);
297 RestoreInitialLocaleSettings() ;
303 CTrapCleanup* cleanup = CTrapCleanup::New();
304 TEST(cleanup != NULL);
307 TheTest.Start(_L("Test to demonstrate Locale flexibility"));
310 TRAPD(err, ::TestLocaleFlexibility());
312 TEST2(err, KErrNone);