applayerprotocols/httptransportfw/Test/T_HttpIntegration/TEngine.h
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     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 // 
       
    16 //
       
    17 
       
    18 #include <e32base.h>
       
    19 #include <e32cons.h>
       
    20 #include <f32file.h>
       
    21 
       
    22 //-----------------------------------------------------------------------------
       
    23 
       
    24 #ifndef __TENGINE_H__
       
    25 #define __TENGINE_H__
       
    26 
       
    27 //-----------------------------------------------------------------------------
       
    28 
       
    29 #include "GT0149.h"
       
    30 #include "ECommandIDs.h"
       
    31 #include "CPile.h"	
       
    32 #include "CCmdFamily.h"		
       
    33 #include "CCmdFile.h"			
       
    34 #include "CLogFile.h"			
       
    35 #include "CIFControl.h"			
       
    36 #include "CConsoleReader.h"
       
    37 #include "CCatalogue.h"
       
    38 #include "CObjCatalogue.h"
       
    39 #include "CCmdBase.h"
       
    40 
       
    41 //-----------------------------------------------------------------------------
       
    42 //	Forward declare Templated Classes
       
    43 
       
    44 template<class T> class CPile;
       
    45 
       
    46 #if !defined(TEMPLATED_CATALOGUE)
       
    47 
       
    48 class CCatalogue;
       
    49 
       
    50 #else
       
    51 
       
    52 template<class T> class CCatalogue;
       
    53 
       
    54 #endif
       
    55 
       
    56 //-----------------------------------------------------------------------------
       
    57 
       
    58 class   TTestMachineOverflow : public TDes16Overflow
       
    59 {
       
    60 public:
       
    61 	virtual void Overflow( TDes16& aDes );
       
    62 };
       
    63 
       
    64 //-----------------------------------------------------------------------------
       
    65 
       
    66 class CTEngine : public CActive
       
    67 {
       
    68 public:     // Constructors and destructors
       
    69 
       
    70 	// Constructors with and without console.
       
    71 	static CTEngine* NewL ( CConsoleBase* aConsole = NULL );
       
    72 	static CTEngine* NewLC( CConsoleBase* aConsole = NULL );
       
    73 
       
    74 	//  Destructor.
       
    75 	~CTEngine();
       
    76 
       
    77 private:    // Constructors and destructors
       
    78 
       
    79 	// Private constructor.
       
    80 	void ConstructL();
       
    81 
       
    82 	// Default constructor is not there.
       
    83 	CTEngine(CConsoleBase *aConsole);
       
    84 
       
    85 public:     // New functions
       
    86 
       
    87 	// Set command family (the known commands).
       
    88 	void SetCmdFamily(CCmdFamily *);
       
    89 
       
    90 	// Console is enabled?
       
    91 	TBool ConsoleEnabled();
       
    92 
       
    93 	// Disable console i/o.
       
    94 	void DisableConsole();
       
    95 
       
    96 	// Enable console i/o.
       
    97 	void EnableConsole();
       
    98 
       
    99 	// Get console, NULL if is not available.
       
   100 	CConsoleBase *Console() const;
       
   101 
       
   102 	// Unformatted Write to console (if enabled).
       
   103 	void Write  (const TDesC &);
       
   104 	void Writeln(const TDesC &);
       
   105 	void Writeln(); // new-line
       
   106 
       
   107 	// Formatted Printf to console (if enabled).
       
   108 	void Printf  (TRefByValue<const TDesC> aFmt, ...);
       
   109 	void Printf  (TRefByValue<const TDesC> aFmt, VA_LIST& aList);
       
   110 	void Printfln(TRefByValue<const TDesC> aFmt, ...);
       
   111 	void Printfln(TRefByValue<const TDesC> aFmt, VA_LIST& aList);
       
   112 
       
   113 	// Wait for a key press
       
   114 	void Pause(const TDesC& aPrompt);
       
   115 
       
   116 	// Hold for an interval
       
   117 	void Hold(TTimeIntervalMicroSeconds32 aInterval);
       
   118 
       
   119 	// Set and Get the command file path. SetCmdPath returns
       
   120 	// KErrArgument for illegal aPath param.
       
   121 	TInt SetCmdPath(const TDesC &);
       
   122 	TPtrC CmdPath() const;
       
   123 
       
   124 	TPtrC FileName() const;
       
   125 
       
   126 	// Call command file and Get the present command file.
       
   127 	TInt CallCmdFile(const TDesC &);
       
   128 	TInt CallCmdFile(const TDesC &, const TDesC &);
       
   129 	CCmdFile *CmdFile();
       
   130 
       
   131 	// Close the present command file or close them all.
       
   132 	TInt CloseCmdFile();
       
   133 	void CloseCmdFiles();
       
   134 
       
   135 	// Set and Get the log file path. SetLogPath returns
       
   136 	// KErrArgument for illegal aPath param.
       
   137 	TInt SetLogPath(const TDesC &);
       
   138 	TPtrC LogPath() const;
       
   139 
       
   140 	// Open a log file and Get the present log file.
       
   141 	TInt OpenLogFile(const TDesC &);
       
   142 	CLogFile *LogFile();
       
   143 
       
   144 	// Close the present log file or close them all.
       
   145 	TInt CloseLogFile();
       
   146 	void CloseLogFiles();
       
   147 
       
   148 	// Unformatted Write to the log (if there's one).
       
   149 	void LogWrite  (const TDesC &);
       
   150 	void LogWriteln(const TDesC &);
       
   151 	void LogWriteln();
       
   152 
       
   153 	// Formatted Printf to the log (if there's one).
       
   154 	void LogPrintf  (TRefByValue<const TDesC> aFmt, ... );
       
   155 	void LogPrintf  (TRefByValue<const TDesC> aFmt, VA_LIST &);
       
   156 	void LogPrintfln(TRefByValue<const TDesC> aFmt, ... );
       
   157 	void LogPrintfln(TRefByValue<const TDesC> aFmt, VA_LIST &);
       
   158 
       
   159 	// Standard message output. A message you write goes to the log
       
   160 	// if there is one open. A message is printed to the display as
       
   161 	// well, except when running a command file with echo mode off.
       
   162 	void MsgWrite   (const TDesC& aText);
       
   163 	void MsgWriteln (const TDesC& aText);
       
   164 	void MsgWriteln ();
       
   165 	void MsgPrintf  (TRefByValue<const TDesC> aFmt, ...);
       
   166 	void MsgPrintf  (TRefByValue<const TDesC> aFmt, VA_LIST& aList);
       
   167 	void MsgPrintfln(TRefByValue<const TDesC> aFmt, ...);
       
   168 	void MsgPrintfln(TRefByValue<const TDesC> aFmt, VA_LIST& aList);
       
   169 
       
   170 	// Set and Get the command Prompt.
       
   171 	TInt SetPrompt(const TDesC &aPrompt);
       
   172 	TPtrC Prompt() const;
       
   173 
       
   174 	// Run commands from the console.
       
   175 	void Run();
       
   176 
       
   177 	//	Run with just the file name (no args)
       
   178 	TInt Run(const TDesC &);
       
   179 
       
   180 	//	Run with the file name and args
       
   181 	TInt Run(const TDesC &, const TDesC &);
       
   182 
       
   183 	// Stop the test engine.
       
   184 	void Terminate();  // Terminate command files and log files.
       
   185 	void StopEngine(); // Terminate and stop i.e. exit test run
       
   186 	TBool Stopped();    // Stop has been raised?
       
   187 
       
   188 	// Set and Get Echo mode On/Off switch.
       
   189 	void SetEchoMode(const TBool & = ETrue);
       
   190 	TBool EchoMode();
       
   191 
       
   192 	// Get the defines.
       
   193 	#if !defined(TEMPLATED_CATALOGUE)
       
   194 		CCatalogue *Defines();
       
   195 
       
   196 		CObjCatalogue *Domains() const {return iDomain;}
       
   197 		
       
   198 	#else
       
   199 		CPile<CLabeledText> *Defines();
       
   200 	#endif
       
   201 
       
   202 	// Complete the asynch request
       
   203 	void CompleteRequest();
       
   204 
       
   205 	TInt SetFileName(const TDesC &aName, RFile &aReqFile) ;
       
   206 
       
   207 	void GetUserInput(const TDesC &, TDes &);
       
   208 	void DumpData(const TDesC8 &, const TBool & = ETrue);
       
   209 
       
   210 	TBool Log(void) { return iLogActivity; }
       
   211 
       
   212 	void SetResultDefine(TInt aValue);
       
   213 	void SetResultDefine (const TDesC& aDefineTxt, TInt aValue);
       
   214 	void SetErrorDefine(TInt aValue);
       
   215 	void SetErrorDefine (const TDesC& aDefineTxt, TInt aValue);
       
   216 	void DeleteResultDefine (const TDesC& aDefineTxt);
       
   217 	void DeleteErrorDefine (const TDesC& aDefineTxt);
       
   218 
       
   219 	void SetShowCmdLine(const TBool &aValue) { iShowCmdLine = aValue; }
       
   220 	TBool GetShowCmdLine(void) { return iShowCmdLine; }
       
   221 
       
   222 	TPtrC GetDefine(const TDesC &) const;
       
   223 
       
   224 	//----------------------------------------------------------------
       
   225 	//	helper methods for IfMode
       
   226 
       
   227 	CIFControl::TIFMode GetIfMode();
       
   228 	void SetIfMode(const CIFControl::TIFMode &);
       
   229 	CIFControl::TIFProcessing GetIfState();
       
   230 	void SetIfState(const CIFControl::TIFProcessing &);
       
   231 	void IfL(const CIFControl::TIFMode &, const TBool &, const CIFControl::TIFProcessing &);
       
   232 	void EndIf(); 
       
   233 	void UpdateIFState(const CIFControl::TIFMode &);
       
   234 
       
   235 //-----------------------------------------------------------------------------
       
   236 
       
   237 private:
       
   238 
       
   239 	// Read command line (iCmdline).
       
   240 	TInt ReadCmdline(TBool aConsole = ETrue);
       
   241 	TInt ReadCmdFile(); // from command file
       
   242 	TInt ReadConsole(); // from console
       
   243 
       
   244 	// Make the command (iCommand) to obey. Copies the command
       
   245 	// line (iCmdline) to iCommand buffer and expands the tags
       
   246 	// to their defined values.
       
   247 	TInt MakeCommand();
       
   248 
       
   249 	// Obey the command (iCommand).
       
   250 	TInt ObeyCommandL();
       
   251 
       
   252 	// Do command tags: expands tags to values.
       
   253 	TBool DoTags();
       
   254 
       
   255 	//	IF Management support
       
   256 	TBool DetermineStepover(CCmdBase *);
       
   257 
       
   258 private:	// Methods from CActive
       
   259 
       
   260 	virtual void RunL();
       
   261 	virtual void DoCancel();
       
   262 
       
   263 private:	// Enums
       
   264 
       
   265 	enum TEngineFilePanics
       
   266 		{
       
   267 		EBufferPanic,
       
   268 		EBufferNotAllocated,
       
   269 		EInvalidFileSizeError
       
   270 		};
       
   271 
       
   272 	enum TEngineState
       
   273 		{
       
   274 		EIdle				= 0,
       
   275 		EStopping,
       
   276 		EGetNextCmd,
       
   277 		EParseCurrentCmd,
       
   278 		ERunCurrentCmd
       
   279 		};
       
   280 
       
   281 private:    // Data
       
   282 
       
   283 	// For filename parsing.
       
   284 	TParse iParse;
       
   285 
       
   286 	//	for Displaying the command line or CmdLine (non translated version)
       
   287 	TBool iShowCmdLine;
       
   288 
       
   289 	// Run control.
       
   290 	TBool iStopped;							// test run stopped
       
   291 	TBool iEchoMode;            // echo mode On/Off
       
   292 
       
   293 	//	need to have a stack of IF structs so that we can process
       
   294 	//	nested if cases.
       
   295 	CPile<CIFControl>	*iIFPile;     // cmd file pile
       
   296 	
       
   297 	// Overflow handler.
       
   298 	TTestMachineOverflow iOverflow;
       
   299 
       
   300 	// State machine state
       
   301 	TEngineState iState;
       
   302 
       
   303 	// Active object that gets line input
       
   304 	CConsoleReader* iConsoleReader;
       
   305 
       
   306 	// Timer object
       
   307 	RTimer iTimer;
       
   308 
       
   309 	//	Timestamp for commands (and logging)
       
   310 	TTime iTimeStamp;
       
   311 
       
   312 	// Command family.
       
   313 	CCmdFamily* iCmdFamily;     // the commands
       
   314 
       
   315 	// Command buffers:
       
   316 	TBuf<256> iCmdline;        // command line
       
   317 	TBuf<1024> iCommand;        // full command
       
   318 
       
   319 	// Command prompt.
       
   320 	TBuf<16> iPrompt;           // prompt
       
   321 
       
   322 	// Console information.
       
   323 	CConsoleBase	*iConsole;     // console
       
   324 	TBool iConsoleEnabled;      // enabled?
       
   325 	TBuf<1024> iPrintBuf;       // formatted...
       
   326 
       
   327 	// The command files.
       
   328 	CCmdFile *iCmdFile;     // cmd file now!
       
   329 	CPile<CCmdFile>	*iCmdPile;     // cmd file pile
       
   330 	TFileName     iCmdPath;     // cmd file path
       
   331 
       
   332 	// The log files.
       
   333 	TFileName     iLogPath;     // log file path
       
   334 	CLogFile			*iLogFile;     // log file now
       
   335 	CPile<CLogFile>	*iLogPile;     // log file pile
       
   336 
       
   337 	// Catalog of the tag and call argument defines.
       
   338 	// Get the defines.
       
   339 	#if !defined(TEMPLATED_CATALOGUE)
       
   340 		CCatalogue *iDefines;
       
   341 
       
   342 	#else
       
   343 		CPile<CLabeledText>	*iDefines;
       
   344 	#endif
       
   345 
       
   346 	//	need to have access to a generic cat or pile
       
   347 	//	of (TAny *) which can be cast into pointers
       
   348 	//	for our domain specific lists (e.g. RHTTPSession)
       
   349 	//	Object Collection for use as/when by domain tools
       
   350 	CObjCatalogue *iDomain;
       
   351 
       
   352 	//	File Management
       
   353 	//	In some cases access to local files is useful.
       
   354 	//	as a result, make the services globally accessible from the TestEngine
       
   355 	RFs iFileServer;
       
   356 	TFileName iFileName;
       
   357 
       
   358 	TBool iLogActivity;
       
   359 };
       
   360 
       
   361 
       
   362 #endif  // __TENGINE_H__
       
   363         
       
   364 //-----------------------------------------------------------------------------
       
   365 // End of File
       
   366 //-----------------------------------------------------------------------------