os/graphics/egl/egltest/endpointtestsuite/automated/tinc/egltest_parameters.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 /**
    17  @file
    18  @test
    19  @internalComponent - Internal Symbian test code
    20 */
    21 
    22 
    23 #ifndef __EGLTEST_PARAMETERS_H__
    24 #define __EGLTEST_PARAMETERS_H__
    25 
    26 
    27 #include <e32base.h>
    28 #include <EGL/egl.h>
    29 #include <EGL/eglext.h>
    30 
    31 
    32 //This table defines the candidate constants that could be used as bad
    33 //parameters. They are candidate becuase they will be evaluated at runtime and
    34 //if any conflict with known good params, they will be excluded. When creating
    35 //the dynamic list, non static params are added such as [validParam] + 1.
    36 const TInt KCandidateBadParams[] =
    37     {
    38     0,
    39     4,
    40     5,
    41     0xBADFEE0,
    42     0xBADFEED
    43     };
    44 const TInt KNumCandidateBadParams = sizeof(KCandidateBadParams)/sizeof(KCandidateBadParams[0]);
    45 
    46 
    47 template <typename T>
    48 class CParameters : public CBase
    49     {
    50 public:
    51     static CParameters* NewLC(TBool aCreateBadParams, const RArray<T>& aValidParamsArray, TInt aIndex);
    52     static CParameters* NewLC(TBool aCreateBadParams, const T* aValidParamsArray, TInt aCount, TInt aIndex);
    53     static CParameters* NewLC(TBool aCreateBadParams, T aValidParam);
    54     ~CParameters();
    55     TInt Count() const;
    56     T& operator[](TInt aIndex);
    57     const T& operator[](TInt aIndex) const;
    58 
    59 private:
    60     CParameters();
    61     void ConstructL(TBool aCreateBadParams, const RArray<T>& aValidParamsArray, TInt aIndex);
    62     void ConstructL(TBool aCreateBadParams, const T* aValidParamsArray, TInt aCount, TInt aIndex);
    63     void ConstructL(TBool aCreateBadParams, T aValidParam);
    64 
    65     void MakeBadParamsL(const RArray<T>& aValidParamsArray);
    66     void MakeGoodParamsL(const RArray<T>& aValidParamsArray, TInt aIndex);
    67 
    68     TBool IsErrorValue(const T aValue) const;
    69 private:
    70     RArray<T> iParams;
    71     };
    72 
    73 
    74 typedef CParameters<EGLDisplay> CDisplayParams;
    75 typedef CParameters<EGLEndpointNOK> CEndpointParams;
    76 typedef CParameters<EGLImageKHR> CImageParams;
    77 typedef CParameters<EGLenum> CEnumParams;
    78 typedef CParameters<EGLint> CIntParams;
    79 typedef CParameters<TSurfaceId> CSurfaceIdParams;
    80 typedef CParameters<TRequestStatus *> CSyncParams;
    81 
    82 template <typename T>
    83 CParameters<T>* CParameters<T>::NewLC(TBool aCreateBadParams, const RArray<T>& aValidParamsArray, TInt aIndex)
    84     {
    85     CParameters<T>* obj = new (ELeave) CParameters();
    86     CleanupStack::PushL(obj);
    87     obj->ConstructL(aCreateBadParams, aValidParamsArray);
    88     return obj;
    89     }
    90 
    91 
    92 template <typename T>
    93 CParameters<T>* CParameters<T>::NewLC(TBool aCreateBadParams, const T* aValidParamsArray, TInt aCount, TInt aIndex)
    94     {
    95     CParameters<T>* obj = new (ELeave) CParameters();
    96     CleanupStack::PushL(obj);
    97     obj->ConstructL(aCreateBadParams, aValidParamsArray, aCount, aIndex);
    98     return obj;
    99     }
   100 
   101 
   102 template <typename T>
   103 CParameters<T>* CParameters<T>::NewLC(TBool aCreateBadParams, T aValidParam)
   104     {
   105     CParameters<T>* obj = new (ELeave) CParameters();
   106     CleanupStack::PushL(obj);
   107     obj->ConstructL(aCreateBadParams, aValidParam);
   108     return obj;
   109     }
   110 
   111 template <typename T>
   112 CParameters<T>::CParameters()
   113     {
   114     }
   115 
   116 
   117 template <typename T>
   118 void CParameters<T>::ConstructL(TBool aCreateBadParams, const RArray<T>& aValidParamsArray, TInt aIndex)
   119     {
   120     if(aCreateBadParams)
   121         {
   122         MakeBadParamsL(aValidParamsArray);
   123         }
   124     else
   125         {
   126         MakeGoodParamsL(aValidParamsArray, aIndex);
   127         }
   128     }
   129 
   130 
   131 template <typename T>
   132 void CParameters<T>::ConstructL(TBool aCreateBadParams, const T* aValidParamsArray, TInt aCount, TInt aIndex)
   133     {
   134     RArray<T> validParamsArray;
   135     CleanupClosePushL(validParamsArray);
   136     for(TInt i=0; i < aCount; i++)
   137         {
   138         validParamsArray.AppendL(aValidParamsArray[i]);
   139         }
   140     ConstructL(aCreateBadParams, validParamsArray, aIndex);
   141     CleanupStack::PopAndDestroy(1);
   142     }
   143 
   144 
   145 template <typename T>
   146 void CParameters<T>::ConstructL(TBool aCreateBadParams, T aValidParam)
   147     {
   148     ConstructL(aCreateBadParams, &aValidParam, 1, 0);
   149     }
   150 
   151 
   152 template <typename T>
   153 void CParameters<T>::MakeGoodParamsL(const RArray<T>& aValidParamsArray, TInt aIndex)
   154     {
   155     ASSERT(iParams.Count() == 0);
   156     iParams.AppendL(aValidParamsArray[aIndex]);
   157     }
   158 
   159 
   160 template <typename T>
   161 void CParameters<T>::MakeBadParamsL(const RArray<T>& aValidParamsArray)
   162     {
   163     RArray<T> candidateParams;
   164     CleanupClosePushL(candidateParams);
   165 
   166     //Pack the static bad params into an candidateParams.
   167     for(TInt i=0; i < KNumCandidateBadParams; i++)
   168         {
   169         candidateParams.AppendL((T)KCandidateBadParams[i]);
   170         }
   171 
   172     //Pack the dynamic bad params (ie validParam+1 for each valid param).
   173     for(TInt i=0; i < aValidParamsArray.Count(); i++)
   174         {
   175         candidateParams.AppendL((T)((TInt)aValidParamsArray[i] + 1));
   176         }
   177 
   178     //Iterate over candidateParams and add them to the final
   179     //bad params array if they don't clash with any valid params.
   180     for(TInt i=0; i < candidateParams.Count(); i++)
   181         {
   182         TBool useCurParam = ETrue;
   183         for(TInt n=0; n < aValidParamsArray.Count(); n++)
   184             {
   185             if(!IsErrorValue(aValidParamsArray[n]) && candidateParams[i] == aValidParamsArray[n])
   186                 {
   187                 useCurParam = EFalse;
   188                 break;
   189                 }
   190             }
   191         // Check if it's already in the list - no point in testing the same value more than once.
   192         for(TInt j = 0; useCurParam && j < iParams.Count(); j++)
   193             {
   194             if (candidateParams[i] == iParams[j])
   195                 {
   196                 useCurParam = EFalse;
   197                 }
   198             }
   199 
   200         if(useCurParam)
   201             {
   202             iParams.AppendL(candidateParams[i]);
   203             }
   204         }
   205 
   206     //Final bad params are in iParams. Delete candidateParams.
   207     CleanupStack::PopAndDestroy(1);
   208     }
   209 
   210 template <typename T>
   211 TBool CParameters<T>::IsErrorValue(const T aValue) const
   212     {
   213     return aValue == 0;   // Default value, eg. EGL_NO_DISPLAY
   214     }
   215 
   216 template <>
   217 TBool CParameters<TSurfaceId>::IsErrorValue(const TSurfaceId aValue) const
   218     {
   219     return aValue.IsNull();
   220     }
   221 
   222 template <typename T>
   223 CParameters<T>::~CParameters()
   224     {
   225     iParams.Close();
   226     }
   227 
   228 
   229 template <typename T>
   230 TInt CParameters<T>::Count() const
   231     {
   232     return iParams.Count();
   233     }
   234 
   235 
   236 template <typename T>
   237 T& CParameters<T>::operator[](TInt aIndex)
   238     {
   239     return iParams[aIndex];
   240     }
   241 
   242 
   243 template <typename T>
   244 const T& CParameters<T>::operator[](TInt aIndex) const
   245     {
   246     return iParams[aIndex];
   247     }
   248 
   249 template<>
   250 void CParameters<TSurfaceId>::MakeBadParamsL(const RArray<TSurfaceId>& aValidParamsArray)
   251     {
   252     RArray<TSurfaceId> candidateParams;
   253     CleanupClosePushL(candidateParams);
   254 
   255     static const TSurfaceId KCandidateSurfaceBadParams[]=
   256     {
   257             { 0 },
   258             { 12346, 18129, 192121, 98198 },
   259             { 11111, 22222, 222222, 33333 },
   260             { -1, -1, -1, -1 },
   261             { 0x80000000, 0x80000000, 0x80000000, 0x80000000 },
   262             { 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF },
   263     };
   264     //Pack the static bad params into an candidateParams.
   265     for(TInt i=0; i < KNumCandidateBadParams; i++)
   266         {
   267         candidateParams.AppendL(KCandidateSurfaceBadParams[i]);
   268         }
   269 
   270     //Pack the dynamic bad params (ie validParam+1 for each valid param).
   271     for(TInt i=0; i < aValidParamsArray.Count(); i++)
   272         {
   273         TSurfaceId id = aValidParamsArray[i];
   274         id.iInternal[3]++;
   275         candidateParams.AppendL(id);
   276         }
   277 
   278     RSurfaceManager surfManager;
   279     User::LeaveIfError(surfManager.Open());
   280     CleanupClosePushL(surfManager);
   281     //Iterate over candidateParams and add them to the final
   282     //bad params array if they don't clash with any valid params.
   283     for(TInt i=0; i < candidateParams.Count(); i++)
   284         {
   285         TBool useCurParam = ETrue;
   286         for(TInt n=0; n < aValidParamsArray.Count(); n++)
   287             {
   288             TInt err = surfManager.OpenSurface(candidateParams[i]);
   289             if(err == KErrNone && !IsErrorValue(aValidParamsArray[n]) && candidateParams[i] == aValidParamsArray[n])
   290                 {
   291                 // It is unlikely we get here for ANY reason, but we always close the surface -
   292                 // it may not have successfully opened, but it's fine to do even if we didn't successfully open
   293                 // the surface. Just ignore any error.
   294                 surfManager.CloseSurface(candidateParams[i]);
   295                 useCurParam = EFalse;
   296                 break;
   297                 }
   298             }
   299         if(useCurParam)
   300             {
   301             iParams.AppendL(candidateParams[i]);
   302             }
   303         }
   304     //Final bad params are in iParams. Delete candidateParams, and close surfManager.
   305     CleanupStack::PopAndDestroy(2);
   306     }
   307 
   308 template<>
   309 void CParameters<TRequestStatus *>::MakeBadParamsL(const RArray<TRequestStatus *>& /* aValidParamsArray */)
   310     {
   311     // Currently, the only TRequestStatus that we can test for is NULL.
   312     // Since TRequestStatus can be any valid memory, it is impossible to
   313     // test for "bad" values by any simple measure - the app will panic
   314     // if random address is passed along, but there is no easy way to determine
   315     // if it's a valid or invalid address.
   316     iParams.AppendL(0);
   317     }
   318 
   319 #endif