os/ossrv/lowlevellibsandfws/apputils/initLocale/test/T_LocaleFlexiOldLocaleModel.cpp
Update contrib.
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"
32 // Name of the exe to be called explicitly
33 _LIT(KInitPersistLocaleExeName, "InitialiseLocale.exe");
34 _LIT(KFrenchLocale, "elocl.02");
36 _LIT(KSpanishLocale, "elocl.04");
38 // Central Repository Data cage file-path
39 _LIT(KPersistLocale, "C:\\private\\10202be9\\persists\\1020E4D3.*");
41 LOCAL_D RTest TheTest(_L("T_LocaleFlexiOldLocaleModel"));
45 TExtendedLocale initialExtendedLocale;
48 void GetInitialLocaleSettings()
50 initialExtendedLocale.LoadSystemSettings() ;
53 void RestoreInitialLocaleSettings()
55 initialExtendedLocale.SaveSystemSettings() ;
59 //Test macros and functions
61 LOCAL_C void Check(TInt aValue, TInt aLine)
65 RestoreInitialLocaleSettings();
66 TheTest(EFalse, aLine);
70 LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
72 if(aValue != aExpected)
74 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
75 RestoreInitialLocaleSettings();
76 TheTest(EFalse, aLine);
81 #define TEST(arg) ::Check((arg), __LINE__)
82 #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 Spanish "));
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);
219 //becasue we check whether locale content can be persisted is the system in this code block , we mark this test case here.
220 TheTest.Start(_L(" @SYMTestCaseID:TI18N-INITLOCALE-CT-4007 persist system locale content"));
225 @SYMTestCaseID SYSLIB-BAFL-CIT-0141
226 @SYMTestCaseDesc Check that locale settings can be selected from single DLL
227 @SYMTestPriority High
228 @SYMTestActions Ensure that all settings are loaded from a DLL, system set and persisted
229 @SYMTestExpectedResults The test must not fail.
232 LOCAL_D void ChangeLocaleSingleDll()
234 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CIT-0141 Test to demonstrate change of Locale from single DLL "));
236 TExtendedLocale myExtendedLocale;
237 myExtendedLocale.LoadSystemSettings() ;
240 DllName.Copy(KSpanishLocale);
242 TheTest.Printf(_L("Changing Locale to Spanish"));
244 // Change the locale to French Locale, all settings from single Dll
245 myExtendedLocale.LoadLocale(DllName);
247 // Save the changes to system settings
248 myExtendedLocale.SaveSystemSettings();
251 User::After(1000000);
253 TUid LocaleRepositoryUid ;
254 LocaleRepositoryUid.iUid = KLocalePersistRepositoryUid;
255 CRepository* repository = CRepository::NewLC(LocaleRepositoryUid) ;
257 // To get names of DLLs to be loaded
260 // Test for the language settings
261 TInt err = repository->Get(KLocaleLanguageDll, aDllName);
264 // Failed to read DLL name, bail out!
265 CleanupStack::PopAndDestroy(repository) ;
268 TheTest.Printf(_L("\nTested for Locale settings loaded by single Dll: %S"), &aDllName);
269 TEST(DllName.CompareF(aDllName.Right(8))==0);
271 CleanupStack::PopAndDestroy (repository);
275 // Call the tests that test flexibility of Locale
276 void TestLocaleFlexibility()
280 GetInitialLocaleSettings() ;
282 // Kick-in InitialiseLocale.exe, This will be done as part of system start in actual
284 TInt r = process.Create(KInitPersistLocaleExeName, KNullDesC);
287 process.Resume(); // Start the process going
288 User::After(1000000);
290 ChangeLocaleMultiDll();
291 ChangeLocaleSingleDll();
293 User::After(1000000);
295 User::After(1000000);
298 RestoreInitialLocaleSettings() ;
300 User::After(1000000);
301 // Set up for next test
302 SetUpTestCorruptLocale();
308 CTrapCleanup* cleanup = CTrapCleanup::New();
309 TEST(cleanup != NULL);
312 TheTest.Start(_L("Test to demonstrate Locale flexibility in old locale model"));
315 TRAPD(err, ::TestLocaleFlexibility());
317 TEST2(err, KErrNone);