commonappservices/alarmserver/Test/testhelpers.h
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 2003-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 // AlarmServer Test Helper module
       
    15 // 
       
    16 //
       
    17 
       
    18 #ifndef __TEST_HELPERS__
       
    19 #define __TEST_HELPERS__
       
    20 
       
    21 #include <e32test.h>
       
    22 
       
    23 
       
    24 #define PUSH(x) CleanupStack::PushL(x)
       
    25 #define POP(x)  CleanupStack::Pop(x)
       
    26 #define POPD(x) CleanupStack::PopAndDestroy(x)
       
    27 
       
    28 // Logging macros //
       
    29 GLDEF_C RTest test(KTestName);
       
    30 int __NB_ERR;
       
    31 int __NB_failures = 0;
       
    32 
       
    33 _LIT(KNBTestSmile, "\n{°±°}");
       
    34 _LIT(KNBTestNoErrMask, "%s(%d) : runtime error: Function '%s' returned %d\n");
       
    35 _LIT(KNBTestTrapMask,  "%s(%d) : runtime error: Function '%s' left with code %d\n");
       
    36 _LIT(KNBTestTrueMask,  "%s(%d) : runtime error: Statement '%s' equals %d\n");
       
    37 
       
    38 
       
    39 #ifndef max
       
    40 #define max(a,b)            (((a) > (b)) ? (a) : (b))
       
    41 #endif
       
    42 
       
    43 
       
    44 #define __ttv(x, c, l, f, val, leave)  \
       
    45 	if (x != val) \
       
    46 	__NB_PRINT_ERROR(KNBTestTrueMask, x, _S(c), l,_S(f), leave)
       
    47 
       
    48 #define TESTVALUE(x, val)  __ttv(x, #x, __LINE__,__FILE__,val,EFalse)
       
    49 #define TESTVALUEL(x, val) __ttv(x, #x, __LINE__,__FILE__,val,ETrue)
       
    50 
       
    51 
       
    52 #define __ttr(x, c, l, f, leave)  \
       
    53 	if (x == EFalse) \
       
    54 	__NB_PRINT_ERROR(KNBTestTrueMask, x, _S(c), l,_S(f), leave)
       
    55 
       
    56 #define TESTTRUE(x)  __ttr(x, #x, __LINE__,__FILE__,EFalse)
       
    57 #define TESTTRUEL(x) __ttr(x, #x, __LINE__,__FILE__,ETrue)
       
    58 
       
    59 #define __ttt(x, c, l, f, leave)  \
       
    60 	if (x != KErrNone) \
       
    61 	__NB_PRINT_ERROR(KNBTestNoErrMask, x, _S(c), l,_S(f), leave)
       
    62 
       
    63 #define TESTNOERR(x)  __ttt(x, #x, __LINE__,__FILE__, EFalse)
       
    64 #define TESTNOERRL(x) __ttt(x, #x, __LINE__,__FILE__, ETrue) 		
       
    65 
       
    66 #define __ttp(x, c, l, f, leave)		\
       
    67 	TRAP(__NB_ERR, x);		\
       
    68 	if (__NB_ERR != KErrNone)	\
       
    69 	  __NB_PRINT_ERROR(KNBTestTrapMask, __NB_ERR, _S(c), l,_S(f), leave)
       
    70 
       
    71 #define TESTTRAP(x)  __ttp(x, #x, __LINE__,__FILE__, EFalse)
       
    72 #define TESTTRAPL(x) __ttp(x, #x, __LINE__,__FILE__, ETrue)
       
    73 
       
    74 GLDEF_C void __NB_PRINT_ERROR(const TDesC& aMask, TInt aResult, const TText* aCommand, TInt aLineNum,const TText* aFileName, TBool leave = EFalse)
       
    75 	{
       
    76 	TBuf<0x400> str;
       
    77 	str.Format(aMask, aFileName, aLineNum, aCommand, aResult);
       
    78 	test.Printf(KNBTestSmile);
       
    79 	test.Printf(str);
       
    80 	if (leave)
       
    81 		User::Leave(aResult < 0 ? aResult : KErrUnknown);
       
    82 	else
       
    83 		++__NB_failures;
       
    84 	}
       
    85 //
       
    86 
       
    87 
       
    88 
       
    89 
       
    90 
       
    91 
       
    92 #endif //__TEST_HELPERS__