testexecfw/symbianunittestfw/symbianunittestfw_pub/symbian_unit_test_api/inc/symbianunittestmacros.h
changeset 1 bbd31066657e
parent 0 3e07fef1e154
equal deleted inserted replaced
0:3e07fef1e154 1:bbd31066657e
    22 #include <e32std.h>
    22 #include <e32std.h>
    23 
    23 
    24 // MACROS
    24 // MACROS
    25 #ifdef SYMBIAN_UNIT_TEST
    25 #ifdef SYMBIAN_UNIT_TEST
    26 
    26 
       
    27     inline TInt operator==( TTrue, TInt aInt )
       
    28         {
       
    29         return aInt;
       
    30         }
       
    31 
       
    32     inline TInt operator==( TInt aInt, TTrue )
       
    33         {
       
    34         return aInt;
       
    35         }
       
    36 
       
    37     inline TInt operator!=( TTrue, TInt aInt )
       
    38         {
       
    39         return !aInt;
       
    40         }
       
    41 
       
    42     inline TInt operator!=( TInt aInt, TTrue )
       
    43         {
       
    44         return !aInt;
       
    45         }
       
    46 
       
    47     
    27     /** 
    48     /** 
    28     * Calls the base class constructor that sets the name of unit test.
    49     * Calls the base class constructor that sets the name of unit test.
    29     */
    50     */
    30     #define BASE_CONSTRUCT\
    51     #define BASE_CONSTRUCT\
    31         CSymbianUnitTest::ConstructL( _L8( __PRETTY_FUNCTION__ ) );
    52         CSymbianUnitTest::ConstructL( _L8( __PRETTY_FUNCTION__ ) );
    33     /**
    54     /**
    34     * Adds a new unit test case to this unit test.
    55     * Adds a new unit test case to this unit test.
    35     * The default setup and teardown functions will be used.
    56     * The default setup and teardown functions will be used.
    36     * @param aTestPtr a function pointer to the unit test case
    57     * @param aTestPtr a function pointer to the unit test case
    37     */
    58     */
    38     #define ADD_SUT( aTestPtr )\
    59     #ifndef __GCCE__
    39         AddTestCaseL(\
    60         #define ADD_SUT( aTestPtr )\
    40             _L( #aTestPtr ),\
    61             AddTestCaseL(\
    41             CSymbianUnitTest::FunctionPtr( SetupL ),\
    62                 _L( #aTestPtr ),\
    42             CSymbianUnitTest::FunctionPtr( aTestPtr ),\
    63                 CSymbianUnitTest::FunctionPtr( SetupL ),\
    43             CSymbianUnitTest::FunctionPtr( Teardown ) );
    64                 CSymbianUnitTest::FunctionPtr(aTestPtr),\
       
    65                 CSymbianUnitTest::FunctionPtr( Teardown ) );
       
    66             
       
    67     #else
       
    68         #define ADD_SUT( aTestPtr )\
       
    69             AddTestCaseL(\
       
    70                 _L( #aTestPtr ),\
       
    71                 CSymbianUnitTest::FunctionPtr( &CSymbianUnitTest::SetupL ),\
       
    72                 CSymbianUnitTest::FunctionPtr(&TYPE::aTestPtr),\
       
    73                 CSymbianUnitTest::FunctionPtr( &CSymbianUnitTest::Teardown ) );
       
    74     #endif
       
    75             
    44 
    76 
    45     /**
    77     /**
    46     * Adds a new unit test case to this unit test.
    78     * Adds a new unit test case to this unit test.
    47     * The user can specify
    79     * The user can specify
    48     * @param aSetupPtr a function pointer to the setup function 
    80     * @param aSetupPtr a function pointer to the setup function 
    49     *        that will be executed before the actual unit test case
    81     *        that will be executed before the actual unit test case
    50     * @param aTestPtr a function pointer to the unit test case
    82     * @param aTestPtr a function pointer to the unit test case
    51     * @param aTeardownPtr a function pointer to the teardown function
    83     * @param aTeardownPtr a function pointer to the teardown function
    52     *        that will be executed after the actual unit test case
    84     *        that will be executed after the actual unit test case
    53     */
    85     */
    54     #define ADD_SUT_WITH_SETUP_AND_TEARDOWN( aSetupPtr, aTestPtr, aTeardownPtr )\
    86     #ifndef __GCCE__
    55         AddTestCaseL(\
    87         #define ADD_SUT_WITH_SETUP_AND_TEARDOWN( aSetupPtr, aTestPtr, aTeardownPtr )\
    56             _L( #aTestPtr ),\
    88             AddTestCaseL(\
    57             CSymbianUnitTest::FunctionPtr( aSetupPtr ),\
    89                 _L( #aTestPtr ),\
    58             CSymbianUnitTest::FunctionPtr( aTestPtr ),\
    90                 CSymbianUnitTest::FunctionPtr( aSetupPtr ),\
    59             CSymbianUnitTest::FunctionPtr( aTeardownPtr ) );
    91                 CSymbianUnitTest::FunctionPtr( aTestPtr ),\
       
    92                 CSymbianUnitTest::FunctionPtr( aTeardownPtr ) );
       
    93      #else
       
    94          #define ADD_SUT_WITH_SETUP_AND_TEARDOWN( aSetupPtr, aTestPtr, aTeardownPtr )\
       
    95             AddTestCaseL(\
       
    96                 _L( #aTestPtr ),\
       
    97                 CSymbianUnitTest::FunctionPtr( &TYPE::aSetupPtr ),\
       
    98                 CSymbianUnitTest::FunctionPtr( &TYPE::aTestPtr ),\
       
    99                 CSymbianUnitTest::FunctionPtr( &TYPE::aTeardownPtr ) );
       
   100      
       
   101      #endif
    60 
   102 
    61     /**
   103     /**
    62     * Asserts a condition in a unit test case.
   104     * Asserts a condition in a unit test case.
    63     * Leaves with a Symbian unit test framework specific error code
   105     * Leaves with a Symbian unit test framework specific error code
    64     * if the condition evaluates to EFalse.
   106     * if the condition evaluates to EFalse.
    65     * In case of a failed assertion, the framework records 
   107     * In case of a failed assertion, the framework records 
    66     * the failure reason, line number and file name to the test results.
   108     * the failure reason, line number and file name to the test results.
    67     * @param aCondition the asserted condition.
   109     * @param aCondition the asserted condition.
    68     */
   110     */
       
   111     
       
   112        
    69     #define SUT_ASSERT( aCondition )\
   113     #define SUT_ASSERT( aCondition )\
    70         if ( !TBool( aCondition ) )\
   114         if ( aCondition ) {} else\
    71             {\
   115             {\
    72             AssertionFailedL( _L8( #aCondition ), __LINE__, _L8( __FILE__ ) );\
   116             AssertionFailedL( _L8( #aCondition ), __LINE__, _L8( __FILE__ ) );\
    73             }
   117             }
    74 
   118 
       
   119    /**
       
   120     * Asserts a condition in a unit test case.
       
   121     * Leaves with a Symbian unit test framework specific error code
       
   122     * if the condition evaluates to EFalse.
       
   123     * In case of a failed assertion, the framework records 
       
   124     * the failure reason, line number and file name to the test results.
       
   125     * @param aCondition the asserted condition.
       
   126     * @param aDescription the error description
       
   127     */
       
   128     
       
   129        
       
   130     #define SUT_ASSERT_DESC( aCondition, aDescription )\
       
   131         if ( aCondition ) {} else\
       
   132             {\
       
   133             AssertionFailedL( _L8( aDescription ), __LINE__, _L8( __FILE__ ) );\
       
   134             }
       
   135 
       
   136 
    75     /**
   137     /**
    76     * Asserts that two values are equal.
   138     * Asserts that two values are equal.
    77     * Leaves with a Symbian unit test framework specific error code
   139     * Leaves with a Symbian unit test framework specific error code
    78     * if the values are not equal.
   140     * if the values are not equal.
    79     * In case of a failed assertion, the framework records 
   141     * In case of a failed assertion, the framework records 
    81     * @param aExpectedValue the expected value
   143     * @param aExpectedValue the expected value
    82     * @param aActualValue the actual value
   144     * @param aActualValue the actual value
    83     */
   145     */
    84     #define SUT_ASSERT_EQUALS( aExpected, aActual )\
   146     #define SUT_ASSERT_EQUALS( aExpected, aActual )\
    85         AssertEqualsL( aExpected, aActual, __LINE__, _L8( __FILE__ ) );
   147         AssertEqualsL( aExpected, aActual, __LINE__, _L8( __FILE__ ) );
       
   148 
       
   149     /**
       
   150     * Asserts that two values are equal.
       
   151     * Leaves with a Symbian unit test framework specific error code
       
   152     * if the values are not equal.
       
   153     * In case of a failed assertion, the framework records 
       
   154     * the failure reason, line number and file name to the test results.
       
   155     * @param aExpectedValue the expected value
       
   156     * @param aActualValue the actual value
       
   157     * @param aDescription the error description
       
   158     */
       
   159     #define SUT_ASSERT_EQUALS_DESC( aExpected, aActual, aDescription )\
       
   160         AssertEqualsL( aExpected, aActual, __LINE__, _L8( __FILE__ ), _L8(aDescription) );
    86 
   161 
    87     /**
   162     /**
    88     * Asserts that a statement leaves an expected value.
   163     * Asserts that a statement leaves an expected value.
    89     * Leaves with a Symbian unit test framework specific error code
   164     * Leaves with a Symbian unit test framework specific error code
    90     * if the leave code is not the expected one.
   165     * if the leave code is not the expected one.
   115     * @param aStatement the statement
   190     * @param aStatement the statement
   116     */
   191     */
   117     #define SUT_ASSERT_LEAVE( aStatement )\
   192     #define SUT_ASSERT_LEAVE( aStatement )\
   118         {\
   193         {\
   119         TInt KLine( __LINE__ );\
   194         TInt KLine( __LINE__ );\
   120         TBool leaveOccured( ETrue );\
   195         TRAPD( err, aStatement)\
   121         TRAPD( err, aStatement; leaveOccured = EFalse; )\
   196         if ( err==KErrNone )\
   122         if ( !leaveOccured )\
       
   123             {\
   197             {\
   124             RecordNoLeaveFromStatementL( _L8( #aStatement ), KLine, _L8( __FILE__ ) );\
   198             RecordNoLeaveFromStatementL( _L8( #aStatement ), KLine, _L8( __FILE__ ) );\
   125             }\
   199             }\
   126         }
   200         }
       
   201         
   127 
   202 
   128     /**
   203     /**
   129     * Can be used to hide the friend declaration for a unit test class.
   204     * Can be used to hide the friend declaration for a unit test class.
   130     */
   205     */
   131     #define SYMBIAN_UNIT_TEST_CLASS( ClassName ) friend class ClassName;
   206     #define SYMBIAN_UNIT_TEST_CLASS( ClassName ) friend class ClassName;
       
   207             
       
   208     #define DEFINE_TEST_CLASS( aClassName )\
       
   209         typedef aClassName TYPE;
       
   210     
       
   211     
   132 #else 
   212 #else 
   133     #define SYMBIAN_UNIT_TEST_CLASS( ClassName )
   213     #define SYMBIAN_UNIT_TEST_CLASS( ClassName )
   134 #endif // SYMBIAN_UNIT_TEST
   214 #endif // SYMBIAN_UNIT_TEST
   135 
   215 
   136 #endif // SYMBIANUNITTESTMACROS_H
   216 #endif // SYMBIANUNITTESTMACROS_H