1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/server/t_dlocl.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,773 @@
1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// f32test\server\t_dlocl.cpp
1.18 +// Tests UserSvr::ChangeLocale() function
1.19 +//
1.20 +//
1.21 +
1.22 +#define __E32TEST_EXTENSION__
1.23 +
1.24 +#include <e32std.h>
1.25 +#include <e32std_private.h>
1.26 +#include <e32test.h>
1.27 +#include <f32file.h>
1.28 +#include <e32svr.h>
1.29 +#include <collate.h>
1.30 +
1.31 +#include "t_server.h"
1.32 +
1.33 +LOCAL_D TFindLibrary fLib;
1.34 +
1.35 +typedef TInt (*TLibEntry)(TInt);
1.36 +typedef TInt (*TLibEntry2)();
1.37 +
1.38 +const TBool KEY_DOWN=EFalse;
1.39 +const TBool EXPECT_KEY_PRESS=ETrue;
1.40 +
1.41 +RTest test(_L("T_DLOCL"));
1.42 +
1.43 +_LIT(ELOCL_DEFAULT, "");
1.44 +_LIT(ELOCLGE, "T_LOCLGE");
1.45 +_LIT(ELOCLUS, "T_LOCLUS");
1.46 +_LIT(ELOCLUS1, "T_LOCLUS1");
1.47 +_LIT(ELOCLUS2, "T_LOCLUS2");
1.48 +_LIT(EKDATA, "EKDATA");
1.49 +_LIT(DUMMYDLL, "EDISP");
1.50 +_LIT(KColonColon, "::");
1.51 +_LIT(KDLLExtension, ".DLL");
1.52 +
1.53 +GLDEF_D CKeyTranslator *KeyTranslator=CKeyTranslator::New();
1.54 +LOCAL_D CCaptureKeys *CaptureKeys;
1.55 +
1.56 +void testConv(const TDesC& aDes,TBool aKeyup,TBool aRet,TUint aScanCode,TUint aKeyCode,TInt aModifiers)
1.57 + {
1.58 +
1.59 + TKeyData keyData;
1.60 + TBool ret=KeyTranslator->TranslateKey(aScanCode, aKeyup,*CaptureKeys,keyData);
1.61 + test.Next(aDes);
1.62 + test(ret==aRet);
1.63 + test((keyData.iKeyCode==aKeyCode));
1.64 + test((keyData.iModifiers==aModifiers));
1.65 + }
1.66 +
1.67 +void testChangeKeyData()
1.68 + {
1.69 + TName pn(RProcess().Name());
1.70 + pn+=KColonColon;
1.71 + TFullName n;
1.72 + CaptureKeys=new CCaptureKeys();
1.73 + CaptureKeys->Construct();
1.74 + test.Printf(_L("Test default key data\n"));
1.75 + testConv(_L("\nFirst Special key down"),KEY_DOWN,EXPECT_KEY_PRESS,ESpecialKeyBase,ESpecialKeyBase,0);
1.76 +
1.77 + RLibrary testLib;
1.78 + TInt res=testLib.Load(EKDATA);
1.79 + test(res==KErrNone);
1.80 + THandleInfo handleInfo;
1.81 + testLib.HandleInfo(&handleInfo);
1.82 + test(handleInfo.iNumOpenInThread==2);
1.83 + testLib.Close();
1.84 +
1.85 + test.Printf(_L("Change to unknown dll \n")); // Test with non keydata type dll
1.86 + res=KeyTranslator->ChangeKeyData(DUMMYDLL);
1.87 + test(res==KErrArgument);
1.88 +
1.89 + res=testLib.Load(EKDATA);
1.90 + test(res==KErrNone);
1.91 + testLib.HandleInfo(&handleInfo);
1.92 + test(handleInfo.iNumOpenInThread==2);
1.93 + testLib.Close();
1.94 +
1.95 + res=testLib.Load(DUMMYDLL);
1.96 + test(res==KErrNone);
1.97 + testLib.HandleInfo(&handleInfo);
1.98 + test(handleInfo.iNumOpenInThread==1);
1.99 + testLib.Close();
1.100 +
1.101 + fLib.Find(_L("*"));
1.102 + while (fLib.Next(n)==KErrNone)
1.103 + {
1.104 + TName findname=pn;
1.105 + findname+=DUMMYDLL;
1.106 + test.Printf(_L(" %S\n"),&n);
1.107 + test(n.FindF(findname) == KErrNotFound);
1.108 + }
1.109 + //
1.110 + test.Printf(_L("Change to EKDATA.dll\n"));
1.111 + res=KeyTranslator->ChangeKeyData(EKDATA);
1.112 + test(res==KErrNone);
1.113 +
1.114 + res=testLib.Load(EKDATA);
1.115 + test(res==KErrNone);
1.116 + testLib.HandleInfo(&handleInfo);
1.117 + test(handleInfo.iNumOpenInThread==2);
1.118 + testLib.Close();
1.119 + res=testLib.Load(DUMMYDLL);
1.120 + test(res==KErrNone);
1.121 + testLib.HandleInfo(&handleInfo);
1.122 + test(handleInfo.iNumOpenInThread==1);
1.123 + testLib.Close();
1.124 +
1.125 + fLib.Find(_L("*"));
1.126 + while (fLib.Next(n)==KErrNone)
1.127 + {
1.128 + TName findname=pn;
1.129 + findname+=EKDATA;
1.130 + test.Printf(_L(" %S\n"),&n);
1.131 + if(n.FindF(findname) != KErrNotFound)
1.132 + break;
1.133 + }
1.134 + //The test below fails if we use Secure APIs
1.135 + //test(n.FindF(EKDATA) == KErrNotSupported);
1.136 + testConv(_L("\nFirst Special key down"),KEY_DOWN,EXPECT_KEY_PRESS,ESpecialKeyBase,ESpecialKeyBase,0);
1.137 +
1.138 + test.Printf(_L("Change back to Default KeyData\n"));
1.139 + res=KeyTranslator->ChangeKeyData(_L(""));
1.140 + test(res==KErrNone);
1.141 +
1.142 + res=testLib.Load(EKDATA);
1.143 + test(res==KErrNone);
1.144 + testLib.HandleInfo(&handleInfo);
1.145 + test(handleInfo.iNumOpenInThread==2);
1.146 + testLib.Close();
1.147 +
1.148 + res=testLib.Load(DUMMYDLL);
1.149 + test(res==KErrNone);
1.150 + testLib.HandleInfo(&handleInfo);
1.151 + test(handleInfo.iNumOpenInThread==1);
1.152 + testLib.Close();
1.153 +
1.154 + fLib.Find(_L("*"));
1.155 + while (fLib.Next(n)==KErrNone)
1.156 + {
1.157 + TName findname=pn;
1.158 + findname+=DUMMYDLL;
1.159 + test.Printf(_L(" %S\n"),&n);
1.160 + test(n.FindF(findname) == KErrNotFound);
1.161 + }
1.162 + testConv(_L("\nFirst Special key down"),KEY_DOWN,EXPECT_KEY_PRESS,ESpecialKeyBase,ESpecialKeyBase,0);
1.163 + delete CaptureKeys;
1.164 + }
1.165 +
1.166 +void testUS(const TLocale& aLocale)
1.167 + {
1.168 +//#ifdef __WINS__
1.169 + test(aLocale.CountryCode()==1);
1.170 + test(aLocale.DateFormat()==EDateAmerican);
1.171 + test(aLocale.TimeFormat()==ETime12);
1.172 + test(aLocale.CurrencySymbolPosition()==ELocaleBefore);
1.173 + test(aLocale.CurrencySpaceBetween()==FALSE);
1.174 + test(aLocale.CurrencyDecimalPlaces()==2);
1.175 + test(aLocale.CurrencyNegativeInBrackets()==EFalse);
1.176 + test(aLocale.CurrencyTriadsAllowed()==TRUE);
1.177 + test(aLocale.ThousandsSeparator()==',');
1.178 + test(aLocale.DecimalSeparator()=='.');
1.179 + test(aLocale.DateSeparator(0)==0);
1.180 + test(aLocale.DateSeparator(1)=='/');
1.181 + test(aLocale.DateSeparator(2)=='/');
1.182 + test(aLocale.DateSeparator(3)==0);
1.183 + test(aLocale.TimeSeparator(0)==0);
1.184 + test(aLocale.TimeSeparator(1)==':');
1.185 + test(aLocale.TimeSeparator(2)==':');
1.186 + test(aLocale.TimeSeparator(3)==0);
1.187 + test(aLocale.AmPmSymbolPosition()==TRUE);
1.188 + test(aLocale.AmPmSpaceBetween()==TRUE);
1.189 + test(aLocale.HomeDaylightSavingZone()==EDstNorthern);
1.190 + test(aLocale.WorkDays()==0x1f);
1.191 + test(aLocale.StartOfWeek()==ESunday);
1.192 + test(aLocale.ClockFormat()==EClockAnalog);
1.193 + test(aLocale.UnitsGeneral()==EUnitsImperial);
1.194 + test(aLocale.UnitsDistanceShort()==EUnitsImperial);
1.195 + test(aLocale.UnitsDistanceLong()==EUnitsImperial);
1.196 +//#endif
1.197 + }
1.198 +
1.199 +
1.200 +void testUK(const TLocale& aLocale)
1.201 + {
1.202 +//#ifdef __WINS__
1.203 + test(aLocale.CountryCode()==44);
1.204 + test(aLocale.DateFormat()==EDateEuropean);
1.205 + test(aLocale.TimeFormat()==ETime12);
1.206 + test(aLocale.CurrencySymbolPosition()==ELocaleBefore);
1.207 + test(aLocale.CurrencySpaceBetween()==FALSE);
1.208 + test(aLocale.CurrencyDecimalPlaces()==2);
1.209 + test(aLocale.CurrencyNegativeInBrackets()==EFalse);
1.210 + test(aLocale.CurrencyTriadsAllowed()==TRUE);
1.211 + test(aLocale.ThousandsSeparator()==',');
1.212 + test(aLocale.DecimalSeparator()=='.');
1.213 + test(aLocale.DateSeparator(0)==0);
1.214 + test(aLocale.DateSeparator(1)=='/');
1.215 + test(aLocale.DateSeparator(2)=='/');
1.216 + test(aLocale.DateSeparator(3)==0);
1.217 + test(aLocale.TimeSeparator(0)==0);
1.218 + test(aLocale.TimeSeparator(1)==':');
1.219 + test(aLocale.TimeSeparator(2)==':');
1.220 + test(aLocale.TimeSeparator(3)==0);
1.221 + test(aLocale.AmPmSymbolPosition()==TRUE);
1.222 + test(aLocale.AmPmSpaceBetween()==TRUE);
1.223 + test(aLocale.HomeDaylightSavingZone()==EDstEuropean);
1.224 + test(aLocale.WorkDays()==0x1f);
1.225 + test(aLocale.StartOfWeek()==EMonday);
1.226 + test(aLocale.ClockFormat()==EClockAnalog);
1.227 + test(aLocale.UnitsGeneral()==EUnitsImperial);
1.228 + test(aLocale.UnitsDistanceShort()==EUnitsImperial);
1.229 + test(aLocale.UnitsDistanceLong()==EUnitsImperial);
1.230 +//#endif
1.231 + }
1.232 +
1.233 +void testGE(const TLocale& aLocale)
1.234 + {
1.235 +//#ifdef __WINS__
1.236 + test(aLocale.CountryCode()==49);
1.237 + test(aLocale.DateFormat()==EDateEuropean);
1.238 + test(aLocale.TimeFormat()==ETime24);
1.239 + test(aLocale.CurrencySymbolPosition()==ELocaleAfter);
1.240 + test(aLocale.CurrencySpaceBetween()==TRUE);
1.241 + test(aLocale.CurrencyDecimalPlaces()==2);
1.242 + test(aLocale.CurrencyNegativeInBrackets()==TRUE);
1.243 + test(aLocale.CurrencyTriadsAllowed()==TRUE);
1.244 + test(aLocale.ThousandsSeparator()=='.');
1.245 + test(aLocale.DecimalSeparator()==',');
1.246 + test(aLocale.DateSeparator(0)==0);
1.247 + test(aLocale.DateSeparator(1)=='.');
1.248 + test(aLocale.DateSeparator(2)=='.');
1.249 + test(aLocale.DateSeparator(3)==0);
1.250 +
1.251 + test(aLocale.TimeSeparator(0)==0);
1.252 + test(aLocale.TimeSeparator(1)==':');
1.253 + test(aLocale.TimeSeparator(2)==':');
1.254 + test(aLocale.TimeSeparator(3)==0);
1.255 + test(aLocale.AmPmSymbolPosition()==TRUE);
1.256 + test(aLocale.AmPmSpaceBetween()==TRUE);
1.257 + test(aLocale.HomeDaylightSavingZone()==EDstEuropean);
1.258 + test(aLocale.WorkDays()==0x1f);
1.259 + test(aLocale.StartOfWeek()==EMonday);
1.260 + test(aLocale.ClockFormat()==EClockDigital);
1.261 + test(aLocale.UnitsGeneral()==EUnitsMetric);
1.262 + test(aLocale.UnitsDistanceShort()==EUnitsMetric);
1.263 + test(aLocale.UnitsDistanceLong()==EUnitsMetric);
1.264 +//#endif
1.265 + }
1.266 +
1.267 +
1.268 +
1.269 +/**
1.270 + Subscribe to a system event.
1.271 +
1.272 + @param aNotifier notifier
1.273 + @param aStatus request status that is used with the notifier
1.274 + @param aEventMask Specifies the event. See TChanges
1.275 +*/
1.276 +static void SubscribeToSystemChangeNotification(RChangeNotifier& aNotifier, TRequestStatus& aStatus, TUint32 aEventMask)
1.277 +{
1.278 +
1.279 + const TInt KMaxAttempts = 100;
1.280 + TInt i;
1.281 + for(i=0; i<KMaxAttempts; ++i)
1.282 + {
1.283 + test.Printf(_L("SubscribeToSystemChangeNotification(0x%x), attempt:%d\n"), aEventMask, i);
1.284 +
1.285 + TInt nRes = aNotifier.Logon(aStatus);
1.286 + test(nRes==KErrNone);
1.287 +
1.288 + if(aStatus.Int() == KRequestPending)
1.289 + break;
1.290 +
1.291 + //-- some other system-wide event can just happen; re-subscribe
1.292 + test( !(aStatus.Int() & aEventMask));
1.293 + }
1.294 +
1.295 + test(i<KMaxAttempts);
1.296 +}
1.297 +
1.298 +/**
1.299 + Wait for the event(s) specified in aEventMask to happen
1.300 +
1.301 + @param aNotifier notifier
1.302 + @param aStatus request status that is used with the notifier
1.303 + @param aEventMask Specifies the event. See TChanges
1.304 +*/
1.305 +static void WaitForSystemChange(RChangeNotifier& aNotifier, TRequestStatus& aStatus, TUint32 aEventMask)
1.306 +{
1.307 + //-- it would be nice to have here a timeout processing in order not to wait forever.. but later.
1.308 + for(;;)
1.309 + {
1.310 + User::WaitForRequest(aStatus);
1.311 + if(aStatus.Int() & aEventMask)
1.312 + return;
1.313 +
1.314 + //-- some other system-wide unexpected event happened, we need to resubscribe
1.315 + test.Printf(_L("WaitForSystemChange(0x%x), happened:0x%x, resubscribing...\n"), aEventMask, aStatus.Int());
1.316 + SubscribeToSystemChangeNotification(aNotifier, aStatus, aEventMask);
1.317 + }
1.318 +
1.319 +}
1.320 +
1.321 +
1.322 +void testChangeLocale()
1.323 + {
1.324 + TLocale locale;
1.325 +
1.326 + RChangeNotifier notifier;
1.327 + TInt res=notifier.Create();
1.328 + test(res==KErrNone);
1.329 + TRequestStatus stat;
1.330 +
1.331 + res=notifier.Logon(stat);
1.332 + test(res==KErrNone);
1.333 + // initial value of stat already tested by t_chnot
1.334 +
1.335 + SubscribeToSystemChangeNotification(notifier, stat, EChangesLocale);
1.336 +
1.337 + test.Printf(_L("Change to US Locale\n"));
1.338 + res=UserSvr::ChangeLocale(ELOCLUS);
1.339 + test.Printf(_L("res=%d\n"),res);
1.340 + test(res==KErrNone);
1.341 +
1.342 + WaitForSystemChange(notifier, stat, EChangesLocale);
1.343 + test(stat.Int() & EChangesLocale);
1.344 +
1.345 + //-------------------
1.346 + SubscribeToSystemChangeNotification(notifier, stat, EChangesLocale);
1.347 +
1.348 + locale.Refresh();
1.349 + // let's not test localisation data details now that the internationalisation
1.350 + // team rather than us release the localisation dlls (changed 9/6/98)
1.351 + testUS(locale);
1.352 +
1.353 + test.Printf(_L("Change to GE Locale\n"));
1.354 + res=UserSvr::ChangeLocale(ELOCLGE);
1.355 + test.Printf(_L("res=%d\n"),res);
1.356 + test(res==KErrNone);
1.357 +
1.358 + WaitForSystemChange(notifier, stat, EChangesLocale);
1.359 + test(stat.Int() & EChangesLocale);
1.360 +
1.361 + //-------------------
1.362 +
1.363 + SubscribeToSystemChangeNotification(notifier, stat, EChangesLocale);
1.364 +
1.365 + locale.Refresh();
1.366 + // let's not test localisation data details now that the internationalisation
1.367 + // team rather than us release the localisation dlls (changed 9/6/98)
1.368 + testGE(locale);
1.369 +
1.370 + test.Printf(_L("Load non ELOCL type DLL\n"));
1.371 + res=UserSvr::ChangeLocale(DUMMYDLL);
1.372 + test.Printf(_L("res=%d\n"),res);
1.373 + test(res == KErrNotSupported);
1.374 +
1.375 + //-- ensure that there wasn't locale change
1.376 + const TInt KMaxAttempts = 100;
1.377 + TInt i;
1.378 + for(i=0; i<KMaxAttempts; ++i)
1.379 + {
1.380 + if(stat ==KRequestPending)
1.381 + break;
1.382 +
1.383 + //-- check that if something system-wide happened, it wasn't a locale change
1.384 + test(!(stat.Int() & EChangesLocale));
1.385 + SubscribeToSystemChangeNotification(notifier, stat, EChangesLocale);
1.386 + }
1.387 + test(i<KMaxAttempts);
1.388 +
1.389 +
1.390 + locale.Refresh();
1.391 + // let's not test localisation data details now that the internationalisation
1.392 + // team rather than us release the localisation dlls (changed 9/6/98)
1.393 + testGE(locale);
1.394 +
1.395 + //This test using US1 locale is for identifying different collation table
1.396 + //used for matching and comparing. To specify a table to be used in the
1.397 + //matching we just need to add the TCollationTable::EMatchingTable flag
1.398 + //inside the TCollationMethods::iFlags
1.399 + test.Printf(_L("Change to US1 Locale\n"));
1.400 + res=UserSvr::ChangeLocale(ELOCLUS1);
1.401 + test.Printf(_L("res=%d\n"),res);
1.402 + test(res==KErrNone);
1.403 +
1.404 + WaitForSystemChange(notifier, stat, EChangesLocale);
1.405 + test(stat.Int() & EChangesLocale);
1.406 +
1.407 +
1.408 + //-------------------
1.409 + SubscribeToSystemChangeNotification(notifier, stat, EChangesLocale);
1.410 +
1.411 + locale.Refresh();
1.412 +
1.413 + //Testing the different collation table used for Matching and Comparing
1.414 + //after loading this new locale using T_LOCLUS1.DLL.
1.415 + //test.Printf(_L("Test for differnt collation table for Matching and Comparing\n"));
1.416 + //TCollationMethod m=*Mem::GetDefaultMatchingTable();
1.417 + //test(m.iFlags & TCollationMethod::EMatchingTable);
1.418 +
1.419 + //The collation table t_locl.cpp can be found in \locl\t_locl.cpp
1.420 + //Expected collation override for MatchC A==B and a==b
1.421 + //Expected collation override for CompareC A>B and a>b
1.422 + //Collation tables cannot be changed at runtime
1.423 +/* TBuf16<1> a_cap(_L("A"));
1.424 + TBuf16<1> a_small(_L("a"));
1.425 +
1.426 + //Test using the locale independent matching and comparing
1.427 + test(a_cap.Match(_L("B"))!=0);
1.428 + test(a_cap.Compare(_L("B"))<0);
1.429 + test(a_small.Match(_L("b"))!=0);
1.430 + test(a_small.Compare(_L("b"))<0);
1.431 + //Test that the default collation table(1st table) is selected here
1.432 + test(a_cap.CompareC(_L("B"))!=0);
1.433 + test(a_small.CompareC(_L("b"))!=0);
1.434 + test(a_cap.CompareC(_L("B"))>0);
1.435 + test(a_small.CompareC(_L("b"))>0);
1.436 + //Test that the Matching collation table(3rd table) is selected here
1.437 + test(a_cap.MatchC(_L("B"))==0);
1.438 + test(a_small.MatchC(_L("b"))==0);
1.439 +*/
1.440 + test.Printf(_L("Back to default UK Locale\n"));
1.441 + res=UserSvr::ChangeLocale(ELOCL_DEFAULT);
1.442 + test.Printf(_L("res=%d\n"),res);
1.443 + test(res==KErrNone);
1.444 +
1.445 + WaitForSystemChange(notifier, stat, EChangesLocale);
1.446 + test(stat.Int() & EChangesLocale);
1.447 +
1.448 + //-------------------
1.449 +
1.450 + SubscribeToSystemChangeNotification(notifier, stat, EChangesLocale);
1.451 +
1.452 + locale.Refresh();
1.453 + testUK(locale);
1.454 +
1.455 + //Test for locale which does not have a matching collation table
1.456 + TCollationMethod m1=*Mem::GetDefaultMatchingTable();
1.457 + test((m1.iFlags & TCollationMethod::EMatchingTable)==0);
1.458 +
1.459 + //************************************************
1.460 + test.Printf(_L("Change to US Locale with file open on drive\n"));
1.461 +
1.462 + _LIT(KTestFile, "TEST.TXT");
1.463 + RFile file;
1.464 + res = file.Replace(TheFs, KTestFile, 0);
1.465 + test(res == KErrNone);
1.466 +
1.467 +
1.468 + res=UserSvr::ChangeLocale(ELOCLUS);
1.469 + test.Printf(_L("res=%d\n"),res);
1.470 + test(res==KErrNone);
1.471 +
1.472 +
1.473 + WaitForSystemChange(notifier, stat, EChangesLocale);
1.474 + test(stat.Int() & EChangesLocale);
1.475 +
1.476 +
1.477 + //-------------------
1.478 + SubscribeToSystemChangeNotification(notifier, stat, EChangesLocale);
1.479 +
1.480 +
1.481 + _LIT8(KTestData, "Arsenal");
1.482 + res = file.Write(KTestData);
1.483 + test(res==KErrNone);
1.484 + file.Close();
1.485 +
1.486 + res = file.Open(TheFs, KTestFile, 0);
1.487 + test(res == KErrNone);
1.488 + file.Close();
1.489 + res = TheFs.Delete(KTestFile);
1.490 + test(res==KErrNone);
1.491 +
1.492 + //************************************************
1.493 +
1.494 + //-- close the notifier
1.495 + notifier.Close();
1.496 + User::WaitForRequest(stat);
1.497 +
1.498 + //-- n.b. it's actually a bad idea to expect _exact_ event completion from the RChangeNotifier, because
1.499 + //-- this is a system-wide events observer and any of the TChanges events can happen, not only EChangesLocale.
1.500 + //-- so this test is a bit flawed.
1.501 +
1.502 + //test(stat==KErrGeneral);
1.503 + }
1.504 +
1.505 +const TText * const DateSuffixTable[KMaxSuffixes] =
1.506 + {
1.507 + _S("st"),_S("nd"),_S("rd"),_S("th"),_S("th"),
1.508 + _S("th"),_S("th"),_S("th"),_S("th"),_S("th"),
1.509 + _S("th"),_S("th"),_S("th"),_S("th"),_S("th"),
1.510 + _S("th"),_S("th"),_S("th"),_S("th"),_S("th"),
1.511 + _S("st"),_S("nd"),_S("rd"),_S("th"),_S("th"),
1.512 + _S("th"),_S("th"),_S("th"),_S("th"),_S("th"),
1.513 + _S("st")
1.514 + };
1.515 +
1.516 +const TText * const DayTable[KMaxDays] =
1.517 + {
1.518 + _S("Monday"),
1.519 + _S("Tuesday"),
1.520 + _S("Wednesday"),
1.521 + _S("Thursday"),
1.522 + _S("Friday"),
1.523 + _S("Saturday"),
1.524 + _S("Sunday")
1.525 + };
1.526 +
1.527 +const TText * const DayAbbTable[KMaxDays] =
1.528 + {
1.529 + _S("Mon"),
1.530 + _S("Tue"),
1.531 + _S("Wed"),
1.532 + _S("Thu"),
1.533 + _S("Fri"),
1.534 + _S("Sat"),
1.535 + _S("Sun")
1.536 + };
1.537 +
1.538 +const TText * const MonthTable[KMaxMonths] =
1.539 + {
1.540 + _S("January"),
1.541 + _S("February"),
1.542 + _S("March"),
1.543 + _S("April"),
1.544 + _S("May"),
1.545 + _S("June"),
1.546 + _S("July"),
1.547 + _S("August"),
1.548 + _S("September"),
1.549 + _S("October"),
1.550 + _S("November"),
1.551 + _S("December")
1.552 + };
1.553 +
1.554 +const TText * const MonthAbbTable[KMaxMonths] =
1.555 + {
1.556 + _S("Jan"),
1.557 + _S("Feb"),
1.558 + _S("Mar"),
1.559 + _S("Apr"),
1.560 + _S("May"),
1.561 + _S("Jun"),
1.562 + _S("Jul"),
1.563 + _S("Aug"),
1.564 + _S("Sep"),
1.565 + _S("Oct"),
1.566 + _S("Nov"),
1.567 + _S("Dec")
1.568 + };
1.569 +
1.570 +const TText * const AmPmTable[KMaxAmPms] = {_S("am"),_S("pm")};
1.571 +
1.572 +void testExtendedUS(TUint aAspect, TExtendedLocale& aLocale)
1.573 + {
1.574 + TLocale* loc = aLocale.GetLocale();
1.575 + testUS(*loc);
1.576 +
1.577 + if(aAspect & ELocaleLanguageSettings)
1.578 + {
1.579 + TLanguage tl = User::Language();
1.580 + test(tl == ELangAmerican);
1.581 +
1.582 + TDateSuffix datesuffix;
1.583 + TInt i;
1.584 + for(i=0;i<KMaxSuffixes;++i)
1.585 + {
1.586 + datesuffix.Set(i);
1.587 + test(datesuffix.Compare(TPtrC(DateSuffixTable[i])) == 0);
1.588 + }
1.589 +
1.590 + TDayName dayname;
1.591 + for(i=0;i<KMaxDays;++i)
1.592 + {
1.593 + dayname.Set((TDay)i);
1.594 + test(dayname.Compare(TPtrC(DayTable[i])) == 0);
1.595 + }
1.596 +
1.597 + TDayNameAbb daynameabb;
1.598 + for(i=0;i<KMaxDays;++i)
1.599 + {
1.600 + daynameabb.Set((TDay)i);
1.601 + test(daynameabb.Compare(TPtrC(DayAbbTable[i])) == 0);
1.602 + }
1.603 +
1.604 + TMonthName monthname;
1.605 + for(i=0;i<KMaxMonths;++i)
1.606 + {
1.607 + monthname.Set((TMonth)i);
1.608 + test(monthname.Compare(TPtrC(MonthTable[i])) == 0);
1.609 + }
1.610 +
1.611 + TMonthNameAbb monthnameabb;
1.612 + for(i=0;i<KMaxMonths;++i)
1.613 + {
1.614 + monthnameabb.Set((TMonth)i);
1.615 + test(monthnameabb.Compare(TPtrC(MonthAbbTable[i])) == 0);
1.616 + }
1.617 +
1.618 + TAmPmName ampmname;
1.619 + for(i=0;i<KMaxAmPms;++i)
1.620 + {
1.621 + ampmname.Set((TAmPm)i);
1.622 + test(ampmname.Compare(TPtrC(AmPmTable[i])) == 0);
1.623 + }
1.624 + }
1.625 +
1.626 + if(aAspect & ELocaleLocaleSettings)
1.627 + {
1.628 + TCurrencySymbol symbol;
1.629 + symbol.Set();
1.630 + test(symbol.Compare(TPtrC(_S("$"))) == 0);
1.631 + }
1.632 +
1.633 + if(aAspect & ELocaleTimeDateSettings)
1.634 + {
1.635 + TShortDateFormatSpec shortdate;
1.636 + shortdate.Set();
1.637 + test(shortdate.Compare(TPtrC(_S("%F%*M/%*D/%Y"))) == 0);
1.638 +
1.639 + TLongDateFormatSpec longdate;
1.640 + longdate.Set();
1.641 + test(longdate.Compare(TPtrC(_S("%F%*D%X %N %Y"))) == 0);
1.642 +
1.643 + TTimeFormatSpec spec;
1.644 + spec.Set();
1.645 + test(spec.Compare(TPtrC(_S("%F%*I:%T:%S %*A"))) == 0);
1.646 + }
1.647 +
1.648 + }
1.649 +
1.650 +
1.651 +void testExtendedLocale()
1.652 + {
1.653 + TExtendedLocale locale;
1.654 + locale.LoadLocale(ELOCLUS);
1.655 + TInt r = locale.SaveSystemSettings();
1.656 + test(r == KErrNone);
1.657 + testExtendedUS(ELocaleLanguageSettings | ELocaleCollateSetting | ELocaleLocaleSettings | ELocaleTimeDateSettings, locale);
1.658 +
1.659 + r = locale.SetCurrencySymbol(TPtrC(_S("Leu")));
1.660 + test(r == KErrNone);
1.661 + TCurrencySymbol symbol;
1.662 + symbol.Set();
1.663 + test(symbol.Compare(TPtrC(_S("Leu"))) == 0);
1.664 +
1.665 + User::SetCurrencySymbol(TPtrC(_S("Le")));
1.666 + symbol.Set();
1.667 + test(symbol.Compare(TPtrC(_S("Le"))) == 0);
1.668 +
1.669 + TFileName dllName;
1.670 + TFileName eloclus;
1.671 + eloclus.Copy(ELOCLUS);
1.672 + eloclus.Append(TPtrC(KDLLExtension));
1.673 + r = locale.GetLocaleDllName(ELocaleLanguageSettings, dllName);
1.674 + test(r == KErrNone);
1.675 + test.Printf(_L("dllName looking for %s (%s)\n"), dllName.Ptr(), eloclus.Ptr());
1.676 + test(dllName.Find(eloclus) != KErrNotFound);
1.677 +
1.678 + dllName.FillZ();
1.679 +
1.680 + r = locale.GetLocaleDllName(ELocaleCollateSetting, dllName);
1.681 + test(r == KErrNone);
1.682 + test(dllName.Find(eloclus) != KErrNotFound);
1.683 +
1.684 + dllName.FillZ();
1.685 +
1.686 + r = locale.GetLocaleDllName(ELocaleLocaleSettings, dllName);
1.687 + test(r == KErrNone);
1.688 + test(dllName.Find(eloclus) != KErrNotFound);
1.689 +
1.690 + dllName.FillZ();
1.691 +
1.692 + r = locale.GetLocaleDllName(ELocaleTimeDateSettings, dllName);
1.693 + test(r == KErrNone);
1.694 + test(dllName.Find(eloclus) != KErrNotFound);
1.695 +
1.696 + dllName.FillZ();
1.697 +
1.698 + r = locale.LoadLocaleAspect(ELocaleLocaleSettings | ELocaleTimeDateSettings, ELOCLGE);
1.699 + test(r == KErrNone);
1.700 +
1.701 + r = locale.SaveSystemSettings();
1.702 + test(r == KErrNone);
1.703 +
1.704 + testExtendedUS(ELocaleLanguageSettings | ELocaleCollateSetting, locale);
1.705 +
1.706 + symbol.Set();
1.707 + test(symbol.Compare(TPtrC(_S("DM"))) == 0);
1.708 +
1.709 + TShortDateFormatSpec shortdate;
1.710 + shortdate.Set();
1.711 + test(shortdate.Compare(TPtrC(_S("%F%*D.%*M.%Y"))) == 0);
1.712 +
1.713 + TLongDateFormatSpec longdate;
1.714 + longdate.Set();
1.715 + test(longdate.Compare(TPtrC(_S("%F%*D%X %N %Y"))) == 0);
1.716 +
1.717 + TTimeFormatSpec spec;
1.718 + spec.Set();
1.719 + test(spec.Compare(TPtrC(_S("%F%H:%T:%S"))) == 0);
1.720 +
1.721 + TFileName eloclge;
1.722 + eloclge.Copy(ELOCLGE);
1.723 + eloclge.Append(KDLLExtension);
1.724 + r = locale.GetLocaleDllName(ELocaleLanguageSettings, dllName);
1.725 + test(r == KErrNone);
1.726 + test(dllName.Find(eloclus) != KErrNotFound);
1.727 +
1.728 + dllName.FillZ();
1.729 +
1.730 + r = locale.GetLocaleDllName(ELocaleCollateSetting, dllName);
1.731 + test(r == KErrNone);
1.732 + test(dllName.Find(eloclus) != KErrNotFound);
1.733 +
1.734 + dllName.FillZ();
1.735 +
1.736 + r = locale.GetLocaleDllName(ELocaleLocaleSettings, dllName);
1.737 + test(r == KErrNone);
1.738 + test(dllName.Find(eloclge) != KErrNotFound);
1.739 +
1.740 + dllName.FillZ();
1.741 +
1.742 + r = locale.GetLocaleDllName(ELocaleTimeDateSettings, dllName);
1.743 + test(r == KErrNone);
1.744 + test(dllName.Find(eloclge) != KErrNotFound);
1.745 +
1.746 + dllName.FillZ();
1.747 +
1.748 + }
1.749 +
1.750 +void testDigitsInMonthsNames()
1.751 + {
1.752 + test.Next(_L("Testing date parsing when month names include digits"));
1.753 +
1.754 + TTime time;
1.755 + _LIT(KMonthJan, "30 Th1 2006 14:31:50");
1.756 + test_Equal(KErrArgument, time.Parse(KMonthJan));
1.757 + test_KErrNone(UserSvr::ChangeLocale(ELOCLUS2));
1.758 + test_Equal(EParseDatePresent | EParseTimePresent, time.Parse(KMonthJan));
1.759 + test_KErrNone(UserSvr::ChangeLocale(ELOCL_DEFAULT));
1.760 + }
1.761 +
1.762 +GLDEF_C void CallTestsL(void)
1.763 + {
1.764 +
1.765 + test.Title();
1.766 + test.Start(_L("Starting T_DLOCL tests"));
1.767 +
1.768 + testChangeLocale();
1.769 + testChangeKeyData();
1.770 + testExtendedLocale();
1.771 + testDigitsInMonthsNames();
1.772 + test.Next(_L("Close connection to the file server\n"));
1.773 +
1.774 + test.End();
1.775 + }
1.776 +