os/graphics/windowing/windowserver/test/tauto/TSCRDEV.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.
     1 // Copyright (c) 1996-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 // Screen device test code
    15 // 
    16 //
    17 
    18 /**
    19  @file
    20  @test
    21  @internalComponent - Internal Symbian test code
    22 */
    23 
    24 #include "TSCRDEV.H"
    25 
    26 //Define this to get visible pauses (in test 6: DeviceResSwitchL)
    27 //#define VISIBLE_PAUSES
    28 
    29 //Define this to get extra logging which may be useful in tracking down a fail
    30 //#define EXTRA_LOGGING
    31 
    32 CTScreenDevice::CTScreenDevice(CTestStep* aStep) : CTWsGraphicsBase(aStep)
    33 	{}
    34 
    35 CTScreenDevice::~CTScreenDevice()
    36 	{}
    37 
    38 void CTScreenDevice::ConstructL()
    39 	{
    40 	//The following is just another test... it doesn't leave any resources for use by the test class AFAICT...
    41 	RWsSession aSession;
    42 	CWsScreenDevice *device1;
    43 	CWsScreenDevice *device2;
    44 	CWsScreenDevice *device3;
    45 
    46 	aSession.Connect();
    47 	device1=new(ELeave) CWsScreenDevice(aSession);
    48 	device1->Construct(iTest->iScreenNumber);
    49 	delete device1;
    50 	device1=new(ELeave) CWsScreenDevice(aSession);
    51 	device1->Construct(iTest->iScreenNumber);
    52 	device2=new(ELeave) CWsScreenDevice(aSession);
    53 	device2->Construct(iTest->iScreenNumber);
    54 	device3=new(ELeave) CWsScreenDevice(aSession);
    55 	device3->Construct(iTest->iScreenNumber);
    56 	delete device3;
    57 	CFbsFont *font;
    58 	User::LeaveIfError(device1->GetNearestFontToDesignHeightInTwips((CFont *&)font,TFontSpec()));
    59 	RWindowGroup group(aSession);
    60 	group.Construct(777);
    61 	group.SetOwningWindowGroup(TheClient->iGroup->GroupWin()->Identifier());
    62 	RWindow win(aSession);
    63 	win.Construct(group,77);
    64 	CWindowGc *gc=new(ELeave) CWindowGc(device1);
    65 	gc->Construct();
    66 	gc->Activate(win);
    67 	gc->UseFont(font);
    68 	device1->ReleaseFont(font);
    69 	aSession.Flush();
    70 	delete gc;
    71 	win.Close();
    72 	group.Close();
    73 	delete device1;
    74 	delete device2;
    75 	aSession.Close();
    76 	}
    77 
    78 
    79 void CTScreenDevice::TestTwipPixelConversions()
    80 	{
    81 	TInt result=TheClient->iScreen->HorizontalTwipsToPixels(TheClient->iScreen->HorizontalPixelsToTwips(1234));
    82 	TEST(result==1234);
    83 	if (result!=1234)
    84 		INFO_PRINTF3(_L("TheClient->iScreen->HorizontalTwipsToPixels(TheClient->iScreen->HorizontalPixelsToTwips(1234) return value  - Expected: %d, Actual: %d"), 1234, result);
    85 
    86 	result=TheClient->iScreen->VerticalTwipsToPixels(TheClient->iScreen->VerticalPixelsToTwips(1234));
    87 	TEST(result==1234);
    88 	if (result!=1234)
    89 		INFO_PRINTF3(_L("TheClient->iScreen->VerticalTwipsToPixels(TheClient->iScreen->VerticalPixelsToTwips(1234) return value  - Expected: %d, Actual: %d"), 1234, result);
    90 
    91 	TSize pixels=TheClient->iScreen->SizeInPixels();
    92 	TSize twips=TheClient->iScreen->SizeInTwips();
    93 	TInt conv=TheClient->iScreen->HorizontalPixelsToTwips(pixels.iWidth);
    94 	TEST(conv==twips.iWidth);
    95 	if (conv!=twips.iWidth)
    96 		INFO_PRINTF3(_L("TheClient->iScreen->HorizontalPixelsToTwips(pixels.iWidth) return value  - Expected: %d, Actual: %d"), twips.iWidth, conv);
    97 
    98 	conv=TheClient->iScreen->VerticalPixelsToTwips(pixels.iHeight);
    99 	TEST(conv==twips.iHeight);
   100 	if (conv!=twips.iHeight)
   101 		INFO_PRINTF3(_L("TheClient->iScreen->VerticalPixelsToTwips(pixels.iHeight) return value  - Expected: %d, Actual: %d"), twips.iHeight, conv);
   102 	}
   103 
   104 #define TEST_VALUE 100000000
   105 void CTScreenDevice::TestTwipPixelOverflow()
   106 	{
   107 	TInt result=TheClient->iScreen->HorizontalTwipsToPixels(TheClient->iScreen->HorizontalPixelsToTwips(TEST_VALUE));
   108 	TEST(result==TEST_VALUE);
   109 	if (result!=TEST_VALUE)
   110 		INFO_PRINTF3(_L("TheClient->iScreen->HorizontalTwipsToPixels(TheClient->iScreen->HorizontalPixelsToTwips(TEST_VALUE)) return value  - Expected: %d, Actual: %d"), TEST_VALUE, result);
   111 
   112 	result=TheClient->iScreen->VerticalTwipsToPixels(TheClient->iScreen->VerticalPixelsToTwips(TEST_VALUE));
   113 	TEST(result==TEST_VALUE);
   114 	if (result!=TEST_VALUE)
   115 		INFO_PRINTF3(_L("TheClient->iScreen->VerticalTwipsToPixels(TheClient->iScreen->VerticalPixelsToTwips(TEST_VALUE)) return value  - Expected: %d, Actual: %d"), TEST_VALUE, result);
   116 
   117 	result = TheClient->iScreen->HorizontalPixelsToTwips(TEST_VALUE);
   118 	TEST(result>0);
   119 	if (!result>0)
   120 		INFO_PRINTF3(_L("TheClient->iScreen->HorizontalPixelsToTwips(TEST_VALUE) return value  - Expected: %d less than, Actual: %d"), 0, result);
   121 
   122 	result = TheClient->iScreen->VerticalPixelsToTwips(TEST_VALUE);
   123 	TEST(result>0);
   124 	if (!result>0)
   125 		INFO_PRINTF3(_L("TheClient->iScreen->VerticalPixelsToTwips(TEST_VALUE) return value  - Expected: %d less than, Actual: %d"), 0, result);
   126 
   127 	result = TheClient->iScreen->HorizontalTwipsToPixels(TEST_VALUE);
   128 	TEST(result>0);
   129 	if (!result>0)
   130 		INFO_PRINTF3(_L("TheClient->iScreen->HorizontalTwipsToPixels(TEST_VALUE) return value  - Expected: %d less than, Actual: %d"), 0, result);
   131 
   132 	result = TheClient->iScreen->VerticalTwipsToPixels(TEST_VALUE);
   133 	TEST(result>0);
   134 	if (!result>0)
   135 		INFO_PRINTF3(_L("TheClient->iScreen->VerticalTwipsToPixels(TEST_VALUE) return value  - Expected: %d less than, Actual: %d"), 0, result);
   136 	}
   137 
   138 void CTScreenDevice::TwipsCacheFlushL()
   139 	{
   140 	RWsSession session;
   141 	CWsScreenDevice* device;
   142 	CFont* font;
   143 	CFont* font2;
   144 	const TFontSpec fontspec(KTestFontTypefaceName,250);
   145 	TPixelsTwipsAndRotation sizeAndRotation;
   146 
   147 	// create a CWsScreenDevice instance
   148 	User::LeaveIfError(session.Connect());
   149 	device=new(ELeave) CWsScreenDevice(session);
   150 	device->Construct(iTest->iScreenNumber);
   151 
   152 	// Record a font height for use by latter tests
   153 	User::LeaveIfError(device->GetNearestFontToDesignHeightInTwips(font,fontspec));
   154 	const TInt height0=font->HeightInPixels();
   155 	device->ReleaseFont(font);
   156 
   157 	// 1. find font with best-matching height in twips,
   158 	// 2. change twips size of the screen (leaving pixel-size same),
   159 	// 3. find font with best-matching height in twips,
   160 	// 4. make sure that the newly found font is not the same as previous and has the different height in pixels
   161 	device->GetDefaultScreenSizeAndRotation(sizeAndRotation);
   162 #if defined(EXTRA_LOGGING)
   163 	_LIT(KLog1,"Font height: %d for unchanged device.   pixels=%d,%d  twips=%d,%d");
   164 	LOG_MESSAGE6(KLog1,height0,sizeAndRotation.iPixelSize.iWidth,sizeAndRotation.iPixelSize.iHeight
   165 						,sizeAndRotation.iTwipsSize.iWidth,sizeAndRotation.iTwipsSize.iHeight);
   166 #endif
   167 	sizeAndRotation.iTwipsSize.iHeight=2000;
   168 	sizeAndRotation.iTwipsSize.iWidth =3000;
   169 	device->SetScreenSizeAndRotation(sizeAndRotation);
   170 
   171 	User::LeaveIfError(device->GetNearestFontToDesignHeightInTwips(font,fontspec));
   172 	TInt height=font->HeightInPixels();
   173 #if defined(EXTRA_LOGGING)
   174 	_LIT(KLog2,"Font height: %d for device with twips set to 2000x3000");
   175 	LOG_MESSAGE2(KLog2,height);
   176 #endif
   177 	TFontSpec returnedSpec=font->FontSpecInTwips();
   178 
   179 	sizeAndRotation.iTwipsSize.iHeight=4000;
   180 	sizeAndRotation.iTwipsSize.iWidth =6000;
   181 	device->SetScreenSizeAndRotation(sizeAndRotation);
   182 
   183 	User::LeaveIfError(device->GetNearestFontToDesignHeightInTwips(font2,fontspec));
   184 	TInt height2=font2->HeightInPixels();
   185 	TFontSpec returnedSpec2 = font2->FontSpecInTwips();
   186 #if defined(EXTRA_LOGGING)
   187 	_LIT(KLog3,"Font height: %d for device with twips set to 4000x6000");
   188 	LOG_MESSAGE2(KLog3,height2);
   189 #endif
   190 
   191 	TEST(font!=font2);
   192 	TEST(height!=height2);
   193 	_LIT(KLogErrM,"Font Heights in pixels match unexpectantly, height=%d");
   194 	if (height==height2)
   195 		INFO_PRINTF2(KLogErrM,height);
   196 
   197 	device->ReleaseFont(font2);
   198 	device->ReleaseFont(font);
   199 
   200 	// 1. find font with best-matching height in twips,
   201 	// 2. change pixel size of the screen (leaving twip-size same),
   202 	// 3. find font with best-matching height in twips,
   203 	// 4. make sure that the newly found font is not the same as previous and has the different height in pixels
   204 	device->GetDefaultScreenSizeAndRotation(sizeAndRotation);
   205 	sizeAndRotation.iPixelSize.iHeight=240;
   206 	sizeAndRotation.iPixelSize.iWidth =640;
   207 	device->SetScreenSizeAndRotation(sizeAndRotation);
   208 
   209 	User::LeaveIfError(device->GetNearestFontToDesignHeightInTwips(font,fontspec));
   210 	height=font->HeightInPixels();
   211 	returnedSpec=font->FontSpecInTwips();
   212 #if defined(EXTRA_LOGGING)
   213 	_LIT(KLog4,"Font height: %d for device with pixels set to 240x640   twips=%d,%d");
   214 	LOG_MESSAGE4(KLog4,height,sizeAndRotation.iTwipsSize.iWidth,sizeAndRotation.iTwipsSize.iHeight);
   215 #endif
   216 
   217 	sizeAndRotation.iPixelSize.iHeight=480;
   218 	sizeAndRotation.iPixelSize.iWidth =1280;
   219 	device->SetScreenSizeAndRotation(sizeAndRotation);
   220 
   221 	User::LeaveIfError(device->GetNearestFontToDesignHeightInTwips(font2,fontspec));
   222 	height2=font2->HeightInPixels();
   223 	returnedSpec2=font2->FontSpecInTwips();
   224 #if defined(EXTRA_LOGGING)
   225 	_LIT(KLog5,"Font height: %d for device with pixels set to 480x1280");
   226 	LOG_MESSAGE2(KLog5,height2);
   227 #endif
   228 
   229 	TEST(font!=font2);
   230 	TEST(height!=height2);
   231 	if (height==height2)
   232 		INFO_PRINTF2(KLogErrM,height);
   233 
   234 	device->ReleaseFont(font2);
   235 	device->ReleaseFont(font);
   236 
   237 	// 1. double the width and height of screen in both pixels and twips
   238 	// 2. find font with best-matching height in twips,
   239 	// 3. make sure that the newly found font is the same as previous and has the same height in pixels
   240 	device->GetDefaultScreenSizeAndRotation(sizeAndRotation);
   241 	device->SetScreenSizeAndRotation(sizeAndRotation);
   242 	User::LeaveIfError(device->GetNearestFontToDesignHeightInTwips(font,fontspec));
   243 	sizeAndRotation.iPixelSize.iHeight*=2;
   244 	sizeAndRotation.iPixelSize.iWidth *=2;
   245 	sizeAndRotation.iTwipsSize.iHeight*=2;
   246 	sizeAndRotation.iTwipsSize.iWidth *=2;
   247 	device->SetScreenSizeAndRotation(sizeAndRotation);
   248 
   249 	User::LeaveIfError(device->GetNearestFontToDesignHeightInTwips(font2,fontspec));
   250 	height2=font2->HeightInPixels();
   251 #if defined(EXTRA_LOGGING)
   252 	_LIT(KLog6,"Font height: %d for device doubled size.   pixels=%d,%d  twips=%d,%d");
   253 	LOG_MESSAGE6(KLog6,height2,sizeAndRotation.iPixelSize.iWidth,sizeAndRotation.iPixelSize.iHeight
   254 							,sizeAndRotation.iTwipsSize.iWidth,sizeAndRotation.iTwipsSize.iHeight);
   255 #endif
   256 
   257 	TEST(font==font2);
   258 	TEST(height0==height2);
   259 	_LIT(KLogErrD,"Font Heights in pixels don't match, expected=%d, actual=%d");
   260 	if (height0!=height2)
   261 		INFO_PRINTF3(KLogErrD,height0,height2);
   262 
   263 	device->ReleaseFont(font2);
   264 	device->ReleaseFont(font);
   265 
   266 	// 1. swap width and height sizes of screen for both pixels and twips
   267 	// 2. find font with best-matching height in twips,
   268 	// 3. make sure that the newly found font is the same as previous and has the same height in pixels
   269 	device->GetDefaultScreenSizeAndRotation(sizeAndRotation);
   270 	device->SetScreenSizeAndRotation(sizeAndRotation);
   271 	User::LeaveIfError(device->GetNearestFontToDesignHeightInTwips(font,fontspec));
   272 	TInt swap=sizeAndRotation.iPixelSize.iHeight;
   273 	sizeAndRotation.iPixelSize.iHeight=sizeAndRotation.iPixelSize.iWidth;
   274 	sizeAndRotation.iPixelSize.iWidth =swap;
   275 	swap=sizeAndRotation.iTwipsSize.iHeight;
   276 	sizeAndRotation.iTwipsSize.iHeight=sizeAndRotation.iTwipsSize.iWidth;
   277 	sizeAndRotation.iTwipsSize.iWidth =swap;
   278 	device->SetScreenSizeAndRotation(sizeAndRotation);
   279 	User::LeaveIfError(device->GetNearestFontToDesignHeightInTwips(font2,fontspec));
   280 	height2 = font2->HeightInPixels();
   281 #if defined(EXTRA_LOGGING)
   282 	_LIT(KLog7,"Font height: %d for device rotated size.   pixels=%d,%d  twips=%d,%d");
   283 	LOG_MESSAGE6(KLog7,height2,sizeAndRotation.iPixelSize.iWidth,sizeAndRotation.iPixelSize.iHeight
   284 							,sizeAndRotation.iTwipsSize.iWidth,sizeAndRotation.iTwipsSize.iHeight);
   285 #endif
   286 
   287 	TEST(font==font2);
   288 	TEST(height0==height2);
   289 	if (height0!=height2)
   290 		INFO_PRINTF3(KLogErrD,height0,height2);
   291 
   292 	device->ReleaseFont(font2);
   293 	device->ReleaseFont(font);
   294 
   295 	delete device;
   296 	session.Close();
   297 	}
   298 
   299 void CTScreenDevice::CheckBitmapL(CFbsBitmap *aBitmap, const TRect &aRect)
   300 	{
   301 	CFbsBitmapDevice *device=CFbsBitmapDevice::NewL(aBitmap);
   302 	CleanupStack::PushL(device);
   303 	TInt height=Min(aRect.Size().iHeight,aBitmap->SizeInPixels().iHeight);
   304 	TInt width=Min(aRect.Size().iWidth,aBitmap->SizeInPixels().iWidth);
   305 	TPoint pos(0,0);
   306 	TInt bufLen=CFbsBitmap::ScanLineLength(width,EGray4);
   307 	TAny *buf1=User::AllocLC(bufLen);
   308 	TAny *buf2=User::AllocLC(bufLen);
   309 	TPtr8 scanBuf1((TUint8 *)buf1,bufLen);
   310 	TPtr8 scanBuf2((TUint8 *)buf2,bufLen);
   311 	TInt oddPixels=width%4;
   312 	TInt byte1,byte2;
   313 	for(;pos.iY<height;pos.iY++)
   314 		{
   315 		TheClient->iScreen->GetScanLine(scanBuf1,pos+aRect.iTl,width,EGray4);
   316 		device->GetScanLine(scanBuf2,pos,width,EGray4);
   317 		if (oddPixels>0)
   318 			{
   319 			byte1=(scanBuf1[bufLen-1]<<(2*(4-oddPixels)))%256;
   320 			byte2=(scanBuf2[bufLen-1]<<(2*(4-oddPixels)))%256;
   321 			TEST(byte1==byte2);
   322 			if (byte1!=byte2)
   323 				INFO_PRINTF3(_L("byte1==byte2  - byte1: %d, byte2 Height: %d"), byte1, byte2);
   324 
   325 			scanBuf1=scanBuf1.Left(bufLen-1);
   326 			scanBuf2=scanBuf2.Left(bufLen-1);
   327 			}
   328 		TBool retVal = !scanBuf1.Compare(scanBuf2);
   329 		TEST(retVal);
   330 		if (!retVal)
   331 			INFO_PRINTF3(_L("!scanBuf1.Compare(scanBuf2) return value  - Expected: %d, Actual: %d"), ETrue, retVal);
   332 		}
   333 	CleanupStack::PopAndDestroy(3);
   334 	}
   335 
   336 void CTScreenDevice::doTestScreenToBitmapL()
   337 	{
   338 	RBlankWindow shieldWin(TheClient->iWs);
   339 	shieldWin.Construct(*TheClient->iGroup->GroupWin(),1);
   340 	shieldWin.SetOrdinalPosition(0,-1);
   341 	shieldWin.SetColor(TRgb::Gray4(1));
   342 	shieldWin.Activate();
   343 	CleanupStack::PushL(TCleanupItem(CleanUpWindow,&shieldWin));
   344 	TSize scrSize(TheClient->iScreen->SizeInPixels());
   345 	CWsBitmap *wsBitmap=new(ELeave) CWsBitmap(TheClient->iWs);
   346 	CleanupStack::PushL(wsBitmap);
   347 	User::LeaveIfError(wsBitmap->Create(scrSize,EGray4));
   348 	CFbsBitmap *bitmap=new(ELeave) CFbsBitmap;
   349 	CleanupStack::PushL(bitmap);
   350 
   351 	TheClient->iWs.Finish();
   352 	TheClient->WaitForRedrawsToFinish();
   353 	
   354 	User::LeaveIfError(bitmap->Create(TSize(30,10),EGray4));
   355 //
   356 	User::LeaveIfError(TheClient->iScreen->CopyScreenToBitmap(wsBitmap));
   357 	CheckBitmapL(wsBitmap,TRect(scrSize));
   358 //
   359 	User::LeaveIfError(TheClient->iScreen->CopyScreenToBitmap(bitmap));
   360 	CheckBitmapL(bitmap,TRect(scrSize));
   361 //
   362 	TRect rect1(111,10,222,20);
   363 	User::LeaveIfError(TheClient->iScreen->CopyScreenToBitmap(wsBitmap,rect1));
   364 	CheckBitmapL(wsBitmap,rect1);
   365 //
   366 	TRect rect2(10,20,100,200);
   367 	User::LeaveIfError(TheClient->iScreen->CopyScreenToBitmap(bitmap,rect2));
   368 	CheckBitmapL(bitmap,rect2);
   369 //
   370 // Now some mad values
   371 //
   372 // Right edge left of left edge
   373 	User::LeaveIfError(TheClient->iScreen->CopyScreenToBitmap(bitmap,TRect(100,20,90,200)));
   374 // Off the edge of the screen
   375 	User::LeaveIfError(TheClient->iScreen->CopyScreenToBitmap(bitmap,TRect(-10,20,-5,200)));
   376 // Off the edge of the screen again
   377 	User::LeaveIfError(TheClient->iScreen->CopyScreenToBitmap(bitmap,TRect(scrSize.AsPoint()+TPoint(5,5),TSize(10,10))));
   378 //
   379 	CleanupStack::PopAndDestroy(3);
   380 	}
   381 
   382 
   383 
   384 void CTScreenDevice::TestScreenToBitmap()
   385 	{
   386 	TRAPD(ret,doTestScreenToBitmapL());
   387 	TEST(ret==KErrNone);
   388 	if (ret!=KErrNone)
   389 		INFO_PRINTF3(_L("doTestScreenToBitmapL() return value  - Expected: %d, Actual: %d"), KErrNone, ret);
   390 	}
   391 	
   392 
   393 CCachePanic::~CCachePanic()
   394 	{
   395 	delete iWsScrDev;
   396 	iWs.Close();
   397 	}
   398 
   399 void CCachePanic::ConstructL(TInt aScreenNumber, TInt aInt)
   400 	{
   401 	iScreenNumber = aScreenNumber;
   402 	iInt = aInt;
   403 
   404 	User::LeaveIfError(iWs.Connect());
   405 	iWsScrDev=new(ELeave) CWsScreenDevice(iWs);
   406 	User::LeaveIfError(iWsScrDev->Construct(iScreenNumber));
   407 	}
   408 
   409 TInt CCachePanic::DoTest(CCachePanic* aTestClass)
   410 	{
   411 	CActiveScheduler* activeScheduler=new(ELeave) CActiveScheduler;
   412 	CActiveScheduler::Install(activeScheduler);
   413 	CleanupStack::PushL(activeScheduler);
   414 	TRAP_IGNORE(aTestClass->TestL());
   415 	CleanupStack::PopAndDestroy(activeScheduler);
   416 	return EWsExitReasonFinished;
   417 	}
   418 
   419 void CCachePanic::TestL()
   420 	{
   421 	AutoPanic(EAutoPanicTestFailed);
   422 	}
   423 
   424 TInt CTwipsPanic::RunTest(TInt aInt, TAny* aPtr)
   425 	{
   426 	TInt error = KErrNone;
   427 
   428 	CTwipsPanic* self=new(ELeave) CTwipsPanic();
   429 	CleanupStack::PushL(self);
   430 
   431 	TRAP(error, self->ConstructL((TInt)aPtr, aInt));
   432 	if (!error)
   433 		{
   434 		error = CCachePanic::DoTest(self);
   435 		}
   436 	CleanupStack::PopAndDestroy(self);
   437 	return error;
   438 	}
   439 
   440 void CTwipsPanic::TestL()
   441 	{
   442 	TPixelsTwipsAndRotation sizeAndRotation;
   443 	TFontSpec fontspec(KTestFontTypefaceName,250);
   444 
   445 	CFbsFont *font;
   446 	CFbsFont *font2;
   447 
   448 	iWsScrDev->GetDefaultScreenSizeAndRotation(sizeAndRotation);
   449 	sizeAndRotation.iTwipsSize.iHeight = 2000;
   450 	sizeAndRotation.iTwipsSize.iWidth  = 3000;
   451 	iWsScrDev->SetScreenSizeAndRotation(sizeAndRotation);
   452 	iWsScrDev->GetNearestFontToDesignHeightInTwips((CFont *&)font,fontspec);
   453 	iWsScrDev->GetNearestFontToDesignHeightInTwips((CFont *&)font2,fontspec);
   454 	sizeAndRotation.iTwipsSize.iHeight = 4000;
   455 	sizeAndRotation.iTwipsSize.iWidth  = 6000;
   456 	iWsScrDev->SetScreenSizeAndRotation(sizeAndRotation);
   457 	iWsScrDev->ReleaseFont(font);
   458 	}
   459 
   460 TInt CScanLinePanic::RunTest(TInt aInt, TAny* aPtr)
   461 	{
   462 	TInt error = KErrNone;
   463 
   464 	CScanLinePanic* self=new(ELeave) CScanLinePanic();
   465 	CleanupStack::PushL(self);
   466 
   467 	TRAP(error, self->ConstructL((TInt)aPtr, aInt));
   468 	if (!error)
   469 		{
   470 		error = CCachePanic::DoTest(self);
   471 		}
   472 	CleanupStack::PopAndDestroy(self);
   473 	return error;    
   474 	}
   475 
   476 void CScanLinePanic::TestL()
   477 	{
   478 	switch (iInt)
   479 		{
   480 		case TESTCASE_GRAPHICS_WSERV_0473:
   481 			TestLengthInvariant();
   482 			break;
   483 		case TESTCASE_GRAPHICS_WSERV_0474:
   484 			TestBufferInvariant();
   485 			break;
   486 		}
   487 	}
   488 
   489 void CScanLinePanic::TestLengthInvariant()
   490 	{
   491 	TInt buffLength=50;
   492 	TInt length=-1;
   493 	TUint8* buffer=new(ELeave) TUint8[buffLength];
   494 	TPtr8 scanline(buffer, buffLength, buffLength);
   495 	iWsScrDev->GetScanLine(scanline, TPoint(), length, EColor64K);
   496 	delete buffer;    
   497 	}
   498 
   499 void CScanLinePanic::TestBufferInvariant()
   500 	{
   501 	TInt buffLength=19;
   502 	TInt length=10;
   503 	TUint8* buffer=new(ELeave) TUint8[buffLength];
   504 	TPtr8 scanline(buffer, buffLength, buffLength);
   505 	iWsScrDev->GetScanLine(scanline, TPoint(), length, EColor64K);
   506 	delete buffer;    
   507 	}
   508 
   509 void CTScreenDevice::RunTestCaseL(TInt /*aCurTestCase*/)
   510 	{
   511 	((CTScreenDeviceStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
   512 	switch(++iTest->iState)
   513 		{
   514 /**
   515 @SYMTestCaseID		GRAPHICS-WSERV-0080
   516 
   517 @SYMDEF  			DEF081259
   518 
   519 @SYMTestCaseDesc    Test twips to pixels conversions
   520 
   521 @SYMTestPriority    High
   522 
   523 @SYMTestStatus      Implemented
   524 
   525 @SYMTestActions     Converts pixels to twips and then back the result back to pixels. Checks screen size request methods both in pixels and twips
   526 
   527 @SYMTestExpectedResults Expects that back and forth conversions preserve an original value.
   528 */
   529 		case 1:
   530 			((CTScreenDeviceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0080"));
   531 			iTest->LogSubTest(_L("Screen Device 1"));
   532 			TestTwipPixelConversions();
   533 			break;
   534 /**
   535 @SYMTestCaseID		GRAPHICS-WSERV-0081
   536 
   537 @SYMDEF  			DEF081259
   538 
   539 @SYMTestCaseDesc    Tests CWsScreenDevice::CopyScreenToBitmap method
   540 
   541 @SYMTestPriority    High
   542 
   543 @SYMTestStatus      Implemented
   544 
   545 @SYMTestActions     Creates a blank window on the screen and uses CWsScreenDevice::CopyScreenToBitmap to copy parts of the screen image to either CWsBitmap or CFbsBitmap
   546 
   547 @SYMTestExpectedResults Expects that the method will not fail and that the image is copied correctly making pixel-to-pixel comparisons
   548 */
   549 		case 2:
   550 			((CTScreenDeviceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0081"));
   551 			iTest->LogSubTest(_L("Copy Screen To Bitmap"));
   552 			TestScreenToBitmap();
   553 			break;
   554 /**
   555 @SYMTestCaseID		GRAPHICS-WSERV-0082
   556 
   557 @SYMDEF  			DEF081259
   558 
   559 @SYMTestCaseDesc    Test for integrity of twips to pixels conversions providing big values
   560 
   561 @SYMTestPriority    High
   562 
   563 @SYMTestStatus      Implemented
   564 
   565 @SYMTestActions     Calls twips to pixels (and backward) conversions for 100000000 value
   566 
   567 @SYMTestExpectedResults Expects that back and forth conversions preserve an original value. Make sure that the result is always greater that 0.
   568 */
   569 		case 3:
   570 			((CTScreenDeviceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0082"));
   571 			iTest->LogSubTest(_L("Twip To Pixels Overflow"));
   572 			TestTwipPixelOverflow();
   573 			break;
   574 /**
   575 @SYMTestCaseID		GRAPHICS-WSERV-0083
   576 
   577 @SYMDEF  			DEF081259
   578 
   579 @SYMTestCaseDesc    Test that twips-in-pixel ratio change for screen size affects twips-in-pixel ratio of font
   580 
   581 @SYMTestPriority    High
   582 
   583 @SYMTestStatus      Implemented
   584 
   585 @SYMTestActions     Changes number of twips on screen (leaving number of pixels same), changes number of pixels on screen (leaving number of twips same), makes proportional changes of screen size for both twips and pixels
   586 
   587 @SYMTestExpectedResults Expects that twips-in-pixel ratio of font leaves the same only when screen size was changed through multipying of width by a coefficient (same for both twips and pixels) and multipying of height by a coefficient (same for both twips and pixels)
   588 */
   589 		case 4:
   590 			((CTScreenDeviceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0083"));
   591 			iTest->LogSubTest(_L("Twips cache flush after device size change"));
   592 			TwipsCacheFlushL();
   593 			break;
   594 		case 5:
   595 			((CTScreenDeviceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0083"));
   596 			iTest->LogSubTest(_L("Twips cache reset"));
   597 			// not expecting any panic
   598 			TEST(iTest->TestPanicL(CTwipsPanic::RunTest, 0, 0, (TAny*)iTest->iScreenNumber, _L("")));
   599 			break;
   600 /**
   601 @SYMTestCaseID      GRAPHICS-WSERV-0473
   602 
   603 @SYMDEF             DEF116127
   604 
   605 @SYMTestCaseDesc    Invariant testing length parameter of less then 0 values in CWsScreenDevice::GetScanLine()
   606 					method
   607 
   608 @SYMTestActions     Calls CWsScreenDevice::GetScanLine with aLength of -1.
   609 
   610 **/            
   611 		case 6:
   612 			((CTScreenDeviceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0473"));
   613 			iTest->LogSubTest(_L("Testing ScanLine length invariant"));
   614 			TEST(iTest->TestPanicL(CScanLinePanic::RunTest, EWservPanicInvalidParameter, 
   615 				 CScanLinePanic::TESTCASE_GRAPHICS_WSERV_0473,
   616 				 (TAny*)iTest->iScreenNumber, _L("WSERV")));
   617 			break;
   618 /**
   619 @SYMTestCaseID      GRAPHICS-WSERV-0474
   620 
   621 @SYMDEF             DEF116127
   622 
   623 @SYMTestCaseDesc    Invariant testing buffer parameter for required size.
   624 
   625 @SYMTestActions     Calls CWsScreenDevice::GetScanLine with buffer too small to contain requested data.
   626 **/            
   627 		case 7:
   628 			((CTScreenDeviceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0474"));
   629 			iTest->LogSubTest(_L("Testing ScanLine buffer invariant"));
   630 			TEST(iTest->TestPanicL(CScanLinePanic::RunTest, EWservPanicInvalidParameter,
   631 				 CScanLinePanic::TESTCASE_GRAPHICS_WSERV_0474,
   632 				 (TAny*)iTest->iScreenNumber, _L("WSERV")));
   633 			break;
   634 		default:
   635 			((CTScreenDeviceStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   636 			((CTScreenDeviceStep*)iStep)->CloseTMSGraphicsStep();
   637 			TestComplete();
   638 		}
   639 	((CTScreenDeviceStep*)iStep)->RecordTestResultL();
   640 	}
   641 
   642 __WS_CONSTRUCT_STEP__(ScreenDevice)