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