0
|
1 |
// Copyright (c) 1994-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 the License "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 |
// e32\include\e32test.h
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
/**
|
|
19 |
@file e32test.h
|
|
20 |
@publishedAll
|
|
21 |
@released
|
|
22 |
*/
|
|
23 |
|
|
24 |
#ifndef __E32TEST_H__
|
|
25 |
#define __E32TEST_H__
|
|
26 |
#include <e32std.h>
|
|
27 |
#ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
|
|
28 |
#include <e32std_private.h>
|
|
29 |
#include <e32base_private.h>
|
|
30 |
#endif
|
|
31 |
#include <e32base.h>
|
|
32 |
#include <e32cons.h>
|
|
33 |
#include <e32kpan.h>
|
|
34 |
#include <e32debug.h>
|
|
35 |
#ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
|
|
36 |
#include <e32def_private.h>
|
|
37 |
#include <e32event_private.h>
|
|
38 |
#endif
|
|
39 |
|
|
40 |
|
|
41 |
/**
|
|
42 |
Test console.
|
|
43 |
|
|
44 |
The class creates a console window to which test results can be logged
|
|
45 |
through the various overloads of the operator().
|
|
46 |
*/
|
|
47 |
class RTest
|
|
48 |
{
|
|
49 |
public:
|
|
50 |
IMPORT_C RTest(const TDesC &aTitle,TInt aThrowaway,const TText* anOtherThrowaway);
|
|
51 |
IMPORT_C RTest(const TDesC &aTitle,TInt aThrowaway);
|
|
52 |
IMPORT_C RTest(const TDesC &aTitle);
|
|
53 |
IMPORT_C void Close();
|
|
54 |
IMPORT_C void Title();
|
|
55 |
IMPORT_C void Start(const TDesC &aHeading);
|
|
56 |
IMPORT_C void Next(const TDesC &aHeading);
|
|
57 |
IMPORT_C void End();
|
|
58 |
IMPORT_C void operator()(TInt aResult,TInt aLineNum,const TText* aFileName);
|
|
59 |
IMPORT_C void operator()(TInt aResult,TInt aLineNum);
|
|
60 |
IMPORT_C void operator()(TInt aResult);
|
|
61 |
IMPORT_C void Panic(TInt anError,TRefByValue<const TDesC> aFmt,...);
|
|
62 |
IMPORT_C void Panic(TRefByValue<const TDesC> aFmt,...);
|
|
63 |
IMPORT_C void Printf(TRefByValue<const TDesC> aFmt,...);
|
|
64 |
IMPORT_C TKeyCode Getch();
|
|
65 |
inline static const TAny* String(TInt aSel,const TText8 *aBuf1,const TText16 *aBuf2);
|
|
66 |
inline CConsoleBase* Console() const;
|
|
67 |
inline void SetConsole(CConsoleBase* aConsole);
|
|
68 |
inline TBool Logged() const;
|
|
69 |
inline void SetLogged(TBool aToLog);
|
|
70 |
inline void HandleError(TInt aError, TInt aLine, const TText* aFileName);
|
|
71 |
inline void HandleNull(TInt aLine, const TText* aFileName);
|
|
72 |
inline void HandleNotEqual(TInt aExpected, TInt aActual, TInt aLine, const TText* aFileName);
|
|
73 |
inline void HandleFailedCompare(TInt aLeft, const TText* aComp, TInt aRight, TInt aLine, const TText* aFileName);
|
|
74 |
inline void HandleValue(TInt aValue, TInt aLine, const TText* aFileName);
|
|
75 |
|
|
76 |
IMPORT_C static TInt CloseHandleAndWaitForDestruction(RHandleBase& aH); /**< @internalTechnology */
|
|
77 |
|
|
78 |
protected:
|
|
79 |
void CheckConsoleCreated();
|
|
80 |
void DisplayLevel();
|
|
81 |
inline void Push();
|
|
82 |
inline void Pop();
|
|
83 |
private:
|
|
84 |
enum {EMaxStack=0x100,EMaxBuffer=0x100};
|
|
85 |
private:
|
|
86 |
TInt iTest;
|
|
87 |
TInt iCheck;
|
|
88 |
TInt iLevel;
|
|
89 |
TBool iLogging;
|
|
90 |
CConsoleBase *iConsole;
|
|
91 |
TBuf<0x40> iTitle;
|
|
92 |
TInt iStack[EMaxStack];
|
|
93 |
TText iBuf[EMaxBuffer];
|
|
94 |
};
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
/**
|
|
100 |
Gets the console.
|
|
101 |
|
|
102 |
@return A pointer to the console object.
|
|
103 |
*/
|
|
104 |
inline CConsoleBase* RTest::Console() const
|
|
105 |
{ return(iConsole); }
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
/**
|
|
111 |
Utility function that returns a pointer to the specified TText8* argument
|
|
112 |
or the TText16* argument depending on the value of the aSel argument.
|
|
113 |
|
|
114 |
@param aSel An integer containing the size of a TText8 type or TText16 type.
|
|
115 |
@param aBuf1 A pointer to 8-bit text.
|
|
116 |
@param aBuf2 A pointer to 16-bit text.
|
|
117 |
|
|
118 |
@return A pointer to aBuf1, if the value of aSel is the size of a TText8 type,
|
|
119 |
otherwise a pointer to aBuf2.
|
|
120 |
*/
|
|
121 |
inline const TAny *RTest::String(TInt aSel,const TText8 *aBuf1,const TText16 *aBuf2)
|
|
122 |
{ return(aSel == sizeof(TText8) ? (TAny *)aBuf1 : (TAny *)aBuf2); }
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
/**
|
|
127 |
@internalComponent
|
|
128 |
*/
|
|
129 |
inline void RTest::Push()
|
|
130 |
{ iStack[iLevel++] = iTest; iTest = 0; }
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
/**
|
|
135 |
@internalComponent
|
|
136 |
*/
|
|
137 |
inline void RTest::Pop()
|
|
138 |
{ iTest = iStack[--iLevel]; }
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
/**
|
|
144 |
Sets the console.
|
|
145 |
|
|
146 |
@param aConsole A pointer to the console object to be used.
|
|
147 |
*/
|
|
148 |
inline void RTest::SetConsole(CConsoleBase* aConsole)
|
|
149 |
{ iConsole = aConsole; }
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
/**
|
|
155 |
Tests whether the logging flag is set.
|
|
156 |
|
|
157 |
If the logging flag is set, console output is also written to
|
|
158 |
the debug output as represented by a RDebug object.
|
|
159 |
|
|
160 |
@return True, if the logging flag is set, false otherwise.
|
|
161 |
*/
|
|
162 |
inline TBool RTest::Logged() const
|
|
163 |
{ return(iLogging); }
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
/**
|
|
169 |
Sets the logging flag.
|
|
170 |
|
|
171 |
If the logging flag is set, console output is also written to
|
|
172 |
the debug output as represented by a RDebug object.
|
|
173 |
|
|
174 |
@param aToLog ETrue, if the logging flag is to be set, EFalse, otherwise.
|
|
175 |
*/
|
|
176 |
inline void RTest::SetLogged(TBool aToLog)
|
|
177 |
{ iLogging = aToLog; }
|
|
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
// test equivalent of _L
|
|
183 |
/**
|
|
184 |
@internalComponent
|
|
185 |
*/
|
|
186 |
#define _TL(a) (S*)RTest::String(sizeof(S),(TText8*)a,(TText16*)L ## a)
|
|
187 |
|
|
188 |
// the next two, slightly confusing, macros are necessary in order
|
|
189 |
// to enable proper string merging with certain compilers.
|
|
190 |
|
|
191 |
/**
|
|
192 |
@internalComponent
|
|
193 |
*/
|
|
194 |
#define __test(x,l,f) test(x,l,_S(f))
|
|
195 |
|
|
196 |
/**
|
|
197 |
@internalComponent
|
|
198 |
*/
|
|
199 |
#define test(x) __test(x,__LINE__,__FILE__)
|
|
200 |
|
|
201 |
|
|
202 |
#ifdef __E32TEST_EXTENSION__
|
|
203 |
|
|
204 |
/**
|
|
205 |
@internalComponent
|
|
206 |
*/
|
|
207 |
#define __S(f) _S(f)
|
|
208 |
|
|
209 |
/**
|
|
210 |
@internalComponent
|
|
211 |
|
|
212 |
Panics and displays an appropriate error message if x is less then zero (Indicating an error code).
|
|
213 |
*/
|
|
214 |
#define test_NotNegative(x) { TInt _r = (x); if (_r < 0) test.HandleError(_r, __LINE__,__S(__FILE__)); }
|
|
215 |
|
|
216 |
/**
|
|
217 |
@internalComponent
|
|
218 |
|
|
219 |
Panics and displays an appropriate error message if x is not equal to KErrNone.
|
|
220 |
*/
|
|
221 |
#define test_KErrNone(x) { TInt _r = (x); if (_r !=KErrNone) test.HandleError(_r, __LINE__,__S(__FILE__)); }
|
|
222 |
|
|
223 |
/**
|
|
224 |
@internalComponent
|
|
225 |
|
|
226 |
Panics and displays an appropriate error message if the trapped statement/block x leaves.
|
|
227 |
*/
|
|
228 |
#define test_TRAP(x) { TRAPD(_r, x); if (_r != KErrNone) test.HandleError(_r, __LINE__,__S(__FILE__)); }
|
|
229 |
|
|
230 |
/**
|
|
231 |
@internalComponent
|
|
232 |
|
|
233 |
Panics and displays an appropriate error message if x is not equal to NULL.
|
|
234 |
*/
|
|
235 |
#define test_NotNull(x) { TAny* _a = (TAny*)(x); if (_a == NULL) test.HandleNull(__LINE__,__S(__FILE__)); }
|
|
236 |
/**
|
|
237 |
@internalComponent
|
|
238 |
|
|
239 |
Panics and displays an appropriate error message if e (expected) is not equal to a (actual).
|
|
240 |
*/
|
|
241 |
#define test_Equal(e, a) { TInt _e = TInt(e); TInt _a = TInt(a); if (_e != _a) test.HandleNotEqual(_e, _a, __LINE__,__S(__FILE__)); }
|
|
242 |
|
|
243 |
/**
|
|
244 |
@internalComponent
|
|
245 |
|
|
246 |
Panics and displays an appropriate error message if the comparison specified with operator b, between a and c, is EFalse.
|
|
247 |
*/
|
|
248 |
#define test_Compare(a,b,c) {TInt _a = TInt(a); TInt _c = TInt(c); if (!(_a b _c)) test.HandleFailedCompare(_a, __S(#b), _c, __LINE__,__S(__FILE__)); }
|
|
249 |
|
|
250 |
|
|
251 |
/**
|
|
252 |
@internalComponent
|
|
253 |
|
|
254 |
Panics and displays an appropriate error message displaying v, if the expression e is false.
|
|
255 |
*/
|
|
256 |
#define test_Value(v, e) if (!(e)) test.HandleValue(v, __LINE__,__S(__FILE__));
|
|
257 |
|
|
258 |
/**
|
|
259 |
@internalComponent
|
|
260 |
|
|
261 |
If expression e is false, statement s is executed then a Panic is raised.
|
|
262 |
*/
|
|
263 |
#define test_Assert(e,s) if(!(e)) {s; test.operator()(EFalse, __LINE__,__S(__FILE__)); }
|
|
264 |
|
|
265 |
|
|
266 |
|
|
267 |
#endif
|
|
268 |
|
|
269 |
|
|
270 |
/**
|
|
271 |
Prints a failure message, including an error code at the console and raises a panic.
|
|
272 |
|
|
273 |
|
|
274 |
@param aError The error code to be printed in the failure massage.
|
|
275 |
@param aLineNum A line number that is printed in the failure message.
|
|
276 |
@param aFileName A file name that is printed in the failure message.
|
|
277 |
|
|
278 |
@panic USER 84 Always.
|
|
279 |
*/
|
|
280 |
inline void RTest::HandleError(TInt aError, TInt aLine, const TText* aFileName)
|
|
281 |
{
|
|
282 |
RDebug::Printf("RTEST: Error %d at line %d", aError,aLine);
|
|
283 |
Printf(_L("RTEST: Error %d\n"), aError);
|
|
284 |
operator()(EFalse, aLine, aFileName);
|
|
285 |
}
|
|
286 |
/**
|
|
287 |
Prints a failure message indicating null was encountered, at the console and raises a panic.
|
|
288 |
|
|
289 |
@param aLineNum A line number that is printed in the failure message.
|
|
290 |
@param aFileName A file name that is printed in the failure message.
|
|
291 |
|
|
292 |
@panic USER 84 Always.
|
|
293 |
*/
|
|
294 |
|
|
295 |
inline void RTest::HandleNull(TInt aLine, const TText* aFileName)
|
|
296 |
{
|
|
297 |
RDebug::Printf("RTEST: Null value at line %d", aLine);
|
|
298 |
Printf(_L("RTEST: Null value\n"));
|
|
299 |
operator()(EFalse, aLine, aFileName);
|
|
300 |
}
|
|
301 |
|
|
302 |
|
|
303 |
/**
|
|
304 |
Prints a failure message indicating that two value (also printed) where not equal, at the console and raises a panic.
|
|
305 |
|
|
306 |
@param aExpected The value that is to be printed as expected.
|
|
307 |
@param aActual The value that is to be printed as being actually received.
|
|
308 |
@param aLineNum A line number that is printed in the failure message.
|
|
309 |
@param aFileName A file name that is printed in the failure message.
|
|
310 |
|
|
311 |
@panic USER 84 Always.
|
|
312 |
*/
|
|
313 |
|
|
314 |
inline void RTest::HandleNotEqual(TInt aExpected, TInt aActual, TInt aLine, const TText* aFileName)
|
|
315 |
{
|
|
316 |
RDebug::Printf("RTEST: Expected 0x%x (%d) but got 0x%x (%d) at line %d", aExpected,aExpected,aActual,aActual,aLine);
|
|
317 |
Printf(_L("RTEST: Expected 0x%x (%d) but got 0x%x (%d)\n"), aExpected,aExpected,aActual,aActual);
|
|
318 |
operator()(EFalse, aLine, aFileName);
|
|
319 |
}
|
|
320 |
|
|
321 |
|
|
322 |
/**
|
|
323 |
Prints a failure message indicating that a comparison between two values (also printed) resulted in EFalse,
|
|
324 |
at the console and raises a panic.
|
|
325 |
|
|
326 |
@param aLeft The left value of the comparison.
|
|
327 |
@param aComp A string representing the comparison operator.
|
|
328 |
@param aRight The right value of the comparison.
|
|
329 |
@param aLineNum A line number that is printed in the failure message.
|
|
330 |
@param aFileName A file name that is printed in the failure message.
|
|
331 |
|
|
332 |
@panic USER 84 Always.
|
|
333 |
*/
|
|
334 |
inline void RTest::HandleFailedCompare(TInt aLeft, const TText* aComp, TInt aRight, TInt aLine, const TText* aFileName)
|
|
335 |
{
|
|
336 |
RDebug::Printf("RTEST: (0x%x (%d) %s 0x%x (%d)) == EFalse at line %d", aLeft,aLeft,aComp,aRight,aRight,aLine);
|
|
337 |
Printf(_L("RTEST: (0x%x (%d) %s 0x%x (%d)) == EFalse\n"), aLeft,aLeft,aComp, aRight,aRight);
|
|
338 |
operator()(EFalse, aLine, aFileName);
|
|
339 |
}
|
|
340 |
|
|
341 |
|
|
342 |
/**
|
|
343 |
Prints a failure message indicating that aValue was not an expected value, at the console and raises a panic.
|
|
344 |
|
|
345 |
@param aValue The value that is to be printed as not being an expected value.
|
|
346 |
@param aLineNum A line number that is printed in the failure message.
|
|
347 |
@param aFileName A file name that is printed in the failure message.
|
|
348 |
|
|
349 |
@panic USER 84 Always.
|
|
350 |
*/
|
|
351 |
inline void RTest::HandleValue(TInt aValue, TInt aLine, const TText* aFileName)
|
|
352 |
{
|
|
353 |
Printf(_L("RTEST: %d (0x%x) was not an expected value.\n"), aValue, aValue);
|
|
354 |
operator()(EFalse, aLine, aFileName);
|
|
355 |
}
|
|
356 |
|
|
357 |
|
|
358 |
/**
|
|
359 |
@internalTechnology
|
|
360 |
*/
|
|
361 |
_LIT(KLitCloseAndWait,"Close&Wait");
|
|
362 |
|
|
363 |
/**
|
|
364 |
@internalTechnology
|
|
365 |
*/
|
|
366 |
#define CLOSE_AND_WAIT(h) ((void)(RTest::CloseHandleAndWaitForDestruction(h) && (User::Panic(KLitCloseAndWait,__LINE__),1)))
|
|
367 |
|
|
368 |
|
|
369 |
|
|
370 |
#endif
|
|
371 |
|