sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32test\server\t_dlocl.cpp sl@0: // Tests UserSvr::ChangeLocale() function sl@0: // sl@0: // sl@0: sl@0: #define __E32TEST_EXTENSION__ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "t_server.h" sl@0: sl@0: LOCAL_D TFindLibrary fLib; sl@0: sl@0: typedef TInt (*TLibEntry)(TInt); sl@0: typedef TInt (*TLibEntry2)(); sl@0: sl@0: const TBool KEY_DOWN=EFalse; sl@0: const TBool EXPECT_KEY_PRESS=ETrue; sl@0: sl@0: RTest test(_L("T_DLOCL")); sl@0: sl@0: _LIT(ELOCL_DEFAULT, ""); sl@0: _LIT(ELOCLGE, "T_LOCLGE"); sl@0: _LIT(ELOCLUS, "T_LOCLUS"); sl@0: _LIT(ELOCLUS1, "T_LOCLUS1"); sl@0: _LIT(ELOCLUS2, "T_LOCLUS2"); sl@0: _LIT(EKDATA, "EKDATA"); sl@0: _LIT(DUMMYDLL, "EDISP"); sl@0: _LIT(KColonColon, "::"); sl@0: _LIT(KDLLExtension, ".DLL"); sl@0: sl@0: GLDEF_D CKeyTranslator *KeyTranslator=CKeyTranslator::New(); sl@0: LOCAL_D CCaptureKeys *CaptureKeys; sl@0: sl@0: void testConv(const TDesC& aDes,TBool aKeyup,TBool aRet,TUint aScanCode,TUint aKeyCode,TInt aModifiers) sl@0: { sl@0: sl@0: TKeyData keyData; sl@0: TBool ret=KeyTranslator->TranslateKey(aScanCode, aKeyup,*CaptureKeys,keyData); sl@0: test.Next(aDes); sl@0: test(ret==aRet); sl@0: test((keyData.iKeyCode==aKeyCode)); sl@0: test((keyData.iModifiers==aModifiers)); sl@0: } sl@0: sl@0: void testChangeKeyData() sl@0: { sl@0: TName pn(RProcess().Name()); sl@0: pn+=KColonColon; sl@0: TFullName n; sl@0: CaptureKeys=new CCaptureKeys(); sl@0: CaptureKeys->Construct(); sl@0: test.Printf(_L("Test default key data\n")); sl@0: testConv(_L("\nFirst Special key down"),KEY_DOWN,EXPECT_KEY_PRESS,ESpecialKeyBase,ESpecialKeyBase,0); sl@0: sl@0: RLibrary testLib; sl@0: TInt res=testLib.Load(EKDATA); sl@0: test(res==KErrNone); sl@0: THandleInfo handleInfo; sl@0: testLib.HandleInfo(&handleInfo); sl@0: test(handleInfo.iNumOpenInThread==2); sl@0: testLib.Close(); sl@0: sl@0: test.Printf(_L("Change to unknown dll \n")); // Test with non keydata type dll sl@0: res=KeyTranslator->ChangeKeyData(DUMMYDLL); sl@0: test(res==KErrArgument); sl@0: sl@0: res=testLib.Load(EKDATA); sl@0: test(res==KErrNone); sl@0: testLib.HandleInfo(&handleInfo); sl@0: test(handleInfo.iNumOpenInThread==2); sl@0: testLib.Close(); sl@0: sl@0: res=testLib.Load(DUMMYDLL); sl@0: test(res==KErrNone); sl@0: testLib.HandleInfo(&handleInfo); sl@0: test(handleInfo.iNumOpenInThread==1); sl@0: testLib.Close(); sl@0: sl@0: fLib.Find(_L("*")); sl@0: while (fLib.Next(n)==KErrNone) sl@0: { sl@0: TName findname=pn; sl@0: findname+=DUMMYDLL; sl@0: test.Printf(_L(" %S\n"),&n); sl@0: test(n.FindF(findname) == KErrNotFound); sl@0: } sl@0: // sl@0: test.Printf(_L("Change to EKDATA.dll\n")); sl@0: res=KeyTranslator->ChangeKeyData(EKDATA); sl@0: test(res==KErrNone); sl@0: sl@0: res=testLib.Load(EKDATA); sl@0: test(res==KErrNone); sl@0: testLib.HandleInfo(&handleInfo); sl@0: test(handleInfo.iNumOpenInThread==2); sl@0: testLib.Close(); sl@0: res=testLib.Load(DUMMYDLL); sl@0: test(res==KErrNone); sl@0: testLib.HandleInfo(&handleInfo); sl@0: test(handleInfo.iNumOpenInThread==1); sl@0: testLib.Close(); sl@0: sl@0: fLib.Find(_L("*")); sl@0: while (fLib.Next(n)==KErrNone) sl@0: { sl@0: TName findname=pn; sl@0: findname+=EKDATA; sl@0: test.Printf(_L(" %S\n"),&n); sl@0: if(n.FindF(findname) != KErrNotFound) sl@0: break; sl@0: } sl@0: //The test below fails if we use Secure APIs sl@0: //test(n.FindF(EKDATA) == KErrNotSupported); sl@0: testConv(_L("\nFirst Special key down"),KEY_DOWN,EXPECT_KEY_PRESS,ESpecialKeyBase,ESpecialKeyBase,0); sl@0: sl@0: test.Printf(_L("Change back to Default KeyData\n")); sl@0: res=KeyTranslator->ChangeKeyData(_L("")); sl@0: test(res==KErrNone); sl@0: sl@0: res=testLib.Load(EKDATA); sl@0: test(res==KErrNone); sl@0: testLib.HandleInfo(&handleInfo); sl@0: test(handleInfo.iNumOpenInThread==2); sl@0: testLib.Close(); sl@0: sl@0: res=testLib.Load(DUMMYDLL); sl@0: test(res==KErrNone); sl@0: testLib.HandleInfo(&handleInfo); sl@0: test(handleInfo.iNumOpenInThread==1); sl@0: testLib.Close(); sl@0: sl@0: fLib.Find(_L("*")); sl@0: while (fLib.Next(n)==KErrNone) sl@0: { sl@0: TName findname=pn; sl@0: findname+=DUMMYDLL; sl@0: test.Printf(_L(" %S\n"),&n); sl@0: test(n.FindF(findname) == KErrNotFound); sl@0: } sl@0: testConv(_L("\nFirst Special key down"),KEY_DOWN,EXPECT_KEY_PRESS,ESpecialKeyBase,ESpecialKeyBase,0); sl@0: delete CaptureKeys; sl@0: } sl@0: sl@0: void testUS(const TLocale& aLocale) sl@0: { sl@0: //#ifdef __WINS__ sl@0: test(aLocale.CountryCode()==1); sl@0: test(aLocale.DateFormat()==EDateAmerican); sl@0: test(aLocale.TimeFormat()==ETime12); sl@0: test(aLocale.CurrencySymbolPosition()==ELocaleBefore); sl@0: test(aLocale.CurrencySpaceBetween()==FALSE); sl@0: test(aLocale.CurrencyDecimalPlaces()==2); sl@0: test(aLocale.CurrencyNegativeInBrackets()==EFalse); sl@0: test(aLocale.CurrencyTriadsAllowed()==TRUE); sl@0: test(aLocale.ThousandsSeparator()==','); sl@0: test(aLocale.DecimalSeparator()=='.'); sl@0: test(aLocale.DateSeparator(0)==0); sl@0: test(aLocale.DateSeparator(1)=='/'); sl@0: test(aLocale.DateSeparator(2)=='/'); sl@0: test(aLocale.DateSeparator(3)==0); sl@0: test(aLocale.TimeSeparator(0)==0); sl@0: test(aLocale.TimeSeparator(1)==':'); sl@0: test(aLocale.TimeSeparator(2)==':'); sl@0: test(aLocale.TimeSeparator(3)==0); sl@0: test(aLocale.AmPmSymbolPosition()==TRUE); sl@0: test(aLocale.AmPmSpaceBetween()==TRUE); sl@0: test(aLocale.HomeDaylightSavingZone()==EDstNorthern); sl@0: test(aLocale.WorkDays()==0x1f); sl@0: test(aLocale.StartOfWeek()==ESunday); sl@0: test(aLocale.ClockFormat()==EClockAnalog); sl@0: test(aLocale.UnitsGeneral()==EUnitsImperial); sl@0: test(aLocale.UnitsDistanceShort()==EUnitsImperial); sl@0: test(aLocale.UnitsDistanceLong()==EUnitsImperial); sl@0: //#endif sl@0: } sl@0: sl@0: sl@0: void testUK(const TLocale& aLocale) sl@0: { sl@0: //#ifdef __WINS__ sl@0: test(aLocale.CountryCode()==44); sl@0: test(aLocale.DateFormat()==EDateEuropean); sl@0: test(aLocale.TimeFormat()==ETime12); sl@0: test(aLocale.CurrencySymbolPosition()==ELocaleBefore); sl@0: test(aLocale.CurrencySpaceBetween()==FALSE); sl@0: test(aLocale.CurrencyDecimalPlaces()==2); sl@0: test(aLocale.CurrencyNegativeInBrackets()==EFalse); sl@0: test(aLocale.CurrencyTriadsAllowed()==TRUE); sl@0: test(aLocale.ThousandsSeparator()==','); sl@0: test(aLocale.DecimalSeparator()=='.'); sl@0: test(aLocale.DateSeparator(0)==0); sl@0: test(aLocale.DateSeparator(1)=='/'); sl@0: test(aLocale.DateSeparator(2)=='/'); sl@0: test(aLocale.DateSeparator(3)==0); sl@0: test(aLocale.TimeSeparator(0)==0); sl@0: test(aLocale.TimeSeparator(1)==':'); sl@0: test(aLocale.TimeSeparator(2)==':'); sl@0: test(aLocale.TimeSeparator(3)==0); sl@0: test(aLocale.AmPmSymbolPosition()==TRUE); sl@0: test(aLocale.AmPmSpaceBetween()==TRUE); sl@0: test(aLocale.HomeDaylightSavingZone()==EDstEuropean); sl@0: test(aLocale.WorkDays()==0x1f); sl@0: test(aLocale.StartOfWeek()==EMonday); sl@0: test(aLocale.ClockFormat()==EClockAnalog); sl@0: test(aLocale.UnitsGeneral()==EUnitsImperial); sl@0: test(aLocale.UnitsDistanceShort()==EUnitsImperial); sl@0: test(aLocale.UnitsDistanceLong()==EUnitsImperial); sl@0: //#endif sl@0: } sl@0: sl@0: void testGE(const TLocale& aLocale) sl@0: { sl@0: //#ifdef __WINS__ sl@0: test(aLocale.CountryCode()==49); sl@0: test(aLocale.DateFormat()==EDateEuropean); sl@0: test(aLocale.TimeFormat()==ETime24); sl@0: test(aLocale.CurrencySymbolPosition()==ELocaleAfter); sl@0: test(aLocale.CurrencySpaceBetween()==TRUE); sl@0: test(aLocale.CurrencyDecimalPlaces()==2); sl@0: test(aLocale.CurrencyNegativeInBrackets()==TRUE); sl@0: test(aLocale.CurrencyTriadsAllowed()==TRUE); sl@0: test(aLocale.ThousandsSeparator()=='.'); sl@0: test(aLocale.DecimalSeparator()==','); sl@0: test(aLocale.DateSeparator(0)==0); sl@0: test(aLocale.DateSeparator(1)=='.'); sl@0: test(aLocale.DateSeparator(2)=='.'); sl@0: test(aLocale.DateSeparator(3)==0); sl@0: sl@0: test(aLocale.TimeSeparator(0)==0); sl@0: test(aLocale.TimeSeparator(1)==':'); sl@0: test(aLocale.TimeSeparator(2)==':'); sl@0: test(aLocale.TimeSeparator(3)==0); sl@0: test(aLocale.AmPmSymbolPosition()==TRUE); sl@0: test(aLocale.AmPmSpaceBetween()==TRUE); sl@0: test(aLocale.HomeDaylightSavingZone()==EDstEuropean); sl@0: test(aLocale.WorkDays()==0x1f); sl@0: test(aLocale.StartOfWeek()==EMonday); sl@0: test(aLocale.ClockFormat()==EClockDigital); sl@0: test(aLocale.UnitsGeneral()==EUnitsMetric); sl@0: test(aLocale.UnitsDistanceShort()==EUnitsMetric); sl@0: test(aLocale.UnitsDistanceLong()==EUnitsMetric); sl@0: //#endif sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: Subscribe to a system event. sl@0: sl@0: @param aNotifier notifier sl@0: @param aStatus request status that is used with the notifier sl@0: @param aEventMask Specifies the event. See TChanges sl@0: */ sl@0: static void SubscribeToSystemChangeNotification(RChangeNotifier& aNotifier, TRequestStatus& aStatus, TUint32 aEventMask) sl@0: { sl@0: sl@0: const TInt KMaxAttempts = 100; sl@0: TInt i; sl@0: for(i=0; iB and a>b sl@0: //Collation tables cannot be changed at runtime sl@0: /* TBuf16<1> a_cap(_L("A")); sl@0: TBuf16<1> a_small(_L("a")); sl@0: sl@0: //Test using the locale independent matching and comparing sl@0: test(a_cap.Match(_L("B"))!=0); sl@0: test(a_cap.Compare(_L("B"))<0); sl@0: test(a_small.Match(_L("b"))!=0); sl@0: test(a_small.Compare(_L("b"))<0); sl@0: //Test that the default collation table(1st table) is selected here sl@0: test(a_cap.CompareC(_L("B"))!=0); sl@0: test(a_small.CompareC(_L("b"))!=0); sl@0: test(a_cap.CompareC(_L("B"))>0); sl@0: test(a_small.CompareC(_L("b"))>0); sl@0: //Test that the Matching collation table(3rd table) is selected here sl@0: test(a_cap.MatchC(_L("B"))==0); sl@0: test(a_small.MatchC(_L("b"))==0); sl@0: */ sl@0: test.Printf(_L("Back to default UK Locale\n")); sl@0: res=UserSvr::ChangeLocale(ELOCL_DEFAULT); sl@0: test.Printf(_L("res=%d\n"),res); sl@0: test(res==KErrNone); sl@0: sl@0: WaitForSystemChange(notifier, stat, EChangesLocale); sl@0: test(stat.Int() & EChangesLocale); sl@0: sl@0: //------------------- sl@0: sl@0: SubscribeToSystemChangeNotification(notifier, stat, EChangesLocale); sl@0: sl@0: locale.Refresh(); sl@0: testUK(locale); sl@0: sl@0: //Test for locale which does not have a matching collation table sl@0: TCollationMethod m1=*Mem::GetDefaultMatchingTable(); sl@0: test((m1.iFlags & TCollationMethod::EMatchingTable)==0); sl@0: sl@0: //************************************************ sl@0: test.Printf(_L("Change to US Locale with file open on drive\n")); sl@0: sl@0: _LIT(KTestFile, "TEST.TXT"); sl@0: RFile file; sl@0: res = file.Replace(TheFs, KTestFile, 0); sl@0: test(res == KErrNone); sl@0: sl@0: sl@0: res=UserSvr::ChangeLocale(ELOCLUS); sl@0: test.Printf(_L("res=%d\n"),res); sl@0: test(res==KErrNone); sl@0: sl@0: sl@0: WaitForSystemChange(notifier, stat, EChangesLocale); sl@0: test(stat.Int() & EChangesLocale); sl@0: sl@0: sl@0: //------------------- sl@0: SubscribeToSystemChangeNotification(notifier, stat, EChangesLocale); sl@0: sl@0: sl@0: _LIT8(KTestData, "Arsenal"); sl@0: res = file.Write(KTestData); sl@0: test(res==KErrNone); sl@0: file.Close(); sl@0: sl@0: res = file.Open(TheFs, KTestFile, 0); sl@0: test(res == KErrNone); sl@0: file.Close(); sl@0: res = TheFs.Delete(KTestFile); sl@0: test(res==KErrNone); sl@0: sl@0: //************************************************ sl@0: sl@0: //-- close the notifier sl@0: notifier.Close(); sl@0: User::WaitForRequest(stat); sl@0: sl@0: //-- n.b. it's actually a bad idea to expect _exact_ event completion from the RChangeNotifier, because sl@0: //-- this is a system-wide events observer and any of the TChanges events can happen, not only EChangesLocale. sl@0: //-- so this test is a bit flawed. sl@0: sl@0: //test(stat==KErrGeneral); sl@0: } sl@0: sl@0: const TText * const DateSuffixTable[KMaxSuffixes] = sl@0: { sl@0: _S("st"),_S("nd"),_S("rd"),_S("th"),_S("th"), sl@0: _S("th"),_S("th"),_S("th"),_S("th"),_S("th"), sl@0: _S("th"),_S("th"),_S("th"),_S("th"),_S("th"), sl@0: _S("th"),_S("th"),_S("th"),_S("th"),_S("th"), sl@0: _S("st"),_S("nd"),_S("rd"),_S("th"),_S("th"), sl@0: _S("th"),_S("th"),_S("th"),_S("th"),_S("th"), sl@0: _S("st") sl@0: }; sl@0: sl@0: const TText * const DayTable[KMaxDays] = sl@0: { sl@0: _S("Monday"), sl@0: _S("Tuesday"), sl@0: _S("Wednesday"), sl@0: _S("Thursday"), sl@0: _S("Friday"), sl@0: _S("Saturday"), sl@0: _S("Sunday") sl@0: }; sl@0: sl@0: const TText * const DayAbbTable[KMaxDays] = sl@0: { sl@0: _S("Mon"), sl@0: _S("Tue"), sl@0: _S("Wed"), sl@0: _S("Thu"), sl@0: _S("Fri"), sl@0: _S("Sat"), sl@0: _S("Sun") sl@0: }; sl@0: sl@0: const TText * const MonthTable[KMaxMonths] = sl@0: { sl@0: _S("January"), sl@0: _S("February"), sl@0: _S("March"), sl@0: _S("April"), sl@0: _S("May"), sl@0: _S("June"), sl@0: _S("July"), sl@0: _S("August"), sl@0: _S("September"), sl@0: _S("October"), sl@0: _S("November"), sl@0: _S("December") sl@0: }; sl@0: sl@0: const TText * const MonthAbbTable[KMaxMonths] = sl@0: { sl@0: _S("Jan"), sl@0: _S("Feb"), sl@0: _S("Mar"), sl@0: _S("Apr"), sl@0: _S("May"), sl@0: _S("Jun"), sl@0: _S("Jul"), sl@0: _S("Aug"), sl@0: _S("Sep"), sl@0: _S("Oct"), sl@0: _S("Nov"), sl@0: _S("Dec") sl@0: }; sl@0: sl@0: const TText * const AmPmTable[KMaxAmPms] = {_S("am"),_S("pm")}; sl@0: sl@0: void testExtendedUS(TUint aAspect, TExtendedLocale& aLocale) sl@0: { sl@0: TLocale* loc = aLocale.GetLocale(); sl@0: testUS(*loc); sl@0: sl@0: if(aAspect & ELocaleLanguageSettings) sl@0: { sl@0: TLanguage tl = User::Language(); sl@0: test(tl == ELangAmerican); sl@0: sl@0: TDateSuffix datesuffix; sl@0: TInt i; sl@0: for(i=0;i