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