os/graphics/windowing/windowserver/test/tauto/TGETPIXEL.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/windowing/windowserver/test/tauto/TGETPIXEL.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,395 @@
     1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// GETPIXEL.CPP
    1.18 +// Automatically test GetPixel
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +/**
    1.23 + @file
    1.24 + @test
    1.25 + @internalComponent - Internal Symbian test code
    1.26 +*/
    1.27 +
    1.28 +#include "TGETPIXEL.H"
    1.29 +
    1.30 +CTGetPixel::CTGetPixel(CTestStep* aStep):
    1.31 +	CTWsGraphicsBase(aStep)
    1.32 +	{
    1.33 +	}
    1.34 +
    1.35 +CTGetPixel::~CTGetPixel()
    1.36 +	{
    1.37 +	iWindow.Close();
    1.38 +	User::Free(iRgbBuf);
    1.39 +	}
    1.40 +
    1.41 +LOCAL_C TInt DoPanicTest(TInt aFunc, TAny *aScreenNumber)
    1.42 +	{
    1.43 +	RWsSession ws;
    1.44 +	if (ws.Connect()==KErrNone)
    1.45 +		switch(aFunc)
    1.46 +			{
    1.47 +			case 1:	// Get pixels into a TPtr 1 pixel too small
    1.48 +				{
    1.49 +				CWsScreenDevice *screen = new(ELeave) CWsScreenDevice(ws);
    1.50 +				User::LeaveIfError(screen->Construct((TInt)aScreenNumber));
    1.51 +				CFbsBitmap *bitmap=new(ELeave) CFbsBitmap();
    1.52 +				TInt bitWid=80;
    1.53 +				TRgb *buf=NULL;
    1.54 +				if (bitmap->Create(TSize(1,bitWid), EGray16)==KErrNone && (buf=(TRgb *)User::Alloc((bitWid-1)*sizeof(TRgb)))!=NULL)
    1.55 +					{
    1.56 +					TPtr8 desc((TUint8 *)buf,(bitWid-1)*sizeof(TRgb));
    1.57 +    				screen->GetScanLine(desc,TPoint(0,0),bitWid, ERgb);
    1.58 +					}
    1.59 +				}
    1.60 +				break;
    1.61 +			}
    1.62 +	return(EWsExitReasonBad);
    1.63 +	}
    1.64 +
    1.65 +void CTGetPixel::ClearOutRedraws()
    1.66 +// This has been added because partial redraw store can be triggered to request a
    1.67 +// low priority redraw from the window even though in normal circumstances the window
    1.68 +// would not expect to receive any sort of redraw event.
    1.69 +	{
    1.70 +	iWindow.BeginRedraw();
    1.71 +	iWindow.EndRedraw();
    1.72 +	}
    1.73 +
    1.74 +void CTGetPixel::TestPanicsL()
    1.75 +	{
    1.76 +	if (!iTest->IsFullRomL())
    1.77 +		{
    1.78 +		TEST(iTest->TestWsPanicL(DoPanicTest,EWservPanicInvalidParameter,1,(TAny*)iTest->iScreenNumber));
    1.79 +		}
    1.80 +	}
    1.81 +
    1.82 +void CTGetPixel::DrawAndCheckLine(const TPoint &aPos,TInt aLen,TRgb aColor)
    1.83 +	{
    1.84 +	TheGc->Activate(iWindow);
    1.85 +	TheGc->SetPenColor(aColor);
    1.86 +	iWindow.BeginRedraw(TRect(aPos,TSize(aLen, 1)));
    1.87 +	TheGc->DrawLine(aPos,aPos+TSize(aLen,0));
    1.88 +	iWindow.EndRedraw();
    1.89 +	TheGc->Deactivate();
    1.90 +	iRgbBuf=(TRgb *)User::ReAlloc(iRgbBuf,aLen*sizeof(TRgb));
    1.91 +	TPtr8 ptr((TUint8 *)iRgbBuf,aLen*sizeof(TRgb));
    1.92 +	TheClient->iScreen->GetScanLine(ptr, aPos+iWindow.InquireOffset(*TheClient->iGroup->WinTreeNode()), aLen, EColor16MA);
    1.93 +	TRgb result(TRgb::Gray16(aColor.Gray16()));
    1.94 +	if (TheClient->iScreen->DisplayMode()==EColor64K)
    1.95 +		result=TRgb::Color64K(result.Color64K());
    1.96 +	for(TInt index=0;index<aLen;index++)
    1.97 +		{
    1.98 +		TEST(iRgbBuf[index]==result);
    1.99 +		}
   1.100 +	}
   1.101 +
   1.102 +void CTGetPixel::ConstructL()
   1.103 +	{
   1.104 +	iWindow = TheClient->iWs;
   1.105 +	TheGc->Activate(*BaseWin->Win());
   1.106 +	TheGc->Clear();
   1.107 +	TheGc->SetBrushColor(TRgb::Gray16(0));
   1.108 +	TheGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   1.109 +	TheGc->SetPenStyle(CGraphicsContext::ENullPen);
   1.110 +	TheGc->DrawRect(TRect(iWinSize));
   1.111 +	TheGc->Deactivate();
   1.112 +	
   1.113 +	iWindow.Construct(*TheClient->iGroup->GroupWin(),ENullWsHandle);
   1.114 +	iWinSize=TSize(TheClient->iScreen->SizeInPixels());
   1.115 +	iWinSize.iWidth/=3;
   1.116 +	iWinSize.iHeight/=3;
   1.117 +	iWindow.SetRequiredDisplayMode(EGray16);
   1.118 +	TheClient->iWs.Flush();
   1.119 +	iTest->DelayIfFullRomL();	// Need to wait for view server to mess around when display mode changed
   1.120 +	TheClient->WaitForRedrawsToFinish();// otherwise it will stomp on top of our window invalidating it.
   1.121 +	iWindow.SetExtent(TPoint(iWinSize.iWidth,iWinSize.iHeight),iWinSize);
   1.122 +	iWindow.EnableRedrawStore(EFalse);	// Otherwise drawing might trigger a redraw when purging redraw store
   1.123 +	
   1.124 +	iWindow.Activate();
   1.125 +	iWindow.BeginRedraw();
   1.126 +	iWindow.EndRedraw();
   1.127 +		
   1.128 +	}
   1.129 +
   1.130 +void CTGetPixel::TestCheckRect()
   1.131 +	{
   1.132 +	TSize size(TheClient->iScreen->SizeInPixels());
   1.133 +	TEST(TheClient->iScreen->RectCompare(TRect(size),TRect(TPoint(iTest->StdTestWindowSize().iWidth>>1,0),iTest->StdTestWindowSize()))==EFalse);
   1.134 +	}
   1.135 +
   1.136 +void CTGetPixel::DrawColorsL()
   1.137 +	{
   1.138 +	TPoint point(0,0);
   1.139 +	TInt color=-1;
   1.140 +	iWindow.BeginRedraw();
   1.141 +	FOREVER
   1.142 +		{
   1.143 +		TheGc->SetPenColor(TRgb::Color256(++color));
   1.144 +		TheGc->Plot(point);
   1.145 +		if (color==255)
   1.146 +			break;
   1.147 +		if (++point.iX==iWinSize.iWidth)
   1.148 +			{
   1.149 +			point.iX=0;
   1.150 +			if (++point.iY==iWinSize.iHeight)
   1.151 +				break;
   1.152 +			}
   1.153 +		}
   1.154 +	iWindow.EndRedraw();
   1.155 +	}
   1.156 +
   1.157 +void CTGetPixel::TestColors(CPalette* aPalette)
   1.158 +	{
   1.159 +	TInt numColors=iWinSize.iWidth;
   1.160 +	TPtr8 ptr(REINTERPRET_CAST(TUint8*,iRgbBuf),numColors*sizeof(TRgb));
   1.161 +	TPtr8 paletteData(NULL,0);
   1.162 +	TInt color=0;
   1.163 +	TPoint point(iWinSize.AsPoint());
   1.164 +	do	{
   1.165 +		if (color+numColors>256)
   1.166 +			numColors=256-color;
   1.167 +		TheClient->iScreen->GetScanLine(ptr,point,numColors,EColor16MA);
   1.168 +		aPalette->GetDataPtr(color,numColors,paletteData);
   1.169 +		TEST(ptr==paletteData);
   1.170 +		color+=numColors;
   1.171 +		} while (color<256 && ++point.iY<2*iWinSize.iHeight);
   1.172 +	}
   1.173 +
   1.174 +void CTGetPixel::CheckPaletteL(CPalette*& aPalette)
   1.175 +	{
   1.176 +	User::LeaveIfError(TheClient->iScreen->SetCustomPalette(aPalette));
   1.177 +	TestColors(aPalette);
   1.178 +	delete aPalette;
   1.179 +	User::LeaveIfError(TheClient->iScreen->GetPalette(aPalette));
   1.180 +	TestColors(aPalette);
   1.181 +	}
   1.182 +
   1.183 +inline TInt Inc(TInt& aValue)
   1.184 +	{
   1.185 +	if (aValue>255-83)
   1.186 +		aValue-=256-83;
   1.187 +	else
   1.188 +		aValue+=83;
   1.189 +	return aValue;
   1.190 +	}
   1.191 +
   1.192 +inline TInt Inc2(TInt& aValue)
   1.193 +	{
   1.194 +	if (aValue>255-41)
   1.195 +		aValue-=256-41;
   1.196 +	else
   1.197 +		aValue+=41;
   1.198 +	return aValue;
   1.199 +	}
   1.200 +
   1.201 +void CTGetPixel::PaletteTestL()
   1.202 +	{
   1.203 +	//INFO_PRINTF1(_L("AUTO  PaletteTest "));
   1.204 +	TInt numEntries;
   1.205 +	TBool modifiable;
   1.206 +	TheClient->iScreen->PaletteAttributes(modifiable,numEntries);
   1.207 +	INFO_PRINTF2(_L("Number of entries in the palette %d"), numEntries);
   1.208 +	if(numEntries > 65536)
   1.209 +		{
   1.210 +		INFO_PRINTF1(_L("These test cases has been skipped, as the screen is set up in true colour display mode, where palette is not applicable"));
   1.211 +		return; 
   1.212 +		}
   1.213 +	CPalette* palette=NULL;
   1.214 +	if (!modifiable)
   1.215 +		{
   1.216 +		if (numEntries==4)
   1.217 +			palette=CPalette::NewDefaultL(EGray4);
   1.218 +		else if (numEntries==16)
   1.219 +			palette=CPalette::NewDefaultL(EGray16);
   1.220 +		else
   1.221 +			palette=CPalette::NewL(numEntries);
   1.222 +		//INFO_PRINTF1(_L(" Creating Empty Palette, setting it as palette"));
   1.223 +		TInt err=TheClient->iScreen->SetCustomPalette(palette);
   1.224 +		TEST(err==KErrNoMemory || err==KErrNotSupported || (err==KErrNone && numEntries<=16));		//Series5MX palettes are changeable even though they say they aren't
   1.225 +		//INFO_PRINTF1(_L(" Palette setting test passed OK"));
   1.226 +		delete palette;
   1.227 +		}
   1.228 +	TInt err=iWindow.SetRequiredDisplayMode(EColor256);
   1.229 +	TheGc->Activate(iWindow);
   1.230 +	DrawColorsL();
   1.231 +	//INFO_PRINTF1(_L(" Drawn Colors"));
   1.232 +	TheClient->iScreen->PaletteAttributes(modifiable,numEntries);
   1.233 +	iRgbBuf=STATIC_CAST(TRgb*,User::ReAllocL(iRgbBuf,Max(256,iWinSize.iWidth)*sizeof(TRgb)));
   1.234 +	if (err<KErrNone || modifiable==EFalse)
   1.235 +		{
   1.236 +		//INFO_PRINTF1(_L(" Palette Fixed"));
   1.237 +		TInt err=TheClient->iScreen->GetPalette(palette);
   1.238 +		if (err==KErrNotSupported)
   1.239 +			return;
   1.240 +		User::LeaveIfError(err);
   1.241 +		TestColors(palette);
   1.242 +		delete palette;
   1.243 +		//INFO_PRINTF1(_L(" Tested Palette OK"));
   1.244 +		return;
   1.245 +		}
   1.246 +	//INFO_PRINTF1(_L(" Palette Changeable"));
   1.247 +	TEST(numEntries==256);
   1.248 +	CPalette* defPalette=CPalette::NewDefaultL(EColor256);
   1.249 +	CleanupStack::PushL(defPalette);
   1.250 +	TestColors(defPalette);
   1.251 +	User::LeaveIfError(TheClient->iScreen->GetPalette(palette));
   1.252 +	TestColors(palette);
   1.253 +	TInt color;
   1.254 +	TInt index=0;
   1.255 +	for (color=0;color<256;++color)
   1.256 +		palette->SetEntry(color,TRgb::Gray256(color));
   1.257 +	CheckPaletteL(palette);
   1.258 +	for (color=0;color<256;++color)
   1.259 +		palette->SetEntry(color,TRgb(Inc(index),Inc(index),Inc(index)));
   1.260 +	CheckPaletteL(palette);
   1.261 +	for (color=0;color<256;++color)
   1.262 +		palette->SetEntry(color,TRgb(Inc2(index),Inc2(index),Inc2(index)));
   1.263 +	CheckPaletteL(palette);
   1.264 +	delete palette;
   1.265 +	User::LeaveIfError(TheClient->iScreen->SetCustomPalette(defPalette));
   1.266 +	TestColors(defPalette);
   1.267 +	CleanupStack::PopAndDestroy(defPalette);
   1.268 +	ClearOutRedraws();
   1.269 +	}
   1.270 +
   1.271 +void CTGetPixel::RunTestCaseL(TInt /*aCurTestCase*/)
   1.272 +	{
   1.273 +	((CTGetPixelStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
   1.274 +	switch(++iTest->iState)
   1.275 +		{
   1.276 +/**
   1.277 +@SYMTestCaseID		GRAPHICS-WSERV-0212
   1.278 +
   1.279 +@SYMDEF             DEF081259
   1.280 +
   1.281 +@SYMTestCaseDesc    Draw lines and check them by scanning the lines
   1.282 +
   1.283 +@SYMTestPriority    High
   1.284 +
   1.285 +@SYMTestStatus      Implemented
   1.286 +
   1.287 +@SYMTestActions     Draw lines and then scan them to check that they have
   1.288 +					been drawn correctly
   1.289 +
   1.290 +@SYMTestExpectedResults Scanning the lines reveals they have been drawn correctly
   1.291 +*/
   1.292 +		case 1:
   1.293 +			((CTGetPixelStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0212"));
   1.294 +			TheClient->iWs.SetAutoFlush(ETrue);
   1.295 +			iTest->LogSubTest(_L("Basic"));
   1.296 +			DrawAndCheckLine(TPoint(0,2),iWinSize.iWidth-2,TRgb::Gray4(0));
   1.297 +			DrawAndCheckLine(TPoint(0,iWinSize.iHeight-2),iWinSize.iWidth,TRgb::Gray4(1));
   1.298 +			DrawAndCheckLine(TPoint(iWinSize.iWidth-1,iWinSize.iHeight-1),1,TRgb::Gray4(2));
   1.299 +			ClearOutRedraws();
   1.300 +			TheClient->iWs.SetAutoFlush(EFalse);
   1.301 +			break;
   1.302 +/**
   1.303 +@SYMTestCaseID		GRAPHICS-WSERV-0213
   1.304 +
   1.305 +@SYMDEF             DEF081259
   1.306 +
   1.307 +@SYMTestCaseDesc    Draw line on every line of a window and
   1.308 +					check them by scanning the lines
   1.309 +
   1.310 +@SYMTestPriority    High
   1.311 +
   1.312 +@SYMTestStatus      Implemented
   1.313 +
   1.314 +@SYMTestActions     Draw lines on every line of a window and
   1.315 +					check them by scanning the lines
   1.316 +
   1.317 +@SYMTestExpectedResults Scanning the lines reveals they have been drawn correctly
   1.318 +*/
   1.319 +
   1.320 +		case 2:
   1.321 +			{
   1.322 +			((CTGetPixelStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0213"));
   1.323 +			iTest->LogSubTest(_L("Full window"));
   1.324 +			for(TInt ypos=0;ypos<iWinSize.iHeight;ypos++)
   1.325 +				DrawAndCheckLine(TPoint(0,ypos),iWinSize.iWidth,TRgb::Gray4(0));
   1.326 +			ClearOutRedraws();
   1.327 +			}
   1.328 +			break;
   1.329 +/**
   1.330 +@SYMTestCaseID		GRAPHICS-WSERV-0214
   1.331 +
   1.332 +@SYMDEF             DEF081259
   1.333 +
   1.334 +@SYMTestCaseDesc    Test the check rect method 
   1.335 +
   1.336 +@SYMTestPriority    High
   1.337 +
   1.338 +@SYMTestStatus      Implemented
   1.339 +
   1.340 +@SYMTestActions     Use the check rect method to check the image in a window
   1.341 +
   1.342 +@SYMTestExpectedResults The check rect method functions correctly
   1.343 +*/
   1.344 +		case 3:
   1.345 +			((CTGetPixelStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0214"));
   1.346 +			iTest->LogSubTest(_L("Check Rect"));
   1.347 +			TestCheckRect();
   1.348 +			break;
   1.349 +/**
   1.350 +@SYMTestCaseID		GRAPHICS-WSERV-0215
   1.351 +
   1.352 +@SYMDEF             DEF081259
   1.353 +
   1.354 +@SYMTestCaseDesc    Test that the GetScanLine method panics correctly 
   1.355 +
   1.356 +@SYMTestPriority    High
   1.357 +
   1.358 +@SYMTestStatus      Implemented
   1.359 +
   1.360 +@SYMTestActions     Cause the GetScanLine method to panic and chekc the response
   1.361 +
   1.362 +@SYMTestExpectedResults The panic for the GetScanLine method is correct
   1.363 +*/
   1.364 +		case 4:
   1.365 +			((CTGetPixelStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0215"));
   1.366 +			iTest->LogSubTest(_L("Panic"));
   1.367 +			TestPanicsL();
   1.368 +			break;
   1.369 +/**
   1.370 +@SYMTestCaseID		GRAPHICS-WSERV-0216
   1.371 +
   1.372 +@SYMDEF             DEF081259
   1.373 +
   1.374 +@SYMTestCaseDesc    Test that CPalette class functions correctly 
   1.375 +
   1.376 +@SYMTestPriority    High
   1.377 +
   1.378 +@SYMTestStatus      Implemented
   1.379 +
   1.380 +@SYMTestActions     Create a CPalette object and exercise all its methods
   1.381 +
   1.382 +@SYMTestExpectedResults The palette functions as exepcted
   1.383 +*/
   1.384 +		case 5:
   1.385 +			((CTGetPixelStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0216"));
   1.386 +			iTest->LogSubTest(_L("Palette Test"));
   1.387 +			PaletteTestL();
   1.388 +			break;
   1.389 +		case 6:
   1.390 +            		((CTGetPixelStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   1.391 +			((CTGetPixelStep*)iStep)->CloseTMSGraphicsStep();
   1.392 +			TestComplete();
   1.393 +			break;
   1.394 +		}
   1.395 +	((CTGetPixelStep*)iStep)->RecordTestResultL();
   1.396 +	}
   1.397 +	
   1.398 +__WS_CONSTRUCT_STEP__(GetPixel)