os/graphics/windowing/windowserver/test/tauto/tw32cmdbuf.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/tw32cmdbuf.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,283 @@
     1.4 +// Copyright (c) 2007-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 +// The fix solves the problem of bitmap drawing command being added to the window server
    1.18 +// command buffer without the bitmap handle(s) being added to the command buffer bitmap array.
    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 "tw32cmdbuf.h"
    1.29 +
    1.30 +const TInt KMaxTestIterations = 300;
    1.31 +const TInt KMinTestIterations = 100;
    1.32 +
    1.33 +CTW32CmdBuf::CTW32CmdBuf(CTestStep* aStep):
    1.34 +	CTGraphicsBase(aStep)
    1.35 +	{
    1.36 +	}
    1.37 +
    1.38 +CTW32CmdBuf::~CTW32CmdBuf()
    1.39 +	{
    1.40 +	}
    1.41 +
    1.42 +void CTW32CmdBuf::ConstructL()
    1.43 +	{
    1.44 +	}
    1.45 +
    1.46 +void CTW32CmdBuf::RunTestCaseL(TInt aCurTestCase)
    1.47 +	{
    1.48 +	((CTW32CmdBufStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
    1.49 +	switch(aCurTestCase)
    1.50 +		{
    1.51 +		case 1:
    1.52 +			((CTW32CmdBufStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0452"));
    1.53 +			INFO_PRINTF1(_L("Test all the drawing commands involving a CFbsBitmap\n"));
    1.54 +			DoCmdBufTestsL();
    1.55 +			break;
    1.56 +		default:
    1.57 +			((CTW32CmdBufStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
    1.58 +			((CTW32CmdBufStep*)iStep)->CloseTMSGraphicsStep();
    1.59 +			INFO_PRINTF1(_L("Test complete\n"));
    1.60 +			TestComplete();
    1.61 +		}
    1.62 +	((CTW32CmdBufStep*)iStep)->RecordTestResultL();
    1.63 +	}
    1.64 +
    1.65 +/**
    1.66 +* TTestFunctionPtr pointer-to-function type definition
    1.67 +*/
    1.68 +typedef	void (*TTestFunctionPtr)(CWindowGc* aGc, CFbsBitmap* aBitmap, CFbsBitmap* aMask);
    1.69 +
    1.70 +
    1.71 +/**
    1.72 +* Calls CWindowGc::DrawBitmap(const TPoint &aTopLeft, const CFbsBitmap *aDevice)
    1.73 +*/
    1.74 +void CallDrawBitmap1(CWindowGc* aGc, CFbsBitmap* aBitmap, CFbsBitmap* /*aMask*/)
    1.75 +	{
    1.76 +	aGc->DrawBitmap(TPoint(0, 0), aBitmap);
    1.77 +	}
    1.78 +
    1.79 +/**
    1.80 +* Calls CWindowGc::DrawBitmap(const TRect &aDestRect, const CFbsBitmap *aDevice)
    1.81 +*/
    1.82 +void CallDrawBitmap2(CWindowGc* aGc, CFbsBitmap* aBitmap, CFbsBitmap* /*aMask*/)
    1.83 +	{
    1.84 +	aGc->DrawBitmap(TRect(0, 0, 100, 100), aBitmap);
    1.85 +	}
    1.86 +	
    1.87 +/**
    1.88 +* Calls CWindowGc::DrawBitmap(const TRect &aDestRect, const CFbsBitmap *aDevice, const TRect &aSourceRect)
    1.89 +*/
    1.90 +void CallDrawBitmap3(CWindowGc* aGc, CFbsBitmap* aBitmap, CFbsBitmap* /*aMask*/)
    1.91 +	{
    1.92 +	aGc->DrawBitmap(TRect(0, 0, 100, 100), aBitmap, TRect(0, 0, 100, 100));
    1.93 +	}
    1.94 +	
    1.95 +/**
    1.96 +* Calls CWindowGc::DrawBitmapMasked(const TRect& aDestRect, const CFbsBitmap* aBitmap, const TRect& aSourceRect, const CFbsBitmap* aMaskBitmap, TBool aInvertMask)
    1.97 +*/
    1.98 +void CallDrawBitmapMasked(CWindowGc* aGc, CFbsBitmap* aBitmap, CFbsBitmap* aMask)
    1.99 +	{
   1.100 +	aGc->DrawBitmapMasked(TRect(0, 0, 100, 100), aBitmap, TRect(0, 0, 100, 100), aMask, EFalse);
   1.101 +	}
   1.102 +
   1.103 +/**
   1.104 +* Calls CWindowGc::UseBrushPattern(const CFbsBitmap *aDevice)
   1.105 +*/	
   1.106 +void CallUseBrushPattern(CWindowGc* aGc, CFbsBitmap* aBitmap, CFbsBitmap* /*aMask*/)
   1.107 +	{
   1.108 +	aGc->UseBrushPattern(aBitmap);
   1.109 +	}
   1.110 +
   1.111 +/**
   1.112 +* Calls CWindowGc::BitBlt(const TPoint &aPos, const CFbsBitmap *aBitmap)
   1.113 +*/
   1.114 +void CallBitBlt1(CWindowGc* aGc, CFbsBitmap* aBitmap, CFbsBitmap* /*aMask*/)
   1.115 +	{
   1.116 +	aGc->BitBlt(TPoint(0, 0), aBitmap);
   1.117 +	}
   1.118 +
   1.119 +/**
   1.120 +* Calls CWindowGc::BitBlt(const TPoint &aDestination, const CFbsBitmap *aBitmap, const TRect &aSource)
   1.121 +*/
   1.122 +void CallBitBlt2(CWindowGc* aGc, CFbsBitmap* aBitmap, CFbsBitmap* /*aMask*/)
   1.123 +	{
   1.124 +	aGc->BitBlt(TPoint(0, 0), aBitmap, TRect(0, 0, 100, 100));
   1.125 +	}
   1.126 +
   1.127 +/**
   1.128 +* Calls CWindowGc::BitBltMasked(const TPoint& aPoint,const CFbsBitmap* aBitmap,const TRect& aSourceRect,const CFbsBitmap* aMaskBitmap,TBool aInvertMask)
   1.129 +*/
   1.130 +void CallBitBltMasked(CWindowGc* aGc, CFbsBitmap* aBitmap, CFbsBitmap* aMask)
   1.131 +	{
   1.132 +	aGc->BitBltMasked(TPoint(0, 0), aBitmap, TRect(0, 0, 100, 100), aMask, EFalse);
   1.133 +	}
   1.134 +
   1.135 +/**
   1.136 +* Calls CWindowGc::AlphaBlendBitmaps(const TPoint& aDestPt, const CFbsBitmap* aSrcBmp, const TRect& aSrcRect, const CFbsBitmap* aAlphaBmp, const TPoint& aAlphaPt)
   1.137 +*/	
   1.138 +void CallAlphaBlendBitmaps(CWindowGc* aGc, CFbsBitmap* aBitmap, CFbsBitmap* aMask)
   1.139 +	{
   1.140 +	aGc->AlphaBlendBitmaps(TPoint(0, 0), aBitmap, TRect(0, 0, 100, 100), aMask, TPoint(0, 0));
   1.141 +	}
   1.142 +
   1.143 +/**
   1.144 +* Drawing command function array.
   1.145 +*/	
   1.146 +const TTestFunctionPtr KTestFunctions[] =
   1.147 +		{
   1.148 +		CallDrawBitmap1,
   1.149 +		CallDrawBitmap2,
   1.150 +		CallDrawBitmap3,
   1.151 +		CallDrawBitmapMasked,
   1.152 +		CallUseBrushPattern,
   1.153 +		CallBitBlt1,
   1.154 +		CallBitBlt2,
   1.155 +		CallBitBltMasked,
   1.156 +		CallAlphaBlendBitmaps,
   1.157 +		};
   1.158 +
   1.159 +/**
   1.160 + * @SYMTestCaseID			GRAPHICS-WSERV-0452
   1.161 + * @SYMTestCaseDesc			Tests drawing commands with bitmap handles.
   1.162 + * @SYMDEF					INC111655
   1.163 + * @SYMFssID				CWindowGc::DrawBitmap() \n 
   1.164 + * 							CWindowGc::DrawBitmapMasked()\n 
   1.165 + * 							CWindowGc::UseBrushPattern()\n 
   1.166 + * 							CWindowGc::BitBlt()\n 
   1.167 + * 							CWindowGc::AlphaBlendBitmaps()
   1.168 + * @SYMTestPriority			Critical
   1.169 + * @SYMTestType				Unit Test
   1.170 + * @SYMTestPurpose			To ensure drawing commands with bitmap handles are added to the
   1.171 + 							command buffer successfully when the buffer is full.
   1.172 + * @SYMTestActions			Fill the command buffer with CWindowGc::Clear() commands in a loop until
   1.173 + 							the buffer is full, create bitmap(s), then call the draw command and then 
   1.174 + 							delete the bitmap handle(s). All tests are done in a second thread.
   1.175 + * @SYMTestExpectedResults	The function should not panic. Without the fix the functions will panic
   1.176 + 							with WSERV 7. 
   1.177 + * @SYMTestStatus			Implemented 
   1.178 + */	
   1.179 +void CTW32CmdBuf::DoCmdBufTestsL()
   1.180 +	{
   1.181 +	CreateSecondThreadAndDoTestL(ECallDrawBitmap1);
   1.182 +	CreateSecondThreadAndDoTestL(ECallDrawBitmap2);
   1.183 +	CreateSecondThreadAndDoTestL(ECallDrawBitmap3);
   1.184 +	CreateSecondThreadAndDoTestL(ECallDrawBitmapMasked);
   1.185 +	CreateSecondThreadAndDoTestL(ECallUseBrushPattern);	
   1.186 +	CreateSecondThreadAndDoTestL(ECallBitBlt1);
   1.187 +	CreateSecondThreadAndDoTestL(ECallBitBlt2);
   1.188 +	CreateSecondThreadAndDoTestL(ECallBitBltMasked);
   1.189 +	CreateSecondThreadAndDoTestL(ECallAlphaBlendBitmaps);
   1.190 +	}
   1.191 +
   1.192 +/**
   1.193 +* Creates a second thread to run the test.
   1.194 +* 
   1.195 +* @param aFunctionIndex The drawing function command to be executed. All commands are defined in TestFunctionIndex.
   1.196 +*/
   1.197 +void CTW32CmdBuf::CreateSecondThreadAndDoTestL(TTestFunctionIndex aFunctionIndex)
   1.198 +	{	
   1.199 +	RThread thread;
   1.200 +	TBuf<30> threadName(KTW32CmdBufSecondThread);
   1.201 +	static TInt threadSerialNumber = 0;
   1.202 +	threadName.AppendNum(++threadSerialNumber);
   1.203 +	User::LeaveIfError(thread.Create(threadName, TestCmdBufFunction, KDefaultStackSize, KMinHeapSize, 0x4000, &aFunctionIndex));
   1.204 +	TRequestStatus status;
   1.205 +	thread.Logon(status);
   1.206 +	thread.Resume();
   1.207 +	User::WaitForRequest(status);
   1.208 +	TEST(thread.ExitType()==EExitKill);
   1.209 +	TEST(thread.ExitReason() == KErrNone);
   1.210 +	thread.Close();	
   1.211 +	}
   1.212 +
   1.213 +/**
   1.214 +* Runs the test in a second thread.
   1.215 +*
   1.216 +* @param aFunctionIndex The drawing function command to be executed. All commands are defined in TestFunctionIndex.
   1.217 +*/
   1.218 +TInt CTW32CmdBuf::DoTestCmdBufFunctionL(TTestFunctionIndex aFunctionIndex)
   1.219 +	{
   1.220 +	RWsSession session;
   1.221 +	User::LeaveIfError(session.Connect());
   1.222 +	CleanupClosePushL(session);
   1.223 +	CWsScreenDevice *device = new(ELeave) CWsScreenDevice(session);
   1.224 +	CleanupStack::PushL(device);
   1.225 +	User::LeaveIfError(device->Construct(CTestBase::iScreenNo));
   1.226 +	CWindowGc* gc;
   1.227 +	User::LeaveIfError(device->CreateContext(gc));
   1.228 +	CleanupStack::PushL(gc);
   1.229 +	RWindowGroup group(session);
   1.230 +	User::LeaveIfError(group.Construct(1, EFalse));
   1.231 +	CleanupClosePushL(group);
   1.232 +	RWindow window(session);
   1.233 +	User::LeaveIfError(window.Construct(group, 2));
   1.234 +	CleanupClosePushL(window);
   1.235 +	window.SetExtent(TPoint(0,0), TSize(200, 200));
   1.236 +	User::LeaveIfError(window.SetRequiredDisplayMode(EColor64K));
   1.237 +	window.Activate();	
   1.238 +	gc->Activate(window);
   1.239 +	session.SetAutoFlush(EFalse);
   1.240 +	window.Invalidate();
   1.241 +	window.BeginRedraw();
   1.242 +	for(TInt i=KMinTestIterations; i<KMaxTestIterations; ++i)
   1.243 +		{
   1.244 +		for(TInt j=0; j<i; ++j)
   1.245 +			{
   1.246 +			gc->Clear();
   1.247 +			}
   1.248 +
   1.249 +		CFbsBitmap* bitmap = new(ELeave) CFbsBitmap;
   1.250 +		CleanupStack::PushL(bitmap);
   1.251 +		User::LeaveIfError(bitmap->Create(TSize(100, 100), EColor64K));
   1.252 +		CFbsBitmap* mask = new(ELeave) CFbsBitmap;
   1.253 +		CleanupStack::PushL(mask);
   1.254 +		User::LeaveIfError(mask->Create(TSize(100, 100), EColor64K));
   1.255 +		KTestFunctions[aFunctionIndex](gc, bitmap, mask);
   1.256 +		CleanupStack::PopAndDestroy(2);
   1.257 +		session.Flush();	
   1.258 +		}	
   1.259 +	window.EndRedraw();	
   1.260 +	gc->Deactivate();
   1.261 +	CleanupStack::PopAndDestroy(5);
   1.262 +	return KErrNone;
   1.263 +	}
   1.264 +
   1.265 +/**
   1.266 +* Second thread entry function.
   1.267 +*
   1.268 +* @param aInfo The parameter(s) passed to the second thread in this case the function index.
   1.269 +*/
   1.270 +TInt CTW32CmdBuf::TestCmdBufFunction(TAny* aInfo)
   1.271 +	{	
   1.272 +	if(!aInfo)
   1.273 +		{
   1.274 +		return KErrArgument;
   1.275 +		}
   1.276 +	TTestFunctionIndex functionIndex = *(TTestFunctionIndex*)aInfo;
   1.277 +	CTrapCleanup *trap = CTrapCleanup::New();
   1.278 +	__ASSERT_ALWAYS(trap, User::Invariant());
   1.279 +	
   1.280 +	TRAPD(err, DoTestCmdBufFunctionL(functionIndex));	
   1.281 +	
   1.282 +	delete trap;
   1.283 +	return err;
   1.284 +	}
   1.285 +
   1.286 +__CONSTRUCT_STEP__(W32CmdBuf)