sl@0: // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #if !defined(__IPUTESTUTILS_H__) sl@0: #define __IPUTESTUTILS_H__ sl@0: sl@0: sl@0: // System includes sl@0: // sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: sl@0: // Constants sl@0: const TUid KUidIpuTestUtils = {0x10005188}; sl@0: const TInt KMaxUserEntrySize = 50; sl@0: sl@0: //Test Harness Logging sl@0: sl@0: #define KLogsDir _L("c:\\logs\\testexecute\\") sl@0: #define KInuLogsDirName _L("InetProtUtil") sl@0: sl@0: #define KTestHeader _L("Test Results") sl@0: #define KTestStarting _L("Test %d Starting") sl@0: #define KTestStartingWithDesc _L("Test %d Starting (%S)") sl@0: #define KNextTestStepWithDesc _L("Test %d Step %d (%S)") sl@0: #define KTestPassed _L("Test %d OK") sl@0: #define KTestFailed _L("Test %d FAILED (error = %d)") sl@0: #define KTestHarnessCompleted _L("Tests Completed Ok") sl@0: #define KTestHarnessFailed _L("Test FAILED (%d failed test(s))") sl@0: #define KTestFailInfo _L("Test %d : %S failed with Error %d") sl@0: #define KTestCommentPrepend _L("\t") sl@0: sl@0: class CIpuTestHarness : public CBase sl@0: // sl@0: // Test harness providing logging features sl@0: { sl@0: public: sl@0: sl@0: enum TTestMode sl@0: { sl@0: ETestModeNormal, sl@0: ETestModeMemoryLeak sl@0: }; sl@0: sl@0: IMPORT_C static CIpuTestHarness* NewLC(const TDesC& aTitle); sl@0: IMPORT_C static CIpuTestHarness* NewL(const TDesC& aTitle); sl@0: ~CIpuTestHarness(); sl@0: sl@0: IMPORT_C void StartTestL(const TDesC& aName); sl@0: IMPORT_C void NextStep(const TDesC& aStepName); sl@0: IMPORT_C void EndTest(TInt aErrorCode); sl@0: IMPORT_C void LogIt(TRefByValue aFmt, ...); sl@0: IMPORT_C void operator()(TInt aResult,TInt aLineNum); sl@0: IMPORT_C void operator()(TInt aResult); sl@0: IMPORT_C void PressAnyKey(); sl@0: IMPORT_C void DumpData(HBufC8& aData, TBool logIt = EFalse); sl@0: IMPORT_C void GetAnEntry(const TDesC & ourPrompt, TDes & currentstring); sl@0: IMPORT_C TInt GetSelection(const TDesC& ourPrompt, const TDesC& validChoices); sl@0: IMPORT_C void SetScript(RFile& scriptFile); sl@0: inline void DoResourceLeakTest(TBool aValue); sl@0: inline RTest& Test(); sl@0: inline void SetTestMode(TTestMode aTestMode); sl@0: sl@0: inline static void DefaultLogFileName(TDes& aFileName); sl@0: private: sl@0: CIpuTestHarness(const TDesC& aTitle); sl@0: void ConstructL(const TDesC& aTitle); sl@0: void Panic(TInt aPanic); sl@0: void TestHarnessFailed(); sl@0: void TestHarnessComplete(); sl@0: void ResourceLeakTest(); sl@0: inline void CreateFlogger(const TDesC& aFileName, TInt aShowDate=ETrue, TInt aShowTime=ETrue); sl@0: inline void WriteComment(const TDesC& aComment); sl@0: TInt ReadLineFromScript(TDes& aBuffer); sl@0: sl@0: private: sl@0: // Helper class to store failed tests sl@0: class CTestInfo; sl@0: enum TPanicCode sl@0: { sl@0: EBadStartTest, sl@0: EBadEndTest, sl@0: EBadCLogPtr sl@0: }; sl@0: private: sl@0: RTest iTest; sl@0: RFileLogger iFlogger; sl@0: RFile* iScriptFile; sl@0: TInt iTestCount; sl@0: CArrayPtrFlat* iFailedTests; sl@0: TTime iStartTime; sl@0: TBool iCanStartTest; sl@0: TInt iStepNumber; sl@0: TInt iStartHandleCount; sl@0: TBool iDoResourceLeakTest; sl@0: TBool iScriptRunning; sl@0: TTestMode iTestMode; sl@0: }; sl@0: sl@0: class CIpuTestHarness::CTestInfo : public CBase sl@0: // sl@0: // Holds test number and name sl@0: { sl@0: public: sl@0: static CTestInfo* NewLC(const TDesC& aName, TInt aNumber, TInt aErrorCode); sl@0: static CTestInfo* NewL(const TDesC& aName, TInt aNumber, TInt aErrorCode); sl@0: ~CTestInfo(); sl@0: sl@0: void SetNameL(const TDesC& aName); sl@0: void SetNumber(TInt aNumber); sl@0: void SetErrorCode(TInt aErrorCode); sl@0: sl@0: inline TPtr Name() const; sl@0: inline TInt Number() const; sl@0: inline TInt ErrorCode() const; sl@0: private: sl@0: CTestInfo(); sl@0: void ConstructL(const TDesC& aName, TInt aNumber, TInt aErrorCode); sl@0: private: sl@0: HBufC* iName; sl@0: TInt iNumber; sl@0: TInt iErrorCode; sl@0: }; sl@0: sl@0: #include "IpuTestUtils.inl" sl@0: sl@0: #endif // __IPUTESTUTILS_H__