diff -r cdf2f6e5c390 -r bf7481649c98 egl/egltest/endpointtestsuite/automated/tinc/egltest_parameters.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/egl/egltest/endpointtestsuite/automated/tinc/egltest_parameters.h Fri Jun 11 14:58:47 2010 +0300 @@ -0,0 +1,320 @@ +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// + +/** + @file + @test + @internalComponent - Internal Symbian test code +*/ + + +#ifndef __EGLTEST_PARAMETERS_H__ +#define __EGLTEST_PARAMETERS_H__ + + +#include +#include +#include + + +//This table defines the candidate constants that could be used as bad +//parameters. They are candidate becuase they will be evaluated at runtime and +//if any conflict with known good params, they will be excluded. When creating +//the dynamic list, non static params are added such as [validParam] + 1. +const TInt KCandidateBadParams[] = + { + 0, + 4, + 5, + 0xBADFEE0, + 0xBADFEED + }; +const TInt KNumCandidateBadParams = sizeof(KCandidateBadParams)/sizeof(KCandidateBadParams[0]); + + +template +class CParameters : public CBase + { +public: + static CParameters* NewLC(TBool aCreateBadParams, const RArray& aValidParamsArray, TInt aIndex); + static CParameters* NewLC(TBool aCreateBadParams, const T* aValidParamsArray, TInt aCount, TInt aIndex); + static CParameters* NewLC(TBool aCreateBadParams, T aValidParam); + ~CParameters(); + TInt Count() const; + T& operator[](TInt aIndex); + const T& operator[](TInt aIndex) const; + +private: + CParameters(); + void ConstructL(TBool aCreateBadParams, const RArray& aValidParamsArray, TInt aIndex); + void ConstructL(TBool aCreateBadParams, const T* aValidParamsArray, TInt aCount, TInt aIndex); + void ConstructL(TBool aCreateBadParams, T aValidParam); + + void MakeBadParamsL(const RArray& aValidParamsArray); + void MakeGoodParamsL(const RArray& aValidParamsArray, TInt aIndex); + + TBool IsErrorValue(const T aValue) const; +private: + RArray iParams; + }; + + +typedef CParameters CDisplayParams; +typedef CParameters CEndpointParams; +typedef CParameters CImageParams; +typedef CParameters CEnumParams; +typedef CParameters CIntParams; +typedef CParameters CSurfaceIdParams; +typedef CParameters CSyncParams; + +template +CParameters* CParameters::NewLC(TBool aCreateBadParams, const RArray& aValidParamsArray, TInt aIndex) + { + CParameters* obj = new (ELeave) CParameters(); + CleanupStack::PushL(obj); + obj->ConstructL(aCreateBadParams, aValidParamsArray); + return obj; + } + + +template +CParameters* CParameters::NewLC(TBool aCreateBadParams, const T* aValidParamsArray, TInt aCount, TInt aIndex) + { + CParameters* obj = new (ELeave) CParameters(); + CleanupStack::PushL(obj); + obj->ConstructL(aCreateBadParams, aValidParamsArray, aCount, aIndex); + return obj; + } + + +template +CParameters* CParameters::NewLC(TBool aCreateBadParams, T aValidParam) + { + CParameters* obj = new (ELeave) CParameters(); + CleanupStack::PushL(obj); + obj->ConstructL(aCreateBadParams, aValidParam); + return obj; + } + +template +CParameters::CParameters() + { + } + + +template +void CParameters::ConstructL(TBool aCreateBadParams, const RArray& aValidParamsArray, TInt aIndex) + { + if(aCreateBadParams) + { + MakeBadParamsL(aValidParamsArray); + } + else + { + MakeGoodParamsL(aValidParamsArray, aIndex); + } + } + + +template +void CParameters::ConstructL(TBool aCreateBadParams, const T* aValidParamsArray, TInt aCount, TInt aIndex) + { + RArray validParamsArray; + CleanupClosePushL(validParamsArray); + for(TInt i=0; i < aCount; i++) + { + validParamsArray.AppendL(aValidParamsArray[i]); + } + ConstructL(aCreateBadParams, validParamsArray, aIndex); + CleanupStack::PopAndDestroy(1); + } + + +template +void CParameters::ConstructL(TBool aCreateBadParams, T aValidParam) + { + ConstructL(aCreateBadParams, &aValidParam, 1, 0); + } + + +template +void CParameters::MakeGoodParamsL(const RArray& aValidParamsArray, TInt aIndex) + { + ASSERT(iParams.Count() == 0); + iParams.AppendL(aValidParamsArray[aIndex]); + } + + +template +void CParameters::MakeBadParamsL(const RArray& aValidParamsArray) + { + RArray candidateParams; + CleanupClosePushL(candidateParams); + + //Pack the static bad params into an candidateParams. + for(TInt i=0; i < KNumCandidateBadParams; i++) + { + candidateParams.AppendL((T)KCandidateBadParams[i]); + } + + //Pack the dynamic bad params (ie validParam+1 for each valid param). + for(TInt i=0; i < aValidParamsArray.Count(); i++) + { + candidateParams.AppendL((T)((TInt)aValidParamsArray[i] + 1)); + } + + //Iterate over candidateParams and add them to the final + //bad params array if they don't clash with any valid params. + for(TInt i=0; i < candidateParams.Count(); i++) + { + TBool useCurParam = ETrue; + for(TInt n=0; n < aValidParamsArray.Count(); n++) + { + if(!IsErrorValue(aValidParamsArray[n]) && candidateParams[i] == aValidParamsArray[n]) + { + useCurParam = EFalse; + break; + } + } + // Can/should we use "search" here? + // Check if it's already in the list - no point in testing the same value more than once. + for(TInt j = 0; useCurParam && j < iParams.Count(); j++) + { + if (candidateParams[i] == iParams[j]) + { + useCurParam = EFalse; + } + } + + if(useCurParam) + { + iParams.AppendL(candidateParams[i]); + } + } + + //Final bad params are in iParams. Delete candidateParams. + CleanupStack::PopAndDestroy(1); + } + +template +TBool CParameters::IsErrorValue(const T aValue) const + { + return aValue == 0; // Default value, eg. EGL_NO_DISPLAY + } + +template <> +TBool CParameters::IsErrorValue(const TSurfaceId aValue) const + { + return aValue.IsNull(); + } + +template +CParameters::~CParameters() + { + iParams.Close(); + } + + +template +TInt CParameters::Count() const + { + return iParams.Count(); + } + + +template +T& CParameters::operator[](TInt aIndex) + { + return iParams[aIndex]; + } + + +template +const T& CParameters::operator[](TInt aIndex) const + { + return iParams[aIndex]; + } + +template<> +void CParameters::MakeBadParamsL(const RArray& aValidParamsArray) + { + RArray candidateParams; + CleanupClosePushL(candidateParams); + + static const TSurfaceId KCandidateSurfaceBadParams[]= + { + { 0 }, + { 12346, 18129, 192121, 98198 }, + { 11111, 22222, 222222, 33333 }, + { -1, -1, -1, -1 }, + { 0x80000000, 0x80000000, 0x80000000, 0x80000000 }, + { 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF }, + }; + //Pack the static bad params into an candidateParams. + for(TInt i=0; i < KNumCandidateBadParams; i++) + { + candidateParams.AppendL(KCandidateSurfaceBadParams[i]); + } + + //Pack the dynamic bad params (ie validParam+1 for each valid param). + for(TInt i=0; i < aValidParamsArray.Count(); i++) + { + TSurfaceId id = aValidParamsArray[i]; + id.iInternal[3]++; + candidateParams.AppendL(id); + } + + RSurfaceManager surfManager; + User::LeaveIfError(surfManager.Open()); + CleanupClosePushL(surfManager); + //Iterate over candidateParams and add them to the final + //bad params array if they don't clash with any valid params. + for(TInt i=0; i < candidateParams.Count(); i++) + { + TBool useCurParam = ETrue; + for(TInt n=0; n < aValidParamsArray.Count(); n++) + { + TInt err = surfManager.OpenSurface(candidateParams[i]); + if(err == KErrNone && !IsErrorValue(aValidParamsArray[n]) && candidateParams[i] == aValidParamsArray[n]) + { + // It is unlikely we get here for ANY reason, but we always close the surface - + // it may not have successfully opened, but it's fine to do even if we didn't successfully open + // the surface. Just ignore any error. + surfManager.CloseSurface(candidateParams[i]); + useCurParam = EFalse; + break; + } + } + if(useCurParam) + { + iParams.AppendL(candidateParams[i]); + } + } + //Final bad params are in iParams. Delete candidateParams, and close surfManager. + CleanupStack::PopAndDestroy(2); + } + +template<> +void CParameters::MakeBadParamsL(const RArray& /* aValidParamsArray */) + { + // Currently, the only TRequestStatus that we can test for is NULL. + // Since TRequestStatus can be any valid memory, it is impossible to + // test for "bad" values by any simple measure - the app will panic + // if random address is passed along, but there is no easy way to determine + // if it's a valid or invalid address. + iParams.AppendL(0); + } + +#endif