RTest Class Reference

class RTest

Test console.

The class creates a console window to which test results can be logged through the various overloads of the operator().

Public Member Functions
RTest(const TDesC &, TInt, const TText *)
RTest(const TDesC &, TInt)
RTest(const TDesC &)
IMPORT_C voidClose()
IMPORT_C TIntCloseHandleAndWaitForDestruction(RHandleBase &)
CConsoleBase *Console()
IMPORT_C voidEnd()
IMPORT_C TKeyCodeGetch()
voidHandleError(TInt, TInt, const TText *)
voidHandleFailedCompare(TInt, const TText *, TInt, TInt, const TText *)
voidHandleNotEqual(TInt, TInt, TInt, const TText *)
voidHandleNull(TInt, const TText *)
voidHandleValue(TInt, TInt, const TText *)
TBool Logged()
IMPORT_C voidNext(const TDesC &)
IMPORT_C voidPanic(TInt, TRefByValue< const TDesC >, ...)
IMPORT_C voidPanic(TRefByValue< const TDesC >, ...)
IMPORT_C voidPrintf(TRefByValue< const TDesC >, ...)
voidSetConsole(CConsoleBase *)
voidSetLogged(TBool)
IMPORT_C voidStart(const TDesC &)
const TAny *String(TInt, const TText8 *, const TText16 *)
IMPORT_C voidTitle()
IMPORT_C voidoperator()(TInt, TInt, const TText *)
IMPORT_C voidoperator()(TInt, TInt)
IMPORT_C voidoperator()(TInt)
Protected Member Functions
voidCheckConsoleCreated()
voidDisplayLevel()
voidPop()
voidPush()
Private Attributes
TText iBuf
TInt iCheck
CConsoleBase *iConsole
TInt iLevel
TBool iLogging
TInt iStack
TInt iTest
TBuf< 0x40 >iTitle

Constructor & Destructor Documentation

RTest(const TDesC &, TInt, const TText *)

IMPORT_CRTest(const TDesC &aTitle,
TIntaThrowaway,
const TText *anOtherThrowaway
)

Constructor.

Parameters

const TDesC & aTitleA title describing this use of RTest. This is also referred to as the console title.
TInt aThrowawayNot used.
const TText * anOtherThrowawayNot used.

RTest(const TDesC &, TInt)

IMPORT_CRTest(const TDesC &aTitle,
TIntaThrowaway
)

Constructor.

Parameters

const TDesC & aTitleA title describing this use of RTest. This is also referred to as the console title.
TInt aThrowawayNot used.

RTest(const TDesC &)

IMPORT_CRTest(const TDesC &aTitle)

Constructor.

Parameters

const TDesC & aTitleA title describing this use of RTest. This is also referred to as the console title.

Member Functions Documentation

CheckConsoleCreated()

voidCheckConsoleCreated()[protected]

Close()

IMPORT_C voidClose()

Closes the console and frees any resources acquired.

CloseHandleAndWaitForDestruction(RHandleBase &)

IMPORT_C TIntCloseHandleAndWaitForDestruction(RHandleBase &aH)[static]

Parameters

RHandleBase & aH

Console()

CConsoleBase *Console()const [inline]

Gets the console.

DisplayLevel()

voidDisplayLevel()[protected]

End()

IMPORT_C voidEnd()

Ends the current set of tests.

If this set of tests is not nested within another set, then a message reporting success is written to the console.

panic
USER 84 if there was no matching call to RTest::Start(), i.e. more calls to End() have been made than calls to Start().
RTest::Start()

Getch()

IMPORT_C TKeyCodeGetch()

Gets an input key stroke.

HandleError(TInt, TInt, const TText *)

voidHandleError(TIntaError,
TIntaLine,
const TText *aFileName
)[inline]

Prints a failure message, including an error code at the console and raises a panic.

panic
USER 84 Always.

Parameters

TInt aErrorThe error code to be printed in the failure massage.
TInt aLine
const TText * aFileNameA file name that is printed in the failure message.

HandleFailedCompare(TInt, const TText *, TInt, TInt, const TText *)

voidHandleFailedCompare(TIntaLeft,
const TText *aComp,
TIntaRight,
TIntaLine,
const TText *aFileName
)[inline]

Prints a failure message indicating that a comparison between two values (also printed) resulted in EFalse, at the console and raises a panic.

panic
USER 84 Always.

Parameters

TInt aLeftThe left value of the comparison.
const TText * aCompA string representing the comparison operator.
TInt aRightThe right value of the comparison.
TInt aLine
const TText * aFileNameA file name that is printed in the failure message.

HandleNotEqual(TInt, TInt, TInt, const TText *)

voidHandleNotEqual(TIntaExpected,
TIntaActual,
TIntaLine,
const TText *aFileName
)[inline]

Prints a failure message indicating that two value (also printed) where not equal, at the console and raises a panic.

panic
USER 84 Always.

Parameters

TInt aExpectedThe value that is to be printed as expected.
TInt aActualThe value that is to be printed as being actually received.
TInt aLine
const TText * aFileNameA file name that is printed in the failure message.

HandleNull(TInt, const TText *)

voidHandleNull(TIntaLine,
const TText *aFileName
)[inline]

Prints a failure message indicating null was encountered, at the console and raises a panic.

panic
USER 84 Always.

Parameters

TInt aLine
const TText * aFileNameA file name that is printed in the failure message.

HandleValue(TInt, TInt, const TText *)

voidHandleValue(TIntaValue,
TIntaLine,
const TText *aFileName
)[inline]

Prints a failure message indicating that aValue was not an expected value, at the console and raises a panic.

panic
USER 84 Always.

Parameters

TInt aValueThe value that is to be printed as not being an expected value.
TInt aLine
const TText * aFileNameA file name that is printed in the failure message.

Logged()

TBool Logged()const [inline]

Tests whether the logging flag is set.

If the logging flag is set, console output is also written to the debug output as represented by a RDebug object.

Next(const TDesC &)

IMPORT_C voidNext(const TDesC &aHeading)

Marks the start of the next test.

RTest::Start()

Parameters

const TDesC & aHeadingA heading describing the test; this is printed at the console. This function is also called by Start(), which passes the text that describes the set of tests.

Panic(TInt, TRefByValue< const TDesC >, ...)

IMPORT_C voidPanic(TIntanError,
TRefByValue< const TDesC >aFmt,
...
)

Prints an error message and an error code, and raises a USER 84 panic.

Parameters

TInt anErrorThe error code.
TRefByValue< const TDesC > aFmtA format list.
...

Panic(TRefByValue< const TDesC >, ...)

IMPORT_C voidPanic(TRefByValue< const TDesC >aFmt,
...
)

Prints an error message, and raises a USER 84 panic.

Parameters

TRefByValue< const TDesC > aFmtA format list.
...

Pop()

voidPop()[protected, inline]

Printf(TRefByValue< const TDesC >, ...)

IMPORT_C voidPrintf(TRefByValue< const TDesC >aFmt,
...
)

Prints text to the console.

If the logging flag is set, the string is also written to the debug output as represented by an RDebug object.

RTest::SetLogged() Rtest::Logged() RDebug

Parameters

TRefByValue< const TDesC > aFmtA format list.
...

Push()

voidPush()[protected, inline]

SetConsole(CConsoleBase *)

voidSetConsole(CConsoleBase *aConsole)[inline]

Sets the console.

Parameters

CConsoleBase * aConsoleA pointer to the console object to be used.

SetLogged(TBool)

voidSetLogged(TBoolaToLog)[inline]

Sets the logging flag.

If the logging flag is set, console output is also written to the debug output as represented by a RDebug object.

Parameters

TBool aToLogETrue, if the logging flag is to be set, EFalse, otherwise.

Start(const TDesC &)

IMPORT_C voidStart(const TDesC &aHeading)

Marks the start of a set of tests.

Note that sets of tests can be nested.

A call to this function must be matched by a call to RTest::End() to mark the end of this set of tests.

RTest::End()

Parameters

const TDesC & aHeadingA heading describing the set of tests; this is printed at the console.

String(TInt, const TText8 *, const TText16 *)

const TAny *String(TIntaSel,
const TText8 *aBuf1,
const TText16 *aBuf2
)[static, inline]

Utility function that returns a pointer to the specified TText8* argument or the TText16* argument depending on the value of the aSel argument.

Parameters

TInt aSelAn integer containing the size of a TText8 type or TText16 type.
const TText8 * aBuf1A pointer to 8-bit text.
const TText16 * aBuf2A pointer to 16-bit text.

Title()

IMPORT_C voidTitle()

Prints out the console title and version number.

The format of the text is:

RTEST TITLE: XXX YYY
Epoc/32 YYY

where XXX is the console title, and YYY is the version number, formatted as described by TVersion::Name().

TVersion::Name() RTest::Printf()

operator()(TInt, TInt, const TText *)

IMPORT_C voidoperator()(TIntaResult,
TIntaLineNum,
const TText *aFileName
)

Checks the result of a condition and, if this is false, prints a failure message at the console and raises a panic.

Before checking the condition passed in, the operator increments a check number. This is a value that is set to zero at the start of a test and is incremented by this operator (and by all variants of it). It identifies the check being made within the current test. This value is printed on a failure message.

Typically, the operator is called, passing a test condition, for example:

RTest test(... heading text...,line number... file name)
TInt r;
...some operation to be tested that returns a value in r...
test(r==KErrNone);

The failure message has the format:

: FAIL : XXX failed check N in FFF at line Number: M
RTEST: Checkpoint-fail

where XXX is the console title, N is the check number, FFF is the filename, and M is the line number passed in.

panic
USER 84 if the condition being tested is false.
RTest::Next() RTest::Start()

Parameters

TInt aResultThe condition being tested. This is interpreted as a true or false value.
TInt aLineNumA line number that is printed in the failure message if the condition being tested is false.
const TText * aFileNameA file name that is printed in the failure message if the condition being tested is false.

operator()(TInt, TInt)

IMPORT_C voidoperator()(TIntaResult,
TIntaLineNum
)

Checks the result of a condition and, if this is false, prints a failure message at the console and raises a panic.

Before checking the condition passed in, the operator increments a check number. This is a value that is set to zero at the start of a test and is incremented by this operator (and by all variants of it). It identifies the check being made within the current test. This value is printed on the failure message.

Typically, the operator is called, passing a test condition, for example:

RTest test(... heading text...,line number)
TInt r;
...some operation to be tested that returns a value in r...
test(r==KErrNone);

The failure message has the format:

: FAIL : XXX failed check N at line Number: M
RTEST: Checkpoint-fail

where XXX is the console title, N is the check number, and M is the line number passed in.

panic
USER 84 if the condition being tested is false.
RTest::Next() RTest::Start()

Parameters

TInt aResultThe condition being tested. This is interpreted as a true or false value.
TInt aLineNumA line number that is printed in the failure message if the condition being tested is false.

operator()(TInt)

IMPORT_C voidoperator()(TIntaResult)

Checks the result of a condition and, if this is false, prints a failure message at the console and raises a panic.

Before checking the condition passed in, the operator increments a check number. This is a value that is set to zero at the start of a test and is incremented by this operator (and by all variants of it). It identifies the check being made within the current test. This value is printed on the failure message.

Typically, the operator is called, passing a test condition, for example:

RTest test(... heading text...)
TInt r;
...some operation to be tested that returns a value in r...
test(r==KErrNone);

The failure message has the format:

: FAIL : XXX failed check N
RTEST: Checkpoint-fail

where XXX is the console title, and N is the check number.

panic
USER 84 if the condition being tested is false.
RTest::Next() RTest::Start()

Parameters

TInt aResultThe condition being tested. This is interpreted as a true or false value.

Member Data Documentation

TText iBuf

TText iBuf[private]

TInt iCheck

TInt iCheck[private]

CConsoleBase * iConsole

CConsoleBase *iConsole[private]

TInt iLevel

TInt iLevel[private]

TBool iLogging

TBool iLogging[private]

TInt iStack

TInt iStack[private]

TInt iTest

TInt iTest[private]

TBuf< 0x40 > iTitle

TBuf< 0x40 >iTitle[private]