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 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <bautils.h>
|
sl@0
|
17 |
#include <f32file.h>
|
sl@0
|
18 |
#include <e32cmn.h>
|
sl@0
|
19 |
#include <e32test.h>
|
sl@0
|
20 |
#include <e32std.h>
|
sl@0
|
21 |
#include <e32const.h>
|
sl@0
|
22 |
#include <babackup.h>
|
sl@0
|
23 |
#include <hal.h>
|
sl@0
|
24 |
#include <centralrepository.h>
|
sl@0
|
25 |
#include "LocaleRepository.h"
|
sl@0
|
26 |
#include "InitialiseLocale.h"
|
sl@0
|
27 |
|
sl@0
|
28 |
|
sl@0
|
29 |
_LIT(KInitialiseLocaleExeName, "InitialiseLocale.exe");
|
sl@0
|
30 |
|
sl@0
|
31 |
// Symbian VendorID as specified in
|
sl@0
|
32 |
// "Platform security engineering guide" Section 2.1.3.2
|
sl@0
|
33 |
const TVendorId KSymbianVendorId(0x70000001);
|
sl@0
|
34 |
|
sl@0
|
35 |
RTest TheTest(_L("T_Initialise_Locale"));
|
sl@0
|
36 |
|
sl@0
|
37 |
// const TInt KDefaultCountryCode = 29 ;
|
sl@0
|
38 |
const TInt KNewCountryCode = 46 ;
|
sl@0
|
39 |
TInt defaultCountryCode ;
|
sl@0
|
40 |
|
sl@0
|
41 |
TCurrencySymbol defaultCurrencySymbol;
|
sl@0
|
42 |
|
sl@0
|
43 |
_LIT(KCurrencySymbol, "ABC") ;
|
sl@0
|
44 |
TBuf<8> KNewCurrencySymbol (KCurrencySymbol) ;
|
sl@0
|
45 |
|
sl@0
|
46 |
_LIT(KLongDateFormat, "%F%*D%X %N %Y") ;
|
sl@0
|
47 |
TBuf<20> KDefaultLongDateFormat (KLongDateFormat) ;
|
sl@0
|
48 |
|
sl@0
|
49 |
_LIT(KShortDateFormat, "%F%*D/%*M/%Y") ;
|
sl@0
|
50 |
TBuf<20> KDefaultShortDateFormat (KShortDateFormat) ;
|
sl@0
|
51 |
|
sl@0
|
52 |
_LIT(KTimeFormat, "%F%*I:%T:%S %*A") ;
|
sl@0
|
53 |
TBuf<20> KDefaultTimeFormat (KTimeFormat) ;
|
sl@0
|
54 |
|
sl@0
|
55 |
TExtendedLocale initialExtendedLocale;
|
sl@0
|
56 |
|
sl@0
|
57 |
void GetInitialLocaleSettings()
|
sl@0
|
58 |
{
|
sl@0
|
59 |
initialExtendedLocale.LoadSystemSettings() ;
|
sl@0
|
60 |
}
|
sl@0
|
61 |
|
sl@0
|
62 |
void RestoreInitialLocaleSettings()
|
sl@0
|
63 |
{
|
sl@0
|
64 |
initialExtendedLocale.SaveSystemSettings() ;
|
sl@0
|
65 |
User::After(1000000);
|
sl@0
|
66 |
}
|
sl@0
|
67 |
|
sl@0
|
68 |
//Test macros and functions
|
sl@0
|
69 |
|
sl@0
|
70 |
LOCAL_C void Check(TInt aValue, TInt aLine)
|
sl@0
|
71 |
{
|
sl@0
|
72 |
if(!aValue)
|
sl@0
|
73 |
{
|
sl@0
|
74 |
RestoreInitialLocaleSettings();
|
sl@0
|
75 |
TheTest(EFalse, aLine);
|
sl@0
|
76 |
}
|
sl@0
|
77 |
}
|
sl@0
|
78 |
|
sl@0
|
79 |
LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
if(aValue != aExpected)
|
sl@0
|
82 |
{
|
sl@0
|
83 |
RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
|
sl@0
|
84 |
RestoreInitialLocaleSettings();
|
sl@0
|
85 |
TheTest(EFalse, aLine);
|
sl@0
|
86 |
}
|
sl@0
|
87 |
}
|
sl@0
|
88 |
|
sl@0
|
89 |
LOCAL_C void Check(TPtrC aValue, TPtrC aExpected, TInt aLine)
|
sl@0
|
90 |
{
|
sl@0
|
91 |
if(aValue != aExpected)
|
sl@0
|
92 |
{
|
sl@0
|
93 |
RDebug::Print(_L("*** Expected error: %S, got: %S\r\n"), &aExpected, &aValue);
|
sl@0
|
94 |
RestoreInitialLocaleSettings();
|
sl@0
|
95 |
TheTest(EFalse, aLine);
|
sl@0
|
96 |
}
|
sl@0
|
97 |
}
|
sl@0
|
98 |
|
sl@0
|
99 |
#define TEST(arg) ::Check((arg), __LINE__)
|
sl@0
|
100 |
#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
|
sl@0
|
101 |
#define TEST3(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
|
sl@0
|
102 |
|
sl@0
|
103 |
/**
|
sl@0
|
104 |
@SYMTestCaseID SYSLIB-BAFL-CIT-0200
|
sl@0
|
105 |
@SYMTestCaseDesc Check that default locale values are loaded on startup.
|
sl@0
|
106 |
@SYMTestPriority High
|
sl@0
|
107 |
@SYMTestActions Ensure that country code in system locale data matches value in persisted data
|
sl@0
|
108 |
@SYMTestExpectedResults The test must not fail.
|
sl@0
|
109 |
@SYMREQ PREQ1003
|
sl@0
|
110 |
*/
|
sl@0
|
111 |
void CheckDefaultLocaleCountryCode()
|
sl@0
|
112 |
{
|
sl@0
|
113 |
TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CIT-0200 Check default country code "));
|
sl@0
|
114 |
|
sl@0
|
115 |
TExtendedLocale myExtendedLocale;
|
sl@0
|
116 |
myExtendedLocale.LoadSystemSettings() ;
|
sl@0
|
117 |
TLocale* myLocale = myExtendedLocale.GetLocale() ;
|
sl@0
|
118 |
TInt countryCode = myLocale->CountryCode();
|
sl@0
|
119 |
TheTest.Printf(_L("Default Country code is %d\n"), defaultCountryCode) ;
|
sl@0
|
120 |
TheTest.Printf(_L("Current Country code is %d\n"), countryCode) ;
|
sl@0
|
121 |
|
sl@0
|
122 |
TEST2(countryCode, defaultCountryCode) ;
|
sl@0
|
123 |
TheTest.End();
|
sl@0
|
124 |
}
|
sl@0
|
125 |
|
sl@0
|
126 |
/**
|
sl@0
|
127 |
@SYMTestCaseID SYSLIB-BAFL-CT-3160
|
sl@0
|
128 |
@SYMTestCaseDesc Check that default locale values i.e. Currency Symbol and long date, short date & time format.
|
sl@0
|
129 |
@SYMTestPriority High
|
sl@0
|
130 |
@SYMTestActions Ensure that these values are set to the default values as defined.
|
sl@0
|
131 |
@SYMTestExpectedResults The test must not fail.
|
sl@0
|
132 |
@SYMREQ PREQ1003
|
sl@0
|
133 |
*/
|
sl@0
|
134 |
void CheckDefaultLocaleValues()
|
sl@0
|
135 |
{
|
sl@0
|
136 |
TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-3160 Check default Locale Values "));
|
sl@0
|
137 |
TExtendedLocale myExtendedLocale;
|
sl@0
|
138 |
myExtendedLocale.LoadSystemSettings() ;
|
sl@0
|
139 |
|
sl@0
|
140 |
TPtrC currencySymbolPtr = myExtendedLocale.GetCurrencySymbol();
|
sl@0
|
141 |
TPtrC longDateFormatPtr = myExtendedLocale.GetLongDateFormatSpec();
|
sl@0
|
142 |
TPtrC shortDateFormatPtr = myExtendedLocale.GetShortDateFormatSpec();
|
sl@0
|
143 |
TPtrC timeFormatPtr = myExtendedLocale.GetTimeFormatSpec();
|
sl@0
|
144 |
|
sl@0
|
145 |
TheTest.Printf(_L("New Currency Symbol is %S \n"), ¤cySymbolPtr);
|
sl@0
|
146 |
TheTest.Printf(_L("Default Long Date Format is %S \n"), &longDateFormatPtr);
|
sl@0
|
147 |
TheTest.Printf(_L("Default Short Date Format is %S \n"), &shortDateFormatPtr);
|
sl@0
|
148 |
TheTest.Printf(_L("Default Time Format is %S \n"), &timeFormatPtr);
|
sl@0
|
149 |
|
sl@0
|
150 |
TPtrC expectedCurrSymPtr(KNewCurrencySymbol);
|
sl@0
|
151 |
TEST3(currencySymbolPtr, expectedCurrSymPtr);
|
sl@0
|
152 |
|
sl@0
|
153 |
TPtrC expectedlongDatePtr(KDefaultLongDateFormat);
|
sl@0
|
154 |
TEST3(longDateFormatPtr, expectedlongDatePtr);
|
sl@0
|
155 |
|
sl@0
|
156 |
TPtrC expectedShortDatePtr(KDefaultShortDateFormat);
|
sl@0
|
157 |
TEST3(shortDateFormatPtr, expectedShortDatePtr);
|
sl@0
|
158 |
|
sl@0
|
159 |
TPtrC expectedTimePtr(KDefaultTimeFormat);
|
sl@0
|
160 |
TEST3(timeFormatPtr, expectedTimePtr);
|
sl@0
|
161 |
|
sl@0
|
162 |
TheTest.End();
|
sl@0
|
163 |
}
|
sl@0
|
164 |
|
sl@0
|
165 |
/**
|
sl@0
|
166 |
@SYMTestCaseID SYSLIB-BAFL-CIT-0201
|
sl@0
|
167 |
@SYMTestCaseDesc Check that locale settings can be saved to and read from system locale data through TExtendedLocale.
|
sl@0
|
168 |
@SYMTestPriority High
|
sl@0
|
169 |
@SYMTestActions Change a number of locale values, write to system data, read back from data, check result
|
sl@0
|
170 |
@SYMTestExpectedResults The test must not fail.
|
sl@0
|
171 |
@SYMREQ PREQ1003
|
sl@0
|
172 |
*/
|
sl@0
|
173 |
void ChangeLocaleCountryCode()
|
sl@0
|
174 |
{
|
sl@0
|
175 |
TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CIT-0201 Define a TLocale "));
|
sl@0
|
176 |
TheTest.Next(_L("Setting CountryCode"));
|
sl@0
|
177 |
|
sl@0
|
178 |
TExtendedLocale myExtendedLocale;
|
sl@0
|
179 |
myExtendedLocale.LoadSystemSettings() ;
|
sl@0
|
180 |
TLocale* myLocale = myExtendedLocale.GetLocale() ;
|
sl@0
|
181 |
TheTest.Printf(_L("Setting Country code to %d\n"), KNewCountryCode) ;
|
sl@0
|
182 |
myLocale->SetCountryCode(KNewCountryCode);
|
sl@0
|
183 |
TheTest.Printf(_L("Saving new settings to system locale data\n")) ;
|
sl@0
|
184 |
myExtendedLocale.SaveSystemSettings() ;
|
sl@0
|
185 |
TheTest.Printf(_L("Loading new settings from system locale data\n")) ;
|
sl@0
|
186 |
myExtendedLocale.LoadSystemSettings() ;
|
sl@0
|
187 |
myLocale = myExtendedLocale.GetLocale() ;
|
sl@0
|
188 |
TInt countryCode = myLocale->CountryCode() ;
|
sl@0
|
189 |
TheTest.Printf(_L("New Country code is %d\n"), countryCode) ;
|
sl@0
|
190 |
TEST2(countryCode, KNewCountryCode) ;
|
sl@0
|
191 |
TheTest.End();
|
sl@0
|
192 |
}
|
sl@0
|
193 |
|
sl@0
|
194 |
|
sl@0
|
195 |
/**
|
sl@0
|
196 |
@SYMTestCaseID SYSLIB-BAFL-CIT-188
|
sl@0
|
197 |
@SYMTestCaseDesc Check that locale settings are saved into central repository.
|
sl@0
|
198 |
@SYMTestPriority High
|
sl@0
|
199 |
@SYMTestActions Ensure that locale data stored in the central repository match the data in the system locale
|
sl@0
|
200 |
@SYMTestExpectedResults The test must not fail.
|
sl@0
|
201 |
@SYMREQ PREQ1003
|
sl@0
|
202 |
*/
|
sl@0
|
203 |
void CheckRepositoryLocaleCountryCode(CRepository *repository)
|
sl@0
|
204 |
{
|
sl@0
|
205 |
TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CIT-188 Checking persisted country code "));
|
sl@0
|
206 |
TInt datacageCountryCode;
|
sl@0
|
207 |
TheTest.Printf(_L("Getting repository data cage\n")) ;
|
sl@0
|
208 |
TInt err = repository->Get(KLocaleCountryCode, datacageCountryCode) ;
|
sl@0
|
209 |
TEST2(err, KErrNone);
|
sl@0
|
210 |
TheTest.Printf(_L("Country code from repository = %d\n"), datacageCountryCode) ;
|
sl@0
|
211 |
TEST2(datacageCountryCode, KNewCountryCode) ;
|
sl@0
|
212 |
TheTest.End();
|
sl@0
|
213 |
}
|
sl@0
|
214 |
|
sl@0
|
215 |
/**
|
sl@0
|
216 |
@SYMTestCaseID SYSLIB-BAFL-CT-4051
|
sl@0
|
217 |
@SYMTestCaseDesc Check that the VendorID is set to 0x70000001 (Symbian's VendorID)
|
sl@0
|
218 |
@SYMTestPriority Medium
|
sl@0
|
219 |
@SYMTestActions 1. Create a process for InitialiseLocale.exe
|
sl@0
|
220 |
2. Compare the processes VID against the expected VID (0x70000001)
|
sl@0
|
221 |
@SYMTestExpectedResults The VIDs should be identical and so the test will pass.
|
sl@0
|
222 |
@SYMDEF INC121403
|
sl@0
|
223 |
*/
|
sl@0
|
224 |
void TestVendorIdINC121403(RProcess& aProcess)
|
sl@0
|
225 |
{
|
sl@0
|
226 |
TheTest.Next (_L ("TestVendorIDINC121403"));
|
sl@0
|
227 |
|
sl@0
|
228 |
// Test that the VendorID of InitialiseLocale.exe is set to the Symbian VendorID
|
sl@0
|
229 |
TEST2(KSymbianVendorId.iId, aProcess.VendorId().iId);
|
sl@0
|
230 |
}
|
sl@0
|
231 |
|
sl@0
|
232 |
/**
|
sl@0
|
233 |
Sets up the Currency Symbol test. Outputs default values then sets the Currency Symbol
|
sl@0
|
234 |
to a test value ("ABC") and stores this value in the repository, before InitialiseLocale has run.
|
sl@0
|
235 |
*/
|
sl@0
|
236 |
void ChangeLocaleCurrencySymbol(CRepository *repository, TCurrencySymbol & defaultCurrencySymbol)
|
sl@0
|
237 |
{
|
sl@0
|
238 |
TheTest.Start(_L("Setting CurrencySymbol\n"));
|
sl@0
|
239 |
|
sl@0
|
240 |
TExtendedLocale myExtendedLocale;
|
sl@0
|
241 |
myExtendedLocale.LoadSystemSettings() ;
|
sl@0
|
242 |
|
sl@0
|
243 |
TheTest.Printf(_L("Default Currency Symbol is: %S\n"), &defaultCurrencySymbol);
|
sl@0
|
244 |
|
sl@0
|
245 |
TCurrencySymbol datacageCurrencySymbol;
|
sl@0
|
246 |
TInt err = repository->Get(KLocaleCurrencySymbol, datacageCurrencySymbol) ;
|
sl@0
|
247 |
TEST2(err, KErrNone);
|
sl@0
|
248 |
TheTest.Printf(_L("Currency Symbol from repository data cage is: %S\n"), &datacageCurrencySymbol);
|
sl@0
|
249 |
|
sl@0
|
250 |
TheTest.Printf(_L("Setting Currency Symbol to: %S\n"), &KNewCurrencySymbol);
|
sl@0
|
251 |
|
sl@0
|
252 |
TheTest.Printf(_L("Saving Currency Symbol to repository.\n\n"));
|
sl@0
|
253 |
err = repository->Set(KLocaleCurrencySymbol, KNewCurrencySymbol);
|
sl@0
|
254 |
TEST2(err, KErrNone);
|
sl@0
|
255 |
User::SetCurrencySymbol(KNewCurrencySymbol);
|
sl@0
|
256 |
|
sl@0
|
257 |
TheTest.End();
|
sl@0
|
258 |
}
|
sl@0
|
259 |
|
sl@0
|
260 |
/**
|
sl@0
|
261 |
After InitialiseLocale has run. Gets the Currency Symbol back from the repository and then
|
sl@0
|
262 |
outputs it. This output should be the same value as the test value ("ABC") that was set to the
|
sl@0
|
263 |
repository in the above function.
|
sl@0
|
264 |
*/
|
sl@0
|
265 |
void TestLocaleCurrencySymbol(CRepository *repository)
|
sl@0
|
266 |
{
|
sl@0
|
267 |
TheTest.Start(_L("Checking value in the repository after InitialiseLocale() has run.\n"));
|
sl@0
|
268 |
|
sl@0
|
269 |
TCurrencySymbol reposCurrencySymbol;
|
sl@0
|
270 |
TInt err = repository->Get(KLocaleCurrencySymbol, reposCurrencySymbol);
|
sl@0
|
271 |
TEST2(err, KErrNone);
|
sl@0
|
272 |
|
sl@0
|
273 |
TheTest.Printf(_L("The Currency Symbol after InitialiseLocale() has ran is: %S\n\n"), &reposCurrencySymbol);
|
sl@0
|
274 |
|
sl@0
|
275 |
TEST(KNewCurrencySymbol == reposCurrencySymbol);
|
sl@0
|
276 |
|
sl@0
|
277 |
TheTest.End();
|
sl@0
|
278 |
}
|
sl@0
|
279 |
|
sl@0
|
280 |
|
sl@0
|
281 |
|
sl@0
|
282 |
//
|
sl@0
|
283 |
// Test new locale initialisation and persistence mechanism
|
sl@0
|
284 |
void TestLocaleChanges()
|
sl@0
|
285 |
{
|
sl@0
|
286 |
RProcess process;
|
sl@0
|
287 |
|
sl@0
|
288 |
GetInitialLocaleSettings() ;
|
sl@0
|
289 |
|
sl@0
|
290 |
// Restore default contents of locale settings repository
|
sl@0
|
291 |
TUid LocaleRepositoryUid ;
|
sl@0
|
292 |
LocaleRepositoryUid.iUid = KLocalePersistRepositoryUid ;
|
sl@0
|
293 |
CRepository* repository = CRepository::NewLC(LocaleRepositoryUid) ;
|
sl@0
|
294 |
repository->Reset();
|
sl@0
|
295 |
|
sl@0
|
296 |
TInt err = repository->Get(KLocaleCountryCode, defaultCountryCode) ;
|
sl@0
|
297 |
TEST2(err, KErrNone);
|
sl@0
|
298 |
ChangeLocaleCurrencySymbol(repository, defaultCurrencySymbol);
|
sl@0
|
299 |
|
sl@0
|
300 |
// Initialise locale data and start persistence notifier by spawning
|
sl@0
|
301 |
// process - this will be done as part of system start in actual
|
sl@0
|
302 |
// release code!
|
sl@0
|
303 |
TInt r = process.Create(KInitialiseLocaleExeName, KNullDesC);
|
sl@0
|
304 |
if(r == KErrNone)
|
sl@0
|
305 |
{
|
sl@0
|
306 |
TRequestStatus stat;
|
sl@0
|
307 |
process.Rendezvous(stat);
|
sl@0
|
308 |
process.Resume(); // Start the process going
|
sl@0
|
309 |
//wait for the locale initialisation to complete first before testing
|
sl@0
|
310 |
User::WaitForRequest(stat);
|
sl@0
|
311 |
TEST2((stat.Int()==KErrNone)||(stat.Int()==KErrAlreadyExists),ETrue);
|
sl@0
|
312 |
TInt flag;
|
sl@0
|
313 |
TUid initLocaleUid=TUid::Uid(KUidLocalePersistProperties);
|
sl@0
|
314 |
r=RProperty::Get(initLocaleUid,(TUint)EInitialisationState,flag);
|
sl@0
|
315 |
TEST2(r,KErrNone);
|
sl@0
|
316 |
//check for the P&S flag that indicates localeinitialisation complete
|
sl@0
|
317 |
TEST2(flag,ELocaleInitialisationComplete);
|
sl@0
|
318 |
TestLocaleCurrencySymbol(repository);
|
sl@0
|
319 |
User::After(1000000);
|
sl@0
|
320 |
CheckDefaultLocaleCountryCode();
|
sl@0
|
321 |
User::After(1000000);
|
sl@0
|
322 |
CheckDefaultLocaleValues();
|
sl@0
|
323 |
User::After(1000000);
|
sl@0
|
324 |
ChangeLocaleCountryCode();
|
sl@0
|
325 |
User::After(1000000);
|
sl@0
|
326 |
CheckRepositoryLocaleCountryCode(repository);
|
sl@0
|
327 |
User::After(1000000);
|
sl@0
|
328 |
TestVendorIdINC121403(process);
|
sl@0
|
329 |
process.Close();
|
sl@0
|
330 |
User::After(1000000);
|
sl@0
|
331 |
}
|
sl@0
|
332 |
CleanupStack::PopAndDestroy(repository) ;
|
sl@0
|
333 |
RestoreInitialLocaleSettings() ;
|
sl@0
|
334 |
}
|
sl@0
|
335 |
|
sl@0
|
336 |
|
sl@0
|
337 |
|
sl@0
|
338 |
TInt E32Main()
|
sl@0
|
339 |
{
|
sl@0
|
340 |
CTrapCleanup* tc = CTrapCleanup::New();
|
sl@0
|
341 |
TheTest(tc != NULL);
|
sl@0
|
342 |
|
sl@0
|
343 |
__UHEAP_MARK;
|
sl@0
|
344 |
|
sl@0
|
345 |
TheTest.Start(_L("Basic Locale initialisation TheTests"));
|
sl@0
|
346 |
TheTest.Title();
|
sl@0
|
347 |
TRAPD(err, ::TestLocaleChanges())
|
sl@0
|
348 |
TEST2(err, KErrNone);
|
sl@0
|
349 |
|
sl@0
|
350 |
TheTest.End();
|
sl@0
|
351 |
TheTest.Close();
|
sl@0
|
352 |
|
sl@0
|
353 |
__UHEAP_MARKEND;
|
sl@0
|
354 |
|
sl@0
|
355 |
delete tc;
|
sl@0
|
356 |
|
sl@0
|
357 |
return(KErrNone);
|
sl@0
|
358 |
}
|