os/graphics/windowing/windowserver/test/tauto/TGETPIXEL.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// GETPIXEL.CPP
sl@0
    15
// Automatically test GetPixel
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
/**
sl@0
    20
 @file
sl@0
    21
 @test
sl@0
    22
 @internalComponent - Internal Symbian test code
sl@0
    23
*/
sl@0
    24
sl@0
    25
#include "TGETPIXEL.H"
sl@0
    26
sl@0
    27
CTGetPixel::CTGetPixel(CTestStep* aStep):
sl@0
    28
	CTWsGraphicsBase(aStep)
sl@0
    29
	{
sl@0
    30
	}
sl@0
    31
sl@0
    32
CTGetPixel::~CTGetPixel()
sl@0
    33
	{
sl@0
    34
	iWindow.Close();
sl@0
    35
	User::Free(iRgbBuf);
sl@0
    36
	}
sl@0
    37
sl@0
    38
LOCAL_C TInt DoPanicTest(TInt aFunc, TAny *aScreenNumber)
sl@0
    39
	{
sl@0
    40
	RWsSession ws;
sl@0
    41
	if (ws.Connect()==KErrNone)
sl@0
    42
		switch(aFunc)
sl@0
    43
			{
sl@0
    44
			case 1:	// Get pixels into a TPtr 1 pixel too small
sl@0
    45
				{
sl@0
    46
				CWsScreenDevice *screen = new(ELeave) CWsScreenDevice(ws);
sl@0
    47
				User::LeaveIfError(screen->Construct((TInt)aScreenNumber));
sl@0
    48
				CFbsBitmap *bitmap=new(ELeave) CFbsBitmap();
sl@0
    49
				TInt bitWid=80;
sl@0
    50
				TRgb *buf=NULL;
sl@0
    51
				if (bitmap->Create(TSize(1,bitWid), EGray16)==KErrNone && (buf=(TRgb *)User::Alloc((bitWid-1)*sizeof(TRgb)))!=NULL)
sl@0
    52
					{
sl@0
    53
					TPtr8 desc((TUint8 *)buf,(bitWid-1)*sizeof(TRgb));
sl@0
    54
    				screen->GetScanLine(desc,TPoint(0,0),bitWid, ERgb);
sl@0
    55
					}
sl@0
    56
				}
sl@0
    57
				break;
sl@0
    58
			}
sl@0
    59
	return(EWsExitReasonBad);
sl@0
    60
	}
sl@0
    61
sl@0
    62
void CTGetPixel::ClearOutRedraws()
sl@0
    63
// This has been added because partial redraw store can be triggered to request a
sl@0
    64
// low priority redraw from the window even though in normal circumstances the window
sl@0
    65
// would not expect to receive any sort of redraw event.
sl@0
    66
	{
sl@0
    67
	iWindow.BeginRedraw();
sl@0
    68
	iWindow.EndRedraw();
sl@0
    69
	}
sl@0
    70
sl@0
    71
void CTGetPixel::TestPanicsL()
sl@0
    72
	{
sl@0
    73
	if (!iTest->IsFullRomL())
sl@0
    74
		{
sl@0
    75
		TEST(iTest->TestWsPanicL(DoPanicTest,EWservPanicInvalidParameter,1,(TAny*)iTest->iScreenNumber));
sl@0
    76
		}
sl@0
    77
	}
sl@0
    78
sl@0
    79
void CTGetPixel::DrawAndCheckLine(const TPoint &aPos,TInt aLen,TRgb aColor)
sl@0
    80
	{
sl@0
    81
	TheGc->Activate(iWindow);
sl@0
    82
	TheGc->SetPenColor(aColor);
sl@0
    83
	iWindow.BeginRedraw(TRect(aPos,TSize(aLen, 1)));
sl@0
    84
	TheGc->DrawLine(aPos,aPos+TSize(aLen,0));
sl@0
    85
	iWindow.EndRedraw();
sl@0
    86
	TheGc->Deactivate();
sl@0
    87
	iRgbBuf=(TRgb *)User::ReAlloc(iRgbBuf,aLen*sizeof(TRgb));
sl@0
    88
	TPtr8 ptr((TUint8 *)iRgbBuf,aLen*sizeof(TRgb));
sl@0
    89
	TheClient->iScreen->GetScanLine(ptr, aPos+iWindow.InquireOffset(*TheClient->iGroup->WinTreeNode()), aLen, EColor16MA);
sl@0
    90
	TRgb result(TRgb::Gray16(aColor.Gray16()));
sl@0
    91
	if (TheClient->iScreen->DisplayMode()==EColor64K)
sl@0
    92
		result=TRgb::Color64K(result.Color64K());
sl@0
    93
	for(TInt index=0;index<aLen;index++)
sl@0
    94
		{
sl@0
    95
		TEST(iRgbBuf[index]==result);
sl@0
    96
		}
sl@0
    97
	}
sl@0
    98
sl@0
    99
void CTGetPixel::ConstructL()
sl@0
   100
	{
sl@0
   101
	iWindow = TheClient->iWs;
sl@0
   102
	TheGc->Activate(*BaseWin->Win());
sl@0
   103
	TheGc->Clear();
sl@0
   104
	TheGc->SetBrushColor(TRgb::Gray16(0));
sl@0
   105
	TheGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   106
	TheGc->SetPenStyle(CGraphicsContext::ENullPen);
sl@0
   107
	TheGc->DrawRect(TRect(iWinSize));
sl@0
   108
	TheGc->Deactivate();
sl@0
   109
	
sl@0
   110
	iWindow.Construct(*TheClient->iGroup->GroupWin(),ENullWsHandle);
sl@0
   111
	iWinSize=TSize(TheClient->iScreen->SizeInPixels());
sl@0
   112
	iWinSize.iWidth/=3;
sl@0
   113
	iWinSize.iHeight/=3;
sl@0
   114
	iWindow.SetRequiredDisplayMode(EGray16);
sl@0
   115
	TheClient->iWs.Flush();
sl@0
   116
	iTest->DelayIfFullRomL();	// Need to wait for view server to mess around when display mode changed
sl@0
   117
	TheClient->WaitForRedrawsToFinish();// otherwise it will stomp on top of our window invalidating it.
sl@0
   118
	iWindow.SetExtent(TPoint(iWinSize.iWidth,iWinSize.iHeight),iWinSize);
sl@0
   119
	iWindow.EnableRedrawStore(EFalse);	// Otherwise drawing might trigger a redraw when purging redraw store
sl@0
   120
	
sl@0
   121
	iWindow.Activate();
sl@0
   122
	iWindow.BeginRedraw();
sl@0
   123
	iWindow.EndRedraw();
sl@0
   124
		
sl@0
   125
	}
sl@0
   126
sl@0
   127
void CTGetPixel::TestCheckRect()
sl@0
   128
	{
sl@0
   129
	TSize size(TheClient->iScreen->SizeInPixels());
sl@0
   130
	TEST(TheClient->iScreen->RectCompare(TRect(size),TRect(TPoint(iTest->StdTestWindowSize().iWidth>>1,0),iTest->StdTestWindowSize()))==EFalse);
sl@0
   131
	}
sl@0
   132
sl@0
   133
void CTGetPixel::DrawColorsL()
sl@0
   134
	{
sl@0
   135
	TPoint point(0,0);
sl@0
   136
	TInt color=-1;
sl@0
   137
	iWindow.BeginRedraw();
sl@0
   138
	FOREVER
sl@0
   139
		{
sl@0
   140
		TheGc->SetPenColor(TRgb::Color256(++color));
sl@0
   141
		TheGc->Plot(point);
sl@0
   142
		if (color==255)
sl@0
   143
			break;
sl@0
   144
		if (++point.iX==iWinSize.iWidth)
sl@0
   145
			{
sl@0
   146
			point.iX=0;
sl@0
   147
			if (++point.iY==iWinSize.iHeight)
sl@0
   148
				break;
sl@0
   149
			}
sl@0
   150
		}
sl@0
   151
	iWindow.EndRedraw();
sl@0
   152
	}
sl@0
   153
sl@0
   154
void CTGetPixel::TestColors(CPalette* aPalette)
sl@0
   155
	{
sl@0
   156
	TInt numColors=iWinSize.iWidth;
sl@0
   157
	TPtr8 ptr(REINTERPRET_CAST(TUint8*,iRgbBuf),numColors*sizeof(TRgb));
sl@0
   158
	TPtr8 paletteData(NULL,0);
sl@0
   159
	TInt color=0;
sl@0
   160
	TPoint point(iWinSize.AsPoint());
sl@0
   161
	do	{
sl@0
   162
		if (color+numColors>256)
sl@0
   163
			numColors=256-color;
sl@0
   164
		TheClient->iScreen->GetScanLine(ptr,point,numColors,EColor16MA);
sl@0
   165
		aPalette->GetDataPtr(color,numColors,paletteData);
sl@0
   166
		TEST(ptr==paletteData);
sl@0
   167
		color+=numColors;
sl@0
   168
		} while (color<256 && ++point.iY<2*iWinSize.iHeight);
sl@0
   169
	}
sl@0
   170
sl@0
   171
void CTGetPixel::CheckPaletteL(CPalette*& aPalette)
sl@0
   172
	{
sl@0
   173
	User::LeaveIfError(TheClient->iScreen->SetCustomPalette(aPalette));
sl@0
   174
	TestColors(aPalette);
sl@0
   175
	delete aPalette;
sl@0
   176
	User::LeaveIfError(TheClient->iScreen->GetPalette(aPalette));
sl@0
   177
	TestColors(aPalette);
sl@0
   178
	}
sl@0
   179
sl@0
   180
inline TInt Inc(TInt& aValue)
sl@0
   181
	{
sl@0
   182
	if (aValue>255-83)
sl@0
   183
		aValue-=256-83;
sl@0
   184
	else
sl@0
   185
		aValue+=83;
sl@0
   186
	return aValue;
sl@0
   187
	}
sl@0
   188
sl@0
   189
inline TInt Inc2(TInt& aValue)
sl@0
   190
	{
sl@0
   191
	if (aValue>255-41)
sl@0
   192
		aValue-=256-41;
sl@0
   193
	else
sl@0
   194
		aValue+=41;
sl@0
   195
	return aValue;
sl@0
   196
	}
sl@0
   197
sl@0
   198
void CTGetPixel::PaletteTestL()
sl@0
   199
	{
sl@0
   200
	//INFO_PRINTF1(_L("AUTO  PaletteTest "));
sl@0
   201
	TInt numEntries;
sl@0
   202
	TBool modifiable;
sl@0
   203
	TheClient->iScreen->PaletteAttributes(modifiable,numEntries);
sl@0
   204
	INFO_PRINTF2(_L("Number of entries in the palette %d"), numEntries);
sl@0
   205
	if(numEntries > 65536)
sl@0
   206
		{
sl@0
   207
		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"));
sl@0
   208
		return; 
sl@0
   209
		}
sl@0
   210
	CPalette* palette=NULL;
sl@0
   211
	if (!modifiable)
sl@0
   212
		{
sl@0
   213
		if (numEntries==4)
sl@0
   214
			palette=CPalette::NewDefaultL(EGray4);
sl@0
   215
		else if (numEntries==16)
sl@0
   216
			palette=CPalette::NewDefaultL(EGray16);
sl@0
   217
		else
sl@0
   218
			palette=CPalette::NewL(numEntries);
sl@0
   219
		//INFO_PRINTF1(_L(" Creating Empty Palette, setting it as palette"));
sl@0
   220
		TInt err=TheClient->iScreen->SetCustomPalette(palette);
sl@0
   221
		TEST(err==KErrNoMemory || err==KErrNotSupported || (err==KErrNone && numEntries<=16));		//Series5MX palettes are changeable even though they say they aren't
sl@0
   222
		//INFO_PRINTF1(_L(" Palette setting test passed OK"));
sl@0
   223
		delete palette;
sl@0
   224
		}
sl@0
   225
	TInt err=iWindow.SetRequiredDisplayMode(EColor256);
sl@0
   226
	TheGc->Activate(iWindow);
sl@0
   227
	DrawColorsL();
sl@0
   228
	//INFO_PRINTF1(_L(" Drawn Colors"));
sl@0
   229
	TheClient->iScreen->PaletteAttributes(modifiable,numEntries);
sl@0
   230
	iRgbBuf=STATIC_CAST(TRgb*,User::ReAllocL(iRgbBuf,Max(256,iWinSize.iWidth)*sizeof(TRgb)));
sl@0
   231
	if (err<KErrNone || modifiable==EFalse)
sl@0
   232
		{
sl@0
   233
		//INFO_PRINTF1(_L(" Palette Fixed"));
sl@0
   234
		TInt err=TheClient->iScreen->GetPalette(palette);
sl@0
   235
		if (err==KErrNotSupported)
sl@0
   236
			return;
sl@0
   237
		User::LeaveIfError(err);
sl@0
   238
		TestColors(palette);
sl@0
   239
		delete palette;
sl@0
   240
		//INFO_PRINTF1(_L(" Tested Palette OK"));
sl@0
   241
		return;
sl@0
   242
		}
sl@0
   243
	//INFO_PRINTF1(_L(" Palette Changeable"));
sl@0
   244
	TEST(numEntries==256);
sl@0
   245
	CPalette* defPalette=CPalette::NewDefaultL(EColor256);
sl@0
   246
	CleanupStack::PushL(defPalette);
sl@0
   247
	TestColors(defPalette);
sl@0
   248
	User::LeaveIfError(TheClient->iScreen->GetPalette(palette));
sl@0
   249
	TestColors(palette);
sl@0
   250
	TInt color;
sl@0
   251
	TInt index=0;
sl@0
   252
	for (color=0;color<256;++color)
sl@0
   253
		palette->SetEntry(color,TRgb::Gray256(color));
sl@0
   254
	CheckPaletteL(palette);
sl@0
   255
	for (color=0;color<256;++color)
sl@0
   256
		palette->SetEntry(color,TRgb(Inc(index),Inc(index),Inc(index)));
sl@0
   257
	CheckPaletteL(palette);
sl@0
   258
	for (color=0;color<256;++color)
sl@0
   259
		palette->SetEntry(color,TRgb(Inc2(index),Inc2(index),Inc2(index)));
sl@0
   260
	CheckPaletteL(palette);
sl@0
   261
	delete palette;
sl@0
   262
	User::LeaveIfError(TheClient->iScreen->SetCustomPalette(defPalette));
sl@0
   263
	TestColors(defPalette);
sl@0
   264
	CleanupStack::PopAndDestroy(defPalette);
sl@0
   265
	ClearOutRedraws();
sl@0
   266
	}
sl@0
   267
sl@0
   268
void CTGetPixel::RunTestCaseL(TInt /*aCurTestCase*/)
sl@0
   269
	{
sl@0
   270
	((CTGetPixelStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
sl@0
   271
	switch(++iTest->iState)
sl@0
   272
		{
sl@0
   273
/**
sl@0
   274
@SYMTestCaseID		GRAPHICS-WSERV-0212
sl@0
   275
sl@0
   276
@SYMDEF             DEF081259
sl@0
   277
sl@0
   278
@SYMTestCaseDesc    Draw lines and check them by scanning the lines
sl@0
   279
sl@0
   280
@SYMTestPriority    High
sl@0
   281
sl@0
   282
@SYMTestStatus      Implemented
sl@0
   283
sl@0
   284
@SYMTestActions     Draw lines and then scan them to check that they have
sl@0
   285
					been drawn correctly
sl@0
   286
sl@0
   287
@SYMTestExpectedResults Scanning the lines reveals they have been drawn correctly
sl@0
   288
*/
sl@0
   289
		case 1:
sl@0
   290
			((CTGetPixelStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0212"));
sl@0
   291
			TheClient->iWs.SetAutoFlush(ETrue);
sl@0
   292
			iTest->LogSubTest(_L("Basic"));
sl@0
   293
			DrawAndCheckLine(TPoint(0,2),iWinSize.iWidth-2,TRgb::Gray4(0));
sl@0
   294
			DrawAndCheckLine(TPoint(0,iWinSize.iHeight-2),iWinSize.iWidth,TRgb::Gray4(1));
sl@0
   295
			DrawAndCheckLine(TPoint(iWinSize.iWidth-1,iWinSize.iHeight-1),1,TRgb::Gray4(2));
sl@0
   296
			ClearOutRedraws();
sl@0
   297
			TheClient->iWs.SetAutoFlush(EFalse);
sl@0
   298
			break;
sl@0
   299
/**
sl@0
   300
@SYMTestCaseID		GRAPHICS-WSERV-0213
sl@0
   301
sl@0
   302
@SYMDEF             DEF081259
sl@0
   303
sl@0
   304
@SYMTestCaseDesc    Draw line on every line of a window and
sl@0
   305
					check them by scanning the lines
sl@0
   306
sl@0
   307
@SYMTestPriority    High
sl@0
   308
sl@0
   309
@SYMTestStatus      Implemented
sl@0
   310
sl@0
   311
@SYMTestActions     Draw lines on every line of a window and
sl@0
   312
					check them by scanning the lines
sl@0
   313
sl@0
   314
@SYMTestExpectedResults Scanning the lines reveals they have been drawn correctly
sl@0
   315
*/
sl@0
   316
sl@0
   317
		case 2:
sl@0
   318
			{
sl@0
   319
			((CTGetPixelStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0213"));
sl@0
   320
			iTest->LogSubTest(_L("Full window"));
sl@0
   321
			for(TInt ypos=0;ypos<iWinSize.iHeight;ypos++)
sl@0
   322
				DrawAndCheckLine(TPoint(0,ypos),iWinSize.iWidth,TRgb::Gray4(0));
sl@0
   323
			ClearOutRedraws();
sl@0
   324
			}
sl@0
   325
			break;
sl@0
   326
/**
sl@0
   327
@SYMTestCaseID		GRAPHICS-WSERV-0214
sl@0
   328
sl@0
   329
@SYMDEF             DEF081259
sl@0
   330
sl@0
   331
@SYMTestCaseDesc    Test the check rect method 
sl@0
   332
sl@0
   333
@SYMTestPriority    High
sl@0
   334
sl@0
   335
@SYMTestStatus      Implemented
sl@0
   336
sl@0
   337
@SYMTestActions     Use the check rect method to check the image in a window
sl@0
   338
sl@0
   339
@SYMTestExpectedResults The check rect method functions correctly
sl@0
   340
*/
sl@0
   341
		case 3:
sl@0
   342
			((CTGetPixelStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0214"));
sl@0
   343
			iTest->LogSubTest(_L("Check Rect"));
sl@0
   344
			TestCheckRect();
sl@0
   345
			break;
sl@0
   346
/**
sl@0
   347
@SYMTestCaseID		GRAPHICS-WSERV-0215
sl@0
   348
sl@0
   349
@SYMDEF             DEF081259
sl@0
   350
sl@0
   351
@SYMTestCaseDesc    Test that the GetScanLine method panics correctly 
sl@0
   352
sl@0
   353
@SYMTestPriority    High
sl@0
   354
sl@0
   355
@SYMTestStatus      Implemented
sl@0
   356
sl@0
   357
@SYMTestActions     Cause the GetScanLine method to panic and chekc the response
sl@0
   358
sl@0
   359
@SYMTestExpectedResults The panic for the GetScanLine method is correct
sl@0
   360
*/
sl@0
   361
		case 4:
sl@0
   362
			((CTGetPixelStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0215"));
sl@0
   363
			iTest->LogSubTest(_L("Panic"));
sl@0
   364
			TestPanicsL();
sl@0
   365
			break;
sl@0
   366
/**
sl@0
   367
@SYMTestCaseID		GRAPHICS-WSERV-0216
sl@0
   368
sl@0
   369
@SYMDEF             DEF081259
sl@0
   370
sl@0
   371
@SYMTestCaseDesc    Test that CPalette class functions correctly 
sl@0
   372
sl@0
   373
@SYMTestPriority    High
sl@0
   374
sl@0
   375
@SYMTestStatus      Implemented
sl@0
   376
sl@0
   377
@SYMTestActions     Create a CPalette object and exercise all its methods
sl@0
   378
sl@0
   379
@SYMTestExpectedResults The palette functions as exepcted
sl@0
   380
*/
sl@0
   381
		case 5:
sl@0
   382
			((CTGetPixelStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0216"));
sl@0
   383
			iTest->LogSubTest(_L("Palette Test"));
sl@0
   384
			PaletteTestL();
sl@0
   385
			break;
sl@0
   386
		case 6:
sl@0
   387
            		((CTGetPixelStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
sl@0
   388
			((CTGetPixelStep*)iStep)->CloseTMSGraphicsStep();
sl@0
   389
			TestComplete();
sl@0
   390
			break;
sl@0
   391
		}
sl@0
   392
	((CTGetPixelStep*)iStep)->RecordTestResultL();
sl@0
   393
	}
sl@0
   394
	
sl@0
   395
__WS_CONSTRUCT_STEP__(GetPixel)