applayerprotocols/wapbase/inc/WapTestUtils.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(__WAPTESTUTILS_H__)
       
    17 #define __WAPTESTUTILS_H__
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <e32test.h>
       
    21 #include <f32file.h>
       
    22 #include <flogger.h>
       
    23 
       
    24 #if !defined(__LOGGING)
       
    25 	#define __LOGGING
       
    26 #endif
       
    27 
       
    28 #include "waplog.h"
       
    29 #include "logdef.h"
       
    30 
       
    31 //	Constants
       
    32 const TUid KUidWapTestUtils = {0x10005188};
       
    33 const TInt KMaxUserEntrySize = 50;
       
    34 
       
    35 //Test Harness Logging
       
    36 
       
    37 #define KLogsDir				_L("c:\\logs\\")
       
    38 #define KWapLogsDirName			_L("WapTest")
       
    39 
       
    40 #define KTestHeader				_L("Test Results")
       
    41 #define KTestStarting			_L("Test %d Starting")
       
    42 #define KTestStartingWithDesc	_L("Test %d Starting (%S)")
       
    43 #define KNextTestStepWithDesc	_L("Test %d Step %d (%S)")
       
    44 #define KTestPassed				_L("Test %d OK")
       
    45 #define KTestFailed				_L("Test %d FAILED (error = %d)")
       
    46 #define KTestHarnessCompleted	_L("Tests Completed Ok")
       
    47 #define KTestHarnessFailed		_L("Test FAILED (%d failed test(s))")
       
    48 #define KTestFailInfo			_L("Test %d : %S failed with Error %d") 
       
    49 #define KTestCommentPrepend		_L("\t")
       
    50 
       
    51 
       
    52 class CWapTestHarness : public CBase
       
    53 /**
       
    54 	Test harness providing logging features
       
    55 	@publishedAll
       
    56 	@deprecated
       
    57 */
       
    58 
       
    59 	{
       
    60 public:
       
    61 	IMPORT_C static CWapTestHarness* NewLC(const TDesC& aTitle);
       
    62 	IMPORT_C static CWapTestHarness* NewL(const TDesC& aTitle);
       
    63 	~CWapTestHarness();
       
    64 
       
    65 	IMPORT_C void StartTestL(const TDesC& aName);
       
    66 	IMPORT_C void NextStep(const TDesC& aStepName);
       
    67 	IMPORT_C void EndTest(TInt aErrorCode);
       
    68 	IMPORT_C void LogIt(TRefByValue<const TDesC> aFmt, ...);
       
    69 	IMPORT_C void operator()(TInt aResult,TInt aLineNum);
       
    70 	IMPORT_C void operator()(TInt aResult);
       
    71 	IMPORT_C void PressAnyKey();
       
    72 	IMPORT_C void DumpData(HBufC8& aData, TBool logIt = EFalse);
       
    73 	IMPORT_C void GetAnEntry(const TDesC & ourPrompt, TDes & currentstring);
       
    74 	IMPORT_C TInt GetSelection(const TDesC& ourPrompt, const TDesC& validChoices);
       
    75 	IMPORT_C void SetScript(RFile& scriptFile);
       
    76 	inline void DoResourceLeakTest(TBool aValue);
       
    77 	inline RTest& Test();
       
    78 
       
    79 	inline static void DefaultLogFileName(TDes& aFileName);
       
    80 private:
       
    81 	CWapTestHarness(const TDesC& aTitle);
       
    82 	void ConstructL(const TDesC& aTitle);
       
    83 	void Panic(TInt aPanic);
       
    84 	void TestHarnessFailed();
       
    85 	void TestHarnessComplete();
       
    86 	void ResourceLeakTest();
       
    87 	inline void CreateFlogger(const TDesC& aFileName, TInt aShowDate=ETrue, TInt aShowTime=ETrue);
       
    88 	inline void WriteComment(const TDesC& aComment);
       
    89 	TInt ReadLineFromScript(TDes& aBuffer);
       
    90 
       
    91 private:
       
    92 	//	Helper class to store failed tests
       
    93 	class CTestInfo;
       
    94 	enum TPanicCode
       
    95 		{
       
    96 		EBadStartTest,
       
    97 		EBadEndTest,
       
    98 		EBadCLogPtr
       
    99 		};
       
   100 private:
       
   101 	RTest iTest;
       
   102 	RFileLogger iFlogger;
       
   103 	RFile* iScriptFile;
       
   104 	__DECLARE_LOG;	//	Does CLogClient* iLogPtr;
       
   105 	TInt iTestCount;
       
   106 	CArrayPtrFlat<CTestInfo>* iFailedTests;
       
   107 	TTime iStartTime;
       
   108 	TBool iCanStartTest;
       
   109 	TInt iStepNumber;
       
   110 	TInt iStartHandleCount;
       
   111 	TBool iDoResourceLeakTest;
       
   112 	TBool iScriptRunning;
       
   113 	};
       
   114 
       
   115 class CWapTestHarness::CTestInfo : public CBase
       
   116 
       
   117 /**
       
   118 	Holds test number and name
       
   119 	@publishedAll
       
   120 	@deprecated
       
   121 */
       
   122 	{
       
   123 public:
       
   124 	static CTestInfo* NewLC(const TDesC& aName, TInt aNumber, TInt aErrorCode);
       
   125 	static CTestInfo* NewL(const TDesC& aName, TInt aNumber, TInt aErrorCode);
       
   126 	~CTestInfo();
       
   127 
       
   128 	void SetNameL(const TDesC& aName);
       
   129 	void SetNumber(TInt aNumber);
       
   130 	void SetErrorCode(TInt aErrorCode);
       
   131 
       
   132 	inline TPtr Name() const;
       
   133 	inline TInt Number() const;
       
   134 	inline TInt ErrorCode() const;
       
   135 private:
       
   136 	CTestInfo();
       
   137 	void ConstructL(const TDesC& aName, TInt aNumber, TInt aErrorCode);
       
   138 private:
       
   139 	HBufC* iName;
       
   140 	TInt iNumber;
       
   141 	TInt iErrorCode;
       
   142 	};
       
   143 
       
   144 #include <waptestutils.inl>
       
   145 
       
   146 #endif	//	__WAPTESTUTILS_H__