|
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 CAiStateProvider |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <e32base.h> |
|
20 #include <e32cmn.h> |
|
21 #include <bautils.h> |
|
22 #include <babitflags.h> |
|
23 #include <AknDef.h> |
|
24 #include <digia/eunit/eunitmacros.h> |
|
25 #include <digia/eunit/teunitassertioninfo.h> |
|
26 |
|
27 // User includes |
|
28 #include <hspublisherinfo.h> |
|
29 #include "ut_aistateprovider.h" |
|
30 |
|
31 #include "aistateprovider.h" |
|
32 #include "aifwpublisherinfo.h" |
|
33 |
|
34 // Constants |
|
35 const TInt KUid( 0xBABE2BED ); |
|
36 _LIT( KTestPublisher, "TestPublisher" ); |
|
37 _LIT8( KNs, "TestNamespace" ); |
|
38 |
|
39 // ======== LOCAL FUNCTIONS ======== |
|
40 |
|
41 // ======== MEMBER FUNCTIONS ======= |
|
42 // ---------------------------------------------------------------------------- |
|
43 // UT_AiStateProvider::NewL() |
|
44 // |
|
45 // ---------------------------------------------------------------------------- |
|
46 // |
|
47 UT_AiStateProvider* UT_AiStateProvider::NewL() |
|
48 { |
|
49 UT_AiStateProvider* self = UT_AiStateProvider::NewLC(); |
|
50 CleanupStack::Pop( self ); |
|
51 return self; |
|
52 } |
|
53 |
|
54 // ---------------------------------------------------------------------------- |
|
55 // UT_AiStateProvider::NewLC() |
|
56 // |
|
57 // ---------------------------------------------------------------------------- |
|
58 // |
|
59 UT_AiStateProvider* UT_AiStateProvider::NewLC() |
|
60 { |
|
61 UT_AiStateProvider* self = new ( ELeave ) UT_AiStateProvider(); |
|
62 CleanupStack::PushL( self ); |
|
63 self->ConstructL(); |
|
64 return self; |
|
65 } |
|
66 |
|
67 // ---------------------------------------------------------------------------- |
|
68 // UT_AiStateProvider::~UT_AiStateProvider() |
|
69 // |
|
70 // ---------------------------------------------------------------------------- |
|
71 // |
|
72 UT_AiStateProvider::~UT_AiStateProvider() |
|
73 { |
|
74 } |
|
75 |
|
76 // ---------------------------------------------------------------------------- |
|
77 // UT_AiStateProvider::UT_AiStateProvider() |
|
78 // |
|
79 // ---------------------------------------------------------------------------- |
|
80 // |
|
81 UT_AiStateProvider::UT_AiStateProvider() |
|
82 { |
|
83 } |
|
84 |
|
85 // ---------------------------------------------------------------------------- |
|
86 // UT_AiStateProvider::ConstructL() |
|
87 // |
|
88 // ---------------------------------------------------------------------------- |
|
89 // |
|
90 void UT_AiStateProvider::ConstructL() |
|
91 { |
|
92 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
93 // It generates the test case table. |
|
94 CEUnitTestSuiteClass::ConstructL(); |
|
95 } |
|
96 |
|
97 // ---------------------------------------------------------------------------- |
|
98 // UT_AiStateProvider::NotifyStateChange() |
|
99 // |
|
100 // ---------------------------------------------------------------------------- |
|
101 // |
|
102 void UT_AiStateProvider::NotifyStateChange( TAiFwState aState ) |
|
103 { |
|
104 if ( iIgnoreNotifyStateChange ) |
|
105 { |
|
106 return; |
|
107 } |
|
108 |
|
109 EUNIT_ASSERT_EQUALS( aState, iExpectedState ); |
|
110 |
|
111 if ( iExpectedState == EAiFwUiStartup ) |
|
112 { |
|
113 // Need to ignore until state provider is fully constructed |
|
114 iIgnoreNotifyStateChange = ETrue; |
|
115 } |
|
116 } |
|
117 |
|
118 // ---------------------------------------------------------------------------- |
|
119 // UT_AiStateProvider::NotifyLoadPlugin() |
|
120 // |
|
121 // ---------------------------------------------------------------------------- |
|
122 // |
|
123 void UT_AiStateProvider::NotifyLoadPlugin( const TAiFwPublisherInfo& aInfo ) |
|
124 { |
|
125 //TODO: ok? |
|
126 THsPublisherInfo info( TUid::Uid( KUid ), KTestPublisher, KNs ); |
|
127 |
|
128 EUNIT_ASSERT_EQUALS( aInfo.Info(), info ); |
|
129 |
|
130 EUNIT_ASSERT_EQUALS( aInfo.Reason(), EAiFwSystemStartup ); |
|
131 } |
|
132 |
|
133 // ---------------------------------------------------------------------------- |
|
134 // UT_AiStateProvider::NotifyDestroyPlugin() |
|
135 // |
|
136 // ---------------------------------------------------------------------------- |
|
137 // |
|
138 void UT_AiStateProvider::NotifyDestroyPlugin( const TAiFwPublisherInfo& aInfo ) |
|
139 { |
|
140 //TODO: ok? |
|
141 THsPublisherInfo info( TUid::Uid( KUid ), KTestPublisher, KNs ); |
|
142 |
|
143 EUNIT_ASSERT_EQUALS( aInfo.Info(), info ); |
|
144 |
|
145 EUNIT_ASSERT_EQUALS( aInfo.Reason(), EAiFwSystemShutdown ); |
|
146 } |
|
147 |
|
148 // ---------------------------------------------------------------------------- |
|
149 // UT_AiStateProvider::NotifyUpdatePlugins() |
|
150 // |
|
151 // ---------------------------------------------------------------------------- |
|
152 // |
|
153 /*void UT_AiStateProvider::NotifyUpdatePlugins() |
|
154 { |
|
155 iPluginsUpdated = ETrue; |
|
156 }*/ |
|
157 |
|
158 // ---------------------------------------------------------------------------- |
|
159 // UT_AiStateProvider::NotifyReloadPlugins() |
|
160 // |
|
161 // ---------------------------------------------------------------------------- |
|
162 // |
|
163 void UT_AiStateProvider::NotifyReloadPlugins() |
|
164 { |
|
165 iPluginsUpdated = ETrue; |
|
166 } |
|
167 |
|
168 // ---------------------------------------------------------------------------- |
|
169 // UT_AiStateProvider::NotifyReleasePlugins() |
|
170 // |
|
171 // ---------------------------------------------------------------------------- |
|
172 // |
|
173 void UT_AiStateProvider::NotifyReleasePlugins( const RArray<TUid>& ) |
|
174 { |
|
175 } |
|
176 |
|
177 // ---------------------------------------------------------------------------- |
|
178 // UT_AiStateProvider::SetupL() |
|
179 // |
|
180 // ---------------------------------------------------------------------------- |
|
181 // |
|
182 void UT_AiStateProvider::SetupL() |
|
183 { |
|
184 CCoeEnv* env( CCoeEnv::Static() ); |
|
185 |
|
186 iExpectedState = EAiFwUiStartup; |
|
187 |
|
188 iProvider = CAiStateProvider::NewL( *this ); |
|
189 iProvider->StartL( *env ); |
|
190 |
|
191 iIgnoreNotifyStateChange = EFalse; |
|
192 } |
|
193 |
|
194 // ---------------------------------------------------------------------------- |
|
195 // UT_AiStateProvider::Teardown() |
|
196 // |
|
197 // ---------------------------------------------------------------------------- |
|
198 // |
|
199 void UT_AiStateProvider::Teardown() |
|
200 { |
|
201 iExpectedState = EAiFwUiShutdown; |
|
202 |
|
203 iProvider->Stop(); |
|
204 |
|
205 delete iProvider; |
|
206 iProvider = NULL; |
|
207 } |
|
208 |
|
209 // ---------------------------------------------------------------------------- |
|
210 // UT_AiStateProvider::TestStartStopL() |
|
211 // |
|
212 // ---------------------------------------------------------------------------- |
|
213 // |
|
214 void UT_AiStateProvider::TestStartStopL() |
|
215 { |
|
216 CCoeEnv* env( CCoeEnv::Static() ); |
|
217 |
|
218 EUNIT_ASSERT_EQUALS( iProvider->iStarted, ETrue ); |
|
219 |
|
220 iExpectedState = EAiFwUiShutdown; |
|
221 |
|
222 iProvider->Stop(); |
|
223 |
|
224 EUNIT_ASSERT_EQUALS( iProvider->iStarted, EFalse ); |
|
225 EUNIT_ASSERT_EQUALS( iProvider->iCoeEnv == NULL, ETrue ); |
|
226 EUNIT_ASSERT_EQUALS( iProvider->iEcomObserver == NULL, ETrue ); |
|
227 EUNIT_ASSERT_EQUALS( iProvider->iBackupRestoreObserver == NULL, ETrue ); |
|
228 EUNIT_ASSERT_EQUALS( iProvider->iLightObserver == NULL, ETrue ); |
|
229 |
|
230 iExpectedState = EAiFwUiStartup; |
|
231 |
|
232 iProvider->StartL( *env ); |
|
233 |
|
234 EUNIT_ASSERT_EQUALS( iProvider->iStarted, ETrue ); |
|
235 EUNIT_ASSERT_EQUALS( iProvider->iCoeEnv != NULL, ETrue ); |
|
236 EUNIT_ASSERT_EQUALS( iProvider->iEcomObserver != NULL, ETrue ); |
|
237 EUNIT_ASSERT_EQUALS( iProvider->iBackupRestoreObserver != NULL, ETrue ); |
|
238 EUNIT_ASSERT_EQUALS( iProvider->iLightObserver != NULL, ETrue ); |
|
239 |
|
240 iIgnoreNotifyStateChange = EFalse; |
|
241 iExpectedState = (TAiFwState)0; |
|
242 // Should not get any notification because already started |
|
243 iProvider->StartL( *env ); |
|
244 |
|
245 EUNIT_ASSERT_EQUALS( iProvider->iStarted, ETrue ); |
|
246 EUNIT_ASSERT_EQUALS( iProvider->iCoeEnv != NULL, ETrue ); |
|
247 EUNIT_ASSERT_EQUALS( iProvider->iEcomObserver != NULL, ETrue ); |
|
248 EUNIT_ASSERT_EQUALS( iProvider->iBackupRestoreObserver != NULL, ETrue ); |
|
249 EUNIT_ASSERT_EQUALS( iProvider->iLightObserver != NULL, ETrue ); |
|
250 |
|
251 iExpectedState = EAiFwUiShutdown; |
|
252 |
|
253 iProvider->Stop(); |
|
254 |
|
255 EUNIT_ASSERT_EQUALS( iProvider->iStarted, EFalse ); |
|
256 EUNIT_ASSERT_EQUALS( iProvider->iCoeEnv == NULL, ETrue ); |
|
257 EUNIT_ASSERT_EQUALS( iProvider->iEcomObserver == NULL, ETrue ); |
|
258 EUNIT_ASSERT_EQUALS( iProvider->iBackupRestoreObserver == NULL, ETrue ); |
|
259 EUNIT_ASSERT_EQUALS( iProvider->iLightObserver == NULL, ETrue ); |
|
260 |
|
261 iExpectedState = (TAiFwState)0; |
|
262 // Should not get any notification because already stopped |
|
263 iProvider->Stop(); |
|
264 |
|
265 EUNIT_ASSERT_EQUALS( iProvider->iStarted, EFalse ); |
|
266 EUNIT_ASSERT_EQUALS( iProvider->iCoeEnv == NULL, ETrue ); |
|
267 EUNIT_ASSERT_EQUALS( iProvider->iEcomObserver == NULL, ETrue ); |
|
268 EUNIT_ASSERT_EQUALS( iProvider->iBackupRestoreObserver == NULL, ETrue ); |
|
269 EUNIT_ASSERT_EQUALS( iProvider->iLightObserver == NULL, ETrue ); |
|
270 } |
|
271 |
|
272 // ---------------------------------------------------------------------------- |
|
273 // UT_AiStateProvider::TestFgBgStateL() |
|
274 // |
|
275 // ---------------------------------------------------------------------------- |
|
276 // |
|
277 void UT_AiStateProvider::TestFgBgStateL() |
|
278 { |
|
279 TWsEvent event; |
|
280 |
|
281 iExpectedState = EAiFwForeground; |
|
282 |
|
283 event.SetType( KAknFullOrPartialForegroundGained ); |
|
284 |
|
285 iProvider->MonitorWsMessage( event ); |
|
286 |
|
287 iExpectedState = EAiFwBackground; |
|
288 |
|
289 event.SetType( KAknFullOrPartialForegroundLost ); |
|
290 |
|
291 iProvider->MonitorWsMessage( event ); |
|
292 |
|
293 event.SetType( 0 ); |
|
294 |
|
295 iProvider->MonitorWsMessage( event ); |
|
296 } |
|
297 |
|
298 // ---------------------------------------------------------------------------- |
|
299 // UT_AiStateProvider::TestLightStateL() |
|
300 // |
|
301 // ---------------------------------------------------------------------------- |
|
302 // |
|
303 void UT_AiStateProvider::TestLightStateL() |
|
304 { |
|
305 iExpectedState = EAiFwBacklightOn; |
|
306 |
|
307 iProvider->LightStatusChanged( |
|
308 CHWRMLight::EPrimaryDisplay, CHWRMLight::ELightOn ); |
|
309 |
|
310 iExpectedState = EAiFwBacklightOff; |
|
311 |
|
312 iProvider->LightStatusChanged( |
|
313 CHWRMLight::EPrimaryDisplay, CHWRMLight::ELightOff ); |
|
314 |
|
315 iProvider->LightStatusChanged( |
|
316 CHWRMLight::EPrimaryDisplay, CHWRMLight::ELightStatusUnknown ); |
|
317 |
|
318 iProvider->LightStatusChanged( |
|
319 CHWRMLight::ENoTarget, CHWRMLight::ELightStatusUnknown ); |
|
320 } |
|
321 |
|
322 // ---------------------------------------------------------------------------- |
|
323 // UT_AiStateProvider::TestSkinChangeL() |
|
324 // |
|
325 // ---------------------------------------------------------------------------- |
|
326 // |
|
327 void UT_AiStateProvider::TestSkinChangeL() |
|
328 { |
|
329 iProvider->SkinContentChanged(); |
|
330 iProvider->SkinPackageChanged( ( TAknsSkinStatusPackageChangeReason) 0 ); |
|
331 |
|
332 iExpectedState = EAiFwGeneralThemeChange; |
|
333 |
|
334 iProvider->SkinConfigurationChanged( |
|
335 EAknsSkinStatusConfigurationDeployed ); |
|
336 |
|
337 iProvider->SkinConfigurationChanged( |
|
338 EAknsSkinStatusConfigurationMerged ); |
|
339 } |
|
340 |
|
341 // ---------------------------------------------------------------------------- |
|
342 // UT_AiStateProvider::TestEcomRegistryChangeL() |
|
343 // |
|
344 // ---------------------------------------------------------------------------- |
|
345 // |
|
346 void UT_AiStateProvider::TestEcomRegistryChangeL() |
|
347 { |
|
348 iPluginsUpdated = EFalse; |
|
349 |
|
350 iProvider->NotifyEcomRegistryChanged(); |
|
351 |
|
352 EUNIT_ASSERT_EQUALS( iPluginsUpdated, ETrue ); |
|
353 } |
|
354 |
|
355 // ---------------------------------------------------------------------------- |
|
356 // UT_AiStateProvider::TestLoadDestroyPluginL() |
|
357 // |
|
358 // ---------------------------------------------------------------------------- |
|
359 // |
|
360 void UT_AiStateProvider::TestLoadDestroyPluginL() |
|
361 { |
|
362 //TODO: ok? |
|
363 THsPublisherInfo hsInfo( TUid::Uid( KUid ), KTestPublisher, KNs ); |
|
364 TAiFwPublisherInfo info( hsInfo, TAiFwCallback(), EAiFwSystemStartup ); |
|
365 |
|
366 iProvider->LoadPlugin( info ); |
|
367 |
|
368 iProvider->DestroyPlugin( info/*, EAiFwSystemShutdown*/ ); |
|
369 } |
|
370 |
|
371 // ---------------------------------------------------------------------------- |
|
372 // UT_AiStateProvider::TestChangePluginStateL() |
|
373 // |
|
374 // ---------------------------------------------------------------------------- |
|
375 // |
|
376 void UT_AiStateProvider::TestChangePluginStateL() |
|
377 { |
|
378 iExpectedState = EAiFwOffline; |
|
379 |
|
380 iProvider->ChangePluginState( EAiFwOffline ); |
|
381 |
|
382 iExpectedState = EAiFwOnline; |
|
383 |
|
384 iProvider->ChangePluginState( EAiFwOnline ); |
|
385 |
|
386 iProvider->ChangePluginState( EAiFwBacklightOn ); |
|
387 iProvider->ChangePluginState( EAiFwBackupRestoreStart ); |
|
388 } |
|
389 |
|
390 // ---------------------------------------------------------------------------- |
|
391 // UT_AiStateProvider::TestBackupRestoreStateChangeL() |
|
392 // |
|
393 // ---------------------------------------------------------------------------- |
|
394 // |
|
395 void UT_AiStateProvider::TestBackupRestoreStateChangeL() |
|
396 { |
|
397 iIgnoreNotifyStateChange = ETrue; |
|
398 |
|
399 EUNIT_ASSERT_EQUALS( |
|
400 CAiStateProvider::BackupRestoreEvent( iProvider ), KErrNone ); |
|
401 } |
|
402 |
|
403 // ---------------------------------------------------------------------------- |
|
404 // UT_AiStateProvider::SwiUidListEventL() |
|
405 // |
|
406 // ---------------------------------------------------------------------------- |
|
407 // |
|
408 void UT_AiStateProvider::SwiUidListEventL() |
|
409 { |
|
410 TInt ret = iProvider->SwiUidListEvent( iProvider ); |
|
411 } |
|
412 |
|
413 //------------------------------------------------------------------------------ |
|
414 // Test case table |
|
415 // |
|
416 //------------------------------------------------------------------------------ |
|
417 // |
|
418 EUNIT_BEGIN_TEST_TABLE( |
|
419 UT_AiStateProvider, |
|
420 "Unit test suite for CAiStateProvider", |
|
421 "UNIT" ) |
|
422 |
|
423 EUNIT_TEST( |
|
424 "Start/Stop provider", |
|
425 "CAiStateProvider", |
|
426 "", |
|
427 "FUNCTIONALITY", |
|
428 SetupL, TestStartStopL, Teardown ) |
|
429 |
|
430 EUNIT_TEST( |
|
431 "Fg/Bg state change", |
|
432 "CAiStateProvider", |
|
433 "", |
|
434 "FUNCTIONALITY", |
|
435 SetupL, TestFgBgStateL, Teardown ) |
|
436 |
|
437 EUNIT_TEST( |
|
438 "Light state change", |
|
439 "CAiStateProvider", |
|
440 "", |
|
441 "FUNCTIONALITY", |
|
442 SetupL, TestLightStateL, Teardown ) |
|
443 |
|
444 EUNIT_TEST( |
|
445 "Skin change", |
|
446 "CAiStateProvider", |
|
447 "", |
|
448 "FUNCTIONALITY", |
|
449 SetupL, TestSkinChangeL, Teardown ) |
|
450 |
|
451 EUNIT_TEST( |
|
452 "Ecom registry change", |
|
453 "CAiStateProvider", |
|
454 "", |
|
455 "FUNCTIONALITY", |
|
456 SetupL, TestEcomRegistryChangeL, Teardown ) |
|
457 |
|
458 EUNIT_TEST( |
|
459 "Load/Destroy plugin", |
|
460 "CAiStateProvider", |
|
461 "", |
|
462 "FUNCTIONALITY", |
|
463 SetupL, TestLoadDestroyPluginL, Teardown ) |
|
464 |
|
465 EUNIT_TEST( |
|
466 "Change plugin state", |
|
467 "CAiStateProvider", |
|
468 "", |
|
469 "FUNCTIONALITY", |
|
470 SetupL, TestChangePluginStateL, Teardown ) |
|
471 |
|
472 EUNIT_TEST( |
|
473 "Backup/Restore state", |
|
474 "CAiStateProvider", |
|
475 "", |
|
476 "FUNCTIONALITY", |
|
477 SetupL, TestBackupRestoreStateChangeL, Teardown ) |
|
478 |
|
479 EUNIT_TEST( |
|
480 "Swi Uid List Event", |
|
481 "CAiStateProvider", |
|
482 "", |
|
483 "FUNCTIONALITY", |
|
484 SetupL, SwiUidListEventL, Teardown ) |
|
485 |
|
486 EUNIT_END_TEST_TABLE |
|
487 |
|
488 // End of file |