genericservices/httputils/Test/IpuTestUtils/IpuTestUtils.h
changeset 0 e4d67989cc36
child 67 a1e347446159
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2001-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(__IPUTESTUTILS_H__)
       
    17 #define __IPUTESTUTILS_H__
       
    18 
       
    19 
       
    20 // System includes
       
    21 //
       
    22 #include <e32base.h>
       
    23 #include <e32test.h>
       
    24 #include <f32file.h>
       
    25 #include <flogger.h>
       
    26 
       
    27 
       
    28 //	Constants
       
    29 const TUid KUidIpuTestUtils = {0x10005188};
       
    30 const TInt KMaxUserEntrySize = 50;
       
    31 
       
    32 //Test Harness Logging
       
    33 
       
    34 #define KLogsDir				_L("c:\\logs\\")
       
    35 #define KInuLogsDirName			_L("InetProtUtil")
       
    36 
       
    37 #define KTestHeader				_L("Test Results")
       
    38 #define KTestStarting			_L("Test %d Starting")
       
    39 #define KTestStartingWithDesc	_L("Test %d Starting (%S)")
       
    40 #define KNextTestStepWithDesc	_L("Test %d Step %d (%S)")
       
    41 #define KTestPassed				_L("Test %d OK")
       
    42 #define KTestFailed				_L("Test %d FAILED (error = %d)")
       
    43 #define KTestHarnessCompleted	_L("Tests Completed Ok")
       
    44 #define KTestHarnessFailed		_L("Test FAILED (%d failed test(s))")
       
    45 #define KTestFailInfo			_L("Test %d : %S failed with Error %d") 
       
    46 #define KTestCommentPrepend		_L("\t")
       
    47 
       
    48 class CIpuTestHarness : public CBase
       
    49 //
       
    50 //	Test harness providing logging features
       
    51 	{
       
    52 public:
       
    53 
       
    54 	enum TTestMode
       
    55 		{
       
    56 		ETestModeNormal,
       
    57 		ETestModeMemoryLeak
       
    58 		};
       
    59 
       
    60 	IMPORT_C static CIpuTestHarness* NewLC(const TDesC& aTitle);
       
    61 	IMPORT_C static CIpuTestHarness* NewL(const TDesC& aTitle);
       
    62 	~CIpuTestHarness();
       
    63 
       
    64 	IMPORT_C void StartTestL(const TDesC& aName);
       
    65 	IMPORT_C void NextStep(const TDesC& aStepName);
       
    66 	IMPORT_C void EndTest(TInt aErrorCode);
       
    67 	IMPORT_C void LogIt(TRefByValue<const TDesC> aFmt, ...);
       
    68 	IMPORT_C void operator()(TInt aResult,TInt aLineNum);
       
    69 	IMPORT_C void operator()(TInt aResult);
       
    70 	IMPORT_C void PressAnyKey();
       
    71 	IMPORT_C void DumpData(HBufC8& aData, TBool logIt = EFalse);
       
    72 	IMPORT_C void GetAnEntry(const TDesC & ourPrompt, TDes & currentstring);
       
    73 	IMPORT_C TInt GetSelection(const TDesC& ourPrompt, const TDesC& validChoices);
       
    74 	IMPORT_C void SetScript(RFile& scriptFile);
       
    75 	inline void DoResourceLeakTest(TBool aValue);
       
    76 	inline RTest& Test();
       
    77 	inline void SetTestMode(TTestMode aTestMode);
       
    78 
       
    79 	inline static void DefaultLogFileName(TDes& aFileName);
       
    80 private:
       
    81 	CIpuTestHarness(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 	TInt iTestCount;
       
   105 	CArrayPtrFlat<CTestInfo>* iFailedTests;
       
   106 	TTime iStartTime;
       
   107 	TBool iCanStartTest;
       
   108 	TInt iStepNumber;
       
   109 	TInt iStartHandleCount;
       
   110 	TBool iDoResourceLeakTest;
       
   111 	TBool iScriptRunning;
       
   112 	TTestMode iTestMode;
       
   113 	};
       
   114 
       
   115 class CIpuTestHarness::CTestInfo : public CBase
       
   116 //
       
   117 //	Holds test number and name
       
   118 	{
       
   119 public:
       
   120 	static CTestInfo* NewLC(const TDesC& aName, TInt aNumber, TInt aErrorCode);
       
   121 	static CTestInfo* NewL(const TDesC& aName, TInt aNumber, TInt aErrorCode);
       
   122 	~CTestInfo();
       
   123 
       
   124 	void SetNameL(const TDesC& aName);
       
   125 	void SetNumber(TInt aNumber);
       
   126 	void SetErrorCode(TInt aErrorCode);
       
   127 
       
   128 	inline TPtr Name() const;
       
   129 	inline TInt Number() const;
       
   130 	inline TInt ErrorCode() const;
       
   131 private:
       
   132 	CTestInfo();
       
   133 	void ConstructL(const TDesC& aName, TInt aNumber, TInt aErrorCode);
       
   134 private:
       
   135 	HBufC* iName;
       
   136 	TInt iNumber;
       
   137 	TInt iErrorCode;
       
   138 	};
       
   139 
       
   140 #include "IpuTestUtils.inl"
       
   141 
       
   142 #endif	//	__IPUTESTUTILS_H__