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