sl@0
|
1 |
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <e32test.h>
|
sl@0
|
17 |
#include <f32file.h>
|
sl@0
|
18 |
#include <e32svr.h>
|
sl@0
|
19 |
|
sl@0
|
20 |
_LIT(KGerLocale, "T_LOCLGE.DLL");
|
sl@0
|
21 |
_LIT(KEngLocale, "T_LOCLUS.DLL");
|
sl@0
|
22 |
|
sl@0
|
23 |
#ifndef __WINS__
|
sl@0
|
24 |
_LIT(KEngLocaleRAM, "T_LOCLUS_RAM.DLL"); //this should be RAM-loaded library..
|
sl@0
|
25 |
#else
|
sl@0
|
26 |
_LIT(KEngLocaleRAM, "T_LOCLUS.DLL");
|
sl@0
|
27 |
#endif
|
sl@0
|
28 |
|
sl@0
|
29 |
//
|
sl@0
|
30 |
class RTestSafeLocale : public RTest
|
sl@0
|
31 |
{
|
sl@0
|
32 |
public:
|
sl@0
|
33 |
RTestSafeLocale(const TDesC &aTitle): RTest(aTitle), iFailHdnFunc(NULL) {}
|
sl@0
|
34 |
RTestSafeLocale(const TDesC &aTitle, void(*func)(RTest &aTest)) : RTest(aTitle), iFailHdnFunc(func) {}
|
sl@0
|
35 |
|
sl@0
|
36 |
//new wersion of operator, which calls handler if check failed
|
sl@0
|
37 |
void operator()(TInt aResult)
|
sl@0
|
38 |
{
|
sl@0
|
39 |
if (!aResult && iFailHdnFunc) iFailHdnFunc(*this);
|
sl@0
|
40 |
RTest::operator ()(aResult);
|
sl@0
|
41 |
}
|
sl@0
|
42 |
|
sl@0
|
43 |
//new version of End, which calls handler before exit..
|
sl@0
|
44 |
IMPORT_C void End()
|
sl@0
|
45 |
{
|
sl@0
|
46 |
if (iFailHdnFunc) iFailHdnFunc(*this);
|
sl@0
|
47 |
RTest::End();
|
sl@0
|
48 |
}
|
sl@0
|
49 |
|
sl@0
|
50 |
//pointer to handler..
|
sl@0
|
51 |
void (*iFailHdnFunc)(RTest &aTest);
|
sl@0
|
52 |
};
|
sl@0
|
53 |
|
sl@0
|
54 |
// cleanup handler, which restores default locale on test end or failure..
|
sl@0
|
55 |
void TestCleanup(RTest &aTest)
|
sl@0
|
56 |
{
|
sl@0
|
57 |
aTest.Printf(_L("\nTest cleanup: changing locale to default..\n"));
|
sl@0
|
58 |
UserSvr::ChangeLocale(_L(""));
|
sl@0
|
59 |
aTest.Printf(_L("Default language: %d\n"), User::Language());
|
sl@0
|
60 |
}
|
sl@0
|
61 |
|
sl@0
|
62 |
// global gTest object..
|
sl@0
|
63 |
RTestSafeLocale gTest(_L("T_LOCCHANGE"), &TestCleanup);
|
sl@0
|
64 |
|
sl@0
|
65 |
// try to load locale dll prior to changing it..
|
sl@0
|
66 |
TInt LoadLocaleCrash(const TDesC& aName)
|
sl@0
|
67 |
{
|
sl@0
|
68 |
//First - load the library..
|
sl@0
|
69 |
RLibrary lib;
|
sl@0
|
70 |
TInt err = lib.Load(aName);
|
sl@0
|
71 |
if (err)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
gTest.Printf(_L("\nRLibrary::Load() failed, err %d"), err);
|
sl@0
|
74 |
return err;
|
sl@0
|
75 |
}
|
sl@0
|
76 |
// try to change locale.. (it should ignore the previously loaded library..
|
sl@0
|
77 |
// and load locale library again in the global area.
|
sl@0
|
78 |
err = UserSvr::ChangeLocale(aName);
|
sl@0
|
79 |
if (err)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
gTest.Printf(_L("\nUserSvr::ChangeLocale() failed, err %d"), err);
|
sl@0
|
82 |
return err;
|
sl@0
|
83 |
}
|
sl@0
|
84 |
|
sl@0
|
85 |
lib.Close();
|
sl@0
|
86 |
return KErrNone;
|
sl@0
|
87 |
}
|
sl@0
|
88 |
|
sl@0
|
89 |
// change locale normally..
|
sl@0
|
90 |
TInt LoadLocale(const TDesC& aName)
|
sl@0
|
91 |
{
|
sl@0
|
92 |
TInt r = UserSvr::ChangeLocale(aName);
|
sl@0
|
93 |
if (r != KErrNone)
|
sl@0
|
94 |
return r;
|
sl@0
|
95 |
return KErrNone;
|
sl@0
|
96 |
}
|
sl@0
|
97 |
|
sl@0
|
98 |
// main..
|
sl@0
|
99 |
TInt E32Main()
|
sl@0
|
100 |
{
|
sl@0
|
101 |
gTest.Start(_L("Test Locale Change\n"));
|
sl@0
|
102 |
|
sl@0
|
103 |
TInt r;
|
sl@0
|
104 |
RChangeNotifier notifier;
|
sl@0
|
105 |
TRequestStatus status;
|
sl@0
|
106 |
gTest(notifier.Create() == KErrNone);
|
sl@0
|
107 |
gTest(notifier.Logon(status) == KErrNone);
|
sl@0
|
108 |
User::WaitForRequest(status);
|
sl@0
|
109 |
|
sl@0
|
110 |
// Monitor locale change event
|
sl@0
|
111 |
gTest(notifier.Logon(status) == KErrNone);
|
sl@0
|
112 |
|
sl@0
|
113 |
r = LoadLocale(KGerLocale);
|
sl@0
|
114 |
gTest(r == KErrNone);
|
sl@0
|
115 |
User::WaitForRequest(status);
|
sl@0
|
116 |
gTest(status.Int() & EChangesLocale);
|
sl@0
|
117 |
gTest.Printf(_L("New Language: %d\n"), User::Language());
|
sl@0
|
118 |
gTest(notifier.Logon(status) == KErrNone);
|
sl@0
|
119 |
|
sl@0
|
120 |
r = LoadLocale(KEngLocale);
|
sl@0
|
121 |
gTest(r == KErrNone);
|
sl@0
|
122 |
User::WaitForRequest(status);
|
sl@0
|
123 |
gTest(status.Int() & EChangesLocale);
|
sl@0
|
124 |
gTest.Printf(_L("New Language: %d\n"), User::Language());
|
sl@0
|
125 |
gTest(notifier.Logon(status) == KErrNone);
|
sl@0
|
126 |
|
sl@0
|
127 |
r = LoadLocaleCrash(KEngLocaleRAM);
|
sl@0
|
128 |
gTest(r == KErrNone);
|
sl@0
|
129 |
User::WaitForRequest(status);
|
sl@0
|
130 |
gTest(status.Int() & EChangesLocale);
|
sl@0
|
131 |
gTest.Printf(_L("New Language: %d\n"), User::Language());
|
sl@0
|
132 |
|
sl@0
|
133 |
notifier.Close();
|
sl@0
|
134 |
gTest.End();
|
sl@0
|
135 |
return 0;
|
sl@0
|
136 |
}
|