First public contribution.
1 // Copyright (c) 2005-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
20 _LIT(KGerLocale, "T_LOCLGE.DLL");
21 _LIT(KEngLocale, "T_LOCLUS.DLL");
24 _LIT(KEngLocaleRAM, "T_LOCLUS_RAM.DLL"); //this should be RAM-loaded library..
26 _LIT(KEngLocaleRAM, "T_LOCLUS.DLL");
30 class RTestSafeLocale : public RTest
33 RTestSafeLocale(const TDesC &aTitle): RTest(aTitle), iFailHdnFunc(NULL) {}
34 RTestSafeLocale(const TDesC &aTitle, void(*func)(RTest &aTest)) : RTest(aTitle), iFailHdnFunc(func) {}
36 //new wersion of operator, which calls handler if check failed
37 void operator()(TInt aResult)
39 if (!aResult && iFailHdnFunc) iFailHdnFunc(*this);
40 RTest::operator ()(aResult);
43 //new version of End, which calls handler before exit..
46 if (iFailHdnFunc) iFailHdnFunc(*this);
50 //pointer to handler..
51 void (*iFailHdnFunc)(RTest &aTest);
54 // cleanup handler, which restores default locale on test end or failure..
55 void TestCleanup(RTest &aTest)
57 aTest.Printf(_L("\nTest cleanup: changing locale to default..\n"));
58 UserSvr::ChangeLocale(_L(""));
59 aTest.Printf(_L("Default language: %d\n"), User::Language());
62 // global gTest object..
63 RTestSafeLocale gTest(_L("T_LOCCHANGE"), &TestCleanup);
65 // try to load locale dll prior to changing it..
66 TInt LoadLocaleCrash(const TDesC& aName)
68 //First - load the library..
70 TInt err = lib.Load(aName);
73 gTest.Printf(_L("\nRLibrary::Load() failed, err %d"), err);
76 // try to change locale.. (it should ignore the previously loaded library..
77 // and load locale library again in the global area.
78 err = UserSvr::ChangeLocale(aName);
81 gTest.Printf(_L("\nUserSvr::ChangeLocale() failed, err %d"), err);
89 // change locale normally..
90 TInt LoadLocale(const TDesC& aName)
92 TInt r = UserSvr::ChangeLocale(aName);
101 gTest.Start(_L("Test Locale Change\n"));
104 RChangeNotifier notifier;
105 TRequestStatus status;
106 gTest(notifier.Create() == KErrNone);
107 gTest(notifier.Logon(status) == KErrNone);
108 User::WaitForRequest(status);
110 // Monitor locale change event
111 gTest(notifier.Logon(status) == KErrNone);
113 r = LoadLocale(KGerLocale);
114 gTest(r == KErrNone);
115 User::WaitForRequest(status);
116 gTest(status.Int() & EChangesLocale);
117 gTest.Printf(_L("New Language: %d\n"), User::Language());
118 gTest(notifier.Logon(status) == KErrNone);
120 r = LoadLocale(KEngLocale);
121 gTest(r == KErrNone);
122 User::WaitForRequest(status);
123 gTest(status.Int() & EChangesLocale);
124 gTest.Printf(_L("New Language: %d\n"), User::Language());
125 gTest(notifier.Logon(status) == KErrNone);
127 r = LoadLocaleCrash(KEngLocaleRAM);
128 gTest(r == KErrNone);
129 User::WaitForRequest(status);
130 gTest(status.Int() & EChangesLocale);
131 gTest.Printf(_L("New Language: %d\n"), User::Language());