os/graphics/egl/egltest/endpointtestsuite/automated/tinc/egltest_parameters.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/egl/egltest/endpointtestsuite/automated/tinc/egltest_parameters.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,319 @@
     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 +//
    1.18 +
    1.19 +/**
    1.20 + @file
    1.21 + @test
    1.22 + @internalComponent - Internal Symbian test code
    1.23 +*/
    1.24 +
    1.25 +
    1.26 +#ifndef __EGLTEST_PARAMETERS_H__
    1.27 +#define __EGLTEST_PARAMETERS_H__
    1.28 +
    1.29 +
    1.30 +#include <e32base.h>
    1.31 +#include <EGL/egl.h>
    1.32 +#include <EGL/eglext.h>
    1.33 +
    1.34 +
    1.35 +//This table defines the candidate constants that could be used as bad
    1.36 +//parameters. They are candidate becuase they will be evaluated at runtime and
    1.37 +//if any conflict with known good params, they will be excluded. When creating
    1.38 +//the dynamic list, non static params are added such as [validParam] + 1.
    1.39 +const TInt KCandidateBadParams[] =
    1.40 +    {
    1.41 +    0,
    1.42 +    4,
    1.43 +    5,
    1.44 +    0xBADFEE0,
    1.45 +    0xBADFEED
    1.46 +    };
    1.47 +const TInt KNumCandidateBadParams = sizeof(KCandidateBadParams)/sizeof(KCandidateBadParams[0]);
    1.48 +
    1.49 +
    1.50 +template <typename T>
    1.51 +class CParameters : public CBase
    1.52 +    {
    1.53 +public:
    1.54 +    static CParameters* NewLC(TBool aCreateBadParams, const RArray<T>& aValidParamsArray, TInt aIndex);
    1.55 +    static CParameters* NewLC(TBool aCreateBadParams, const T* aValidParamsArray, TInt aCount, TInt aIndex);
    1.56 +    static CParameters* NewLC(TBool aCreateBadParams, T aValidParam);
    1.57 +    ~CParameters();
    1.58 +    TInt Count() const;
    1.59 +    T& operator[](TInt aIndex);
    1.60 +    const T& operator[](TInt aIndex) const;
    1.61 +
    1.62 +private:
    1.63 +    CParameters();
    1.64 +    void ConstructL(TBool aCreateBadParams, const RArray<T>& aValidParamsArray, TInt aIndex);
    1.65 +    void ConstructL(TBool aCreateBadParams, const T* aValidParamsArray, TInt aCount, TInt aIndex);
    1.66 +    void ConstructL(TBool aCreateBadParams, T aValidParam);
    1.67 +
    1.68 +    void MakeBadParamsL(const RArray<T>& aValidParamsArray);
    1.69 +    void MakeGoodParamsL(const RArray<T>& aValidParamsArray, TInt aIndex);
    1.70 +
    1.71 +    TBool IsErrorValue(const T aValue) const;
    1.72 +private:
    1.73 +    RArray<T> iParams;
    1.74 +    };
    1.75 +
    1.76 +
    1.77 +typedef CParameters<EGLDisplay> CDisplayParams;
    1.78 +typedef CParameters<EGLEndpointNOK> CEndpointParams;
    1.79 +typedef CParameters<EGLImageKHR> CImageParams;
    1.80 +typedef CParameters<EGLenum> CEnumParams;
    1.81 +typedef CParameters<EGLint> CIntParams;
    1.82 +typedef CParameters<TSurfaceId> CSurfaceIdParams;
    1.83 +typedef CParameters<TRequestStatus *> CSyncParams;
    1.84 +
    1.85 +template <typename T>
    1.86 +CParameters<T>* CParameters<T>::NewLC(TBool aCreateBadParams, const RArray<T>& aValidParamsArray, TInt aIndex)
    1.87 +    {
    1.88 +    CParameters<T>* obj = new (ELeave) CParameters();
    1.89 +    CleanupStack::PushL(obj);
    1.90 +    obj->ConstructL(aCreateBadParams, aValidParamsArray);
    1.91 +    return obj;
    1.92 +    }
    1.93 +
    1.94 +
    1.95 +template <typename T>
    1.96 +CParameters<T>* CParameters<T>::NewLC(TBool aCreateBadParams, const T* aValidParamsArray, TInt aCount, TInt aIndex)
    1.97 +    {
    1.98 +    CParameters<T>* obj = new (ELeave) CParameters();
    1.99 +    CleanupStack::PushL(obj);
   1.100 +    obj->ConstructL(aCreateBadParams, aValidParamsArray, aCount, aIndex);
   1.101 +    return obj;
   1.102 +    }
   1.103 +
   1.104 +
   1.105 +template <typename T>
   1.106 +CParameters<T>* CParameters<T>::NewLC(TBool aCreateBadParams, T aValidParam)
   1.107 +    {
   1.108 +    CParameters<T>* obj = new (ELeave) CParameters();
   1.109 +    CleanupStack::PushL(obj);
   1.110 +    obj->ConstructL(aCreateBadParams, aValidParam);
   1.111 +    return obj;
   1.112 +    }
   1.113 +
   1.114 +template <typename T>
   1.115 +CParameters<T>::CParameters()
   1.116 +    {
   1.117 +    }
   1.118 +
   1.119 +
   1.120 +template <typename T>
   1.121 +void CParameters<T>::ConstructL(TBool aCreateBadParams, const RArray<T>& aValidParamsArray, TInt aIndex)
   1.122 +    {
   1.123 +    if(aCreateBadParams)
   1.124 +        {
   1.125 +        MakeBadParamsL(aValidParamsArray);
   1.126 +        }
   1.127 +    else
   1.128 +        {
   1.129 +        MakeGoodParamsL(aValidParamsArray, aIndex);
   1.130 +        }
   1.131 +    }
   1.132 +
   1.133 +
   1.134 +template <typename T>
   1.135 +void CParameters<T>::ConstructL(TBool aCreateBadParams, const T* aValidParamsArray, TInt aCount, TInt aIndex)
   1.136 +    {
   1.137 +    RArray<T> validParamsArray;
   1.138 +    CleanupClosePushL(validParamsArray);
   1.139 +    for(TInt i=0; i < aCount; i++)
   1.140 +        {
   1.141 +        validParamsArray.AppendL(aValidParamsArray[i]);
   1.142 +        }
   1.143 +    ConstructL(aCreateBadParams, validParamsArray, aIndex);
   1.144 +    CleanupStack::PopAndDestroy(1);
   1.145 +    }
   1.146 +
   1.147 +
   1.148 +template <typename T>
   1.149 +void CParameters<T>::ConstructL(TBool aCreateBadParams, T aValidParam)
   1.150 +    {
   1.151 +    ConstructL(aCreateBadParams, &aValidParam, 1, 0);
   1.152 +    }
   1.153 +
   1.154 +
   1.155 +template <typename T>
   1.156 +void CParameters<T>::MakeGoodParamsL(const RArray<T>& aValidParamsArray, TInt aIndex)
   1.157 +    {
   1.158 +    ASSERT(iParams.Count() == 0);
   1.159 +    iParams.AppendL(aValidParamsArray[aIndex]);
   1.160 +    }
   1.161 +
   1.162 +
   1.163 +template <typename T>
   1.164 +void CParameters<T>::MakeBadParamsL(const RArray<T>& aValidParamsArray)
   1.165 +    {
   1.166 +    RArray<T> candidateParams;
   1.167 +    CleanupClosePushL(candidateParams);
   1.168 +
   1.169 +    //Pack the static bad params into an candidateParams.
   1.170 +    for(TInt i=0; i < KNumCandidateBadParams; i++)
   1.171 +        {
   1.172 +        candidateParams.AppendL((T)KCandidateBadParams[i]);
   1.173 +        }
   1.174 +
   1.175 +    //Pack the dynamic bad params (ie validParam+1 for each valid param).
   1.176 +    for(TInt i=0; i < aValidParamsArray.Count(); i++)
   1.177 +        {
   1.178 +        candidateParams.AppendL((T)((TInt)aValidParamsArray[i] + 1));
   1.179 +        }
   1.180 +
   1.181 +    //Iterate over candidateParams and add them to the final
   1.182 +    //bad params array if they don't clash with any valid params.
   1.183 +    for(TInt i=0; i < candidateParams.Count(); i++)
   1.184 +        {
   1.185 +        TBool useCurParam = ETrue;
   1.186 +        for(TInt n=0; n < aValidParamsArray.Count(); n++)
   1.187 +            {
   1.188 +            if(!IsErrorValue(aValidParamsArray[n]) && candidateParams[i] == aValidParamsArray[n])
   1.189 +                {
   1.190 +                useCurParam = EFalse;
   1.191 +                break;
   1.192 +                }
   1.193 +            }
   1.194 +        // Check if it's already in the list - no point in testing the same value more than once.
   1.195 +        for(TInt j = 0; useCurParam && j < iParams.Count(); j++)
   1.196 +            {
   1.197 +            if (candidateParams[i] == iParams[j])
   1.198 +                {
   1.199 +                useCurParam = EFalse;
   1.200 +                }
   1.201 +            }
   1.202 +
   1.203 +        if(useCurParam)
   1.204 +            {
   1.205 +            iParams.AppendL(candidateParams[i]);
   1.206 +            }
   1.207 +        }
   1.208 +
   1.209 +    //Final bad params are in iParams. Delete candidateParams.
   1.210 +    CleanupStack::PopAndDestroy(1);
   1.211 +    }
   1.212 +
   1.213 +template <typename T>
   1.214 +TBool CParameters<T>::IsErrorValue(const T aValue) const
   1.215 +    {
   1.216 +    return aValue == 0;   // Default value, eg. EGL_NO_DISPLAY
   1.217 +    }
   1.218 +
   1.219 +template <>
   1.220 +TBool CParameters<TSurfaceId>::IsErrorValue(const TSurfaceId aValue) const
   1.221 +    {
   1.222 +    return aValue.IsNull();
   1.223 +    }
   1.224 +
   1.225 +template <typename T>
   1.226 +CParameters<T>::~CParameters()
   1.227 +    {
   1.228 +    iParams.Close();
   1.229 +    }
   1.230 +
   1.231 +
   1.232 +template <typename T>
   1.233 +TInt CParameters<T>::Count() const
   1.234 +    {
   1.235 +    return iParams.Count();
   1.236 +    }
   1.237 +
   1.238 +
   1.239 +template <typename T>
   1.240 +T& CParameters<T>::operator[](TInt aIndex)
   1.241 +    {
   1.242 +    return iParams[aIndex];
   1.243 +    }
   1.244 +
   1.245 +
   1.246 +template <typename T>
   1.247 +const T& CParameters<T>::operator[](TInt aIndex) const
   1.248 +    {
   1.249 +    return iParams[aIndex];
   1.250 +    }
   1.251 +
   1.252 +template<>
   1.253 +void CParameters<TSurfaceId>::MakeBadParamsL(const RArray<TSurfaceId>& aValidParamsArray)
   1.254 +    {
   1.255 +    RArray<TSurfaceId> candidateParams;
   1.256 +    CleanupClosePushL(candidateParams);
   1.257 +
   1.258 +    static const TSurfaceId KCandidateSurfaceBadParams[]=
   1.259 +    {
   1.260 +            { 0 },
   1.261 +            { 12346, 18129, 192121, 98198 },
   1.262 +            { 11111, 22222, 222222, 33333 },
   1.263 +            { -1, -1, -1, -1 },
   1.264 +            { 0x80000000, 0x80000000, 0x80000000, 0x80000000 },
   1.265 +            { 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF },
   1.266 +    };
   1.267 +    //Pack the static bad params into an candidateParams.
   1.268 +    for(TInt i=0; i < KNumCandidateBadParams; i++)
   1.269 +        {
   1.270 +        candidateParams.AppendL(KCandidateSurfaceBadParams[i]);
   1.271 +        }
   1.272 +
   1.273 +    //Pack the dynamic bad params (ie validParam+1 for each valid param).
   1.274 +    for(TInt i=0; i < aValidParamsArray.Count(); i++)
   1.275 +        {
   1.276 +        TSurfaceId id = aValidParamsArray[i];
   1.277 +        id.iInternal[3]++;
   1.278 +        candidateParams.AppendL(id);
   1.279 +        }
   1.280 +
   1.281 +    RSurfaceManager surfManager;
   1.282 +    User::LeaveIfError(surfManager.Open());
   1.283 +    CleanupClosePushL(surfManager);
   1.284 +    //Iterate over candidateParams and add them to the final
   1.285 +    //bad params array if they don't clash with any valid params.
   1.286 +    for(TInt i=0; i < candidateParams.Count(); i++)
   1.287 +        {
   1.288 +        TBool useCurParam = ETrue;
   1.289 +        for(TInt n=0; n < aValidParamsArray.Count(); n++)
   1.290 +            {
   1.291 +            TInt err = surfManager.OpenSurface(candidateParams[i]);
   1.292 +            if(err == KErrNone && !IsErrorValue(aValidParamsArray[n]) && candidateParams[i] == aValidParamsArray[n])
   1.293 +                {
   1.294 +                // It is unlikely we get here for ANY reason, but we always close the surface -
   1.295 +                // it may not have successfully opened, but it's fine to do even if we didn't successfully open
   1.296 +                // the surface. Just ignore any error.
   1.297 +                surfManager.CloseSurface(candidateParams[i]);
   1.298 +                useCurParam = EFalse;
   1.299 +                break;
   1.300 +                }
   1.301 +            }
   1.302 +        if(useCurParam)
   1.303 +            {
   1.304 +            iParams.AppendL(candidateParams[i]);
   1.305 +            }
   1.306 +        }
   1.307 +    //Final bad params are in iParams. Delete candidateParams, and close surfManager.
   1.308 +    CleanupStack::PopAndDestroy(2);
   1.309 +    }
   1.310 +
   1.311 +template<>
   1.312 +void CParameters<TRequestStatus *>::MakeBadParamsL(const RArray<TRequestStatus *>& /* aValidParamsArray */)
   1.313 +    {
   1.314 +    // Currently, the only TRequestStatus that we can test for is NULL.
   1.315 +    // Since TRequestStatus can be any valid memory, it is impossible to
   1.316 +    // test for "bad" values by any simple measure - the app will panic
   1.317 +    // if random address is passed along, but there is no easy way to determine
   1.318 +    // if it's a valid or invalid address.
   1.319 +    iParams.AppendL(0);
   1.320 +    }
   1.321 +
   1.322 +#endif