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