|
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: STIFUnit macros declarations |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef STIFUnit_MACROS_H |
|
19 #define STIFUnit_MACROS_H |
|
20 |
|
21 // Enumeration types |
|
22 // Reason for running test method |
|
23 enum TCallReason |
|
24 { |
|
25 EEnumerateTestCases, |
|
26 ERunTestCase, |
|
27 ECountTestCases, //Used to count test cases. |
|
28 //This should be already done by enumerating procedure, |
|
29 //however in case of test crash all internal data are |
|
30 //being lost. |
|
31 }; |
|
32 |
|
33 |
|
34 // Strings |
|
35 _LIT( KAssertFailedEquals, "AssertEquals Failed [F:%s][L:%d]" ); |
|
36 _LIT( KAssertFailedNotEquals, "AssertNotEquals Failed [F:%s][L:%d]" ); |
|
37 _LIT( KAssertFailedNull, "AssertNull Failed [F:%s][L:%d]" ); |
|
38 _LIT( KAssertFailedNotNull, "AssertNotNull Failed [F:%s][L:%d]" ); |
|
39 _LIT( KAssertFailedSame, "AssertSame Failed [F:%s][L:%d]" ); |
|
40 _LIT( KAssertFailedNotSame, "AssertNotSame Failed [F:%s][L:%d]" ); |
|
41 _LIT( KAssertFailedTrue, "AssertTrue Failed [F:%s][L:%d]" ); |
|
42 _LIT( KAssertFailedFalse, "AssertFalse Failed [F:%s][L:%d]" ); |
|
43 _LIT( KAssertFailedNotLeaves, "AssertNotLeaves Failed [F:%s][L:%d]" ); |
|
44 _LIT( KAssertFailedLeaves, "AssertLeaves Failed [F:%s][L:%d]" ); |
|
45 _LIT( KAssertFailedLeavesWith, "AssertLeavesWith Failed [F:%s][L:%d]" ); |
|
46 |
|
47 |
|
48 #ifdef _UNICODE |
|
49 #define __STIF_WIDEN2(x) L ## x |
|
50 #define __STIF_WIDEN(x) __STIF_WIDEN2(x) |
|
51 #define __STIF_DBG_FILE__ __STIF_WIDEN(__FILE__) |
|
52 #else |
|
53 #define __STIF_DBG_FILE__ __FILE__ |
|
54 #endif |
|
55 |
|
56 |
|
57 // Logs to the STIF log file AND to the RDebug |
|
58 #define STIF_LOG( aMessage ) \ |
|
59 iLog->Log( _L( aMessage ) ); RDebug::Print( _L( aMessage ) ); |
|
60 |
|
61 |
|
62 // Defines a separate test case which consists of two blocks - one for enumeration of test cases |
|
63 // second for running the testcase. |
|
64 #define STIF_TESTDEFINE( aTestName ) \ |
|
65 _test_case_no++; \ |
|
66 if( aRunReason == EEnumerateTestCases ) \ |
|
67 { \ |
|
68 TTestCaseInfo* newCase = new( ELeave ) TTestCaseInfo(); \ |
|
69 CleanupStack::PushL( newCase ); \ |
|
70 newCase->iCaseNumber = _test_case_no; \ |
|
71 newCase->iTitle.Copy( _L( #aTestName ) ); \ |
|
72 User::LeaveIfError(aTestCases.Append ( newCase ) ); \ |
|
73 CleanupStack::Pop( newCase ); \ |
|
74 } \ |
|
75 else if(aRunReason == ERunTestCase && _test_case_no == aTestToRun) |
|
76 |
|
77 #define STIF_RUN_SETUP -1 |
|
78 #define STIF_RUN_TEARDOWN -2 |
|
79 |
|
80 // Defines a setup section of MainTestL method |
|
81 #define STIF_SETUP \ |
|
82 if( aRunReason == ERunTestCase && aTestToRun == STIF_RUN_SETUP ) |
|
83 |
|
84 // Defines a teardown section of MainTestL method |
|
85 #define STIF_TEARDOWN \ |
|
86 if( aRunReason == ERunTestCase && aTestToRun == STIF_RUN_TEARDOWN ) |
|
87 |
|
88 /********************************************************************************* |
|
89 * Assert Macros |
|
90 *********************************************************************************/ |
|
91 #define __STIF_ASSERT_SHARED( aFunction, aMessage ) \ |
|
92 if(!aFunction) \ |
|
93 { \ |
|
94 iLog->Log( aMessage, __STIF_DBG_FILE__, __LINE__ );\ |
|
95 aResult.SetResult( KErrGeneral, _L("Testcase failed"));\ |
|
96 User::Leave( KErrGeneral );\ |
|
97 } |
|
98 |
|
99 #define __STIF_ASSERT_SHARED_DESC( aFunction, aMessage, aDesc ) \ |
|
100 if(!aFunction) \ |
|
101 { \ |
|
102 iLog->Log( aMessage, __STIF_DBG_FILE__, __LINE__ );\ |
|
103 aResult.SetResult( KErrGeneral, aDesc );\ |
|
104 User::Leave( KErrGeneral );\ |
|
105 } \ |
|
106 else \ |
|
107 { \ |
|
108 aResult.SetResult( KErrNone, aDesc ); \ |
|
109 } |
|
110 |
|
111 |
|
112 |
|
113 #define STIF_ASSERT_EQUALS( aExpected, aActual ) \ |
|
114 __STIF_ASSERT_SHARED( AssertEquals( aExpected, aActual ) , KAssertFailedEquals ); |
|
115 |
|
116 #define STIF_ASSERT_EQUALS_DESC( aExpected, aActual, aDescription ) \ |
|
117 __STIF_ASSERT_SHARED_DESC( AssertEquals( aExpected, aActual ) , KAssertFailedEquals, aDescription ); |
|
118 |
|
119 #define STIF_ASSERT_NOT_EQUALS( aExpected, aActual ) \ |
|
120 __STIF_ASSERT_SHARED( !AssertEquals( aExpected, aActual ) , KAssertFailedNotEquals ); |
|
121 |
|
122 #define STIF_ASSERT_NOT_EQUALS_DESC( aExpected, aActual, aDescription ) \ |
|
123 __STIF_ASSERT_SHARED_DESC( !AssertEquals( aExpected, aActual ) , KAssertFailedNotEquals, aDescription ); |
|
124 |
|
125 #define STIF_ASSERT_NULL( aPtr ) \ |
|
126 __STIF_ASSERT_SHARED( AssertNull( aPtr ), KAssertFailedNull ); |
|
127 |
|
128 #define STIF_ASSERT_NULL_DESC( aPtr, aDescription ) \ |
|
129 __STIF_ASSERT_SHARED_DESC( AssertNull( aPtr ), KAssertFailedNull, aDescription ); |
|
130 |
|
131 #define STIF_ASSERT_NOT_NULL( aPtr ) \ |
|
132 __STIF_ASSERT_SHARED( !AssertNull( aPtr ), KAssertFailedNotNull ); |
|
133 |
|
134 #define STIF_ASSERT_NOT_NULL_DESC( aPtr, aDescription ) \ |
|
135 __STIF_ASSERT_SHARED_DESC( !AssertNull( aPtr ), KAssertFailedNotNull, aDescription ); |
|
136 |
|
137 #define STIF_ASSERT_SAME( aExpectedPtr, aActualPtr ) \ |
|
138 __STIF_ASSERT_SHARED( AssertSame( aExpectedPtr, aActualPtr ), KAssertFailedSame ); |
|
139 |
|
140 #define STIF_ASSERT_SAME_DESC( aExpectedPtr, aActualPtr, aDescription ) \ |
|
141 __STIF_ASSERT_SHARED_DESC( AssertSame( aExpectedPtr, aActualPtr ), KAssertFailedSame, aDescription ); |
|
142 |
|
143 #define STIF_ASSERT_NOT_SAME( aExpectedPtr, aActualPtr) \ |
|
144 __STIF_ASSERT_SHARED( !AssertSame( aExpectedPtr, aActualPtr ), KAssertFailedNotSame ); |
|
145 |
|
146 #define STIF_ASSERT_NOT_SAME_DESC( aExpectedPtr, aActualPtr, aDescription ) \ |
|
147 __STIF_ASSERT_SHARED_DESC( !AssertSame( aExpectedPtr, aActualPtr ), KAssertFailedNotSame, aDescription ); |
|
148 |
|
149 #define STIF_ASSERT_TRUE( aCondition ) \ |
|
150 __STIF_ASSERT_SHARED( AssertTrue( aCondition ), KAssertFailedTrue ); |
|
151 |
|
152 #define STIF_ASSERT_TRUE_DESC( aCondition, aDescription ) \ |
|
153 __STIF_ASSERT_SHARED_DESC( AssertTrue( aCondition ), KAssertFailedTrue, aDescription ); |
|
154 |
|
155 #define STIF_ASSERT_FALSE( aCondition ) \ |
|
156 __STIF_ASSERT_SHARED( !AssertTrue( aCondition ), KAssertFailedFalse ); |
|
157 |
|
158 #define STIF_ASSERT_FALSE_DESC( aCondition, aDescription ) \ |
|
159 __STIF_ASSERT_SHARED_DESC( !AssertTrue( aCondition), KAssertFailedFalse, aDescription ); |
|
160 |
|
161 // Eclosing block is used to create the scope for the __leaveValue |
|
162 #define STIF_ASSERT_NOT_LEAVES( aStatement ) \ |
|
163 { \ |
|
164 TRAPD( __leaveValue, aStatement ); \ |
|
165 __STIF_ASSERT_SHARED( AssertEquals( __leaveValue, KErrNone ), KAssertFailedNotLeaves ); \ |
|
166 } |
|
167 |
|
168 #define STIF_ASSERT_NOT_LEAVES_DESC( aStatement, aDescription ) \ |
|
169 { \ |
|
170 TRAPD( __leaveValue, aStatement ); \ |
|
171 __STIF_ASSERT_SHARED_DESC( AssertEquals( __leaveValue, KErrNone ), KAssertFailedNotLeaves, aDescription ); \ |
|
172 } |
|
173 |
|
174 // Eclosing block is used to create the scope for the __leaveValue |
|
175 #define STIF_ASSERT_LEAVES( aStatement ) \ |
|
176 { \ |
|
177 TRAPD( __leaveValue, aStatement ); \ |
|
178 __STIF_ASSERT_SHARED( !AssertEquals( __leaveValue, KErrNone ), KAssertFailedLeaves ); \ |
|
179 } |
|
180 |
|
181 #define STIF_ASSERT_LEAVES_DESC( aStatement, aDescription ) \ |
|
182 { \ |
|
183 TRAPD( __leaveValue, aStatement ); \ |
|
184 __STIF_ASSERT_SHARED_DESC( !AssertEquals( __leaveValue, KErrNone ), KAssertFailedLeaves, aDescription ); \ |
|
185 } |
|
186 |
|
187 // Eclosing block is used to create the scope for the __leaveValue |
|
188 #define STIF_ASSERT_LEAVES_WITH( aLeaveCode, aStatement ) \ |
|
189 { \ |
|
190 TRAPD( __leaveValue, aStatement ); \ |
|
191 __STIF_ASSERT_SHARED( AssertEquals( __leaveValue, aLeaveCode ), KAssertFailedLeaves ); \ |
|
192 } |
|
193 |
|
194 #define STIF_ASSERT_LEAVES_WITH_DESC( aLeaveCode, aStatement, aDescription ) \ |
|
195 { \ |
|
196 TRAPD( __leaveValue, aStatement ); \ |
|
197 __STIF_ASSERT_SHARED_DESC( AssertEquals( __leaveValue, aLeaveCode ), KAssertFailedLeaves, aDescription ); \ |
|
198 } |
|
199 |
|
200 #define STIF_ASSERT_PANIC( aPanicCode, aStatement ) \ |
|
201 { \ |
|
202 TestModuleIf().SetExitReason( CTestModuleIf::EPanic, aPanicCode ); \ |
|
203 aStatement; \ |
|
204 } |
|
205 |
|
206 #define STIF_ASSERT_PANIC_DESC( aPanicCode, aStatement, aDescription ) \ |
|
207 { \ |
|
208 TestModuleIf().SetExitReason( CTestModuleIf::EPanic, aPanicCode ); \ |
|
209 aResult.SetResult(KErrNone, aDescription); \ |
|
210 aStatement; \ |
|
211 } |
|
212 |
|
213 #include <StifUnitUtils.inl> |
|
214 |
|
215 #endif |