58 // |
58 // |
59 void UT_CSymbianUnitTestCommandLineParser::ConstructL() |
59 void UT_CSymbianUnitTestCommandLineParser::ConstructL() |
60 { |
60 { |
61 BASE_CONSTRUCT |
61 BASE_CONSTRUCT |
62 |
62 |
|
63 DEFINE_TEST_CLASS( UT_CSymbianUnitTestCommandLineParser ) |
|
64 |
63 ADD_SUT( UT_SetOutputFormatL ) |
65 ADD_SUT( UT_SetOutputFormatL ) |
64 ADD_SUT( UT_SetTestDllNamesL ) |
66 ADD_SUT( UT_SetTestDllNamesL ) |
65 ADD_SUT( UT_FindArgumentL ) |
67 ADD_SUT( UT_FindArgumentL ) |
|
68 ADD_SUT( UT_SetTimeoutL ) |
|
69 ADD_SUT( UT_SetTestCaseNamesL ) |
|
70 //ADD_SUT( UT_TestCommandLineL ) |
66 } |
71 } |
67 |
72 |
68 // --------------------------------------------------------------------------- |
73 // --------------------------------------------------------------------------- |
69 // |
74 // |
70 // --------------------------------------------------------------------------- |
75 // --------------------------------------------------------------------------- |
114 iParser->iArguments->Args().Reset(); |
119 iParser->iArguments->Args().Reset(); |
115 iParser->iArguments->Args().AppendL( KOutputFormatShort ); |
120 iParser->iArguments->Args().AppendL( KOutputFormatShort ); |
116 iParser->SetOutputFormatL(); |
121 iParser->SetOutputFormatL(); |
117 SUT_ASSERT_EQUALS( _L( "txt" ), iParser->OutputFormat() ) |
122 SUT_ASSERT_EQUALS( _L( "txt" ), iParser->OutputFormat() ) |
118 } |
123 } |
119 |
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 void UT_CSymbianUnitTestCommandLineParser::UT_SetTimeoutL() |
|
129 { |
|
130 // Default timeout. |
|
131 iParser->iArguments->Args().Reset(); |
|
132 iParser->SetTimeoutL(); |
|
133 SUT_ASSERT_EQUALS( iParser->Timeout(), 30 ) |
|
134 |
|
135 // Set timeout=50, long form. |
|
136 _LIT( KTimeoutLong, "-timeout=50" ); |
|
137 iParser->iArguments->Args().Reset(); |
|
138 iParser->iArguments->Args().AppendL( KTimeoutLong ); |
|
139 iParser->SetTimeoutL(); |
|
140 SUT_ASSERT_EQUALS( iParser->Timeout(), 50 ) |
|
141 |
|
142 // Set timeout=50, short form. |
|
143 _LIT( KTimeoutShort, "-to=20" ); |
|
144 iParser->iArguments->Args().Reset(); |
|
145 iParser->iArguments->Args().AppendL( KTimeoutShort ); |
|
146 iParser->SetTimeoutL(); |
|
147 SUT_ASSERT_EQUALS( iParser->Timeout(), 20 ) |
|
148 |
|
149 // Set timeout to invalid value, long form. |
|
150 _LIT( KInvalidTimeoutLong, "-timeout=-50" ); |
|
151 iParser->iArguments->Args().Reset(); |
|
152 iParser->iArguments->Args().AppendL( KInvalidTimeoutLong ); |
|
153 iParser->SetTimeoutL(); |
|
154 SUT_ASSERT_EQUALS( iParser->Timeout(), 30 ) |
|
155 } |
120 // ----------------------------------------------------------------------------- |
156 // ----------------------------------------------------------------------------- |
121 // |
157 // |
122 // ----------------------------------------------------------------------------- |
158 // ----------------------------------------------------------------------------- |
123 // |
159 // |
124 void UT_CSymbianUnitTestCommandLineParser::UT_SetTestDllNamesL() |
160 void UT_CSymbianUnitTestCommandLineParser::UT_SetTestDllNamesL() |
160 SUT_ASSERT_EQUALS( |
196 SUT_ASSERT_EQUALS( |
161 _L( "test4.dll" ), iParser->TestDllNames().MdcaPoint( 1 ) ) |
197 _L( "test4.dll" ), iParser->TestDllNames().MdcaPoint( 1 ) ) |
162 SUT_ASSERT( !iParser->ShowHelp() ) |
198 SUT_ASSERT( !iParser->ShowHelp() ) |
163 } |
199 } |
164 |
200 |
|
201 // --------------------------------------------------------------------------- |
|
202 // |
|
203 // --------------------------------------------------------------------------- |
|
204 // |
|
205 void UT_CSymbianUnitTestCommandLineParser::UT_SetTestCaseNamesL() |
|
206 { |
|
207 // Testcase Names, no name. |
|
208 iParser->SetTestCaseNamesL(); |
|
209 SUT_ASSERT( !iParser->TestCaseNames().MdcaCount() ) |
|
210 |
|
211 // One testcase name, long form. |
|
212 _LIT( KOneTestCaseNameLong, "-cases=case1" ); |
|
213 iParser->iArguments->Args().Reset(); |
|
214 iParser->iArguments->Args().AppendL( KOneTestCaseNameLong ); |
|
215 iParser->SetTestCaseNamesL(); |
|
216 SUT_ASSERT_EQUALS( 1, iParser->TestCaseNames().MdcaCount() ) |
|
217 SUT_ASSERT_EQUALS( |
|
218 _L( "case1" ), iParser->TestCaseNames().MdcaPoint( 0 ) ) |
|
219 |
|
220 // One testcase name, short form. |
|
221 _LIT( KOneTestCaseNameShort, "-c=case2" ); |
|
222 iParser->iArguments->Args().Reset(); |
|
223 iParser->iArguments->Args().AppendL( KOneTestCaseNameShort ); |
|
224 iParser->SetTestCaseNamesL(); |
|
225 SUT_ASSERT_EQUALS( 1, iParser->TestCaseNames().MdcaCount() ) |
|
226 SUT_ASSERT_EQUALS( |
|
227 _L( "case2" ), iParser->TestCaseNames().MdcaPoint( 0 ) ) |
|
228 |
|
229 // Two testcase names, long form. |
|
230 _LIT( KTwoTestCaseNameLong, "-cases=case3,case4" ); |
|
231 iParser->iArguments->Args().Reset(); |
|
232 iParser->iArguments->Args().AppendL( KTwoTestCaseNameLong ); |
|
233 iParser->SetTestCaseNamesL(); |
|
234 SUT_ASSERT_EQUALS( 2, iParser->TestCaseNames().MdcaCount() ) |
|
235 SUT_ASSERT_EQUALS( |
|
236 _L( "case3" ), iParser->TestCaseNames().MdcaPoint( 0 ) ) |
|
237 SUT_ASSERT_EQUALS( |
|
238 _L( "case4" ), iParser->TestCaseNames().MdcaPoint( 1 ) ) |
|
239 |
|
240 // Two testcase names, short form. |
|
241 _LIT( KTwoTestCaseNameShort, "-c=case5,case6" ); |
|
242 iParser->iArguments->Args().Reset(); |
|
243 iParser->iArguments->Args().AppendL( KTwoTestCaseNameShort ); |
|
244 iParser->SetTestCaseNamesL(); |
|
245 SUT_ASSERT_EQUALS( 2, iParser->TestCaseNames().MdcaCount() ) |
|
246 SUT_ASSERT_EQUALS( |
|
247 _L( "case5" ), iParser->TestCaseNames().MdcaPoint( 0 ) ) |
|
248 SUT_ASSERT_EQUALS( |
|
249 _L( "case6" ), iParser->TestCaseNames().MdcaPoint( 1 ) ) |
|
250 } |
|
251 |
165 // ----------------------------------------------------------------------------- |
252 // ----------------------------------------------------------------------------- |
166 // |
253 // |
167 // ----------------------------------------------------------------------------- |
254 // ----------------------------------------------------------------------------- |
168 // |
255 // |
169 void UT_CSymbianUnitTestCommandLineParser::UT_FindArgumentL() |
256 void UT_CSymbianUnitTestCommandLineParser::UT_FindArgumentL() |
210 iParser->iArguments->Args().AppendL( KValidArgument2 ); |
297 iParser->iArguments->Args().AppendL( KValidArgument2 ); |
211 _LIT( KShortKey, "k" ); |
298 _LIT( KShortKey, "k" ); |
212 SUT_ASSERT( iParser->FindArgument( KNullDesC, KShortKey, value ) ) |
299 SUT_ASSERT( iParser->FindArgument( KNullDesC, KShortKey, value ) ) |
213 SUT_ASSERT_EQUALS( _L( "value2" ), value ) |
300 SUT_ASSERT_EQUALS( _L( "value2" ), value ) |
214 } |
301 } |
|
302 |
|
303 void UT_CSymbianUnitTestCommandLineParser::LaunchExample( TInt aType ) |
|
304 { |
|
305 _LIT( KSymbianUnitTestFilename, "symbianunittest.exe" ); |
|
306 _LIT( KSymbianUnitTestArgs, "-t=ut_racecar.dll -noprompt -output=" ); |
|
307 |
|
308 const TInt KMaxArgLength( 255 ); |
|
309 TBuf<KMaxArgLength> strArgs; |
|
310 strArgs.Copy( KSymbianUnitTestArgs ); |
|
311 |
|
312 switch( aType ) |
|
313 { |
|
314 case 0: // html |
|
315 strArgs.Append( _L("html") ); |
|
316 break; |
|
317 |
|
318 case 1: // xml |
|
319 strArgs.Append( _L("xml") ); |
|
320 break; |
|
321 |
|
322 case 2: // txt |
|
323 strArgs.Append( _L("txt") ); |
|
324 break; |
|
325 |
|
326 default: |
|
327 //strArgs.Append( _L("html") ); |
|
328 strArgs = strArgs.Left( 27 ); |
|
329 } |
|
330 |
|
331 RProcess proc; |
|
332 proc.Create( KSymbianUnitTestFilename, strArgs ); |
|
333 TRequestStatus status; |
|
334 proc.Logon( status ); |
|
335 proc.Resume(); |
|
336 |
|
337 User::WaitForRequest( status ); |
|
338 proc.Close(); |
|
339 if ( KErrNone != status.Int() ) |
|
340 { |
|
341 User::LeaveIfError( status.Int() ); |
|
342 } |
|
343 } |
|
344 |
|
345 void UT_CSymbianUnitTestCommandLineParser::UT_TestCommandLineL() |
|
346 { |
|
347 // set output = html, xml, txt, default; |
|
348 for(TInt i=0; i<30; ++i) |
|
349 { |
|
350 LaunchExample(i); |
|
351 } |
|
352 } |