lafagnosticuifoundation/cone/tef/tconeevents.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent - Internal Symbian test code
       
    21  @test
       
    22 */
       
    23 
       
    24 #include <e32std.h>
       
    25 #include "COEAUI.H"
       
    26 #include "tconeevents.h"
       
    27 
       
    28 const TInt KUserEvent=60850;		//0xEDB2 - a random number that is unlikely to be used by other applicaions for user event sending
       
    29 
       
    30 /**
       
    31  Low priority active object to unnest the Active Scheduler
       
    32 */
       
    33 class CStopTheScheduler : public CAsyncOneShot
       
    34 	{
       
    35 public:
       
    36 	inline CStopTheScheduler(TInt aPriority) : CAsyncOneShot(aPriority) {}
       
    37 	//Virtual function from CActive
       
    38 	void RunL();
       
    39 	};
       
    40 
       
    41 void CStopTheScheduler::RunL()
       
    42 	{
       
    43 	CActiveScheduler::Stop();
       
    44 	}
       
    45 
       
    46 
       
    47 /**
       
    48  A control to test the recieving of redraw events.
       
    49  */
       
    50 class CDrawControl : public CCoeControl
       
    51 	{
       
    52 public:
       
    53 	static CDrawControl* NewLC(TInt aPos);
       
    54 	TBool HasDrawn();
       
    55 protected:
       
    56 	//Virtual function from CCoeControl
       
    57 	void Draw(const TRect& aRect) const;
       
    58 private:
       
    59 	void ConstructL(TInt aPos);
       
    60 	void inline Flush() {iCoeEnv->WsSession().Flush();}
       
    61 private:
       
    62 	__MUTABLE TBool iDrawn;
       
    63 	};
       
    64 
       
    65 /**
       
    66  Create an object and leave it on the cleanup stack
       
    67  */
       
    68 CDrawControl* CDrawControl::NewLC(TInt aPos)
       
    69 	{
       
    70 	CDrawControl* self=new(ELeave) CDrawControl();
       
    71 	CleanupStack::PushL(self);
       
    72 	self->ConstructL(aPos);
       
    73 	return self;
       
    74 	}
       
    75 
       
    76 /**
       
    77  Set up the control
       
    78  */
       
    79 void CDrawControl::ConstructL(TInt aPos)
       
    80 	{
       
    81 	TSize scrSize(iCoeEnv->ScreenDevice()->SizeInPixels());
       
    82 	TPoint topLeft(scrSize.iWidth/6,scrSize.iHeight/6);
       
    83 	if (aPos==2)
       
    84 		topLeft.SetXY(scrSize.iWidth/2-10,scrSize.iHeight/6+10);
       
    85 	SetExtent(topLeft,TSize(scrSize.iWidth/3+10,scrSize.iHeight*2/3-10));
       
    86 	CreateWindowL();
       
    87 	Window().SetBackgroundColor(aPos==1 ? TRgb(255,85,85):TRgb(85,255,85));	//Bright Red or Green
       
    88 	ActivateL();
       
    89 	//iCoeEnv->WsSession().LogCommand(RWsSession::ELoggingStatusDump);		//Useful for debugging window creation problems
       
    90 	DrawNow();
       
    91 	Flush();
       
    92 	}
       
    93 
       
    94 /**
       
    95  Draw the controls window
       
    96  */
       
    97 void CDrawControl::Draw(const TRect& aRect) const
       
    98 	{
       
    99 	TRect rect(aRect);
       
   100 	const TSize size(aRect.Size());
       
   101 	rect.Shrink(size.iWidth/5,size.iHeight/5);
       
   102 	CWindowGc& gc=SystemGc();
       
   103 	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   104 	gc.SetBrushColor(TRgb(85,85,255));	//Bright Blue
       
   105 	gc.DrawRect(rect);
       
   106 	MUTABLE_CAST(TBool&,iDrawn)=ETrue;
       
   107 	}
       
   108 
       
   109 /**
       
   110  Return if the control has be drawn and reset the flag
       
   111  */
       
   112 TBool CDrawControl::HasDrawn()
       
   113 	{
       
   114 	TBool drawn=iDrawn;
       
   115 	iDrawn=EFalse;
       
   116 	return drawn;
       
   117 	}
       
   118 
       
   119 
       
   120 /**
       
   121  Constructor for the APP UI for this test
       
   122  */
       
   123 CConeEventsAppUi::CConeEventsAppUi(CTmsTestStep* aStep,CCoeEnv* aCoe)
       
   124 	: CTestCoeAppUi(aStep), iCoe(aCoe)
       
   125 	{}
       
   126 
       
   127 /**
       
   128  Creates control for this test
       
   129  */
       
   130 void CConeEventsAppUi::ConstructL()
       
   131 	{
       
   132 	CTestCoeAppUi::ConstructL();
       
   133 	AutoTestManager().StartAutoTest();
       
   134 	}
       
   135 
       
   136 /**
       
   137  Creates control for this test
       
   138  */
       
   139 void CConeEventsAppUi::HandleWsEventL(const TWsEvent& aEvent,CCoeControl* aDestination)
       
   140 	{
       
   141 	if (aEvent.Type()!=KUserEvent)
       
   142 		CTestCoeAppUi::HandleWsEventL(aEvent,aDestination);
       
   143 	else
       
   144 		{
       
   145 		++iEventCount;
       
   146 		iCoe->WsSession().Finish();
       
   147 		}
       
   148 	}
       
   149 
       
   150 /**
       
   151  @SYMTestCaseID UIF-APPFWK-CONE-0033
       
   152 
       
   153  @SYMDEF PDEF131541
       
   154 
       
   155  @SYMTestCaseDesc Tests that all events are recieved before a AO of lower priority runs.
       
   156 
       
   157  @SYMTestPriority High
       
   158 
       
   159  @SYMTestStatus Implemented
       
   160 
       
   161  @SYMTestActions Sends lots of events and recieves them back while low priority AO is active.
       
   162 
       
   163  @SYMTestExpectedResults All events are recieved before a AO of lower priority runs
       
   164 
       
   165  @SYMTestType Unit Test
       
   166  */
       
   167 void CConeEventsAppUi::ManyEvents()
       
   168 	{
       
   169 	CStopTheScheduler* stop=new CStopTheScheduler(EActivePriorityWsEvents-10);
       
   170 	if (!stop)
       
   171 		{
       
   172 		TEST(EFalse);
       
   173 		_LIT(KLog,"Not enough memory to run test");
       
   174 		INFO_PRINTF1(KLog);
       
   175 		}
       
   176 	RWsSession& ws=iCoe->WsSession();
       
   177 	const TInt id=iCoe->RootWin().Identifier();
       
   178 	TWsEvent event;
       
   179 	event.SetType(KUserEvent);
       
   180 	TInt events;
       
   181 	TInt ii;
       
   182 	for (events=0;events<10;++events)
       
   183 		{
       
   184 		for (ii=events;ii>0;--ii)
       
   185 			ws.SendEventToWindowGroup(id,event);
       
   186 		iEventCount=0;
       
   187 		stop->Call();
       
   188 		CActiveScheduler::Start();
       
   189 		TEST(iEventCount==events);
       
   190 		if (iEventCount!=events)
       
   191 			{
       
   192 			_LIT(KLog,"Recieved %d events when %d expected");
       
   193 			INFO_PRINTF3(KLog,iEventCount,events);
       
   194 			}
       
   195 		}
       
   196 	delete stop;
       
   197 	}
       
   198 
       
   199 /**
       
   200  @SYMTestCaseID UIF-APPFWK-CONE-0034
       
   201 
       
   202  @SYMDEF PDEF131541
       
   203 
       
   204  @SYMTestCaseDesc Tests that all redraw events are recieved before a AO of lower priority runs.
       
   205 
       
   206  @SYMTestPriority High
       
   207 
       
   208  @SYMTestStatus Implemented
       
   209 
       
   210  @SYMTestActions Creates two redraws and receives them while low priority AO is active.
       
   211 
       
   212  @SYMTestExpectedResults Both redraws occure before the AO runs
       
   213 
       
   214  @SYMTestType Unit Test
       
   215  */
       
   216 void CConeEventsAppUi::ManyRedrawsL()
       
   217 	{
       
   218 	CStopTheScheduler* stop=new(ELeave) CStopTheScheduler(EActivePriorityRedrawEvents-10);
       
   219 	CleanupStack::PushL(stop);
       
   220 	CDrawControl* stateObCnt1=CDrawControl::NewLC(1);
       
   221 	CDrawControl* stateObCnt2=CDrawControl::NewLC(2);
       
   222 	stateObCnt1->DrawDeferred();
       
   223 	stateObCnt2->DrawDeferred();
       
   224 	stop->Call();
       
   225 	CActiveScheduler::Start();
       
   226 	TBool cnt1Drawn=stateObCnt1->HasDrawn();
       
   227 	TBool cnt2Drawn=stateObCnt2->HasDrawn();
       
   228 	TEST(cnt1Drawn && cnt2Drawn);
       
   229 	if (!cnt1Drawn || !cnt2Drawn)
       
   230 		{
       
   231 		_LIT(KLog,"Error!!  Control1 Drawn: %d  Control2 Drawn: %d  Both controls should have been drawn");
       
   232 		INFO_PRINTF3(KLog,cnt1Drawn,cnt2Drawn);
       
   233 		}
       
   234 	CleanupStack::PopAndDestroy(3,stop);
       
   235 	}
       
   236 
       
   237 /**
       
   238  Function to call each of the tests in turn
       
   239  */
       
   240 void CConeEventsAppUi::RunTestStepL(TInt aStepNum)
       
   241 	{
       
   242 	_LIT(KTest1,"Test 1: Many Events");
       
   243 	_LIT(KTest2,"Test 2: Many Redraws");
       
   244 	switch(aStepNum)
       
   245 		{
       
   246 	case 1:
       
   247 		SetTestStepID(_L("UIF-APPFWK-CONE-0033"));
       
   248 		INFO_PRINTF1(KTest1);
       
   249 		ManyEvents();
       
   250 		RecordTestResultL();
       
   251 		break;
       
   252 	case 2:
       
   253 		SetTestStepID(_L("UIF-APPFWK-CONE-0034"));
       
   254 		INFO_PRINTF1(KTest2);
       
   255 		ManyRedrawsL();
       
   256 		RecordTestResultL();
       
   257 		CloseTMSGraphicsStep();
       
   258 		break;
       
   259 	default:
       
   260 		AutoTestManager().FinishAllTestCases(CAutoTestManager::EPass);
       
   261 		break;
       
   262 		}
       
   263 	}
       
   264 
       
   265 /**
       
   266  Constructor for the main test class
       
   267  */
       
   268 CTConeEvents::CTConeEvents(TInt aMode) :iMode(aMode)
       
   269 	{
       
   270 	SetTestStepName(aMode==1?KTConeEvents():KTConeEvents2());
       
   271 	}
       
   272 
       
   273 /**
       
   274  Finish creating the Control Enviroment and create the App UI.
       
   275  */
       
   276 void CTConeEvents::ConstructL(CCoeEnv* aCoe)
       
   277 	{
       
   278 	aCoe->ConstructL();
       
   279 	CConeEventsAppUi* appUi=new(ELeave) CConeEventsAppUi(this,aCoe);
       
   280 	aCoe->SetAppUi(appUi);
       
   281 	appUi->ConstructL();
       
   282 	}
       
   283 
       
   284 /**
       
   285  Entry function for CTConeEvents Test Step.
       
   286  */
       
   287 TVerdict CTConeEvents::doTestStepL()
       
   288 	{
       
   289 	INFO_PRINTF1(_L("Test Started"));
       
   290 	CCoeEnv* coe=new(ELeave) CCoeEnv();		//Need to create the CoeEnv here because it creates a new clean-up stack
       
   291 	TRAPD(err,ConstructL(coe));
       
   292 	if (!err)
       
   293 		{
       
   294 		if (iMode==1)
       
   295 			coe->ExecuteD();
       
   296 		else
       
   297 			{
       
   298 			TRAPD(ret,CActiveScheduler::Start());
       
   299 			_LIT(KTest,"CONE-Test");
       
   300 			__ASSERT_ALWAYS(ret==KLeaveExit || ret==KErrNone,User::Panic(KTest,EConeTestWrongLeave));
       
   301 			coe->DisableExitChecks(ETrue);
       
   302 			delete coe;		//Need to delete the CoeEnv as otherwise there is a CleanupStack panic in TestExecute
       
   303 			}
       
   304 		}
       
   305 	else
       
   306 		{
       
   307 		SetTestStepResult(EFail);
       
   308 		delete coe;
       
   309 		}
       
   310 	INFO_PRINTF1(_L("Test Finished"));
       
   311 	return TestStepResult();
       
   312 	}