author | Johnson Ma <johnson.ma@nokia.com> |
Mon, 29 Mar 2010 14:46:27 +0800 | |
changeset 1 | bbd31066657e |
parent 0 | 3e07fef1e154 |
permissions | -rw-r--r-- |
0 | 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 |
*/ |
|
17 |
||
18 |
#include "symbianunittestresult.h" |
|
19 |
#include "symbianunittestobserver.h" |
|
20 |
#include "sutlogger.h" |
|
21 |
#include <symbianunittest.h> |
|
22 |
#include <e32math.h> |
|
23 |
#include <utf.h> |
|
24 |
#include <e32debug.h> |
|
25 |
||
26 |
// Assertion failure message formats: |
|
27 |
_LIT8( KIntsNotEqualFormat, "Asserted: expected=%d, actual=%d" ); |
|
28 |
_LIT8( KDesCsNotEqualFormat, "Asserted: expected='%S', actual='%S'" ); |
|
29 |
_LIT8( KAssertLeaveFormat1, "'%S' expected to leave: expected=%d, actual=%d" ); |
|
30 |
_LIT8( KAssertLeaveFormat2, "'%S' expected to leave but did not leave" ); |
|
31 |
||
32 |
const TInt KMaxSizeOfTwoIntsAsText = 80; |
|
33 |
const TInt KErrSymbianUnitTestAssertionFailed = -99999999; |
|
34 |
_LIT( KTestThreadName, "SymbianUnitTestThread" ); |
|
35 |
const TInt KTestThreadMaxHeapSize = 0x400000; // 4 MB |
|
36 |
_LIT8( KDoubleColon8, "::" ); |
|
37 |
_LIT( KDoubleColon16, "::" ); |
|
38 |
||
39 |
// ----------------------------------------------------------------------------- |
|
40 |
// |
|
41 |
// ----------------------------------------------------------------------------- |
|
42 |
// |
|
43 |
EXPORT_C void CSymbianUnitTest::ConstructL( const TDesC8& aName ) |
|
44 |
{ |
|
45 |
TInt doubleColonPos( aName.FindF( KDoubleColon8 ) ); |
|
46 |
TPtrC8 classNamePtr( aName ); |
|
47 |
if ( doubleColonPos > 0 ) |
|
48 |
{ |
|
49 |
classNamePtr.Set( aName.Left( doubleColonPos ) ); |
|
50 |
} |
|
1
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
51 |
|
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
52 |
iName = CnvUtfConverter::ConvertToUnicodeFromUtf8L( classNamePtr ); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
53 |
|
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
54 |
SUT_LOG_FORMAT(_L("enter CSymbianUnitTest::ConstructL -- aName : [%S]"), iName ); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
55 |
|
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
56 |
// unify the same name for armv5 & winscw. |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
57 |
// on winscw, the function name is abc, |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
58 |
// on armv5, the function name is void abc. |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
59 |
// unify to abc. |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
60 |
TChar chSpace( ' ' ); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
61 |
TChar chTab( '\t' ); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
62 |
TChar chAsterisk( '*' ); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
63 |
TChar chAnd( '&' ); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
64 |
TBuf<100> strTmp( *iName ); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
65 |
strTmp.Trim(); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
66 |
TInt pos; |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
67 |
|
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
68 |
// "char * & abc" => abc |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
69 |
pos = strTmp.LocateReverse( chAnd ); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
70 |
if( KErrNotFound != pos ) |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
71 |
{ |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
72 |
TPtrC ptr = strTmp.Right( strTmp.Length() - pos - 1 ); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
73 |
strTmp = ptr; |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
74 |
strTmp.Trim(); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
75 |
} |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
76 |
// "void * abc" => abc |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
77 |
pos = strTmp.LocateReverse( chAsterisk ); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
78 |
if( KErrNotFound != pos ) |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
79 |
{ |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
80 |
TPtrC ptr = strTmp.Right( strTmp.Length() - pos - 1 ); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
81 |
strTmp = ptr; |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
82 |
strTmp.Trim(); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
83 |
} |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
84 |
// "void abc" |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
85 |
pos = strTmp.LocateReverse( chSpace ); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
86 |
if( KErrNotFound != pos ) |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
87 |
{ |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
88 |
TPtrC ptr = strTmp.Right( strTmp.Length() - pos - 1 ); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
89 |
strTmp = ptr; |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
90 |
strTmp.Trim(); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
91 |
} |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
92 |
// "void abc" |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
93 |
pos = strTmp.LocateReverse( chTab ); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
94 |
if( KErrNotFound != pos ) |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
95 |
{ |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
96 |
TPtrC ptr = strTmp.Right( strTmp.Length() - pos - 1 ); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
97 |
strTmp = ptr; |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
98 |
strTmp.Trim(); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
99 |
} |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
100 |
|
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
101 |
*iName = strTmp; |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
102 |
|
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
103 |
SUT_LOG_FORMAT(_L("exit CSymbianUnitTest::ConstructL -- aName : [%S]"), iName ); |
0 | 104 |
} |
105 |
||
106 |
// ----------------------------------------------------------------------------- |
|
107 |
// |
|
108 |
// ----------------------------------------------------------------------------- |
|
109 |
// |
|
110 |
EXPORT_C CSymbianUnitTest::CSymbianUnitTest() |
|
111 |
: iAllocFailureType( RHeap::ENone ), |
|
112 |
iAllocFailureRate( 0 ) |
|
113 |
{ |
|
114 |
} |
|
115 |
||
116 |
// ----------------------------------------------------------------------------- |
|
117 |
// |
|
118 |
// ----------------------------------------------------------------------------- |
|
119 |
// |
|
120 |
EXPORT_C CSymbianUnitTest::~CSymbianUnitTest() |
|
121 |
{ |
|
122 |
delete iName; |
|
123 |
iTestCases.ResetAndDestroy(); |
|
124 |
} |
|
125 |
||
126 |
// ----------------------------------------------------------------------------- |
|
127 |
// From MSymbianUnitTestInterface |
|
128 |
// ----------------------------------------------------------------------------- |
|
129 |
// |
|
130 |
EXPORT_C void CSymbianUnitTest::ExecuteL( |
|
131 |
MSymbianUnitTestObserver& aObserver, |
|
132 |
CSymbianUnitTestResult& aResult, |
|
133 |
MSymbianUnitTestInterface::TFailureSimulation aFailureSimulation, |
|
134 |
const CDesCArray& aTestCaseNames, |
|
135 |
TInt aTimeout ) |
|
136 |
{ |
|
137 |
if ( aFailureSimulation == EMemAllocFailureSimulation ) |
|
138 |
{ |
|
139 |
iAllocFailureType = RHeap::EDeterministic; |
|
140 |
} |
|
141 |
else |
|
142 |
{ |
|
143 |
iAllocFailureType = RHeap::ENone; |
|
144 |
} |
|
145 |
SUT_LOG_FORMAT(_L("start testing, total test cases[%d]"), iTestCases.Count()); |
|
146 |
//print the test cases name in the log |
|
147 |
for ( TInt i = iTestCases.Count() -1; i >=0 ; i-- ) |
|
148 |
{ |
|
149 |
CSymbianUnitTestCase& testCase = *( iTestCases[ i ] ); |
|
150 |
//check the specified test case list if any |
|
151 |
if ( aTestCaseNames.Count() > 0 ) |
|
152 |
{ |
|
153 |
TInt index=0; |
|
154 |
TInt ret = aTestCaseNames.Find(testCase.Name(), index ); |
|
155 |
if (ret != 0) |
|
156 |
{ |
|
157 |
//the case isn't in the specified test case names, skip it |
|
158 |
SUT_LOG_FORMAT(_L("skip test case[%S]"), &testCase.Name()); |
|
159 |
delete iTestCases[i]; |
|
160 |
iTestCases.Remove(i); |
|
161 |
continue; |
|
162 |
} |
|
163 |
} |
|
164 |
SUT_LOG_FORMAT(_L("TestCase[%S]"), &testCase.Name()); |
|
165 |
} |
|
166 |
||
167 |
for ( TInt i = 0; i < iTestCases.Count(); i++ ) |
|
168 |
{ |
|
169 |
CSymbianUnitTestCase& testCase = *( iTestCases[ i ] ); |
|
170 |
||
171 |
aResult.StartTestL( testCase.Name() ); |
|
172 |
ExecuteTestCaseInThreadL( testCase, aResult, aTimeout ); |
|
173 |
aResult.EndTestL(); |
|
174 |
aObserver.IncrementExecutedTestsCount(); |
|
175 |
} |
|
176 |
SUT_LOG_FORMAT(_L("testing finished, total passed test cases[%d]"), aResult.PassedTestCount()); |
|
177 |
} |
|
178 |
||
179 |
// ----------------------------------------------------------------------------- |
|
180 |
// From MSymbianUnitTestInterface |
|
181 |
// ----------------------------------------------------------------------------- |
|
182 |
// |
|
183 |
EXPORT_C TInt CSymbianUnitTest::TestCaseCount() |
|
184 |
{ |
|
185 |
return iTestCases.Count(); |
|
186 |
} |
|
187 |
||
188 |
// ----------------------------------------------------------------------------- |
|
189 |
// From MSymbianUnitTestInterface |
|
190 |
// ----------------------------------------------------------------------------- |
|
191 |
// |
|
192 |
EXPORT_C const TDesC& CSymbianUnitTest::Name() const |
|
193 |
{ |
|
194 |
if ( iName ) |
|
195 |
{ |
|
196 |
return *iName; |
|
197 |
} |
|
198 |
return KNullDesC; |
|
199 |
} |
|
200 |
||
201 |
// ----------------------------------------------------------------------------- |
|
202 |
// |
|
203 |
// ----------------------------------------------------------------------------- |
|
204 |
// |
|
205 |
EXPORT_C void CSymbianUnitTest::SetupL() |
|
206 |
{ |
|
207 |
// The default implementation is no operation |
|
208 |
} |
|
209 |
||
210 |
// ----------------------------------------------------------------------------- |
|
211 |
// |
|
212 |
// ----------------------------------------------------------------------------- |
|
213 |
// |
|
214 |
EXPORT_C void CSymbianUnitTest::Teardown() |
|
215 |
{ |
|
216 |
// The default implementation is no operation |
|
217 |
} |
|
218 |
||
219 |
// ----------------------------------------------------------------------------- |
|
220 |
// |
|
221 |
// ----------------------------------------------------------------------------- |
|
222 |
// |
|
223 |
EXPORT_C TBool CSymbianUnitTest::IsMemoryAllocationFailureSimulationUsed() const |
|
224 |
{ |
|
225 |
return ( iAllocFailureType == RHeap::EDeterministic ); |
|
226 |
} |
|
227 |
||
228 |
// ----------------------------------------------------------------------------- |
|
229 |
// |
|
230 |
// ----------------------------------------------------------------------------- |
|
231 |
// |
|
232 |
EXPORT_C void CSymbianUnitTest::AddTestCaseL( |
|
233 |
const TDesC& aName, |
|
234 |
FunctionPtr aSetupFunction, |
|
235 |
FunctionPtr aTestFunction, |
|
236 |
FunctionPtr aTeardownFunction ) |
|
237 |
{ |
|
238 |
const TInt KTestCaseNameLength = |
|
239 |
Name().Length() + KDoubleColon16().Length() + aName.Length(); |
|
240 |
HBufC* name = HBufC::NewLC( KTestCaseNameLength ); |
|
241 |
name->Des().Append( Name() ); |
|
242 |
name->Des().Append( KDoubleColon16 ); |
|
243 |
name->Des().Append( aName ); |
|
244 |
CSymbianUnitTestCase* testCase = |
|
245 |
CSymbianUnitTestCase::NewL( |
|
246 |
*name, aSetupFunction, aTestFunction, aTeardownFunction ); |
|
247 |
CleanupStack::PopAndDestroy( name ); |
|
248 |
CleanupStack::PushL( testCase ); |
|
249 |
iTestCases.AppendL( testCase ); |
|
250 |
CleanupStack::Pop( testCase ); |
|
251 |
} |
|
252 |
||
253 |
// ----------------------------------------------------------------------------- |
|
254 |
// |
|
255 |
// ----------------------------------------------------------------------------- |
|
256 |
// |
|
257 |
EXPORT_C void CSymbianUnitTest::AssertEqualsL( |
|
258 |
TInt aExpectedValue, |
|
259 |
TInt aActualValue, |
|
260 |
TInt aLineNumber, |
|
261 |
const TDesC8& aFileName ) |
|
262 |
{ |
|
263 |
if ( aExpectedValue != aActualValue ) |
|
264 |
{ |
|
265 |
StopAllocFailureSimulation(); |
|
266 |
HBufC8* msg = HBufC8::NewLC( |
|
267 |
KIntsNotEqualFormat().Size() + KMaxSizeOfTwoIntsAsText ); |
|
268 |
msg->Des().Format( KIntsNotEqualFormat, aExpectedValue, aActualValue ); |
|
269 |
AssertionFailedL( *msg, aLineNumber, aFileName ); |
|
270 |
} |
|
271 |
} |
|
272 |
||
273 |
// ----------------------------------------------------------------------------- |
|
274 |
// |
|
275 |
// ----------------------------------------------------------------------------- |
|
276 |
// |
|
277 |
EXPORT_C void CSymbianUnitTest::AssertEqualsL( |
|
278 |
const TDesC8& aExpectedValue, |
|
279 |
const TDesC8& aActualValue, |
|
280 |
TInt aLineNumber, |
|
281 |
const TDesC8& aFileName ) |
|
282 |
{ |
|
283 |
if ( aExpectedValue.Compare( aActualValue ) != 0 ) |
|
284 |
{ |
|
285 |
StopAllocFailureSimulation(); |
|
286 |
TInt size = |
|
287 |
KDesCsNotEqualFormat().Size() + |
|
288 |
aExpectedValue.Size() + |
|
289 |
aActualValue.Size(); |
|
290 |
HBufC8 *msg = HBufC8::NewLC( size ); |
|
291 |
msg->Des().Format( KDesCsNotEqualFormat, |
|
292 |
&aExpectedValue, |
|
293 |
&aActualValue ); |
|
294 |
AssertionFailedL( *msg, aLineNumber, aFileName ); |
|
295 |
} |
|
296 |
} |
|
297 |
||
298 |
// ----------------------------------------------------------------------------- |
|
299 |
// |
|
300 |
// ----------------------------------------------------------------------------- |
|
301 |
// |
|
302 |
EXPORT_C void CSymbianUnitTest::AssertEqualsL( |
|
303 |
const TDesC16& aExpectedValue, |
|
304 |
const TDesC16& aActualValue, |
|
305 |
TInt aLineNumber, |
|
306 |
const TDesC8& aFileName ) |
|
307 |
{ |
|
308 |
if ( aExpectedValue.Compare( aActualValue ) != 0 ) |
|
309 |
{ |
|
310 |
StopAllocFailureSimulation(); |
|
311 |
HBufC8* msg = NotEqualsMessageLC( aExpectedValue, aActualValue ); |
|
312 |
AssertionFailedL( *msg, aLineNumber, aFileName ); |
|
313 |
} |
|
314 |
} |
|
315 |
||
316 |
// ----------------------------------------------------------------------------- |
|
317 |
// |
|
318 |
// ----------------------------------------------------------------------------- |
|
319 |
// |
|
320 |
EXPORT_C void CSymbianUnitTest::AssertLeaveL( |
|
321 |
const TDesC8& aStatement, |
|
322 |
TInt aActualLeaveCode, |
|
323 |
TInt aExpectedLeaveCode, |
|
324 |
TInt aLineNumber, |
|
325 |
const TDesC8& aFileName ) |
|
326 |
{ |
|
327 |
if ( aActualLeaveCode == KErrNoMemory && |
|
328 |
aExpectedLeaveCode != KErrNoMemory && |
|
329 |
iAllocFailureType == RHeap::EDeterministic ) |
|
330 |
{ |
|
331 |
User::Leave( KErrNoMemory ); |
|
332 |
} |
|
333 |
if ( aActualLeaveCode != aExpectedLeaveCode ) |
|
334 |
{ |
|
335 |
StopAllocFailureSimulation(); |
|
336 |
HBufC8* msg = HBufC8::NewLC( |
|
337 |
KAssertLeaveFormat1().Size() + |
|
338 |
aStatement.Size() + |
|
339 |
KMaxSizeOfTwoIntsAsText ); |
|
340 |
msg->Des().Format( KAssertLeaveFormat2, &aStatement, |
|
341 |
aExpectedLeaveCode, aActualLeaveCode ); |
|
342 |
AssertionFailedL( *msg, aLineNumber, aFileName ); |
|
343 |
} |
|
344 |
} |
|
345 |
||
346 |
// ----------------------------------------------------------------------------- |
|
347 |
// |
|
348 |
// ----------------------------------------------------------------------------- |
|
349 |
// |
|
350 |
EXPORT_C void CSymbianUnitTest::RecordNoLeaveFromStatementL( |
|
351 |
const TDesC8& aStatement, |
|
352 |
TInt aLineNumber, |
|
353 |
const TDesC8& aFileName ) |
|
354 |
{ |
|
355 |
StopAllocFailureSimulation(); |
|
356 |
HBufC8* msg = |
|
357 |
HBufC8::NewLC( KAssertLeaveFormat1().Size() + aStatement.Size() ); |
|
358 |
msg->Des().Format( KAssertLeaveFormat1, &aStatement ); |
|
359 |
AssertionFailedL( *msg, aLineNumber, aFileName ); |
|
360 |
} |
|
361 |
||
362 |
// ----------------------------------------------------------------------------- |
|
363 |
// |
|
364 |
// ----------------------------------------------------------------------------- |
|
365 |
// |
|
366 |
EXPORT_C void CSymbianUnitTest::AssertionFailedL( |
|
367 |
const TDesC8& aFailureMessage, |
|
368 |
TInt aLineNumber, |
|
369 |
const TDesC8& aFileName ) |
|
370 |
{ |
|
371 |
TInt dummy( 0 ); |
|
372 |
TInt heapCellsBeforeAddingTheFailure( User::Heap().AllocSize( dummy ) ); |
|
373 |
||
374 |
if ( iTestResult ) |
|
375 |
{ |
|
376 |
User::LeaveIfError( iTestResult->AddAssertFailure( |
|
377 |
aFailureMessage, aLineNumber, aFileName ) ); |
|
378 |
} |
|
379 |
||
380 |
TInt heapCellsAfterAddingTheFailure( User::Heap().AllocSize( dummy ) ); |
|
381 |
iHeapCellsReservedByAssertFailure = |
|
382 |
heapCellsAfterAddingTheFailure - heapCellsBeforeAddingTheFailure; |
|
383 |
User::Leave( KErrSymbianUnitTestAssertionFailed ); |
|
384 |
} |
|
385 |
||
1
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
386 |
|
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
387 |
// ----------------------------------------------------------------------------- |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
388 |
// |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
389 |
// ----------------------------------------------------------------------------- |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
390 |
// |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
391 |
EXPORT_C void CSymbianUnitTest::AssertEqualsL( |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
392 |
TInt aExpectedValue, |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
393 |
TInt aActualValue, |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
394 |
TInt aLineNumber, |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
395 |
const TDesC8& aFileName, |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
396 |
const TDesC8& aFailureMessage ) |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
397 |
{ |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
398 |
if ( aExpectedValue != aActualValue ) |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
399 |
{ |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
400 |
StopAllocFailureSimulation(); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
401 |
AssertionFailedL( aFailureMessage, aLineNumber, aFileName ); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
402 |
} |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
403 |
} |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
404 |
|
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
405 |
// ----------------------------------------------------------------------------- |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
406 |
// |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
407 |
// ----------------------------------------------------------------------------- |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
408 |
// |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
409 |
EXPORT_C void CSymbianUnitTest::AssertEqualsL( |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
410 |
const TDesC8& aExpectedValue, |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
411 |
const TDesC8& aActualValue, |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
412 |
TInt aLineNumber, |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
413 |
const TDesC8& aFileName, |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
414 |
const TDesC8& aFailureMessage ) |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
415 |
{ |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
416 |
if ( aExpectedValue.Compare( aActualValue ) != 0 ) |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
417 |
{ |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
418 |
StopAllocFailureSimulation(); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
419 |
AssertionFailedL( aFailureMessage, aLineNumber, aFileName ); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
420 |
} |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
421 |
} |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
422 |
|
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
423 |
// ----------------------------------------------------------------------------- |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
424 |
// |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
425 |
// ----------------------------------------------------------------------------- |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
426 |
// |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
427 |
EXPORT_C void CSymbianUnitTest::AssertEqualsL( |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
428 |
const TDesC16& aExpectedValue, |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
429 |
const TDesC16& aActualValue, |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
430 |
TInt aLineNumber, |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
431 |
const TDesC8& aFileName, |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
432 |
const TDesC8& aFailureMessage ) |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
433 |
{ |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
434 |
if ( aExpectedValue.Compare( aActualValue ) != 0 ) |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
435 |
{ |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
436 |
StopAllocFailureSimulation(); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
437 |
AssertionFailedL( aFailureMessage, aLineNumber, aFileName ); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
438 |
} |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
439 |
} |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
440 |
|
0 | 441 |
// ----------------------------------------------------------------------------- |
442 |
// |
|
443 |
// ----------------------------------------------------------------------------- |
|
444 |
// |
|
445 |
CSymbianUnitTest::CSymbianUnitTestCase* |
|
446 |
CSymbianUnitTest::CSymbianUnitTestCase::NewL( |
|
447 |
const TDesC& aName, |
|
448 |
FunctionPtr aSetupFunction, |
|
449 |
FunctionPtr aTestFunction, |
|
450 |
FunctionPtr aTeardownFunction ) |
|
451 |
{ |
|
452 |
CSymbianUnitTestCase* self = |
|
453 |
new( ELeave )CSymbianUnitTestCase( |
|
454 |
aSetupFunction, aTestFunction, aTeardownFunction ); |
|
455 |
CleanupStack::PushL( self ); |
|
456 |
self->ConstructL( aName ); |
|
457 |
CleanupStack::Pop( self ); |
|
458 |
return self; |
|
459 |
} |
|
460 |
||
461 |
// ----------------------------------------------------------------------------- |
|
462 |
// |
|
463 |
// ----------------------------------------------------------------------------- |
|
464 |
// |
|
465 |
CSymbianUnitTest::CSymbianUnitTestCase::CSymbianUnitTestCase( |
|
466 |
FunctionPtr aSetupFunction, |
|
467 |
FunctionPtr aTestFunction, |
|
468 |
FunctionPtr aTeardownFunction ) : |
|
469 |
iSetupFunction( aSetupFunction ), |
|
470 |
iTestFunction( aTestFunction ), |
|
471 |
iTeardownFunction( aTeardownFunction ) |
|
472 |
{ |
|
473 |
} |
|
474 |
||
475 |
// ----------------------------------------------------------------------------- |
|
476 |
// |
|
477 |
// ----------------------------------------------------------------------------- |
|
478 |
// |
|
479 |
void CSymbianUnitTest::CSymbianUnitTestCase::ConstructL( const TDesC& aName ) |
|
480 |
{ |
|
481 |
iName = aName.AllocL(); |
|
482 |
} |
|
483 |
||
484 |
// ----------------------------------------------------------------------------- |
|
485 |
// |
|
486 |
// ----------------------------------------------------------------------------- |
|
487 |
// |
|
488 |
CSymbianUnitTest::CSymbianUnitTestCase::~CSymbianUnitTestCase() |
|
489 |
{ |
|
490 |
delete iName; |
|
491 |
} |
|
492 |
||
493 |
// ----------------------------------------------------------------------------- |
|
494 |
// |
|
495 |
// ----------------------------------------------------------------------------- |
|
496 |
// |
|
497 |
const TDesC& CSymbianUnitTest::CSymbianUnitTestCase::Name() const |
|
498 |
{ |
|
499 |
return *iName; |
|
500 |
} |
|
501 |
||
502 |
// ----------------------------------------------------------------------------- |
|
503 |
// |
|
504 |
// ----------------------------------------------------------------------------- |
|
505 |
// |
|
506 |
HBufC8* CSymbianUnitTest::NotEqualsMessageLC( |
|
507 |
const TDesC16& aExpectedValue, |
|
508 |
const TDesC16& aActualValue ) |
|
509 |
{ |
|
510 |
TInt length = |
|
511 |
KDesCsNotEqualFormat().Length() + |
|
512 |
aExpectedValue.Length() + |
|
513 |
aActualValue.Length(); |
|
514 |
HBufC8* msg = HBufC8::NewLC( length ); |
|
515 |
||
516 |
HBufC8* expected = |
|
517 |
CnvUtfConverter::ConvertFromUnicodeToUtf8L( aExpectedValue ); |
|
518 |
CleanupStack::PushL( expected ); |
|
519 |
||
520 |
HBufC8* actual = CnvUtfConverter::ConvertFromUnicodeToUtf8L( aActualValue ); |
|
521 |
CleanupStack::PushL( actual ); |
|
522 |
||
523 |
msg->Des().Format( KDesCsNotEqualFormat, expected, actual ); |
|
524 |
||
525 |
CleanupStack::PopAndDestroy( actual ); |
|
526 |
CleanupStack::PopAndDestroy( expected ); |
|
527 |
||
528 |
return msg; |
|
529 |
} |
|
530 |
||
531 |
// ----------------------------------------------------------------------------- |
|
532 |
// |
|
533 |
// ----------------------------------------------------------------------------- |
|
534 |
// |
|
535 |
void CSymbianUnitTest::ExecuteTestCaseInThreadL( |
|
536 |
CSymbianUnitTestCase& aTestCase, |
|
537 |
CSymbianUnitTestResult& aResult, |
|
538 |
TInt aTimeout ) |
|
539 |
{ |
|
540 |
iCurrentTestCase = &aTestCase; |
|
541 |
iTestResult = &aResult; |
|
542 |
||
543 |
//create exec thread |
|
544 |
TName threadName( KTestThreadName ); |
|
545 |
// Append a random number to make the name unique |
|
546 |
const TInt KThreadIdWidth = 10; |
|
547 |
threadName.AppendNumFixedWidthUC( Math::Random(), EHex, KThreadIdWidth ); |
|
548 |
RThread execThread; |
|
549 |
TInt err = execThread.Create( threadName, |
|
550 |
TestThreadEntryFunction, |
|
551 |
KDefaultStackSize, |
|
552 |
KMinHeapSize, |
|
553 |
KTestThreadMaxHeapSize, |
|
554 |
this ); |
|
555 |
User::LeaveIfError( err ); |
|
556 |
CleanupClosePushL( execThread ); |
|
557 |
||
558 |
||
559 |
//start exec thread |
|
560 |
TRequestStatus status; |
|
561 |
execThread.Logon( status ); |
|
562 |
execThread.Resume(); |
|
563 |
||
564 |
TBool timedOut = EFalse; |
|
565 |
if (aTimeout > 0 ) |
|
566 |
{ |
|
567 |
SUT_LOG_DEBUGF(_L("run test case with timeout %d"), aTimeout); |
|
568 |
//run test case with timeout control |
|
569 |
TRequestStatus waitStatus = KRequestPending; |
|
570 |
RTimer timer; |
|
571 |
User::LeaveIfError(timer.CreateLocal()); |
|
572 |
CleanupClosePushL(timer); |
|
573 |
timer.After(waitStatus, aTimeout*1000000); |
|
574 |
User::WaitForRequest( status, waitStatus ); |
|
575 |
if (waitStatus.Int() == KRequestPending) |
|
576 |
{ |
|
577 |
timer.Cancel(); |
|
578 |
} |
|
579 |
||
580 |
if (status.Int() == KRequestPending) |
|
581 |
{ |
|
582 |
//test case did not complete in time |
|
583 |
//terminate the exec thread |
|
584 |
SUT_LOG_DEBUG(" test case timed out, kill the exec thread"); |
|
585 |
timedOut = ETrue; |
|
586 |
execThread.Kill(KErrTimedOut); |
|
587 |
aResult.AddTimeOutErrorL( aTimeout ); |
|
588 |
} |
|
589 |
CleanupStack::PopAndDestroy( &timer ); |
|
590 |
} |
|
591 |
else |
|
592 |
{ |
|
593 |
SUT_LOG_DEBUG(" run test case without timeout"); |
|
594 |
//exec test case without timeout control |
|
595 |
User::WaitForRequest(status); |
|
596 |
} |
|
597 |
if (status.Int() != KErrNone && !timedOut) |
|
598 |
{ |
|
599 |
SUT_LOG_DEBUG("testcase exec thread panic"); |
|
600 |
aResult.AddPanicInfoL( |
|
601 |
execThread.ExitCategory(), |
|
602 |
execThread.ExitReason(), |
|
603 |
iAllocFailureRate ); |
|
604 |
} |
|
605 |
CleanupStack::PopAndDestroy( &execThread ); |
|
606 |
} |
|
607 |
||
608 |
// ----------------------------------------------------------------------------- |
|
609 |
// |
|
610 |
// ----------------------------------------------------------------------------- |
|
611 |
// |
|
612 |
TInt CSymbianUnitTest::TestThreadEntryFunction( TAny* aPtr ) |
|
613 |
{ |
|
614 |
CSymbianUnitTest* self = reinterpret_cast< CSymbianUnitTest* >( aPtr ); |
|
615 |
TInt err = KErrNoMemory; |
|
616 |
CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
617 |
if ( cleanupStack ) |
|
618 |
{ |
|
619 |
// Operator new used without ELeave on purpose to avoid using TRAP. |
|
620 |
CActiveScheduler* scheduler = new CActiveScheduler; |
|
621 |
if ( scheduler ) |
|
622 |
{ |
|
623 |
CActiveScheduler::Install( scheduler ); |
|
624 |
TRAP( err, self->ExecuteTestCaseL() ) |
|
625 |
delete scheduler; |
|
626 |
} |
|
627 |
} |
|
628 |
delete cleanupStack; |
|
629 |
return err; |
|
630 |
} |
|
631 |
||
632 |
// ----------------------------------------------------------------------------- |
|
633 |
// |
|
634 |
// ----------------------------------------------------------------------------- |
|
635 |
// |
|
636 |
void CSymbianUnitTest::ExecuteTestCaseL() |
|
637 |
{ |
|
638 |
__ASSERT_ALWAYS( iTestResult, User::Leave( KErrNotFound ) ); |
|
639 |
__ASSERT_ALWAYS( iCurrentTestCase, User::Leave( KErrNotFound ) ); |
|
640 |
iAllocFailureRate = 0; |
|
641 |
iLeakedMemory = 0; |
|
642 |
TInt leaveCodeFromTest( KErrNoMemory ); |
|
643 |
if ( iAllocFailureType == RHeap::EDeterministic ) |
|
644 |
{ |
|
645 |
TUint counter( 1 ); |
|
646 |
while ( leaveCodeFromTest == KErrNoMemory ) |
|
647 |
{ |
|
648 |
iAllocFailureRate = counter; |
|
649 |
DoExecuteTestCaseL( leaveCodeFromTest ); |
|
650 |
counter++; |
|
651 |
} |
|
652 |
} |
|
653 |
else |
|
654 |
{ |
|
655 |
DoExecuteTestCaseL( leaveCodeFromTest ); |
|
656 |
} |
|
657 |
// Add the possible failure or memory leak to the results |
|
658 |
if ( leaveCodeFromTest == KErrNone ) |
|
659 |
{ |
|
660 |
if ( iLeakedMemory > 0 ) |
|
661 |
{ |
|
662 |
iTestResult->AddMemoryLeakInfoL( iLeakedMemory, iAllocFailureRate ); |
|
663 |
} |
|
664 |
} |
|
665 |
else if ( leaveCodeFromTest != KErrSymbianUnitTestAssertionFailed ) |
|
666 |
{ |
|
667 |
iTestResult->AddLeaveFromTestL( leaveCodeFromTest, iAllocFailureRate ); |
|
668 |
} |
|
669 |
else |
|
670 |
{ |
|
671 |
// No operation here. |
|
672 |
// Assertion failure has happened and it has been added to the results. |
|
673 |
} |
|
674 |
} |
|
675 |
||
676 |
// ----------------------------------------------------------------------------- |
|
677 |
// |
|
678 |
// ----------------------------------------------------------------------------- |
|
679 |
// |
|
680 |
void CSymbianUnitTest::DoExecuteTestCaseL( TInt& aLeaveCodeFromTest ) |
|
681 |
{ |
|
682 |
__ASSERT_ALWAYS( iTestResult, User::Leave( KErrNotFound ) ); |
|
683 |
__ASSERT_ALWAYS( iCurrentTestCase, User::Leave( KErrNotFound ) ); |
|
684 |
||
685 |
aLeaveCodeFromTest = KErrNone; |
|
686 |
iHeapCellsReservedByAssertFailure = 0; |
|
687 |
TInt memoryBeforeTest( 0 ); |
|
688 |
TInt heapCellsBeforeTest( User::Heap().AllocSize( memoryBeforeTest ) ); |
|
689 |
||
690 |
TRAPD( err, ( this->*iCurrentTestCase->iSetupFunction )() ) |
|
691 |
if ( err != KErrNone ) |
|
692 |
{ |
|
693 |
( this->*iCurrentTestCase->iTeardownFunction )(); |
|
694 |
iTestResult->AddSetupErrorL( err ); |
|
695 |
return; |
|
696 |
} |
|
697 |
||
698 |
StartAllocFailureSimulation(); |
|
699 |
TRAP( aLeaveCodeFromTest, ( this->*iCurrentTestCase->iTestFunction )() ); |
|
700 |
StopAllocFailureSimulation(); |
|
701 |
||
702 |
( this->*iCurrentTestCase->iTeardownFunction )(); |
|
703 |
||
704 |
TInt memoryAfterTest( 0 ); |
|
705 |
TInt heapCellsAfterTest( User::Heap().AllocSize( memoryAfterTest ) ); |
|
706 |
TInt leakedHeapCells = |
|
707 |
heapCellsAfterTest - |
|
708 |
( heapCellsBeforeTest + iHeapCellsReservedByAssertFailure ); |
|
709 |
if ( leakedHeapCells > 0 ) |
|
710 |
{ |
|
711 |
iLeakedMemory = memoryAfterTest - memoryBeforeTest; |
|
712 |
} |
|
713 |
} |
|
714 |
||
715 |
// ----------------------------------------------------------------------------- |
|
716 |
// |
|
717 |
// ----------------------------------------------------------------------------- |
|
718 |
// |
|
719 |
void CSymbianUnitTest::StartAllocFailureSimulation() |
|
720 |
{ |
|
721 |
__UHEAP_SETFAIL( iAllocFailureType, iAllocFailureRate ); |
|
722 |
} |
|
723 |
||
724 |
// ----------------------------------------------------------------------------- |
|
725 |
// |
|
726 |
// ----------------------------------------------------------------------------- |
|
727 |
// |
|
728 |
void CSymbianUnitTest::StopAllocFailureSimulation() |
|
729 |
{ |
|
730 |
__UHEAP_RESET; |
|
731 |
} |