|
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: This file contains the header file of the STIF |
|
15 * normal and hardcoded modules assert macros. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef NormalHardcodedAssert_MACROS_H |
|
21 #define NormalHardcodedAssert_MACROS_H |
|
22 |
|
23 _LIT( KAssertFailedEquals, "AssertEquals Failed [F:%s][L:%d]" ); |
|
24 _LIT( KAssertFailedNotEquals, "AssertNotEquals Failed [F:%s][L:%d]" ); |
|
25 _LIT( KAssertFailedNull, "AssertNull Failed [F:%s][L:%d]" ); |
|
26 _LIT( KAssertFailedNotNull, "AssertNotNull Failed [F:%s][L:%d]" ); |
|
27 _LIT( KAssertFailedSame, "AssertSame Failed [F:%s][L:%d]" ); |
|
28 _LIT( KAssertFailedNotSame, "AssertNotSame Failed [F:%s][L:%d]" ); |
|
29 _LIT( KAssertFailedTrue, "AssertTrue Failed [F:%s][L:%d]" ); |
|
30 _LIT( KAssertFailedFalse, "AssertFalse Failed [F:%s][L:%d]" ); |
|
31 _LIT( KAssertFailedNotLeaves, "AssertNotLeaves Failed [F:%s][L:%d]" ); |
|
32 _LIT( KAssertFailedLeaves, "AssertLeaves Failed [F:%s][L:%d]" ); |
|
33 _LIT( KAssertFailedLeavesWith, "AssertLeavesWith Failed [F:%s][L:%d]" ); |
|
34 |
|
35 |
|
36 #ifdef _UNICODE |
|
37 #define __STIF_WIDEN2(x) L ## x |
|
38 #define __STIF_WIDEN(x) __STIF_WIDEN2(x) |
|
39 #define __STIF_DBG_FILE__ __STIF_WIDEN(__FILE__) |
|
40 #else |
|
41 #define __STIF_DBG_FILE__ __FILE__ |
|
42 #endif |
|
43 |
|
44 #ifdef _UNICODE |
|
45 #define __STF_WIDEN2(x) L ## x |
|
46 #define __STF_WIDEN(x) __STF_WIDEN2(x) |
|
47 #define __STF_DBG_FILE__ __STF_WIDEN(__FILE__) |
|
48 #else |
|
49 #define __STF_DBG_FILE__ __FILE__ |
|
50 #endif |
|
51 |
|
52 // Logs to the STIF log file AND to the RDebug |
|
53 #define STIF_LOG( aMessage ) \ |
|
54 iLog->Log( _L( aMessage ) ); RDebug::Print( _L( aMessage ) ); |
|
55 |
|
56 // Logs to the STF log file AND to the RDebug |
|
57 #define STF_LOG( aMessage ) \ |
|
58 iLog->Log( _L( aMessage ) ); RDebug::Print( _L( aMessage ) ); |
|
59 |
|
60 /********************************************************************************* |
|
61 * STF Assert Macros |
|
62 *********************************************************************************/ |
|
63 #define __STF_ASSERT_SHARED( aFunction, aMessage ) \ |
|
64 if(!aFunction) \ |
|
65 { \ |
|
66 iLog->Log( aMessage, __STF_DBG_FILE__, __LINE__ );\ |
|
67 aResult.SetResult( KErrGeneral, _L("Testcase failed"));\ |
|
68 return KErrNone;\ |
|
69 } |
|
70 |
|
71 #define __STF_ASSERT_SHARED_DESC( aFunction, aMessage, aDesc ) \ |
|
72 if(!aFunction) \ |
|
73 { \ |
|
74 iLog->Log( aMessage, __STF_DBG_FILE__, __LINE__ );\ |
|
75 aResult.SetResult( KErrGeneral, aDesc );\ |
|
76 return KErrNone;\ |
|
77 } \ |
|
78 else \ |
|
79 { \ |
|
80 aResult.SetResult( KErrNone, aDesc ); \ |
|
81 } |
|
82 |
|
83 |
|
84 |
|
85 #define STF_ASSERT_EQUALS( aExpected, aActual ) \ |
|
86 __STF_ASSERT_SHARED( AssertEquals( aExpected, aActual ) , KAssertFailedEquals ); |
|
87 |
|
88 #define STF_ASSERT_EQUALS_DESC( aExpected, aActual, aDescription ) \ |
|
89 __STF_ASSERT_SHARED_DESC( AssertEquals( aExpected, aActual ) , KAssertFailedEquals, aDescription ); |
|
90 |
|
91 #define STF_ASSERT_NOT_EQUALS( aExpected, aActual ) \ |
|
92 __STF_ASSERT_SHARED( !AssertEquals( aExpected, aActual ) , KAssertFailedNotEquals ); |
|
93 |
|
94 #define STF_ASSERT_NOT_EQUALS_DESC( aExpected, aActual, aDescription ) \ |
|
95 __STF_ASSERT_SHARED_DESC( !AssertEquals( aExpected, aActual ) , KAssertFailedNotEquals, aDescription ); |
|
96 |
|
97 #define STF_ASSERT_NULL( aPtr ) \ |
|
98 __STF_ASSERT_SHARED( AssertNull( aPtr ), KAssertFailedNull ); |
|
99 |
|
100 #define STF_ASSERT_NULL_DESC( aPtr, aDescription ) \ |
|
101 __STF_ASSERT_SHARED_DESC( AssertNull( aPtr ), KAssertFailedNull, aDescription ); |
|
102 |
|
103 #define STF_ASSERT_NOT_NULL( aPtr ) \ |
|
104 __STF_ASSERT_SHARED( !AssertNull( aPtr ), KAssertFailedNotNull ); |
|
105 |
|
106 #define STF_ASSERT_NOT_NULL_DESC( aPtr, aDescription ) \ |
|
107 __STF_ASSERT_SHARED_DESC( !AssertNull( aPtr ), KAssertFailedNotNull, aDescription ); |
|
108 |
|
109 #define STF_ASSERT_SAME( aExpectedPtr, aActualPtr ) \ |
|
110 __STF_ASSERT_SHARED( AssertSame( aExpectedPtr, aActualPtr ), KAssertFailedSame ); |
|
111 |
|
112 #define STF_ASSERT_SAME_DESC( aExpectedPtr, aActualPtr, aDescription ) \ |
|
113 __STF_ASSERT_SHARED_DESC( AssertSame( aExpectedPtr, aActualPtr ), KAssertFailedSame, aDescription ); |
|
114 |
|
115 #define STF_ASSERT_NOT_SAME( aExpectedPtr, aActualPtr) \ |
|
116 __STF_ASSERT_SHARED( !AssertSame( aExpectedPtr, aActualPtr ), KAssertFailedNotSame ); |
|
117 |
|
118 #define STF_ASSERT_NOT_SAME_DESC( aExpectedPtr, aActualPtr, aDescription ) \ |
|
119 __STF_ASSERT_SHARED_DESC( !AssertSame( aExpectedPtr, aActualPtr ), KAssertFailedNotSame, aDescription ); |
|
120 |
|
121 #define STF_ASSERT_TRUE( aCondition ) \ |
|
122 __STF_ASSERT_SHARED( AssertTrue( aCondition ), KAssertFailedTrue ); |
|
123 |
|
124 #define STF_ASSERT_TRUE_DESC( aCondition, aDescription ) \ |
|
125 __STF_ASSERT_SHARED_DESC( AssertTrue( aCondition ), KAssertFailedTrue, aDescription ); |
|
126 |
|
127 #define STF_ASSERT_FALSE( aCondition ) \ |
|
128 __STF_ASSERT_SHARED( !AssertTrue( aCondition ), KAssertFailedFalse ); |
|
129 |
|
130 #define STF_ASSERT_FALSE_DESC( aCondition, aDescription ) \ |
|
131 __STF_ASSERT_SHARED_DESC( !AssertTrue( aCondition), KAssertFailedFalse, aDescription ); |
|
132 |
|
133 // Eclosing block is used to create the scope for the __leaveValue |
|
134 #define STF_ASSERT_NOT_LEAVES( aStatement ) \ |
|
135 { \ |
|
136 TRAPD( __leaveValue, aStatement ); \ |
|
137 __STF_ASSERT_SHARED( AssertEquals( __leaveValue, KErrNone ), KAssertFailedNotLeaves ); \ |
|
138 } |
|
139 |
|
140 #define STF_ASSERT_NOT_LEAVES_DESC( aStatement, aDescription ) \ |
|
141 { \ |
|
142 TRAPD( __leaveValue, aStatement ); \ |
|
143 __STF_ASSERT_SHARED_DESC( AssertEquals( __leaveValue, KErrNone ), KAssertFailedNotLeaves, aDescription ); \ |
|
144 } |
|
145 |
|
146 // Eclosing block is used to create the scope for the __leaveValue |
|
147 #define STF_ASSERT_LEAVES( aStatement ) \ |
|
148 { \ |
|
149 TRAPD( __leaveValue, aStatement ); \ |
|
150 __STF_ASSERT_SHARED( !AssertEquals( __leaveValue, KErrNone ), KAssertFailedLeaves ); \ |
|
151 } |
|
152 |
|
153 #define STF_ASSERT_LEAVES_DESC( aStatement, aDescription ) \ |
|
154 { \ |
|
155 TRAPD( __leaveValue, aStatement ); \ |
|
156 __STF_ASSERT_SHARED_DESC( !AssertEquals( __leaveValue, KErrNone ), KAssertFailedLeaves, aDescription ); \ |
|
157 } |
|
158 |
|
159 // Eclosing block is used to create the scope for the __leaveValue |
|
160 #define STF_ASSERT_LEAVES_WITH( aLeaveCode, aStatement ) \ |
|
161 { \ |
|
162 TRAPD( __leaveValue, aStatement ); \ |
|
163 __STF_ASSERT_SHARED( AssertEquals( __leaveValue, aLeaveCode ), KAssertFailedLeaves ); \ |
|
164 } |
|
165 |
|
166 #define STF_ASSERT_LEAVES_WITH_DESC( aLeaveCode, aStatement, aDescription ) \ |
|
167 { \ |
|
168 TRAPD( __leaveValue, aStatement ); \ |
|
169 __STF_ASSERT_SHARED_DESC( AssertEquals( __leaveValue, aLeaveCode ), KAssertFailedLeaves, aDescription ); \ |
|
170 } |
|
171 |
|
172 #define STF_ASSERT_PANIC( aPanicCode, aStatement ) \ |
|
173 { \ |
|
174 TestModuleIf().SetExitReason( CTestModuleIf::EPanic, aPanicCode ); \ |
|
175 aStatement; \ |
|
176 } |
|
177 |
|
178 #define STF_ASSERT_PANIC_DESC( aPanicCode, aStatement, aDescription ) \ |
|
179 { \ |
|
180 TestModuleIf().SetExitReason( CTestModuleIf::EPanic, aPanicCode ); \ |
|
181 aResult.SetResult(KErrNone, aDescription); \ |
|
182 aStatement; \ |
|
183 } |
|
184 |
|
185 |
|
186 /********************************************************************************* |
|
187 * STIF Assert Macros |
|
188 *********************************************************************************/ |
|
189 #define __STIF_ASSERT_SHARED( aFunction, aMessage ) \ |
|
190 if(!aFunction) \ |
|
191 { \ |
|
192 iLog->Log( aMessage, __STIF_DBG_FILE__, __LINE__ );\ |
|
193 aResult.SetResult( KErrGeneral, _L("Testcase failed"));\ |
|
194 return KErrNone;\ |
|
195 } |
|
196 |
|
197 #define __STIF_ASSERT_SHARED_DESC( aFunction, aMessage, aDesc ) \ |
|
198 if(!aFunction) \ |
|
199 { \ |
|
200 iLog->Log( aMessage, __STIF_DBG_FILE__, __LINE__ );\ |
|
201 aResult.SetResult( KErrGeneral, aDesc );\ |
|
202 return KErrNone;\ |
|
203 } \ |
|
204 else \ |
|
205 { \ |
|
206 aResult.SetResult( KErrNone, aDesc ); \ |
|
207 } |
|
208 |
|
209 |
|
210 |
|
211 #define STIF_ASSERT_EQUALS( aExpected, aActual ) \ |
|
212 __STIF_ASSERT_SHARED( AssertEquals( aExpected, aActual ) , KAssertFailedEquals ); |
|
213 |
|
214 #define STIF_ASSERT_EQUALS_DESC( aExpected, aActual, aDescription ) \ |
|
215 __STIF_ASSERT_SHARED_DESC( AssertEquals( aExpected, aActual ) , KAssertFailedEquals, aDescription ); |
|
216 |
|
217 #define STIF_ASSERT_NOT_EQUALS( aExpected, aActual ) \ |
|
218 __STIF_ASSERT_SHARED( !AssertEquals( aExpected, aActual ) , KAssertFailedNotEquals ); |
|
219 |
|
220 #define STIF_ASSERT_NOT_EQUALS_DESC( aExpected, aActual, aDescription ) \ |
|
221 __STIF_ASSERT_SHARED_DESC( !AssertEquals( aExpected, aActual ) , KAssertFailedNotEquals, aDescription ); |
|
222 |
|
223 #define STIF_ASSERT_NULL( aPtr ) \ |
|
224 __STIF_ASSERT_SHARED( AssertNull( aPtr ), KAssertFailedNull ); |
|
225 |
|
226 #define STIF_ASSERT_NULL_DESC( aPtr, aDescription ) \ |
|
227 __STIF_ASSERT_SHARED_DESC( AssertNull( aPtr ), KAssertFailedNull, aDescription ); |
|
228 |
|
229 #define STIF_ASSERT_NOT_NULL( aPtr ) \ |
|
230 __STIF_ASSERT_SHARED( !AssertNull( aPtr ), KAssertFailedNotNull ); |
|
231 |
|
232 #define STIF_ASSERT_NOT_NULL_DESC( aPtr, aDescription ) \ |
|
233 __STIF_ASSERT_SHARED_DESC( !AssertNull( aPtr ), KAssertFailedNotNull, aDescription ); |
|
234 |
|
235 #define STIF_ASSERT_SAME( aExpectedPtr, aActualPtr ) \ |
|
236 __STIF_ASSERT_SHARED( AssertSame( aExpectedPtr, aActualPtr ), KAssertFailedSame ); |
|
237 |
|
238 #define STIF_ASSERT_SAME_DESC( aExpectedPtr, aActualPtr, aDescription ) \ |
|
239 __STIF_ASSERT_SHARED_DESC( AssertSame( aExpectedPtr, aActualPtr ), KAssertFailedSame, aDescription ); |
|
240 |
|
241 #define STIF_ASSERT_NOT_SAME( aExpectedPtr, aActualPtr) \ |
|
242 __STIF_ASSERT_SHARED( !AssertSame( aExpectedPtr, aActualPtr ), KAssertFailedNotSame ); |
|
243 |
|
244 #define STIF_ASSERT_NOT_SAME_DESC( aExpectedPtr, aActualPtr, aDescription ) \ |
|
245 __STIF_ASSERT_SHARED_DESC( !AssertSame( aExpectedPtr, aActualPtr ), KAssertFailedNotSame, aDescription ); |
|
246 |
|
247 #define STIF_ASSERT_TRUE( aCondition ) \ |
|
248 __STIF_ASSERT_SHARED( AssertTrue( aCondition ), KAssertFailedTrue ); |
|
249 |
|
250 #define STIF_ASSERT_TRUE_DESC( aCondition, aDescription ) \ |
|
251 __STIF_ASSERT_SHARED_DESC( AssertTrue( aCondition ), KAssertFailedTrue, aDescription ); |
|
252 |
|
253 #define STIF_ASSERT_FALSE( aCondition ) \ |
|
254 __STIF_ASSERT_SHARED( !AssertTrue( aCondition ), KAssertFailedFalse ); |
|
255 |
|
256 #define STIF_ASSERT_FALSE_DESC( aCondition, aDescription ) \ |
|
257 __STIF_ASSERT_SHARED_DESC( !AssertTrue( aCondition), KAssertFailedFalse, aDescription ); |
|
258 |
|
259 // Eclosing block is used to create the scope for the __leaveValue |
|
260 #define STIF_ASSERT_NOT_LEAVES( aStatement ) \ |
|
261 { \ |
|
262 TRAPD( __leaveValue, aStatement ); \ |
|
263 __STIF_ASSERT_SHARED( AssertEquals( __leaveValue, KErrNone ), KAssertFailedNotLeaves ); \ |
|
264 } |
|
265 |
|
266 #define STIF_ASSERT_NOT_LEAVES_DESC( aStatement, aDescription ) \ |
|
267 { \ |
|
268 TRAPD( __leaveValue, aStatement ); \ |
|
269 __STIF_ASSERT_SHARED_DESC( AssertEquals( __leaveValue, KErrNone ), KAssertFailedNotLeaves, aDescription ); \ |
|
270 } |
|
271 |
|
272 // Eclosing block is used to create the scope for the __leaveValue |
|
273 #define STIF_ASSERT_LEAVES( aStatement ) \ |
|
274 { \ |
|
275 TRAPD( __leaveValue, aStatement ); \ |
|
276 __STIF_ASSERT_SHARED( !AssertEquals( __leaveValue, KErrNone ), KAssertFailedLeaves ); \ |
|
277 } |
|
278 |
|
279 #define STIF_ASSERT_LEAVES_DESC( aStatement, aDescription ) \ |
|
280 { \ |
|
281 TRAPD( __leaveValue, aStatement ); \ |
|
282 __STIF_ASSERT_SHARED_DESC( !AssertEquals( __leaveValue, KErrNone ), KAssertFailedLeaves, aDescription ); \ |
|
283 } |
|
284 |
|
285 // Eclosing block is used to create the scope for the __leaveValue |
|
286 #define STIF_ASSERT_LEAVES_WITH( aLeaveCode, aStatement ) \ |
|
287 { \ |
|
288 TRAPD( __leaveValue, aStatement ); \ |
|
289 __STIF_ASSERT_SHARED( AssertEquals( __leaveValue, aLeaveCode ), KAssertFailedLeaves ); \ |
|
290 } |
|
291 |
|
292 #define STIF_ASSERT_LEAVES_WITH_DESC( aLeaveCode, aStatement, aDescription ) \ |
|
293 { \ |
|
294 TRAPD( __leaveValue, aStatement ); \ |
|
295 __STIF_ASSERT_SHARED_DESC( AssertEquals( __leaveValue, aLeaveCode ), KAssertFailedLeaves, aDescription ); \ |
|
296 } |
|
297 |
|
298 #define STIF_ASSERT_PANIC( aPanicCode, aStatement ) \ |
|
299 { \ |
|
300 TestModuleIf().SetExitReason( CTestModuleIf::EPanic, aPanicCode ); \ |
|
301 aStatement; \ |
|
302 } |
|
303 |
|
304 #define STIF_ASSERT_PANIC_DESC( aPanicCode, aStatement, aDescription ) \ |
|
305 { \ |
|
306 TestModuleIf().SetExitReason( CTestModuleIf::EPanic, aPanicCode ); \ |
|
307 aResult.SetResult(KErrNone, aDescription); \ |
|
308 aStatement; \ |
|
309 } |
|
310 |
|
311 template <class T> |
|
312 inline TBool AssertEquals(const T& aExpected, const T& aActual) |
|
313 /** |
|
314 * AssertEquals |
|
315 * |
|
316 * |
|
317 * @param aExpected - Expected result |
|
318 * @param aActual - Actual result |
|
319 * @return - True if equal |
|
320 */ |
|
321 { |
|
322 if( aExpected==aActual ) |
|
323 { |
|
324 return ETrue; |
|
325 } |
|
326 return EFalse; |
|
327 } |
|
328 |
|
329 template <class T> |
|
330 inline TBool AssertNull(const T* aPtr) |
|
331 /** |
|
332 * AssertNull |
|
333 * |
|
334 * |
|
335 * @param aPtr - Pointer |
|
336 * @return - True if NULL |
|
337 */ |
|
338 { |
|
339 if( aPtr==NULL ) |
|
340 { |
|
341 return ETrue; |
|
342 } |
|
343 return EFalse; |
|
344 } |
|
345 |
|
346 template <class T> |
|
347 inline TBool AssertSame(const T* aExpectedPtr, const T* aActualPtr) |
|
348 /** |
|
349 * AssertSame |
|
350 * |
|
351 * |
|
352 * @param aExpectedPtr - Expected pointer |
|
353 * @param aActualPtr - Actual pointer |
|
354 * @return - True if equal |
|
355 */ |
|
356 { |
|
357 if( aExpectedPtr==aActualPtr ) |
|
358 { |
|
359 return ETrue; |
|
360 } |
|
361 return EFalse; |
|
362 } |
|
363 |
|
364 inline TBool AssertTrue(const TBool& aCondition) |
|
365 /** |
|
366 * AssertTrue |
|
367 * |
|
368 * |
|
369 * @param aCondition - Condition |
|
370 * @return - True if aCondition is true |
|
371 */ |
|
372 { |
|
373 if( !aCondition ) |
|
374 { |
|
375 return EFalse; |
|
376 } |
|
377 return ETrue; |
|
378 } |
|
379 |
|
380 #endif |