3 |
3 |
4 #ifndef ALFMODULETEST_H |
4 #ifndef ALFMODULETEST_H |
5 #define ALFMODULETEST_H |
5 #define ALFMODULETEST_H |
6 |
6 |
7 // Define this to build module testing enchanced version of ALF |
7 // Define this to build module testing enchanced version of ALF |
8 // #define USE_MODULE_TEST_HOOKS_FOR_ALF |
8 //#define USE_MODULE_TEST_HOOKS_FOR_ALF |
9 |
9 |
10 #if !defined(USE_MODULE_TEST_HOOKS_FOR_ALF) || !defined(AMT_CONTROL) |
10 #if !defined(USE_MODULE_TEST_HOOKS_FOR_ALF) || !defined(AMT_CONTROL) |
11 |
11 |
|
12 #define AMT_DATA() |
12 #define AMT_FUNC(func) |
13 #define AMT_FUNC(func) |
13 #define AMT_FUNC_EXC(func) |
14 #define AMT_FUNC_EXC(func) |
14 #define AMT_FUNC_EXC_IF(cond, func) |
15 #define AMT_FUNC_EXC_RET(ret, func) |
|
16 #define AMT_FUNC_EXC_IF(cond, func) |
|
17 #define AMT_FUNC_EXC_IF_RET(cond, ret, func) |
15 #define AMT_INC_COUNTER(member) |
18 #define AMT_INC_COUNTER(member) |
16 #define AMT_DEC_COUNTER(member) |
19 #define AMT_DEC_COUNTER(member) |
17 #define AMT_SET_VALUE(member, val) |
20 #define AMT_SET_VALUE(member, val) |
18 #define AMT_GET_VALUE(x, member) |
21 #define AMT_GET_VALUE(x, member) |
19 #define AMT_INC_COUNTER_IF(cond, member) |
22 #define AMT_INC_COUNTER_IF(cond, member) |
20 #define AMT_DEC_COUNTER_IF(cond, member) |
23 #define AMT_DEC_COUNTER_IF(cond, member) |
21 #define AMT_SET_VALUE_IF(cond, member, val) |
24 #define AMT_SET_VALUE_IF(cond, member, val) |
22 #define AMT_GET_VALUE_IF(cond, x, member) |
25 #define AMT_GET_VALUE_IF(cond, x, member) |
|
26 |
|
27 #define AMT_MAP_APPEND(memberMap, key, type, defaultValue) |
|
28 #define AMT_MAP_SET_VALUE_IF(cond, memberMap, key, value, type) |
|
29 #define AMT_MAP_INC_VALUE_IF(cond, memberMap, key, type) |
|
30 #define AMT_MAP_DEC_VALUE_IF(cond, memberMap, key, type) |
|
31 #define AMT_MAP_SET_VALUE(memberMap, key, value, type) |
|
32 #define AMT_MAP_INC_VALUE(memberMap, key, type) |
|
33 #define AMT_MAP_DEC_VALUE(memberMap, key, type) |
|
34 #define AMT_MAP_RESET(memberMap) |
|
35 |
23 #define AMT_PRINT_STATE() |
36 #define AMT_PRINT_STATE() |
24 |
37 |
25 #ifndef AMT_CONTROL |
38 #ifndef AMT_CONTROL |
26 #error "Error: you need to define AMT_CONTROL macro in your code to be able to use ALF module test system!" |
39 #error "Error: you need to define AMT_CONTROL macro in your code to be able to use ALF module test system!" |
27 // The user have to define AMT_CONTROL, e.g. like this: |
40 // The user have to define AMT_CONTROL, e.g. like this: |
60 #define AMT_INC_COUNTER_IF(cond, member) AMT_FUNC_EXC_IF((cond), AMT_DATA()->member++) |
75 #define AMT_INC_COUNTER_IF(cond, member) AMT_FUNC_EXC_IF((cond), AMT_DATA()->member++) |
61 #define AMT_DEC_COUNTER_IF(cond, member) AMT_FUNC_EXC_IF((cond), AMT_DATA()->member--) |
76 #define AMT_DEC_COUNTER_IF(cond, member) AMT_FUNC_EXC_IF((cond), AMT_DATA()->member--) |
62 #define AMT_SET_VALUE_IF(cond, member, val) AMT_FUNC_EXC_IF((cond), AMT_DATA()->member=(val)) |
77 #define AMT_SET_VALUE_IF(cond, member, val) AMT_FUNC_EXC_IF((cond), AMT_DATA()->member=(val)) |
63 #define AMT_GET_VALUE_IF(cond, x, member) AMT_FUNC_EXC_IF((cond), (x) = AMT_DATA()->member) |
78 #define AMT_GET_VALUE_IF(cond, x, member) AMT_FUNC_EXC_IF((cond), (x) = AMT_DATA()->member) |
64 |
79 |
|
80 // Map operation macros, that will do lock/unlock |
|
81 #define AMT_MAP_APPEND(memberMap, key, type, defaultValue) AMT_FUNC_EXC(AMT_DATA()->memberMap.Append(key, type, defaultValue)) |
|
82 #define AMT_MAP_SET_VALUE_IF(cond, memberMap, key, value, type) AMT_FUNC_EXC_IF((cond), AMT_DATA()->memberMap.SetValue(key, value, type)) |
|
83 #define AMT_MAP_INC_VALUE_IF(cond, memberMap, key, type) AMT_FUNC_EXC_IF((cond && AMT_DATA()->memberMap.Find(key, type)), AMT_DATA()->memberMap.SetValue(key, AMT_DATA()->memberMap.Find(key, type)->Value() + 1, type)) |
|
84 #define AMT_MAP_DEC_VALUE_IF(cond, memberMap, key, type) AMT_FUNC_EXC_IF((cond && AMT_DATA()->memberMap.Find(key, type)), AMT_DATA()->memberMap.SetValue(key, AMT_DATA()->memberMap.Find(key, type)->Value() - 1, type)) |
|
85 #define AMT_MAP_SET_VALUE(memberMap, key, value, type) AMT_FUNC_EXC_IF(ETrue, AMT_DATA()->memberMap.SetValue(key, value, type)) |
|
86 #define AMT_MAP_INC_VALUE(memberMap, key, type) AMT_MAP_INC_VALUE_IF(ETrue, memberMap, key, type) |
|
87 #define AMT_MAP_DEC_VALUE(memberMap, key, type) AMT_MAP_DEC_VALUE_IF(ETrue, memberMap, key, type) |
|
88 #define AMT_MAP_RESET(memberMap) AMT_FUNC_EXC(AMT_DATA()->memberMap.Reset()) |
65 |
89 |
66 // *** Global object names |
90 // *** Global object names |
67 _LIT(KAlfModuleTestChunkName, "ALF_MODULE_TEST_CHUNK"); |
91 _LIT(KAlfModuleTestChunkName, "ALF_MODULE_TEST_CHUNK"); |
68 _LIT(KAlfModuleTestMutexName, "ALF_MODULE_TEST_MUTEX"); |
92 _LIT(KAlfModuleTestMutexName, "ALF_MODULE_TEST_MUTEX"); |
69 |
93 |
|
94 |
|
95 /** |
|
96 * TAlfModuleTestType specifies recognized test types. |
|
97 */ |
|
98 enum TAlfModuleTestType |
|
99 { |
|
100 // Do not use this value when creating item. |
|
101 EAlfModuleTestTypeNone, |
|
102 |
|
103 // Render stage component specific tests |
|
104 EAlfModuleTestTypeRenderStageChangeSize, |
|
105 EAlfModuleTestTypeRenderStageChangePosition, |
|
106 EAlfModuleTestTypeRenderStageChangeFlag, |
|
107 |
|
108 // Streamer hierarchy model component specific tests |
|
109 EAlfModuleTestTypeHierarchyModelChangeSize, |
|
110 EAlfModuleTestTypeHierarchyModelChangePosition, |
|
111 EAlfModuleTestTypeHierarchyModelChangeFlag, |
|
112 |
|
113 // Server bridge component specific tests |
|
114 EAlfModuleTestTypeBridgeChangeSize, |
|
115 EAlfModuleTestTypeBridgeChangePosition, |
|
116 EAlfModuleTestTypeBridgeChangeFlag, |
|
117 |
|
118 // Do not use this value when creating item. |
|
119 // This is just meant for Find operations when all tests are accepted. |
|
120 EAlfModuleTestTypeAll |
|
121 }; |
|
122 |
|
123 |
|
124 /** |
|
125 * CAlfModuleTestItem |
|
126 * |
|
127 * Provides key-value pair that is used in TAlfModuleTestMap. |
|
128 */ |
|
129 template< class T > |
|
130 NONSHARABLE_CLASS( TAlfModuleTestItem ) |
|
131 { |
|
132 |
|
133 public: |
|
134 |
|
135 /** |
|
136 * Constructor to initialize variables. |
|
137 * |
|
138 * @param aKey Key that identifies the item. |
|
139 * In test cases this could be for example handle. |
|
140 * @param aTestType Defines for what this test item is meant for. |
|
141 */ |
|
142 TAlfModuleTestItem( TInt aKey, const TAlfModuleTestType& aTestType, const T& aDefaultValue ): |
|
143 iKey( aKey ), |
|
144 iTestType( aTestType ), |
|
145 iValue( aDefaultValue ), |
|
146 iValueSetCount( 0 ) |
|
147 { |
|
148 } |
|
149 |
|
150 |
|
151 /** |
|
152 * @param aObject Value to be compared. |
|
153 * @return ETrue if given object equals the value of this item. |
|
154 * Else EFalse. |
|
155 */ |
|
156 TBool Equals( const T& aValue, const TAlfModuleTestType& aTestType ) const |
|
157 { |
|
158 // Also, check that value has been set. If it has not been set, |
|
159 // then think objects as unequals. |
|
160 return ( iValueSetCount > 0 |
|
161 && iValue == aValue |
|
162 && TestTypeMatch( aTestType ) ); |
|
163 } |
|
164 |
|
165 |
|
166 /** |
|
167 * @return TInt Key that should be set during creation of this object. |
|
168 */ |
|
169 TInt Key() const |
|
170 { |
|
171 return iKey; |
|
172 } |
|
173 |
|
174 /** |
|
175 * @see ValueSet to check if the value has already been set. |
|
176 * |
|
177 * @return const T& Value that corresonds the key. |
|
178 */ |
|
179 const T& Value() const |
|
180 { |
|
181 return iValue; |
|
182 } |
|
183 |
|
184 |
|
185 /** |
|
186 * @param aValue Value to be set for the key |
|
187 */ |
|
188 void SetValue( const T& aValue ) |
|
189 { |
|
190 iValue = aValue; |
|
191 ++iValueSetCount; |
|
192 } |
|
193 |
|
194 |
|
195 /** |
|
196 * @return TInt Informs how many times the value has been set. |
|
197 */ |
|
198 TInt ValueSetCount() const |
|
199 { |
|
200 return iValueSetCount; |
|
201 } |
|
202 |
|
203 /** |
|
204 * @return const TAlfModuleTestType& Defines what the test is for |
|
205 */ |
|
206 const TAlfModuleTestType& TestType() const |
|
207 { |
|
208 return iTestType; |
|
209 } |
|
210 |
|
211 |
|
212 /** |
|
213 * @param aTestType |
|
214 * @return TBool ETrue if flag matches this item. Else EFalse. |
|
215 */ |
|
216 TBool TestTypeMatch( const TAlfModuleTestType& aTestType ) const |
|
217 { |
|
218 return ( EAlfModuleTestTypeAll == aTestType |
|
219 || iTestType == aTestType ); |
|
220 } |
|
221 |
|
222 |
|
223 /** |
|
224 * Resets the item info |
|
225 */ |
|
226 void Reset() |
|
227 { |
|
228 iValueSetCount = 0; |
|
229 } |
|
230 |
|
231 |
|
232 private: // data |
|
233 |
|
234 TInt iKey; |
|
235 TAlfModuleTestType iTestType; |
|
236 T iValue; |
|
237 TInt iValueSetCount; |
|
238 |
|
239 }; |
|
240 |
|
241 |
|
242 /** |
|
243 * Class CAlfModuleTestMap |
|
244 * |
|
245 * Provides map functionality for the key-value-pairs. |
|
246 * In test cases, this should most likely be used so, that |
|
247 * first test case classes create items with certain keys, for example with handle values. |
|
248 * Then, define hooks are used in the code to update values that corresond the correct handles. |
|
249 * In the end, test case classes can check that items have correct values set and if the test |
|
250 * is passed. |
|
251 */ |
|
252 template< class T > |
|
253 NONSHARABLE_CLASS( TAlfModuleTestMap ) |
|
254 { |
|
255 public: |
|
256 |
|
257 // Maximum item count in the map |
|
258 static const TInt KMaxArrayCount = 50; |
|
259 |
|
260 |
|
261 /** |
|
262 * Constructor to initialize variables. |
|
263 */ |
|
264 TAlfModuleTestMap(): |
|
265 iCount( 0 ), |
|
266 iSetValueCallCount( 0 ) |
|
267 { |
|
268 } |
|
269 |
|
270 |
|
271 /** |
|
272 * @param aKey |
|
273 * @param aTestType Informs what type of test is accepted. Others are skipped. |
|
274 * @return T* Ownership is not transferred. |
|
275 * NULL if item is not found. |
|
276 */ |
|
277 TAlfModuleTestItem< T >* Find( TInt aKey, const TAlfModuleTestType& aTestType ) |
|
278 { |
|
279 // Try to find the item corresponding the given key. |
|
280 for ( TInt i = 0; i < iCount; ++i ) |
|
281 { |
|
282 TAlfModuleTestItem< T >& testItem( iArray[ i ] ); |
|
283 if ( testItem.Key() == aKey |
|
284 && testItem.TestTypeMatch( aTestType ) ) |
|
285 { |
|
286 return &( testItem ); |
|
287 } |
|
288 } |
|
289 // Item corresponding the given key was not found. |
|
290 return NULL; |
|
291 } |
|
292 |
|
293 |
|
294 /** |
|
295 * Function to append new item into the map. |
|
296 * |
|
297 * @param aKey |
|
298 * @param aTestType Describes for what case the appended test item is created for. |
|
299 * @return TInt System wide error code. |
|
300 */ |
|
301 TInt Append( TInt aKey, const TAlfModuleTestType& aTestType, const T& aDefaultValue ) |
|
302 { |
|
303 if ( iCount == KMaxArrayCount ) |
|
304 { |
|
305 // Array already full. |
|
306 return KErrOverflow; |
|
307 } |
|
308 else if ( Find( aKey, aTestType ) ) |
|
309 { |
|
310 // Key has already been inserted. |
|
311 return KErrAlreadyExists; |
|
312 } |
|
313 |
|
314 // Append new key value set into the array. |
|
315 iArray[ iCount ] = TAlfModuleTestItem< T >( aKey, aTestType, aDefaultValue ); |
|
316 ++iCount; |
|
317 return KErrNone; |
|
318 } |
|
319 |
|
320 |
|
321 /** |
|
322 * Sets the value for the item. |
|
323 * Item itself should already exist in the array before |
|
324 * setting its value here. See, Append function. |
|
325 * |
|
326 * @param aKey |
|
327 * @param aValue |
|
328 * @return TInt System wide error code. |
|
329 */ |
|
330 TInt SetValue( TInt aKey, const T& aValue, const TAlfModuleTestType& aTestType ) |
|
331 { |
|
332 // Increase counter, because this function is called. |
|
333 ++iSetValueCallCount; |
|
334 TAlfModuleTestItem< T >* item( Find( aKey, aTestType ) ); |
|
335 if ( !item ) |
|
336 { |
|
337 // Item was not found from the array. |
|
338 return KErrNotFound; |
|
339 } |
|
340 // Item exists. So, set its values. |
|
341 item->SetValue( aValue ); |
|
342 return KErrNone; |
|
343 } |
|
344 |
|
345 |
|
346 /** |
|
347 * Resets the map |
|
348 */ |
|
349 void Reset() |
|
350 { |
|
351 // Just reset the counter. |
|
352 // We do not bother to reset map items, because when counter is reseted |
|
353 // already set items and their info is left out of the scope. |
|
354 iCount = 0; |
|
355 iSetValueCallCount = 0; |
|
356 } |
|
357 |
|
358 |
|
359 /** |
|
360 * Checks if all the values of items in the array match the given value. |
|
361 * |
|
362 * @param aValue Reference to the value that items are compared to. |
|
363 * @param aTestType Informs the test type whose items should be compared. |
|
364 */ |
|
365 TInt CountEquals( const T& aValue, const TAlfModuleTestType& aTestType ) const |
|
366 { |
|
367 TInt count( 0 ); |
|
368 for ( TInt i = 0; i < iCount; ++i ) |
|
369 { |
|
370 if ( iArray[ i ].Equals( aValue, aTestType ) ) |
|
371 { |
|
372 // Item matches |
|
373 ++count; |
|
374 } |
|
375 } |
|
376 return count; |
|
377 } |
|
378 |
|
379 |
|
380 /** |
|
381 * @return TInt Number of map items |
|
382 */ |
|
383 TInt ItemCount() const |
|
384 { |
|
385 return iCount; |
|
386 } |
|
387 |
|
388 |
|
389 /** |
|
390 * @return const TAlfModuleTestItem< T >& Reference to the map item |
|
391 */ |
|
392 const TAlfModuleTestItem< T >& Item( TInt aIndex ) const |
|
393 { |
|
394 return iArray[ aIndex ]; |
|
395 } |
|
396 |
|
397 |
|
398 /** |
|
399 * @return TInt Number of times SetValue function has been called |
|
400 * since last reset. This information can be used |
|
401 * to check if hooks have been used correct times during |
|
402 * a test case. Notice, that this informs the number of |
|
403 * function calls, not the number of times a value has actually |
|
404 * set for some item. |
|
405 */ |
|
406 TInt SetValueCallCount() const |
|
407 { |
|
408 return iSetValueCallCount; |
|
409 } |
|
410 |
|
411 |
|
412 private: // data |
|
413 |
|
414 TAlfModuleTestItem< T > iArray[ KMaxArrayCount ]; |
|
415 // Informs number of array items |
|
416 TInt iCount; |
|
417 // Informs how many times SetItem has been called since last reset. |
|
418 // Notice, that this informs the number of function calls, not the number |
|
419 // of times a value has actually set for some item. |
|
420 TInt iSetValueCallCount; |
|
421 |
|
422 }; |
|
423 |
|
424 |
70 /* |
425 /* |
71 * Class CAlfModuleTestData |
426 * Class CAlfModuleTestData |
72 */ |
427 */ |
73 |
428 |
74 NONSHARABLE_CLASS(CAlfModuleTestData) : public CBase |
429 NONSHARABLE_CLASS(CAlfModuleTestData) : public CBase |
113 RDebug::Print(_L("iVisualPositionChangedCount=%d"), iVisualPositionChangedCount); |
468 RDebug::Print(_L("iVisualPositionChangedCount=%d"), iVisualPositionChangedCount); |
114 RDebug::Print(_L("iLatestVisualExtentRect= x:%d, y:%d, width=%d, height=%d"), |
469 RDebug::Print(_L("iLatestVisualExtentRect= x:%d, y:%d, width=%d, height=%d"), |
115 iLatestVisualExtentRect.iTl.iX, iLatestVisualExtentRect.iTl.iY, |
470 iLatestVisualExtentRect.iTl.iX, iLatestVisualExtentRect.iTl.iY, |
116 iLatestVisualExtentRect.Width(), iLatestVisualExtentRect.Height()); |
471 iLatestVisualExtentRect.Width(), iLatestVisualExtentRect.Height()); |
117 RDebug::Print(_L("iTotalVisualFlagChangedCount=%d"), iTotalVisualFlagChangedCount); |
472 RDebug::Print(_L("iTotalVisualFlagChangedCount=%d"), iTotalVisualFlagChangedCount); |
118 RDebug::Print(_L("iTotalVisualAttributeChangedCount=%d"), iTotalVisualAttributeChangedCount); |
473 RDebug::Print(_L("iTotalVisualAttributeChangedCount=%d"), iTotalVisualAttributeChangedCount); |
|
474 RDebug::Print(_L("iSizeMap =>")); |
|
475 PrintSizeMapState( iSizeMap ); |
|
476 RDebug::Print(_L("iPositionMap =>")); |
|
477 PrintPositionMapState( iPositionMap ); |
119 RDebug::Print(_L("*** ALF INTERNAL STATE ***")); |
478 RDebug::Print(_L("*** ALF INTERNAL STATE ***")); |
120 } |
479 } |
121 |
480 |
|
481 |
|
482 void PrintSizeMapState( TAlfModuleTestMap< TSize > aMap ) |
|
483 { |
|
484 RDebug::Print(_L("*** ALF INTERNAL SIZE MAP STATE -->")); |
|
485 RDebug::Print(_L("Map item count=%d, SetValue call count=%d"), |
|
486 aMap.ItemCount(), aMap.SetValueCallCount()); |
|
487 for ( TInt i = 0; i < aMap.ItemCount(); ++i ) |
|
488 { |
|
489 const TAlfModuleTestItem< TSize >& item( aMap.Item( i ) ); |
|
490 RDebug::Print(_L("Map item %d, iKey=%d, iTestType=%d, iValueSetCount=%d"), |
|
491 i, item.Key(), item.TestType(), item.ValueSetCount()); |
|
492 RDebug::Print(_L("Map item index=%d, width=%d, height=%d"), |
|
493 i, item.Value().iWidth, item.Value().iHeight); |
|
494 } |
|
495 RDebug::Print(_L("<-- ALF INTERNAL SIZE MAP STATE ***")); |
|
496 } |
|
497 |
|
498 |
|
499 void PrintPositionMapState( TAlfModuleTestMap< TPoint > aMap ) |
|
500 { |
|
501 RDebug::Print(_L("*** ALF INTERNAL POSITION MAP STATE -->")); |
|
502 RDebug::Print(_L("Map item count=%d, SetValue call count=%d"), |
|
503 aMap.ItemCount(), aMap.SetValueCallCount()); |
|
504 for ( TInt i = 0; i < aMap.ItemCount(); ++i ) |
|
505 { |
|
506 const TAlfModuleTestItem< TPoint >& item( aMap.Item( i ) ); |
|
507 RDebug::Print(_L("Map item %d, iKey=%d, iTestType=%d, iValueSetCount=%d"), |
|
508 i, item.Key(), item.TestType(), item.ValueSetCount()); |
|
509 RDebug::Print(_L("Map item index=%d, x=%d, y=%d"), |
|
510 i, item.Value().iX, item.Value().iY); |
|
511 } |
|
512 RDebug::Print(_L("<-- ALF INTERNAL POSITION MAP STATE ***")); |
|
513 } |
|
514 |
122 |
515 |
123 public: |
516 public: |
124 TBool iIsEnabled; // *** not yet implemented. For run-time enabling/disabling of the test system. |
517 TBool iIsEnabled; // *** not yet implemented. For run-time enabling/disabling of the test system. |
125 |
518 |
126 // Alf Render Stage |
519 // Alf Render Stage |