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 "symbianunittestcommandlineparser.h" |
|
19 #include "symbianunittestdllnameparser.h" |
|
20 #include "symbianunittestrunner.h" |
|
21 |
|
22 _LIT( KHelpKey, "-help" ); |
|
23 _LIT( KHelpKeyShort, "-h" ); |
|
24 _LIT( KTestsKey, "-tests=" ); |
|
25 _LIT( KTestsKeyShort, "-t=" ); |
|
26 _LIT( KTestCasesKey, "-cases=" ); |
|
27 _LIT( KTestCasesKeyShort, "-c=" ); |
|
28 _LIT( KAllocKey, "-alloc" ); |
|
29 _LIT( KAllocKeyShort, "-a" ); |
|
30 _LIT( KBackgroundKey, "-background" ); |
|
31 _LIT( KBackgroundKeyShort, "-b" ); |
|
32 _LIT( KOutputKey, "-output=" ); |
|
33 _LIT( KOutputKeyShort, "-o=" ); |
|
34 _LIT( KNoPromptKey, "-noprompt" ); |
|
35 _LIT( KTimeoutKey, "-timeout=" ); |
|
36 _LIT( KTimeoutKeyShort, "-to=" ); |
|
37 |
|
38 |
|
39 _LIT( KOutputFileName, "SymbianUnitTestResults" ); |
|
40 _LIT( KDefaultOutputFormat, "html" ); |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CSymbianUnitTestCommandLineParser* CSymbianUnitTestCommandLineParser::NewLC() |
|
47 { |
|
48 CSymbianUnitTestCommandLineParser* self = |
|
49 new( ELeave )CSymbianUnitTestCommandLineParser(); |
|
50 CleanupStack::PushL( self ); |
|
51 self->ConstructL(); |
|
52 return self; |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 CSymbianUnitTestCommandLineParser* CSymbianUnitTestCommandLineParser::NewL() |
|
60 { |
|
61 CSymbianUnitTestCommandLineParser* self = |
|
62 CSymbianUnitTestCommandLineParser::NewLC(); |
|
63 CleanupStack::Pop( self ); |
|
64 return self; |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 CSymbianUnitTestCommandLineParser::CSymbianUnitTestCommandLineParser() |
|
72 : iBackground( EFalse ) |
|
73 { |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 void CSymbianUnitTestCommandLineParser::ConstructL() |
|
81 { |
|
82 iArguments = CCommandLineArguments::NewL(); |
|
83 TPtrC dummy; |
|
84 iShowHelp = FindArgument( KHelpKey, KHelpKeyShort, dummy ); |
|
85 iAllocFailureSimulation = FindArgument( KAllocKey, KAllocKeyShort, dummy ); |
|
86 iNoPrompt = FindArgument( KNoPromptKey, KNoPromptKey, dummy ); |
|
87 iBackground = FindArgument( KBackgroundKey, KBackgroundKeyShort, dummy ); |
|
88 SetOutputFormatL(); |
|
89 SetTimeoutL(); |
|
90 SetTestDllNamesL(); |
|
91 SetTestCaseNamesL(); |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 CSymbianUnitTestCommandLineParser::~CSymbianUnitTestCommandLineParser() |
|
99 { |
|
100 delete iTestDllNames; |
|
101 delete iTestCaseNames; |
|
102 delete iOutputFormat; |
|
103 delete iArguments; |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 TBool CSymbianUnitTestCommandLineParser::ShowHelp() const |
|
111 { |
|
112 return iShowHelp; |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 // ----------------------------------------------------------------------------- |
|
118 // |
|
119 const MDesCArray& CSymbianUnitTestCommandLineParser::TestDllNames() const |
|
120 { |
|
121 return *iTestDllNames; |
|
122 } |
|
123 |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 const CDesCArray& CSymbianUnitTestCommandLineParser::TestCaseNames() const |
|
129 { |
|
130 return *iTestCaseNames; |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 TBool CSymbianUnitTestCommandLineParser::MemoryAllocationFailureSimulation() const |
|
138 { |
|
139 return iAllocFailureSimulation; |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 TBool CSymbianUnitTestCommandLineParser::Background() const |
|
147 { |
|
148 return iBackground; |
|
149 } |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 const TDesC& CSymbianUnitTestCommandLineParser::OutputFileName() const |
|
156 { |
|
157 return KOutputFileName; |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 const TDesC& CSymbianUnitTestCommandLineParser::OutputFormat() const |
|
165 { |
|
166 return *iOutputFormat; |
|
167 } |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 TInt CSymbianUnitTestCommandLineParser::Timeout() const |
|
174 { |
|
175 return iTimeout; |
|
176 } |
|
177 |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 TBool CSymbianUnitTestCommandLineParser::PromptUser() const |
|
184 { |
|
185 return !iNoPrompt; |
|
186 } |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 // ----------------------------------------------------------------------------- |
|
191 // |
|
192 void CSymbianUnitTestCommandLineParser::SetOutputFormatL() |
|
193 { |
|
194 HBufC* outputFormat = NULL; |
|
195 TPtrC outputFormatPtr; |
|
196 TBool found = EFalse; |
|
197 found = FindArgument( KOutputKey, KOutputKeyShort, outputFormatPtr ); |
|
198 if ( found ) |
|
199 { |
|
200 outputFormat = outputFormatPtr.AllocL(); |
|
201 } |
|
202 else |
|
203 { |
|
204 outputFormat = KDefaultOutputFormat().AllocL(); |
|
205 } |
|
206 delete iOutputFormat; |
|
207 iOutputFormat = outputFormat; |
|
208 } |
|
209 |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 // ----------------------------------------------------------------------------- |
|
213 // |
|
214 void CSymbianUnitTestCommandLineParser::SetTimeoutL() |
|
215 { |
|
216 iTimeout = KSymbianUnitTestDefaultTimeout; //use default |
|
217 TPtrC timeoutPtr; |
|
218 TBool hasTimeout = FindArgument( KTimeoutKey, KTimeoutKeyShort, timeoutPtr ); |
|
219 if ( hasTimeout) |
|
220 { |
|
221 TLex timeoutLex(timeoutPtr); |
|
222 TInt timeout; |
|
223 TInt ret = timeoutLex.Val(timeout); |
|
224 hasTimeout = ( ret == KErrNone && timeout >= 0 ); |
|
225 if ( hasTimeout ) |
|
226 { |
|
227 iTimeout = timeout; |
|
228 } |
|
229 } |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 void CSymbianUnitTestCommandLineParser::SetTestDllNamesL() |
|
237 { |
|
238 CDesCArray* testDllNames = new( ELeave )CDesCArrayFlat( 1 ); |
|
239 CleanupStack::PushL( testDllNames ); |
|
240 TPtrC testDllNamesPtr; |
|
241 TBool found = EFalse; |
|
242 found = FindArgument( KTestsKey, KTestsKeyShort, testDllNamesPtr ); |
|
243 if ( found ) |
|
244 { |
|
245 TSymbianUnitTestDllNameParser parser; |
|
246 parser.Parse( testDllNamesPtr ); |
|
247 TPtrC testDllNamePtr; |
|
248 TBool hasNext = EFalse; |
|
249 hasNext = ( parser.GetNext( testDllNamePtr ) == KErrNone ); |
|
250 while ( hasNext ) |
|
251 { |
|
252 testDllNames->AppendL( testDllNamePtr ); |
|
253 hasNext = ( parser.GetNext( testDllNamePtr ) == KErrNone ); |
|
254 } |
|
255 } |
|
256 iShowHelp = ( testDllNames->Count() == 0 ); |
|
257 CleanupStack::Pop( testDllNames ); |
|
258 delete iTestDllNames; |
|
259 iTestDllNames = testDllNames; |
|
260 } |
|
261 |
|
262 // ----------------------------------------------------------------------------- |
|
263 // |
|
264 // ----------------------------------------------------------------------------- |
|
265 // |
|
266 void CSymbianUnitTestCommandLineParser::SetTestCaseNamesL() |
|
267 { |
|
268 CDesCArray* testCaseNames = new( ELeave )CDesCArrayFlat( 1 ); |
|
269 CleanupStack::PushL( testCaseNames ); |
|
270 TPtrC testCaseNamesPtr; |
|
271 TBool found = EFalse; |
|
272 found = FindArgument( KTestCasesKey, KTestCasesKeyShort, testCaseNamesPtr ); |
|
273 if ( found ) |
|
274 { |
|
275 //reuse the testdll parser here for case names |
|
276 TSymbianUnitTestDllNameParser parser; |
|
277 parser.Parse( testCaseNamesPtr ); |
|
278 TPtrC testCaseNamePtr; |
|
279 TBool hasNext = EFalse; |
|
280 hasNext = ( parser.GetNext( testCaseNamePtr ) == KErrNone ); |
|
281 while ( hasNext ) |
|
282 { |
|
283 testCaseNames->AppendL( testCaseNamePtr ); |
|
284 hasNext = ( parser.GetNext( testCaseNamePtr ) == KErrNone ); |
|
285 } |
|
286 } |
|
287 CleanupStack::Pop( testCaseNames ); |
|
288 delete iTestCaseNames; |
|
289 iTestCaseNames = testCaseNames; |
|
290 } |
|
291 |
|
292 // ----------------------------------------------------------------------------- |
|
293 // |
|
294 // ----------------------------------------------------------------------------- |
|
295 // |
|
296 TBool CSymbianUnitTestCommandLineParser::FindArgument( |
|
297 const TDesC& aKey, |
|
298 const TDesC& aShortKey, |
|
299 TPtrC& aValue ) |
|
300 { |
|
301 TBool found( EFalse ); |
|
302 for ( TInt i = 0; i < iArguments->Count(); i++ ) |
|
303 { |
|
304 TPtrC arg( iArguments->Arg( i ) ); |
|
305 if ( arg.FindF( aKey ) == 0 || arg.FindF( aShortKey ) == 0 ) |
|
306 { |
|
307 found = ETrue; |
|
308 TInt equalsPos = arg.Locate( '=' ); |
|
309 if ( equalsPos > 0 & equalsPos < arg.Length() - 1 ) |
|
310 { |
|
311 aValue.Set( arg.Mid( equalsPos + 1 ) ); |
|
312 } |
|
313 } |
|
314 } |
|
315 return found; |
|
316 } |
|