|
1 /* |
|
2 * Copyright (c) 2010 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: unit test for the mcsplugin handler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // CLASS HEADER |
|
20 #include "ut_mcspluginhandler.h" |
|
21 |
|
22 |
|
23 // EXTERNAL INCLUDES |
|
24 #include <mcsmenu.h> |
|
25 #include <mcsmenuitem.h> |
|
26 #include <mcsmenufilter.h> |
|
27 #include <mcsdef.h> |
|
28 #include <digia/eunit/eunitmacros.h> |
|
29 #include <e32cmn.h> |
|
30 |
|
31 // INTERNAL INCLUDES |
|
32 #include "mcspluginhandler.h" |
|
33 #include "mcsplugincompletedoperation.h" |
|
34 #include "mcspluginparamval.h" |
|
35 #include "mcspluginwatcher.h" |
|
36 #include "caouserafter.h" |
|
37 |
|
38 |
|
39 const TInt KWait_05_secs = 0.5 * 1000000; |
|
40 const TInt KWait_1_secs = 1 * 1000000; |
|
41 const TInt KWait_2_secs = 2 * 1000000; |
|
42 const TInt KWait_3_secs = 3 * 1000000; |
|
43 |
|
44 TInt32 KMCSCmailMtmUidValue = 0x2001F406; |
|
45 |
|
46 _LIT( KUrl, "http://www.nokia.com" ); |
|
47 _LIT( KUrlInvalid, "services://nothingcanbeworse" ); |
|
48 _LIT( KDialed, "logs:dialed" ); |
|
49 _LIT( KBookmarkIconFile, "aimcsplugin.mif" ); |
|
50 _LIT( KBookmarkIconId, "16386" ); |
|
51 _LIT( KBookmarkIconMaskId, "16387" ); |
|
52 |
|
53 _LIT( KMyMenuData, "matrixmenudata" ); |
|
54 _LIT( KMenuUrl, "menu:url" ); |
|
55 _LIT( KMenuShortcut, "menu:shortcut" ); |
|
56 _LIT( KMenuWrong, "menu:failingmenu" ); |
|
57 _LIT( KMenuAttrParam, "param" ); |
|
58 _LIT8( KCmdOpen, "open" ); |
|
59 |
|
60 // CONSTRUCTION |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 UT_McsPluginHandler* UT_McsPluginHandler::NewL() |
|
67 { |
|
68 UT_McsPluginHandler* self = UT_McsPluginHandler::NewLC(); |
|
69 CleanupStack::Pop(); |
|
70 |
|
71 return self; |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 UT_McsPluginHandler* UT_McsPluginHandler::NewLC() |
|
79 { |
|
80 UT_McsPluginHandler* self = new(ELeave) UT_McsPluginHandler(); |
|
81 CleanupStack::PushL(self); |
|
82 |
|
83 self->ConstructL(); |
|
84 |
|
85 return self; |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // Destructor (virtual by CBase) |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 UT_McsPluginHandler::~UT_McsPluginHandler() |
|
93 { |
|
94 iMenu.Close(); |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // Default constructor |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 UT_McsPluginHandler::UT_McsPluginHandler() |
|
102 { |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // Second phase construct |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 void UT_McsPluginHandler::ConstructL() |
|
110 { |
|
111 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
112 // It generates the test case table. |
|
113 CEUnitTestSuiteClass::ConstructL(); |
|
114 } |
|
115 |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // void UT_McsPluginHandler::HandleSessionEventL |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 void UT_McsPluginHandler::HandleSessionEventL( |
|
122 TMsvSessionEvent /*aEvent*/, |
|
123 TAny* /*aArg1*/, |
|
124 TAny* /*aArg2*/, |
|
125 TAny* /*aArg3*/ ) |
|
126 { |
|
127 // No event handling |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------------------------- |
|
131 // void UT_McsPluginHandler::SetupL() |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 void UT_McsPluginHandler::SetupL() |
|
135 { |
|
136 iMenu.OpenL( KMyMenuData ); |
|
137 iHandler = CMCSPluginHandler::NewL( iMenu ); |
|
138 iWatcher = CMCSPluginWatcher::NewL( CMCSPluginWatcher::EOperation ); |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // void UT_McsPluginHandler::Teardown() |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 void UT_McsPluginHandler::Teardown() |
|
146 { |
|
147 if ( iWatcher ) |
|
148 { |
|
149 iWatcher->Cancel(); |
|
150 delete iWatcher; |
|
151 iWatcher = NULL; |
|
152 } |
|
153 if ( iHandler ) |
|
154 { |
|
155 delete iHandler; |
|
156 iHandler = NULL; |
|
157 } |
|
158 iMenu.Close(); |
|
159 } |
|
160 |
|
161 // --------------------------------------------------------------------------- |
|
162 // void UT_McsPluginHandler::SupportedTypesTestL() |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 void UT_McsPluginHandler::SupportedTypesTestL() |
|
166 { |
|
167 // Checks all supported types (excludes unsupported) |
|
168 // Change if added/removed |
|
169 EUNIT_ASSERT( iHandler->SupportsType( KMenuTypeFolder ) ); |
|
170 EUNIT_ASSERT( iHandler->SupportsType( KMenuTypeSuite ) ); |
|
171 EUNIT_ASSERT( iHandler->SupportsType( KMenuShortcut ) ); |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------------------------- |
|
175 // void UT_McsPluginHandler::CommandHandlingL() |
|
176 // --------------------------------------------------------------------------- |
|
177 // |
|
178 void UT_McsPluginHandler::CommandHandlingL() |
|
179 { |
|
180 CMenuItem* menuItem = NULL; |
|
181 |
|
182 /** |
|
183 * Test 1 - incorrect command to handle |
|
184 */ |
|
185 // Try with incorrect settings |
|
186 menuItem = CMenuItem::CreateL( iMenu, KMenuWrong, 0, 0 ); |
|
187 CleanupStack::PushL( menuItem ); |
|
188 menuItem->SetAttributeL( KMenuAttrLongName, KUrlInvalid ); |
|
189 menuItem->SetAttributeL( KMenuAttrParam, KUrlInvalid ); |
|
190 menuItem->SetAttributeL( KMenuAttrIconFile, KBookmarkIconFile ); |
|
191 menuItem->SetAttributeL( KMenuAttrIconId, KBookmarkIconId ); |
|
192 menuItem->SetAttributeL( KMenuAttrMaskId, KBookmarkIconMaskId ); |
|
193 EUNIT_ASSERT_LEAVE |
|
194 ( |
|
195 // Should leave here!!! |
|
196 CMCSPluginCompletedOperation* opl = NULL; |
|
197 opl = static_cast<CMCSPluginCompletedOperation*> ( |
|
198 iHandler->HandleCommandL( |
|
199 *menuItem, KNullDesC8, KNullDesC8, iWatcher->iStatus ) ); |
|
200 ); |
|
201 |
|
202 CleanupStack::PopAndDestroy( menuItem ); // iWatcher is not incorporated |
|
203 } |
|
204 |
|
205 // --------------------------------------------------------------------------- |
|
206 // UT_McsPluginHandler::LaunchShortcutL() |
|
207 // --------------------------------------------------------------------------- |
|
208 // |
|
209 void UT_McsPluginHandler::LaunchShortcutL() |
|
210 { |
|
211 CMenuItem* menuItem = NULL; |
|
212 |
|
213 /** |
|
214 * Test 1 - correct command to handle, incorrect menu data |
|
215 */ |
|
216 menuItem = CMenuItem::CreateL( iMenu, KMenuShortcut, 0, 0 ); |
|
217 CleanupStack::PushL( menuItem ); |
|
218 menuItem->SetAttributeL( KMenuAttrLongName, KDialed ); |
|
219 // KMenuAttrParam is omitted - shortcut cannot be launched |
|
220 //menuItem->SetAttributeL( KMenuAttrParam, KDialed ); |
|
221 menuItem->SetAttributeL( KMenuAttrIconFile, KBookmarkIconFile ); |
|
222 menuItem->SetAttributeL( KMenuAttrIconId, KBookmarkIconId ); |
|
223 menuItem->SetAttributeL( KMenuAttrMaskId, KBookmarkIconMaskId ); |
|
224 |
|
225 EUNIT_ASSERT_LEAVE |
|
226 ( |
|
227 // Should leave here!!! |
|
228 CMCSPluginCompletedOperation* opl = NULL; |
|
229 opl = static_cast<CMCSPluginCompletedOperation*> |
|
230 ( iHandler->HandleCommandL( *menuItem, KCmdOpen, KNullDesC8, |
|
231 iWatcher->iStatus ) ); |
|
232 ); |
|
233 |
|
234 CleanupStack::PopAndDestroy( menuItem ); // iWatcher is not incorporated |
|
235 } |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // UT_McsPluginHandler::LaunchItemL() |
|
239 // --------------------------------------------------------------------------- |
|
240 // |
|
241 void UT_McsPluginHandler::LaunchItemL() |
|
242 { |
|
243 //ToDo: Is shortcut launching the best way to test the function? In case |
|
244 // when launched cannot be killed |
|
245 |
|
246 CMenuOperation* op = NULL; |
|
247 CMenuItem* menuItem = NULL; |
|
248 |
|
249 menuItem = CMenuItem::CreateL( iMenu, KMenuShortcut, 0, 0 ); |
|
250 CleanupStack::PushL( menuItem ); |
|
251 menuItem->SetAttributeL( KMenuAttrLongName, KParamValueEmail ); |
|
252 menuItem->SetAttributeL( KMenuAttrParam, KParamValueEmail ); |
|
253 menuItem->SetAttributeL( KMenuAttrIconFile, KBookmarkIconFile ); |
|
254 menuItem->SetAttributeL( KMenuAttrIconId, KBookmarkIconId ); |
|
255 menuItem->SetAttributeL( KMenuAttrMaskId, KBookmarkIconMaskId ); |
|
256 |
|
257 op = iHandler->HandleCommandL( *menuItem, KCmdOpen, KNullDesC8, |
|
258 iWatcher->iStatus ); |
|
259 iWatcher->Watch( op ); |
|
260 |
|
261 // checks CActive iStatus |
|
262 TInt tcs = 0; |
|
263 while ( iWatcher->GetStatus() == KRequestPending ) |
|
264 { |
|
265 CAOUserAfter::AfterLD( 1000000 ); |
|
266 if ( ( tcs++ ) > 20 ) |
|
267 break; |
|
268 } |
|
269 iWatcher->Cancel(); |
|
270 |
|
271 CleanupStack::Pop( menuItem ); // destroyed by iWatcher |
|
272 //ToDo: Is it necessary to test all possibilities? |
|
273 } |
|
274 |
|
275 // --------------------------------------------------------------------------- |
|
276 // UT_McsPluginHandler::SessionEventL() |
|
277 // --------------------------------------------------------------------------- |
|
278 // |
|
279 void UT_McsPluginHandler::SessionEventL() |
|
280 { |
|
281 // Test HandleSessionEventL |
|
282 // The funciton is empty now, so it tests leave only |
|
283 EUNIT_ASSERT_NO_LEAVE( iHandler->HandleSessionEventL( |
|
284 MMsvSessionObserver::EMsvEntriesCreated, NULL, NULL, NULL ) ); |
|
285 } |
|
286 |
|
287 // TEST TABLE |
|
288 |
|
289 EUNIT_BEGIN_TEST_TABLE |
|
290 ( |
|
291 UT_McsPluginHandler, |
|
292 "MCS plugin handler tests", |
|
293 "UNIT" |
|
294 ) |
|
295 |
|
296 EUNIT_TEST |
|
297 ( |
|
298 "Tests supported types for the mcs plugina handler", |
|
299 "CMcsPluginHandler", |
|
300 "SupportsType", |
|
301 "FUNCTIONALITY", |
|
302 SetupL, SupportedTypesTestL, Teardown |
|
303 ) |
|
304 |
|
305 EUNIT_TEST |
|
306 ( |
|
307 "Tests command handling", |
|
308 "CMcsPluginHandler", |
|
309 "HandleCommandL", |
|
310 "FUNCTIONALITY", |
|
311 SetupL, CommandHandlingL, Teardown |
|
312 ) |
|
313 |
|
314 EUNIT_TEST |
|
315 ( |
|
316 "Tests command handling & shortcut launching", |
|
317 "CMcsPluginHandler", |
|
318 "HandleCommandL, LaunchShortcutL", |
|
319 "FUNCTIONALITY", |
|
320 SetupL, LaunchShortcutL, Teardown |
|
321 ) |
|
322 |
|
323 EUNIT_TEST |
|
324 ( |
|
325 "Tests command handling & shortcut launching 2", |
|
326 "CMcsPluginHandler", |
|
327 "HandleCommandL, LaunchShortcutL", |
|
328 "FUNCTIONALITY", |
|
329 SetupL, LaunchItemL, Teardown |
|
330 ) |
|
331 |
|
332 EUNIT_TEST |
|
333 ( |
|
334 "Tests HandleSessionEventL", |
|
335 "CMcsPluginHandler", |
|
336 "HandleSessionEventL", |
|
337 "FUNCTIONALITY", |
|
338 SetupL, SessionEventL, Teardown |
|
339 ) |
|
340 |
|
341 EUNIT_END_TEST_TABLE |
|
342 |
|
343 // END OF FILE |