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