1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kernel/eka/include/e32test.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,371 @@
1.4 +// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32\include\e32test.h
1.18 +//
1.19 +//
1.20 +
1.21 +/**
1.22 + @file e32test.h
1.23 + @publishedAll
1.24 + @released
1.25 +*/
1.26 +
1.27 +#ifndef __E32TEST_H__
1.28 +#define __E32TEST_H__
1.29 +#include <e32std.h>
1.30 +#ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
1.31 +#include <e32std_private.h>
1.32 +#include <e32base_private.h>
1.33 +#endif
1.34 +#include <e32base.h>
1.35 +#include <e32cons.h>
1.36 +#include <e32kpan.h>
1.37 +#include <e32debug.h>
1.38 +#ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
1.39 +#include <e32def_private.h>
1.40 +#include <e32event_private.h>
1.41 +#endif
1.42 +
1.43 +
1.44 +/**
1.45 +Test console.
1.46 +
1.47 +The class creates a console window to which test results can be logged
1.48 +through the various overloads of the operator().
1.49 +*/
1.50 +class RTest
1.51 + {
1.52 +public:
1.53 + IMPORT_C RTest(const TDesC &aTitle,TInt aThrowaway,const TText* anOtherThrowaway);
1.54 + IMPORT_C RTest(const TDesC &aTitle,TInt aThrowaway);
1.55 + IMPORT_C RTest(const TDesC &aTitle);
1.56 + IMPORT_C void Close();
1.57 + IMPORT_C void Title();
1.58 + IMPORT_C void Start(const TDesC &aHeading);
1.59 + IMPORT_C void Next(const TDesC &aHeading);
1.60 + IMPORT_C void End();
1.61 + IMPORT_C void operator()(TInt aResult,TInt aLineNum,const TText* aFileName);
1.62 + IMPORT_C void operator()(TInt aResult,TInt aLineNum);
1.63 + IMPORT_C void operator()(TInt aResult);
1.64 + IMPORT_C void Panic(TInt anError,TRefByValue<const TDesC> aFmt,...);
1.65 + IMPORT_C void Panic(TRefByValue<const TDesC> aFmt,...);
1.66 + IMPORT_C void Printf(TRefByValue<const TDesC> aFmt,...);
1.67 + IMPORT_C TKeyCode Getch();
1.68 + inline static const TAny* String(TInt aSel,const TText8 *aBuf1,const TText16 *aBuf2);
1.69 + inline CConsoleBase* Console() const;
1.70 + inline void SetConsole(CConsoleBase* aConsole);
1.71 + inline TBool Logged() const;
1.72 + inline void SetLogged(TBool aToLog);
1.73 + inline void HandleError(TInt aError, TInt aLine, const TText* aFileName);
1.74 + inline void HandleNull(TInt aLine, const TText* aFileName);
1.75 + inline void HandleNotEqual(TInt aExpected, TInt aActual, TInt aLine, const TText* aFileName);
1.76 + inline void HandleFailedCompare(TInt aLeft, const TText* aComp, TInt aRight, TInt aLine, const TText* aFileName);
1.77 + inline void HandleValue(TInt aValue, TInt aLine, const TText* aFileName);
1.78 +
1.79 + IMPORT_C static TInt CloseHandleAndWaitForDestruction(RHandleBase& aH); /**< @internalTechnology */
1.80 +
1.81 +protected:
1.82 + void CheckConsoleCreated();
1.83 + void DisplayLevel();
1.84 + inline void Push();
1.85 + inline void Pop();
1.86 +private:
1.87 + enum {EMaxStack=0x100,EMaxBuffer=0x100};
1.88 +private:
1.89 + TInt iTest;
1.90 + TInt iCheck;
1.91 + TInt iLevel;
1.92 + TBool iLogging;
1.93 + CConsoleBase *iConsole;
1.94 + TBuf<0x40> iTitle;
1.95 + TInt iStack[EMaxStack];
1.96 + TText iBuf[EMaxBuffer];
1.97 + };
1.98 +
1.99 +
1.100 +
1.101 +
1.102 +/**
1.103 +Gets the console.
1.104 +
1.105 +@return A pointer to the console object.
1.106 +*/
1.107 +inline CConsoleBase* RTest::Console() const
1.108 + { return(iConsole); }
1.109 +
1.110 +
1.111 +
1.112 +
1.113 +/**
1.114 +Utility function that returns a pointer to the specified TText8* argument
1.115 +or the TText16* argument depending on the value of the aSel argument.
1.116 +
1.117 +@param aSel An integer containing the size of a TText8 type or TText16 type.
1.118 +@param aBuf1 A pointer to 8-bit text.
1.119 +@param aBuf2 A pointer to 16-bit text.
1.120 +
1.121 +@return A pointer to aBuf1, if the value of aSel is the size of a TText8 type,
1.122 + otherwise a pointer to aBuf2.
1.123 +*/
1.124 +inline const TAny *RTest::String(TInt aSel,const TText8 *aBuf1,const TText16 *aBuf2)
1.125 + { return(aSel == sizeof(TText8) ? (TAny *)aBuf1 : (TAny *)aBuf2); }
1.126 +
1.127 +
1.128 +
1.129 +/**
1.130 +@internalComponent
1.131 +*/
1.132 +inline void RTest::Push()
1.133 + { iStack[iLevel++] = iTest; iTest = 0; }
1.134 +
1.135 +
1.136 +
1.137 +/**
1.138 +@internalComponent
1.139 +*/
1.140 +inline void RTest::Pop()
1.141 + { iTest = iStack[--iLevel]; }
1.142 +
1.143 +
1.144 +
1.145 +
1.146 +/**
1.147 +Sets the console.
1.148 +
1.149 +@param aConsole A pointer to the console object to be used.
1.150 +*/
1.151 +inline void RTest::SetConsole(CConsoleBase* aConsole)
1.152 + { iConsole = aConsole; }
1.153 +
1.154 +
1.155 +
1.156 +
1.157 +/**
1.158 +Tests whether the logging flag is set.
1.159 +
1.160 +If the logging flag is set, console output is also written to
1.161 +the debug output as represented by a RDebug object.
1.162 +
1.163 +@return True, if the logging flag is set, false otherwise.
1.164 +*/
1.165 +inline TBool RTest::Logged() const
1.166 + { return(iLogging); }
1.167 +
1.168 +
1.169 +
1.170 +
1.171 +/**
1.172 +Sets the logging flag.
1.173 +
1.174 +If the logging flag is set, console output is also written to
1.175 +the debug output as represented by a RDebug object.
1.176 +
1.177 +@param aToLog ETrue, if the logging flag is to be set, EFalse, otherwise.
1.178 +*/
1.179 +inline void RTest::SetLogged(TBool aToLog)
1.180 + { iLogging = aToLog; }
1.181 +
1.182 +
1.183 +
1.184 +
1.185 +// test equivalent of _L
1.186 +/**
1.187 +@internalComponent
1.188 +*/
1.189 +#define _TL(a) (S*)RTest::String(sizeof(S),(TText8*)a,(TText16*)L ## a)
1.190 +
1.191 +// the next two, slightly confusing, macros are necessary in order
1.192 +// to enable proper string merging with certain compilers.
1.193 +
1.194 +/**
1.195 +@internalComponent
1.196 +*/
1.197 +#define __test(x,l,f) test(x,l,_S(f))
1.198 +
1.199 +/**
1.200 +@internalComponent
1.201 +*/
1.202 +#define test(x) __test(x,__LINE__,__FILE__)
1.203 +
1.204 +
1.205 +#ifdef __E32TEST_EXTENSION__
1.206 +
1.207 +/**
1.208 +@internalComponent
1.209 +*/
1.210 +#define __S(f) _S(f)
1.211 +
1.212 +/**
1.213 +@internalComponent
1.214 +
1.215 +Panics and displays an appropriate error message if x is less then zero (Indicating an error code).
1.216 +*/
1.217 +#define test_NotNegative(x) { TInt _r = (x); if (_r < 0) test.HandleError(_r, __LINE__,__S(__FILE__)); }
1.218 +
1.219 +/**
1.220 +@internalComponent
1.221 +
1.222 +Panics and displays an appropriate error message if x is not equal to KErrNone.
1.223 +*/
1.224 +#define test_KErrNone(x) { TInt _r = (x); if (_r !=KErrNone) test.HandleError(_r, __LINE__,__S(__FILE__)); }
1.225 +
1.226 +/**
1.227 +@internalComponent
1.228 +
1.229 +Panics and displays an appropriate error message if the trapped statement/block x leaves.
1.230 +*/
1.231 +#define test_TRAP(x) { TRAPD(_r, x); if (_r != KErrNone) test.HandleError(_r, __LINE__,__S(__FILE__)); }
1.232 +
1.233 +/**
1.234 +@internalComponent
1.235 +
1.236 +Panics and displays an appropriate error message if x is not equal to NULL.
1.237 +*/
1.238 +#define test_NotNull(x) { TAny* _a = (TAny*)(x); if (_a == NULL) test.HandleNull(__LINE__,__S(__FILE__)); }
1.239 +/**
1.240 +@internalComponent
1.241 +
1.242 +Panics and displays an appropriate error message if e (expected) is not equal to a (actual).
1.243 +*/
1.244 +#define test_Equal(e, a) { TInt _e = TInt(e); TInt _a = TInt(a); if (_e != _a) test.HandleNotEqual(_e, _a, __LINE__,__S(__FILE__)); }
1.245 +
1.246 +/**
1.247 +@internalComponent
1.248 +
1.249 +Panics and displays an appropriate error message if the comparison specified with operator b, between a and c, is EFalse.
1.250 +*/
1.251 +#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__)); }
1.252 +
1.253 +
1.254 +/**
1.255 +@internalComponent
1.256 +
1.257 +Panics and displays an appropriate error message displaying v, if the expression e is false.
1.258 +*/
1.259 +#define test_Value(v, e) if (!(e)) test.HandleValue(v, __LINE__,__S(__FILE__));
1.260 +
1.261 +/**
1.262 +@internalComponent
1.263 +
1.264 +If expression e is false, statement s is executed then a Panic is raised.
1.265 +*/
1.266 +#define test_Assert(e,s) if(!(e)) {s; test.operator()(EFalse, __LINE__,__S(__FILE__)); }
1.267 +
1.268 +
1.269 +
1.270 +#endif
1.271 +
1.272 +
1.273 +/**
1.274 +Prints a failure message, including an error code at the console and raises a panic.
1.275 +
1.276 +
1.277 +@param aError The error code to be printed in the failure massage.
1.278 +@param aLineNum A line number that is printed in the failure message.
1.279 +@param aFileName A file name that is printed in the failure message.
1.280 +
1.281 +@panic USER 84 Always.
1.282 +*/
1.283 +inline void RTest::HandleError(TInt aError, TInt aLine, const TText* aFileName)
1.284 + {
1.285 + RDebug::Printf("RTEST: Error %d at line %d", aError,aLine);
1.286 + Printf(_L("RTEST: Error %d\n"), aError);
1.287 + operator()(EFalse, aLine, aFileName);
1.288 + }
1.289 +/**
1.290 +Prints a failure message indicating null was encountered, at the console and raises a panic.
1.291 +
1.292 +@param aLineNum A line number that is printed in the failure message.
1.293 +@param aFileName A file name that is printed in the failure message.
1.294 +
1.295 +@panic USER 84 Always.
1.296 +*/
1.297 +
1.298 +inline void RTest::HandleNull(TInt aLine, const TText* aFileName)
1.299 + {
1.300 + RDebug::Printf("RTEST: Null value at line %d", aLine);
1.301 + Printf(_L("RTEST: Null value\n"));
1.302 + operator()(EFalse, aLine, aFileName);
1.303 + }
1.304 +
1.305 +
1.306 +/**
1.307 +Prints a failure message indicating that two value (also printed) where not equal, at the console and raises a panic.
1.308 +
1.309 +@param aExpected The value that is to be printed as expected.
1.310 +@param aActual The value that is to be printed as being actually received.
1.311 +@param aLineNum A line number that is printed in the failure message.
1.312 +@param aFileName A file name that is printed in the failure message.
1.313 +
1.314 +@panic USER 84 Always.
1.315 +*/
1.316 +
1.317 +inline void RTest::HandleNotEqual(TInt aExpected, TInt aActual, TInt aLine, const TText* aFileName)
1.318 + {
1.319 + RDebug::Printf("RTEST: Expected 0x%x (%d) but got 0x%x (%d) at line %d", aExpected,aExpected,aActual,aActual,aLine);
1.320 + Printf(_L("RTEST: Expected 0x%x (%d) but got 0x%x (%d)\n"), aExpected,aExpected,aActual,aActual);
1.321 + operator()(EFalse, aLine, aFileName);
1.322 + }
1.323 +
1.324 +
1.325 +/**
1.326 +Prints a failure message indicating that a comparison between two values (also printed) resulted in EFalse,
1.327 +at the console and raises a panic.
1.328 +
1.329 +@param aLeft The left value of the comparison.
1.330 +@param aComp A string representing the comparison operator.
1.331 +@param aRight The right value of the comparison.
1.332 +@param aLineNum A line number that is printed in the failure message.
1.333 +@param aFileName A file name that is printed in the failure message.
1.334 +
1.335 +@panic USER 84 Always.
1.336 +*/
1.337 +inline void RTest::HandleFailedCompare(TInt aLeft, const TText* aComp, TInt aRight, TInt aLine, const TText* aFileName)
1.338 + {
1.339 + RDebug::Printf("RTEST: (0x%x (%d) %s 0x%x (%d)) == EFalse at line %d", aLeft,aLeft,aComp,aRight,aRight,aLine);
1.340 + Printf(_L("RTEST: (0x%x (%d) %s 0x%x (%d)) == EFalse\n"), aLeft,aLeft,aComp, aRight,aRight);
1.341 + operator()(EFalse, aLine, aFileName);
1.342 + }
1.343 +
1.344 +
1.345 +/**
1.346 +Prints a failure message indicating that aValue was not an expected value, at the console and raises a panic.
1.347 +
1.348 +@param aValue The value that is to be printed as not being an expected value.
1.349 +@param aLineNum A line number that is printed in the failure message.
1.350 +@param aFileName A file name that is printed in the failure message.
1.351 +
1.352 +@panic USER 84 Always.
1.353 +*/
1.354 +inline void RTest::HandleValue(TInt aValue, TInt aLine, const TText* aFileName)
1.355 + {
1.356 + Printf(_L("RTEST: %d (0x%x) was not an expected value.\n"), aValue, aValue);
1.357 + operator()(EFalse, aLine, aFileName);
1.358 + }
1.359 +
1.360 +
1.361 +/**
1.362 +@internalTechnology
1.363 +*/
1.364 +_LIT(KLitCloseAndWait,"Close&Wait");
1.365 +
1.366 +/**
1.367 +@internalTechnology
1.368 +*/
1.369 +#define CLOSE_AND_WAIT(h) ((void)(RTest::CloseHandleAndWaitForDestruction(h) && (User::Panic(KLitCloseAndWait,__LINE__),1)))
1.370 +
1.371 +
1.372 +
1.373 +#endif
1.374 +