|
1 /* |
|
2 * Copyright (c) 2004 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: EUnit unit test class for CAiEventHandler |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <e32base.h> |
|
20 #include <e32cmn.h> |
|
21 #include <bautils.h> |
|
22 #include <digia/eunit/eunitmacros.h> |
|
23 #include <digia/eunit/teunitassertioninfo.h> |
|
24 |
|
25 // User includes |
|
26 #include <hspublisherinfo.h> |
|
27 #include "ut_aieventhandler.h" |
|
28 #include "aiuicontrollermanager_stub.h" |
|
29 |
|
30 #include "aipluginfactory.h" |
|
31 #include "aieventhandler.h" |
|
32 #include "aifwpublisherinfo.h" |
|
33 #include "aistatemanager.h" |
|
34 |
|
35 // Constants |
|
36 _LIT( KProfile, "Profile" ); |
|
37 _LIT( KDevStat, "DeviceStatus" ); |
|
38 _LIT( KUnknown, "Unknown" ); |
|
39 |
|
40 const TInt KProfileUid( 0x10275101 ); |
|
41 const TInt KDeviceStatusUid( 0x102750F8 ); |
|
42 const TInt KUnknownUid( 0xBABE2BED ); |
|
43 |
|
44 _LIT8( KNs1, "namespace1" ); |
|
45 _LIT8( KNs2, "namespace2" ); |
|
46 |
|
47 // ======== LOCAL FUNCTIONS ======== |
|
48 |
|
49 // ======== MEMBER FUNCTIONS ======= |
|
50 // ---------------------------------------------------------------------------- |
|
51 // UT_AiEventHandler::NewL() |
|
52 // |
|
53 // ---------------------------------------------------------------------------- |
|
54 // |
|
55 UT_AiEventHandler* UT_AiEventHandler::NewL() |
|
56 { |
|
57 UT_AiEventHandler* self = UT_AiEventHandler::NewLC(); |
|
58 CleanupStack::Pop( self ); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // ---------------------------------------------------------------------------- |
|
63 // UT_AiEventHandler::NewLC() |
|
64 // |
|
65 // ---------------------------------------------------------------------------- |
|
66 // |
|
67 UT_AiEventHandler* UT_AiEventHandler::NewLC() |
|
68 { |
|
69 UT_AiEventHandler* self = new ( ELeave ) UT_AiEventHandler(); |
|
70 CleanupStack::PushL( self ); |
|
71 self->ConstructL(); |
|
72 return self; |
|
73 } |
|
74 |
|
75 // ---------------------------------------------------------------------------- |
|
76 // UT_AiEventHandler::~UT_AiEventHandler() |
|
77 // |
|
78 // ---------------------------------------------------------------------------- |
|
79 // |
|
80 UT_AiEventHandler::~UT_AiEventHandler() |
|
81 { |
|
82 } |
|
83 |
|
84 // ---------------------------------------------------------------------------- |
|
85 // UT_AiEventHandler::UT_AiEventHandler() |
|
86 // |
|
87 // ---------------------------------------------------------------------------- |
|
88 // |
|
89 UT_AiEventHandler::UT_AiEventHandler() |
|
90 { |
|
91 } |
|
92 |
|
93 // ---------------------------------------------------------------------------- |
|
94 // UT_AiEventHandler::ConstructL() |
|
95 // |
|
96 // ---------------------------------------------------------------------------- |
|
97 // |
|
98 void UT_AiEventHandler::ConstructL() |
|
99 { |
|
100 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
101 // It generates the test case table. |
|
102 CEUnitTestSuiteClass::ConstructL(); |
|
103 } |
|
104 |
|
105 // ---------------------------------------------------------------------------- |
|
106 // UT_AiEventHandler::SetupL() |
|
107 // |
|
108 // ---------------------------------------------------------------------------- |
|
109 // |
|
110 void UT_AiEventHandler::SetupL() |
|
111 { |
|
112 iUiMgr = CAiUiControllerManager::NewL(); |
|
113 |
|
114 iFactory = CAiPluginFactory::NewL( *iUiMgr ); |
|
115 iFactory->ConstructL(); |
|
116 |
|
117 iStateManager = CAiStateManager::NewL( *iFactory ); |
|
118 |
|
119 iHandler = CAiEventHandler::NewL( *iFactory ); |
|
120 |
|
121 iWait = new ( ELeave ) CActiveSchedulerWait; |
|
122 |
|
123 iResult = KErrNone; |
|
124 } |
|
125 |
|
126 // ---------------------------------------------------------------------------- |
|
127 // UT_AiEventHandler::Teardown() |
|
128 // |
|
129 // ---------------------------------------------------------------------------- |
|
130 // |
|
131 void UT_AiEventHandler::Teardown() |
|
132 { |
|
133 delete iHandler; |
|
134 iHandler = NULL; |
|
135 |
|
136 delete iFactory; |
|
137 iFactory = NULL; |
|
138 |
|
139 delete iUiMgr; |
|
140 iUiMgr = NULL; |
|
141 |
|
142 delete iStateManager; |
|
143 iStateManager = NULL; |
|
144 |
|
145 if ( iWait->IsStarted() ) |
|
146 { |
|
147 iWait->AsyncStop(); |
|
148 } |
|
149 delete iWait; |
|
150 iWait = NULL; |
|
151 } |
|
152 |
|
153 //------------------------------------------------------------------------------ |
|
154 // UT_AiEventHandler::TestHandlePluginEventL() |
|
155 // |
|
156 //------------------------------------------------------------------------------ |
|
157 // |
|
158 void UT_AiEventHandler::TestHandlePluginEventL() |
|
159 { |
|
160 THsPublisherInfo profile( |
|
161 TUid::Uid( KProfileUid ), KProfile, KNs1 ); |
|
162 |
|
163 THsPublisherInfo devstat( |
|
164 TUid::Uid( KDeviceStatusUid ), KDevStat, KNs2 ); |
|
165 |
|
166 THsPublisherInfo unknown( |
|
167 TUid::Uid( KUnknownUid ), KUnknown, KNs1 ); |
|
168 |
|
169 _LIT( KProfileEvent, "Profile/SwitchProfileByIndex" ); |
|
170 _LIT( KDeviceStatusEvent, "DeviceStatus/DummyEvent" ); |
|
171 _LIT( KUnknownEvent, "Unknown/DummyEvent" ); |
|
172 _LIT( KIvalidEvent, "ååäaäåp39469568sdfsdfs" ); |
|
173 _LIT( KInvalidEvent2, "--\\\afsd////ååäaäåp39469568sdfsdfs" ); |
|
174 |
|
175 TAiFwPublisherInfo profileInfo( profile, TAiFwCallback( CallBack, this ), EAiFwPluginStartup ); |
|
176 iFactory->LoadPlugin( profileInfo ); |
|
177 iWait->Start(); |
|
178 EUNIT_ASSERT_EQUALS( iResult, KErrNone ); |
|
179 EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( profile ) != NULL, ETrue ); |
|
180 |
|
181 TAiFwPublisherInfo devstatInfo( devstat, TAiFwCallback( CallBack, this ), EAiFwPluginStartup ); |
|
182 iFactory->LoadPlugin( devstatInfo ); |
|
183 iWait->Start(); |
|
184 EUNIT_ASSERT_EQUALS( iResult, KErrNone ); |
|
185 EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( devstat ) != NULL, ETrue ); |
|
186 |
|
187 iHandler->HandlePluginEvent( KProfileEvent ); |
|
188 iHandler->HandlePluginEvent( KDeviceStatusEvent ); |
|
189 iHandler->HandlePluginEvent( KUnknownEvent ); |
|
190 iHandler->HandlePluginEvent( KIvalidEvent ); |
|
191 iHandler->HandlePluginEvent( KInvalidEvent2 ); |
|
192 |
|
193 iHandler->HandlePluginEventL( profile, KProfileEvent ); |
|
194 iHandler->HandlePluginEventL( devstat, KDeviceStatusEvent ); |
|
195 iHandler->HandlePluginEventL( unknown, KUnknownEvent ); |
|
196 |
|
197 profileInfo = TAiFwPublisherInfo( profile, TAiFwCallback( CallBack, this ), EAiFwPluginShutdown ); |
|
198 iFactory->DestroyPlugin( profileInfo ); |
|
199 devstatInfo = TAiFwPublisherInfo( devstat, TAiFwCallback( CallBack, this ), EAiFwPluginShutdown ); |
|
200 iFactory->DestroyPlugin( devstatInfo ); |
|
201 } |
|
202 |
|
203 //------------------------------------------------------------------------------ |
|
204 // UT_AiEventHandler::TestHasMenuItemL() |
|
205 // |
|
206 //------------------------------------------------------------------------------ |
|
207 // |
|
208 void UT_AiEventHandler::TestHasMenuItemL() |
|
209 { |
|
210 THsPublisherInfo profile( |
|
211 TUid::Uid( KProfileUid ), KProfile, KNs1 ); |
|
212 |
|
213 THsPublisherInfo devstat( |
|
214 TUid::Uid( KDeviceStatusUid ), KDevStat, KNs2 ); |
|
215 |
|
216 THsPublisherInfo unknown( |
|
217 TUid::Uid( KUnknownUid ), KUnknown, KNs1 ); |
|
218 |
|
219 _LIT( KMenuitem, "Some_menuitem" ); |
|
220 |
|
221 TAiFwPublisherInfo profileInfo( profile, TAiFwCallback( CallBack, this ), EAiFwPluginStartup ); |
|
222 iFactory->LoadPlugin( profileInfo ); |
|
223 iWait->Start(); |
|
224 EUNIT_ASSERT_EQUALS( iResult, KErrNone ); |
|
225 EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( profile ) != NULL, ETrue ); |
|
226 |
|
227 TAiFwPublisherInfo devstatInfo( devstat, TAiFwCallback( CallBack, this ), EAiFwPluginStartup ); |
|
228 iFactory->LoadPlugin( devstatInfo ); |
|
229 iWait->Start(); |
|
230 EUNIT_ASSERT_EQUALS( iResult, KErrNone ); |
|
231 EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( devstat ) != NULL, ETrue ); |
|
232 |
|
233 iHandler->HasMenuItemL( profile, KMenuitem ); |
|
234 iHandler->HasMenuItemL( devstat, KMenuitem ); |
|
235 iHandler->HasMenuItemL( unknown, KMenuitem ); |
|
236 |
|
237 profileInfo = TAiFwPublisherInfo( profile, TAiFwCallback( CallBack, this ), EAiFwPluginShutdown ); |
|
238 iFactory->DestroyPlugin( profileInfo ); |
|
239 |
|
240 devstatInfo = TAiFwPublisherInfo( devstat, TAiFwCallback( CallBack, this ), EAiFwPluginShutdown ); |
|
241 iFactory->DestroyPlugin( devstatInfo ); |
|
242 } |
|
243 |
|
244 //------------------------------------------------------------------------------ |
|
245 // UT_AiEventHandler::TestRefreshContentL() |
|
246 // |
|
247 //------------------------------------------------------------------------------ |
|
248 // |
|
249 void UT_AiEventHandler::TestRefreshContentL() |
|
250 { |
|
251 THsPublisherInfo profile( |
|
252 TUid::Uid( KProfileUid ), KProfile, KNs1 ); |
|
253 |
|
254 THsPublisherInfo devstat( |
|
255 TUid::Uid( KDeviceStatusUid ), KDevStat, KNs2 ); |
|
256 |
|
257 THsPublisherInfo unknown( |
|
258 TUid::Uid( KUnknownUid ), KUnknown, KNs1 ); |
|
259 |
|
260 _LIT( KProfileContent, "Profile/ActiveProfileName" ); |
|
261 _LIT( KDeviceStatusContent, "DeviceStatus/NetworkIdentity" ); |
|
262 _LIT( KUnknownContent, "Unknown/DummyContentId" ); |
|
263 |
|
264 _LIT( KNetworkIdentity, "NetworkIdentity" ); |
|
265 |
|
266 TAiFwPublisherInfo profileInfo( profile, TAiFwCallback( CallBack, this ) , EAiFwPluginStartup ); |
|
267 iFactory->LoadPlugin( profileInfo ); |
|
268 iWait->Start(); |
|
269 EUNIT_ASSERT_EQUALS( iResult, KErrNone ); |
|
270 EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( profile ) != NULL, ETrue ); |
|
271 |
|
272 TAiFwPublisherInfo devstatInfo( devstat, TAiFwCallback( CallBack, this ), EAiFwPluginStartup ); |
|
273 iFactory->LoadPlugin( devstatInfo ); |
|
274 iWait->Start(); |
|
275 EUNIT_ASSERT_EQUALS( iResult, KErrNone ); |
|
276 EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( devstat ) != NULL, ETrue ); |
|
277 |
|
278 iHandler->RefreshContent( KProfileContent ); |
|
279 iHandler->RefreshContent( KDeviceStatusContent ); |
|
280 iHandler->RefreshContent( KUnknownContent ); |
|
281 |
|
282 iHandler->RefreshContent( profile, KProfileContent ); |
|
283 iHandler->RefreshContent( devstat, KDeviceStatusContent ); |
|
284 iHandler->RefreshContent( unknown, KUnknownContent ); |
|
285 |
|
286 iHandler->RefreshContent( devstat, KNetworkIdentity ); |
|
287 |
|
288 profileInfo = TAiFwPublisherInfo( profile, TAiFwCallback( CallBack, this ), EAiFwPluginShutdown ); |
|
289 iFactory->DestroyPlugin( profileInfo ); |
|
290 |
|
291 devstatInfo = TAiFwPublisherInfo( devstat, TAiFwCallback( CallBack, this ), EAiFwPluginShutdown ); |
|
292 iFactory->DestroyPlugin( devstatInfo ); |
|
293 } |
|
294 |
|
295 //------------------------------------------------------------------------------ |
|
296 // UT_AiEventHandler::TestSuspendContentL() |
|
297 // |
|
298 //------------------------------------------------------------------------------ |
|
299 // |
|
300 void UT_AiEventHandler::TestSuspendContentL() |
|
301 { |
|
302 THsPublisherInfo profile( |
|
303 TUid::Uid( KProfileUid ), KProfile, KNs1 ); |
|
304 |
|
305 THsPublisherInfo devstat( |
|
306 TUid::Uid( KDeviceStatusUid ), KDevStat, KNs2 ); |
|
307 |
|
308 THsPublisherInfo unknown( |
|
309 TUid::Uid( KUnknownUid ), KUnknown, KNs1 ); |
|
310 |
|
311 _LIT( KProfileContent, "ActiveProfileName" ); |
|
312 _LIT( KDeviceStatusContent, "NetworkIdentity" ); |
|
313 _LIT( KUnknownContent, "DummyContentId" ); |
|
314 |
|
315 TAiFwPublisherInfo profileInfo( profile, TAiFwCallback( CallBack, this ), EAiFwPluginStartup ); |
|
316 iFactory->LoadPlugin( profileInfo ); |
|
317 iWait->Start(); |
|
318 EUNIT_ASSERT_EQUALS( iResult, KErrNone ); |
|
319 EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( profile ) != NULL, ETrue ); |
|
320 |
|
321 TAiFwPublisherInfo devstatInfo( devstat, TAiFwCallback( CallBack, this ), EAiFwPluginStartup ); |
|
322 iFactory->LoadPlugin( devstatInfo ); |
|
323 iWait->Start(); |
|
324 EUNIT_ASSERT_EQUALS( iResult, KErrNone ); |
|
325 EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( devstat ) != NULL, ETrue ); |
|
326 |
|
327 iHandler->SuspendContent( profile, KProfileContent ); |
|
328 iHandler->SuspendContent( devstat, KDeviceStatusContent ); |
|
329 iHandler->SuspendContent( unknown, KUnknownContent ); |
|
330 |
|
331 profileInfo = TAiFwPublisherInfo( profile, TAiFwCallback( CallBack, this ), EAiFwPluginShutdown ); |
|
332 iFactory->DestroyPlugin( profileInfo ); |
|
333 |
|
334 devstatInfo = TAiFwPublisherInfo( devstat, TAiFwCallback( CallBack, this ), EAiFwPluginShutdown ); |
|
335 iFactory->DestroyPlugin( devstatInfo ); |
|
336 } |
|
337 |
|
338 // ---------------------------------------------------------------------------- |
|
339 // CAiPluginFactory::CallBack() |
|
340 // |
|
341 // ---------------------------------------------------------------------------- |
|
342 // |
|
343 void UT_AiEventHandler::CallBack( TAny* aPtr, TInt aResult ) |
|
344 { |
|
345 UT_AiEventHandler* self = static_cast< UT_AiEventHandler* >( aPtr ); |
|
346 self->iResult = aResult; |
|
347 self->iWait->AsyncStop(); |
|
348 } |
|
349 |
|
350 //------------------------------------------------------------------------------ |
|
351 // Test case table |
|
352 // |
|
353 //------------------------------------------------------------------------------ |
|
354 // |
|
355 EUNIT_BEGIN_TEST_TABLE( |
|
356 UT_AiEventHandler, |
|
357 "Unit test suite for CAiEventHandler", |
|
358 "UNIT" ) |
|
359 |
|
360 EUNIT_TEST( |
|
361 "HandlePluginEvent", |
|
362 "CAiEventHandler", |
|
363 "", |
|
364 "FUNCTIONALITY", |
|
365 SetupL, TestHandlePluginEventL, Teardown ) |
|
366 |
|
367 EUNIT_TEST( |
|
368 "HasMenuItem", |
|
369 "CAiEventHandler", |
|
370 "", |
|
371 "FUNCTIONALITY", |
|
372 SetupL, TestHasMenuItemL, Teardown ) |
|
373 |
|
374 EUNIT_TEST( |
|
375 "RefreshContent", |
|
376 "CAiEventHandler", |
|
377 "", |
|
378 "FUNCTIONALITY", |
|
379 SetupL, TestRefreshContentL, Teardown ) |
|
380 |
|
381 EUNIT_TEST( |
|
382 "SuspendContent", |
|
383 "CAiEventHandler", |
|
384 "", |
|
385 "FUNCTIONALITY", |
|
386 SetupL, TestSuspendContentL, Teardown ) |
|
387 |
|
388 EUNIT_END_TEST_TABLE |
|
389 |
|
390 // End of file |