testexecfw/symbianunittestfw/symbianunittestfw_pub/symbian_unit_test_api/inc/symbianunittestmacros.h
changeset 0 3e07fef1e154
child 1 bbd31066657e
equal deleted inserted replaced
-1:000000000000 0:3e07fef1e154
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef SYMBIANUNITTESTMACROS_H
       
    19 #define SYMBIANUNITTESTMACROS_H
       
    20 
       
    21 // INCLUDES
       
    22 #include <e32std.h>
       
    23 
       
    24 // MACROS
       
    25 #ifdef SYMBIAN_UNIT_TEST
       
    26 
       
    27     /** 
       
    28     * Calls the base class constructor that sets the name of unit test.
       
    29     */
       
    30     #define BASE_CONSTRUCT\
       
    31         CSymbianUnitTest::ConstructL( _L8( __PRETTY_FUNCTION__ ) );
       
    32 
       
    33     /**
       
    34     * Adds a new unit test case to this unit test.
       
    35     * The default setup and teardown functions will be used.
       
    36     * @param aTestPtr a function pointer to the unit test case
       
    37     */
       
    38     #define ADD_SUT( aTestPtr )\
       
    39         AddTestCaseL(\
       
    40             _L( #aTestPtr ),\
       
    41             CSymbianUnitTest::FunctionPtr( SetupL ),\
       
    42             CSymbianUnitTest::FunctionPtr( aTestPtr ),\
       
    43             CSymbianUnitTest::FunctionPtr( Teardown ) );
       
    44 
       
    45     /**
       
    46     * Adds a new unit test case to this unit test.
       
    47     * The user can specify
       
    48     * @param aSetupPtr a function pointer to the setup function 
       
    49     *        that will be executed before the actual unit test case
       
    50     * @param aTestPtr a function pointer to the unit test case
       
    51     * @param aTeardownPtr a function pointer to the teardown function
       
    52     *        that will be executed after the actual unit test case
       
    53     */
       
    54     #define ADD_SUT_WITH_SETUP_AND_TEARDOWN( aSetupPtr, aTestPtr, aTeardownPtr )\
       
    55         AddTestCaseL(\
       
    56             _L( #aTestPtr ),\
       
    57             CSymbianUnitTest::FunctionPtr( aSetupPtr ),\
       
    58             CSymbianUnitTest::FunctionPtr( aTestPtr ),\
       
    59             CSymbianUnitTest::FunctionPtr( aTeardownPtr ) );
       
    60 
       
    61     /**
       
    62     * Asserts a condition in a unit test case.
       
    63     * Leaves with a Symbian unit test framework specific error code
       
    64     * if the condition evaluates to EFalse.
       
    65     * In case of a failed assertion, the framework records 
       
    66     * the failure reason, line number and file name to the test results.
       
    67     * @param aCondition the asserted condition.
       
    68     */
       
    69     #define SUT_ASSERT( aCondition )\
       
    70         if ( !TBool( aCondition ) )\
       
    71             {\
       
    72             AssertionFailedL( _L8( #aCondition ), __LINE__, _L8( __FILE__ ) );\
       
    73             }
       
    74 
       
    75     /**
       
    76     * Asserts that two values are equal.
       
    77     * Leaves with a Symbian unit test framework specific error code
       
    78     * if the values are not equal.
       
    79     * In case of a failed assertion, the framework records 
       
    80     * the failure reason, line number and file name to the test results.
       
    81     * @param aExpectedValue the expected value
       
    82     * @param aActualValue the actual value
       
    83     */
       
    84     #define SUT_ASSERT_EQUALS( aExpected, aActual )\
       
    85         AssertEqualsL( aExpected, aActual, __LINE__, _L8( __FILE__ ) );
       
    86 
       
    87     /**
       
    88     * Asserts that a statement leaves an expected value.
       
    89     * Leaves with a Symbian unit test framework specific error code
       
    90     * if the leave code is not the expected one.
       
    91     * In case of a failed assertion, the framework records 
       
    92     * the failure reason, line number and file name to the test results.
       
    93     * @param aStatement the statement
       
    94     * @param aError the expected leave code
       
    95     */
       
    96     #define SUT_ASSERT_LEAVE_WITH( aStatement, aError )\
       
    97         {\
       
    98         TInt KLine( __LINE__ );\
       
    99         TRAPD( err, aStatement )\
       
   100         AssertLeaveL( _L8( #aStatement ), err, aError, KLine, _L8( __FILE__ ) );\
       
   101         }
       
   102 
       
   103     /**
       
   104     * Asserts that a statement leaves.
       
   105     * The macro itself leaves with a Symbian unit test framework 
       
   106     * specific error code if the statement leaves.
       
   107     * In case of a failed assertion, the framework records 
       
   108     * the failure reason, the line number and file name to the test results.
       
   109     *
       
   110     * Note: SUT_ASSERT_LEAVE_WITH should be used instead 
       
   111     * whenever possible, because the implementation of 
       
   112     * SYMBIAN_UT_ASSERT_LEAVE TRAPs also KErrNoMemory.
       
   113     * This means that all the memory allocations are not looped through 
       
   114     * during the memory allocation failure simulation.
       
   115     * @param aStatement the statement
       
   116     */
       
   117     #define SUT_ASSERT_LEAVE( aStatement )\
       
   118         {\
       
   119         TInt KLine( __LINE__ );\
       
   120         TBool leaveOccured( ETrue );\
       
   121         TRAPD( err, aStatement; leaveOccured = EFalse; )\
       
   122         if ( !leaveOccured )\
       
   123             {\
       
   124             RecordNoLeaveFromStatementL( _L8( #aStatement ), KLine, _L8( __FILE__ ) );\
       
   125             }\
       
   126         }
       
   127 
       
   128     /**
       
   129     * Can be used to hide the friend declaration for a unit test class.
       
   130     */
       
   131     #define SYMBIAN_UNIT_TEST_CLASS( ClassName ) friend class ClassName;
       
   132 #else 
       
   133     #define SYMBIAN_UNIT_TEST_CLASS( ClassName )
       
   134 #endif // SYMBIAN_UNIT_TEST
       
   135 
       
   136 #endif // SYMBIANUNITTESTMACROS_H