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 |
|
45 // Logs to the STIF log file AND to the RDebug |
|
46 #define STIF_LOG( aMessage ) \ |
|
47 iLog->Log( _L( aMessage ) ); RDebug::Print( _L( aMessage ) ); |
|
48 |
|
49 |
|
50 /********************************************************************************* |
|
51 * Assert Macros |
|
52 *********************************************************************************/ |
|
53 #define __STIF_ASSERT_SHARED( aFunction, aMessage ) \ |
|
54 if(!aFunction) \ |
|
55 { \ |
|
56 iLog->Log( aMessage, __STIF_DBG_FILE__, __LINE__ );\ |
|
57 aResult.SetResult( KErrGeneral, _L("Testcase failed"));\ |
|
58 return KErrNone;\ |
|
59 } |
|
60 |
|
61 #define __STIF_ASSERT_SHARED_DESC( aFunction, aMessage, aDesc ) \ |
|
62 if(!aFunction) \ |
|
63 { \ |
|
64 iLog->Log( aMessage, __STIF_DBG_FILE__, __LINE__ );\ |
|
65 aResult.SetResult( KErrGeneral, aDesc );\ |
|
66 return KErrNone;\ |
|
67 } \ |
|
68 else \ |
|
69 { \ |
|
70 aResult.SetResult( KErrNone, aDesc ); \ |
|
71 } |
|
72 |
|
73 |
|
74 |
|
75 #define STIF_ASSERT_EQUALS( aExpected, aActual ) \ |
|
76 __STIF_ASSERT_SHARED( AssertEquals( aExpected, aActual ) , KAssertFailedEquals ); |
|
77 |
|
78 #define STIF_ASSERT_EQUALS_DESC( aExpected, aActual, aDescription ) \ |
|
79 __STIF_ASSERT_SHARED_DESC( AssertEquals( aExpected, aActual ) , KAssertFailedEquals, aDescription ); |
|
80 |
|
81 #define STIF_ASSERT_NOT_EQUALS( aExpected, aActual ) \ |
|
82 __STIF_ASSERT_SHARED( !AssertEquals( aExpected, aActual ) , KAssertFailedNotEquals ); |
|
83 |
|
84 #define STIF_ASSERT_NOT_EQUALS_DESC( aExpected, aActual, aDescription ) \ |
|
85 __STIF_ASSERT_SHARED_DESC( !AssertEquals( aExpected, aActual ) , KAssertFailedNotEquals, aDescription ); |
|
86 |
|
87 #define STIF_ASSERT_NULL( aPtr ) \ |
|
88 __STIF_ASSERT_SHARED( AssertNull( aPtr ), KAssertFailedNull ); |
|
89 |
|
90 #define STIF_ASSERT_NULL_DESC( aPtr, aDescription ) \ |
|
91 __STIF_ASSERT_SHARED_DESC( AssertNull( aPtr ), KAssertFailedNull, aDescription ); |
|
92 |
|
93 #define STIF_ASSERT_NOT_NULL( aPtr ) \ |
|
94 __STIF_ASSERT_SHARED( !AssertNull( aPtr ), KAssertFailedNotNull ); |
|
95 |
|
96 #define STIF_ASSERT_NOT_NULL_DESC( aPtr, aDescription ) \ |
|
97 __STIF_ASSERT_SHARED_DESC( !AssertNull( aPtr ), KAssertFailedNotNull, aDescription ); |
|
98 |
|
99 #define STIF_ASSERT_SAME( aExpectedPtr, aActualPtr ) \ |
|
100 __STIF_ASSERT_SHARED( AssertSame( aExpectedPtr, aActualPtr ), KAssertFailedSame ); |
|
101 |
|
102 #define STIF_ASSERT_SAME_DESC( aExpectedPtr, aActualPtr, aDescription ) \ |
|
103 __STIF_ASSERT_SHARED_DESC( AssertSame( aExpectedPtr, aActualPtr ), KAssertFailedSame, aDescription ); |
|
104 |
|
105 #define STIF_ASSERT_NOT_SAME( aExpectedPtr, aActualPtr) \ |
|
106 __STIF_ASSERT_SHARED( !AssertSame( aExpectedPtr, aActualPtr ), KAssertFailedNotSame ); |
|
107 |
|
108 #define STIF_ASSERT_NOT_SAME_DESC( aExpectedPtr, aActualPtr, aDescription ) \ |
|
109 __STIF_ASSERT_SHARED_DESC( !AssertSame( aExpectedPtr, aActualPtr ), KAssertFailedNotSame, aDescription ); |
|
110 |
|
111 #define STIF_ASSERT_TRUE( aCondition ) \ |
|
112 __STIF_ASSERT_SHARED( AssertTrue( aCondition ), KAssertFailedTrue ); |
|
113 |
|
114 #define STIF_ASSERT_TRUE_DESC( aCondition, aDescription ) \ |
|
115 __STIF_ASSERT_SHARED_DESC( AssertTrue( aCondition ), KAssertFailedTrue, aDescription ); |
|
116 |
|
117 #define STIF_ASSERT_FALSE( aCondition ) \ |
|
118 __STIF_ASSERT_SHARED( !AssertTrue( aCondition ), KAssertFailedFalse ); |
|
119 |
|
120 #define STIF_ASSERT_FALSE_DESC( aCondition, aDescription ) \ |
|
121 __STIF_ASSERT_SHARED_DESC( !AssertTrue( aCondition), KAssertFailedFalse, aDescription ); |
|
122 |
|
123 // Eclosing block is used to create the scope for the __leaveValue |
|
124 #define STIF_ASSERT_NOT_LEAVES( aStatement ) \ |
|
125 { \ |
|
126 TRAPD( __leaveValue, aStatement ); \ |
|
127 __STIF_ASSERT_SHARED( AssertEquals( __leaveValue, KErrNone ), KAssertFailedNotLeaves ); \ |
|
128 } |
|
129 |
|
130 #define STIF_ASSERT_NOT_LEAVES_DESC( aStatement, aDescription ) \ |
|
131 { \ |
|
132 TRAPD( __leaveValue, aStatement ); \ |
|
133 __STIF_ASSERT_SHARED_DESC( AssertEquals( __leaveValue, KErrNone ), KAssertFailedNotLeaves, aDescription ); \ |
|
134 } |
|
135 |
|
136 // Eclosing block is used to create the scope for the __leaveValue |
|
137 #define STIF_ASSERT_LEAVES( aStatement ) \ |
|
138 { \ |
|
139 TRAPD( __leaveValue, aStatement ); \ |
|
140 __STIF_ASSERT_SHARED( !AssertEquals( __leaveValue, KErrNone ), KAssertFailedLeaves ); \ |
|
141 } |
|
142 |
|
143 #define STIF_ASSERT_LEAVES_DESC( aStatement, aDescription ) \ |
|
144 { \ |
|
145 TRAPD( __leaveValue, aStatement ); \ |
|
146 __STIF_ASSERT_SHARED_DESC( !AssertEquals( __leaveValue, KErrNone ), KAssertFailedLeaves, aDescription ); \ |
|
147 } |
|
148 |
|
149 // Eclosing block is used to create the scope for the __leaveValue |
|
150 #define STIF_ASSERT_LEAVES_WITH( aLeaveCode, aStatement ) \ |
|
151 { \ |
|
152 TRAPD( __leaveValue, aStatement ); \ |
|
153 __STIF_ASSERT_SHARED( AssertEquals( __leaveValue, aLeaveCode ), KAssertFailedLeaves ); \ |
|
154 } |
|
155 |
|
156 #define STIF_ASSERT_LEAVES_WITH_DESC( aLeaveCode, aStatement, aDescription ) \ |
|
157 { \ |
|
158 TRAPD( __leaveValue, aStatement ); \ |
|
159 __STIF_ASSERT_SHARED_DESC( AssertEquals( __leaveValue, aLeaveCode ), KAssertFailedLeaves, aDescription ); \ |
|
160 } |
|
161 |
|
162 #define STIF_ASSERT_PANIC( aPanicCode, aStatement ) \ |
|
163 { \ |
|
164 TestModuleIf().SetExitReason( CTestModuleIf::EPanic, aPanicCode ); \ |
|
165 aStatement; \ |
|
166 } |
|
167 |
|
168 #define STIF_ASSERT_PANIC_DESC( aPanicCode, aStatement, aDescription ) \ |
|
169 { \ |
|
170 TestModuleIf().SetExitReason( CTestModuleIf::EPanic, aPanicCode ); \ |
|
171 aResult.SetResult(KErrNone, aDescription); \ |
|
172 aStatement; \ |
|
173 } |
|
174 |
|
175 template <class T> |
|
176 inline TBool AssertEquals(const T& aExpected, const T& aActual) |
|
177 /** |
|
178 * AssertEquals |
|
179 * |
|
180 * |
|
181 * @param aExpected - Expected result |
|
182 * @param aActual - Actual result |
|
183 * @return - True if equal |
|
184 */ |
|
185 { |
|
186 if( aExpected==aActual ) |
|
187 { |
|
188 return ETrue; |
|
189 } |
|
190 return EFalse; |
|
191 } |
|
192 |
|
193 template <class T> |
|
194 inline TBool AssertNull(const T* aPtr) |
|
195 /** |
|
196 * AssertNull |
|
197 * |
|
198 * |
|
199 * @param aPtr - Pointer |
|
200 * @return - True if NULL |
|
201 */ |
|
202 { |
|
203 if( aPtr==NULL ) |
|
204 { |
|
205 return ETrue; |
|
206 } |
|
207 return EFalse; |
|
208 } |
|
209 |
|
210 template <class T> |
|
211 inline TBool AssertSame(const T* aExpectedPtr, const T* aActualPtr) |
|
212 /** |
|
213 * AssertSame |
|
214 * |
|
215 * |
|
216 * @param aExpectedPtr - Expected pointer |
|
217 * @param aActualPtr - Actual pointer |
|
218 * @return - True if equal |
|
219 */ |
|
220 { |
|
221 if( aExpectedPtr==aActualPtr ) |
|
222 { |
|
223 return ETrue; |
|
224 } |
|
225 return EFalse; |
|
226 } |
|
227 |
|
228 inline TBool AssertTrue(const TBool& aCondition) |
|
229 /** |
|
230 * AssertTrue |
|
231 * |
|
232 * |
|
233 * @param aCondition - Condition |
|
234 * @return - True if aCondition is true |
|
235 */ |
|
236 { |
|
237 if( !aCondition ) |
|
238 { |
|
239 return EFalse; |
|
240 } |
|
241 return ETrue; |
|
242 } |
|
243 |
|
244 #endif |
|
245 |
|
246 // End of File |
|