applayerprotocols/httptransportfw/Test/t_utils/httptestutils.h
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2000-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 	IMPORT_C void CleanupFailedTestsArray ();
       
   112 	IMPORT_C void CreateFailedTestsArrayL ();
       
   113 private:	// Methods from TDesOverflow
       
   114 
       
   115 	IMPORT_C virtual void Overflow(TDes& aDes);
       
   116 
       
   117 private:
       
   118 	//##ModelId=3C4C4C420366
       
   119 	CHTTPTestUtils(const TDesC& aTitle);
       
   120 	//##ModelId=3C4C4C420352
       
   121 	void ConstructL(const TDesC& aTitle);
       
   122 	//##ModelId=3C4C4C420348
       
   123 	void Panic(TInt aPanic);
       
   124 	//##ModelId=3C4C4C42033E
       
   125 	void TestHarnessFailed();
       
   126 	//##ModelId=3C4C4C420335
       
   127 	void TestHarnessComplete();
       
   128 	//##ModelId=3C4C4C420334
       
   129 	void ResourceLeakTest();
       
   130 	//##ModelId=3C4C4C420320
       
   131 	inline void WriteComment(const TDesC& aComment);
       
   132 	//##ModelId=3C4C4C42030C
       
   133 	TInt ReadLineFromScript(TDes& aBuffer);
       
   134 
       
   135 	//##ModelId=3C4C4C420302
       
   136 	void CreateLogFiles(const TDesC& aTestName);
       
   137 
       
   138 	void Print(const TDesC& aDescriptor);
       
   139 
       
   140 
       
   141 private:
       
   142 	//	Helper class to store failed tests
       
   143 	class CTestInfo;
       
   144 	enum TPanicCode
       
   145 		{
       
   146 		EBadStartTest,
       
   147 		EBadEndTest,
       
   148 		EBadCLogPtr
       
   149 		};
       
   150 private:
       
   151 	//##ModelId=3C4C4C4202F8
       
   152 	RTest iTest;
       
   153 	//##ModelId=3C4C4C4202E6
       
   154 	RFs iFs;
       
   155 	//##ModelId=3C4C4C4202D0
       
   156 	RFile* iScriptFile;
       
   157 	__DECLARE_LOG	
       
   158 	//##ModelId=3C4C4C4202BE
       
   159 	RFileLogger iTestSummaryLogger;
       
   160 	//##ModelId=3C4C4C4202B2
       
   161 	TInt iTestCount;
       
   162 	//##ModelId=3C4C4C42029F
       
   163 	CArrayPtrFlat<CTestInfo>* iFailedTests;
       
   164 	//##ModelId=3C4C4C42027F
       
   165 	TTime iStartTime;
       
   166 	//##ModelId=3C4C4C420263
       
   167 	TBool iCanStartTest;
       
   168 	//##ModelId=3C4C4C420259
       
   169 	TInt iStepNumber;
       
   170 	//##ModelId=3C4C4C42024F
       
   171 	TInt iStartHandleCount;
       
   172 	//##ModelId=3C4C4C420243
       
   173 	TBool iDoResourceLeakTest;
       
   174 	//##ModelId=3C4C4C420239
       
   175 	TBool iScriptRunning;
       
   176 	//##ModelId=3C4C4C420227
       
   177 	TBool iSilent; // if true logs only to file and not to console
       
   178 	//##ModelId=3C4C4C42021E
       
   179 	CTestInfo* iCurrentTest;
       
   180 	};
       
   181 
       
   182 class CHTTPTestUtils::CTestInfo : public CBase
       
   183 //
       
   184 //	Holds test number and name
       
   185 	{
       
   186 public:
       
   187 	static CTestInfo* NewLC(const TDesC& aName, TInt aNumber, TInt aErrorCode);
       
   188 	static CTestInfo* NewL(const TDesC& aName, TInt aNumber, TInt aErrorCode);
       
   189 	~CTestInfo();
       
   190 
       
   191 	void SetNameL(const TDesC& aName);
       
   192 	void SetNumber(TInt aNumber);
       
   193 	void SetErrorCode(TInt aErrorCode);
       
   194 
       
   195 	inline TPtr Name() const;
       
   196 	inline TInt Number() const;
       
   197 	inline TInt ErrorCode() const;
       
   198 private:
       
   199 	CTestInfo();
       
   200 	void ConstructL(const TDesC& aName, TInt aNumber, TInt aErrorCode);
       
   201 private:
       
   202 	HBufC* iName;
       
   203 	TInt iNumber;
       
   204 	TInt iErrorCode;
       
   205 	};
       
   206 
       
   207 #include "httptestutils.inl"
       
   208 
       
   209 #endif	//	__HTTPTESTUTILS_H__