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