|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // System includes |
|
20 #include <e32base.h> |
|
21 #include <e32cmn.h> |
|
22 #include <digia/eunit/eunitmacros.h> |
|
23 #include <digia/eunit/teunitassertioninfo.h> |
|
24 #include <digia/eunit/eunitdecorators.h> |
|
25 |
|
26 // User includes |
|
27 #include "aiwspluginanim.h" |
|
28 |
|
29 #include "animgeneralfunctions_stub.h" |
|
30 #include "numerickeyhandler_stub.h" |
|
31 #include "wsanim_stub.h" |
|
32 #include "testeventhandler_stub.h" |
|
33 |
|
34 #include "ut_aiwspluginanimtls.h" |
|
35 #include "ut_aiwspluginanim.h" |
|
36 |
|
37 // Constants |
|
38 namespace |
|
39 { |
|
40 const TInt KAiWgId = 42; |
|
41 const TInt KTargetWgId = KAiWgId + 1; |
|
42 const TAiWsPluginAnimInitData KWsPluginInitData = |
|
43 { KAiWgId, KTargetWgId }; |
|
44 const TBool KNoFocus = EFalse; |
|
45 } |
|
46 |
|
47 |
|
48 // ======== LOCAL FUNCTIONS ======== |
|
49 |
|
50 // ---------------------------------------------------------------------------- |
|
51 // ResetEvent() |
|
52 // |
|
53 // ---------------------------------------------------------------------------- |
|
54 // |
|
55 void ResetEvent( TRawEvent& aEvent ) |
|
56 { |
|
57 Mem::FillZ( &aEvent, sizeof( TRawEvent ) ); |
|
58 } |
|
59 |
|
60 // ---------------------------------------------------------------------------- |
|
61 // operator==() |
|
62 // |
|
63 // ---------------------------------------------------------------------------- |
|
64 // |
|
65 TBool operator==( const TRawEvent& aLhs, const TRawEvent& aRhs ) |
|
66 { |
|
67 const TUint8* lhs = reinterpret_cast<const TUint8*>( &aLhs ); |
|
68 const TUint8* rhs = reinterpret_cast<const TUint8*>( &aRhs ); |
|
69 return ( Mem::Compare( lhs, sizeof(TRawEvent), rhs, sizeof(TRawEvent) ) == 0 ); |
|
70 } |
|
71 |
|
72 // ======== MEMBER FUNCTIONS ======= |
|
73 // ---------------------------------------------------------------------------- |
|
74 // UT_AiWsPluginAnim::NewL() |
|
75 // |
|
76 // ---------------------------------------------------------------------------- |
|
77 // |
|
78 UT_AiWsPluginAnim* UT_AiWsPluginAnim::NewL() |
|
79 { |
|
80 UT_AiWsPluginAnim* self = UT_AiWsPluginAnim::NewLC(); |
|
81 CleanupStack::Pop(); |
|
82 |
|
83 return self; |
|
84 } |
|
85 |
|
86 // ---------------------------------------------------------------------------- |
|
87 // UT_AiWsPluginAnim::NewLC() |
|
88 // |
|
89 // ---------------------------------------------------------------------------- |
|
90 // |
|
91 UT_AiWsPluginAnim* UT_AiWsPluginAnim::NewLC() |
|
92 { |
|
93 UT_AiWsPluginAnim* self = new( ELeave ) UT_AiWsPluginAnim(); |
|
94 CleanupStack::PushL( self ); |
|
95 |
|
96 self->ConstructL(); |
|
97 |
|
98 return self; |
|
99 } |
|
100 |
|
101 // ---------------------------------------------------------------------------- |
|
102 // UT_AiWsPluginAnim::~UT_AiWsPluginAnim() |
|
103 // |
|
104 // ---------------------------------------------------------------------------- |
|
105 // |
|
106 UT_AiWsPluginAnim::~UT_AiWsPluginAnim() |
|
107 { |
|
108 delete iCAiWsPluginAnim; |
|
109 delete iAnimGeneralFunctions; |
|
110 UT_AiWsPluginAnimTls::Destroy(); |
|
111 } |
|
112 |
|
113 // ---------------------------------------------------------------------------- |
|
114 // UT_AiWsPluginAnim::UT_AiWsPluginAnim() |
|
115 // |
|
116 // ---------------------------------------------------------------------------- |
|
117 // |
|
118 UT_AiWsPluginAnim::UT_AiWsPluginAnim() |
|
119 { |
|
120 } |
|
121 |
|
122 // ---------------------------------------------------------------------------- |
|
123 // UT_AiWsPluginAnim::ConstructL() |
|
124 // |
|
125 // ---------------------------------------------------------------------------- |
|
126 // |
|
127 void UT_AiWsPluginAnim::ConstructL() |
|
128 { |
|
129 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
130 // It generates the test case table. |
|
131 CEUnitTestSuiteClass::ConstructL(); |
|
132 } |
|
133 |
|
134 // ---------------------------------------------------------------------------- |
|
135 // UT_AiWsPluginAnim::EmptySetup() |
|
136 // |
|
137 // ---------------------------------------------------------------------------- |
|
138 // |
|
139 void UT_AiWsPluginAnim::EmptySetup() |
|
140 { |
|
141 } |
|
142 |
|
143 // ---------------------------------------------------------------------------- |
|
144 // UT_AiWsPluginAnim::SetupTlsL() |
|
145 // |
|
146 // ---------------------------------------------------------------------------- |
|
147 // |
|
148 void UT_AiWsPluginAnim::SetupTlsL() |
|
149 { |
|
150 if ( !iTls ) |
|
151 { |
|
152 UT_AiWsPluginAnimTls::CreateL(); |
|
153 iTls = UT_AiWsPluginAnimTls::Instance(); |
|
154 } |
|
155 } |
|
156 |
|
157 // ---------------------------------------------------------------------------- |
|
158 // UT_AiWsPluginAnim::SetupDependenciesL() |
|
159 // |
|
160 // ---------------------------------------------------------------------------- |
|
161 // |
|
162 void UT_AiWsPluginAnim::SetupDependenciesL() |
|
163 { |
|
164 if ( !iAnimGeneralFunctions ) |
|
165 { |
|
166 iAnimGeneralFunctions = CAnimGeneralFunctionsStub::NewL(); |
|
167 } |
|
168 } |
|
169 |
|
170 // ---------------------------------------------------------------------------- |
|
171 // UT_AiWsPluginAnim::SetupTestObjL() |
|
172 // |
|
173 // ---------------------------------------------------------------------------- |
|
174 // |
|
175 void UT_AiWsPluginAnim::SetupTestObjL( TBool aHasFocus ) |
|
176 { |
|
177 CAiWsPluginAnim* obj = new (ELeave) CAiWsPluginAnim; |
|
178 CleanupStack::PushL( obj ); |
|
179 |
|
180 CWsAnim::SetFunctions( *obj, iAnimGeneralFunctions ); |
|
181 obj->ConstructL( const_cast<TAiWsPluginAnimInitData*> |
|
182 (&KWsPluginInitData), aHasFocus ); |
|
183 |
|
184 CleanupStack::Pop( obj ); |
|
185 iCAiWsPluginAnim = obj; |
|
186 } |
|
187 |
|
188 // ---------------------------------------------------------------------------- |
|
189 // UT_AiWsPluginAnim::SetupL() |
|
190 // |
|
191 // ---------------------------------------------------------------------------- |
|
192 // |
|
193 void UT_AiWsPluginAnim::UT_AiWsPluginAnim::SetupL( TBool aHasFocus ) |
|
194 { |
|
195 SetupTlsL(); |
|
196 SetupDependenciesL(); |
|
197 SetupTestObjL( aHasFocus ); |
|
198 } |
|
199 |
|
200 // ---------------------------------------------------------------------------- |
|
201 // UT_AiWsPluginAnim::SetupL() |
|
202 // |
|
203 // ---------------------------------------------------------------------------- |
|
204 // |
|
205 void UT_AiWsPluginAnim::SetupL() |
|
206 { |
|
207 SetupL( KNoFocus ); |
|
208 } |
|
209 |
|
210 // ---------------------------------------------------------------------------- |
|
211 // UT_AiWsPluginAnim::SetupNoSliderL() |
|
212 // |
|
213 // ---------------------------------------------------------------------------- |
|
214 // |
|
215 void UT_AiWsPluginAnim::SetupNoSliderL( TBool aHasFocus ) |
|
216 { |
|
217 SetupTlsL(); |
|
218 iTls->SetFeatureSupportedL( KFeatureIdKeypadNoSlider, ETrue ); |
|
219 SetupDependenciesL(); |
|
220 SetupTestObjL( aHasFocus ); |
|
221 } |
|
222 |
|
223 // ---------------------------------------------------------------------------- |
|
224 // UT_AiWsPluginAnim::SetupNoSliderL() |
|
225 // |
|
226 // ---------------------------------------------------------------------------- |
|
227 // |
|
228 void UT_AiWsPluginAnim::SetupNoSliderL() |
|
229 { |
|
230 SetupNoSliderL( KNoFocus ); |
|
231 } |
|
232 |
|
233 // ---------------------------------------------------------------------------- |
|
234 // UT_AiWsPluginAnim::Teardown() |
|
235 // |
|
236 // ---------------------------------------------------------------------------- |
|
237 // |
|
238 void UT_AiWsPluginAnim::Teardown() |
|
239 { |
|
240 delete iCAiWsPluginAnim; |
|
241 iCAiWsPluginAnim = NULL; |
|
242 |
|
243 delete iAnimGeneralFunctions; |
|
244 iAnimGeneralFunctions = NULL; |
|
245 |
|
246 if ( iTls ) |
|
247 { |
|
248 // Store feature manager ref count for testing in T_ConstructL |
|
249 iFeatMgrCount = iTls->FeatMgrCount(); |
|
250 } |
|
251 |
|
252 UT_AiWsPluginAnimTls::Destroy(); |
|
253 iTls = NULL; |
|
254 } |
|
255 |
|
256 // ---------------------------------------------------------------------------- |
|
257 // UT_AiWsPluginAnim::T_ConstructL() |
|
258 // |
|
259 // ---------------------------------------------------------------------------- |
|
260 // |
|
261 void UT_AiWsPluginAnim::T_ConstructL( TBool aHasFocus ) |
|
262 { |
|
263 // Test that iCAiWsPluginAnim is in the correct state |
|
264 EUNIT_ASSERT_EQUALS( iCAiWsPluginAnim->HasFocus(), aHasFocus ); |
|
265 EUNIT_ASSERT_EQUALS( iCAiWsPluginAnim->Modifiers(), 0 ); |
|
266 |
|
267 // Test that event handlers are initialized to correct state |
|
268 TArray<T_AiWsPlugin::CTestEventHandler*> |
|
269 eventHandlers( iTls->EventHandlers() ); |
|
270 |
|
271 for( TInt i = 0; i < eventHandlers.Count(); ++i ) |
|
272 { |
|
273 T_AiWsPlugin::CTestEventHandler* handler = eventHandlers[i]; |
|
274 EUNIT_ASSERT_EQUALS( handler->Focus(), aHasFocus ); |
|
275 EUNIT_ASSERT( handler->UiState() ); |
|
276 EUNIT_ASSERT_EQUALS( handler->UiState()->HasFocus(), aHasFocus ); |
|
277 EUNIT_ASSERT_EQUALS( handler->UiState()->Modifiers(), 0 ); |
|
278 } |
|
279 |
|
280 // Test that numeric key handler is correctly set up |
|
281 AiWsPlugin::CNumericKeyHandler* numKeyHandler = |
|
282 iTls->FindEventHandler< AiWsPlugin::CNumericKeyHandler >(); |
|
283 |
|
284 EUNIT_ASSERT( numKeyHandler ); |
|
285 EUNIT_ASSERT_EQUALS( numKeyHandler->iTargetWgId, KTargetWgId ); |
|
286 |
|
287 MAnimGeneralFunctionsWindowExtension* ext = |
|
288 static_cast<MAnimGeneralFunctionsWindowExtension*>( |
|
289 iAnimGeneralFunctions->ExtendedInterface |
|
290 ( MAnimGeneralFunctions::EWindowExtensionInterface ) ); |
|
291 |
|
292 EUNIT_ASSERT_EQUALS( numKeyHandler->iWindowExt, ext ); |
|
293 } |
|
294 |
|
295 // ---------------------------------------------------------------------------- |
|
296 // UT_AiWsPluginAnim::T_ConstructL() |
|
297 // |
|
298 // ---------------------------------------------------------------------------- |
|
299 // |
|
300 void UT_AiWsPluginAnim::T_ConstructL() |
|
301 { |
|
302 // Test construction with no focus |
|
303 SetupL( EFalse ); |
|
304 EUNIT_ASSERT_EQUALS( iFeatMgrCount, 0 ); |
|
305 T_ConstructL( EFalse ); |
|
306 Teardown(); |
|
307 SetupNoSliderL( EFalse ); |
|
308 T_ConstructL( EFalse ); |
|
309 Teardown(); |
|
310 EUNIT_ASSERT_EQUALS( iFeatMgrCount, 0 ); |
|
311 |
|
312 // Test construction with focus |
|
313 SetupL( ETrue ); |
|
314 T_ConstructL( ETrue ); |
|
315 Teardown(); |
|
316 EUNIT_ASSERT_EQUALS( iFeatMgrCount, 0 ); |
|
317 SetupNoSliderL( ETrue ); |
|
318 T_ConstructL( ETrue ); |
|
319 Teardown(); |
|
320 EUNIT_ASSERT_EQUALS( iFeatMgrCount, 0 ); |
|
321 } |
|
322 |
|
323 // ---------------------------------------------------------------------------- |
|
324 // UT_AiWsPluginAnim::T_CAiWsPluginAnim_EmptyFunctionsL() |
|
325 // |
|
326 // ---------------------------------------------------------------------------- |
|
327 // |
|
328 void UT_AiWsPluginAnim::T_CAiWsPluginAnim_EmptyFunctionsL() |
|
329 { |
|
330 // Call empty functions to ensure coverage targets are reached |
|
331 TInt result = KErrNotFound; |
|
332 EUNIT_ASSERT_NO_LEAVE( result = iCAiWsPluginAnim->CommandReplyL( 0, NULL ) ); |
|
333 EUNIT_ASSERT_EQUALS( result, KErrNone ); |
|
334 |
|
335 EUNIT_ASSERT_NO_LEAVE( iCAiWsPluginAnim->Command( 0, NULL ) ); |
|
336 |
|
337 EUNIT_ASSERT_NO_LEAVE( iCAiWsPluginAnim->Animate( NULL ) ); |
|
338 |
|
339 EUNIT_ASSERT_NO_LEAVE( iCAiWsPluginAnim->Redraw() ); |
|
340 } |
|
341 |
|
342 // ---------------------------------------------------------------------------- |
|
343 // UT_AiWsPluginAnim::T_CAiWsPluginAnim_FocusChangedL() |
|
344 // |
|
345 // ---------------------------------------------------------------------------- |
|
346 // |
|
347 void UT_AiWsPluginAnim::T_CAiWsPluginAnim_FocusChangedL( TBool aFocus ) |
|
348 { |
|
349 iCAiWsPluginAnim->FocusChanged( aFocus ); |
|
350 |
|
351 EUNIT_ASSERT_EQUALS( iCAiWsPluginAnim->HasFocus(), aFocus ); |
|
352 |
|
353 TArray<T_AiWsPlugin::CTestEventHandler*> |
|
354 eventHandlers( iTls->EventHandlers() ); |
|
355 |
|
356 for ( TInt i = 0; i < eventHandlers.Count(); ++i ) |
|
357 { |
|
358 T_AiWsPlugin::CTestEventHandler* handler = eventHandlers[i]; |
|
359 EUNIT_ASSERT_EQUALS( handler->Focus(), aFocus ); |
|
360 EUNIT_ASSERT( handler->UiState() ); |
|
361 EUNIT_ASSERT_EQUALS( handler->UiState()->HasFocus(), aFocus ); |
|
362 } |
|
363 } |
|
364 |
|
365 // ---------------------------------------------------------------------------- |
|
366 // UT_AiWsPluginAnim::T_CAiWsPluginAnim_FocusChangedL() |
|
367 // |
|
368 // ---------------------------------------------------------------------------- |
|
369 // |
|
370 void UT_AiWsPluginAnim::T_CAiWsPluginAnim_FocusChangedL() |
|
371 { |
|
372 T_CAiWsPluginAnim_FocusChangedL( ETrue ); |
|
373 T_CAiWsPluginAnim_FocusChangedL( EFalse ); |
|
374 T_CAiWsPluginAnim_FocusChangedL( !iCAiWsPluginAnim->HasFocus() ); |
|
375 T_CAiWsPluginAnim_FocusChangedL( !iCAiWsPluginAnim->HasFocus() ); |
|
376 } |
|
377 |
|
378 // ---------------------------------------------------------------------------- |
|
379 // UT_AiWsPluginAnim::TestLastEventsL() |
|
380 // |
|
381 // ---------------------------------------------------------------------------- |
|
382 // |
|
383 void TestLastEventsL( |
|
384 const TArray<T_AiWsPlugin::CTestEventHandler*>& aEventHandlers, |
|
385 const TRawEvent& aRefEvent ) |
|
386 { |
|
387 for( TInt i = 0; i < aEventHandlers.Count(); ++i ) |
|
388 { |
|
389 T_AiWsPlugin::CTestEventHandler* handler = aEventHandlers[i]; |
|
390 EUNIT_ASSERT_EQUALS( handler->LastEvent(), aRefEvent ); |
|
391 handler->ResetLastEvent(); |
|
392 } |
|
393 } |
|
394 |
|
395 // ---------------------------------------------------------------------------- |
|
396 // UT_AiWsPluginAnim::T_CAiWsPluginAnim_OfferRawEventL() |
|
397 // |
|
398 // ---------------------------------------------------------------------------- |
|
399 // |
|
400 void UT_AiWsPluginAnim::T_CAiWsPluginAnim_OfferRawEventL() |
|
401 { |
|
402 TRawEvent nullEvent; |
|
403 ResetEvent( nullEvent ); |
|
404 TRawEvent testEvent( nullEvent ); |
|
405 TArray<T_AiWsPlugin::CTestEventHandler*> eventHandlers( iTls->EventHandlers() ); |
|
406 |
|
407 // Check initial state |
|
408 TestLastEventsL( eventHandlers, nullEvent ); |
|
409 |
|
410 // Test modifier key event |
|
411 testEvent.Set( TRawEvent::EKeyDown, EStdKeyLeftShift ); |
|
412 EUNIT_ASSERT( !iCAiWsPluginAnim->OfferRawEvent( testEvent ) ); |
|
413 // Modifier key events should not be forwarded to event handlers |
|
414 TestLastEventsL( eventHandlers, nullEvent ); |
|
415 testEvent.Set( TRawEvent::EKeyUp, EStdKeyLeftShift ); |
|
416 EUNIT_ASSERT( !iCAiWsPluginAnim->OfferRawEvent( testEvent ) ); |
|
417 // Modifier key events should not be forwarded to event handlers |
|
418 TestLastEventsL( eventHandlers, nullEvent ); |
|
419 |
|
420 // Test non-modifier key event |
|
421 testEvent.Set( TRawEvent::EKeyDown, EStdKeyDevice0 ); |
|
422 EUNIT_ASSERT( !iCAiWsPluginAnim->OfferRawEvent( testEvent ) ); |
|
423 // Non-modifier key events should be forwarded to event handlers |
|
424 TestLastEventsL( eventHandlers, nullEvent ); |
|
425 testEvent.Set( TRawEvent::EKeyUp, EStdKeyDevice0 ); |
|
426 EUNIT_ASSERT( !iCAiWsPluginAnim->OfferRawEvent( testEvent ) ); |
|
427 // Non-modifier key events should be forwarded to event handlers |
|
428 TestLastEventsL( eventHandlers, nullEvent ); |
|
429 |
|
430 // Test event consuming |
|
431 testEvent.Set( TRawEvent::EKeyDown, EStdKeyDevice1 ); |
|
432 // Make the first event handler consume the event |
|
433 eventHandlers[0]->RespondToEvent( testEvent ); |
|
434 // OfferRawEvent should return true because the event is consumed |
|
435 EUNIT_ASSERT( iCAiWsPluginAnim->OfferRawEvent( testEvent ) ); |
|
436 } |
|
437 |
|
438 //------------------------------------------------------------------------------ |
|
439 // Test case table |
|
440 // |
|
441 //------------------------------------------------------------------------------ |
|
442 // |
|
443 EUNIT_BEGIN_TEST_TABLE( |
|
444 UT_AiWsPluginAnim, |
|
445 "Test suite for class CAiWsPluginAnim", |
|
446 "UNIT" ) |
|
447 |
|
448 EUNIT_TEST( |
|
449 "Construction", |
|
450 "CAiWsPluginAnim", |
|
451 "ConstructL", |
|
452 "FUNCTIONALITY", |
|
453 EmptySetup, T_ConstructL, Teardown) |
|
454 |
|
455 EUNIT_TEST( |
|
456 "Test empty pure virtual overloads", |
|
457 "CAiWsPluginAnim", |
|
458 "CommandReplyL - test0", |
|
459 "FUNCTIONALITY", |
|
460 SetupL, T_CAiWsPluginAnim_EmptyFunctionsL, Teardown) |
|
461 |
|
462 EUNIT_TEST( |
|
463 "FocusChanged", |
|
464 "CAiWsPluginAnim", |
|
465 "FocusChanged", |
|
466 "FUNCTIONALITY", |
|
467 SetupL, T_CAiWsPluginAnim_FocusChangedL, Teardown) |
|
468 |
|
469 EUNIT_TEST( |
|
470 "OfferRawEvent", |
|
471 "CAiWsPluginAnim", |
|
472 "OfferRawEvent", |
|
473 "FUNCTIONALITY", |
|
474 SetupL, T_CAiWsPluginAnim_OfferRawEventL, Teardown) |
|
475 |
|
476 EUNIT_END_TEST_TABLE |
|
477 |