ximpfw/tsrc/tsrcutils/eunitcommon/eunittools.h
changeset 0 e6b17d312c8b
child 41 eedf17a17c27
equal deleted inserted replaced
-1:000000000000 0:e6b17d312c8b
       
     1 /*
       
     2 * Copyright (c) 2006 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: XIMP Framework Test Code 
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef EUNITTOOLS_H
       
    19 #define EUNITTOOLS_H
       
    20 
       
    21 #include <e32std.h>
       
    22 #include <eunitmacros.h>
       
    23 #include <ceunittestcasedecorator.h>
       
    24 #include <ceunitalloctestcasedecorator.h>
       
    25 #include <ceunitemptytestcasedecorator.h>
       
    26 #include "cglobalwaitingnote.h"
       
    27 
       
    28 
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // ASSERTION HELPER
       
    32 // Leaves if the provided error code is decorator error.
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 #define LEAVE_IF_DECORATOR_ERROR( aErr ) \
       
    36     { \
       
    37     if( aErr == KErrNoMemory ) \
       
    38         { \
       
    39         User::Leave( KErrNoMemory ); \
       
    40         } \
       
    41     }
       
    42 
       
    43 
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // ASSERTION HELPER
       
    47 // Returns from current function if the provided error code is decorator error.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 #define RETURN_IF_DECORATOR_ERROR( aErr ) \
       
    51     { \
       
    52     if( aErr == KErrNoMemory ) \
       
    53         { \
       
    54         return KErrNoMemory; \
       
    55         } \
       
    56     }
       
    57 
       
    58 
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // MEMORY LEAK TRACKING HELPER
       
    62 // Performs __UHEAP_MARK and shows visual notify.
       
    63 // (Visual notify gives time to reset HookLogger heap checks.)
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 #define __UHEAP_MARK_WITH_VISUAL_NOTIFY \
       
    67     { \
       
    68     __UHEAP_MARK; \
       
    69     EUnitTools::NotifyFromTestEnterL(); \
       
    70     }
       
    71 
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // MEMORY LEAK TRACKING HELPER
       
    75 // Performs __UHEAP_MARKEND with JIT debugger on.
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 #define __UHEAP_MARKEND_WITH_DEBUGGER \
       
    79     { \
       
    80     TBool __justInTime = User::JustInTime(); \
       
    81     User::SetJustInTime( ETrue ); \
       
    82     __UHEAP_MARKEND; \
       
    83     User::SetJustInTime( __justInTime ); \
       
    84     }
       
    85 
       
    86 
       
    87 
       
    88 
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // TEST CASE DECLARATION
       
    92 // Defines not decorated test case.
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 #define PRFW_NOT_DECORATED_TEST( aDescription, aClass, aMethods, aCategory, aSetupMethod, aTestMethod, aTeardownMethod )\
       
    96 EUNIT_NOT_DECORATED_TEST( aDescription, aClass, aMethods, aCategory, aSetupMethod, aTestMethod, aTeardownMethod )
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // TEST CASE DECLARATION
       
   100 // Defines decorated test case.
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 #define PRFW_DECORATED_TEST( aDescription, aClass, aMethods, aCategory, aSetupMethod, aTestMethod, aTeardownMethod )\
       
   104 EUNIT_TEST( aDescription, aClass, aMethods, aCategory, aSetupMethod, aTestMethod, aTeardownMethod )
       
   105 
       
   106 #define PRFW_ASSERT_DESC( aCondition, aDescription ) \
       
   107     if ( aCondition ) { } else { \
       
   108         TEUnitAssertionInfo __eunit_assert_info = { \
       
   109 			__EUNIT_INTERNAL_ASSERT_BASE( aCondition, aDescription ), \
       
   110         	NULL }; \
       
   111         EUnit::AssertionFailedL( __eunit_assert_info ); }
       
   112 
       
   113 
       
   114 /**
       
   115  * Collection of EUnit Tools
       
   116  */
       
   117 class EUnitTools
       
   118     {
       
   119     public:
       
   120         static inline void NotifyFromTestEnterL();
       
   121 
       
   122     };
       
   123 
       
   124 
       
   125 
       
   126 inline void EUnitTools::NotifyFromTestEnterL()
       
   127     {
       
   128     __UHEAP_MARK;
       
   129 
       
   130     TInt decoratorfailCount = -1;
       
   131     CEUnitTestCaseDecorator* decorator = CEUnitTestCaseDecorator::ActiveTestCaseDecorator( KNullDesC ); //Any decorator
       
   132     if( decorator )
       
   133         {
       
   134         decorator->GetParameter( _L("ErrorCount"), //Run loop counter value
       
   135                                  decoratorfailCount );
       
   136         }
       
   137 
       
   138     if( !decorator ||
       
   139         ( decoratorfailCount == 1 ) )
       
   140         {
       
   141         EUNIT_DISABLE_ANY_DECORATOR;
       
   142 
       
   143         TFileName processImage = RProcess().FileName();
       
   144         TBuf<350> msg;
       
   145         msg.Append( _L("Entering to test case. Test process:") );
       
   146         msg.Append( processImage );
       
   147 
       
   148         CGlobalWaitingNote::ShowMsgL( msg, 15000000, 15 );  //15 seconds, 1 second steps
       
   149 
       
   150         EUNIT_ENABLE_ANY_DECORATOR;
       
   151         }
       
   152     }
       
   153 
       
   154 
       
   155 
       
   156 #endif // EUNITTOOLS_H
       
   157 
       
   158 
       
   159 
       
   160 //  end of file
       
   161 
       
   162 
       
   163 
       
   164