|
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // $Header$ |
|
15 // GT0149 Applications Protocol Integration Test Harness |
|
16 // blank application |
|
17 // created by: mark j davey |
|
18 // mjd systems solutions ltd |
|
19 // mark@mjdss.com |
|
20 // This is the 'main' code entry point for the Test Harness Application. |
|
21 // As other projects adopt policy, then separate DLL's will be created for |
|
22 // each group which can be specified (or colocated) for inclusion. |
|
23 // This way the harness is sanitized from the project knowledge domain |
|
24 // |
|
25 // |
|
26 |
|
27 #include <e32base.h> |
|
28 #include <e32cons.h> |
|
29 #include <uri8.h> |
|
30 #include <bacline.h> |
|
31 |
|
32 //---------------------------------------------------------------------------- |
|
33 // application specific includes |
|
34 |
|
35 #include "GT0149.h" |
|
36 #include "ECommandIDs.h" |
|
37 #include "ErrorCodes.h" |
|
38 #include "TEngine.h" |
|
39 #include "CCmdFamily.h" |
|
40 #include "CCmdBase.h" |
|
41 #include "CCmdStandard.h" |
|
42 #include "CCmdMisc.h" |
|
43 #include "CCmdLog.h" |
|
44 #include "CLogFile.h" |
|
45 #include "HttpSessionCmds.h" |
|
46 #include "HttpTransactionCmds.h" |
|
47 |
|
48 //---------------------------------------------------------------------------- |
|
49 |
|
50 #if defined (HTTP_INTEGRATION) |
|
51 |
|
52 // for StartC32() |
|
53 #if !defined __C32COMM_H__ |
|
54 #include <c32comm.h> |
|
55 #endif |
|
56 |
|
57 #if !defined __IN_SOCK_H__ |
|
58 #include <in_sock.h> |
|
59 #endif |
|
60 |
|
61 #if defined (__WINS__) |
|
62 #define PDD_NAME _L("ECDRV") |
|
63 #else |
|
64 #define PDD_NAME _L("EUART1") |
|
65 #define PDD2_NAME _L("EUART2") |
|
66 #define PDD3_NAME _L("EUART3") |
|
67 #define PDD4_NAME _L("EUART4") |
|
68 #endif |
|
69 |
|
70 #define LDD_NAME _L("ECOMM") |
|
71 |
|
72 //---------------------------------------------------------------------------- |
|
73 // Integration Domain specific includes |
|
74 |
|
75 #include "CHTTPFamily.h" |
|
76 |
|
77 #endif |
|
78 |
|
79 //---------------------------------------------------------------------------- |
|
80 // create this (Console) ONLY if we're NOT being driven from the command line |
|
81 |
|
82 LOCAL_D CConsoleBase *Console; |
|
83 |
|
84 //---------------------------------------------------------------------------- |
|
85 // Global Defines for |
|
86 |
|
87 GLDEF_D TBool exitConsoleAtExit = ETrue; |
|
88 GLDEF_D TBool consoleRequired = EFalse; |
|
89 GLDEF_D TBool debugRequired = EFalse; |
|
90 GLDEF_D TInt sysError = KErrNone; |
|
91 TPtrC ScriptFilename; |
|
92 TBuf<256> Arguments; |
|
93 TInt nArgs; |
|
94 |
|
95 //---------------------------------------------------------------------------- |
|
96 // method defs |
|
97 |
|
98 LOCAL_C TInt ExecuteManagerL(void); |
|
99 LOCAL_C TInt CreateFrameworkCommandsL(CCmdFamily *); |
|
100 LOCAL_C void TestHarnessMainL(void); |
|
101 LOCAL_C void pressAnyKey(void); |
|
102 LOCAL_C void reportError(void); |
|
103 LOCAL_C void processCommandLine(void); |
|
104 |
|
105 //---------------------------------------------------------------------------- |
|
106 |
|
107 #if defined (HTTP_INTEGRATION) |
|
108 |
|
109 // specialist commands here... |
|
110 // ideally this is a method from a dynamically loaded DLL... |
|
111 |
|
112 LOCAL_C void InitCommsL(); |
|
113 LOCAL_C TInt CreateHTTPIntegrationCommands(CCmdFamily *); |
|
114 |
|
115 |
|
116 #endif |
|
117 |
|
118 //---------------------------------------------------------------------------- |
|
119 // Register the fundamental 'framework' commands |
|
120 |
|
121 LOCAL_C TInt CreateFrameworkCommandsL(CCmdFamily *aList) |
|
122 { |
|
123 aList->RegisterL(CCmdRemark::NewL(THA_KCmdRemark, THA_TxtCmdRemark)); |
|
124 aList->RegisterL(CCmdRemark::NewL(THA_KCmdComment, THA_TxtCmdComment)); |
|
125 |
|
126 aList->RegisterL(CCmdExit::NewL(THA_KCmdExit, THA_TxtCmdExit )); |
|
127 aList->RegisterL(CCmdExit::NewL(THA_KCmdExit, THA_TxtCmdQuit )); |
|
128 aList->RegisterL(CCmdExit::NewL(THA_KCmdExit, THA_TxtCmdStop )); |
|
129 |
|
130 aList->RegisterL(CCmdEchoMode::NewL( THA_KCmdEchoMode, THA_TxtCmdEchoMode)); |
|
131 |
|
132 aList->RegisterL(CCmdPause::NewL(THA_KCmdPause, THA_TxtCmdPause)); |
|
133 |
|
134 aList->RegisterL(CCmdHold::NewL(THA_KCmdHold, THA_TxtCmdHold)); |
|
135 aList->RegisterL(CCmdLogPath::NewL(THA_KCmdLogPath, THA_TxtCmdLogPath)); |
|
136 aList->RegisterL(CCmdLogFile::NewL(THA_KCmdLogFile, THA_TxtCmdLogFile)); |
|
137 aList->RegisterL(CCmdEndLog::NewL(THA_KCmdEndLog, THA_TxtCmdEndLog)); |
|
138 |
|
139 aList->RegisterL(CCmdSetPrompt::NewL(THA_KCmdSetPrompt, THA_TxtCmdSetPrompt)); |
|
140 aList->RegisterL(CCmdSetPath::NewL(THA_KCmdSetPath, THA_TxtCmdSetPath)); |
|
141 |
|
142 aList->RegisterL(CCmdCall::NewL(THA_KCmdCall, THA_TxtCmdCall, THA_TxtCmdCallHelp)); |
|
143 |
|
144 aList->RegisterL(CCmdReturn::NewL(THA_KCmdReturn, THA_TxtCmdReturn)); |
|
145 aList->RegisterL(CCmdCheckMode::NewL(THA_KCmdCheckMode, THA_TxtCmdCheckMode)); |
|
146 aList->RegisterL(CCmdPrint::NewL(THA_KCmdPrint, THA_TxtCmdPrint, THA_TxtCmdPrintHelp)); |
|
147 |
|
148 aList->RegisterL(CCmdDefine::NewL(THA_KCmdDefine, THA_TxtCmdDefine, THA_TxtCmdDefineHelp)); |
|
149 aList->RegisterL(CCmdListAll::NewL(THA_KCmdListAll, THA_TxtCmdListAll, THA_TxtCmdListAllHelp)); |
|
150 |
|
151 // new command: IF, ELSE, ENDIF |
|
152 aList->RegisterL(CCmdIf::NewL(THA_KCmdIf, THA_TxtCmdIf, THA_TxtCmdIfHelp)); |
|
153 aList->RegisterL(CCmdElse::NewL(THA_KCmdElse, THA_TxtCmdElse, THA_TxtCmdElseHelp)); |
|
154 aList->RegisterL(CCmdEndIf::NewL(THA_KCmdEndIf, THA_TxtCmdEndIf, THA_TxtCmdEndIfHelp)); |
|
155 |
|
156 // Register CASE and SELECT COMMANDS (TVi) |
|
157 aList->RegisterL(CCmdCase::NewL(ECase, KTxtCase)); |
|
158 aList->RegisterL(CCmdEndCase::NewL(EEndCase, KTxtEndCase)); |
|
159 aList->RegisterL(CCmdSelect::NewL(ECmdSelect, KTxtCmdSelect)); |
|
160 |
|
161 return KErrNone; |
|
162 } |
|
163 |
|
164 //---------------------------------------------------------------------------- |
|
165 |
|
166 #if defined (HTTP_INTEGRATION) |
|
167 |
|
168 //---------------------------------------------------------------------------- |
|
169 // provide any framework infrastructure configuration |
|
170 |
|
171 LOCAL_C void InitCommsL() |
|
172 { |
|
173 TInt ret = User::LoadPhysicalDevice(PDD_NAME); |
|
174 User::LeaveIfError(ret == KErrAlreadyExists ? KErrNone : ret); |
|
175 |
|
176 #ifndef __WINS__ |
|
177 ret = User::LoadPhysicalDevice(PDD2_NAME); |
|
178 ret = User::LoadPhysicalDevice(PDD3_NAME); |
|
179 ret = User::LoadPhysicalDevice(PDD4_NAME); |
|
180 #endif |
|
181 |
|
182 ret = User::LoadLogicalDevice(LDD_NAME); |
|
183 User::LeaveIfError(ret == KErrAlreadyExists?KErrNone:ret); |
|
184 ret = StartC32(); |
|
185 User::LeaveIfError(ret == KErrAlreadyExists?KErrNone:ret); |
|
186 } |
|
187 |
|
188 //---------------------------------------------------------------------------- |
|
189 // Register the fundamental 'framework' commands |
|
190 |
|
191 LOCAL_C TInt CreateHTTPIntegrationCommands(CCmdFamily *aList) |
|
192 { |
|
193 aList->RegisterL(CCmdConnect::NewL(THA_KHTTP_Connect, THA_TxtCmdConnect, THA_TxtCmdConnectHelp)); |
|
194 aList->RegisterL(CCmdDisconnect::NewL(THA_KHTTP_Disconnect, THA_TxtCmdDisconnect, THA_TxtCmdDisconnectHelp)); |
|
195 aList->RegisterL(CCmdTransaction::NewL(THA_KHTTP_Transaction, THA_TxtCmdTransaction, THA_TxtCmdTransactionHelp)); |
|
196 aList->RegisterL(CCmdEndTransaction::NewL(THA_KHTTP_EndTransaction, THA_TxtCmdEndTrans, THA_TxtCmdEndTransHelp)); |
|
197 aList->RegisterL(CCmdShowTransaction::NewL(THA_KHTTP_ShowTransaction, THA_TxtCmdShowTrans, THA_TxtCmdShowTransHelp)); |
|
198 |
|
199 return KErrNone; |
|
200 } |
|
201 |
|
202 #endif |
|
203 |
|
204 //---------------------------------------------------------------------------- |
|
205 // This is where it's at |
|
206 // |
|
207 // Create the scheduler, the Command Tree, Look for PlugIn Language DLL's etc |
|
208 // Offer Console *or* script processing |
|
209 |
|
210 LOCAL_C TInt ExecuteManagerL(void) |
|
211 { |
|
212 TInt StackObjects = 0; |
|
213 |
|
214 // Create scheduler etc |
|
215 CActiveScheduler *Scheduler = new (ELeave) CActiveScheduler; |
|
216 CleanupStack::PushL(Scheduler); |
|
217 ++StackObjects; |
|
218 |
|
219 // no problems, so install it |
|
220 CActiveScheduler::Install(Scheduler); |
|
221 |
|
222 if (Console) |
|
223 Console->Printf(KTHAWelcomeMessage); |
|
224 |
|
225 // create the Test Engine and get it cracking... |
|
226 CTEngine *Engine = CTEngine::NewLC(Console); |
|
227 ++StackObjects; |
|
228 |
|
229 // create command list and register |
|
230 |
|
231 CCmdFamily *Commands = CCmdFamily::NewLC(); |
|
232 ++StackObjects; |
|
233 |
|
234 if (Engine) |
|
235 { |
|
236 |
|
237 // we have a basic 'set' of framework commands that are applicable whatever the project |
|
238 // area. as a result these are 'static' |
|
239 CreateFrameworkCommandsL(Commands); |
|
240 |
|
241 // now determine if there are any app specific commands to add to 'Commands' |
|
242 // since this is the 'dynamic' part of the system. All the project commands are |
|
243 // to be supplied in a separate '.dll' which we load and append the commands. |
|
244 // e.g. we have a set of WAP framework commands |
|
245 // CreateWAPFrameworkCommandsL(Commands); |
|
246 |
|
247 #if defined (HTTP_INTEGRATION) |
|
248 |
|
249 InitCommsL(); |
|
250 |
|
251 // ideally do search and load of "dll's" |
|
252 CreateHTTPIntegrationCommands(Commands); |
|
253 |
|
254 #endif |
|
255 |
|
256 // now register the command list to the Test Harness Engine |
|
257 Engine->SetCmdFamily(Commands); |
|
258 |
|
259 // Set our own prompt for the console |
|
260 if (Console) |
|
261 (void) Engine->SetPrompt(THA_CommandPrompt); |
|
262 |
|
263 if (nArgs > 1) |
|
264 sysError = Engine->Run(ScriptFilename, Arguments); |
|
265 else |
|
266 { |
|
267 sysError = KErrNone; |
|
268 Engine->Run(); |
|
269 } |
|
270 } |
|
271 else |
|
272 sysError = KErrUnabletoCreateTestEngine; |
|
273 |
|
274 // and start it! |
|
275 if (sysError != KErrNone) |
|
276 // reset the scheduler to run 'as interactive' |
|
277 Engine->Run(); |
|
278 |
|
279 // kick off the scheduler... |
|
280 CActiveScheduler::Start(); |
|
281 |
|
282 // finish Console |
|
283 |
|
284 CleanupStack::PopAndDestroy(StackObjects); |
|
285 |
|
286 // unnecessary (since global!) |
|
287 return sysError; |
|
288 } |
|
289 |
|
290 //---------------------------------------------------------------------------- |
|
291 // must have some command lines. |
|
292 // <scriptname[.ths]> must be first parameter |
|
293 // -c = Console required once script executed |
|
294 // -d = debug mode on (log to Console as well) |
|
295 // read the command line |
|
296 // If we've got a script provided, then do not create a Console object |
|
297 // unless we have a -d (for debug) mode command |
|
298 |
|
299 LOCAL_C void processCommandLine(void) |
|
300 { |
|
301 TInt iIgnore; |
|
302 CCommandLineArguments *cmdArgs = CCommandLineArguments::NewLC(); |
|
303 |
|
304 nArgs = cmdArgs->Count(); |
|
305 iIgnore = nArgs; |
|
306 if (nArgs == 1) // arg(0) is '.exe' name (arg==1) |
|
307 // no args (apart from Exename) means assume Interactive (Console) session required |
|
308 consoleRequired = ETrue; |
|
309 |
|
310 else |
|
311 { |
|
312 // get the Command File name - why? |
|
313 TPtrC ExeFilename; |
|
314 ExeFilename.Set(cmdArgs->Arg(0)); |
|
315 |
|
316 // construct call arguments |
|
317 for (TInt i = 1; i < nArgs; ++i) |
|
318 { |
|
319 // look for command/control flags |
|
320 TInt Pos = cmdArgs->Arg(i).Find(KControlFlagSeparator); |
|
321 if (Pos != KErrNotFound) |
|
322 { |
|
323 // valid argument (i.e. has a - in front) but is it supported? |
|
324 // require a Console? (Console created and displayed once script |
|
325 if (cmdArgs->Arg(i).Find(KControlFlagRequiredScript) != KErrNotFound) |
|
326 { |
|
327 // remove the -s from the filename and do not add this to the |
|
328 // argument list |
|
329 //ScriptFilename.Set(cmdArgs->Arg(i).Mid(2)); |
|
330 ScriptFilename.Set(cmdArgs->Arg(i).Mid(KControlFlagRequiredScript().Length())); |
|
331 sysError = KSysCmdParameter; |
|
332 } |
|
333 |
|
334 // require a Console? (Console created and displayed once script |
|
335 else if (cmdArgs->Arg(i).Find(KControlFlagRequireConsole) != KErrNotFound) |
|
336 { |
|
337 consoleRequired = ETrue; |
|
338 sysError = KSysCmdParameter; |
|
339 --iIgnore; |
|
340 } |
|
341 |
|
342 else if (cmdArgs->Arg(i).Find(KControlFlagDebugViaConsole) != KErrNotFound) |
|
343 { |
|
344 debugRequired = ETrue; |
|
345 consoleRequired = ETrue; |
|
346 sysError = KSysCmdParameter; |
|
347 --iIgnore; |
|
348 } |
|
349 |
|
350 else |
|
351 sysError = KErrCommandFlagNotDefined; |
|
352 } |
|
353 |
|
354 // get the args - use spaces to separate and 'fill out' |
|
355 Arguments.Append(_L(" ")); // put a space in between them! |
|
356 if (sysError == KAppendParameter) |
|
357 Arguments.Append(cmdArgs->Arg(i)); // copy in the argument |
|
358 |
|
359 } |
|
360 } |
|
361 |
|
362 // update the num args to those we're really interested in |
|
363 nArgs = iIgnore; |
|
364 |
|
365 // clear the error |
|
366 sysError = KErrNone; |
|
367 |
|
368 // no longer need them (args) so delete them! |
|
369 CleanupStack::PopAndDestroy(); |
|
370 } |
|
371 |
|
372 //---------------------------------------------------------------------------- |
|
373 // Application Start Point |
|
374 // Integration Test Harness |
|
375 // |
|
376 // The application can be passed a parameter <scriptname> which is autoexecuted |
|
377 |
|
378 LOCAL_C void TestHarnessMainL(void) |
|
379 { |
|
380 TInt StackObjects = 0; |
|
381 |
|
382 // see what's cooking on the command line... |
|
383 processCommandLine(); |
|
384 |
|
385 // create the Console if required and title it |
|
386 Console = Console::NewL(_L("GT0149 Integration Test Harness"), TSize(KConsFullScreen, KConsFullScreen)); |
|
387 CleanupStack::PushL(Console); |
|
388 ++StackObjects; |
|
389 |
|
390 // execute the bit we want |
|
391 |
|
392 if (sysError == KErrNone) |
|
393 TRAP(sysError, ExecuteManagerL()); |
|
394 |
|
395 // report any errors |
|
396 if (sysError != KErrNone) |
|
397 { |
|
398 reportError(); |
|
399 if (nArgs != 1) // arg(0) is '.exe' name (arg==1) |
|
400 pressAnyKey(); |
|
401 } |
|
402 |
|
403 // inform user we're closing... |
|
404 if (Console) |
|
405 { |
|
406 Console->Printf(_L("\r\n[press any key]")); |
|
407 |
|
408 // get the keypress |
|
409 Console->Getch(); |
|
410 } |
|
411 |
|
412 // finish Console |
|
413 if (StackObjects > 0) |
|
414 CleanupStack::PopAndDestroy(StackObjects); // 2=Console & cmdArgs |
|
415 } |
|
416 |
|
417 //---------------------------------------------------------------------------- |
|
418 // simple log error message |
|
419 |
|
420 LOCAL_C void reportError() |
|
421 { |
|
422 if (Console) |
|
423 { |
|
424 Console->Printf(_L("\r\nThe following error code was returned: %d"), sysError); |
|
425 Console->Printf(_L("\r\nPlease report this to the appropriate project team")); |
|
426 } |
|
427 } |
|
428 |
|
429 //---------------------------------------------------------------------------- |
|
430 |
|
431 LOCAL_C void pressAnyKey() |
|
432 { |
|
433 if (Console) |
|
434 { |
|
435 Console->Printf(_L("\r\n[Press any key]")); |
|
436 Console->Getch(); |
|
437 Console->Printf(_L("\n")); |
|
438 } |
|
439 } |
|
440 |
|
441 //---------------------------------------------------------------------------- |
|
442 |
|
443 GLDEF_C TInt E32Main() |
|
444 // Main program - run the Test Harness within a TRAP harness, reporting any errors that |
|
445 // occur via the panic mechanism. Test for memory leaks using heap marking. |
|
446 { |
|
447 __UHEAP_MARK; |
|
448 CTrapCleanup* tc = CTrapCleanup::New(); |
|
449 |
|
450 TRAPD(err, TestHarnessMainL()); |
|
451 if (err!=KErrNone) |
|
452 User::Panic(_L("\r\nIntegration Test Harness failed with error code: %i"), err); |
|
453 |
|
454 delete tc; |
|
455 |
|
456 __UHEAP_MARKEND; |
|
457 return KErrNone; |
|
458 } |
|
459 |
|
460 //---------------------------------------------------------------------------- |
|
461 |
|
462 |