|
1 // Copyright (c) 1997-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 the License "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 // f32test\server\t_dlocl.cpp |
|
15 // Tests UserSvr::ChangeLocale() function |
|
16 // |
|
17 // |
|
18 |
|
19 #define __E32TEST_EXTENSION__ |
|
20 |
|
21 #include <e32std.h> |
|
22 #include <e32std_private.h> |
|
23 #include <e32test.h> |
|
24 #include <f32file.h> |
|
25 #include <e32svr.h> |
|
26 #include <collate.h> |
|
27 |
|
28 #include "t_server.h" |
|
29 |
|
30 LOCAL_D TFindLibrary fLib; |
|
31 |
|
32 typedef TInt (*TLibEntry)(TInt); |
|
33 typedef TInt (*TLibEntry2)(); |
|
34 |
|
35 const TBool KEY_DOWN=EFalse; |
|
36 const TBool EXPECT_KEY_PRESS=ETrue; |
|
37 |
|
38 RTest test(_L("T_DLOCL")); |
|
39 |
|
40 _LIT(ELOCL_DEFAULT, ""); |
|
41 _LIT(ELOCLGE, "T_LOCLGE"); |
|
42 _LIT(ELOCLUS, "T_LOCLUS"); |
|
43 _LIT(ELOCLUS1, "T_LOCLUS1"); |
|
44 _LIT(ELOCLUS2, "T_LOCLUS2"); |
|
45 _LIT(EKDATA, "EKDATA"); |
|
46 _LIT(DUMMYDLL, "EDISP"); |
|
47 _LIT(KColonColon, "::"); |
|
48 _LIT(KDLLExtension, ".DLL"); |
|
49 |
|
50 GLDEF_D CKeyTranslator *KeyTranslator=CKeyTranslator::New(); |
|
51 LOCAL_D CCaptureKeys *CaptureKeys; |
|
52 |
|
53 void testConv(const TDesC& aDes,TBool aKeyup,TBool aRet,TUint aScanCode,TUint aKeyCode,TInt aModifiers) |
|
54 { |
|
55 |
|
56 TKeyData keyData; |
|
57 TBool ret=KeyTranslator->TranslateKey(aScanCode, aKeyup,*CaptureKeys,keyData); |
|
58 test.Next(aDes); |
|
59 test(ret==aRet); |
|
60 test((keyData.iKeyCode==aKeyCode)); |
|
61 test((keyData.iModifiers==aModifiers)); |
|
62 } |
|
63 |
|
64 void testChangeKeyData() |
|
65 { |
|
66 TName pn(RProcess().Name()); |
|
67 pn+=KColonColon; |
|
68 TFullName n; |
|
69 CaptureKeys=new CCaptureKeys(); |
|
70 CaptureKeys->Construct(); |
|
71 test.Printf(_L("Test default key data\n")); |
|
72 testConv(_L("\nFirst Special key down"),KEY_DOWN,EXPECT_KEY_PRESS,ESpecialKeyBase,ESpecialKeyBase,0); |
|
73 |
|
74 RLibrary testLib; |
|
75 TInt res=testLib.Load(EKDATA); |
|
76 test(res==KErrNone); |
|
77 THandleInfo handleInfo; |
|
78 testLib.HandleInfo(&handleInfo); |
|
79 test(handleInfo.iNumOpenInThread==2); |
|
80 testLib.Close(); |
|
81 |
|
82 test.Printf(_L("Change to unknown dll \n")); // Test with non keydata type dll |
|
83 res=KeyTranslator->ChangeKeyData(DUMMYDLL); |
|
84 test(res==KErrArgument); |
|
85 |
|
86 res=testLib.Load(EKDATA); |
|
87 test(res==KErrNone); |
|
88 testLib.HandleInfo(&handleInfo); |
|
89 test(handleInfo.iNumOpenInThread==2); |
|
90 testLib.Close(); |
|
91 |
|
92 res=testLib.Load(DUMMYDLL); |
|
93 test(res==KErrNone); |
|
94 testLib.HandleInfo(&handleInfo); |
|
95 test(handleInfo.iNumOpenInThread==1); |
|
96 testLib.Close(); |
|
97 |
|
98 fLib.Find(_L("*")); |
|
99 while (fLib.Next(n)==KErrNone) |
|
100 { |
|
101 TName findname=pn; |
|
102 findname+=DUMMYDLL; |
|
103 test.Printf(_L(" %S\n"),&n); |
|
104 test(n.FindF(findname) == KErrNotFound); |
|
105 } |
|
106 // |
|
107 test.Printf(_L("Change to EKDATA.dll\n")); |
|
108 res=KeyTranslator->ChangeKeyData(EKDATA); |
|
109 test(res==KErrNone); |
|
110 |
|
111 res=testLib.Load(EKDATA); |
|
112 test(res==KErrNone); |
|
113 testLib.HandleInfo(&handleInfo); |
|
114 test(handleInfo.iNumOpenInThread==2); |
|
115 testLib.Close(); |
|
116 res=testLib.Load(DUMMYDLL); |
|
117 test(res==KErrNone); |
|
118 testLib.HandleInfo(&handleInfo); |
|
119 test(handleInfo.iNumOpenInThread==1); |
|
120 testLib.Close(); |
|
121 |
|
122 fLib.Find(_L("*")); |
|
123 while (fLib.Next(n)==KErrNone) |
|
124 { |
|
125 TName findname=pn; |
|
126 findname+=EKDATA; |
|
127 test.Printf(_L(" %S\n"),&n); |
|
128 if(n.FindF(findname) != KErrNotFound) |
|
129 break; |
|
130 } |
|
131 //The test below fails if we use Secure APIs |
|
132 //test(n.FindF(EKDATA) == KErrNotSupported); |
|
133 testConv(_L("\nFirst Special key down"),KEY_DOWN,EXPECT_KEY_PRESS,ESpecialKeyBase,ESpecialKeyBase,0); |
|
134 |
|
135 test.Printf(_L("Change back to Default KeyData\n")); |
|
136 res=KeyTranslator->ChangeKeyData(_L("")); |
|
137 test(res==KErrNone); |
|
138 |
|
139 res=testLib.Load(EKDATA); |
|
140 test(res==KErrNone); |
|
141 testLib.HandleInfo(&handleInfo); |
|
142 test(handleInfo.iNumOpenInThread==2); |
|
143 testLib.Close(); |
|
144 |
|
145 res=testLib.Load(DUMMYDLL); |
|
146 test(res==KErrNone); |
|
147 testLib.HandleInfo(&handleInfo); |
|
148 test(handleInfo.iNumOpenInThread==1); |
|
149 testLib.Close(); |
|
150 |
|
151 fLib.Find(_L("*")); |
|
152 while (fLib.Next(n)==KErrNone) |
|
153 { |
|
154 TName findname=pn; |
|
155 findname+=DUMMYDLL; |
|
156 test.Printf(_L(" %S\n"),&n); |
|
157 test(n.FindF(findname) == KErrNotFound); |
|
158 } |
|
159 testConv(_L("\nFirst Special key down"),KEY_DOWN,EXPECT_KEY_PRESS,ESpecialKeyBase,ESpecialKeyBase,0); |
|
160 delete CaptureKeys; |
|
161 } |
|
162 |
|
163 void testUS(const TLocale& aLocale) |
|
164 { |
|
165 //#ifdef __WINS__ |
|
166 test(aLocale.CountryCode()==1); |
|
167 test(aLocale.DateFormat()==EDateAmerican); |
|
168 test(aLocale.TimeFormat()==ETime12); |
|
169 test(aLocale.CurrencySymbolPosition()==ELocaleBefore); |
|
170 test(aLocale.CurrencySpaceBetween()==FALSE); |
|
171 test(aLocale.CurrencyDecimalPlaces()==2); |
|
172 test(aLocale.CurrencyNegativeInBrackets()==EFalse); |
|
173 test(aLocale.CurrencyTriadsAllowed()==TRUE); |
|
174 test(aLocale.ThousandsSeparator()==','); |
|
175 test(aLocale.DecimalSeparator()=='.'); |
|
176 test(aLocale.DateSeparator(0)==0); |
|
177 test(aLocale.DateSeparator(1)=='/'); |
|
178 test(aLocale.DateSeparator(2)=='/'); |
|
179 test(aLocale.DateSeparator(3)==0); |
|
180 test(aLocale.TimeSeparator(0)==0); |
|
181 test(aLocale.TimeSeparator(1)==':'); |
|
182 test(aLocale.TimeSeparator(2)==':'); |
|
183 test(aLocale.TimeSeparator(3)==0); |
|
184 test(aLocale.AmPmSymbolPosition()==TRUE); |
|
185 test(aLocale.AmPmSpaceBetween()==TRUE); |
|
186 test(aLocale.HomeDaylightSavingZone()==EDstNorthern); |
|
187 test(aLocale.WorkDays()==0x1f); |
|
188 test(aLocale.StartOfWeek()==ESunday); |
|
189 test(aLocale.ClockFormat()==EClockAnalog); |
|
190 test(aLocale.UnitsGeneral()==EUnitsImperial); |
|
191 test(aLocale.UnitsDistanceShort()==EUnitsImperial); |
|
192 test(aLocale.UnitsDistanceLong()==EUnitsImperial); |
|
193 //#endif |
|
194 } |
|
195 |
|
196 |
|
197 void testUK(const TLocale& aLocale) |
|
198 { |
|
199 //#ifdef __WINS__ |
|
200 test(aLocale.CountryCode()==44); |
|
201 test(aLocale.DateFormat()==EDateEuropean); |
|
202 test(aLocale.TimeFormat()==ETime12); |
|
203 test(aLocale.CurrencySymbolPosition()==ELocaleBefore); |
|
204 test(aLocale.CurrencySpaceBetween()==FALSE); |
|
205 test(aLocale.CurrencyDecimalPlaces()==2); |
|
206 test(aLocale.CurrencyNegativeInBrackets()==EFalse); |
|
207 test(aLocale.CurrencyTriadsAllowed()==TRUE); |
|
208 test(aLocale.ThousandsSeparator()==','); |
|
209 test(aLocale.DecimalSeparator()=='.'); |
|
210 test(aLocale.DateSeparator(0)==0); |
|
211 test(aLocale.DateSeparator(1)=='/'); |
|
212 test(aLocale.DateSeparator(2)=='/'); |
|
213 test(aLocale.DateSeparator(3)==0); |
|
214 test(aLocale.TimeSeparator(0)==0); |
|
215 test(aLocale.TimeSeparator(1)==':'); |
|
216 test(aLocale.TimeSeparator(2)==':'); |
|
217 test(aLocale.TimeSeparator(3)==0); |
|
218 test(aLocale.AmPmSymbolPosition()==TRUE); |
|
219 test(aLocale.AmPmSpaceBetween()==TRUE); |
|
220 test(aLocale.HomeDaylightSavingZone()==EDstEuropean); |
|
221 test(aLocale.WorkDays()==0x1f); |
|
222 test(aLocale.StartOfWeek()==EMonday); |
|
223 test(aLocale.ClockFormat()==EClockAnalog); |
|
224 test(aLocale.UnitsGeneral()==EUnitsImperial); |
|
225 test(aLocale.UnitsDistanceShort()==EUnitsImperial); |
|
226 test(aLocale.UnitsDistanceLong()==EUnitsImperial); |
|
227 //#endif |
|
228 } |
|
229 |
|
230 void testGE(const TLocale& aLocale) |
|
231 { |
|
232 //#ifdef __WINS__ |
|
233 test(aLocale.CountryCode()==49); |
|
234 test(aLocale.DateFormat()==EDateEuropean); |
|
235 test(aLocale.TimeFormat()==ETime24); |
|
236 test(aLocale.CurrencySymbolPosition()==ELocaleAfter); |
|
237 test(aLocale.CurrencySpaceBetween()==TRUE); |
|
238 test(aLocale.CurrencyDecimalPlaces()==2); |
|
239 test(aLocale.CurrencyNegativeInBrackets()==TRUE); |
|
240 test(aLocale.CurrencyTriadsAllowed()==TRUE); |
|
241 test(aLocale.ThousandsSeparator()=='.'); |
|
242 test(aLocale.DecimalSeparator()==','); |
|
243 test(aLocale.DateSeparator(0)==0); |
|
244 test(aLocale.DateSeparator(1)=='.'); |
|
245 test(aLocale.DateSeparator(2)=='.'); |
|
246 test(aLocale.DateSeparator(3)==0); |
|
247 |
|
248 test(aLocale.TimeSeparator(0)==0); |
|
249 test(aLocale.TimeSeparator(1)==':'); |
|
250 test(aLocale.TimeSeparator(2)==':'); |
|
251 test(aLocale.TimeSeparator(3)==0); |
|
252 test(aLocale.AmPmSymbolPosition()==TRUE); |
|
253 test(aLocale.AmPmSpaceBetween()==TRUE); |
|
254 test(aLocale.HomeDaylightSavingZone()==EDstEuropean); |
|
255 test(aLocale.WorkDays()==0x1f); |
|
256 test(aLocale.StartOfWeek()==EMonday); |
|
257 test(aLocale.ClockFormat()==EClockDigital); |
|
258 test(aLocale.UnitsGeneral()==EUnitsMetric); |
|
259 test(aLocale.UnitsDistanceShort()==EUnitsMetric); |
|
260 test(aLocale.UnitsDistanceLong()==EUnitsMetric); |
|
261 //#endif |
|
262 } |
|
263 |
|
264 |
|
265 |
|
266 /** |
|
267 Subscribe to a system event. |
|
268 |
|
269 @param aNotifier notifier |
|
270 @param aStatus request status that is used with the notifier |
|
271 @param aEventMask Specifies the event. See TChanges |
|
272 */ |
|
273 static void SubscribeToSystemChangeNotification(RChangeNotifier& aNotifier, TRequestStatus& aStatus, TUint32 aEventMask) |
|
274 { |
|
275 |
|
276 const TInt KMaxAttempts = 100; |
|
277 TInt i; |
|
278 for(i=0; i<KMaxAttempts; ++i) |
|
279 { |
|
280 test.Printf(_L("SubscribeToSystemChangeNotification(0x%x), attempt:%d\n"), aEventMask, i); |
|
281 |
|
282 TInt nRes = aNotifier.Logon(aStatus); |
|
283 test(nRes==KErrNone); |
|
284 |
|
285 if(aStatus.Int() == KRequestPending) |
|
286 break; |
|
287 |
|
288 //-- some other system-wide event can just happen; re-subscribe |
|
289 test( !(aStatus.Int() & aEventMask)); |
|
290 } |
|
291 |
|
292 test(i<KMaxAttempts); |
|
293 } |
|
294 |
|
295 /** |
|
296 Wait for the event(s) specified in aEventMask to happen |
|
297 |
|
298 @param aNotifier notifier |
|
299 @param aStatus request status that is used with the notifier |
|
300 @param aEventMask Specifies the event. See TChanges |
|
301 */ |
|
302 static void WaitForSystemChange(RChangeNotifier& aNotifier, TRequestStatus& aStatus, TUint32 aEventMask) |
|
303 { |
|
304 //-- it would be nice to have here a timeout processing in order not to wait forever.. but later. |
|
305 for(;;) |
|
306 { |
|
307 User::WaitForRequest(aStatus); |
|
308 if(aStatus.Int() & aEventMask) |
|
309 return; |
|
310 |
|
311 //-- some other system-wide unexpected event happened, we need to resubscribe |
|
312 test.Printf(_L("WaitForSystemChange(0x%x), happened:0x%x, resubscribing...\n"), aEventMask, aStatus.Int()); |
|
313 SubscribeToSystemChangeNotification(aNotifier, aStatus, aEventMask); |
|
314 } |
|
315 |
|
316 } |
|
317 |
|
318 |
|
319 void testChangeLocale() |
|
320 { |
|
321 TLocale locale; |
|
322 |
|
323 RChangeNotifier notifier; |
|
324 TInt res=notifier.Create(); |
|
325 test(res==KErrNone); |
|
326 TRequestStatus stat; |
|
327 |
|
328 res=notifier.Logon(stat); |
|
329 test(res==KErrNone); |
|
330 // initial value of stat already tested by t_chnot |
|
331 |
|
332 SubscribeToSystemChangeNotification(notifier, stat, EChangesLocale); |
|
333 |
|
334 test.Printf(_L("Change to US Locale\n")); |
|
335 res=UserSvr::ChangeLocale(ELOCLUS); |
|
336 test.Printf(_L("res=%d\n"),res); |
|
337 test(res==KErrNone); |
|
338 |
|
339 WaitForSystemChange(notifier, stat, EChangesLocale); |
|
340 test(stat.Int() & EChangesLocale); |
|
341 |
|
342 //------------------- |
|
343 SubscribeToSystemChangeNotification(notifier, stat, EChangesLocale); |
|
344 |
|
345 locale.Refresh(); |
|
346 // let's not test localisation data details now that the internationalisation |
|
347 // team rather than us release the localisation dlls (changed 9/6/98) |
|
348 testUS(locale); |
|
349 |
|
350 test.Printf(_L("Change to GE Locale\n")); |
|
351 res=UserSvr::ChangeLocale(ELOCLGE); |
|
352 test.Printf(_L("res=%d\n"),res); |
|
353 test(res==KErrNone); |
|
354 |
|
355 WaitForSystemChange(notifier, stat, EChangesLocale); |
|
356 test(stat.Int() & EChangesLocale); |
|
357 |
|
358 //------------------- |
|
359 |
|
360 SubscribeToSystemChangeNotification(notifier, stat, EChangesLocale); |
|
361 |
|
362 locale.Refresh(); |
|
363 // let's not test localisation data details now that the internationalisation |
|
364 // team rather than us release the localisation dlls (changed 9/6/98) |
|
365 testGE(locale); |
|
366 |
|
367 test.Printf(_L("Load non ELOCL type DLL\n")); |
|
368 res=UserSvr::ChangeLocale(DUMMYDLL); |
|
369 test.Printf(_L("res=%d\n"),res); |
|
370 test(res == KErrNotSupported); |
|
371 |
|
372 //-- ensure that there wasn't locale change |
|
373 const TInt KMaxAttempts = 100; |
|
374 TInt i; |
|
375 for(i=0; i<KMaxAttempts; ++i) |
|
376 { |
|
377 if(stat ==KRequestPending) |
|
378 break; |
|
379 |
|
380 //-- check that if something system-wide happened, it wasn't a locale change |
|
381 test(!(stat.Int() & EChangesLocale)); |
|
382 SubscribeToSystemChangeNotification(notifier, stat, EChangesLocale); |
|
383 } |
|
384 test(i<KMaxAttempts); |
|
385 |
|
386 |
|
387 locale.Refresh(); |
|
388 // let's not test localisation data details now that the internationalisation |
|
389 // team rather than us release the localisation dlls (changed 9/6/98) |
|
390 testGE(locale); |
|
391 |
|
392 //This test using US1 locale is for identifying different collation table |
|
393 //used for matching and comparing. To specify a table to be used in the |
|
394 //matching we just need to add the TCollationTable::EMatchingTable flag |
|
395 //inside the TCollationMethods::iFlags |
|
396 test.Printf(_L("Change to US1 Locale\n")); |
|
397 res=UserSvr::ChangeLocale(ELOCLUS1); |
|
398 test.Printf(_L("res=%d\n"),res); |
|
399 test(res==KErrNone); |
|
400 |
|
401 WaitForSystemChange(notifier, stat, EChangesLocale); |
|
402 test(stat.Int() & EChangesLocale); |
|
403 |
|
404 |
|
405 //------------------- |
|
406 SubscribeToSystemChangeNotification(notifier, stat, EChangesLocale); |
|
407 |
|
408 locale.Refresh(); |
|
409 |
|
410 //Testing the different collation table used for Matching and Comparing |
|
411 //after loading this new locale using T_LOCLUS1.DLL. |
|
412 //test.Printf(_L("Test for differnt collation table for Matching and Comparing\n")); |
|
413 //TCollationMethod m=*Mem::GetDefaultMatchingTable(); |
|
414 //test(m.iFlags & TCollationMethod::EMatchingTable); |
|
415 |
|
416 //The collation table t_locl.cpp can be found in \locl\t_locl.cpp |
|
417 //Expected collation override for MatchC A==B and a==b |
|
418 //Expected collation override for CompareC A>B and a>b |
|
419 //Collation tables cannot be changed at runtime |
|
420 /* TBuf16<1> a_cap(_L("A")); |
|
421 TBuf16<1> a_small(_L("a")); |
|
422 |
|
423 //Test using the locale independent matching and comparing |
|
424 test(a_cap.Match(_L("B"))!=0); |
|
425 test(a_cap.Compare(_L("B"))<0); |
|
426 test(a_small.Match(_L("b"))!=0); |
|
427 test(a_small.Compare(_L("b"))<0); |
|
428 //Test that the default collation table(1st table) is selected here |
|
429 test(a_cap.CompareC(_L("B"))!=0); |
|
430 test(a_small.CompareC(_L("b"))!=0); |
|
431 test(a_cap.CompareC(_L("B"))>0); |
|
432 test(a_small.CompareC(_L("b"))>0); |
|
433 //Test that the Matching collation table(3rd table) is selected here |
|
434 test(a_cap.MatchC(_L("B"))==0); |
|
435 test(a_small.MatchC(_L("b"))==0); |
|
436 */ |
|
437 test.Printf(_L("Back to default UK Locale\n")); |
|
438 res=UserSvr::ChangeLocale(ELOCL_DEFAULT); |
|
439 test.Printf(_L("res=%d\n"),res); |
|
440 test(res==KErrNone); |
|
441 |
|
442 WaitForSystemChange(notifier, stat, EChangesLocale); |
|
443 test(stat.Int() & EChangesLocale); |
|
444 |
|
445 //------------------- |
|
446 |
|
447 SubscribeToSystemChangeNotification(notifier, stat, EChangesLocale); |
|
448 |
|
449 locale.Refresh(); |
|
450 testUK(locale); |
|
451 |
|
452 //Test for locale which does not have a matching collation table |
|
453 TCollationMethod m1=*Mem::GetDefaultMatchingTable(); |
|
454 test((m1.iFlags & TCollationMethod::EMatchingTable)==0); |
|
455 |
|
456 //************************************************ |
|
457 test.Printf(_L("Change to US Locale with file open on drive\n")); |
|
458 |
|
459 _LIT(KTestFile, "TEST.TXT"); |
|
460 RFile file; |
|
461 res = file.Replace(TheFs, KTestFile, 0); |
|
462 test(res == KErrNone); |
|
463 |
|
464 |
|
465 res=UserSvr::ChangeLocale(ELOCLUS); |
|
466 test.Printf(_L("res=%d\n"),res); |
|
467 test(res==KErrNone); |
|
468 |
|
469 |
|
470 WaitForSystemChange(notifier, stat, EChangesLocale); |
|
471 test(stat.Int() & EChangesLocale); |
|
472 |
|
473 |
|
474 //------------------- |
|
475 SubscribeToSystemChangeNotification(notifier, stat, EChangesLocale); |
|
476 |
|
477 |
|
478 _LIT8(KTestData, "Arsenal"); |
|
479 res = file.Write(KTestData); |
|
480 test(res==KErrNone); |
|
481 file.Close(); |
|
482 |
|
483 res = file.Open(TheFs, KTestFile, 0); |
|
484 test(res == KErrNone); |
|
485 file.Close(); |
|
486 res = TheFs.Delete(KTestFile); |
|
487 test(res==KErrNone); |
|
488 |
|
489 //************************************************ |
|
490 |
|
491 //-- close the notifier |
|
492 notifier.Close(); |
|
493 User::WaitForRequest(stat); |
|
494 |
|
495 //-- n.b. it's actually a bad idea to expect _exact_ event completion from the RChangeNotifier, because |
|
496 //-- this is a system-wide events observer and any of the TChanges events can happen, not only EChangesLocale. |
|
497 //-- so this test is a bit flawed. |
|
498 |
|
499 //test(stat==KErrGeneral); |
|
500 } |
|
501 |
|
502 const TText * const DateSuffixTable[KMaxSuffixes] = |
|
503 { |
|
504 _S("st"),_S("nd"),_S("rd"),_S("th"),_S("th"), |
|
505 _S("th"),_S("th"),_S("th"),_S("th"),_S("th"), |
|
506 _S("th"),_S("th"),_S("th"),_S("th"),_S("th"), |
|
507 _S("th"),_S("th"),_S("th"),_S("th"),_S("th"), |
|
508 _S("st"),_S("nd"),_S("rd"),_S("th"),_S("th"), |
|
509 _S("th"),_S("th"),_S("th"),_S("th"),_S("th"), |
|
510 _S("st") |
|
511 }; |
|
512 |
|
513 const TText * const DayTable[KMaxDays] = |
|
514 { |
|
515 _S("Monday"), |
|
516 _S("Tuesday"), |
|
517 _S("Wednesday"), |
|
518 _S("Thursday"), |
|
519 _S("Friday"), |
|
520 _S("Saturday"), |
|
521 _S("Sunday") |
|
522 }; |
|
523 |
|
524 const TText * const DayAbbTable[KMaxDays] = |
|
525 { |
|
526 _S("Mon"), |
|
527 _S("Tue"), |
|
528 _S("Wed"), |
|
529 _S("Thu"), |
|
530 _S("Fri"), |
|
531 _S("Sat"), |
|
532 _S("Sun") |
|
533 }; |
|
534 |
|
535 const TText * const MonthTable[KMaxMonths] = |
|
536 { |
|
537 _S("January"), |
|
538 _S("February"), |
|
539 _S("March"), |
|
540 _S("April"), |
|
541 _S("May"), |
|
542 _S("June"), |
|
543 _S("July"), |
|
544 _S("August"), |
|
545 _S("September"), |
|
546 _S("October"), |
|
547 _S("November"), |
|
548 _S("December") |
|
549 }; |
|
550 |
|
551 const TText * const MonthAbbTable[KMaxMonths] = |
|
552 { |
|
553 _S("Jan"), |
|
554 _S("Feb"), |
|
555 _S("Mar"), |
|
556 _S("Apr"), |
|
557 _S("May"), |
|
558 _S("Jun"), |
|
559 _S("Jul"), |
|
560 _S("Aug"), |
|
561 _S("Sep"), |
|
562 _S("Oct"), |
|
563 _S("Nov"), |
|
564 _S("Dec") |
|
565 }; |
|
566 |
|
567 const TText * const AmPmTable[KMaxAmPms] = {_S("am"),_S("pm")}; |
|
568 |
|
569 void testExtendedUS(TUint aAspect, TExtendedLocale& aLocale) |
|
570 { |
|
571 TLocale* loc = aLocale.GetLocale(); |
|
572 testUS(*loc); |
|
573 |
|
574 if(aAspect & ELocaleLanguageSettings) |
|
575 { |
|
576 TLanguage tl = User::Language(); |
|
577 test(tl == ELangAmerican); |
|
578 |
|
579 TDateSuffix datesuffix; |
|
580 TInt i; |
|
581 for(i=0;i<KMaxSuffixes;++i) |
|
582 { |
|
583 datesuffix.Set(i); |
|
584 test(datesuffix.Compare(TPtrC(DateSuffixTable[i])) == 0); |
|
585 } |
|
586 |
|
587 TDayName dayname; |
|
588 for(i=0;i<KMaxDays;++i) |
|
589 { |
|
590 dayname.Set((TDay)i); |
|
591 test(dayname.Compare(TPtrC(DayTable[i])) == 0); |
|
592 } |
|
593 |
|
594 TDayNameAbb daynameabb; |
|
595 for(i=0;i<KMaxDays;++i) |
|
596 { |
|
597 daynameabb.Set((TDay)i); |
|
598 test(daynameabb.Compare(TPtrC(DayAbbTable[i])) == 0); |
|
599 } |
|
600 |
|
601 TMonthName monthname; |
|
602 for(i=0;i<KMaxMonths;++i) |
|
603 { |
|
604 monthname.Set((TMonth)i); |
|
605 test(monthname.Compare(TPtrC(MonthTable[i])) == 0); |
|
606 } |
|
607 |
|
608 TMonthNameAbb monthnameabb; |
|
609 for(i=0;i<KMaxMonths;++i) |
|
610 { |
|
611 monthnameabb.Set((TMonth)i); |
|
612 test(monthnameabb.Compare(TPtrC(MonthAbbTable[i])) == 0); |
|
613 } |
|
614 |
|
615 TAmPmName ampmname; |
|
616 for(i=0;i<KMaxAmPms;++i) |
|
617 { |
|
618 ampmname.Set((TAmPm)i); |
|
619 test(ampmname.Compare(TPtrC(AmPmTable[i])) == 0); |
|
620 } |
|
621 } |
|
622 |
|
623 if(aAspect & ELocaleLocaleSettings) |
|
624 { |
|
625 TCurrencySymbol symbol; |
|
626 symbol.Set(); |
|
627 test(symbol.Compare(TPtrC(_S("$"))) == 0); |
|
628 } |
|
629 |
|
630 if(aAspect & ELocaleTimeDateSettings) |
|
631 { |
|
632 TShortDateFormatSpec shortdate; |
|
633 shortdate.Set(); |
|
634 test(shortdate.Compare(TPtrC(_S("%F%*M/%*D/%Y"))) == 0); |
|
635 |
|
636 TLongDateFormatSpec longdate; |
|
637 longdate.Set(); |
|
638 test(longdate.Compare(TPtrC(_S("%F%*D%X %N %Y"))) == 0); |
|
639 |
|
640 TTimeFormatSpec spec; |
|
641 spec.Set(); |
|
642 test(spec.Compare(TPtrC(_S("%F%*I:%T:%S %*A"))) == 0); |
|
643 } |
|
644 |
|
645 } |
|
646 |
|
647 |
|
648 void testExtendedLocale() |
|
649 { |
|
650 TExtendedLocale locale; |
|
651 locale.LoadLocale(ELOCLUS); |
|
652 TInt r = locale.SaveSystemSettings(); |
|
653 test(r == KErrNone); |
|
654 testExtendedUS(ELocaleLanguageSettings | ELocaleCollateSetting | ELocaleLocaleSettings | ELocaleTimeDateSettings, locale); |
|
655 |
|
656 r = locale.SetCurrencySymbol(TPtrC(_S("Leu"))); |
|
657 test(r == KErrNone); |
|
658 TCurrencySymbol symbol; |
|
659 symbol.Set(); |
|
660 test(symbol.Compare(TPtrC(_S("Leu"))) == 0); |
|
661 |
|
662 User::SetCurrencySymbol(TPtrC(_S("Le"))); |
|
663 symbol.Set(); |
|
664 test(symbol.Compare(TPtrC(_S("Le"))) == 0); |
|
665 |
|
666 TFileName dllName; |
|
667 TFileName eloclus; |
|
668 eloclus.Copy(ELOCLUS); |
|
669 eloclus.Append(TPtrC(KDLLExtension)); |
|
670 r = locale.GetLocaleDllName(ELocaleLanguageSettings, dllName); |
|
671 test(r == KErrNone); |
|
672 test.Printf(_L("dllName looking for %s (%s)\n"), dllName.Ptr(), eloclus.Ptr()); |
|
673 test(dllName.Find(eloclus) != KErrNotFound); |
|
674 |
|
675 dllName.FillZ(); |
|
676 |
|
677 r = locale.GetLocaleDllName(ELocaleCollateSetting, dllName); |
|
678 test(r == KErrNone); |
|
679 test(dllName.Find(eloclus) != KErrNotFound); |
|
680 |
|
681 dllName.FillZ(); |
|
682 |
|
683 r = locale.GetLocaleDllName(ELocaleLocaleSettings, dllName); |
|
684 test(r == KErrNone); |
|
685 test(dllName.Find(eloclus) != KErrNotFound); |
|
686 |
|
687 dllName.FillZ(); |
|
688 |
|
689 r = locale.GetLocaleDllName(ELocaleTimeDateSettings, dllName); |
|
690 test(r == KErrNone); |
|
691 test(dllName.Find(eloclus) != KErrNotFound); |
|
692 |
|
693 dllName.FillZ(); |
|
694 |
|
695 r = locale.LoadLocaleAspect(ELocaleLocaleSettings | ELocaleTimeDateSettings, ELOCLGE); |
|
696 test(r == KErrNone); |
|
697 |
|
698 r = locale.SaveSystemSettings(); |
|
699 test(r == KErrNone); |
|
700 |
|
701 testExtendedUS(ELocaleLanguageSettings | ELocaleCollateSetting, locale); |
|
702 |
|
703 symbol.Set(); |
|
704 test(symbol.Compare(TPtrC(_S("DM"))) == 0); |
|
705 |
|
706 TShortDateFormatSpec shortdate; |
|
707 shortdate.Set(); |
|
708 test(shortdate.Compare(TPtrC(_S("%F%*D.%*M.%Y"))) == 0); |
|
709 |
|
710 TLongDateFormatSpec longdate; |
|
711 longdate.Set(); |
|
712 test(longdate.Compare(TPtrC(_S("%F%*D%X %N %Y"))) == 0); |
|
713 |
|
714 TTimeFormatSpec spec; |
|
715 spec.Set(); |
|
716 test(spec.Compare(TPtrC(_S("%F%H:%T:%S"))) == 0); |
|
717 |
|
718 TFileName eloclge; |
|
719 eloclge.Copy(ELOCLGE); |
|
720 eloclge.Append(KDLLExtension); |
|
721 r = locale.GetLocaleDllName(ELocaleLanguageSettings, dllName); |
|
722 test(r == KErrNone); |
|
723 test(dllName.Find(eloclus) != KErrNotFound); |
|
724 |
|
725 dllName.FillZ(); |
|
726 |
|
727 r = locale.GetLocaleDllName(ELocaleCollateSetting, dllName); |
|
728 test(r == KErrNone); |
|
729 test(dllName.Find(eloclus) != KErrNotFound); |
|
730 |
|
731 dllName.FillZ(); |
|
732 |
|
733 r = locale.GetLocaleDllName(ELocaleLocaleSettings, dllName); |
|
734 test(r == KErrNone); |
|
735 test(dllName.Find(eloclge) != KErrNotFound); |
|
736 |
|
737 dllName.FillZ(); |
|
738 |
|
739 r = locale.GetLocaleDllName(ELocaleTimeDateSettings, dllName); |
|
740 test(r == KErrNone); |
|
741 test(dllName.Find(eloclge) != KErrNotFound); |
|
742 |
|
743 dllName.FillZ(); |
|
744 |
|
745 } |
|
746 |
|
747 void testDigitsInMonthsNames() |
|
748 { |
|
749 test.Next(_L("Testing date parsing when month names include digits")); |
|
750 |
|
751 TTime time; |
|
752 _LIT(KMonthJan, "30 Th1 2006 14:31:50"); |
|
753 test_Equal(KErrArgument, time.Parse(KMonthJan)); |
|
754 test_KErrNone(UserSvr::ChangeLocale(ELOCLUS2)); |
|
755 test_Equal(EParseDatePresent | EParseTimePresent, time.Parse(KMonthJan)); |
|
756 test_KErrNone(UserSvr::ChangeLocale(ELOCL_DEFAULT)); |
|
757 } |
|
758 |
|
759 GLDEF_C void CallTestsL(void) |
|
760 { |
|
761 |
|
762 test.Title(); |
|
763 test.Start(_L("Starting T_DLOCL tests")); |
|
764 |
|
765 testChangeLocale(); |
|
766 testChangeKeyData(); |
|
767 testExtendedLocale(); |
|
768 testDigitsInMonthsNames(); |
|
769 test.Next(_L("Close connection to the file server\n")); |
|
770 |
|
771 test.End(); |
|
772 } |
|
773 |