|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // CLASS HEADER |
|
20 |
|
21 #include "MT_mcsplugin.h" |
|
22 // EXTERNAL INCLUDES |
|
23 |
|
24 #include <aiutility.h> |
|
25 #include <w32std.h> |
|
26 #include <eikenv.h> |
|
27 #include <ecom/ecom.h> |
|
28 #include <ecom/implementationproxy.h> |
|
29 #include <centralrepository.h> |
|
30 #include <aicontentobserver.h> |
|
31 #include <aipluginsettings.h> |
|
32 #include <mcsplugin.h> |
|
33 #include <apgtask.h> |
|
34 #include <aknenv.h> |
|
35 // #include <aicontentpublisher.h> |
|
36 #include <ecom/implementationinformation.h> |
|
37 |
|
38 // #include <aipropertyextension.h> |
|
39 // #include <aieventhandlerextension.h> |
|
40 #include <centralrepository.h> |
|
41 #include <msvids.h> |
|
42 #include <senduimtmuids.h> |
|
43 |
|
44 #include <digia/eunit/eunitmacros.h> |
|
45 #include <digia/eunit/ceunitalloctestcasedecorator.h> |
|
46 |
|
47 #include <hspluginsettings.h> |
|
48 |
|
49 using namespace HSPluginSettingsIf; |
|
50 |
|
51 // INTERNAL INCLUDES |
|
52 |
|
53 #include "observer.h" |
|
54 #include "caouserafter.h" |
|
55 #include <mcspluginuids.hrh> |
|
56 |
|
57 _LIT( KEventNameLaunchByIndex, "LaunchByIndex" ); |
|
58 const TInt KWait_1_secs = 1 * 1000000; |
|
59 const TInt KWait_2_secs = 2 * 1000000; |
|
60 const TInt KWait_5_secs = 5 * 1000000; |
|
61 const TInt KWait_10_secs = 10 * 1000000; |
|
62 const TInt KWait_15_secs = 15 * 1000000; |
|
63 const TInt KWait_20_secs = 20 * 1000000; |
|
64 |
|
65 _LIT( KMcsPluginName, "mcsplugin" ); |
|
66 _LIT8( KNameSpace, "1" ); |
|
67 |
|
68 // CONSTRUCTION |
|
69 |
|
70 /*EXPORT_C*/ MT_mcsplugin* MT_mcsplugin::NewL() |
|
71 { |
|
72 MT_mcsplugin* self = MT_mcsplugin::NewLC(); |
|
73 CleanupStack::Pop(); |
|
74 |
|
75 return self; |
|
76 } |
|
77 |
|
78 /*EXPORT_C*/ MT_mcsplugin* MT_mcsplugin::NewLC() |
|
79 { |
|
80 MT_mcsplugin* self = new(ELeave) MT_mcsplugin(); |
|
81 CleanupStack::PushL(self); |
|
82 |
|
83 self->ConstructL(); |
|
84 |
|
85 return self; |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // Destructor (virtual by CBase) |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 MT_mcsplugin::~MT_mcsplugin() |
|
93 { |
|
94 } |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // Default constructor |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 MT_mcsplugin::MT_mcsplugin() |
|
101 { |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // Second phase construct |
|
106 // --------------------------------------------------------------------------- |
|
107 // |
|
108 void MT_mcsplugin::ConstructL() |
|
109 { |
|
110 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
111 // It generates the test case table. |
|
112 CEUnitTestSuiteClass::ConstructL(); |
|
113 } |
|
114 |
|
115 // METHODS |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 void MT_mcsplugin::HandleSessionEventL(TMsvSessionEvent /*aEvent*/, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/) |
|
122 { |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 void MT_mcsplugin::SetupL() |
|
130 { |
|
131 __UHEAP_MARK; |
|
132 _LIT8( KAppUid, "271012080" ); |
|
133 CHomescreenSettings::InitializeL( KAppUid ); |
|
134 |
|
135 iContentObserver = Observer::NewL(); |
|
136 |
|
137 TUid uid = { AI_UID_ECOM_IMPLEMENTATION_CONTENTPUBLISHER_MCSPLUGIN }; |
|
138 THsPublisherInfo pubInfo( uid, KMcsPluginName, KNameSpace ); |
|
139 |
|
140 EUNIT_ASSERT(iContentObserver); |
|
141 |
|
142 iPlugin = CHsContentPublisher::NewL( pubInfo ); |
|
143 EUNIT_ASSERT( iPlugin ); |
|
144 |
|
145 // Array owned by the plugin |
|
146 RAiSettingsItemArray settings; |
|
147 //Content Item |
|
148 MAiPluginSettings* setting = AiUtility::CreatePluginSettingsL(); |
|
149 CleanupDeletePushL( setting ); |
|
150 MAiPluginContentItem& item = setting->AiPluginContentItem(); |
|
151 item.SetTypeL( _L("image") ); |
|
152 item.SetNameL( _L("widget/icon")); |
|
153 settings.AppendL( setting ); |
|
154 CleanupStack::Pop( setting ); |
|
155 |
|
156 MAiPluginSettings* setting1 = AiUtility::CreatePluginSettingsL(); |
|
157 CleanupDeletePushL( setting1 ); |
|
158 MAiPluginContentItem& item1 = setting1->AiPluginContentItem(); |
|
159 item1.SetTypeL( _L("image") ); |
|
160 item1.SetNameL( _L("widget/presenceicon")); |
|
161 settings.AppendL( setting1 ); |
|
162 CleanupStack::Pop( setting1 ); |
|
163 |
|
164 MAiPluginSettings* setting2 = AiUtility::CreatePluginSettingsL(); |
|
165 CleanupDeletePushL( setting2 ); |
|
166 MAiPluginContentItem& item2 = setting2->AiPluginContentItem(); |
|
167 item2.SetTypeL( _L("text") ); |
|
168 item2.SetNameL( _L("widget/longname")); |
|
169 settings.AppendL( setting2 ); |
|
170 CleanupStack::Pop( setting2 ); |
|
171 |
|
172 MAiPluginSettings* setting3 = AiUtility::CreatePluginSettingsL(); |
|
173 CleanupDeletePushL( setting3 ); |
|
174 MAiPluginContentItem& item3 = setting3->AiPluginContentItem(); |
|
175 item3.SetTypeL( _L("text") ); |
|
176 item3.SetNameL( _L("widget/shortname")); |
|
177 settings.AppendL( setting3 ); |
|
178 CleanupStack::Pop( setting3 ); |
|
179 |
|
180 iPlugin->ConfigureL( settings ); |
|
181 iPlugin->SubscribeL( *iContentObserver ); |
|
182 iPlugin->Start( CHsContentPublisher::ESystemStartup ); |
|
183 |
|
184 iPlugin->Resume( CHsContentPublisher::EForeground ); |
|
185 } |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 void MT_mcsplugin::EmptySetupL() |
|
192 { |
|
193 } |
|
194 |
|
195 // --------------------------------------------------------------------------- |
|
196 // |
|
197 // --------------------------------------------------------------------------- |
|
198 // |
|
199 void MT_mcsplugin::Teardown() |
|
200 { |
|
201 delete iPlugin; |
|
202 iPlugin = NULL; |
|
203 |
|
204 delete iContentObserver; |
|
205 iContentObserver = NULL; |
|
206 |
|
207 CHomescreenSettings::UnInitialize(); |
|
208 __UHEAP_MARKEND; |
|
209 } |
|
210 |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // Tests Resume, plugin is resumed correctly. |
|
214 // If plugin is working correctly it should be able to launch app |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 void MT_mcsplugin::TestResumeL() |
|
218 { |
|
219 // Frees engine, because shortcuts needs to be recreated when theme is changed |
|
220 iPlugin->Resume( CHsContentPublisher::EForeground ); |
|
221 |
|
222 // Free engine one more time... |
|
223 iPlugin->Stop( CHsContentPublisher::ESystemShutdown ); |
|
224 |
|
225 // ... to test last decicions. |
|
226 iPlugin->Resume( CHsContentPublisher::EForeground ); |
|
227 } |
|
228 |
|
229 // --------------------------------------------------------------------------- |
|
230 // Tests Suspend, plugin is suspended. |
|
231 // When plugin is suspended it shouldn't launch apps |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 void MT_mcsplugin::TestSuspendL() |
|
235 { |
|
236 TRAPD(err1, iPlugin->Suspend( CHsContentPublisher::EBackground)); |
|
237 |
|
238 // EUNIT_ASSERT_NO_LEAVE(LaunchAppFailsL(0x00000001, KScutCalculatorUid)); |
|
239 |
|
240 iPlugin->Stop( CHsContentPublisher::ESystemShutdown ); |
|
241 |
|
242 TRAPD(err2, iPlugin->Suspend( CHsContentPublisher::EBackground)); |
|
243 } |
|
244 |
|
245 // --------------------------------------------------------------------------- |
|
246 // Tests SubscribeL, adding observer. |
|
247 // --------------------------------------------------------------------------- |
|
248 // |
|
249 void MT_mcsplugin::TestSubscribeL() |
|
250 { |
|
251 EUNIT_ASSERT_NO_LEAVE(iPlugin->SubscribeL(*iContentObserver)); |
|
252 } |
|
253 |
|
254 // --------------------------------------------------------------------------- |
|
255 // Tests GetPropertyL |
|
256 // Return values shouldn't be null |
|
257 // --------------------------------------------------------------------------- |
|
258 // |
|
259 void MT_mcsplugin::TestGetPropertyL() |
|
260 { |
|
261 TAny* anyPtr = iPlugin->GetProperty( CHsContentPublisher::EPublisherContent ); |
|
262 EUNIT_ASSERT( anyPtr ); |
|
263 |
|
264 MAiContentItemIterator* iter = static_cast<MAiContentItemIterator*>( anyPtr ); |
|
265 EUNIT_ASSERT( iter ); |
|
266 } |
|
267 |
|
268 // --------------------------------------------------------------------------- |
|
269 // Free engine, ensure that plugin won't launch apps. |
|
270 // --------------------------------------------------------------------------- |
|
271 // |
|
272 void MT_mcsplugin::TestFreeEngineL() |
|
273 { |
|
274 iPlugin->Stop( CHsContentPublisher::ESystemShutdown ); |
|
275 |
|
276 iPlugin->Start( CHsContentPublisher::ESystemStartup ); |
|
277 |
|
278 iPlugin->Resume( CHsContentPublisher::EForeground ); |
|
279 |
|
280 // LaunchAppFailsL(0x00000001, KScutCalculatorUid); |
|
281 } |
|
282 |
|
283 |
|
284 |
|
285 // --------------------------------------------------------------------------- |
|
286 // Send invalid parameters to plugin, no crash should occur |
|
287 // --------------------------------------------------------------------------- |
|
288 // |
|
289 void MT_mcsplugin::TestHandleEventErrorHandling() |
|
290 { |
|
291 iPlugin->HandleEvent(_L("invalid"), KNullDesC); |
|
292 iPlugin->HandleEvent(KEventNameLaunchByIndex, KNullDesC); |
|
293 iPlugin->HandleEvent(KEventNameLaunchByIndex, _L("0x")); |
|
294 iPlugin->HandleEvent(KEventNameLaunchByIndex, _L("99999999")); |
|
295 iPlugin->HandleEvent(KEventNameLaunchByIndex, _L("-1")); |
|
296 } |
|
297 |
|
298 |
|
299 // TEST TABLE |
|
300 |
|
301 EUNIT_BEGIN_TEST_TABLE(MT_mcsplugin, "MCSPlugin module tests", "MODULE") |
|
302 |
|
303 EUNIT_TEST("Resume", "MCSPlugin", "Resume", "FUNCTIONALITY", SetupL, TestResumeL, Teardown) |
|
304 EUNIT_TEST("Suspend", "MCSPlugin", "Suspend", "FUNCTIONALITY", SetupL, TestSuspendL, Teardown) |
|
305 EUNIT_TEST("Subscribe", "MCSPlugin", "SubscribeL", "FUNCTIONALITY", SetupL, TestSubscribeL, Teardown) |
|
306 //EUNIT_TEST("Get property", "MCSPlugin", "GetPropertyL", "FUNCTIONALITY", SetupL, TestGetPropertyL, Teardown) |
|
307 //EUNIT_TEST("Free engine", "MCSPlugin", "FreeEngineL", "FUNCTIONALITY", SetupL, TestFreeEngineL, Teardown) |
|
308 EUNIT_TEST("Test different events", "MCSPlugin", "HandleEvent", "FUNCTIONALITY", SetupL, TestHandleEventErrorHandling, Teardown) |
|
309 |
|
310 |
|
311 EUNIT_END_TEST_TABLE |
|
312 |
|
313 // END OF FILE |