messagingfw/wappushfw/tpushscriptbased/t_utils/httptestutils.h
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 2007-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 //
       
    15 
       
    16 #if !defined(__HTTPTESTUTILS_H__)
       
    17 #define __HTTPTESTUTILS_H__
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <e32test.h>
       
    21 #include <f32file.h>
       
    22 
       
    23 
       
    24 #include <http/framework/httplogger.h>
       
    25 
       
    26 //	Constants
       
    27 const TUid KUidWapTestUtils = {0x10005188};
       
    28 const TInt KMaxUserEntrySize = 128;
       
    29 
       
    30 //Test Harness Logging
       
    31 
       
    32 #define KLogsDir				_L("c:\\logs\\")
       
    33 #define KTestHeader				_L("Test Results")
       
    34 #define KTestStarting			_L("Test %d Starting")
       
    35 #define KTestStartingWithDesc	_L("Test %d Starting (%S)")
       
    36 #define KNextTestStepWithDesc	_L("Test %d Step %d (%S)")
       
    37 #define KTestPassed				_L("Test %d OK")
       
    38 #define KTestFailed				_L("Test %d FAILED (error = %d)")
       
    39 #define KTestHarnessCompleted	_L("Tests Completed Ok")
       
    40 #define KTestHarnessFailed		_L("Test FAILED (%d failed test(s))")
       
    41 #define KTestFailInfo			_L("Test %d : %S failed with Error %d") 
       
    42 #define KTestCommentPrepend		_L("\t")
       
    43 #define KRTestFailed			_L("RTEST: FAIL : Failed with error %d\n")
       
    44 
       
    45 //forwd decl
       
    46 class CHttpTestBase;
       
    47 
       
    48 //##ModelId=3C4C4C420207
       
    49 class CHTTPTestUtils : public CBase, public TDesOverflow
       
    50 //
       
    51 //	Test harness providing logging features
       
    52 	{
       
    53 public:
       
    54 	//##ModelId=3C4C4C430136
       
    55 	IMPORT_C static CHTTPTestUtils* NewLC(const TDesC& aTitle);
       
    56 	//##ModelId=3C4C4C43012C
       
    57 	IMPORT_C static CHTTPTestUtils* NewL(const TDesC& aTitle);
       
    58 	//##ModelId=3C4C4C430122
       
    59 	~CHTTPTestUtils();
       
    60 	//##ModelId=3C4C4C430118
       
    61 	IMPORT_C void JustStartTestL(const TDesC& aName);
       
    62 	//##ModelId=3C4C4C430104
       
    63 	IMPORT_C void StartTestL(const TDesC& aName);
       
    64 	//##ModelId=3C4C4C4300FA
       
    65 	IMPORT_C void JustEndTest();
       
    66 	//##ModelId=3C4C4C4300E6
       
    67 	IMPORT_C void NextStep(const TDesC& aStepName);
       
    68 	//##ModelId=3C4C4C4300DC
       
    69 	IMPORT_C void EndTest(TInt aErrorCode);
       
    70 	//##ModelId=3C4C4C4300BE
       
    71 	IMPORT_C void LogIt(TRefByValue<const TDesC> aFmt, ...);
       
    72 	//##ModelId=3C4C4C43008D
       
    73 	IMPORT_C void operator()(TInt aResult,TInt aLineNum);
       
    74 	//##ModelId=3C4C4C4300B4
       
    75 	IMPORT_C void operator()(TInt aResult);
       
    76 	//##ModelId=3C4C4C43008C
       
    77 	IMPORT_C void PressAnyKey();
       
    78 	//##ModelId=3C4C4C43006E
       
    79 	IMPORT_C void DumpData(const TDesC8& aData, TBool logIt = EFalse);
       
    80 	//##ModelId=3C4C4C430050
       
    81 	IMPORT_C void GetAnEntry(const TDesC & ourPrompt, TDes & currentstring);
       
    82 	//##ModelId=3C4C4C430032
       
    83 	IMPORT_C TInt GetSelection(const TDesC& ourPrompt, const TDesC& validChoices);
       
    84 	//##ModelId=3C4C4C43001E
       
    85 	IMPORT_C void SetScript(RFile& scriptFile);
       
    86 	//##ModelId=3C4C4C43000B
       
    87 	inline void DoResourceLeakTest(TBool aValue);
       
    88 	//##ModelId=3C4C4C43000A
       
    89 	inline RTest& Test();
       
    90 
       
    91 	//##ModelId=3C4C4C4203DF
       
    92 	inline static void DefaultLogFileName(TDes& aFileName);
       
    93 
       
    94 	//##ModelId=3C4C4C4203DE
       
    95 	IMPORT_C static void InitCommsL();
       
    96 	//##ModelId=3C4C4C4203D4
       
    97 	IMPORT_C static void HoldOpenConnectionL();
       
    98 	//##ModelId=3C4C4C4203CB
       
    99 	IMPORT_C static void ReleaseConnectionL();
       
   100 
       
   101 	//##ModelId=3C4C4C4203CA
       
   102 	inline TBool IsSilent() const;
       
   103 	//##ModelId=3C4C4C4203B6
       
   104 	inline void SetSilent(TBool aSilent);
       
   105 
       
   106 	//##ModelId=3C4C4C42038E
       
   107 	IMPORT_C TInt ResolveFile(const TDesC& aComponent, const TDesC& aFileName, TParse& aParseOut);
       
   108 	//##ModelId=3C4C4C42037A
       
   109 	IMPORT_C HBufC8* ReadFileLC(const TDesC& aFile);
       
   110 
       
   111 private:	// Methods from TDesOverflow
       
   112 
       
   113 	IMPORT_C virtual void Overflow(TDes& aDes);
       
   114 
       
   115 private:
       
   116 	//##ModelId=3C4C4C420366
       
   117 	CHTTPTestUtils(const TDesC& aTitle);
       
   118 	//##ModelId=3C4C4C420352
       
   119 	void ConstructL(const TDesC& aTitle);
       
   120 	//##ModelId=3C4C4C420348
       
   121 	void Panic(TInt aPanic);
       
   122 	//##ModelId=3C4C4C42033E
       
   123 	void TestHarnessFailed();
       
   124 	//##ModelId=3C4C4C420335
       
   125 	void TestHarnessComplete();
       
   126 	//##ModelId=3C4C4C420334
       
   127 	void ResourceLeakTest();
       
   128 	//##ModelId=3C4C4C420320
       
   129 	inline void WriteComment(const TDesC& aComment);
       
   130 	//##ModelId=3C4C4C42030C
       
   131 	TInt ReadLineFromScript(TDes& aBuffer);
       
   132 
       
   133 	//##ModelId=3C4C4C420302
       
   134 	void CreateLogFiles(const TDesC& aTestName);
       
   135 
       
   136 	void Print(const TDesC& aDescriptor);
       
   137 
       
   138 
       
   139 private:
       
   140 	//	Helper class to store failed tests
       
   141 	class CTestInfo;
       
   142 	enum TPanicCode
       
   143 		{
       
   144 		EBadStartTest,
       
   145 		EBadEndTest,
       
   146 		EBadCLogPtr
       
   147 		};
       
   148 private:
       
   149 	//##ModelId=3C4C4C4202F8
       
   150 	RTest iTest;
       
   151 	//##ModelId=3C4C4C4202E6
       
   152 	RFs iFs;
       
   153 	//##ModelId=3C4C4C4202D0
       
   154 	RFile* iScriptFile;
       
   155 	__DECLARE_LOG	
       
   156 	//##ModelId=3C4C4C4202BE
       
   157 	RFileLogger iTestSummaryLogger;
       
   158 	//##ModelId=3C4C4C4202B2
       
   159 	TInt iTestCount;
       
   160 	//##ModelId=3C4C4C42029F
       
   161 	CArrayPtrFlat<CTestInfo>* iFailedTests;
       
   162 	//##ModelId=3C4C4C42027F
       
   163 	TTime iStartTime;
       
   164 	//##ModelId=3C4C4C420263
       
   165 	TBool iCanStartTest;
       
   166 	//##ModelId=3C4C4C420259
       
   167 	TInt iStepNumber;
       
   168 	//##ModelId=3C4C4C42024F
       
   169 	TInt iStartHandleCount;
       
   170 	//##ModelId=3C4C4C420243
       
   171 	TBool iDoResourceLeakTest;
       
   172 	//##ModelId=3C4C4C420239
       
   173 	TBool iScriptRunning;
       
   174 	//##ModelId=3C4C4C420227
       
   175 	TBool iSilent; // if true logs only to file and not to console
       
   176 	//##ModelId=3C4C4C42021E
       
   177 	CTestInfo* iCurrentTest;
       
   178 	};
       
   179 
       
   180 class CHTTPTestUtils::CTestInfo : public CBase
       
   181 //
       
   182 //	Holds test number and name
       
   183 	{
       
   184 public:
       
   185 	static CTestInfo* NewLC(const TDesC& aName, TInt aNumber, TInt aErrorCode);
       
   186 	static CTestInfo* NewL(const TDesC& aName, TInt aNumber, TInt aErrorCode);
       
   187 	~CTestInfo();
       
   188 
       
   189 	void SetNameL(const TDesC& aName);
       
   190 	void SetNumber(TInt aNumber);
       
   191 	void SetErrorCode(TInt aErrorCode);
       
   192 
       
   193 	inline TPtr Name() const;
       
   194 	inline TInt Number() const;
       
   195 	inline TInt ErrorCode() const;
       
   196 private:
       
   197 	CTestInfo();
       
   198 	void ConstructL(const TDesC& aName, TInt aNumber, TInt aErrorCode);
       
   199 private:
       
   200 	HBufC* iName;
       
   201 	TInt iNumber;
       
   202 	TInt iErrorCode;
       
   203 	};
       
   204 
       
   205 #include "httptestutils.inl"
       
   206 
       
   207 #endif	//	__HTTPTESTUTILS_H__