photosgallery/slideshow/engine/tsrc/t_cshwtimercontrol/t_cshwtimercontrol.cpp
changeset 0 4e91876724a2
child 16 0bc0ea26031e
child 18 bcb43dc84c44
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     1 /*
       
     2 * Copyright (c) 2007-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 timer control for the slideshow
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 //  CLASS HEADER
       
    21 #include "t_cshwtimercontrol.h"
       
    22 
       
    23 //  EXTERNAL INCLUDES
       
    24 #include <digia/eunit/EUnitMacros.h>
       
    25 #include <digia/eunit/EUnitDecorators.h>
       
    26 
       
    27 //  INTERNAL INCLUDES
       
    28 #include "shwevent.h"
       
    29 #include "shwautoptr.h"
       
    30 #include "shwcallback.h"
       
    31 
       
    32 // CONSTRUCTION
       
    33 T_CShwTimerControl* T_CShwTimerControl::NewL()
       
    34     {
       
    35     T_CShwTimerControl* self = T_CShwTimerControl::NewLC();
       
    36     CleanupStack::Pop();
       
    37 
       
    38     return self;
       
    39     }
       
    40 
       
    41 T_CShwTimerControl* T_CShwTimerControl::NewLC()
       
    42     {
       
    43     T_CShwTimerControl* self = new( ELeave ) T_CShwTimerControl;
       
    44     CleanupStack::PushL( self );
       
    45 
       
    46     self->ConstructL();
       
    47 
       
    48     return self;
       
    49     }
       
    50 
       
    51 // Destructor (virtual by CBase)
       
    52 T_CShwTimerControl::~T_CShwTimerControl()
       
    53     {
       
    54     }
       
    55 
       
    56 // Default constructor
       
    57 T_CShwTimerControl::T_CShwTimerControl()
       
    58     {
       
    59     }
       
    60 
       
    61 // Second phase construct
       
    62 void T_CShwTimerControl::ConstructL()
       
    63     {
       
    64     // The ConstructL from the base class CEUnitTestSuiteClass must be called.
       
    65     // It generates the test case table.
       
    66     CEUnitTestSuiteClass::ConstructL();
       
    67     }
       
    68 
       
    69 //  METHODS
       
    70 
       
    71 void T_CShwTimerControl::SendEventL( MShwEvent* aEvent )
       
    72 	{
       
    73 	// need to clone the event since the caller goes out of scope
       
    74 	iEvent = aEvent->CloneLC();
       
    75 	CleanupStack::Pop();
       
    76 	
       
    77 	// stop the scheduler loop if its started
       
    78 	if( iWait.IsStarted() )
       
    79 		{
       
    80 		iWait.AsyncStop();
       
    81 		}
       
    82 	}
       
    83 
       
    84 TInt T_CShwTimerControl::TimerCallBack()
       
    85 	{
       
    86 	iStoppedForTimer = ETrue;
       
    87 	iWait.AsyncStop();
       
    88 	return 0;
       
    89 	}
       
    90 
       
    91 void T_CShwTimerControl::SetupL()
       
    92     {
       
    93     iCShwTimerControl = CShwTimerControl::NewL();
       
    94 	// set the event queue
       
    95 	iCShwTimerControl->SetEventQueue( this );
       
    96     }
       
    97 
       
    98 void T_CShwTimerControl::Teardown()
       
    99     {
       
   100     delete iCShwTimerControl;
       
   101     iCShwTimerControl = NULL;
       
   102     
       
   103     delete iEvent;
       
   104     iEvent = NULL;
       
   105     }
       
   106 
       
   107 void T_CShwTimerControl::Empty()
       
   108 	{
       
   109 	}
       
   110 
       
   111 void T_CShwTimerControl::TestConstructL()
       
   112 	{
       
   113 	// create timer
       
   114     iCShwTimerControl = CShwTimerControl::NewL();
       
   115 	// set the event queue
       
   116 	iCShwTimerControl->SetEventQueue( this );
       
   117 	// test that object exists
       
   118 	EUNIT_ASSERT_DESC( iCShwTimerControl, "object created" );
       
   119 	// delete timer
       
   120     delete iCShwTimerControl;
       
   121     iCShwTimerControl = NULL;
       
   122     // EUnit checks for memory leaks
       
   123 	}
       
   124 
       
   125 void T_CShwTimerControl::T_TimeTickLL()
       
   126 	{
       
   127 	// call timetick
       
   128 	iCShwTimerControl->SendTimerBeatL();
       
   129 	// check that we got the event
       
   130 	EUNIT_ASSERT_DESC( iEvent, "event was received" );
       
   131 	TShwEventTimerBeat* timer = dynamic_cast<TShwEventTimerBeat*>( iEvent );
       
   132 	EUNIT_ASSERT_DESC( timer, "event was TShwEventTimerBeat" );
       
   133 	}
       
   134 
       
   135 void T_CShwTimerControl::T_NotifyLL()
       
   136     {
       
   137     // if should evaluate true: else if( eventStartView )
       
   138     TShwEventStartView start( 123 );
       
   139     iCShwTimerControl->NotifyL( &start );
       
   140 
       
   141 	// Need to let the scheduler loop
       
   142 	iWait.Start();
       
   143 
       
   144 	EUNIT_ASSERT_DESC( iEvent, "event was received" );
       
   145 	TShwEventTimerBeat* timer = dynamic_cast<TShwEventTimerBeat*>( iEvent );
       
   146 	EUNIT_ASSERT_DESC( timer, "event was TShwEventTimerBeat" );
       
   147     }
       
   148     
       
   149 void T_CShwTimerControl::T_NotifyL2L()
       
   150     {
       
   151     // if should evaluate false: else if( eventStartView )
       
   152     MShwEvent* iParam1 = NULL;
       
   153     iCShwTimerControl->NotifyL( iParam1 );
       
   154 
       
   155 	EUNIT_ASSERT_DESC( !iEvent, "event was not received" );
       
   156     }
       
   157     
       
   158 void T_CShwTimerControl::T_PauseL()
       
   159 	{
       
   160     // should evaluate true: else if( eventStartView )
       
   161     // NOTE timer multiplies this with 1000 so this is milliseconds
       
   162     TShwEventStartView start( 123 );
       
   163     iCShwTimerControl->NotifyL( &start );
       
   164 
       
   165 	// then send Pause
       
   166 	// should evaluate true: if ( eventPause )
       
   167 	TShwEventPause pause;
       
   168     iCShwTimerControl->NotifyL( &pause );
       
   169 	// send pause again, its a no-op
       
   170     iCShwTimerControl->NotifyL( &pause );
       
   171 
       
   172 	// create timer to give us callback
       
   173 	TShwAutoPtr< CPeriodic > timer = CPeriodic::NewL( CActive::EPriorityStandard );
       
   174 	// start a timer to stop the asynch loop since we dont expect the 
       
   175 	// iCShwTimerControl to send any event
       
   176 	// start asynch wait for 1 second
       
   177 	iStoppedForTimer = EFalse;
       
   178 	timer->Start( 
       
   179 		1 * 1000000, 
       
   180 		1 * 1000000, 
       
   181 		TShwCallBack< T_CShwTimerControl, TimerCallBack >( this ) );
       
   182 
       
   183 	// Need to let the scheduler loop
       
   184 	iWait.Start();
       
   185 	timer->Cancel();
       
   186 	
       
   187 	EUNIT_ASSERT_DESC( iStoppedForTimer, "stopped in timer, SendEventL not called" );
       
   188 	EUNIT_ASSERT_DESC( !iEvent, "event was not received" );
       
   189 
       
   190 	// send resume
       
   191 	// should evaluate true: else if( eventResume )
       
   192 	TShwEventResume resume;
       
   193     iCShwTimerControl->NotifyL( &resume );
       
   194 
       
   195 	// start the timer again
       
   196 	iStoppedForTimer = EFalse;
       
   197 	timer->Start( 
       
   198 		1 * 1000000, 
       
   199 		1 * 1000000, 
       
   200 		TShwCallBack< T_CShwTimerControl, TimerCallBack >( this ) );
       
   201 
       
   202 	// Need to let the scheduler loop
       
   203 	iWait.Start();
       
   204 	timer->Cancel();
       
   205 
       
   206 	EUNIT_ASSERT_DESC( !iStoppedForTimer, "SendEventL was called" );
       
   207 	EUNIT_ASSERT_DESC( iEvent, "event was received" );
       
   208 	EUNIT_ASSERT_DESC( dynamic_cast<TShwEventTimerBeat*>( iEvent ), "event was timer beat" );
       
   209 	// release the event
       
   210 	delete iEvent; iEvent = NULL;
       
   211 
       
   212 	// send resume again
       
   213 	// should evaluate true: else if( eventResume )
       
   214 	TShwEventResume resume2;
       
   215     iCShwTimerControl->NotifyL( &resume2 );
       
   216 	// start the timer again
       
   217 	iStoppedForTimer = EFalse;
       
   218 	timer->Start( 
       
   219 		1 * 1000000, 
       
   220 		1 * 1000000, 
       
   221 		TShwCallBack< T_CShwTimerControl, TimerCallBack >( this ) );
       
   222 	// Need to let the scheduler loop
       
   223 	iWait.Start();
       
   224 	timer->Cancel();
       
   225 	EUNIT_ASSERT_DESC( iStoppedForTimer, "stopped in timer, SendEventL not called" );
       
   226 	EUNIT_ASSERT_DESC( !iEvent, "event was not received" );
       
   227 	}
       
   228 
       
   229 //  TEST TABLE
       
   230 EUNIT_BEGIN_TEST_TABLE(
       
   231     T_CShwTimerControl,
       
   232     "Test suite for CShwTimerControl",
       
   233     "UNIT" )
       
   234 
       
   235 EUNIT_ALLOC_TEST(
       
   236     "Constructor test",
       
   237     "CShwTimerControl",
       
   238     "NewL",
       
   239     "FUNCTIONALITY",
       
   240     Empty, TestConstructL, Empty )
       
   241 
       
   242 EUNIT_ALLOC_TEST(
       
   243     "TimeTickL - test0",
       
   244     "CShwTimerControl",
       
   245     "TimeTickL",
       
   246     "ERRORHANDLING",
       
   247     SetupL, T_TimeTickLL, Teardown)
       
   248 
       
   249 // these cant be decorated as the EUnit
       
   250 // scheduler does not implement Error method
       
   251 EUNIT_NOT_DECORATED_TEST(
       
   252     "NotifyL - test0",
       
   253     "CShwTimerControl",
       
   254     "NotifyL",
       
   255     "FUNCTIONALITY",
       
   256     SetupL, T_NotifyLL, Teardown)
       
   257     
       
   258 EUNIT_NOT_DECORATED_TEST(
       
   259     "NotifyL - test1",
       
   260     "CShwTimerControl",
       
   261     "NotifyL",
       
   262     "FUNCTIONALITY",
       
   263     SetupL, T_NotifyL2L, Teardown)
       
   264 
       
   265 EUNIT_NOT_DECORATED_TEST(
       
   266     "Pause test",
       
   267     "CShwTimerControl",
       
   268     "NotifyL",
       
   269     "FUNCTIONALITY",
       
   270     SetupL, T_PauseL, Teardown)
       
   271 
       
   272 EUNIT_END_TEST_TABLE
       
   273 
       
   274 //  END OF FILE