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