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