|
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 <digia/eunit/eunitmacros.h> |
|
22 #include <digia/eunit/teunitassertioninfo.h> |
|
23 |
|
24 // User includes |
|
25 #include "aifw_stub.h" |
|
26 #include "aiuicontroller_stub.h" |
|
27 |
|
28 #include "ut_aiuicontrollermanager.h" |
|
29 |
|
30 #include "aiuicontrollermanager.h" |
|
31 |
|
32 // Constants |
|
33 |
|
34 |
|
35 // ======== LOCAL FUNCTIONS ======== |
|
36 // ---------------------------------------------------------------------------- |
|
37 // CAiUiControllerStub |
|
38 // |
|
39 // ---------------------------------------------------------------------------- |
|
40 // |
|
41 CAiUiControllerStub* AsCAiUiControllerStub( CAiUiController* aController ) |
|
42 { |
|
43 return static_cast< CAiUiControllerStub* >( aController ); |
|
44 } |
|
45 |
|
46 // ======== MEMBER FUNCTIONS ======= |
|
47 // ---------------------------------------------------------------------------- |
|
48 // UT_AiUiControllerManager::NewL() |
|
49 // |
|
50 // ---------------------------------------------------------------------------- |
|
51 // |
|
52 UT_AiUiControllerManager* UT_AiUiControllerManager::NewL() |
|
53 { |
|
54 UT_AiUiControllerManager* self = UT_AiUiControllerManager::NewLC(); |
|
55 CleanupStack::Pop( self ); |
|
56 return self; |
|
57 } |
|
58 |
|
59 // ---------------------------------------------------------------------------- |
|
60 // UT_AiUiControllerManager::NewLC() |
|
61 // |
|
62 // ---------------------------------------------------------------------------- |
|
63 // |
|
64 UT_AiUiControllerManager* UT_AiUiControllerManager::NewLC() |
|
65 { |
|
66 UT_AiUiControllerManager* self = new ( ELeave ) UT_AiUiControllerManager(); |
|
67 CleanupStack::PushL( self ); |
|
68 self->ConstructL(); |
|
69 return self; |
|
70 } |
|
71 |
|
72 // ---------------------------------------------------------------------------- |
|
73 // UT_AiUiControllerManager::~UT_AiUiControllerManager() |
|
74 // |
|
75 // ---------------------------------------------------------------------------- |
|
76 // |
|
77 UT_AiUiControllerManager::~UT_AiUiControllerManager() |
|
78 { |
|
79 } |
|
80 |
|
81 // ---------------------------------------------------------------------------- |
|
82 // UT_AiUiControllerManager::UT_AiUiControllerManager() |
|
83 // |
|
84 // ---------------------------------------------------------------------------- |
|
85 // |
|
86 UT_AiUiControllerManager::UT_AiUiControllerManager() |
|
87 { |
|
88 } |
|
89 |
|
90 // ---------------------------------------------------------------------------- |
|
91 // UT_AiUiControllerManager::ConstructL() |
|
92 // |
|
93 // ---------------------------------------------------------------------------- |
|
94 // |
|
95 void UT_AiUiControllerManager::ConstructL() |
|
96 { |
|
97 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
98 // It generates the test case table. |
|
99 CEUnitTestSuiteClass::ConstructL(); |
|
100 } |
|
101 |
|
102 // ---------------------------------------------------------------------------- |
|
103 // UT_AiUiControllerManager::SetupL() |
|
104 // |
|
105 // ---------------------------------------------------------------------------- |
|
106 // |
|
107 void UT_AiUiControllerManager::SetupL() |
|
108 { |
|
109 iAiFw = CAiFw::NewL(); |
|
110 |
|
111 iUiMgr = CAiUiControllerManager::NewL( iAiFw ); |
|
112 |
|
113 // Get rid of real UI controllers |
|
114 iUiMgr->UiControllers().ResetAndDestroy(); |
|
115 |
|
116 CAiUiControllerStub* stub1 = CAiUiControllerStub::NewL(); |
|
117 iUiMgr->UiControllers().Append( stub1 ); |
|
118 |
|
119 CAiUiControllerStub* stub2 = CAiUiControllerStub::NewL(); |
|
120 iUiMgr->UiControllers().Append( stub2 ); |
|
121 |
|
122 stub1->iMain = ETrue; |
|
123 iUiMgr->iMainUiController = stub1; |
|
124 } |
|
125 |
|
126 // ---------------------------------------------------------------------------- |
|
127 // UT_AiUiControllerManager::Teardown() |
|
128 // |
|
129 // ---------------------------------------------------------------------------- |
|
130 // |
|
131 void UT_AiUiControllerManager::Teardown() |
|
132 { |
|
133 delete iUiMgr; |
|
134 iUiMgr = NULL; |
|
135 |
|
136 delete iAiFw; |
|
137 iAiFw = NULL; |
|
138 } |
|
139 |
|
140 // ---------------------------------------------------------------------------- |
|
141 // UT_AiUiControllerManager::TestGetUiControllersL() |
|
142 // |
|
143 // ---------------------------------------------------------------------------- |
|
144 // |
|
145 void UT_AiUiControllerManager::TestGetUiControllersL() |
|
146 { |
|
147 EUNIT_ASSERT_EQUALS( iUiMgr->UiControllers().Count() == 2, ETrue ); |
|
148 } |
|
149 |
|
150 // ---------------------------------------------------------------------------- |
|
151 // UT_AiUiControllerManager::TestActivateUIL() |
|
152 // |
|
153 // ---------------------------------------------------------------------------- |
|
154 // |
|
155 void UT_AiUiControllerManager::TestActivateUIL() |
|
156 { |
|
157 for ( TInt i = 0; i < iUiMgr->UiControllers().Count(); i++ ) |
|
158 { |
|
159 CAiUiControllerStub* stub = |
|
160 AsCAiUiControllerStub( iUiMgr->UiControllers()[i] ); |
|
161 |
|
162 EUNIT_ASSERT_EQUALS( stub->iActive, EFalse ); |
|
163 } |
|
164 |
|
165 iUiMgr->ActivateUI(); |
|
166 |
|
167 for ( TInt i = 0; i < iUiMgr->UiControllers().Count(); i++ ) |
|
168 { |
|
169 CAiUiControllerStub* stub = |
|
170 AsCAiUiControllerStub( iUiMgr->UiControllers()[i] ); |
|
171 |
|
172 EUNIT_ASSERT_EQUALS( stub->iActive, ETrue ); |
|
173 } |
|
174 } |
|
175 |
|
176 // ---------------------------------------------------------------------------- |
|
177 // UT_AiUiControllerManager::TestGetMainUiControllerL() |
|
178 // |
|
179 // ---------------------------------------------------------------------------- |
|
180 // |
|
181 void UT_AiUiControllerManager::TestGetMainUiControllerL() |
|
182 { |
|
183 MAiMainUiController* main( &iUiMgr->MainUiController() ); |
|
184 |
|
185 CAiUiControllerStub* stub( NULL ); |
|
186 |
|
187 TInt count( 0 ); |
|
188 |
|
189 for ( TInt i = 0; i < iUiMgr->UiControllers().Count(); i++ ) |
|
190 { |
|
191 CAiUiControllerStub* temp = |
|
192 AsCAiUiControllerStub( iUiMgr->UiControllers()[i] ); |
|
193 |
|
194 if ( temp->iMain ) |
|
195 { |
|
196 stub = temp; |
|
197 count++; |
|
198 } |
|
199 } |
|
200 |
|
201 EUNIT_ASSERT_EQUALS( count, 1 ); |
|
202 EUNIT_ASSERT_EQUALS( stub == main, ETrue ); |
|
203 } |
|
204 |
|
205 // ---------------------------------------------------------------------------- |
|
206 // UT_AiUiControllerManager::TestIsMainUiControllerL() |
|
207 // |
|
208 // ---------------------------------------------------------------------------- |
|
209 // |
|
210 void UT_AiUiControllerManager::TestIsMainUiControllerL() |
|
211 { |
|
212 for ( TInt i = 0; i < iUiMgr->UiControllers().Count(); i++ ) |
|
213 { |
|
214 CAiUiControllerStub* stub = |
|
215 AsCAiUiControllerStub( iUiMgr->UiControllers()[i] ); |
|
216 |
|
217 if ( stub->iMain ) |
|
218 { |
|
219 EUNIT_ASSERT_EQUALS( iUiMgr->IsMainUiController( *stub ), ETrue ); |
|
220 } |
|
221 else |
|
222 { |
|
223 EUNIT_ASSERT_EQUALS( iUiMgr->IsMainUiController( *stub ), EFalse ); |
|
224 } |
|
225 } |
|
226 } |
|
227 |
|
228 // ---------------------------------------------------------------------------- |
|
229 // UT_AiUiControllerManager::TestRunApplicationL() |
|
230 // |
|
231 // ---------------------------------------------------------------------------- |
|
232 // |
|
233 void UT_AiUiControllerManager::TestRunApplicationL() |
|
234 { |
|
235 iUiMgr->RunApplicationL(); |
|
236 |
|
237 TInt count( 0 ); |
|
238 |
|
239 for ( TInt i = 0; i < iUiMgr->UiControllers().Count(); i++ ) |
|
240 { |
|
241 CAiUiControllerStub* stub = |
|
242 AsCAiUiControllerStub( iUiMgr->UiControllers()[i] ); |
|
243 |
|
244 if ( stub->iRunning ) |
|
245 { |
|
246 count++; |
|
247 } |
|
248 } |
|
249 |
|
250 EUNIT_ASSERT_EQUALS( count, 1 ); |
|
251 |
|
252 CAiUiControllerStub* main = |
|
253 static_cast< CAiUiControllerStub* >( &iUiMgr->MainUiController() ); |
|
254 |
|
255 CAiUiControllerStub* running( NULL ); |
|
256 |
|
257 for ( TInt i = 0; i < iUiMgr->UiControllers().Count(); i++ ) |
|
258 { |
|
259 CAiUiControllerStub* stub = |
|
260 AsCAiUiControllerStub( iUiMgr->UiControllers()[i] ); |
|
261 |
|
262 if ( stub->iRunning ) |
|
263 { |
|
264 running = stub; |
|
265 break; |
|
266 } |
|
267 } |
|
268 |
|
269 EUNIT_ASSERT_EQUALS( running != NULL, ETrue ); |
|
270 EUNIT_ASSERT_EQUALS( main != NULL, ETrue ); |
|
271 EUNIT_ASSERT_EQUALS( running == main, ETrue ); |
|
272 } |
|
273 |
|
274 // ---------------------------------------------------------------------------- |
|
275 // UT_AiUiControllerManager::TestLoadUIDefinitionL() |
|
276 // |
|
277 // ---------------------------------------------------------------------------- |
|
278 // |
|
279 void UT_AiUiControllerManager::TestLoadUIDefinitionL() |
|
280 { |
|
281 for ( TInt i = 0; i < iUiMgr->UiControllers().Count(); i++ ) |
|
282 { |
|
283 CAiUiControllerStub* stub = |
|
284 AsCAiUiControllerStub( iUiMgr->UiControllers()[i] ); |
|
285 |
|
286 EUNIT_ASSERT_EQUALS( stub->iUiDefinition, EFalse ); |
|
287 } |
|
288 |
|
289 iUiMgr->LoadUIDefinition(); |
|
290 |
|
291 for ( TInt i = 0; i < iUiMgr->UiControllers().Count(); i++ ) |
|
292 { |
|
293 CAiUiControllerStub* stub = |
|
294 AsCAiUiControllerStub( iUiMgr->UiControllers()[i] ); |
|
295 |
|
296 EUNIT_ASSERT_EQUALS( stub->iUiDefinition, ETrue ); |
|
297 } |
|
298 } |
|
299 |
|
300 // ---------------------------------------------------------------------------- |
|
301 // UT_AiUiControllerManager::TestGetCoeEnvL() |
|
302 // |
|
303 // ---------------------------------------------------------------------------- |
|
304 // |
|
305 void UT_AiUiControllerManager::TestGetCoeEnvL() |
|
306 { |
|
307 CCoeEnv* env( &iUiMgr->CoeEnv() ); |
|
308 |
|
309 EUNIT_ASSERT_EQUALS( env != NULL, ETrue ); |
|
310 } |
|
311 |
|
312 // ---------------------------------------------------------------------------- |
|
313 // UT_AiUiControllerManager::TestDestroySecondaryUiControllersL() |
|
314 // |
|
315 // ---------------------------------------------------------------------------- |
|
316 // |
|
317 void UT_AiUiControllerManager::TestDestroySecondaryUiControllersL() |
|
318 { |
|
319 TInt count( 0 ); |
|
320 |
|
321 for ( TInt i = 0; i < iUiMgr->UiControllers().Count(); i++ ) |
|
322 { |
|
323 CAiUiControllerStub* stub = |
|
324 AsCAiUiControllerStub( iUiMgr->UiControllers()[i] ); |
|
325 |
|
326 if ( !stub->iMain ) |
|
327 { |
|
328 count++; |
|
329 } |
|
330 } |
|
331 |
|
332 EUNIT_ASSERT_EQUALS( count > 0, ETrue ); |
|
333 |
|
334 iUiMgr->DestroySecondaryUiControllers(); |
|
335 |
|
336 count = 0; |
|
337 |
|
338 for ( TInt i = 0; i < iUiMgr->UiControllers().Count(); i++ ) |
|
339 { |
|
340 CAiUiControllerStub* stub = |
|
341 AsCAiUiControllerStub( iUiMgr->UiControllers()[i] ); |
|
342 |
|
343 if ( !stub->iMain ) |
|
344 { |
|
345 count++; |
|
346 } |
|
347 } |
|
348 |
|
349 EUNIT_ASSERT_EQUALS( count == 0, ETrue ); |
|
350 |
|
351 for ( TInt i = 0; i < iUiMgr->UiControllers().Count(); i++ ) |
|
352 { |
|
353 CAiUiControllerStub* stub = |
|
354 AsCAiUiControllerStub( iUiMgr->UiControllers()[i] ); |
|
355 |
|
356 EUNIT_ASSERT_EQUALS( stub->iMain, ETrue ); |
|
357 } |
|
358 } |
|
359 |
|
360 // ---------------------------------------------------------------------------- |
|
361 // UT_AiUiControllerManager::TestExitMainControllerL() |
|
362 // |
|
363 // ---------------------------------------------------------------------------- |
|
364 // |
|
365 void UT_AiUiControllerManager::TestExitMainControllerL() |
|
366 { |
|
367 TInt count( 0 ); |
|
368 |
|
369 for ( TInt i = 0; i < iUiMgr->UiControllers().Count(); i++ ) |
|
370 { |
|
371 CAiUiControllerStub* stub = |
|
372 AsCAiUiControllerStub( iUiMgr->UiControllers()[i] ); |
|
373 |
|
374 if ( stub->iMain ) |
|
375 { |
|
376 count++; |
|
377 |
|
378 EUNIT_ASSERT_EQUALS( stub->iExit, EFalse ); |
|
379 } |
|
380 } |
|
381 |
|
382 EUNIT_ASSERT_EQUALS( count > 0, ETrue ); |
|
383 |
|
384 TInt count2( 0 ); |
|
385 |
|
386 iUiMgr->ExitMainController(); |
|
387 |
|
388 for ( TInt i = 0; i < iUiMgr->UiControllers().Count(); i++ ) |
|
389 { |
|
390 CAiUiControllerStub* stub = |
|
391 AsCAiUiControllerStub( iUiMgr->UiControllers()[i] ); |
|
392 |
|
393 if ( stub->iMain ) |
|
394 { |
|
395 count2++; |
|
396 EUNIT_ASSERT_EQUALS( stub->iExit, ETrue ); |
|
397 } |
|
398 } |
|
399 |
|
400 EUNIT_ASSERT_EQUALS( count == count2, ETrue ); |
|
401 } |
|
402 |
|
403 // ---------------------------------------------------------------------------- |
|
404 // UT_AiUiControllerManager::TestSetStateHandlerL() |
|
405 // |
|
406 // ---------------------------------------------------------------------------- |
|
407 // |
|
408 void UT_AiUiControllerManager::TestSetStateHandlerL() |
|
409 { |
|
410 for ( TInt i = 0; i < iUiMgr->UiControllers().Count(); i++ ) |
|
411 { |
|
412 CAiUiControllerStub* stub = |
|
413 AsCAiUiControllerStub( iUiMgr->UiControllers()[i] ); |
|
414 |
|
415 EUNIT_ASSERT_EQUALS( stub->iStateHandler, EFalse ); |
|
416 } |
|
417 |
|
418 MAiFwStateHandler* handler = reinterpret_cast< MAiFwStateHandler* >( this ); |
|
419 |
|
420 iUiMgr->SetStateHandler( *handler ); |
|
421 |
|
422 for ( TInt i = 0; i < iUiMgr->UiControllers().Count(); i++ ) |
|
423 { |
|
424 CAiUiControllerStub* stub = |
|
425 AsCAiUiControllerStub( iUiMgr->UiControllers()[i] ); |
|
426 |
|
427 EUNIT_ASSERT_EQUALS( stub->iStateHandler, ETrue ); |
|
428 } |
|
429 } |
|
430 |
|
431 //------------------------------------------------------------------------------ |
|
432 // Test case table |
|
433 // |
|
434 //------------------------------------------------------------------------------ |
|
435 // |
|
436 EUNIT_BEGIN_TEST_TABLE( |
|
437 UT_AiUiControllerManager, |
|
438 "Unit test suite for CAiUiControllerManager", |
|
439 "UNIT" ) |
|
440 |
|
441 EUNIT_TEST( |
|
442 "GetUiControllers", |
|
443 "CAiUiControllerManager", |
|
444 "", |
|
445 "FUNCTIONALITY", |
|
446 SetupL, TestGetUiControllersL, Teardown ) |
|
447 |
|
448 EUNIT_TEST( |
|
449 "ActivateUi", |
|
450 "CAiUiControllerManager", |
|
451 "", |
|
452 "FUNCTIONALITY", |
|
453 SetupL, TestActivateUIL, Teardown ) |
|
454 |
|
455 EUNIT_TEST( |
|
456 "GetMainUiController", |
|
457 "CAiUiControllerManager", |
|
458 "", |
|
459 "FUNCTIONALITY", |
|
460 SetupL, TestGetMainUiControllerL, Teardown ) |
|
461 |
|
462 EUNIT_TEST( |
|
463 "IsMainUiController", |
|
464 "CAiUiControllerManager", |
|
465 "", |
|
466 "FUNCTIONALITY", |
|
467 SetupL, TestIsMainUiControllerL, Teardown ) |
|
468 |
|
469 EUNIT_TEST( |
|
470 "RunApplication", |
|
471 "CAiUiControllerManager", |
|
472 "", |
|
473 "FUNCTIONALITY", |
|
474 SetupL, TestRunApplicationL, Teardown ) |
|
475 |
|
476 EUNIT_TEST( |
|
477 "LoadUiDefinition", |
|
478 "CAiUiControllerManager", |
|
479 "", |
|
480 "FUNCTIONALITY", |
|
481 SetupL, TestLoadUIDefinitionL, Teardown ) |
|
482 |
|
483 EUNIT_TEST( |
|
484 "GetCoeEnv", |
|
485 "CAiUiControllerManager", |
|
486 "", |
|
487 "FUNCTIONALITY", |
|
488 SetupL, TestGetCoeEnvL, Teardown ) |
|
489 |
|
490 EUNIT_TEST( |
|
491 "DestroySecondaryUiControllers", |
|
492 "CAiUiControllerManager", |
|
493 "", |
|
494 "FUNCTIONALITY", |
|
495 SetupL, TestDestroySecondaryUiControllersL, Teardown ) |
|
496 |
|
497 EUNIT_TEST( |
|
498 "ExitMainController", |
|
499 "CAiUiControllerManager", |
|
500 "", |
|
501 "FUNCTIONALITY", |
|
502 SetupL, TestExitMainControllerL, Teardown ) |
|
503 |
|
504 EUNIT_TEST( |
|
505 "SetStateHandler", |
|
506 "CAiUiControllerManager", |
|
507 "", |
|
508 "FUNCTIONALITY", |
|
509 SetupL, TestSetStateHandlerL, Teardown ) |
|
510 |
|
511 EUNIT_END_TEST_TABLE |
|
512 |
|
513 // End of file |