|
1 /* |
|
2 * Copyright (c) 2006-2007 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: Test for effect control for the slideshow |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // CLASS HEADER |
|
22 #include "t_cshweffectcontrol.h" |
|
23 |
|
24 // EXTERNAL INCLUDES |
|
25 #include <EUnitMacros.h> |
|
26 #include <EUnitDecorators.h> |
|
27 |
|
28 // INTERNAL INCLUDES |
|
29 #include "shwslideshowenginepanic.h" |
|
30 #include "shweffectcontrol.h" |
|
31 #include "shwevent.h" |
|
32 #include "shwthumbnailcontext.h" |
|
33 #include "shwautoptr.h" |
|
34 |
|
35 #include "stub_tglxlayoutsplitter.h" |
|
36 #include "stub_glxfetchcontexts.h" |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // Stub for NShwEngine::Panic --> |
|
40 // ----------------------------------------------------------------------------- |
|
41 TBool gNShwEnginePanicCalled = EFalse; |
|
42 namespace NShwEngine |
|
43 { |
|
44 extern void Panic( TShwEnginePanic aPanic ) |
|
45 { |
|
46 gNShwEnginePanicCalled = ETrue; |
|
47 // in test situation just do a leave |
|
48 User::Leave( aPanic ); |
|
49 } |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // <-- Stub for NShwEngine::Panic |
|
54 // ----------------------------------------------------------------------------- |
|
55 |
|
56 // CONSTRUCTION |
|
57 T_CShwEffectControl* T_CShwEffectControl::NewL() |
|
58 { |
|
59 T_CShwEffectControl* self = T_CShwEffectControl::NewLC(); |
|
60 CleanupStack::Pop( self ); |
|
61 return self; |
|
62 } |
|
63 |
|
64 T_CShwEffectControl* T_CShwEffectControl::NewLC() |
|
65 { |
|
66 T_CShwEffectControl* self = new( ELeave ) T_CShwEffectControl(); |
|
67 CleanupStack::PushL( self ); |
|
68 |
|
69 self->ConstructL(); |
|
70 |
|
71 return self; |
|
72 } |
|
73 |
|
74 // Destructor (virtual by CBase) |
|
75 T_CShwEffectControl::~T_CShwEffectControl() |
|
76 { |
|
77 } |
|
78 |
|
79 // Default constructor |
|
80 T_CShwEffectControl::T_CShwEffectControl() : |
|
81 iStubEffectManager( this ) |
|
82 { |
|
83 } |
|
84 |
|
85 // Second phase construct |
|
86 void T_CShwEffectControl::ConstructL() |
|
87 { |
|
88 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
89 // It generates the test case table. |
|
90 CEUnitTestSuiteClass::ConstructL(); |
|
91 } |
|
92 |
|
93 // METHODS |
|
94 void T_CShwEffectControl::MGlxMediaList_MethodCalled( TMGlxMediaListMethodId aMethodId ) |
|
95 { |
|
96 // append the methodid in the array |
|
97 TInt error = iMediaListCalls.Append( aMethodId ); |
|
98 // check that append succeeded |
|
99 if( error != KErrNone ) |
|
100 { |
|
101 // critical error, not enough space to append messages |
|
102 User::Panic( _L("T_CShwEffectControl::MGlxMediaList_MethodCalled"), __LINE__ ); |
|
103 } |
|
104 } |
|
105 |
|
106 void T_CShwEffectControl::MGlxVisualList_MethodCalled( TMGlxVisualListMethodId aMethodId ) |
|
107 { |
|
108 // append the methodid in the array |
|
109 TInt error = iVisualListCalls.Append( aMethodId ); |
|
110 // check that append succeeded |
|
111 if( error != KErrNone ) |
|
112 { |
|
113 // critical error, not enough space to append messages |
|
114 User::Panic( _L("TestError:AppendFail"), -1 ); |
|
115 } |
|
116 } |
|
117 |
|
118 void T_CShwEffectControl::MShwEffectManager_MethodCalled( TMShwEffectManagerMethodId aMethodId ) |
|
119 { |
|
120 // append the methodid in the array |
|
121 TInt error = iEffectCalls.Append( aMethodId ); |
|
122 // check that append succeeded |
|
123 if( error != KErrNone ) |
|
124 { |
|
125 // critical error, not enough space to append messages |
|
126 User::Panic( _L("TestError:AppendFail"), -2 ); |
|
127 } |
|
128 } |
|
129 |
|
130 TInt gSendEventLeaveCode = KErrNone; |
|
131 void T_CShwEffectControl::SendEventL( MShwEvent* aEvent ) |
|
132 { |
|
133 // need to clone the event since the caller goes out of scope |
|
134 TInt error = iEvents.Append( aEvent->CloneLC() ); |
|
135 CleanupStack::Pop(); // aEvent->CloneLC() |
|
136 |
|
137 // check that append succeeded |
|
138 if( error != KErrNone ) |
|
139 { |
|
140 // critical error, not enough space to append events |
|
141 User::Panic( _L("T_CShwEffectControl::NotifyL"), __LINE__ ); |
|
142 } |
|
143 User::LeaveIfError( gSendEventLeaveCode ); |
|
144 |
|
145 // stop the scheduler loop if its started |
|
146 if( iWait.IsStarted() ) |
|
147 { |
|
148 iWait.AsyncStop(); |
|
149 } |
|
150 } |
|
151 |
|
152 void T_CShwEffectControl::EmptySetupL() |
|
153 { |
|
154 gNShwEnginePanicCalled = EFalse; // by default no panic was called |
|
155 gSendEventLeaveCode = KErrNone; // by default no leaves in SendEventL |
|
156 // make room for 20 entries on each array |
|
157 iVisualListCalls.ReserveL( 20 ); |
|
158 iMediaListCalls.ReserveL( 20 ); |
|
159 iEffectCalls.ReserveL( 20 ); |
|
160 iEvents.ReserveL( 20 ); |
|
161 |
|
162 iStubVisualList = new( ELeave ) TMGlxVisualList_Adapter( this ); |
|
163 iStubMediaList = new( ELeave ) TMGlxMediaList_Stub( this ); |
|
164 |
|
165 // set the size and focus of the list |
|
166 iStubVisualList->iSize = 3; |
|
167 iStubVisualList->iFocus = 1; |
|
168 iStubMediaList->iCount = 3; |
|
169 iStubMediaList->iFocus = 1; |
|
170 |
|
171 iStubEffectManager.iViewDuration = 0; |
|
172 iStubEffectManager.iTransitionDuration = 0; |
|
173 |
|
174 // reset the visuals of effect stub |
|
175 iStubEffectManager.iPrepareVisual = reinterpret_cast<CHuiVisual*>( KErrNotFound ); |
|
176 iStubEffectManager.iViewVisual = reinterpret_cast<CHuiVisual*>( KErrNotFound ); |
|
177 iStubEffectManager.iTransitionVisual = reinterpret_cast<CHuiVisual*>( KErrNotFound ); |
|
178 |
|
179 // tell the thumbnail stub to add attributes |
|
180 // this tells the thumbnailcontext stub to add entries to the |
|
181 // array which then tell the thumbnail loader that the |
|
182 // thumbnail was not yet loaded |
|
183 gThumbnailContextRequestCount = 1; |
|
184 // by default size is available |
|
185 gTGlxMediaGetDimensions = ETrue; |
|
186 // by default we dont want alloc behavior |
|
187 gFetchContextAllocTest = EFalse; |
|
188 } |
|
189 |
|
190 void T_CShwEffectControl::SetupL() |
|
191 { |
|
192 // reuse the empty version to create the stubs |
|
193 EmptySetupL(); |
|
194 // create the effect control |
|
195 iCShwEffectControl = |
|
196 CShwEffectControl::NewL( |
|
197 iStubEffectManager, *iStubVisualList, *iStubMediaList, TSize( 320, 240 ) ); |
|
198 // set the event queue |
|
199 iCShwEffectControl->SetEventQueue( this ); |
|
200 |
|
201 // perform the second phase of construction |
|
202 TShwEventInitialize initEvent; |
|
203 iCShwEffectControl->NotifyL( &initEvent ); |
|
204 } |
|
205 |
|
206 void T_CShwEffectControl::Teardown() |
|
207 { |
|
208 // delete effect control |
|
209 delete iCShwEffectControl; |
|
210 iCShwEffectControl = NULL; |
|
211 // close the arrays |
|
212 iEffectCalls.Close(); |
|
213 iVisualListCalls.Close(); |
|
214 iMediaListCalls.Close(); |
|
215 // release events |
|
216 for( TInt i=0; i<iEvents.Count(); i++ ) |
|
217 { |
|
218 MShwEvent* event = iEvents[ i ]; |
|
219 delete event; |
|
220 } |
|
221 iEvents.Close(); |
|
222 // release the visual list stub |
|
223 delete iStubVisualList; |
|
224 iStubVisualList = NULL; |
|
225 // delete the media list stub |
|
226 delete iStubMediaList; |
|
227 iStubMediaList = NULL; |
|
228 } |
|
229 |
|
230 void T_CShwEffectControl::TestConstructionL() |
|
231 { |
|
232 // we want alloc behavior |
|
233 gFetchContextAllocTest = ETrue; |
|
234 // reset stub |
|
235 iStubVisualList->iSize = 11; |
|
236 iStubVisualList->iFocus = 10; |
|
237 // reset the state as setup uses splitter |
|
238 gSplitterAddLayoutLCalled = EFalse; |
|
239 gSplitterRemoveLayoutLCalled = EFalse; |
|
240 // create an effect control |
|
241 CShwEffectControl* tmp = |
|
242 CShwEffectControl::NewL( |
|
243 iStubEffectManager, *iStubVisualList, *iStubMediaList, TSize( 320, 240 ) ); |
|
244 // need to put to cleanupstack in case NotifyL leaves |
|
245 CleanupStack::PushL( tmp ); |
|
246 |
|
247 EUNIT_ASSERT_DESC( tmp, "Construction successfull"); |
|
248 |
|
249 EUNIT_ASSERT_EQUALS_DESC( 0, iEffectCalls.Count(), "Effect manager was not called" ); |
|
250 |
|
251 // perform the second phase of construction |
|
252 TShwEventInitialize initEvent; |
|
253 tmp->NotifyL( &initEvent ); |
|
254 |
|
255 // check that the calls made by CShwEffectControl were correct ones |
|
256 EUNIT_ASSERT_EQUALS_DESC( 2, iEffectCalls.Count(), "Effect manager was called 2 times" ); |
|
257 EUNIT_ASSERT_EQUALS_DESC( E_MShwEffect_p_CurrentEffect, iEffectCalls[ 0 ], "current effect was called" ); |
|
258 EUNIT_ASSERT_EQUALS_DESC( E_MGlxLayout_PrepareViewL, iEffectCalls[ 1 ], "current effect was called" ); |
|
259 |
|
260 // test notify again with size not available |
|
261 gTGlxMediaGetDimensions = EFalse; |
|
262 // call notify again |
|
263 tmp->NotifyL( &initEvent ); |
|
264 // check that the calls made by CShwEffectControl were correct ones |
|
265 EUNIT_ASSERT_EQUALS_DESC( 4, iEffectCalls.Count(), "Effect manager was called 4 times" ); |
|
266 EUNIT_ASSERT_EQUALS_DESC( E_MShwEffect_p_CurrentEffect, iEffectCalls[ 2 ], "current effect was called" ); |
|
267 EUNIT_ASSERT_EQUALS_DESC( E_MGlxLayout_PrepareViewL, iEffectCalls[ 3 ], "current effect was called" ); |
|
268 |
|
269 // check splitter usage |
|
270 EUNIT_ASSERT_DESC( !gSplitterAddLayoutLCalled, "layout was not set" ); |
|
271 EUNIT_ASSERT_DESC( !gSplitterRemoveLayoutLCalled, "layout was not removed" ); |
|
272 |
|
273 CleanupStack::PopAndDestroy( tmp ); |
|
274 } |
|
275 |
|
276 void T_CShwEffectControl::TransitionCompletedL() |
|
277 { |
|
278 // reset the state as setup uses splitter |
|
279 gSplitterAddLayoutLCalled = EFalse; |
|
280 gSplitterRemoveLayoutLCalled = EFalse; |
|
281 |
|
282 // call transition completed |
|
283 iCShwEffectControl->SendTransitionReadyL(); |
|
284 |
|
285 // check that we got the correct event |
|
286 EUNIT_ASSERT_DESC( iEvents.Count() > 0, "we got an event"); |
|
287 EUNIT_ASSERT_DESC( |
|
288 dynamic_cast<TShwEventTransitionReady*>( iEvents[ 0 ] ), |
|
289 "event was correct class" ); |
|
290 |
|
291 // check splitter usage |
|
292 EUNIT_ASSERT_DESC( !gSplitterAddLayoutLCalled, "layout was not set" ); |
|
293 EUNIT_ASSERT_DESC( !gSplitterRemoveLayoutLCalled, "layout was not removed" ); |
|
294 } |
|
295 |
|
296 void T_CShwEffectControl::TransitionCompleted2L() |
|
297 { |
|
298 // tell the thumbnail context that the thumbnail is already loaded |
|
299 // so that the thumbnail loader will immediately make the callback |
|
300 gThumbnailContextRequestCount = 0; |
|
301 // tell the medialist stub to notify that we have the first thumbnail loaded |
|
302 iStubMediaList->NotifyAttributesAvailableL( iStubMediaList->iFocus ); |
|
303 |
|
304 // check that we dont have event |
|
305 EUNIT_ASSERT_EQUALS_DESC( 1, iEvents.Count(), "event received"); |
|
306 // check that we got the correct event |
|
307 EUNIT_ASSERT_DESC( |
|
308 dynamic_cast<TShwEventReadyToView*>( iEvents[ 0 ] ), |
|
309 "event was correct class" ); |
|
310 |
|
311 // send the event |
|
312 TShwEventStartTransition trans( 123 ); |
|
313 iCShwEffectControl->NotifyL( &trans ); |
|
314 |
|
315 // start the wait loop |
|
316 iWait.Start(); |
|
317 // check that we got event |
|
318 EUNIT_ASSERT_EQUALS_DESC( 3, iEvents.Count(), "we got an event"); |
|
319 // check that we got the correct events |
|
320 EUNIT_ASSERT_DESC( |
|
321 dynamic_cast<TShwEventReadyToView*>( iEvents[ 1 ] ), |
|
322 "event was correct class" ); |
|
323 EUNIT_ASSERT_DESC( |
|
324 dynamic_cast<TShwEventTransitionReady*>( iEvents[ 2 ] ), |
|
325 "event was correct class" ); |
|
326 } |
|
327 |
|
328 void T_CShwEffectControl::NotifyLL() |
|
329 { |
|
330 TInt initialEffectCalls = iEffectCalls.Count(); |
|
331 TInt initialVisualCalls = iVisualListCalls.Count(); |
|
332 |
|
333 // reset the state as setup uses splitter |
|
334 gSplitterAddLayoutLCalled = EFalse; |
|
335 gSplitterRemoveLayoutLCalled = EFalse; |
|
336 // reset the visuals |
|
337 iStubEffectManager.iPrepareVisual = reinterpret_cast<CHuiVisual*>( KErrNotFound ); |
|
338 iStubEffectManager.iViewVisual = reinterpret_cast<CHuiVisual*>( KErrNotFound ); |
|
339 iStubEffectManager.iTransitionVisual = reinterpret_cast<CHuiVisual*>( KErrNotFound ); |
|
340 |
|
341 // test not supported event path |
|
342 iCShwEffectControl->NotifyL( NULL ); |
|
343 |
|
344 // check that there was no new calls made by CShwEffectControl to visual list or effect manager |
|
345 EUNIT_ASSERT_EQUALS_DESC( initialEffectCalls, iEffectCalls.Count(), "Effect manager was not called" ); |
|
346 EUNIT_ASSERT_EQUALS_DESC( initialVisualCalls, iVisualListCalls.Count(), "Visual list was not called" ); |
|
347 |
|
348 // test if( viewEvent ) |
|
349 |
|
350 // tell the stub context that a request is complete |
|
351 gThumbnailContextRequestCount = KErrNone; |
|
352 // tell the media list stub to notify that thumbnail in focus is loaded |
|
353 iStubMediaList->NotifyAttributesAvailableL( iStubMediaList->iFocus ); |
|
354 |
|
355 // check that we got the event |
|
356 EUNIT_ASSERT_EQUALS_DESC( 1, iEvents.Count(), "we got an event"); |
|
357 // this was the first time the event was received so we get init complete event |
|
358 EUNIT_ASSERT_DESC( |
|
359 dynamic_cast< TShwEventReadyToView* >( iEvents[ 0 ] ), |
|
360 "TShwEventReadyToView received" ); |
|
361 |
|
362 // tell the stub context that its request is complete, at this point there is no |
|
363 // context so we only test that thumbnail context works without one |
|
364 gThumbnailContextRequestCount = KErrNone; |
|
365 // tell the media list stub to notify that next thumbnail is loaded |
|
366 // remember the modulo |
|
367 iStubMediaList->NotifyAttributesAvailableL( |
|
368 ( iStubMediaList->iFocus + 1 )%iStubMediaList->iCount ); |
|
369 |
|
370 // if( view_event ) : true |
|
371 // if( iLoopStarted ) : false |
|
372 TShwEventStartView start( 999 ); |
|
373 iCShwEffectControl->NotifyL( &start ); |
|
374 |
|
375 // thumbnail notify is always asynchronous so first check we did not yet get the event |
|
376 EUNIT_ASSERT_EQUALS_DESC( 1, iEvents.Count(), "we got only previous event"); |
|
377 // start async wait |
|
378 iWait.Start(); |
|
379 |
|
380 // check that we got view ready event |
|
381 EUNIT_ASSERT_EQUALS_DESC( 2, iEvents.Count(), "we got an event"); |
|
382 EUNIT_ASSERT_DESC( dynamic_cast<TShwEventReadyToAdvance*>( iEvents[ 1 ] ), "TShwEventReadyToAdvance received" ); |
|
383 |
|
384 // check the visual given to effect |
|
385 EUNIT_ASSERT_EQUALS_DESC( (TInt)iStubEffectManager.iPrepareVisual, 2, "prepare was given visual 2 (focus is on 1)" ); |
|
386 EUNIT_ASSERT_EQUALS_DESC( (TInt)iStubEffectManager.iViewVisual, 1, "view was given visual 1 (focus is on 1)" ); |
|
387 EUNIT_ASSERT_EQUALS_DESC( (TInt)iStubEffectManager.iTransitionVisual, KErrNotFound, "transition was not given visual" ); |
|
388 // check splitter usage |
|
389 EUNIT_ASSERT_DESC( gSplitterAddLayoutLCalled, "layout was set (view layout)" ); |
|
390 EUNIT_ASSERT_DESC( gSplitterRemoveLayoutLCalled, "layout was removed (old view layout)" ); |
|
391 |
|
392 // test path: |
|
393 EUNIT_PRINT( _L("if( view_event ) : false") ); |
|
394 EUNIT_PRINT( _L("else if( trans_event ) : true") ); |
|
395 // if( view_event ) : false |
|
396 // else if( trans_event ) : true |
|
397 TInt effectCalls = iEffectCalls.Count(); |
|
398 TInt visualCalls = iVisualListCalls.Count(); |
|
399 // reset the visuals |
|
400 iStubEffectManager.iPrepareVisual = reinterpret_cast<CHuiVisual*>( KErrNotFound ); |
|
401 iStubEffectManager.iViewVisual = reinterpret_cast<CHuiVisual*>( KErrNotFound ); |
|
402 iStubEffectManager.iTransitionVisual = reinterpret_cast<CHuiVisual*>( KErrNotFound ); |
|
403 // send the event |
|
404 TShwEventStartTransition trans( 666 ); |
|
405 iCShwEffectControl->NotifyL( &trans ); |
|
406 // check that view duration was stored from view event |
|
407 EUNIT_ASSERT_EQUALS_DESC( 999, iStubEffectManager.iViewDuration, "view duration is set correctly" ); |
|
408 // check that transition duration was given as parameter |
|
409 EUNIT_ASSERT_EQUALS_DESC( 666, iStubEffectManager.iTransitionDuration, "transition duration is set correctly" ); |
|
410 // check the visual given to effect |
|
411 EUNIT_ASSERT_EQUALS_DESC( (TInt)iStubEffectManager.iPrepareVisual, KErrNotFound, "prepare was not given visual" ); |
|
412 EUNIT_ASSERT_EQUALS_DESC( (TInt)iStubEffectManager.iViewVisual, 2, "view was given visual 2 (focus is on 2)" ); |
|
413 EUNIT_ASSERT_EQUALS_DESC( (TInt)iStubEffectManager.iTransitionVisual, 1, "transition was given visual 1 (focus is on 1)" ); |
|
414 // check splitter usage |
|
415 EUNIT_ASSERT_DESC( gSplitterAddLayoutLCalled, "layout was set" ); |
|
416 EUNIT_ASSERT_DESC( gSplitterRemoveLayoutLCalled, "layout was removed" ); |
|
417 |
|
418 // test path: |
|
419 EUNIT_PRINT( _L("if( view_event ) : true") ); |
|
420 EUNIT_PRINT( _L("if( iLoopStarted ) : true") ); |
|
421 EUNIT_PRINT( _L("else if( trans_event ) : false") ); |
|
422 // if( view_event ) : true |
|
423 // if( iLoopStarted ) : true |
|
424 // reset the state of splitter stub |
|
425 gSplitterAddLayoutLCalled = EFalse; |
|
426 gSplitterRemoveLayoutLCalled = EFalse; |
|
427 effectCalls = iEffectCalls.Count(); |
|
428 visualCalls = iVisualListCalls.Count(); |
|
429 // reset the visuals |
|
430 iStubEffectManager.iPrepareVisual = reinterpret_cast<CHuiVisual*>( KErrNotFound ); |
|
431 iStubEffectManager.iViewVisual = reinterpret_cast<CHuiVisual*>( KErrNotFound ); |
|
432 iStubEffectManager.iTransitionVisual = reinterpret_cast<CHuiVisual*>( KErrNotFound ); |
|
433 // move focus to 2 |
|
434 iStubVisualList->iFocus = 2; |
|
435 iStubMediaList->iFocus = 2; |
|
436 |
|
437 // tell the stub context that its request is complete |
|
438 gThumbnailContextRequestCount = KErrNone; |
|
439 // tell the media list stub to notify that thumbnail is loaded |
|
440 // remember the modulo |
|
441 iStubMediaList->NotifyAttributesAvailableL( |
|
442 ( iStubMediaList->iFocus + 1 )%iStubMediaList->iCount ); |
|
443 |
|
444 // send the event |
|
445 TShwEventStartView start2( 123 ); |
|
446 iCShwEffectControl->NotifyL( &start2 ); |
|
447 |
|
448 // check we got the ready to view event |
|
449 EUNIT_ASSERT_EQUALS_DESC( 3, iEvents.Count(), "we got ready to view"); |
|
450 EUNIT_ASSERT_DESC( dynamic_cast<TShwEventReadyToView*>( iEvents[ 2 ] ), "TShwEventReadyToView received" ); |
|
451 // start async wait |
|
452 iWait.Start(); |
|
453 |
|
454 // check that view duration was not set |
|
455 EUNIT_ASSERT_EQUALS_DESC( 999, iStubEffectManager.iViewDuration, "view duration is same as last, see above" ); |
|
456 // check the visual given to effect |
|
457 EUNIT_ASSERT_EQUALS_DESC( (TInt)iStubEffectManager.iPrepareVisual, 0, "prepare view was given visual 0 (focus is on 2, size is 3)" ); |
|
458 EUNIT_ASSERT_EQUALS_DESC( (TInt)iStubEffectManager.iViewVisual, KErrNotFound, "view was not given visual" ); |
|
459 EUNIT_ASSERT_EQUALS_DESC( (TInt)iStubEffectManager.iTransitionVisual, 1, "exit transition was given visual 1 (focus is on 2)" ); |
|
460 // check that we got view ready event |
|
461 EUNIT_ASSERT_EQUALS_DESC( 4, iEvents.Count(), "event received" ); |
|
462 EUNIT_ASSERT_DESC( dynamic_cast<TShwEventReadyToAdvance*>( iEvents[ 3 ] ), "TShwEventReadyToAdvance received" ); |
|
463 |
|
464 // check splitter usage |
|
465 EUNIT_ASSERT_DESC( !gSplitterAddLayoutLCalled, "layout was not set" ); |
|
466 EUNIT_ASSERT_DESC( gSplitterRemoveLayoutLCalled, "layout was removed" ); |
|
467 } |
|
468 |
|
469 void T_CShwEffectControl::SlowImageLoadL() |
|
470 { |
|
471 // test path: |
|
472 EUNIT_PRINT( _L("if( view_event ) : true") ); |
|
473 EUNIT_PRINT( _L("if( iLoopStarted ) : false") ); |
|
474 EUNIT_PRINT( _L("else if( trans_event ) : false") ); |
|
475 |
|
476 // tell the stub context that its request is complete |
|
477 gThumbnailContextRequestCount = KErrNone; |
|
478 // tell the media list stub to notify that thumbnail in focus is loaded |
|
479 iStubMediaList->NotifyAttributesAvailableL( iStubMediaList->iFocus ); |
|
480 |
|
481 // check that we got the event |
|
482 EUNIT_ASSERT_EQUALS_DESC( 1, iEvents.Count(), "we got an event"); |
|
483 // this was the first time the event was received so we get init complete event |
|
484 EUNIT_ASSERT_DESC( |
|
485 dynamic_cast< TShwEventReadyToView* >( iEvents[ 0 ] ), |
|
486 "TShwEventReadyToView received" ); |
|
487 |
|
488 // tell the stub context that its request is not complete |
|
489 gThumbnailContextRequestCount = 1; |
|
490 |
|
491 // if( view_event ) : true |
|
492 // if( iLoopStarted ) : false |
|
493 TShwEventStartView start( 999 ); |
|
494 iCShwEffectControl->NotifyL( &start ); |
|
495 // variable iLoopStarted is initialized as false so we dont go through the loop |
|
496 // check that we got view ready event |
|
497 EUNIT_ASSERT_EQUALS_DESC( 1, iEvents.Count(), "new event not received" ); |
|
498 |
|
499 // tell the stub context that its request is complete |
|
500 gThumbnailContextRequestCount = KErrNone; |
|
501 // tell the media list stub to notify that thumbnail is loaded |
|
502 // remember the modulo |
|
503 iStubMediaList->NotifyAttributesAvailableL( |
|
504 ( iStubMediaList->iFocus + 1 )%iStubMediaList->iCount ); |
|
505 |
|
506 EUNIT_ASSERT_EQUALS_DESC( 2, iEvents.Count(), "we got an event"); |
|
507 EUNIT_ASSERT_DESC( dynamic_cast<TShwEventReadyToAdvance*>( iEvents[ 1 ] ), "TShwEventReadyToAdvance received" ); |
|
508 } |
|
509 |
|
510 void T_CShwEffectControl::SlowImageLoad2L() |
|
511 { |
|
512 // set the size and focus of the list |
|
513 iStubVisualList->iSize = 10; |
|
514 iStubVisualList->iFocus = 1; |
|
515 iStubMediaList->iCount = 10; |
|
516 iStubMediaList->iFocus = 1; |
|
517 // test path: |
|
518 EUNIT_PRINT( _L("if( view_event ) : true") ); |
|
519 EUNIT_PRINT( _L("if( iLoopStarted ) : false") ); |
|
520 EUNIT_PRINT( _L("else if( trans_event ) : false") ); |
|
521 |
|
522 // tell the stub context that its request is complete |
|
523 gThumbnailContextRequestCount = KErrNone; |
|
524 // tell the media list stub to notify that thumbnail in focus is loaded |
|
525 iStubMediaList->NotifyAttributesAvailableL( iStubMediaList->iFocus ); |
|
526 |
|
527 // check that we got the event |
|
528 EUNIT_ASSERT_EQUALS_DESC( 1, iEvents.Count(), "we got an event"); |
|
529 // this was the first time the event was received so we get init complete event |
|
530 EUNIT_ASSERT_DESC( |
|
531 dynamic_cast< TShwEventReadyToView* >( iEvents[ 0 ] ), |
|
532 "TShwEventReadyToView received" ); |
|
533 |
|
534 // tell the stub context that its request is not complete |
|
535 gThumbnailContextRequestCount = 1; |
|
536 |
|
537 // if( view_event ) : true |
|
538 // if( iLoopStarted ) : false |
|
539 TShwEventStartView start( 999 ); |
|
540 iCShwEffectControl->NotifyL( &start ); |
|
541 // variable iLoopStarted is initialized as false so we dont go through the loop |
|
542 // check that we got view ready event |
|
543 EUNIT_ASSERT_EQUALS_DESC( 1, iEvents.Count(), "new event not received" ); |
|
544 |
|
545 // tell the stub context that its request is complete |
|
546 gThumbnailContextRequestCount = KErrNone; |
|
547 // tell the media list stub to notify that thumbnail is loaded |
|
548 // remember the modulo |
|
549 iStubMediaList->NotifyAttributesAvailableL( |
|
550 ( iStubMediaList->iFocus + 3 )%iStubMediaList->iCount ); |
|
551 EUNIT_ASSERT_EQUALS_DESC( 1, iEvents.Count(), "new event not received" ); |
|
552 |
|
553 // tell the media list stub to notify that thumbnail is loaded |
|
554 // remember the modulo |
|
555 iStubMediaList->NotifyAttributesAvailableL( |
|
556 ( iStubMediaList->iFocus + 2 )%iStubMediaList->iCount ); |
|
557 EUNIT_ASSERT_EQUALS_DESC( 1, iEvents.Count(), "new event not received" ); |
|
558 |
|
559 // tell the stub context that its request is not complete |
|
560 gThumbnailContextRequestCount = 1; |
|
561 // tell the media list stub to notify that thumbnail is loaded |
|
562 // remember the modulo |
|
563 iStubMediaList->NotifyAttributesAvailableL( |
|
564 ( iStubMediaList->iFocus + 1 )%iStubMediaList->iCount ); |
|
565 EUNIT_ASSERT_EQUALS_DESC( 1, iEvents.Count(), "new event not received" ); |
|
566 |
|
567 // tell the stub context that its request is complete |
|
568 gThumbnailContextRequestCount = KErrNone; |
|
569 iStubMediaList->NotifyAttributesAvailableL( |
|
570 ( iStubMediaList->iFocus + 1 )%iStubMediaList->iCount ); |
|
571 EUNIT_ASSERT_EQUALS_DESC( 2, iEvents.Count(), "event received" ); |
|
572 // this was second time the event was received so we get view complete event |
|
573 EUNIT_ASSERT_DESC( |
|
574 dynamic_cast<TShwEventReadyToAdvance*>( iEvents[ 1 ] ), |
|
575 "TShwEventViewReady received" ); |
|
576 } |
|
577 |
|
578 void T_CShwEffectControl::HandleFocusChangedL() |
|
579 { |
|
580 TInt initialVisualListCalls = iVisualListCalls.Count(); |
|
581 iCShwEffectControl->HandleFocusChangedL( 0, 0, NULL, NGlxListDefs::EUnknown ); |
|
582 EUNIT_ASSERT_NOT_EQUALS_DESC( |
|
583 initialVisualListCalls, iVisualListCalls.Count(), "Visual list was called" ); |
|
584 } |
|
585 |
|
586 void T_CShwEffectControl::TestThumbnailLoadingL() |
|
587 { |
|
588 // create shw thumbnail context for index 1 and size 100,100 |
|
589 const TInt thumbIndex = 1; |
|
590 CShwThumbnailContext* context = CShwThumbnailContext::NewLC(thumbIndex, |
|
591 TSize(100, 100), iStubMediaList); |
|
592 |
|
593 // test that the index is returned |
|
594 // set iterator to first |
|
595 context->SetToFirst(iStubMediaList); |
|
596 // then iterate once |
|
597 TInt index = (*context)++; |
|
598 EUNIT_ASSERT_EQUALS_DESC(thumbIndex, index, "check first iterated index"); |
|
599 |
|
600 index = (*context)++; |
|
601 EUNIT_ASSERT_EQUALS_DESC( KErrNotFound, index, "next index is KErrNotFound" ); |
|
602 |
|
603 // check range |
|
604 EUNIT_ASSERT_DESC( !context->InRange( thumbIndex-1 ), "thumbIndex-1 is not in range" ); |
|
605 EUNIT_ASSERT_DESC( !context->InRange( thumbIndex+1 ), "thumbIndex+1 is not in range" ); |
|
606 EUNIT_ASSERT_DESC( context->InRange( thumbIndex ), "thumbIndex is in range" ); |
|
607 |
|
608 CleanupStack::PopAndDestroy(context); |
|
609 } |
|
610 |
|
611 void T_CShwEffectControl::TestErrorsInThumbnailLoadingL() |
|
612 { |
|
613 // set the size and focus of the list |
|
614 iStubVisualList->iSize = 10; |
|
615 iStubVisualList->iFocus = 1; |
|
616 iStubMediaList->iCount = 10; |
|
617 iStubMediaList->iFocus = 1; |
|
618 // first test that first thumbnail does not load |
|
619 // tell the stub context that its request has error |
|
620 gThumbnailContextRequestCount = KErrCorrupt; |
|
621 { |
|
622 // create an effect control, no need to delete or cleanupstack |
|
623 TShwAutoPtr< CShwEffectControl > tmp = |
|
624 CShwEffectControl::NewL( |
|
625 iStubEffectManager, *iStubVisualList, *iStubMediaList, TSize( 320, 240 ) ); |
|
626 // need to set the event queue |
|
627 tmp->SetEventQueue( this ); |
|
628 // perform the second phase of construction |
|
629 TShwEventInitialize initEvent; |
|
630 tmp->NotifyL( &initEvent ); |
|
631 |
|
632 // check that we did not get an event |
|
633 EUNIT_ASSERT_EQUALS_DESC( 0, iEvents.Count(), "we did not yet get an event"); |
|
634 |
|
635 // start async wait loop |
|
636 iWait.Start(); |
|
637 |
|
638 // check that we got the event |
|
639 EUNIT_ASSERT_EQUALS_DESC( 1, iEvents.Count(), "we got an event"); |
|
640 // this was the first time the event was received so we get init complete event |
|
641 EUNIT_ASSERT_DESC( |
|
642 dynamic_cast< TShwEventReadyToView* >( iEvents[ 0 ] ), |
|
643 "TShwEventReadyToView received" ); |
|
644 // delete and remove the event |
|
645 delete iEvents[ 0 ]; |
|
646 iEvents.Remove( 0 ); |
|
647 // tmp gets deleted here, EUnit checks for memory |
|
648 } |
|
649 |
|
650 // test that second thumbnail does not load |
|
651 // tell the stub context that its request is not yet completed |
|
652 gThumbnailContextRequestCount = 1; |
|
653 { |
|
654 // create an effect control, no need to delete or cleanupstack |
|
655 TShwAutoPtr< CShwEffectControl > tmp = |
|
656 CShwEffectControl::NewL( |
|
657 iStubEffectManager, *iStubVisualList, *iStubMediaList, TSize( 320, 240 ) ); |
|
658 // need to set the event queue |
|
659 tmp->SetEventQueue( this ); |
|
660 // perform the second phase of construction |
|
661 TShwEventInitialize initEvent; |
|
662 tmp->NotifyL( &initEvent ); |
|
663 // check that we did not get an event |
|
664 EUNIT_ASSERT_EQUALS_DESC( 0, iEvents.Count(), "we did not yet get new event"); |
|
665 |
|
666 // tell the stub context that the request has error |
|
667 gThumbnailContextRequestCount = KErrCorrupt; |
|
668 // tell the media list stub to notify that first thumbnail is loaded |
|
669 iStubMediaList->NotifyAttributesAvailableL( iStubMediaList->iFocus ); |
|
670 |
|
671 // check that we got the event |
|
672 EUNIT_ASSERT_EQUALS_DESC( 1, iEvents.Count(), "we got an event"); |
|
673 // this was the first time the event was received so we get init complete event |
|
674 EUNIT_ASSERT_DESC( |
|
675 dynamic_cast< TShwEventReadyToView* >( iEvents[ 0 ] ), |
|
676 "TShwEventReadyToView received" ); |
|
677 // delete and remove the event |
|
678 delete iEvents[ 0 ]; |
|
679 iEvents.Remove( 0 ); |
|
680 // tmp gets deleted here, EUnit checks for memory |
|
681 } |
|
682 |
|
683 // test HandleError call before first thumbnail |
|
684 // tell the stub context that its request is not yet completed |
|
685 gThumbnailContextRequestCount = 1; |
|
686 { |
|
687 // create an effect control, no need to delete or cleanupstack |
|
688 TShwAutoPtr< CShwEffectControl > tmp = |
|
689 CShwEffectControl::NewL( |
|
690 iStubEffectManager, *iStubVisualList, *iStubMediaList, TSize( 320, 240 ) ); |
|
691 // need to set the event queue |
|
692 tmp->SetEventQueue( this ); |
|
693 // perform the second phase of construction |
|
694 TShwEventInitialize initEvent; |
|
695 tmp->NotifyL( &initEvent ); |
|
696 // check that we did not get an event |
|
697 EUNIT_ASSERT_EQUALS_DESC( 0, iEvents.Count(), "we did not yet get new event"); |
|
698 |
|
699 // tell the stub context that the request has error |
|
700 gThumbnailContextRequestCount = KErrCorrupt; |
|
701 // tell the media list stub to notify that there was an error |
|
702 iStubMediaList->NotifyError( KErrNoMemory ); |
|
703 |
|
704 // start async wait loop |
|
705 iWait.Start(); |
|
706 |
|
707 // check that we got the event |
|
708 EUNIT_ASSERT_EQUALS_DESC( 1, iEvents.Count(), "we got an event"); |
|
709 // this was the first time the event was received so we get init complete event |
|
710 EUNIT_ASSERT_DESC( |
|
711 dynamic_cast< TShwEventReadyToView* >( iEvents[ 0 ] ), |
|
712 "TShwEventReadyToView received" ); |
|
713 // delete and remove the event |
|
714 delete iEvents[ 0 ]; |
|
715 iEvents.Remove( 0 ); |
|
716 // tmp gets deleted here, EUnit checks for memory |
|
717 } |
|
718 |
|
719 // test HandleError call after first thumbnail |
|
720 // tell the stub context that its request is completed |
|
721 gThumbnailContextRequestCount = KErrNone; |
|
722 { |
|
723 // create an effect control, no need to delete or cleanupstack |
|
724 TShwAutoPtr< CShwEffectControl > tmp = |
|
725 CShwEffectControl::NewL( |
|
726 iStubEffectManager, *iStubVisualList, *iStubMediaList, TSize( 320, 240 ) ); |
|
727 // need to set the event queue |
|
728 tmp->SetEventQueue( this ); |
|
729 // perform the second phase of construction |
|
730 TShwEventInitialize initEvent; |
|
731 tmp->NotifyL( &initEvent ); |
|
732 // check that we did not get an event |
|
733 EUNIT_ASSERT_EQUALS_DESC( 0, iEvents.Count(), "we did not yet get new event"); |
|
734 |
|
735 // start async wait loop |
|
736 iWait.Start(); |
|
737 |
|
738 // check that we got the event |
|
739 EUNIT_ASSERT_EQUALS_DESC( 1, iEvents.Count(), "we got an event"); |
|
740 // this was the first time the event was received so we get init complete event |
|
741 EUNIT_ASSERT_DESC( |
|
742 dynamic_cast< TShwEventReadyToView* >( iEvents[ 0 ] ), |
|
743 "TShwEventReadyToView received" ); |
|
744 // delete and remove the event |
|
745 delete iEvents[ 0 ]; |
|
746 iEvents.Remove( 0 ); |
|
747 |
|
748 // tell the stub context that its request is not yet completed |
|
749 gThumbnailContextRequestCount = 1; |
|
750 // send start view |
|
751 TShwEventStartView startView( 123 ); |
|
752 tmp->NotifyL( &startView ); |
|
753 |
|
754 // tell the stub context that the request has error |
|
755 gThumbnailContextRequestCount = KErrCorrupt; |
|
756 // tell the media list stub to notify that there was an error |
|
757 iStubMediaList->NotifyError( KErrNoMemory ); |
|
758 |
|
759 // start async wait loop |
|
760 iWait.Start(); |
|
761 |
|
762 // check that we got the event |
|
763 EUNIT_ASSERT_EQUALS_DESC( 1, iEvents.Count(), "we got an event"); |
|
764 // this was the first time the event was received so we get init complete event |
|
765 EUNIT_ASSERT_DESC( |
|
766 dynamic_cast< TShwEventReadyToAdvance* >( iEvents[ 0 ] ), |
|
767 "TShwEventReadyToView received" ); |
|
768 // delete and remove the event |
|
769 delete iEvents[ 0 ]; |
|
770 iEvents.Remove( 0 ); |
|
771 // tmp gets deleted here, EUnit checks for memory |
|
772 } |
|
773 |
|
774 // test HandleItemRemovedL call |
|
775 // tell the stub context that its request is not completed |
|
776 gThumbnailContextRequestCount = KErrNone; |
|
777 { |
|
778 // create an effect control, no need to delete or cleanupstack |
|
779 TShwAutoPtr< CShwEffectControl > tmp = |
|
780 CShwEffectControl::NewL( |
|
781 iStubEffectManager, *iStubVisualList, *iStubMediaList, TSize( 320, 240 ) ); |
|
782 // need to set the event queue |
|
783 tmp->SetEventQueue( this ); |
|
784 // perform the second phase of construction |
|
785 TShwEventInitialize initEvent; |
|
786 tmp->NotifyL( &initEvent ); |
|
787 // check that we did not get an event |
|
788 EUNIT_ASSERT_EQUALS_DESC( 0, iEvents.Count(), "we did not yet get new event"); |
|
789 |
|
790 // start async wait loop |
|
791 iWait.Start(); |
|
792 |
|
793 // check that we got the event |
|
794 EUNIT_ASSERT_EQUALS_DESC( 1, iEvents.Count(), "we got an event"); |
|
795 // this was the first time the event was received so we get init complete event |
|
796 EUNIT_ASSERT_DESC( |
|
797 dynamic_cast< TShwEventReadyToView* >( iEvents[ 0 ] ), |
|
798 "TShwEventReadyToView received" ); |
|
799 // delete and remove the event |
|
800 delete iEvents[ 0 ]; |
|
801 iEvents.Remove( 0 ); |
|
802 |
|
803 // tell medialist stub to call HandleItemRemovedL |
|
804 iStubMediaList->NotifyItemRemoved( 0, 1 ); |
|
805 // this time the list was not empty so nothing done |
|
806 // check that we got no event |
|
807 EUNIT_ASSERT_EQUALS_DESC( 0, iEvents.Count(), "we got no event"); |
|
808 // remove items from stub medialist |
|
809 iStubMediaList->iCount = 0; |
|
810 // tell medialist stub to call HandleItemRemovedL |
|
811 iStubMediaList->NotifyItemRemoved( 0, 1 ); |
|
812 |
|
813 // check that we got the event |
|
814 EUNIT_ASSERT_EQUALS_DESC( 1, iEvents.Count(), "we got an event"); |
|
815 // this was the first time the event was received so we get init complete event |
|
816 EUNIT_ASSERT_DESC( |
|
817 dynamic_cast< TShwEventFatalError* >( iEvents[ 0 ] ), |
|
818 "TShwEventReadyToView received" ); |
|
819 // delete and remove the event |
|
820 delete iEvents[ 0 ]; |
|
821 iEvents.Remove( 0 ); |
|
822 |
|
823 // tell medialist stub to call HandleItemRemovedL again |
|
824 iStubMediaList->NotifyItemRemoved( 0, 1 ); |
|
825 // this does nothing as the thumbnail loader was deleted and all contexts removed |
|
826 // check that we got no event |
|
827 EUNIT_ASSERT_EQUALS_DESC( 0, iEvents.Count(), "we got an event"); |
|
828 // tmp gets deleted here, EUnit checks for memory |
|
829 } |
|
830 |
|
831 // test also leave on SendEventL |
|
832 // tell the stub context that its request is not completed |
|
833 gThumbnailContextRequestCount = KErrNone; |
|
834 { |
|
835 // create an effect control, no need to delete or cleanupstack |
|
836 TShwAutoPtr< CShwEffectControl > tmp = |
|
837 CShwEffectControl::NewL( |
|
838 iStubEffectManager, *iStubVisualList, *iStubMediaList, TSize( 320, 240 ) ); |
|
839 // need to set the event queue |
|
840 tmp->SetEventQueue( this ); |
|
841 // perform the second phase of construction |
|
842 TShwEventInitialize initEvent; |
|
843 tmp->NotifyL( &initEvent ); |
|
844 // start async wait loop |
|
845 iWait.Start(); |
|
846 // remove items from stub medialist |
|
847 iStubMediaList->iCount = 0; |
|
848 // tell SendEventL to leave |
|
849 gSendEventLeaveCode = KErrNoMemory; |
|
850 // tell medialist stub to call HandleItemRemovedL |
|
851 TRAPD( error, iStubMediaList->NotifyItemRemoved( 0, 1 ) ); |
|
852 // check that engine did panic |
|
853 EUNIT_ASSERT_DESC( gNShwEnginePanicCalled, "Engine panic was called" ); |
|
854 EUNIT_ASSERT_EQUALS_DESC( |
|
855 NShwEngine::EEngineFatalError, error, "panic code was fatal error"); |
|
856 } |
|
857 |
|
858 } |
|
859 |
|
860 |
|
861 // TEST TABLE |
|
862 EUNIT_BEGIN_TEST_TABLE( |
|
863 T_CShwEffectControl, |
|
864 "Test suite for CShwEffectControl", |
|
865 "UNIT" ) |
|
866 |
|
867 EUNIT_ALLOC_TEST( |
|
868 "Construct-destruct test", |
|
869 "CShwEffectControl", |
|
870 "CShwEffectControl", |
|
871 "FUNCTIONALITY", |
|
872 EmptySetupL, TestConstructionL, Teardown ) // needs to have teardown as alloc test |
|
873 |
|
874 EUNIT_ALLOC_TEST( |
|
875 "test TransitionCompleted", |
|
876 "CShwEffectControl", |
|
877 "TransitionCompleted", |
|
878 "FUNCTIONALITY", |
|
879 SetupL, TransitionCompletedL, Teardown ) |
|
880 |
|
881 EUNIT_NOT_DECORATED_TEST( // cant be decorated as active objects |
|
882 "test TransitionCompleted", |
|
883 "CShwEffectControl", |
|
884 "TransitionCompleted", |
|
885 "FUNCTIONALITY", |
|
886 SetupL, TransitionCompleted2L, Teardown ) |
|
887 |
|
888 EUNIT_NOT_DECORATED_TEST( // cant be decorated as active objects |
|
889 "test NotifyL", |
|
890 "CShwEffectControl", |
|
891 "NotifyL", |
|
892 "FUNCTIONALITY", |
|
893 SetupL, NotifyLL, Teardown ) |
|
894 |
|
895 EUNIT_NOT_DECORATED_TEST( // cant be decorated as active objects |
|
896 "slow image load", |
|
897 "CShwEffectControl", |
|
898 "NotifyL", |
|
899 "FUNCTIONALITY", |
|
900 SetupL, SlowImageLoadL, Teardown ) |
|
901 |
|
902 EUNIT_NOT_DECORATED_TEST( // cant be decorated as active objects |
|
903 "slow image load", |
|
904 "CShwEffectControl", |
|
905 "NotifyL", |
|
906 "FUNCTIONALITY", |
|
907 SetupL, SlowImageLoad2L, Teardown ) |
|
908 |
|
909 EUNIT_TEST( |
|
910 "HandleFocusChangedL", |
|
911 "CShwEffectControl", |
|
912 "HandleFocusChangedL", |
|
913 "FUNCTIONALITY", |
|
914 SetupL, HandleFocusChangedL, Teardown ) |
|
915 |
|
916 EUNIT_TEST( |
|
917 "Thumbnail loading", |
|
918 "CShwThumbnailContext", |
|
919 "multiple", |
|
920 "FUNCTIONALITY", |
|
921 SetupL, TestThumbnailLoadingL, Teardown ) |
|
922 |
|
923 EUNIT_TEST( |
|
924 "Thumbnail errors", |
|
925 "CShwThumbnailLoader", |
|
926 "multiple", |
|
927 "FUNCTIONALITY", |
|
928 EmptySetupL, TestErrorsInThumbnailLoadingL, Teardown ) |
|
929 |
|
930 EUNIT_END_TEST_TABLE |
|
931 |
|
932 // END OF FILE |