summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/tsrc/nbcnttestlib/testhelpers.h
blob: 0f732822663e56c6738deb059670273c245c74c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
* Contact: http://www.qt-project.org/legal
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
* TestHelpers Test module
*
*/



#ifndef __TEST_HELPERS__
#define __TEST_HELPERS__

#include <e32test.h>


#define PUSH(x) CleanupStack::PushL(x)
#define POP(x)  CleanupStack::Pop(x)
#define POPD(x) CleanupStack::PopAndDestroy(x); x = NULL;

//////////// Logging macros ///////////////
GLDEF_C RTest test(KTestName);
//int __NB_ERR;
int __NB_failures = 0;

_LIT(KNBTestSmile, "\n{°±°}");
_LIT(KNBTestNoErrMask, "%s(%d) : runtime error: Function '%s' returned %d\n");
_LIT(KNBTestTrapMask,  "%s(%d) : runtime error: Function '%s' left with code %d\n");
_LIT(KNBTestTrueMask,  "%s(%d) : runtime error: Statement '%s' equals %d\n");


#ifndef max
#define max(a,b)            (((a) > (b)) ? (a) : (b))
#endif


#define __ttv(x, c, l, f, val, leave)  \
	{const TInt __NB_ERR = x;	 \
	if (__NB_ERR != val) \
		__NB_PRINT_ERROR(KNBTestTrueMask, __NB_ERR, _S(c), l,_S(f), leave);}

#define TESTVALUE(x, val)  __ttv(x, #x, __LINE__,__FILE__,val,EFalse)
#define TESTVALUEL(x, val) __ttv(x, #x, __LINE__,__FILE__,val,ETrue)


#define __ttr(x, c, l, f, leave)  \
	{TBool __NB_ERR = x;	 \
	if (__NB_ERR == EFalse) \
	{__NB_PRINT_ERROR(KNBTestTrueMask, __NB_ERR, _S(c), l,_S(f), leave);} }

#define TESTTRUE(x)  __ttr(x, #x, __LINE__,__FILE__,EFalse)
#define TESTTRUEL(x) __ttr(x, #x, __LINE__,__FILE__,ETrue)

#define __ttt(x, c, l, f, leave)  \
	{const TInt __NB_ERR = x;     \
	if (__NB_ERR != KErrNone)	  \
		__NB_PRINT_ERROR(KNBTestNoErrMask, __NB_ERR, _S(c), l,_S(f), leave);}

#define TESTNOERR(x)  __ttt(x, #x, __LINE__,__FILE__, EFalse)
#define TESTNOERRL(x) __ttt(x, #x, __LINE__,__FILE__, ETrue) 		

#define __ttp(x, c, l, f, leave)		\
	{TRAPD(__NB_ERR, x);		\
	if (__NB_ERR != KErrNone)	\
		__NB_PRINT_ERROR(KNBTestTrapMask, __NB_ERR, _S(c), l,_S(f), leave);}

#define TESTTRAP(x)  __ttp(x, #x, __LINE__,__FILE__, EFalse)
#define TESTTRAPL(x) __ttp(x, #x, __LINE__,__FILE__, ETrue)

GLDEF_C void __NB_PRINT_ERROR(const TDesC& aMask, TInt aResult, const TText* aCommand, TInt aLineNum,const TText* aFileName, TBool leave = EFalse)
	{
	TBuf<0x400> str;
	str.Format(aMask, aFileName, aLineNum, aCommand, aResult);
	test.Printf(KNBTestSmile);
	test.Printf(str);
	if (leave)
		User::Leave(aResult < 0 ? aResult : KErrUnknown);
	else
		++__NB_failures;
	}
///////////////////////////////////////////////






#endif //__TEST_HELPERS__