lafagnosticuifoundation/cone/tef/TMultipleScreensStep.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 // Copyright (c) 2007-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  @file
       
    18  @test
       
    19  @internalComponent - Internal Symbian test code 
       
    20 */
       
    21 
       
    22 #include "TMultipleScreensStep.h"
       
    23 #include "../src/coepanic.h"
       
    24 #include <apacmdln.h> 
       
    25 
       
    26 const TInt KFstScreenNo = 0;
       
    27 const TInt KSndScreenNo = 1;
       
    28 const TInt KX = 0;
       
    29 const TInt KY = 0;
       
    30 /*Controls*/
       
    31 
       
    32 CTImageControl::CTImageControl(CFbsBitmap& aBitmap)
       
    33 	:iBitmap(aBitmap)
       
    34 	{
       
    35 	}
       
    36 
       
    37 CTImageControl::~CTImageControl()
       
    38 	{
       
    39 	}
       
    40 
       
    41 CTImageControl* CTImageControl::NewL(RWindowGroup& aWindow,CFbsBitmap& aBitmap)
       
    42 	{
       
    43 	CTImageControl* self = new(ELeave)CTImageControl(aBitmap);
       
    44 	CleanupStack::PushL(self);
       
    45 	self->ConstructL(aWindow);
       
    46 	CleanupStack::Pop();
       
    47 	return self;
       
    48 	}
       
    49 
       
    50 void CTImageControl::ConstructL(RWindowGroup& aWindow)
       
    51 	{	
       
    52    	CreateWindowL(aWindow);
       
    53    	SetExtentToWholeScreen();
       
    54     SetFocus(ETrue);
       
    55 	ActivateL();
       
    56 	}
       
    57 
       
    58 void CTImageControl::Draw(const TRect& /*aRect*/) const
       
    59 	{
       
    60     CWindowGc& gc=SystemGc();
       
    61 	TRect rct(0, 0, iBitmap.SizeInPixels().iWidth, iBitmap.SizeInPixels().iHeight);
       
    62 	gc.Clear();
       
    63 	gc.DrawBitmap(rct,&iBitmap);
       
    64 	}
       
    65 
       
    66 /*AppUI*/
       
    67 CTMultipleScreensAppUi::CTMultipleScreensAppUi(CTmsTestStep* aStep) :
       
    68 	CTestCoeAppUi(aStep),
       
    69 	iNumScreens(0)
       
    70 	{
       
    71 	}
       
    72 
       
    73 void CTMultipleScreensAppUi::ConstructL()
       
    74 	{
       
    75 	CTestCoeAppUi::ConstructL();
       
    76 	iBitmap=new(ELeave) CFbsBitmap();
       
    77 	iBitmap->Load(KImagePath);
       
    78 	AutoTestManager().StartAutoTest();
       
    79 	}
       
    80 
       
    81 CTMultipleScreensAppUi::~CTMultipleScreensAppUi()
       
    82 	{
       
    83 	if(iSndControl)
       
    84 		{
       
    85 		RemoveFromStack(iSndControl);
       
    86 		delete iSndControl;
       
    87 		}
       
    88 
       
    89 	RemoveFromStack(iFstControl);
       
    90 	delete iFstControl;
       
    91 	delete iBitmap;
       
    92 	}
       
    93 	
       
    94 
       
    95 void CTMultipleScreensAppUi::CompareL(TInt aScreenNumber)
       
    96 	{
       
    97 	INFO_PRINTF1(_L("Compare bitmaps..."));
       
    98 	CWsScreenDevice* screenDevice = STATIC_CAST(CWsScreenDevice*,iCoeEnv->SystemGc().Device());
       
    99 	TEST(screenDevice->GetScreenNumber()==aScreenNumber);
       
   100 	TInt bitmapHeight = iBitmap->SizeInPixels().iHeight;
       
   101 	TInt bitmapWidth = iBitmap->SizeInPixels().iWidth;
       
   102 	TDisplayMode screenDisplayMode = screenDevice->DisplayMode();
       
   103 	
       
   104 	TRect rct(KX, KY, bitmapWidth, bitmapHeight);
       
   105 	 
       
   106 	INFO_PRINTF1(_L("Capture screen content."));
       
   107 	CFbsBitmap* screenBitmap = new(ELeave) CFbsBitmap();
       
   108 	CleanupStack::PushL(screenBitmap);
       
   109 	User::LeaveIfError(screenBitmap->Create(iBitmap->SizeInPixels(), screenDisplayMode));
       
   110 	User::LeaveIfError(screenDevice->CopyScreenToBitmap(screenBitmap,rct));
       
   111 
       
   112 	INFO_PRINTF1(_L("Compare the displayed bitmap against the expected one."));
       
   113 	TInt lineLength=iBitmap->ScanLineLength(bitmapWidth, screenDisplayMode);
       
   114 	HBufC8* compareLineBuf=HBufC8::NewLC(lineLength);
       
   115 	TPtr8 compareLinePtr(compareLineBuf->Des());
       
   116 	HBufC8* screenLineBuf=HBufC8::NewLC(lineLength);
       
   117 	TPtr8 screenLinePtr(screenLineBuf->Des());
       
   118 	for (TInt index=0; index<bitmapHeight; index++)
       
   119 		{
       
   120 		iBitmap->GetScanLine(compareLinePtr, TPoint(KX,index), bitmapWidth, screenDisplayMode);
       
   121 		screenBitmap->GetScanLine(screenLinePtr, TPoint(KX,index),bitmapWidth, screenDisplayMode);
       
   122 		INFO_PRINTF2(_L("Scanline: %d"),index);
       
   123 		TEST(compareLinePtr.Compare(screenLinePtr)==KErrNone);
       
   124 		}
       
   125 	CleanupStack::PopAndDestroy(3,screenBitmap);
       
   126 	}
       
   127 
       
   128 
       
   129 /**
       
   130    @SYMTestCaseID          UIF-CONE-0001
       
   131 
       
   132    @SYMPREQ                PREQ1227
       
   133 
       
   134    @SYMREQ                 REQ5544
       
   135 
       
   136    @SYMTestCaseDesc        Get the number of screens supported by the system
       
   137 
       
   138    @SYMTestPriority        High
       
   139 
       
   140    @SYMTestStatus          Implemented
       
   141 
       
   142    @SYMTestActions         Call NumberOfScreens() to find the number of screens that are supported by the system.
       
   143                            API Calls:\n
       
   144 						   TInt CCoeEnv::NumberOfScreens() const
       
   145 
       
   146    @SYMTestExpectedResults This test case gets the number of screens supported by the system.
       
   147 */
       
   148 void CTMultipleScreensAppUi::TestNumberOfScreens()
       
   149 	{
       
   150    	INFO_PRINTF1(_L("Starting TestNumberOfScreens..."));
       
   151 	iNumScreens = iCoeEnv->WsSession().NumberOfScreens();
       
   152    	INFO_PRINTF2(_L("The number of screens supported on this device is %d"),iNumScreens);	
       
   153 	}
       
   154 
       
   155 /**
       
   156    @SYMTestCaseID          UIF-CONE-0002
       
   157 
       
   158    @SYMPREQ                PREQ1227
       
   159 
       
   160    @SYMREQ                 REQ5544
       
   161    
       
   162    @SYMTestCaseDesc        Display image on the first screen.
       
   163 
       
   164    @SYMTestPriority        High
       
   165 
       
   166    @SYMTestStatus          Implemented
       
   167 
       
   168    @SYMTestActions         Pass the second window group as parameter to CreateWindowL of the Control.
       
   169    						   Test that the graphics context was last activated on the first screen device. 
       
   170                            API Calls:\n
       
   171 						   CWsScreenDevice* CCoeEnv::ScreenDevice(TInt aScreenNumber) const
       
   172 						   RWindowGroup* CCoeEnv::RootWin(TInt aScreenNumber) const
       
   173 						   CGraphicsDevice* CWindowGc::Device() const
       
   174 
       
   175    @SYMTestExpectedResults An image is observed on the first screen.
       
   176 */
       
   177 void CTMultipleScreensAppUi::TestDrawOnFirstScreenL()
       
   178 	{
       
   179    	INFO_PRINTF1(_L("Start draw bitmap on first screen..."));
       
   180 	iFstControl=CTImageControl::NewL(*iCoeEnv->RootWin(KFstScreenNo),*iBitmap); 
       
   181    	AddToStackL(iFstControl);
       
   182    	iFstControl->DrawNow();
       
   183 	CompareL(KFstScreenNo);
       
   184    	CWsScreenDevice* fstDev = STATIC_CAST(CWsScreenDevice*,iFstControl->SystemGc().Device());
       
   185 	TEST(fstDev==iCoeEnv->ScreenDevice(KFstScreenNo));
       
   186 	}
       
   187 
       
   188 /**
       
   189    @SYMTestCaseID          UIF-CONE-0003
       
   190 
       
   191    @SYMPREQ                PREQ1227
       
   192 
       
   193    @SYMREQ                 REQ5544
       
   194 
       
   195    @SYMTestCaseDesc        Display image on the second screen.
       
   196 
       
   197    @SYMTestPriority        High
       
   198 
       
   199    @SYMTestStatus          Implemented
       
   200 
       
   201    @SYMTestActions         Pass the second window group as parameter to CreateWindowL of the Control.
       
   202    						   Test that the graphics context was last activated on the second screen device. 
       
   203                            API Calls:\n
       
   204 						   CWsScreenDevice* CCoeEnv::ScreenDevice(TInt aScreenNumber) const
       
   205 						   RWindowGroup* CCoeEnv::RootWin(TInt aScreenNumber) const
       
   206 						   CGraphicsDevice* CWindowGc::Device() const
       
   207 
       
   208    @SYMTestExpectedResults An image is observed on the first screen.
       
   209 */
       
   210 void CTMultipleScreensAppUi::TestDrawOnSecondScreenL()
       
   211 	{
       
   212 	INFO_PRINTF1(_L("Start draw bitmap on second screen..."));
       
   213  	if(KSndScreenNo<iNumScreens) 
       
   214  		{
       
   215 	   	iSndControl = CTImageControl::NewL(*iCoeEnv->RootWin(KSndScreenNo),*iBitmap); 
       
   216  		AddToStackL(iSndControl);
       
   217  		iSndControl->DrawNow();
       
   218 		CompareL(KSndScreenNo);
       
   219  		CWsScreenDevice* sndDev = STATIC_CAST(CWsScreenDevice*, CCoeEnv::Static()->SystemGc().Device());		
       
   220 		TEST(sndDev==iCoeEnv->ScreenDevice(KSndScreenNo));
       
   221  		}
       
   222 	}
       
   223 		
       
   224 /**
       
   225    @SYMTestCaseID          UIF-CONE-0004
       
   226 
       
   227    @SYMPREQ                PREQ1227
       
   228 
       
   229    @SYMREQ                 REQ5544
       
   230 
       
   231    @SYMTestCaseDesc        Tests for an invalid screen number.
       
   232 
       
   233    @SYMTestPriority        High
       
   234 
       
   235    @SYMTestStatus          Implemented
       
   236    
       
   237    @SYMTestActions         TMulScreensApp is launched.Negative tests are carried out on the APIs listed below, by passing an invalid screen number to them.
       
   238                            API Calls:\n
       
   239 						   CWsScreenDevice* CCoeEnv::ScreenDevice(TInt aScreenNumber) const;
       
   240 						   RWindowGroup* CCoeEnv::RootWin(TInt aScreenNumber) const;
       
   241    
       
   242    @SYMTestExpectedResults Application panics and exits with reason number ECoePanicInvalidScreenNumber.
       
   243 */
       
   244 void CTMultipleScreensAppUi::TestInvalidScreenNumberL()
       
   245 	{
       
   246 	INFO_PRINTF1(_L("Start Test TestInvalidScreenNumberL ..."));
       
   247 	_LIT8(KScreenDevice,"ScreenDevice");
       
   248 	StartProcessL(KScreenDevice);	
       
   249 	_LIT8(KWindowGroup,"WindowGroup");
       
   250 	StartProcessL(KWindowGroup);	
       
   251 	// Closes the panic windows created by this test case.
       
   252 	// DEF107910 Caused regression in one of the uikon test cases due to this panic dialog box. 
       
   253 	CloseAllPanicWindowsL();	
       
   254 	}
       
   255 
       
   256 void CTMultipleScreensAppUi::StartProcessL(const TDesC8& aTailEnd)
       
   257 	{
       
   258  	CApaCommandLine* cmdLine=CApaCommandLine::NewLC();
       
   259 	RProcess process; 
       
   260 	User::LeaveIfError(process.Create(KExeName, KNullDesC));
       
   261 	CleanupClosePushL(process);
       
   262 	TRAPD(ret,
       
   263 		{ 
       
   264 		cmdLine->SetExecutableNameL(KExeName);
       
   265 		cmdLine->SetTailEndL(aTailEnd);
       
   266 		cmdLine->SetProcessEnvironmentL(process);
       
   267 		})
       
   268 	TEST(ret==KErrNone);	
       
   269 	TRequestStatus status = KRequestPending;
       
   270 	process.Logon(status);
       
   271 
       
   272 	//Prevent emulator closing when a panic occurs
       
   273 	User::SetJustInTime(EFalse);
       
   274 
       
   275 	process.Resume();
       
   276 	User::WaitForRequest(status); 	
       
   277 
       
   278 	TEST(process.ExitType()==EExitPanic); 
       
   279 	TEST(process.ExitReason()==ECoePanicInvalidScreenNumber);
       
   280 
       
   281 	User::SetJustInTime(ETrue);
       
   282 	CleanupStack::PopAndDestroy(2, cmdLine);
       
   283 	}
       
   284 	
       
   285 void CTMultipleScreensAppUi::RunTestStepL(TInt aStepNum)
       
   286 	{
       
   287 	switch(aStepNum)
       
   288 		{	
       
   289 		case 1:
       
   290 			SetTestStepID(_L("UIF-CONE-0001"));
       
   291 			TestNumberOfScreens();
       
   292 			RecordTestResultL();
       
   293 			break;	
       
   294 		case 2:
       
   295 			SetTestStepID(_L("UIF-CONE-0002"));
       
   296 			TRAPD(err,TestDrawOnFirstScreenL());
       
   297 			TEST(err==KErrNone);
       
   298 			RecordTestResultL();
       
   299 			break;
       
   300 		case 3:
       
   301 			SetTestStepID(_L("UIF-CONE-0003"));
       
   302 			TRAP(err,TestDrawOnSecondScreenL());
       
   303 			TEST(err==KErrNone);
       
   304 			RecordTestResultL();
       
   305 			break;
       
   306 		case 4:
       
   307 			SetTestStepID(_L("UIF-CONE-0004"));
       
   308 			TRAP(err,TestInvalidScreenNumberL());
       
   309 			TEST(err==KErrNone);
       
   310 			RecordTestResultL();
       
   311 			CloseTMSGraphicsStep();
       
   312 			break;
       
   313 		case 5:
       
   314 			INFO_PRINTF1(_L("All tests completed.\n"));
       
   315 			AutoTestManager().FinishAllTestCases(CAutoTestManager::EPass);	
       
   316 			break;
       
   317 		default:
       
   318 			INFO_PRINTF1(_L("CTMultipleScreensAppUi::RunTestStepL default case\n"));
       
   319 			break;	
       
   320 		}
       
   321 	}
       
   322 
       
   323 /*Test step*/
       
   324 CTMultipleScreensStep::CTMultipleScreensStep()
       
   325 	{
       
   326 	SetTestStepName(KTMultipleScreensStep);
       
   327 	}
       
   328 
       
   329 CTMultipleScreensStep::~CTMultipleScreensStep()
       
   330 	{
       
   331 	}
       
   332 
       
   333 void CTMultipleScreensStep::ConstructAppL(CCoeEnv* aCoe)
       
   334 	{
       
   335 	aCoe->ConstructL();
       
   336 	CTMultipleScreensAppUi* appUi=new(ELeave) CTMultipleScreensAppUi(this);
       
   337 	aCoe->SetAppUi(appUi);
       
   338 	appUi->ConstructL();	
       
   339 	}
       
   340 
       
   341 TVerdict CTMultipleScreensStep::doTestStepL() // main function called by E32
       
   342 	{
       
   343 	INFO_PRINTF1(_L("TMultipleScreens Test Started"));
       
   344 	PreallocateHALBuffer();
       
   345 	__UHEAP_MARK;
       
   346 	CCoeEnv* coe=new(ELeave) CCoeEnv;
       
   347 	TRAPD(err,ConstructAppL(coe));
       
   348 	if (!err)
       
   349 		{
       
   350 		coe->ExecuteD();
       
   351 		}
       
   352 	else
       
   353 		{
       
   354 		SetTestStepResult(EFail);
       
   355 		delete coe;
       
   356 		}
       
   357 	REComSession::FinalClose();	
       
   358 	__UHEAP_MARKEND;
       
   359 	INFO_PRINTF1(_L("Test Finished"));
       
   360 	return TestStepResult();
       
   361 	}
       
   362 
       
   363 
       
   364 
       
   365 
       
   366 
       
   367 
       
   368