os/graphics/windowing/windowserver/test/tcsc/cwsgcecscbase.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/windowing/windowserver/test/tcsc/cwsgcecscbase.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,400 @@
     1.4 +// Copyright (c) 2008-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 +// @file
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32std.h>
    1.22 +#include <e32math.h>
    1.23 +#include <w32std.h>
    1.24 +#include <w32debug.h>
    1.25 +#include <e32base.h>
    1.26 +#include "teflogextensions.h"
    1.27 +#include "globalsettings.h"
    1.28 +#include "CWsGceCscBase.h"
    1.29 +#include <bitdraw.h>
    1.30 +#include <bitdrawinterfaceid.h>
    1.31 +#include <imageconversion.h>
    1.32 +#include <test/tefunit.h>
    1.33 +
    1.34 +
    1.35 +CWsGceCscBase::CWsGceCscBase():
    1.36 +iDoTearDown(EFalse),
    1.37 +iUtility(this, NULL)
    1.38 +{
    1.39 +}
    1.40 +
    1.41 +CWsGceCscBase::~CWsGceCscBase()
    1.42 +{
    1.43 +if (iDoTearDown)
    1.44 +	TearDownFromDeleteL();	//This mechanism is not entirely clean to use.
    1.45 +}
    1.46 +
    1.47 +void CWsGceCscBase::SetupL()
    1.48 +{
    1.49 +iDoTearDown=ETrue;
    1.50 +iRed.SetInternal(0xFFFF0000);
    1.51 +iGreen.SetInternal(0xFF00FF00);
    1.52 +iBlue.SetInternal(0xFF0000FF);
    1.53 +iCyan.SetInternal(0xFF00FFFF);
    1.54 +iMagenta.SetInternal(0xFFFF00FF);
    1.55 +iYellow.SetInternal(0xFFFFFF00);
    1.56 +iWhite.SetInternal(0xFFFFFFFF);
    1.57 +
    1.58 +ASSERT_EQUALS_X(iSession.Connect(), KErrNone);
    1.59 +
    1.60 +	{//Stolen from TAuto CloseAllPanicWindows()
    1.61 +	TInt idFocus = iSession.GetFocusWindowGroup();
    1.62 +	TWsEvent event;
    1.63 +	event.SetType(EEventKey); //EEventKeyDown
    1.64 +	TKeyEvent *keyEvent = event.Key();
    1.65 +	keyEvent->iCode = EKeyEscape;
    1.66 +	keyEvent->iScanCode = EStdKeyEscape;
    1.67 +	keyEvent->iModifiers = 0;
    1.68 +	TInt theLimit = 50;
    1.69 +	while(idFocus != NULL && (theLimit-- > 0))
    1.70 +		{
    1.71 +		iSession.SendEventToAllWindowGroups(event);
    1.72 +		TInt idNewFocus = iSession.GetFocusWindowGroup();
    1.73 +		if (idNewFocus!=idFocus)
    1.74 +			{
    1.75 +			INFO_PRINTF1(_L("A window was closed [probably a panic box from the previous test]."));
    1.76 +			}
    1.77 +		idFocus=idNewFocus;
    1.78 +		}
    1.79 +	}
    1.80 +TInt err = KErrNone;
    1.81 +
    1.82 +TRAP(err, iScreenDevice = new (ELeave) CWsScreenDevice(iSession));
    1.83 +PRINT_ON_ERROR2_L(err, _L("Failed to create screen device: %d"), err);
    1.84 +ASSERT_EQUALS_X(iScreenDevice->Construct(TGlobalSettings::Instance().iScreen), KErrNone);
    1.85 +iDisplayMode = iScreenDevice->DisplayMode();	// Get default display mode
    1.86 +
    1.87 +TRAP(err, iGc = new (ELeave) CWindowGc(iScreenDevice));
    1.88 +PRINT_ON_ERROR2_L(err, _L("Failed to create graphics context: %d"), err);
    1.89 +ASSERT_EQUALS_X(iGc->Construct(), KErrNone);
    1.90 +
    1.91 +iGroup = RWindowGroup(iSession);
    1.92 +ASSERT_EQUALS_X(iGroup.Construct(++iWindowHandle,iScreenDevice), KErrNone);
    1.93 +iSession.Flush();
    1.94 +
    1.95 +RWindow testTrans(iSession);
    1.96 +ASSERT_EQUALS_X(testTrans.Construct(iGroup, ++iWindowHandle), KErrNone);
    1.97 +iTransparencyEnabled=(testTrans.SetTransparencyFactor(iWhite)==KErrNone);
    1.98 +testTrans.Close();
    1.99 +
   1.100 +//clean-up if previous test abended
   1.101 +	if (PostTestCleanupInstance().iSharedUtility)
   1.102 +	{
   1.103 +//Temp removed - may be causing ONB fails!
   1.104 +//	if (PostTestCleanupInstance().iSharedUtility->DestroyAll())
   1.105 +//		{
   1.106 +//		INFO_PRINTF1(_L("Destroyed some surfaces from previous test."));
   1.107 +//
   1.108 +//		}
   1.109 +	}
   1.110 +	if (!PostTestCleanupInstance().iCleanedUpOnExit)
   1.111 +	PostTestCleanupInstance().iCleanedUpOnExit=EFalse;
   1.112 +	
   1.113 +	if (!GCEIsSupported())
   1.114 +		{
   1.115 +		INFO_PRINTF1(_L("Some Setup skipped: GCE support is not loaded"));
   1.116 +		return;
   1.117 +		}
   1.118 +
   1.119 +	TRAPD(err_FailedToCreateSurfaceUtility, iUtility = CSurfaceUtility::NewL( PostTestCleanupInstance().iSharedUtility));
   1.120 +	ASSERT_EQUALS(err_FailedToCreateSurfaceUtility,KErrNone);
   1.121 +
   1.122 +}
   1.123 +
   1.124 +void CWsGceCscBase::TearDownL()
   1.125 +{
   1.126 +iDoTearDown=EFalse;
   1.127 +delete iGc;
   1.128 +delete iScreenDevice;
   1.129 +
   1.130 +iGroup.Close();
   1.131 +iSession.Flush();
   1.132 +iSession.Close();
   1.133 +
   1.134 +delete iUtility();
   1.135 +PostTestCleanupInstance().iCleanedUpOnExit=ETrue;
   1.136 +Pause(1000);
   1.137 +}
   1.138 +
   1.139 +void CWsGceCscBase::TearDownFromDeleteL()
   1.140 +{
   1.141 +CWsGceCscBase::TearDownL();
   1.142 +}
   1.143 +
   1.144 +void CWsGceCscBase::Pause(TInt aMilliseconds)
   1.145 +{
   1.146 +User::After(TTimeIntervalMicroSeconds32(aMilliseconds * 1000));
   1.147 +}
   1.148 +
   1.149 +/**	Test using an indipendent method that GCE version of WServ is running
   1.150 + *  This method can only be called after the testcase is started
   1.151 + * 
   1.152 + * 	@return	true if WServ version is GCE technology, false if legacy technology
   1.153 + **/
   1.154 +TBool CWsGceCscBase::GCEIsSupported() const
   1.155 +	{
   1.156 +	CFbsDrawDevice* screenDevice=NULL;
   1.157 +	TDisplayMode displayMode=iScreenDevice->DisplayMode();
   1.158 +	TRAPD(err, screenDevice = CFbsDrawDevice::NewScreenDeviceL(TGlobalSettings::Instance().iScreen, displayMode));
   1.159 +	TBool rv=EFalse;
   1.160 +	if(err == KErrNone)
   1.161 +		{
   1.162 +		TAny* p=NULL;
   1.163 +		rv=(screenDevice->GetInterface(KSurfaceInterfaceID, p)==KErrNone);
   1.164 +		delete screenDevice;
   1.165 +		}
   1.166 +	return rv;
   1.167 +	}
   1.168 +/**	Test using an indipendent method that GCE version of WServ is running
   1.169 + *  This method can be called at any time, even by external code, but creates temporary window session objects
   1.170 + * 
   1.171 + * 	@return	true if WServ version is GCE technology, false if legacy technology
   1.172 + **/
   1.173 +TBool CWsGceCscBase::GCEIsSupportedStatic()
   1.174 +	{
   1.175 +	CFbsDrawDevice* screenDevice=NULL;
   1.176 +	RWsSession session;
   1.177 +	if (session.Connect()!=KErrNone)
   1.178 +		{
   1.179 +		return EFalse;
   1.180 +		}
   1.181 +	CWsScreenDevice screen(session);
   1.182 +	if (screen.Construct(TGlobalSettings::Instance().iScreen)!=KErrNone)
   1.183 +		{
   1.184 +		return EFalse;
   1.185 +		}
   1.186 +	
   1.187 +	TDisplayMode displayMode=screen.DisplayMode();
   1.188 +	TRAPD(err, screenDevice = CFbsDrawDevice::NewScreenDeviceL(TGlobalSettings::Instance().iScreen, displayMode));
   1.189 +	TBool rv=EFalse;
   1.190 +	if(err == KErrNone)
   1.191 +		{
   1.192 +		TAny* p=NULL;
   1.193 +		rv=(screenDevice->GetInterface(KSurfaceInterfaceID, p)==KErrNone);
   1.194 +		delete screenDevice;
   1.195 +		}
   1.196 +	return rv;
   1.197 +	}
   1.198 +
   1.199 +//Allocating an instance of surface utility here means all test code instances will share the same instance of the utility class.
   1.200 +// Owns the singleton
   1.201 +CWsGceCscBase::TPostTestCleanup& CWsGceCscBase::PostTestCleanupInstance()
   1.202 +	{
   1.203 +	static 
   1.204 +	class RPostTestCleanup:public TPostTestCleanup
   1.205 +		{
   1.206 +		public:
   1.207 +		RPostTestCleanup()
   1.208 +			{
   1.209 +			iSharedUtility=NULL;
   1.210 +			iCleanedUpOnExit=ETrue;
   1.211 +			}
   1.212 +		~RPostTestCleanup()
   1.213 +			{
   1.214 +	// I want to cleanly release the surface utility, but at this point the threads have already been pulled down!
   1.215 +	//		if (iSharedUtility)
   1.216 +	//			delete iSharedUtility;
   1.217 +			iSharedUtility=NULL;	//avoid phoenix behaviour
   1.218 +			}
   1.219 +		}	staticInstance;
   1.220 +		return staticInstance;
   1.221 +	}
   1.222 +
   1.223 +// This handles any non-member uses of the extended ASSERT_XXX macros
   1.224 +extern void TefUnitFailLeaveL();
   1.225 +/**
   1.226 + * side-effect: log the state info just before I leave!
   1.227 + * Note that this only logs intentional assertion failures.
   1.228 + * Fails due to panics or throws won't log this info.
   1.229 + **/
   1.230 +void CWsGceCscBase::TefUnitFailLeaveL()
   1.231 +	{
   1.232 +	for (TInt line=0;line<KMaxInfoLines;line++)
   1.233 +		if (iTestInfo[line].Length())
   1.234 +			Logger().LogExtra((TText8*)"Test state at fail - line",line, ESevrAll, iTestInfo[line]);
   1.235 +	TGlobalSettings::Instance().Report(Logger());
   1.236 +	
   1.237 +	User::Leave(KErrTEFUnitFail);
   1.238 +	}
   1.239 +
   1.240 +TInt	CWsGceCscBase::DebugInfo(TWsDebugInfoFunc aFunction, 
   1.241 +		                                 TInt aParam, 
   1.242 +		                                 TDes8& aHostBuffer,
   1.243 +		                                 const void*&aReturnedObject,
   1.244 +		                                 TInt aObjectSize)const
   1.245 +	{
   1.246 +	TInt reqSize=iSession.DebugInfo(aFunction,aHostBuffer,aParam);
   1.247 +	aReturnedObject=NULL;
   1.248 +	if (reqSize<0)
   1.249 +		{
   1.250 +		if ((reqSize%aObjectSize)!=0)
   1.251 +			{
   1.252 +			return KErrCorrupt;
   1.253 +			}
   1.254 +		else
   1.255 +			{
   1.256 +			return reqSize;
   1.257 +			}
   1.258 +		}
   1.259 +	if (reqSize>aHostBuffer.MaxLength())
   1.260 +		{
   1.261 +		return reqSize/aObjectSize;
   1.262 +		}
   1.263 +	if (reqSize==0)
   1.264 +		{
   1.265 +		reqSize=aHostBuffer.MaxLength();
   1.266 +		}
   1.267 +	if ((reqSize%aObjectSize)!=0)
   1.268 +		{
   1.269 +		return KErrCorrupt;
   1.270 +		}
   1.271 +	aReturnedObject=(const void*)aHostBuffer.Ptr();
   1.272 +	reqSize/=aObjectSize;
   1.273 +	return reqSize;
   1.274 +	}
   1.275 +
   1.276 +void CWsGceCscBase::SetCompositionMode(RWindow& aWindow, TDisplayMode aMode)
   1.277 +	{
   1.278 +		iDisplayMode = (TDisplayMode)aWindow.SetRequiredDisplayMode(aMode);
   1.279 +		aWindow.Invalidate();
   1.280 +		aWindow.BeginRedraw();
   1.281 +		aWindow.EndRedraw();
   1.282 +	}
   1.283 +
   1.284 +TBool CWsGceCscBase::Compare(CFbsBitmap& aBitmap1, CFbsBitmap& aBitmap2)
   1.285 +	{
   1.286 +	if ((aBitmap1.SizeInPixels() == aBitmap2.SizeInPixels()) &&
   1.287 +		(aBitmap1.DisplayMode() == aBitmap2.DisplayMode()))
   1.288 +		{
   1.289 +		TSize size = aBitmap1.SizeInPixels();
   1.290 +		TInt width = size.iWidth;
   1.291 +		TInt height = size.iHeight;
   1.292 +		TRgb color1, color2;
   1.293 +		
   1.294 +		for (TInt i = 0; i < width; i++)
   1.295 +			{
   1.296 +			for (TInt j = 0; j < height; j++)
   1.297 +				{
   1.298 +				aBitmap1.GetPixel(color1, TPoint(i, j));
   1.299 +				aBitmap2.GetPixel(color2, TPoint(i, j));
   1.300 +				if (color1 != color2)
   1.301 +					{
   1.302 +					return EFalse;
   1.303 +					}
   1.304 +				}
   1.305 +			}
   1.306 +		
   1.307 +		return ETrue;
   1.308 +		}
   1.309 +	return EFalse;
   1.310 +	}
   1.311 +
   1.312 +void CWsGceCscBase::ConstructOpaqueWindowL(RWindow& aWindow, 
   1.313 +		                                   const TRgb& aColor, 
   1.314 +		                                   TInt aPos,
   1.315 +		                                   const TPoint &aPoint, 
   1.316 +		                                   const TSize &aSize)
   1.317 +	{
   1.318 +	ASSERT_EQUALS_X(aWindow.Construct(iGroup, ++iWindowHandle), KErrNone);
   1.319 +	aWindow.SetRequiredDisplayMode(iDisplayMode);
   1.320 +	aWindow.SetExtent(aPoint, aSize);
   1.321 +	aWindow.SetBackgroundColor(aColor);
   1.322 +	aWindow.SetOrdinalPosition(aPos);	
   1.323 +	aWindow.Activate();
   1.324 +	aWindow.BeginRedraw();
   1.325 +	iGc->Activate(aWindow);
   1.326 +	iGc->Deactivate();
   1.327 +	aWindow.EndRedraw();
   1.328 +	}
   1.329 +
   1.330 +void CWsGceCscBase::ConstructOpaqueWindowLC(RWindow& aWindow, 
   1.331 +		                                    const TRgb& aColor, 
   1.332 +		                                    TInt aPos,
   1.333 +		                                    const TPoint &aPoint, 
   1.334 +		                                    const TSize &aSize)
   1.335 +	{
   1.336 +	ASSERT_EQUALS_X(aWindow.Construct(iGroup, ++iWindowHandle), KErrNone);
   1.337 +	CleanupClosePushL(aWindow);
   1.338 +	aWindow.SetRequiredDisplayMode(iDisplayMode);
   1.339 +	aWindow.SetExtent(aPoint, aSize);
   1.340 +	aWindow.SetBackgroundColor(aColor);
   1.341 +	aWindow.SetOrdinalPosition(aPos);
   1.342 +	aWindow.SetVisible(ETrue);
   1.343 +	aWindow.Activate();
   1.344 +	aWindow.BeginRedraw();
   1.345 +	iGc->Activate(aWindow);
   1.346 +	iGc->Clear();
   1.347 +	iGc->Deactivate();
   1.348 +	aWindow.EndRedraw();
   1.349 +	}
   1.350 +
   1.351 +
   1.352 +void CWsGceCscBase::SetBackgroundColorWindow(RWindow& aWindow, const TRgb& aColor)
   1.353 +	{
   1.354 +	aWindow.Invalidate();
   1.355 +	aWindow.SetBackgroundColor(aColor);
   1.356 +	aWindow.BeginRedraw();
   1.357 +	iGc->Activate(aWindow);
   1.358 +	iGc->Deactivate();
   1.359 +	aWindow.EndRedraw();
   1.360 +	}
   1.361 +
   1.362 +void CWsGceCscBase::ConstructOpaqueSurfacedWindowLC(RWindow& aWindow,
   1.363 +		                                            const TRgb& aColor, 
   1.364 +		                                            TInt aPos,
   1.365 +		                                            const TPoint &aPoint, 
   1.366 +		                                            const TSize &aSize,
   1.367 +		                                            TSurfaceId& aSurfaceID)
   1.368 +	{
   1.369 +	ASSERT_EQUALS_X(aWindow.Construct(iGroup, ++iWindowHandle), KErrNone);
   1.370 +	CleanupClosePushL(aWindow);
   1.371 +	aWindow.SetRequiredDisplayMode(iDisplayMode);
   1.372 +	aWindow.SetExtent(aPoint, aSize);
   1.373 +	aWindow.SetBackgroundColor(aColor);
   1.374 +	aWindow.SetOrdinalPosition(aPos);	
   1.375 +	ASSERT_EQUALS_X(aWindow.SetBackgroundSurface(aSurfaceID), KErrNone);
   1.376 +	aWindow.Activate();
   1.377 +	aWindow.BeginRedraw();
   1.378 +	iGc->Activate(aWindow);
   1.379 +	iGc->Deactivate();
   1.380 +	aWindow.EndRedraw();
   1.381 +	}
   1.382 +
   1.383 +void CWsGceCscBase::ConstructOpaqueSurfacedWindowL(RWindow& aWindow,
   1.384 +		                                           const TRgb& aColor, 
   1.385 +		                                           TInt aPos,
   1.386 +		                                           const TPoint& aPoint, 
   1.387 +		                                           const TSize& aSize,
   1.388 +		                                           const TSurfaceId& aSurfaceID)
   1.389 +	{
   1.390 +	ASSERT_EQUALS_X(aWindow.Construct(iGroup, ++iWindowHandle), KErrNone);
   1.391 +	aWindow.SetRequiredDisplayMode(iDisplayMode);
   1.392 +	aWindow.SetExtent(aPoint, aSize);
   1.393 +	aWindow.SetBackgroundColor(aColor);
   1.394 +	aWindow.SetOrdinalPosition(aPos);	
   1.395 +	ASSERT_EQUALS_X(aWindow.SetBackgroundSurface(aSurfaceID), KErrNone);
   1.396 +	aWindow.Activate();
   1.397 +	aWindow.BeginRedraw();
   1.398 +	iGc->Activate(aWindow);
   1.399 +	iGc->Deactivate();
   1.400 +	aWindow.EndRedraw();
   1.401 +	}
   1.402 +
   1.403 +