1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/waptestutils.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,146 @@
1.4 +// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#if !defined(__WAPTESTUTILS_H__)
1.20 +#define __WAPTESTUTILS_H__
1.21 +
1.22 +#include <e32base.h>
1.23 +#include <e32test.h>
1.24 +#include <f32file.h>
1.25 +#include <flogger.h>
1.26 +
1.27 +#if !defined(__LOGGING)
1.28 + #define __LOGGING
1.29 +#endif
1.30 +
1.31 +#include "waplog.h"
1.32 +#include "logdef.h"
1.33 +
1.34 +// Constants
1.35 +const TUid KUidWapTestUtils = {0x10005188};
1.36 +const TInt KMaxUserEntrySize = 50;
1.37 +
1.38 +//Test Harness Logging
1.39 +
1.40 +#define KLogsDir _L("c:\\logs\\")
1.41 +#define KWapLogsDirName _L("WapTest")
1.42 +
1.43 +#define KTestHeader _L("Test Results")
1.44 +#define KTestStarting _L("Test %d Starting")
1.45 +#define KTestStartingWithDesc _L("Test %d Starting (%S)")
1.46 +#define KNextTestStepWithDesc _L("Test %d Step %d (%S)")
1.47 +#define KTestPassed _L("Test %d OK")
1.48 +#define KTestFailed _L("Test %d FAILED (error = %d)")
1.49 +#define KTestHarnessCompleted _L("Tests Completed Ok")
1.50 +#define KTestHarnessFailed _L("Test FAILED (%d failed test(s))")
1.51 +#define KTestFailInfo _L("Test %d : %S failed with Error %d")
1.52 +#define KTestCommentPrepend _L("\t")
1.53 +
1.54 +
1.55 +class CWapTestHarness : public CBase
1.56 +/**
1.57 + Test harness providing logging features
1.58 + @publishedAll
1.59 + @released
1.60 +*/
1.61 +
1.62 + {
1.63 +public:
1.64 + IMPORT_C static CWapTestHarness* NewLC(const TDesC& aTitle);
1.65 + IMPORT_C static CWapTestHarness* NewL(const TDesC& aTitle);
1.66 + ~CWapTestHarness();
1.67 +
1.68 + IMPORT_C void StartTestL(const TDesC& aName);
1.69 + IMPORT_C void NextStep(const TDesC& aStepName);
1.70 + IMPORT_C void EndTest(TInt aErrorCode);
1.71 + IMPORT_C void LogIt(TRefByValue<const TDesC> aFmt, ...);
1.72 + IMPORT_C void operator()(TInt aResult,TInt aLineNum);
1.73 + IMPORT_C void operator()(TInt aResult);
1.74 + IMPORT_C void PressAnyKey();
1.75 + IMPORT_C void DumpData(HBufC8& aData, TBool logIt = EFalse);
1.76 + IMPORT_C void GetAnEntry(const TDesC & ourPrompt, TDes & currentstring);
1.77 + IMPORT_C TInt GetSelection(const TDesC& ourPrompt, const TDesC& validChoices);
1.78 + IMPORT_C void SetScript(RFile& scriptFile);
1.79 + inline void DoResourceLeakTest(TBool aValue);
1.80 + inline RTest& Test();
1.81 +
1.82 + inline static void DefaultLogFileName(TDes& aFileName);
1.83 +private:
1.84 + CWapTestHarness(const TDesC& aTitle);
1.85 + void ConstructL(const TDesC& aTitle);
1.86 + void Panic(TInt aPanic);
1.87 + void TestHarnessFailed();
1.88 + void TestHarnessComplete();
1.89 + void ResourceLeakTest();
1.90 + inline void CreateFlogger(const TDesC& aFileName, TInt aShowDate=ETrue, TInt aShowTime=ETrue);
1.91 + inline void WriteComment(const TDesC& aComment);
1.92 + TInt ReadLineFromScript(TDes& aBuffer);
1.93 +
1.94 +private:
1.95 + // Helper class to store failed tests
1.96 + class CTestInfo;
1.97 + enum TPanicCode
1.98 + {
1.99 + EBadStartTest,
1.100 + EBadEndTest,
1.101 + EBadCLogPtr
1.102 + };
1.103 +private:
1.104 + RTest iTest;
1.105 + RFileLogger iFlogger;
1.106 + RFile* iScriptFile;
1.107 + __DECLARE_LOG; // Does CLogClient* iLogPtr;
1.108 + TInt iTestCount;
1.109 + CArrayPtrFlat<CTestInfo>* iFailedTests;
1.110 + TTime iStartTime;
1.111 + TBool iCanStartTest;
1.112 + TInt iStepNumber;
1.113 + TInt iStartHandleCount;
1.114 + TBool iDoResourceLeakTest;
1.115 + TBool iScriptRunning;
1.116 + };
1.117 +
1.118 +class CWapTestHarness::CTestInfo : public CBase
1.119 +
1.120 +/**
1.121 + Holds test number and name
1.122 + @publishedAll
1.123 + @released
1.124 +*/
1.125 + {
1.126 +public:
1.127 + static CTestInfo* NewLC(const TDesC& aName, TInt aNumber, TInt aErrorCode);
1.128 + static CTestInfo* NewL(const TDesC& aName, TInt aNumber, TInt aErrorCode);
1.129 + ~CTestInfo();
1.130 +
1.131 + void SetNameL(const TDesC& aName);
1.132 + void SetNumber(TInt aNumber);
1.133 + void SetErrorCode(TInt aErrorCode);
1.134 +
1.135 + inline TPtr Name() const;
1.136 + inline TInt Number() const;
1.137 + inline TInt ErrorCode() const;
1.138 +private:
1.139 + CTestInfo();
1.140 + void ConstructL(const TDesC& aName, TInt aNumber, TInt aErrorCode);
1.141 +private:
1.142 + HBufC* iName;
1.143 + TInt iNumber;
1.144 + TInt iErrorCode;
1.145 + };
1.146 +
1.147 +#include <waptestutils.inl>
1.148 +
1.149 +#endif // __WAPTESTUTILS_H__