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