os/graphics/windowing/windowserver/test/tauto/tw32cmdbuf.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) 2007-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
// The fix solves the problem of bitmap drawing command being added to the window server
sl@0
    15
// command buffer without the bitmap handle(s) being added to the command buffer bitmap array.
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 "tw32cmdbuf.h"
sl@0
    26
sl@0
    27
const TInt KMaxTestIterations = 300;
sl@0
    28
const TInt KMinTestIterations = 100;
sl@0
    29
sl@0
    30
CTW32CmdBuf::CTW32CmdBuf(CTestStep* aStep):
sl@0
    31
	CTGraphicsBase(aStep)
sl@0
    32
	{
sl@0
    33
	}
sl@0
    34
sl@0
    35
CTW32CmdBuf::~CTW32CmdBuf()
sl@0
    36
	{
sl@0
    37
	}
sl@0
    38
sl@0
    39
void CTW32CmdBuf::ConstructL()
sl@0
    40
	{
sl@0
    41
	}
sl@0
    42
sl@0
    43
void CTW32CmdBuf::RunTestCaseL(TInt aCurTestCase)
sl@0
    44
	{
sl@0
    45
	((CTW32CmdBufStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
sl@0
    46
	switch(aCurTestCase)
sl@0
    47
		{
sl@0
    48
		case 1:
sl@0
    49
			((CTW32CmdBufStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0452"));
sl@0
    50
			INFO_PRINTF1(_L("Test all the drawing commands involving a CFbsBitmap\n"));
sl@0
    51
			DoCmdBufTestsL();
sl@0
    52
			break;
sl@0
    53
		default:
sl@0
    54
			((CTW32CmdBufStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
sl@0
    55
			((CTW32CmdBufStep*)iStep)->CloseTMSGraphicsStep();
sl@0
    56
			INFO_PRINTF1(_L("Test complete\n"));
sl@0
    57
			TestComplete();
sl@0
    58
		}
sl@0
    59
	((CTW32CmdBufStep*)iStep)->RecordTestResultL();
sl@0
    60
	}
sl@0
    61
sl@0
    62
/**
sl@0
    63
* TTestFunctionPtr pointer-to-function type definition
sl@0
    64
*/
sl@0
    65
typedef	void (*TTestFunctionPtr)(CWindowGc* aGc, CFbsBitmap* aBitmap, CFbsBitmap* aMask);
sl@0
    66
sl@0
    67
sl@0
    68
/**
sl@0
    69
* Calls CWindowGc::DrawBitmap(const TPoint &aTopLeft, const CFbsBitmap *aDevice)
sl@0
    70
*/
sl@0
    71
void CallDrawBitmap1(CWindowGc* aGc, CFbsBitmap* aBitmap, CFbsBitmap* /*aMask*/)
sl@0
    72
	{
sl@0
    73
	aGc->DrawBitmap(TPoint(0, 0), aBitmap);
sl@0
    74
	}
sl@0
    75
sl@0
    76
/**
sl@0
    77
* Calls CWindowGc::DrawBitmap(const TRect &aDestRect, const CFbsBitmap *aDevice)
sl@0
    78
*/
sl@0
    79
void CallDrawBitmap2(CWindowGc* aGc, CFbsBitmap* aBitmap, CFbsBitmap* /*aMask*/)
sl@0
    80
	{
sl@0
    81
	aGc->DrawBitmap(TRect(0, 0, 100, 100), aBitmap);
sl@0
    82
	}
sl@0
    83
	
sl@0
    84
/**
sl@0
    85
* Calls CWindowGc::DrawBitmap(const TRect &aDestRect, const CFbsBitmap *aDevice, const TRect &aSourceRect)
sl@0
    86
*/
sl@0
    87
void CallDrawBitmap3(CWindowGc* aGc, CFbsBitmap* aBitmap, CFbsBitmap* /*aMask*/)
sl@0
    88
	{
sl@0
    89
	aGc->DrawBitmap(TRect(0, 0, 100, 100), aBitmap, TRect(0, 0, 100, 100));
sl@0
    90
	}
sl@0
    91
	
sl@0
    92
/**
sl@0
    93
* Calls CWindowGc::DrawBitmapMasked(const TRect& aDestRect, const CFbsBitmap* aBitmap, const TRect& aSourceRect, const CFbsBitmap* aMaskBitmap, TBool aInvertMask)
sl@0
    94
*/
sl@0
    95
void CallDrawBitmapMasked(CWindowGc* aGc, CFbsBitmap* aBitmap, CFbsBitmap* aMask)
sl@0
    96
	{
sl@0
    97
	aGc->DrawBitmapMasked(TRect(0, 0, 100, 100), aBitmap, TRect(0, 0, 100, 100), aMask, EFalse);
sl@0
    98
	}
sl@0
    99
sl@0
   100
/**
sl@0
   101
* Calls CWindowGc::UseBrushPattern(const CFbsBitmap *aDevice)
sl@0
   102
*/	
sl@0
   103
void CallUseBrushPattern(CWindowGc* aGc, CFbsBitmap* aBitmap, CFbsBitmap* /*aMask*/)
sl@0
   104
	{
sl@0
   105
	aGc->UseBrushPattern(aBitmap);
sl@0
   106
	}
sl@0
   107
sl@0
   108
/**
sl@0
   109
* Calls CWindowGc::BitBlt(const TPoint &aPos, const CFbsBitmap *aBitmap)
sl@0
   110
*/
sl@0
   111
void CallBitBlt1(CWindowGc* aGc, CFbsBitmap* aBitmap, CFbsBitmap* /*aMask*/)
sl@0
   112
	{
sl@0
   113
	aGc->BitBlt(TPoint(0, 0), aBitmap);
sl@0
   114
	}
sl@0
   115
sl@0
   116
/**
sl@0
   117
* Calls CWindowGc::BitBlt(const TPoint &aDestination, const CFbsBitmap *aBitmap, const TRect &aSource)
sl@0
   118
*/
sl@0
   119
void CallBitBlt2(CWindowGc* aGc, CFbsBitmap* aBitmap, CFbsBitmap* /*aMask*/)
sl@0
   120
	{
sl@0
   121
	aGc->BitBlt(TPoint(0, 0), aBitmap, TRect(0, 0, 100, 100));
sl@0
   122
	}
sl@0
   123
sl@0
   124
/**
sl@0
   125
* Calls CWindowGc::BitBltMasked(const TPoint& aPoint,const CFbsBitmap* aBitmap,const TRect& aSourceRect,const CFbsBitmap* aMaskBitmap,TBool aInvertMask)
sl@0
   126
*/
sl@0
   127
void CallBitBltMasked(CWindowGc* aGc, CFbsBitmap* aBitmap, CFbsBitmap* aMask)
sl@0
   128
	{
sl@0
   129
	aGc->BitBltMasked(TPoint(0, 0), aBitmap, TRect(0, 0, 100, 100), aMask, EFalse);
sl@0
   130
	}
sl@0
   131
sl@0
   132
/**
sl@0
   133
* Calls CWindowGc::AlphaBlendBitmaps(const TPoint& aDestPt, const CFbsBitmap* aSrcBmp, const TRect& aSrcRect, const CFbsBitmap* aAlphaBmp, const TPoint& aAlphaPt)
sl@0
   134
*/	
sl@0
   135
void CallAlphaBlendBitmaps(CWindowGc* aGc, CFbsBitmap* aBitmap, CFbsBitmap* aMask)
sl@0
   136
	{
sl@0
   137
	aGc->AlphaBlendBitmaps(TPoint(0, 0), aBitmap, TRect(0, 0, 100, 100), aMask, TPoint(0, 0));
sl@0
   138
	}
sl@0
   139
sl@0
   140
/**
sl@0
   141
* Drawing command function array.
sl@0
   142
*/	
sl@0
   143
const TTestFunctionPtr KTestFunctions[] =
sl@0
   144
		{
sl@0
   145
		CallDrawBitmap1,
sl@0
   146
		CallDrawBitmap2,
sl@0
   147
		CallDrawBitmap3,
sl@0
   148
		CallDrawBitmapMasked,
sl@0
   149
		CallUseBrushPattern,
sl@0
   150
		CallBitBlt1,
sl@0
   151
		CallBitBlt2,
sl@0
   152
		CallBitBltMasked,
sl@0
   153
		CallAlphaBlendBitmaps,
sl@0
   154
		};
sl@0
   155
sl@0
   156
/**
sl@0
   157
 * @SYMTestCaseID			GRAPHICS-WSERV-0452
sl@0
   158
 * @SYMTestCaseDesc			Tests drawing commands with bitmap handles.
sl@0
   159
 * @SYMDEF					INC111655
sl@0
   160
 * @SYMFssID				CWindowGc::DrawBitmap() \n 
sl@0
   161
 * 							CWindowGc::DrawBitmapMasked()\n 
sl@0
   162
 * 							CWindowGc::UseBrushPattern()\n 
sl@0
   163
 * 							CWindowGc::BitBlt()\n 
sl@0
   164
 * 							CWindowGc::AlphaBlendBitmaps()
sl@0
   165
 * @SYMTestPriority			Critical
sl@0
   166
 * @SYMTestType				Unit Test
sl@0
   167
 * @SYMTestPurpose			To ensure drawing commands with bitmap handles are added to the
sl@0
   168
 							command buffer successfully when the buffer is full.
sl@0
   169
 * @SYMTestActions			Fill the command buffer with CWindowGc::Clear() commands in a loop until
sl@0
   170
 							the buffer is full, create bitmap(s), then call the draw command and then 
sl@0
   171
 							delete the bitmap handle(s). All tests are done in a second thread.
sl@0
   172
 * @SYMTestExpectedResults	The function should not panic. Without the fix the functions will panic
sl@0
   173
 							with WSERV 7. 
sl@0
   174
 * @SYMTestStatus			Implemented 
sl@0
   175
 */	
sl@0
   176
void CTW32CmdBuf::DoCmdBufTestsL()
sl@0
   177
	{
sl@0
   178
	CreateSecondThreadAndDoTestL(ECallDrawBitmap1);
sl@0
   179
	CreateSecondThreadAndDoTestL(ECallDrawBitmap2);
sl@0
   180
	CreateSecondThreadAndDoTestL(ECallDrawBitmap3);
sl@0
   181
	CreateSecondThreadAndDoTestL(ECallDrawBitmapMasked);
sl@0
   182
	CreateSecondThreadAndDoTestL(ECallUseBrushPattern);	
sl@0
   183
	CreateSecondThreadAndDoTestL(ECallBitBlt1);
sl@0
   184
	CreateSecondThreadAndDoTestL(ECallBitBlt2);
sl@0
   185
	CreateSecondThreadAndDoTestL(ECallBitBltMasked);
sl@0
   186
	CreateSecondThreadAndDoTestL(ECallAlphaBlendBitmaps);
sl@0
   187
	}
sl@0
   188
sl@0
   189
/**
sl@0
   190
* Creates a second thread to run the test.
sl@0
   191
* 
sl@0
   192
* @param aFunctionIndex The drawing function command to be executed. All commands are defined in TestFunctionIndex.
sl@0
   193
*/
sl@0
   194
void CTW32CmdBuf::CreateSecondThreadAndDoTestL(TTestFunctionIndex aFunctionIndex)
sl@0
   195
	{	
sl@0
   196
	RThread thread;
sl@0
   197
	TBuf<30> threadName(KTW32CmdBufSecondThread);
sl@0
   198
	static TInt threadSerialNumber = 0;
sl@0
   199
	threadName.AppendNum(++threadSerialNumber);
sl@0
   200
	User::LeaveIfError(thread.Create(threadName, TestCmdBufFunction, KDefaultStackSize, KMinHeapSize, 0x4000, &aFunctionIndex));
sl@0
   201
	TRequestStatus status;
sl@0
   202
	thread.Logon(status);
sl@0
   203
	thread.Resume();
sl@0
   204
	User::WaitForRequest(status);
sl@0
   205
	TEST(thread.ExitType()==EExitKill);
sl@0
   206
	TEST(thread.ExitReason() == KErrNone);
sl@0
   207
	thread.Close();	
sl@0
   208
	}
sl@0
   209
sl@0
   210
/**
sl@0
   211
* Runs the test in a second thread.
sl@0
   212
*
sl@0
   213
* @param aFunctionIndex The drawing function command to be executed. All commands are defined in TestFunctionIndex.
sl@0
   214
*/
sl@0
   215
TInt CTW32CmdBuf::DoTestCmdBufFunctionL(TTestFunctionIndex aFunctionIndex)
sl@0
   216
	{
sl@0
   217
	RWsSession session;
sl@0
   218
	User::LeaveIfError(session.Connect());
sl@0
   219
	CleanupClosePushL(session);
sl@0
   220
	CWsScreenDevice *device = new(ELeave) CWsScreenDevice(session);
sl@0
   221
	CleanupStack::PushL(device);
sl@0
   222
	User::LeaveIfError(device->Construct(CTestBase::iScreenNo));
sl@0
   223
	CWindowGc* gc;
sl@0
   224
	User::LeaveIfError(device->CreateContext(gc));
sl@0
   225
	CleanupStack::PushL(gc);
sl@0
   226
	RWindowGroup group(session);
sl@0
   227
	User::LeaveIfError(group.Construct(1, EFalse));
sl@0
   228
	CleanupClosePushL(group);
sl@0
   229
	RWindow window(session);
sl@0
   230
	User::LeaveIfError(window.Construct(group, 2));
sl@0
   231
	CleanupClosePushL(window);
sl@0
   232
	window.SetExtent(TPoint(0,0), TSize(200, 200));
sl@0
   233
	User::LeaveIfError(window.SetRequiredDisplayMode(EColor64K));
sl@0
   234
	window.Activate();	
sl@0
   235
	gc->Activate(window);
sl@0
   236
	session.SetAutoFlush(EFalse);
sl@0
   237
	window.Invalidate();
sl@0
   238
	window.BeginRedraw();
sl@0
   239
	for(TInt i=KMinTestIterations; i<KMaxTestIterations; ++i)
sl@0
   240
		{
sl@0
   241
		for(TInt j=0; j<i; ++j)
sl@0
   242
			{
sl@0
   243
			gc->Clear();
sl@0
   244
			}
sl@0
   245
sl@0
   246
		CFbsBitmap* bitmap = new(ELeave) CFbsBitmap;
sl@0
   247
		CleanupStack::PushL(bitmap);
sl@0
   248
		User::LeaveIfError(bitmap->Create(TSize(100, 100), EColor64K));
sl@0
   249
		CFbsBitmap* mask = new(ELeave) CFbsBitmap;
sl@0
   250
		CleanupStack::PushL(mask);
sl@0
   251
		User::LeaveIfError(mask->Create(TSize(100, 100), EColor64K));
sl@0
   252
		KTestFunctions[aFunctionIndex](gc, bitmap, mask);
sl@0
   253
		CleanupStack::PopAndDestroy(2);
sl@0
   254
		session.Flush();	
sl@0
   255
		}	
sl@0
   256
	window.EndRedraw();	
sl@0
   257
	gc->Deactivate();
sl@0
   258
	CleanupStack::PopAndDestroy(5);
sl@0
   259
	return KErrNone;
sl@0
   260
	}
sl@0
   261
sl@0
   262
/**
sl@0
   263
* Second thread entry function.
sl@0
   264
*
sl@0
   265
* @param aInfo The parameter(s) passed to the second thread in this case the function index.
sl@0
   266
*/
sl@0
   267
TInt CTW32CmdBuf::TestCmdBufFunction(TAny* aInfo)
sl@0
   268
	{	
sl@0
   269
	if(!aInfo)
sl@0
   270
		{
sl@0
   271
		return KErrArgument;
sl@0
   272
		}
sl@0
   273
	TTestFunctionIndex functionIndex = *(TTestFunctionIndex*)aInfo;
sl@0
   274
	CTrapCleanup *trap = CTrapCleanup::New();
sl@0
   275
	__ASSERT_ALWAYS(trap, User::Invariant());
sl@0
   276
	
sl@0
   277
	TRAPD(err, DoTestCmdBufFunctionL(functionIndex));	
sl@0
   278
	
sl@0
   279
	delete trap;
sl@0
   280
	return err;
sl@0
   281
	}
sl@0
   282
sl@0
   283
__CONSTRUCT_STEP__(W32CmdBuf)