|
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 // Can/should we use "search" here? |
|
192 // Check if it's already in the list - no point in testing the same value more than once. |
|
193 for(TInt j = 0; useCurParam && j < iParams.Count(); j++) |
|
194 { |
|
195 if (candidateParams[i] == iParams[j]) |
|
196 { |
|
197 useCurParam = EFalse; |
|
198 } |
|
199 } |
|
200 |
|
201 if(useCurParam) |
|
202 { |
|
203 iParams.AppendL(candidateParams[i]); |
|
204 } |
|
205 } |
|
206 |
|
207 //Final bad params are in iParams. Delete candidateParams. |
|
208 CleanupStack::PopAndDestroy(1); |
|
209 } |
|
210 |
|
211 template <typename T> |
|
212 TBool CParameters<T>::IsErrorValue(const T aValue) const |
|
213 { |
|
214 return aValue == 0; // Default value, eg. EGL_NO_DISPLAY |
|
215 } |
|
216 |
|
217 template <> |
|
218 TBool CParameters<TSurfaceId>::IsErrorValue(const TSurfaceId aValue) const |
|
219 { |
|
220 return aValue.IsNull(); |
|
221 } |
|
222 |
|
223 template <typename T> |
|
224 CParameters<T>::~CParameters() |
|
225 { |
|
226 iParams.Close(); |
|
227 } |
|
228 |
|
229 |
|
230 template <typename T> |
|
231 TInt CParameters<T>::Count() const |
|
232 { |
|
233 return iParams.Count(); |
|
234 } |
|
235 |
|
236 |
|
237 template <typename T> |
|
238 T& CParameters<T>::operator[](TInt aIndex) |
|
239 { |
|
240 return iParams[aIndex]; |
|
241 } |
|
242 |
|
243 |
|
244 template <typename T> |
|
245 const T& CParameters<T>::operator[](TInt aIndex) const |
|
246 { |
|
247 return iParams[aIndex]; |
|
248 } |
|
249 |
|
250 template<> |
|
251 void CParameters<TSurfaceId>::MakeBadParamsL(const RArray<TSurfaceId>& aValidParamsArray) |
|
252 { |
|
253 RArray<TSurfaceId> candidateParams; |
|
254 CleanupClosePushL(candidateParams); |
|
255 |
|
256 static const TSurfaceId KCandidateSurfaceBadParams[]= |
|
257 { |
|
258 { 0 }, |
|
259 { 12346, 18129, 192121, 98198 }, |
|
260 { 11111, 22222, 222222, 33333 }, |
|
261 { -1, -1, -1, -1 }, |
|
262 { 0x80000000, 0x80000000, 0x80000000, 0x80000000 }, |
|
263 { 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF }, |
|
264 }; |
|
265 //Pack the static bad params into an candidateParams. |
|
266 for(TInt i=0; i < KNumCandidateBadParams; i++) |
|
267 { |
|
268 candidateParams.AppendL(KCandidateSurfaceBadParams[i]); |
|
269 } |
|
270 |
|
271 //Pack the dynamic bad params (ie validParam+1 for each valid param). |
|
272 for(TInt i=0; i < aValidParamsArray.Count(); i++) |
|
273 { |
|
274 TSurfaceId id = aValidParamsArray[i]; |
|
275 id.iInternal[3]++; |
|
276 candidateParams.AppendL(id); |
|
277 } |
|
278 |
|
279 RSurfaceManager surfManager; |
|
280 User::LeaveIfError(surfManager.Open()); |
|
281 CleanupClosePushL(surfManager); |
|
282 //Iterate over candidateParams and add them to the final |
|
283 //bad params array if they don't clash with any valid params. |
|
284 for(TInt i=0; i < candidateParams.Count(); i++) |
|
285 { |
|
286 TBool useCurParam = ETrue; |
|
287 for(TInt n=0; n < aValidParamsArray.Count(); n++) |
|
288 { |
|
289 TInt err = surfManager.OpenSurface(candidateParams[i]); |
|
290 if(err == KErrNone && !IsErrorValue(aValidParamsArray[n]) && candidateParams[i] == aValidParamsArray[n]) |
|
291 { |
|
292 // It is unlikely we get here for ANY reason, but we always close the surface - |
|
293 // it may not have successfully opened, but it's fine to do even if we didn't successfully open |
|
294 // the surface. Just ignore any error. |
|
295 surfManager.CloseSurface(candidateParams[i]); |
|
296 useCurParam = EFalse; |
|
297 break; |
|
298 } |
|
299 } |
|
300 if(useCurParam) |
|
301 { |
|
302 iParams.AppendL(candidateParams[i]); |
|
303 } |
|
304 } |
|
305 //Final bad params are in iParams. Delete candidateParams, and close surfManager. |
|
306 CleanupStack::PopAndDestroy(2); |
|
307 } |
|
308 |
|
309 template<> |
|
310 void CParameters<TRequestStatus *>::MakeBadParamsL(const RArray<TRequestStatus *>& /* aValidParamsArray */) |
|
311 { |
|
312 // Currently, the only TRequestStatus that we can test for is NULL. |
|
313 // Since TRequestStatus can be any valid memory, it is impossible to |
|
314 // test for "bad" values by any simple measure - the app will panic |
|
315 // if random address is passed along, but there is no easy way to determine |
|
316 // if it's a valid or invalid address. |
|
317 iParams.AppendL(0); |
|
318 } |
|
319 |
|
320 #endif |