|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
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 |
|
16 // |
|
17 // |
|
18 |
|
19 #include <bautils.h> |
|
20 #include <f32file.h> |
|
21 #include <e32cmn.h> |
|
22 #include <e32test.h> |
|
23 #include <e32std.h> |
|
24 #include <e32const.h> |
|
25 #include <babackup.h> |
|
26 #include <hal.h> |
|
27 #include <centralrepository.h> |
|
28 #include "LocaleRepository.h" |
|
29 #include "InitialiseLocale.h" |
|
30 |
|
31 // Name of the exe to be called explicitly |
|
32 _LIT(KInitPersistLocaleExeName, "InitialiseLocale.exe"); |
|
33 _LIT(KFrenchLocale, "elocl.02"); |
|
34 |
|
35 _LIT(KSpanishLocale, "elocl.04"); |
|
36 |
|
37 // Central Repository Data cage file-path |
|
38 _LIT(KPersistLocale, "C:\\private\\10202be9\\persists\\1020E4D3.*"); |
|
39 |
|
40 LOCAL_D RTest TheTest(_L("T_LocaleFlexi")); |
|
41 |
|
42 RFs TheFs; |
|
43 |
|
44 TExtendedLocale initialExtendedLocale; |
|
45 |
|
46 |
|
47 void GetInitialLocaleSettings() |
|
48 { |
|
49 initialExtendedLocale.LoadSystemSettings() ; |
|
50 } |
|
51 |
|
52 void RestoreInitialLocaleSettings() |
|
53 { |
|
54 initialExtendedLocale.SaveSystemSettings() ; |
|
55 User::After(1000000); |
|
56 } |
|
57 |
|
58 //Test macros and functions |
|
59 |
|
60 LOCAL_C void Check(TInt aValue, TInt aLine) |
|
61 { |
|
62 if(!aValue) |
|
63 { |
|
64 RestoreInitialLocaleSettings(); |
|
65 TheTest(EFalse, aLine); |
|
66 } |
|
67 } |
|
68 |
|
69 LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine) |
|
70 { |
|
71 if(aValue != aExpected) |
|
72 { |
|
73 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); |
|
74 RestoreInitialLocaleSettings(); |
|
75 TheTest(EFalse, aLine); |
|
76 } |
|
77 } |
|
78 |
|
79 |
|
80 #define TEST(arg) ::Check((arg), __LINE__) |
|
81 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) |
|
82 |
|
83 |
|
84 /* |
|
85 This function prepares for next test i.e, tests InitialiseLocale behaves |
|
86 when persisted file is damaged/corrupt. |
|
87 */ |
|
88 void SetUpTestCorruptLocale() |
|
89 { |
|
90 TExtendedLocale myExtendedLocale; |
|
91 myExtendedLocale.LoadSystemSettings() ; |
|
92 |
|
93 TBuf<100> DllName; |
|
94 DllName.Copy(KFrenchLocale); |
|
95 |
|
96 TheTest.Printf(_L("\n Changing Locale to French Locale(02) so that default values are evident")); |
|
97 |
|
98 // Change the locale to Default Locale, all settings from single Dll |
|
99 myExtendedLocale.LoadLocale(DllName); |
|
100 |
|
101 // Save the changes to system settings |
|
102 myExtendedLocale.SaveSystemSettings(); |
|
103 |
|
104 // Wait so that it persists to repository |
|
105 User::After(1000000); |
|
106 |
|
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); |
|
111 TheFs.Close(); |
|
112 TheTest.Printf(_L("\n Deleted persist file from C: \n")); |
|
113 } |
|
114 |
|
115 /** |
|
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. |
|
121 @SYMREQ PREQ1001 |
|
122 */ |
|
123 LOCAL_D void ChangeLocaleMultiDll() |
|
124 { |
|
125 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CIT-0140 \nTest to demonstrate Locale settings by multiple DLLs ")); |
|
126 |
|
127 TExtendedLocale myExtendedLocale; |
|
128 myExtendedLocale.LoadSystemSettings(); |
|
129 |
|
130 TBuf<100> DllName1 ; |
|
131 DllName1.Copy(KFrenchLocale); |
|
132 |
|
133 TBuf<100> DllName2 ; |
|
134 DllName2.Copy(KSpanishLocale); |
|
135 |
|
136 TheTest.Printf(_L("Changing Language to French ")); |
|
137 |
|
138 // Load the language settings of French |
|
139 myExtendedLocale.LoadLocaleAspect(ELocaleLanguageSettings, DllName1); |
|
140 |
|
141 |
|
142 // Load system charset of French |
|
143 myExtendedLocale.LoadLocaleAspect(ELocaleCollateSetting, DllName1); |
|
144 |
|
145 // Load TLocale settings, currency symbols of Spanish |
|
146 myExtendedLocale.LoadLocaleAspect(ELocaleLocaleSettings, DllName2); |
|
147 |
|
148 // Load time and date display formats of Spanish |
|
149 myExtendedLocale.LoadLocaleAspect(ELocaleTimeDateSettings, DllName2); |
|
150 |
|
151 // Save to system settings |
|
152 myExtendedLocale.SaveSystemSettings(); |
|
153 |
|
154 // Wait |
|
155 User::After(1000000); |
|
156 |
|
157 TUid LocaleRepositoryUid ; |
|
158 LocaleRepositoryUid.iUid = KLocalePersistRepositoryUid ; |
|
159 |
|
160 CRepository* repository = CRepository::NewLC(LocaleRepositoryUid); |
|
161 |
|
162 // To get names of DLLs to be loaded |
|
163 TBuf<100> aDllName ; |
|
164 |
|
165 // Test the language settings |
|
166 TInt err = repository->Get(KLocaleLanguageDll, aDllName); |
|
167 if (err != KErrNone) |
|
168 { |
|
169 // Oops! I hit it again |
|
170 CleanupStack::PopAndDestroy(repository) ; |
|
171 return ; |
|
172 } |
|
173 |
|
174 |
|
175 TheTest.Printf(_L("\nTested for language French(02): %S "), &aDllName); |
|
176 |
|
177 // in this case we are only interested in the name "eloc.XX" |
|
178 |
|
179 TEST(DllName1.CompareF(aDllName.Right(8)) == 0); |
|
180 |
|
181 |
|
182 // Test system charset changes |
|
183 err = repository->Get(KLocaleCollationDll, aDllName); |
|
184 if (err != KErrNone) |
|
185 { |
|
186 // Oops! I hit it again |
|
187 CleanupStack::PopAndDestroy(repository) ; |
|
188 return ; |
|
189 } |
|
190 TheTest.Printf(_L("\nTested for Char set of French(02): %S"), &aDllName); |
|
191 TEST(DllName1.CompareF(aDllName.Right(8))==0); |
|
192 |
|
193 // Test TLocale settings, currency symbols |
|
194 err = repository->Get(KLocaleLocaleDll, aDllName) ; |
|
195 if (err != KErrNone) |
|
196 { |
|
197 // Oops! I hit it again |
|
198 CleanupStack::PopAndDestroy(repository) ; |
|
199 return ; |
|
200 } |
|
201 TheTest.Printf(_L("\nTested for Locale of Spanish(04): %S"), &aDllName); |
|
202 TEST(DllName2.CompareF(aDllName.Right(8))==0); |
|
203 |
|
204 // Test time and date display formats |
|
205 err = repository->Get(KLocaleTimeDateDll, aDllName) ; |
|
206 if (err != KErrNone) |
|
207 { |
|
208 // Oops! I hit it again |
|
209 CleanupStack::PopAndDestroy(repository) ; |
|
210 return ; |
|
211 } |
|
212 TheTest.Printf(_L("\nTested for Time and date format of Spanish(04): %S\n"), &aDllName); |
|
213 TEST(DllName2.CompareF(aDllName.Right(8))==0); |
|
214 |
|
215 // Free the central repository object |
|
216 CleanupStack::PopAndDestroy (repository); |
|
217 TheTest.End() ; |
|
218 } |
|
219 |
|
220 /** |
|
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. |
|
226 @SYMREQ PREQ1001 |
|
227 */ |
|
228 LOCAL_D void ChangeLocaleSingleDll() |
|
229 { |
|
230 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CIT-0141 Test to demonstrate change of Locale from single DLL ")); |
|
231 |
|
232 TExtendedLocale myExtendedLocale; |
|
233 myExtendedLocale.LoadSystemSettings() ; |
|
234 |
|
235 TBuf<100> DllName; |
|
236 DllName.Copy(KSpanishLocale); |
|
237 |
|
238 TheTest.Printf(_L("Changing Locale to Spanish")); |
|
239 |
|
240 // Change the locale to French Locale, all settings from single Dll |
|
241 myExtendedLocale.LoadLocale(DllName); |
|
242 |
|
243 // Save the changes to system settings |
|
244 myExtendedLocale.SaveSystemSettings(); |
|
245 |
|
246 // Wait |
|
247 User::After(1000000); |
|
248 |
|
249 TUid LocaleRepositoryUid ; |
|
250 LocaleRepositoryUid.iUid = KLocalePersistRepositoryUid; |
|
251 CRepository* repository = CRepository::NewLC(LocaleRepositoryUid) ; |
|
252 |
|
253 // To get names of DLLs to be loaded |
|
254 TBuf<100> aDllName ; |
|
255 |
|
256 // Test for the language settings |
|
257 TInt err = repository->Get(KLocaleLanguageDll, aDllName); |
|
258 if (err != KErrNone) |
|
259 { |
|
260 // Failed to read DLL name, bail out! |
|
261 CleanupStack::PopAndDestroy(repository) ; |
|
262 return ; |
|
263 } |
|
264 TheTest.Printf(_L("\nTested for Locale settings loaded by single Dll: %S"), &aDllName); |
|
265 TEST(DllName.CompareF(aDllName.Right(8))==0); |
|
266 |
|
267 CleanupStack::PopAndDestroy (repository); |
|
268 TheTest.End(); |
|
269 } |
|
270 |
|
271 // Call the tests that test flexibility of Locale |
|
272 void TestLocaleFlexibility() |
|
273 { |
|
274 RProcess process; |
|
275 |
|
276 GetInitialLocaleSettings() ; |
|
277 |
|
278 // Kick-in InitialiseLocale.exe, This will be done as part of system start in actual |
|
279 // release code! |
|
280 TInt r = process.Create(KInitPersistLocaleExeName, KNullDesC); |
|
281 if(r == KErrNone) |
|
282 { |
|
283 process.Resume(); // Start the process going |
|
284 User::After(1000000); |
|
285 |
|
286 ChangeLocaleMultiDll(); |
|
287 ChangeLocaleSingleDll(); |
|
288 |
|
289 User::After(1000000); |
|
290 // Set up for next test |
|
291 SetUpTestCorruptLocale(); |
|
292 User::After(1000000); |
|
293 process.Close(); |
|
294 User::After(1000000); |
|
295 } |
|
296 |
|
297 RestoreInitialLocaleSettings() ; |
|
298 } |
|
299 |
|
300 |
|
301 TInt E32Main() |
|
302 { |
|
303 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
304 TEST(cleanup != NULL); |
|
305 |
|
306 __UHEAP_MARK; |
|
307 TheTest.Start(_L("Test to demonstrate Locale flexibility")); |
|
308 TheTest.Title(); |
|
309 |
|
310 TRAPD(err, ::TestLocaleFlexibility()); |
|
311 |
|
312 TEST2(err, KErrNone); |
|
313 |
|
314 TheTest.End(); |
|
315 TheTest.Close(); |
|
316 |
|
317 __UHEAP_MARKEND; |
|
318 delete cleanup; |
|
319 |
|
320 return(KErrNone); |
|
321 } |