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 "ut_symbianunittestresult.h" |
|
19 |
#include "symbianunittestresult.h" |
|
20 |
#include "symbianunittestfailure.h" |
|
21 |
#include <symbianunittestmacros.h> |
|
22 |
||
23 |
||
24 |
// --------------------------------------------------------------------------- |
|
25 |
// |
|
26 |
// --------------------------------------------------------------------------- |
|
27 |
// |
|
28 |
UT_CSymbianUnitTestResult* UT_CSymbianUnitTestResult::NewL() |
|
29 |
{ |
|
30 |
UT_CSymbianUnitTestResult* self = UT_CSymbianUnitTestResult::NewLC(); |
|
31 |
CleanupStack::Pop( self ); |
|
32 |
return self; |
|
33 |
} |
|
34 |
||
35 |
// --------------------------------------------------------------------------- |
|
36 |
// |
|
37 |
// --------------------------------------------------------------------------- |
|
38 |
// |
|
39 |
UT_CSymbianUnitTestResult* UT_CSymbianUnitTestResult::NewLC() |
|
40 |
{ |
|
41 |
UT_CSymbianUnitTestResult* self = |
|
42 |
new( ELeave )UT_CSymbianUnitTestResult(); |
|
43 |
CleanupStack::PushL( self ); |
|
44 |
self->ConstructL(); |
|
45 |
return self; |
|
46 |
} |
|
47 |
||
48 |
// --------------------------------------------------------------------------- |
|
49 |
// |
|
50 |
// --------------------------------------------------------------------------- |
|
51 |
// |
|
52 |
UT_CSymbianUnitTestResult::UT_CSymbianUnitTestResult() |
|
53 |
{ |
|
54 |
} |
|
55 |
||
56 |
// --------------------------------------------------------------------------- |
|
57 |
// |
|
58 |
// --------------------------------------------------------------------------- |
|
59 |
// |
|
60 |
void UT_CSymbianUnitTestResult::ConstructL() |
|
61 |
{ |
|
62 |
BASE_CONSTRUCT |
|
1
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
63 |
|
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
64 |
DEFINE_TEST_CLASS( UT_CSymbianUnitTestResult ) |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
65 |
|
0 | 66 |
ADD_SUT( UT_TestCountL ) |
67 |
ADD_SUT( UT_StartTestL ) |
|
68 |
ADD_SUT( UT_AddFailureL ) |
|
69 |
ADD_SUT( UT_AddSetupErrorL ) |
|
70 |
ADD_SUT( UT_AddLeaveFromTestL ) |
|
71 |
ADD_SUT( UT_AddAssertFailureL ) |
|
72 |
ADD_SUT( UT_AddMemoryLeakInfoL ) |
|
73 |
ADD_SUT( UT_AddPanicInfoL ) |
|
74 |
ADD_SUT( UT_AddTimeOutErrorL ) |
|
75 |
} |
|
76 |
||
77 |
// --------------------------------------------------------------------------- |
|
78 |
// |
|
79 |
// --------------------------------------------------------------------------- |
|
80 |
// |
|
81 |
UT_CSymbianUnitTestResult::~UT_CSymbianUnitTestResult() |
|
82 |
{ |
|
83 |
} |
|
84 |
||
85 |
// --------------------------------------------------------------------------- |
|
86 |
// |
|
87 |
// --------------------------------------------------------------------------- |
|
88 |
// |
|
89 |
void UT_CSymbianUnitTestResult::SetupL() |
|
90 |
{ |
|
91 |
iUnitTestResult = CSymbianUnitTestResult::NewL(); |
|
92 |
} |
|
93 |
||
94 |
// --------------------------------------------------------------------------- |
|
95 |
// |
|
96 |
// --------------------------------------------------------------------------- |
|
97 |
// |
|
98 |
void UT_CSymbianUnitTestResult::Teardown() |
|
99 |
{ |
|
100 |
delete iUnitTestResult; |
|
101 |
iUnitTestResult = NULL; |
|
102 |
} |
|
103 |
||
104 |
// --------------------------------------------------------------------------- |
|
105 |
// |
|
106 |
// --------------------------------------------------------------------------- |
|
107 |
// |
|
108 |
void UT_CSymbianUnitTestResult::UT_TestCountL() |
|
109 |
{ |
|
110 |
// No tests |
|
111 |
SUT_ASSERT_EQUALS( 0, iUnitTestResult->TestCount() ) |
|
112 |
||
113 |
// Increment the test count |
|
114 |
iUnitTestResult->iTestCount++; |
|
115 |
SUT_ASSERT_EQUALS( 1, iUnitTestResult->TestCount() ) |
|
116 |
} |
|
117 |
||
118 |
// --------------------------------------------------------------------------- |
|
119 |
// |
|
120 |
// --------------------------------------------------------------------------- |
|
121 |
// |
|
122 |
void UT_CSymbianUnitTestResult::UT_StartTestL() |
|
123 |
{ |
|
124 |
SUT_ASSERT_EQUALS( KNullDesC, *iUnitTestResult->iCurrentTestName ) |
|
125 |
SUT_ASSERT_EQUALS( 0, iUnitTestResult->TestCount() ) |
|
126 |
||
127 |
_LIT( KTestName, "FailedTest" ); |
|
128 |
iUnitTestResult->StartTestL( KTestName ); |
|
129 |
SUT_ASSERT_EQUALS( KTestName, *iUnitTestResult->iCurrentTestName ) |
|
130 |
SUT_ASSERT_EQUALS( 1, iUnitTestResult->TestCount() ) |
|
131 |
} |
|
132 |
||
133 |
// --------------------------------------------------------------------------- |
|
134 |
// |
|
135 |
// --------------------------------------------------------------------------- |
|
136 |
// |
|
137 |
void UT_CSymbianUnitTestResult::UT_AddFailureL() |
|
138 |
{ |
|
139 |
SUT_ASSERT_EQUALS( 0, iUnitTestResult->Failures().Count() ) |
|
140 |
||
141 |
_LIT8( KFailureText, "FailureText" ); |
|
142 |
||
143 |
// Memory allocation failure rate 0 |
|
144 |
iUnitTestResult->AddFailureL( KFailureText, 0 ); |
|
145 |
SUT_ASSERT_EQUALS( 1, iUnitTestResult->Failures().Count() ) |
|
146 |
SUT_ASSERT_EQUALS( |
|
147 |
KFailureText, iUnitTestResult->Failures()[ 0 ]->FailureMessage() ) |
|
148 |
SUT_ASSERT_EQUALS( |
|
149 |
KErrNotFound, iUnitTestResult->Failures()[ 0 ]->LineNumber() ) |
|
150 |
SUT_ASSERT_EQUALS( |
|
151 |
KNullDesC8, iUnitTestResult->Failures()[ 0 ]->FileName() ) |
|
152 |
||
153 |
// Memory allocation failure rate > 0 |
|
154 |
iUnitTestResult->AddFailureL( KFailureText, 1 ); |
|
155 |
SUT_ASSERT_EQUALS( 2, iUnitTestResult->Failures().Count() ) |
|
156 |
SUT_ASSERT( |
|
157 |
iUnitTestResult->Failures()[ 1 ]->FailureMessage() != KFailureText ) |
|
158 |
SUT_ASSERT_EQUALS( |
|
159 |
KErrNotFound, iUnitTestResult->Failures()[ 1 ]->LineNumber() ) |
|
160 |
SUT_ASSERT_EQUALS( |
|
161 |
KNullDesC8, iUnitTestResult->Failures()[ 1 ]->FileName() ) |
|
162 |
} |
|
163 |
||
164 |
// --------------------------------------------------------------------------- |
|
165 |
// |
|
166 |
// --------------------------------------------------------------------------- |
|
167 |
// |
|
168 |
void UT_CSymbianUnitTestResult::UT_AddSetupErrorL() |
|
169 |
{ |
|
170 |
SUT_ASSERT_EQUALS( 0, iUnitTestResult->Failures().Count() ) |
|
171 |
||
172 |
const TInt KErrorCode = KErrGeneral; |
|
173 |
iUnitTestResult->AddSetupErrorL( KErrorCode ); |
|
174 |
SUT_ASSERT_EQUALS( 1, iUnitTestResult->Failures().Count() ) |
|
175 |
SUT_ASSERT( |
|
176 |
iUnitTestResult->Failures()[ 0 ]->FailureMessage().Length () > 0 ) |
|
177 |
} |
|
178 |
||
179 |
// --------------------------------------------------------------------------- |
|
180 |
// |
|
181 |
// --------------------------------------------------------------------------- |
|
182 |
// |
|
183 |
void UT_CSymbianUnitTestResult::UT_AddLeaveFromTestL() |
|
184 |
{ |
|
185 |
SUT_ASSERT_EQUALS( 0, iUnitTestResult->Failures().Count() ) |
|
186 |
||
187 |
iUnitTestResult->AddLeaveFromTestL( KErrGeneral, 0 ); |
|
188 |
SUT_ASSERT_EQUALS( 1, iUnitTestResult->Failures().Count() ) |
|
189 |
SUT_ASSERT( |
|
190 |
iUnitTestResult->Failures()[ 0 ]->FailureMessage().Length () > 0 ) |
|
191 |
} |
|
192 |
||
193 |
// --------------------------------------------------------------------------- |
|
194 |
// |
|
195 |
// --------------------------------------------------------------------------- |
|
196 |
// |
|
197 |
void UT_CSymbianUnitTestResult::UT_AddAssertFailureL() |
|
198 |
{ |
|
199 |
SUT_ASSERT_EQUALS( 0, iUnitTestResult->Failures().Count() ) |
|
200 |
||
201 |
_LIT8( KFailureMessage, "assert failure" ); |
|
202 |
const TInt KLineNumber = 123; |
|
203 |
_LIT8( KFileName, "myfilename.cpp" ); |
|
204 |
iUnitTestResult->AddAssertFailureL( |
|
205 |
KFailureMessage, KLineNumber, KFileName ); |
|
206 |
SUT_ASSERT_EQUALS( 1, iUnitTestResult->Failures().Count() ) |
|
207 |
SUT_ASSERT_EQUALS( |
|
208 |
KFailureMessage, iUnitTestResult->Failures()[ 0 ]->FailureMessage() ) |
|
209 |
SUT_ASSERT_EQUALS( |
|
210 |
KLineNumber, iUnitTestResult->Failures()[ 0 ]->LineNumber() ) |
|
211 |
SUT_ASSERT_EQUALS( |
|
212 |
KFileName, iUnitTestResult->Failures()[ 0 ]->FileName() ) |
|
213 |
} |
|
214 |
||
215 |
// --------------------------------------------------------------------------- |
|
216 |
// |
|
217 |
// --------------------------------------------------------------------------- |
|
218 |
// |
|
219 |
void UT_CSymbianUnitTestResult::UT_AddMemoryLeakInfoL() |
|
220 |
{ |
|
221 |
SUT_ASSERT_EQUALS( 0, iUnitTestResult->Failures().Count() ) |
|
222 |
||
223 |
iUnitTestResult->AddMemoryLeakInfoL( 1, 0 ); |
|
224 |
SUT_ASSERT_EQUALS( 1, iUnitTestResult->Failures().Count() ) |
|
225 |
SUT_ASSERT( |
|
226 |
iUnitTestResult->Failures()[ 0 ]->FailureMessage().Length () > 0 ) |
|
227 |
} |
|
228 |
||
229 |
// --------------------------------------------------------------------------- |
|
230 |
// |
|
231 |
// --------------------------------------------------------------------------- |
|
232 |
// |
|
233 |
void UT_CSymbianUnitTestResult::UT_AddPanicInfoL() |
|
234 |
{ |
|
235 |
SUT_ASSERT_EQUALS( 0, iUnitTestResult->Failures().Count() ) |
|
236 |
||
237 |
TExitCategoryName dummy; |
|
238 |
iUnitTestResult->AddPanicInfoL( dummy, KErrGeneral, 0 ); |
|
239 |
SUT_ASSERT_EQUALS( 1, iUnitTestResult->Failures().Count() ) |
|
240 |
SUT_ASSERT( |
|
241 |
iUnitTestResult->Failures()[ 0 ]->FailureMessage().Length () > 0 ) |
|
242 |
} |
|
243 |
||
244 |
// --------------------------------------------------------------------------- |
|
245 |
// |
|
246 |
// --------------------------------------------------------------------------- |
|
247 |
// |
|
248 |
void UT_CSymbianUnitTestResult::UT_AddTimeOutErrorL() |
|
249 |
{ |
|
250 |
SUT_ASSERT_EQUALS( 0, iUnitTestResult->Failures().Count() ) |
|
251 |
||
252 |
const TInt KTimeOut = 10; |
|
253 |
iUnitTestResult->AddTimeOutErrorL( KTimeOut ); |
|
254 |
SUT_ASSERT_EQUALS( 1, iUnitTestResult->Failures().Count() ) |
|
255 |
SUT_ASSERT( |
|
256 |
iUnitTestResult->Failures()[ 0 ]->FailureMessage().Length () > 0 ) |
|
257 |
} |
|
258 |