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