toolsandutils/autotest/inc/autotest.h
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 // Copyright (c) 2000-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 #ifndef E32AUTOTEST_H__
       
    17 #define E32AUTOTEST_H__
       
    18 
       
    19 /** @file autotest.h
       
    20  *
       
    21  * Framework for Automated Test code.
       
    22  */
       
    23 
       
    24 #include <e32test.h>
       
    25 #include <f32file.h>
       
    26 
       
    27 #define PRINTF gAutoTest->Printf
       
    28 
       
    29 /**
       
    30  * Latest version can always be found here:
       
    31  * //EPOC/development/personal/alfredh/autotest/...
       
    32  *
       
    33  * Revision history
       
    34  *
       
    35  * 0.04 Merged with RefTsy and SmsStack
       
    36  * 0.03 imported to C32
       
    37  * 0.02 imported to SmsStack
       
    38  * 0.01 first version used in RefTSY
       
    39  */
       
    40 
       
    41 //
       
    42 // prototypes
       
    43 //
       
    44 
       
    45 
       
    46 /**
       
    47  * contains information about one test case, including
       
    48  * name of test case and pointer to the test function
       
    49  *
       
    50  * @internalComponent
       
    51  * @deprecated
       
    52  */
       
    53 struct TAutoTestCase
       
    54 	{
       
    55 	void (*iFunc)(void);   //< function pointer to the actual test case
       
    56 	const TText* iText;    //< textual info about the test case
       
    57 	};
       
    58 
       
    59 static const TInt KMaxCmdLength = 256;
       
    60 
       
    61 /**
       
    62  * This class implements the automated test framework.
       
    63  * It is very simple but lets you run all the test cases
       
    64  * separately or in one go.
       
    65  *
       
    66  * @internalComponent
       
    67  * @deprecated
       
    68  */
       
    69 class CAutoTest : public CBase
       
    70 	{
       
    71   public:
       
    72 	IMPORT_C static CAutoTest* NewL(const struct TAutoTestCase* aTestcases, TInt aNumberOfTestcases, const TDesC& aName, RTest& aTest);
       
    73 	~CAutoTest();
       
    74 	IMPORT_C TInt ExecuteL();
       
    75 	IMPORT_C void TestCheckPointL(TBool aCase, char* aFile, TInt aLine);
       
    76 	IMPORT_C void TestCheckPointCodeL(TInt aCase, char* aFile, TInt aLine);
       
    77 	IMPORT_C void TestCheckPointCompareL(TInt aVal,TInt aExpectedVal, const TDesC& aText, char* aFile,TInt aLine);
       
    78 	IMPORT_C void SetCompInfo(const TDesC8& aCompInfo);
       
    79 	IMPORT_C void GetString(CConsoleBase& aConsole, TDes& aString) const;
       
    80 	IMPORT_C void LogExtra(const TText8* aFile, TInt aLine, TRefByValue<const TDesC> aFmt,...);
       
    81 	IMPORT_C void Printf(TRefByValue<const TDesC> aFmt,...);
       
    82 	IMPORT_C TBool KeepGoing(void);
       
    83 
       
    84   protected:
       
    85 	CAutoTest(const struct TAutoTestCase* aTestcases, TInt aNumberOfTestcases, const TDesC& aName, RTest& aTest);
       
    86 	void ConstructL();
       
    87 	
       
    88   protected:
       
    89 	void PrintMenu() const;
       
    90 	void StartMenuL();
       
    91 	void RunAllTestsL();
       
    92 	TInt RunATestL();
       
    93 	void PrintTestReportL(TInt aTestIndex);
       
    94 	void LogTimeL();
       
    95 	void MachineInfoL();
       
    96 	void PrintThreadsToLogFile();
       
    97 	void SetLogFileL();
       
    98 	const TBool TestSkipped(TUint8 aTestNum);
       
    99 	void GetCommandLineL();
       
   100 	void GetSkipOptions();
       
   101 	void GetKeepGoingOption();
       
   102 
       
   103   private:
       
   104 
       
   105   private:
       
   106 	const struct TAutoTestCase* iTestCases; //< pointer to table with all the test cases
       
   107 	const TInt iNumberOfTestcases;			//< number of test cases in the table
       
   108 	TBuf<KMaxCmdLength> iTestReportName;	//< holds the name of the test report file
       
   109 	TBool iKeepGoing;						//< if true, does not stop if a test fails, but continues
       
   110 	TBool iTestSuiteFailed;					//< indicates if the whole test suite failed or not
       
   111 	TInt* iTestResults;						//< contains all the test results after running test suite
       
   112 	RFs iFileServer;						//< handle to the File Server
       
   113 	RFile iTestReport;						//< handle to the file containing the test report
       
   114 	TInt iTestCase;							//< the test case currently being run
       
   115 	TBuf8<256> iCompInfo;					//< contains information about the Component under test
       
   116 	RTest& iRTest;							//< reference to the test utility class
       
   117 	TBool* iSkipList;						//< List of tests to be skipped in decimal
       
   118 	HBufC* iCommandLine;					//< Internal copy of command line or config file
       
   119 	};
       
   120 
       
   121 //
       
   122 // macros
       
   123 //
       
   124 
       
   125 /**
       
   126  * call this macro to start the automated test framework.
       
   127  *
       
   128  * @param tc Table containing the test cases
       
   129  * @param name Name of the test report file
       
   130  */
       
   131 // Global pointer instance version
       
   132 #define GLOBAL_AUTOTEST_EXECUTE(tc, name, compinfo, test) \
       
   133 gAutoTest = CAutoTest::NewL((tc), sizeof(tc)/sizeof((tc)[0]), name, test); \
       
   134 CleanupStack::PushL(gAutoTest);\
       
   135 gAutoTest->SetCompInfo(compinfo); \
       
   136 gAutoTest->ExecuteL(); \
       
   137 CleanupStack::PopAndDestroy(); 
       
   138 
       
   139 // Stack version
       
   140 #define AUTOTEST_EXECUTE(tc, name, compinfo, test) \
       
   141 CAutoTest* autoTest = CAutoTest::NewL((tc), sizeof(tc)/sizeof((tc)[0]), name, test); \
       
   142 CleanupStack::PushL(autoTest);\
       
   143 autoTest->SetCompInfo(compinfo); \
       
   144 autoTest->ExecuteL(); \
       
   145 CleanupStack::PopAndDestroy(); 
       
   146 
       
   147 // Global checkpoint versions
       
   148 // Writes failure with the error code to file. 'a' is the error code
       
   149 #define GLOBAL_CHECKPOINT_CODE(a) gAutoTest->TestCheckPointCodeL((a), (__FILE__), (__LINE__))
       
   150 // Writes failure only to file. 'a' Parameter is boolean
       
   151 #define GLOBAL_CHECKPOINT(a) gAutoTest->TestCheckPointL((a), (__FILE__), (__LINE__))
       
   152 // Compare expected value a with b. If they're different, string C is logged along with the values
       
   153 #define GLOBAL_CHECKPOINT_COMPARE(a,b,c) gAutoTest->TestCheckPointCompareL((a),(b),(c),(__FILE__),(__LINE__))
       
   154 #endif // E32AUTOTEST_H__