imagingtestenv/imagingtestfw/include/TestFramework.h
changeset 0 5752a19fdefe
equal deleted inserted replaced
-1:000000000000 0:5752a19fdefe
       
     1 // Copyright (c) 2002-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 // Public API for GT0137 Integration Test Framework
       
    15 // 
       
    16 //
       
    17 
       
    18 #ifndef __TESTFRAMEWORK_H__
       
    19 #define __TESTFRAMEWORK_H__
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <f32file.h>
       
    23 #include <ecom/ecom.h>
       
    24 
       
    25 #include <mmf/common/mmfipc.h>
       
    26 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    27 #include <mmf/common/mmfipcserver.h>
       
    28 #endif
       
    29 #include <testframeworkipc.h>
       
    30 
       
    31 /**
       
    32  *
       
    33  * Server name
       
    34  *
       
    35  *
       
    36  *
       
    37  */
       
    38 _LIT(KTestFrameworkServerName, "TestFrameworkServer");
       
    39 
       
    40 /**
       
    41  *
       
    42  * Server .EXE name
       
    43  *
       
    44  *
       
    45  *
       
    46  */
       
    47 
       
    48 // Multimedia Heap Macros
       
    49 #define __MM_HEAP_MARK __UHEAP_MARK;
       
    50 #define __MM_HEAP_MARKEND REComSession::FinalClose(); __UHEAP_MARKEND;
       
    51 
       
    52 
       
    53 _LIT(KTestFrameworkServerImg, "z:\\system\\libs\\TestFrameworkServer.exe"); //<DLL/EXE name
       
    54 
       
    55 /**
       
    56  *
       
    57  * Server UID - MUST match the UID in TestFrameworkServer.mmp
       
    58  *
       
    59  *
       
    60  *
       
    61  */
       
    62 const TUid KTestFrameworkServerUid3={0x101f45ef};
       
    63 
       
    64 /**
       
    65  *
       
    66  * Server stack/heap sizes.
       
    67  * Only needed for WINS
       
    68  *
       
    69  *
       
    70  *
       
    71  */
       
    72 // #if defined (__WINS__)
       
    73 
       
    74 /**
       
    75  *
       
    76  * To specify a version when creating a session with the server
       
    77  *
       
    78  *
       
    79  *
       
    80  */
       
    81 const TUint KTestFrameworkServerMajorVersionNumber = 1;
       
    82 const TUint KTestFrameworkServerMinorVersionNumber = 1;
       
    83 const TUint KTestFrameworkServerBuildVersionNumber = 1;
       
    84 
       
    85 
       
    86 /**
       
    87  *
       
    88  * Opcodes used in message passing between client and server
       
    89  *
       
    90  *
       
    91  *
       
    92  */
       
    93 enum TTestFrameworkRequest
       
    94     {
       
    95     ECreateInputWindow,
       
    96     ENotifyIfWindowChange,
       
    97     ECancelNotifyIfWindowChange,
       
    98     EOpenLog,
       
    99     EWriteLog,
       
   100     ECloseLog,
       
   101     ELogStatus,
       
   102     };
       
   103 
       
   104 /**
       
   105  *
       
   106  * Bitmask flags for logging mode.
       
   107  *
       
   108  *
       
   109  *
       
   110  */
       
   111 enum TTestFrameworkLogMode
       
   112     {
       
   113     ELogToConsole = 0x0001,
       
   114     ELogToFile = 0x0002,
       
   115     ELogToPort = 0x0004,
       
   116     ELogConsoleFull = 0x0008
       
   117     };
       
   118 
       
   119 /**
       
   120  *
       
   121  * For passing window dimensions to console windows.
       
   122  *
       
   123  *
       
   124  *
       
   125  */
       
   126 typedef TPckgBuf<TRect> TRectBuf;
       
   127 
       
   128 // Logging includes
       
   129 
       
   130 /** 
       
   131  *
       
   132  * Max length of log file line and source filename.
       
   133  *
       
   134  *
       
   135  *
       
   136  */
       
   137 const TInt KMaxLogLineLength =  256;
       
   138 const TInt KMaxLogFilenameLength = 200;
       
   139 
       
   140 /**
       
   141  *
       
   142  * Bitmask flags for logging severity levels.
       
   143  *
       
   144  *
       
   145  *
       
   146  */
       
   147 enum TSeverity
       
   148     {
       
   149     ESevrErr  = 0x0001,
       
   150     ESevrWarn = 0x0002,
       
   151     ESevrInfo = 0x0004,
       
   152     ESevrVer  = 0x0007,     // always log verdicts
       
   153     ESevrAll  = 0x0007
       
   154     };
       
   155 
       
   156 /**
       
   157  *
       
   158  * Static helper class for TSeverity.
       
   159  *
       
   160  *
       
   161  *
       
   162  */
       
   163 class LogSeverity
       
   164     {
       
   165 public:
       
   166     IMPORT_C static TBool IsValid(TInt aSev);
       
   167     IMPORT_C static TBool IsActive(TInt aThisSev, TInt aGlobalSev);
       
   168     };
       
   169 
       
   170 /**
       
   171  *
       
   172  * Verdict enumerators for test results.
       
   173  *
       
   174  *
       
   175  *
       
   176  */
       
   177 enum TVerdict
       
   178     {
       
   179     EPass = 0,
       
   180     EFail,
       
   181     EInconclusive,
       
   182     ETestSuiteError,
       
   183     EAbort,
       
   184 
       
   185     //A new TVerdict for a known failed test which cannot be fixed in the near 
       
   186     //future, and is not allowed to be removed from the suite.
       
   187     EKnownFailure 
       
   188     };
       
   189 
       
   190 /**
       
   191  *
       
   192  * Logging client session class.
       
   193  *
       
   194  *
       
   195  *
       
   196  *
       
   197  */
       
   198 class RTestFrameworkClientSession : public RMmfSessionBaseX
       
   199     {
       
   200 public:
       
   201     RTestFrameworkClientSession();
       
   202     TInt Connect();
       
   203     void CreateInputWindow(TRectBuf& aAllocatedWindow, TRequestStatus& aReqStat);
       
   204     void NotifyIfWindowChange(TRectBuf& aNewWindow, TRequestStatus& aReqStat);
       
   205     TInt CancelNotifyIfWindowChange();
       
   206     void OpenLog(const TDesC& aLogName, TInt aLogMode);
       
   207     void OpenLog();
       
   208     void WriteLog(const TDesC& aMsg, TInt aLogMode);
       
   209     void CloseLog();
       
   210     TInt LogStatus();
       
   211     };
       
   212 
       
   213 
       
   214 /**
       
   215  *
       
   216  * Logging helper class, used to panic if format text overflows 
       
   217  * the internal buffer.
       
   218  *
       
   219  *
       
   220  *
       
   221  *
       
   222  */
       
   223 class TIntegrationTestLog16Overflow :public TDes16Overflow
       
   224     {
       
   225 public:
       
   226     // TDes16Overflow pure virtual
       
   227     virtual void Overflow(TDes16& aDes);
       
   228     };
       
   229 
       
   230 /**
       
   231  *
       
   232  * Flags for logging mode.
       
   233  *
       
   234  *
       
   235  *
       
   236  */
       
   237 enum TLogFlags
       
   238     {
       
   239     ELogPutSrcInfo = 0x01,
       
   240     ELogHtmlMode = 0x02
       
   241     };
       
   242 
       
   243  /**
       
   244  *
       
   245  * Logging class for all console/file/port output.
       
   246  *
       
   247  *
       
   248  *
       
   249  *
       
   250  *
       
   251  */
       
   252 class CLog  : public CBase
       
   253     {
       
   254 public:
       
   255     IMPORT_C static CLog* NewL();
       
   256     IMPORT_C static CLog* NewLC();
       
   257     IMPORT_C void Construct();
       
   258     IMPORT_C ~CLog();
       
   259 
       
   260     // open / close log file
       
   261     IMPORT_C void OpenLogFileL(const TDesC& aLogName, TInt aLogMode);
       
   262     IMPORT_C void OpenLogFileL();
       
   263     IMPORT_C void CloseLogFile();
       
   264 
       
   265     // write to log output in Printf() style
       
   266     IMPORT_C void Log(TRefByValue<const TDesC16> aFmt, ...);
       
   267     IMPORT_C void Log(TInt aSeverity, TRefByValue<const TDesC16> aFmt, ...);
       
   268     IMPORT_C void Log(TRefByValue<const TDesC16> aFmt, VA_LIST aList);
       
   269 
       
   270     IMPORT_C void LogExtra(const TText8* aFile, TInt aLine, TInt aSeverity,
       
   271         TRefByValue<const TDesC16> aFmt, VA_LIST aList);
       
   272     IMPORT_C void LogExtra(const TText8* aFile, TInt aLine, TInt aSeverity,
       
   273         TRefByValue<const TDesC16> aFmt, ...);
       
   274     IMPORT_C void LogResult(TVerdict aVerdict, TRefByValue<const TDesC16> aFmt, ...);
       
   275 
       
   276     // add some blank lines to log output
       
   277     IMPORT_C void LogBlankLine(TInt aNumber = 1);
       
   278     
       
   279     // convert an EPOC error to text
       
   280     IMPORT_C static TPtrC EpocErrorToText(TInt aError);
       
   281 
       
   282     // convert a test verdict to text 
       
   283     IMPORT_C static TPtrC TestResultText(TVerdict aTestVerdict);
       
   284 
       
   285     // write formatted text to file - moved from CFileLogger
       
   286     IMPORT_C void WriteFormat(TRefByValue<const TDesC16> aFmt, ...);
       
   287 
       
   288     // write text to console with date / time stamp
       
   289     IMPORT_C void WriteLogConsole(const TDesC& aBuf);
       
   290 
       
   291     // get logging status from session
       
   292     IMPORT_C TInt LogStatus();
       
   293 
       
   294     // accessors
       
   295     IMPORT_C void SetSeverity(TInt aSeverity);
       
   296     IMPORT_C TInt Severity() const; 
       
   297     IMPORT_C void SetPutSrcInfo(TBool aPutSrcInfo);
       
   298     IMPORT_C void SetHtmlLogMode(TBool aArg);
       
   299     IMPORT_C TBool HtmlLogMode() const;
       
   300     
       
   301 private:
       
   302     // the client session
       
   303     RTestFrameworkClientSession iClientSession;
       
   304 
       
   305 protected:
       
   306     // Current server logging status
       
   307     TInt iLogStatus;
       
   308     // Severity level
       
   309     TInt iSeverity;
       
   310     // Do we need to put information about source file & #line? Default is yes.
       
   311     // Do we need to produce HTML log file? Default is yes.
       
   312     TUint iLogFlags;
       
   313 
       
   314     // data buffer for logging - avoids panics in alloc testing
       
   315     TBuf16<KMaxLogLineLength> iDataBuf;
       
   316     };
       
   317 
       
   318 
       
   319 /**
       
   320  *
       
   321  * Print formatting macros.
       
   322  * Any class which implements LogExtra() can use these.
       
   323  *
       
   324  *
       
   325  *
       
   326  */
       
   327 #define __FILE8__                                   REINTERPRET_CAST(const TText8*, __FILE__)
       
   328 
       
   329 #define INFO_PRINTF1(p1)                            LogExtra(__FILE8__, __LINE__, ESevrInfo, (p1)) 
       
   330 #define INFO_PRINTF2(p1, p2)                        LogExtra(__FILE8__, __LINE__, ESevrInfo, (p1), (p2)) 
       
   331 #define INFO_PRINTF3(p1, p2, p3)                    LogExtra(__FILE8__, __LINE__, ESevrInfo, (p1), (p2), (p3)) 
       
   332 #define INFO_PRINTF4(p1, p2, p3, p4)                LogExtra(__FILE8__, __LINE__, ESevrInfo, (p1), (p2), (p3), (p4)) 
       
   333 #define INFO_PRINTF5(p1, p2, p3, p4, p5)            LogExtra(__FILE8__, __LINE__, ESevrInfo, (p1), (p2), (p3), (p4), (p5)) 
       
   334 #define INFO_PRINTF6(p1, p2, p3, p4, p5, p6)        LogExtra(__FILE8__, __LINE__, ESevrInfo, (p1), (p2), (p3), (p4), (p5), (p6)) 
       
   335 #define INFO_PRINTF7(p1, p2, p3, p4, p5, p6, p7)    LogExtra(__FILE8__, __LINE__, ESevrInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7)) 
       
   336 #define INFO_PRINTF8(p1, p2, p3, p4, p5, p6, p7, p8)        LogExtra(__FILE8__, __LINE__, ESevrInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8)) 
       
   337 #define INFO_PRINTF9(p1, p2, p3, p4, p5, p6, p7, p8, p9)    LogExtra(__FILE8__, __LINE__, ESevrInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9)) 
       
   338 
       
   339 #define WARN_PRINTF1(p1)                            LogExtra(__FILE8__, __LINE__, ESevrWarn, (p1)) 
       
   340 #define WARN_PRINTF2(p1, p2)                        LogExtra(__FILE8__, __LINE__, ESevrWarn, (p1), (p2)) 
       
   341 #define WARN_PRINTF3(p1, p2, p3)                    LogExtra(__FILE8__, __LINE__, ESevrWarn, (p1), (p2), (p3)) 
       
   342 #define WARN_PRINTF4(p1, p2, p3, p4)                LogExtra(__FILE8__, __LINE__, ESevrWarn, (p1), (p2), (p3), (p4)) 
       
   343 #define WARN_PRINTF5(p1, p2, p3, p4, p5)            LogExtra(__FILE8__, __LINE__, ESevrWarn, (p1), (p2), (p3), (p4), (p5)) 
       
   344 #define WARN_PRINTF6(p1, p2, p3, p4, p5, p6)        LogExtra(__FILE8__, __LINE__, ESevrWarn, (p1), (p2), (p3), (p4), (p5), (p6)) 
       
   345 #define WARN_PRINTF7(p1, p2, p3, p4, p5, p6, p7)    LogExtra(__FILE8__, __LINE__, ESevrWarn, (p1), (p2), (p3), (p4), (p5), (p6), (p7)) 
       
   346 
       
   347 #define ERR_PRINTF1(p1)                             LogExtra(__FILE8__, __LINE__, ESevrErr, (p1)) 
       
   348 #define ERR_PRINTF2(p1, p2)                         LogExtra(__FILE8__, __LINE__, ESevrErr, (p1), (p2)) 
       
   349 #define ERR_PRINTF3(p1, p2, p3)                     LogExtra(__FILE8__, __LINE__, ESevrErr, (p1), (p2), (p3)) ;
       
   350 #define ERR_PRINTF4(p1, p2, p3, p4)                 LogExtra(__FILE8__, __LINE__, ESevrErr, (p1), (p2), (p3), (p4)) 
       
   351 #define ERR_PRINTF5(p1, p2, p3, p4, p5)             LogExtra(__FILE8__, __LINE__, ESevrErr, (p1), (p2), (p3), (p4), (p5)) 
       
   352 #define ERR_PRINTF6(p1, p2, p3, p4, p5, p6)         LogExtra(__FILE8__, __LINE__, ESevrErr, (p1), (p2), (p3), (p4), (p5), (p6)) 
       
   353 #define ERR_PRINTF7(p1, p2, p3, p4, p5, p6, p7)     LogExtra(__FILE8__, __LINE__, ESevrErr, (p1), (p2), (p3), (p4), (p5), (p6), (p7)) 
       
   354 
       
   355 #define TEST_START(p1)                              LogExtra(__FILE8__, __LINE__, ESevrInfo, (_L("======Start test %S")), (p1)) 
       
   356 #define TEST_NEXT(p1)                               LogExtra(__FILE8__, __LINE__, ESevrInfo, _L("Next test %S"), (p1)) 
       
   357 #define TEST_END()                                  LogExtra(__FILE8__, __LINE__, ESevrInfo, _L("======End test =====") ) 
       
   358 
       
   359 // Test Suite includes
       
   360 
       
   361 /**
       
   362  *
       
   363  * Max length of test suite name.
       
   364  *
       
   365  *
       
   366  *
       
   367  */
       
   368 const TInt KMaxLenTestSuiteName = 55;
       
   369 
       
   370 class RTestStep;
       
   371 
       
   372 /**
       
   373  *
       
   374  * Enumerator to indicate what stage a test has reached.
       
   375  *
       
   376  *
       
   377  *
       
   378  */
       
   379 enum TTestStepStatus
       
   380     {
       
   381     EStepStatusNone = -1,
       
   382     EStepStatusStart = 0,
       
   383     EStepStatusPreamble,
       
   384     EStepStatusTest,
       
   385     EStepStatusFinished
       
   386     };
       
   387 
       
   388 /**
       
   389  *
       
   390  * Base test suite class. All test suite classes
       
   391  * derive from this.
       
   392  *
       
   393  *
       
   394  *
       
   395  *
       
   396  */
       
   397 class CTestSuite : public CBase
       
   398     {
       
   399 public:
       
   400     // second phase constructor
       
   401     // NB this is public because it is called by the factory function
       
   402     IMPORT_C void ConstructL();
       
   403     // destructor
       
   404     IMPORT_C virtual ~CTestSuite();
       
   405     // add a test step to the suite
       
   406     IMPORT_C void AddTestStepL(RTestStep* aTestStep);
       
   407     // get stack and heap size of a named step
       
   408     IMPORT_C void GetHeapAndStackSize(const TDesC& aStep, TInt* aHeapSize, TInt* aStackSize);
       
   409     // public interface to run test steps
       
   410     IMPORT_C TVerdict DoTestStep(const TDesC& aStep, const TDesC& aConfig, const TDesC& aPAramSet);
       
   411 
       
   412 /**
       
   413  *
       
   414  * Test suite second phase initialiser, called from CTestSuite::ConstructL().
       
   415  * All test suites must implement this.
       
   416  * 
       
   417  *
       
   418  *
       
   419  */
       
   420     virtual void InitialiseL() = 0;
       
   421 
       
   422     IMPORT_C void Log(TRefByValue<const TDesC16> aFmt, ...);
       
   423     IMPORT_C void Log(TInt aSeverity, TRefByValue<const TDesC16> aFmt, ...);
       
   424     IMPORT_C void LogExtra(const TText8* aFile, TInt aLine, TInt aSeverity,
       
   425         TRefByValue<const TDesC16> aFmt, ...);
       
   426 
       
   427     // this should be a pure virtual so every test DLL
       
   428     // has to provide a version, but for now defaults to ?.?
       
   429     IMPORT_C virtual TPtrC GetVersion() const;
       
   430 
       
   431     // accessors
       
   432     IMPORT_C void SetSeverity(TInt aSeverity);
       
   433     IMPORT_C TInt Severity() const;
       
   434     IMPORT_C void SetStepStatus(TTestStepStatus aStatus);
       
   435     IMPORT_C TTestStepStatus StepStatus() const;
       
   436     IMPORT_C void SetLogSystem(CLog* aLogger);
       
   437     IMPORT_C CLog* LogSystem() const;
       
   438 
       
   439 protected:
       
   440     // test functions
       
   441     IMPORT_C void TestBooleanTrueL(TBool aCondition, const TText8* aFile, TInt aLine);
       
   442 
       
   443 private:
       
   444     // severity level
       
   445     TInt iSeverity;
       
   446     // File logging system
       
   447     CLog* iLogger;
       
   448     // array of pointers to the test steps in this suite
       
   449     CArrayPtr<RTestStep>* iArrayTestSteps;
       
   450     // status of current test step
       
   451     TTestStepStatus iStepStatus;
       
   452 
       
   453 protected:
       
   454     // the name of this suite
       
   455     TBuf<KMaxLenTestSuiteName> iSuiteName;
       
   456 
       
   457     };
       
   458 
       
   459 // Test Step includes
       
   460 
       
   461 /**
       
   462  *
       
   463  * Max length of step name
       
   464  *
       
   465  *
       
   466  *
       
   467  */
       
   468 const TInt KMaxLenTestStepName = 55;
       
   469 
       
   470 class CTestIniData;
       
   471 
       
   472 /**
       
   473  *
       
   474  * Default stack and heap sizes for test step
       
   475  *
       
   476  *
       
   477  *
       
   478  */
       
   479 const TInt KTestStackSize = KDefaultStackSize;  // 0x2000 = 8k
       
   480 const TInt KMaxTestThreadHeapSize = 0x10000;    // = 64k
       
   481 
       
   482 /**
       
   483  *
       
   484  * Base test step class. All test step classes
       
   485  * derive from this
       
   486  *
       
   487  *
       
   488  *
       
   489  *
       
   490  */
       
   491 class RTestStep
       
   492     {
       
   493 public:
       
   494 
       
   495     IMPORT_C RTestStep();
       
   496 
       
   497     IMPORT_C TAny* operator new(TUint aSize, TAny* aBase) __NO_THROW;
       
   498     IMPORT_C TAny* operator new(TUint aSize, TLeave);
       
   499     IMPORT_C TAny* operator new(TUint aSize) __NO_THROW;
       
   500     IMPORT_C static TAny* newL(TUint aSize);
       
   501     IMPORT_C TAny* operator new(TUint aSize,TUint anExtraSize) __NO_THROW;
       
   502 
       
   503     IMPORT_C void PreOpenL();
       
   504     IMPORT_C virtual TVerdict OpenL();
       
   505     IMPORT_C virtual void CleanupAfterOpenFail();
       
   506     IMPORT_C virtual void Close();
       
   507 
       
   508 /**
       
   509  *
       
   510  * Perform the test step.
       
   511  *
       
   512  * @return  "TVerdict"
       
   513  *          The result of the test step.
       
   514  *
       
   515  *
       
   516  *
       
   517  */
       
   518     virtual TVerdict DoTestStepL() = 0;
       
   519     
       
   520     // initialise the config parameter system
       
   521     IMPORT_C void LoadConfig(const TDesC& aConfig);
       
   522     IMPORT_C void UnloadConfig();
       
   523 
       
   524     // accessors for stack / heap size
       
   525     IMPORT_C TInt StackSize() const;
       
   526     IMPORT_C TInt HeapSize() const;
       
   527 
       
   528     IMPORT_C void SetSuite(CTestSuite* aSuite);
       
   529     IMPORT_C void SetResult(TVerdict aResult);
       
   530     IMPORT_C TPtrC StepName() const;
       
   531     
       
   532     // param set - not required to be exported. Note assumes actual param is stable
       
   533     void SetDefaultParamSet(const TDesC& aParamSet);
       
   534 
       
   535 protected:
       
   536 
       
   537     // tests may optionally implement pre- and post-ambles
       
   538     IMPORT_C virtual TVerdict DoTestStepPreambleL();
       
   539     IMPORT_C virtual TVerdict DoTestStepPostambleL();
       
   540 
       
   541     // read values from the Config file functions
       
   542     IMPORT_C TBool GetBoolFromConfig(const TDesC& aSectName,const TDesC& aKeyName,TBool& aResult);
       
   543     IMPORT_C TBool GetIntFromConfig(const TDesC& aSectName,const TDesC& aKeyName,TInt& aResult);
       
   544     IMPORT_C TBool GetStringFromConfig(const TDesC& aSectName,const TDesC& aKeyName,TPtrC& aResult);
       
   545     IMPORT_C TBool GetHexFromConfig(const TDesC &aSectName,const TDesC &aKeyName,TInt &aResult);
       
   546 
       
   547     // test functions
       
   548     IMPORT_C void TestBooleanTrue(TBool aCondition, const TText8* aFile, TInt aLine);
       
   549     IMPORT_C void TestBooleanTrueL(TBool aCondition, const TText8* aFile, TInt aLine);
       
   550     IMPORT_C void TestBooleanTrueWithErrorCode(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine);
       
   551     IMPORT_C void TestBooleanTrueWithErrorCodeL(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine);
       
   552     IMPORT_C void TestCheckPointCompareL(TInt aVal, TInt aExpectedVal, 
       
   553                                          const TDesC& aText, const TText8* aFile, TInt aLine);
       
   554 
       
   555     // printf format log
       
   556     IMPORT_C void Log(TRefByValue<const TDesC16> aFmt, ...);
       
   557     IMPORT_C void Log(TInt aSeverity, TRefByValue<const TDesC16> aFmt, ...);
       
   558     IMPORT_C void LogExtra(const TText8* aFile, TInt aLine, TInt aSeverity,
       
   559         TRefByValue<const TDesC16> aFmt,...);
       
   560 
       
   561 private:
       
   562     // true if ConfigData has been loaded
       
   563     TBool   iConfigDataAvailable;
       
   564 
       
   565 protected:
       
   566     // the name of the test step
       
   567     TBuf<KMaxLenTestStepName> iTestStepName;
       
   568     // the parameter set to use - supplied to the run_test statement
       
   569     TPtrC iDefaultParamSet;
       
   570     // pointer to suite which owns this test 
       
   571     CTestSuite* iSuite;
       
   572     // the current test step verdict
       
   573     TVerdict iTestStepResult;
       
   574     // config file data
       
   575     CTestIniData *iConfigData;
       
   576     // stack and heap size
       
   577     TInt iStackSize;
       
   578     TInt iHeapSize;
       
   579     };
       
   580     
       
   581 class CAsyncTestActiveScheduler; 
       
   582     
       
   583 /**
       
   584 Sub-class of RTestStep that encapsulates CActiveScheduler and works asynchonously
       
   585 */
       
   586 
       
   587 class RAsyncTestStep : public RTestStep
       
   588     {
       
   589     friend class CAsyncTestActiveScheduler;
       
   590 protected:
       
   591     IMPORT_C RAsyncTestStep();
       
   592     
       
   593     // from RTestStep - these should not be replaced by RAsyncTestStep children
       
   594     IMPORT_C TVerdict DoTestStepL();
       
   595     IMPORT_C TVerdict DoTestStepPostambleL();
       
   596     
       
   597     // new methods
       
   598     /**
       
   599     Start the test
       
   600     This method is used at the beginning of the test, and should initialise whatever
       
   601     is required - typically setting up asynchronous calls that will activate once
       
   602     the call returns. The method is abstract, and must be supplied by any derived
       
   603     class.
       
   604     The ActiveScheduler is active (this call is made from a RunL() instance).
       
   605     If this test leaves, then StopTest() will be called with the leave value, so
       
   606     implicitly the test stops.
       
   607     */
       
   608     virtual void KickoffTestL() = 0;
       
   609     /**
       
   610     Called after the test has stopped to workout the result.
       
   611     This can be replaced by derived classes, if they have specific requirements, but
       
   612     the default should be suitable for most uses. The default returns the result
       
   613     set by StopTest() - if this is not pass, this result will also be written to the log.
       
   614     */
       
   615     IMPORT_C virtual TVerdict CheckTestResult();
       
   616     /**
       
   617     Close test.
       
   618     This call requests the test step to delete any remaining objects left when running
       
   619     a test. It is always called following the test being stopped.
       
   620     */
       
   621     virtual void CloseTest() = 0;
       
   622     
       
   623     // new commands
       
   624     /**
       
   625     Stop the test.
       
   626     This is called by the client to stop a test - calling CActiveScheduler::Stop() on the
       
   627     embedded active scheduler object. aReason is a standard error code. It defaults to
       
   628     KErrNone. aResult is the verdict to use as the result of the test - its default depends
       
   629     on aReason, EPass if the reason is KErrNone and EFail otherwise. 
       
   630     Note that StopTest() can be called multiple times - in which case only the first non-KErrNone
       
   631     reason and the first non-EPass result are used. */
       
   632     IMPORT_C void StopTest();
       
   633     IMPORT_C void StopTest(TInt aReason);
       
   634     IMPORT_C void StopTest(TInt aReason, TVerdict aResult);
       
   635     
       
   636     // these two are intended for overrides of CheckTestResult()
       
   637     /**
       
   638     The aReason value set by StopTest()
       
   639     */
       
   640     IMPORT_C TInt Reason() const;
       
   641     /**
       
   642     The aResult value set by StopTest()
       
   643     */
       
   644     IMPORT_C TVerdict Result() const;
       
   645     
       
   646 private:
       
   647     CActiveScheduler* iScheduler;
       
   648     
       
   649     void SetResult(TVerdict aResult);
       
   650     
       
   651     static TInt CallBack (TAny* aPtr);
       
   652     void DoCallBack();
       
   653     
       
   654     void HandleError(TInt aReason);
       
   655     
       
   656 private:
       
   657 // have copies of these here, as they are commonly required
       
   658     TInt iReason;
       
   659     TVerdict iResult;
       
   660     TBool iResultSet;
       
   661 
       
   662     CAsyncCallBack* iStartAO;
       
   663     CActiveSchedulerWait* iActiveSchedulerWait;
       
   664     TBool iStarted;
       
   665     };
       
   666 
       
   667 /**
       
   668  *
       
   669  * CTestStep, thin subclass of RTestStep - provided for
       
   670  * backward compatibility
       
   671  *
       
   672  *
       
   673  *
       
   674  *
       
   675  */
       
   676 class CTestStep : public RTestStep
       
   677     {
       
   678 public :
       
   679     // CTestStep destructor - provided for backward compatibility ONLY
       
   680     IMPORT_C virtual ~CTestStep();
       
   681     };
       
   682 
       
   683 /**
       
   684  *
       
   685  * Autotest macros mapped to RTestStep functions
       
   686  *
       
   687  *
       
   688  *
       
   689  *
       
   690  */
       
   691 // check a boolean is true
       
   692 #define TESTL(a) TestBooleanTrueL((a), __FILE8__, __LINE__) 
       
   693 #define TEST(a)  TestBooleanTrue((a), __FILE8__, __LINE__) 
       
   694 
       
   695 // check a boolean is true if not return error code b
       
   696 #define TESTE(a, b) TestBooleanTrueWithErrorCode((a), (b), __FILE8__, __LINE__) 
       
   697 #define TESTEL(a, b) TestBooleanTrueWithErrorCodeL((a), (b), __FILE8__, __LINE__)  
       
   698 #define TEST_CHECKL(p1, p2, p3) TestCheckPointCompareL((p1), (p2), (p3), __FILE8__, __LINE__)   
       
   699 // leave error code
       
   700 const TInt KTestErrorCode = 84; 
       
   701 
       
   702 /**
       
   703  *
       
   704  * Test utilities class
       
   705  *
       
   706  *
       
   707  *
       
   708  *
       
   709  */
       
   710 class CTestUtils : public CBase
       
   711     {
       
   712 public:
       
   713 
       
   714     IMPORT_C  static CTestUtils* NewL(CLog* aLogSystem);
       
   715     IMPORT_C  void RunUtils(const TDesC& aText);
       
   716 
       
   717 private:
       
   718     void Construct(CLog* aLogSystem);
       
   719     void RunUtilsL(const TDesC& aText);
       
   720 
       
   721     void MakeDirL (const TDesC& aDirname);
       
   722     void CopyFileL (const TDesC& aOld,const TDesC& aNew); 
       
   723     void CopyAndInvertFileL (const TDesC& aOld,const TDesC& aNew);
       
   724     void DeleteFileL (const TDesC& aFile); 
       
   725     void MakeReadWriteL(const TDesC& aFile);
       
   726 
       
   727     // printf format log
       
   728     void Log(TRefByValue<const TDesC16> aFmt, ...);
       
   729     void Log(TInt aSeverity, TRefByValue<const TDesC16> aFmt, ...);
       
   730     void LogExtra(const TText8* aFile, TInt aLine, TInt aSeverity,
       
   731         TRefByValue<const TDesC16> aFmt,...);
       
   732 
       
   733 private:
       
   734 
       
   735     // called by CopyAndInvertFileL func
       
   736     void DoCopyAndInvertL (const TDesC& aOld,const TDesC& aNew);
       
   737     
       
   738     // pointer to Logging object which handles File and Console logging
       
   739     CLog* iLogSystem;
       
   740     // local file server
       
   741     RFs iFs;
       
   742     };
       
   743     
       
   744 /*
       
   745 Busy unit - once started, uses a log of CPU time.
       
   746 */
       
   747 
       
   748 NONSHARABLE_CLASS(CBusyTestUnit) : public CBase
       
   749     {
       
   750     CBusyTestUnit();
       
   751     CBusyTestUnit(TInt aPercentBusy, TThreadPriority aThreadPriority);
       
   752     void ConstructL();
       
   753     
       
   754 public:
       
   755     ~CBusyTestUnit();
       
   756     
       
   757     IMPORT_C static CBusyTestUnit* NewL(TInt aPercentBusy, TThreadPriority aThreadPriority);
       
   758     IMPORT_C static CBusyTestUnit* NewLC(TInt aPercentBusy, TThreadPriority aThreadPriority);
       
   759     
       
   760     IMPORT_C TInt Start(); // run until Stop()
       
   761     IMPORT_C TInt Start(TTimeIntervalMicroSeconds aRunFor); 
       
   762             // run til Stop or aRunFor. aRunFor=0 means run until Stop()
       
   763     IMPORT_C TInt Start(TTimeIntervalMicroSeconds32 aDelayFor, TTimeIntervalMicroSeconds aRunFor); 
       
   764             // after aDelayFor, run til Stop or aRunFor
       
   765     
       
   766     IMPORT_C void Stop();
       
   767     
       
   768     
       
   769 private:
       
   770     TInt RunThread();
       
   771     static TInt StartThread(TAny* aPtr);
       
   772     void ThreadFunction();
       
   773     
       
   774     static TInt StaticTimerCallback(TAny* aPtr);
       
   775     TInt TimerCallback();
       
   776     
       
   777 private:
       
   778     const TInt iPercentBusy;
       
   779     const TThreadPriority iThreadPriority;
       
   780     TTimeIntervalMicroSeconds iRunFor;
       
   781     CPeriodic* iTimer;
       
   782     volatile TInt iBusyVariable;
       
   783     RThread iChildThread;
       
   784     };
       
   785 
       
   786 
       
   787 #endif // __TESTFRAMEWORK_H__