symport/e32/euser/us_test.cpp
author Pat Downey <patrick.downey@nokia.com>
Thu, 25 Jun 2009 15:59:54 +0100
changeset 1 0a7b44b10206
child 2 806186ab5e14
permissions -rw-r--r--
Catch up of Symbian tools for @1627812
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
     1
// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
     2
// All rights reserved.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
     3
// This component and the accompanying materials are made available
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
     4
// under the terms of the License "Symbian Foundation License v1.0"
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
     5
// which accompanies this distribution, and is available
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
     6
// at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
     7
//
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
     8
// Initial Contributors:
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    10
//
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    11
// Contributors:
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    12
//
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    13
// Description:
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    14
// e32\euser\us_test.cpp
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    15
// 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    16
//
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    17
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    18
#include "us_std.h"
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    19
#include <e32test.h>
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    20
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    21
#if defined(test)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    22
#undef test
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    23
#endif
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    24
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    25
#include <e32svr.h> 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    26
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    27
void RTest::CheckConsoleCreated()
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    28
	{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    29
	// Check that the console has been created.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    30
	if (iConsole == NULL)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    31
		{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    32
		TRAPD(r, iConsole = Console::NewL(iTitle, TSize(KConsFullScreen, KConsFullScreen)))
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    33
		__ASSERT_ALWAYS(r == KErrNone, ::Panic(ERTestCreateConsole));
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    34
		}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    35
	}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    36
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    37
void RTest::DisplayLevel()
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    38
	{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    39
	// Display the current level string.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    40
	TBuf<0x100> aBuf(_L("RTEST: Level "));
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    41
	for (TInt ii = 1; ii < iLevel; ii++)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    42
		{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    43
		if (ii > 1)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    44
			{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    45
			aBuf.AppendFormat(_L(".%02d"), iStack[ii]);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    46
			}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    47
		else
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    48
			{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    49
			aBuf.AppendFormat(_L(" %03d"), iStack[ii]);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    50
			}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    51
		}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    52
	if (iLevel > 1)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    53
		{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    54
		aBuf.AppendFormat(_L(".%02d "), iTest);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    55
		}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    56
	else
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    57
		{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    58
		aBuf.AppendFormat(_L(" %03d "), iTest);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    59
		}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    60
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    61
	Printf(aBuf);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    62
	}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    63
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    64
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    65
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    66
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    67
/**
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    68
Constructor.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    69
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    70
@param aTitle           A title describing this use of RTest.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    71
                        This is also referred to as the console title.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    72
@param aThrowaway       Not used.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    73
@param anOtherThrowaway Not used.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    74
*/
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    75
EXPORT_C RTest::RTest(const TDesC &aTitle,TInt /* aThrowaway */,const TText* /* anOtherThrowaway */)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    76
	: iTest(0), iLevel(0), iLogging(ETrue), iConsole(NULL), iTitle(aTitle)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    77
	// Constructor
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    78
	// There is a #define test(x) test(x, __LINE__) in e32test.h to pass on line info of failing tests,
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    79
	// This depends upon the user naming their RTest object test, but if they do this then an extra
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    80
	// parameter aThrowaway must be added to the constructor
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    81
	{}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    82
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    83
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    84
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    85
/**
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    86
Constructor.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    87
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    88
@param aTitle     A title describing this use of RTest.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    89
                  This is also referred to as the console title.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    90
@param aThrowaway Not used.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    91
*/
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    92
EXPORT_C RTest::RTest(const TDesC &aTitle, TInt /* athrowaway */)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    93
	: iTest(0), iLevel(0), iLogging(ETrue), iConsole(NULL), iTitle(aTitle)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    94
	// Constructor
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    95
	// There is a #define test(x) test(x, __LINE__) in e32test.h to pass on line info of failing tests,
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    96
	// This depends upon the user naming their RTest object test, but if they do this then an extra
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    97
	// parameter aThrowaway must be added to the constructor
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    98
	{}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    99
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   100
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   101
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   102
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   103
/**
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   104
Constructor.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   105
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   106
@param aTitle A title describing this use of RTest.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   107
              This is also referred to as the console title.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   108
*/
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   109
EXPORT_C RTest::RTest(const TDesC &aTitle)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   110
	: iTest(0), iLevel(0), iLogging(ETrue), iConsole(NULL), iTitle(aTitle)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   111
	// Constructor
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   112
	{}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   113
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   114
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   115
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   116
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   117
/**
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   118
Closes the console and frees any resources acquired.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   119
*/
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   120
EXPORT_C void RTest::Close()
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   121
	{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   122
	// Close the console.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   123
	delete iConsole;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   124
	iConsole=NULL;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   125
	}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   126
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   127
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   128
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   129
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   130
/**
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   131
Prints out the console title and version number.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   132
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   133
The format of the text is:
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   134
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   135
@code
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   136
RTEST TITLE: XXX YYY
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   137
Epoc/32 YYY
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   138
@endcode
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   139
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   140
where XXX is the console title, and YYY is the version number,
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   141
formatted as described by TVersion::Name().
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   142
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   143
@see TVersion::Name()
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   144
@see RTest::Printf() 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   145
*/
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   146
EXPORT_C void RTest::Title()
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   147
	{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   148
	// Print out the program title and version number.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   149
	TVersion v(KE32MajorVersionNumber, KE32MinorVersionNumber, KE32BuildVersionNumber);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   150
	TBuf<16> vName=v.Name();
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   151
	Printf(_L("RTEST TITLE: %S %S\n"), &iTitle, &vName);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   152
	vName=User::Version().Name();
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   153
	Printf(_L("Epoc/32 %S\n"), &vName);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   154
	}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   155
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   156
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   157
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   158
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   159
/**
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   160
Marks the start of a set of tests.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   161
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   162
Note that sets of tests can be nested.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   163
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   164
A call to this function must be matched by a call to RTest::End() to mark
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   165
the end of this set of tests.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   166
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   167
@param aHeading A heading describing the set of tests; this is
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   168
                printed at the console.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   169
                
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   170
@see RTest::End()                
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   171
*/
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   172
EXPORT_C void RTest::Start(const TDesC &aHeading)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   173
	{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   174
	// Print out the heading and nest the level.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   175
	Push();
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   176
	Next(aHeading);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   177
	}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   178
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   179
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   180
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   181
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   182
/**
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   183
Marks the start of the next test.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   184
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   185
@param aHeading A heading describing the test; this
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   186
                is printed at the console. This function is also
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   187
                called by Start(), which passes the text that describes
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   188
                the set of tests.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   189
                
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   190
@see RTest::Start()                
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   191
*/
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   192
EXPORT_C void RTest::Next(const TDesC &aHeading)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   193
	{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   194
	// Print out the heading and nest the level.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   195
	iTest++;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   196
	iCheck = 0;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   197
	DisplayLevel();
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   198
	Printf(_L("Next test - %S\n"), &aHeading);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   199
	}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   200
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   201
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   202
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   203
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   204
/**
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   205
Checks the result of a condition and, if this is false, prints
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   206
a failure message at the console and raises a panic.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   207
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   208
Before checking the condition passed in, the operator increments
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   209
a check number. This is a value that is set to zero at the start of a test
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   210
and is incremented by this operator (and by all variants of it). It identifies
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   211
the check being made within the current test.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   212
This value is printed on a failure message.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   213
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   214
Typically, the operator is called, passing a test condition, for example:
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   215
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   216
@code
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   217
RTest test(... heading text...,line number... file name)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   218
TInt r;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   219
...some operation to be tested that returns a value in r...
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   220
test(r==KErrNone);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   221
@endcode
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   222
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   223
The failure message has the format:
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   224
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   225
@code
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   226
: FAIL : XXX failed check N in FFF at line Number: M
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   227
RTEST: Checkpoint-fail
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   228
@endcode
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   229
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   230
where XXX is the console title, N is the check number, FFF is the filename,
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   231
and M is the line number passed in.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   232
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   233
@param aResult   The condition being tested.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   234
                 This is interpreted as a true or false value.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   235
@param aLineNum  A line number that is printed in the failure message if
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   236
                 the condition being tested is false.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   237
@param aFileName A file name that is printed in the failure message if
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   238
                 the condition being tested is false.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   239
                 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   240
@panic USER 84 if the condition being tested is false.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   241
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   242
@see RTest::Next()
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   243
@see RTest::Start()
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   244
*/
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   245
EXPORT_C void RTest::operator()(TInt aResult, TInt aLineNum, const TText* aFileName)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   246
	{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   247
	// Test a condition.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   248
	iCheck++;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   249
	if (!aResult)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   250
		{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   251
		RDebug::Printf(": FAILING : failed check at line number %d", aLineNum);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   252
		DisplayLevel();
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   253
		Printf(_L(": FAIL : %S failed check %d in %s at line number %d\n"),
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   254
			   &iTitle, iCheck, aFileName, aLineNum);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   255
		Panic(_L("Checkpoint-fail\n"));
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   256
		if (!iLogging)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   257
			Getch();
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   258
		}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   259
	}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   260
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   261
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   262
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   263
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   264
/**
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   265
Checks the result of a condition and, if this is false, prints
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   266
a failure message at the console and raises a panic.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   267
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   268
Before checking the condition passed in, the operator increments
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   269
a check number. This is a value that is set to zero at the start of a test
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   270
and is incremented by this operator (and by all variants of it). It identifies
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   271
the check being made within the current test.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   272
This value is printed on the failure message.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   273
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   274
Typically, the operator is called, passing a test condition, for example:
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   275
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   276
@code
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   277
RTest test(... heading text...,line number)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   278
TInt r;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   279
...some operation to be tested that returns a value in r...
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   280
test(r==KErrNone);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   281
@endcode
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   282
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   283
The failure message has the format:
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   284
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   285
@code
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   286
: FAIL : XXX failed check N at line Number: M
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   287
RTEST: Checkpoint-fail
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   288
@endcode
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   289
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   290
where XXX is the console title, N is the check number, and M is
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   291
the line number passed in.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   292
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   293
@param aResult  The condition being tested.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   294
                This is interpreted as a true or false value.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   295
@param aLineNum A line number that is printed in the failure message if
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   296
                the condition being tested is false.               
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   297
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   298
@panic USER 84 if the condition being tested is false.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   299
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   300
@see RTest::Next()
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   301
@see RTest::Start()
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   302
*/
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   303
EXPORT_C void RTest::operator()(TInt aResult,TInt aLineNum)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   304
	{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   305
	// Test a condition.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   306
	iCheck++;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   307
	if (!aResult)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   308
		{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   309
		RDebug::Printf(": FAILING : failed check at line Number: %d", aLineNum);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   310
		DisplayLevel();
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   311
		Printf(_L(": FAIL : %S failed check %d at line Number: %d\n"), &iTitle, iCheck, aLineNum);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   312
		Panic(_L("Checkpoint-fail\n"));
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   313
		if (!iLogging)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   314
			Getch();
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   315
		}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   316
	}  
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   317
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   318
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   319
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   320
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   321
/**
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   322
Checks the result of a condition and, if this is false, prints
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   323
a failure message at the console and raises a panic.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   324
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   325
Before checking the condition passed in, the operator increments
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   326
a check number. This is a value that is set to zero at the start of a test
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   327
and is incremented by this operator (and by all variants of it). It identifies
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   328
the check being made within the current test.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   329
This value is printed on the failure message.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   330
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   331
Typically, the operator is called, passing a test condition, for example:
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   332
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   333
@code
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   334
RTest test(... heading text...)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   335
TInt r;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   336
...some operation to be tested that returns a value in r...
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   337
test(r==KErrNone);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   338
@endcode
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   339
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   340
The failure message has the format:
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   341
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   342
@code
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   343
: FAIL : XXX failed check N
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   344
RTEST: Checkpoint-fail
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   345
@endcode
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   346
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   347
where XXX is the console title, and N is the check number.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   348
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   349
@param aResult The condition being tested.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   350
               This is interpreted as a true or false value.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   351
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   352
@panic USER 84 if the condition being tested is false.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   353
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   354
@see RTest::Next()
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   355
@see RTest::Start()
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   356
*/
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   357
EXPORT_C void RTest::operator()(TInt aResult)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   358
	{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   359
	// Test a condition.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   360
	iCheck++;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   361
	if (!aResult)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   362
		{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   363
		RDebug::Printf(": FAILING : failed check\n");
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   364
		DisplayLevel();
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   365
		Printf(_L(": FAIL : %S failed check %d\n"), &iTitle, iCheck);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   366
		Panic(_L("Checkpoint-fail\n"));
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   367
		if (!iLogging)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   368
			Getch();
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   369
		}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   370
	}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   371
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   372
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   373
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   374
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   375
/**
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   376
Ends the current set of tests.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   377
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   378
If this set of tests is not nested within another set,
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   379
then a message reporting success is written to
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   380
the console.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   381
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   382
@panic USER 84 if there was no matching call to RTest::Start(),
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   383
               i.e. more calls to End() have been made than calls to Start().
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   384
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   385
@see RTest::Start()
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   386
*/
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   387
EXPORT_C void RTest::End()
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   388
	{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   389
	// End the current level of tests.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   390
	if (TInt(iLevel-1) < 0)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   391
		{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   392
		Panic(_L("End() without matching Start()\n"));
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   393
		}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   394
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   395
	Pop();
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   396
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   397
	if (iLevel == 0)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   398
		{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   399
		Printf(_L("RTEST: SUCCESS : %S test completed O.K.\n"), &iTitle);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   400
		if (!iLogging)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   401
			Getch();
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   402
		}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   403
	}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   404
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   405
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   406
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   407
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   408
/**
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   409
Prints an error message and an error code,
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   410
and raises a USER 84 panic.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   411
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   412
@param anError The error code.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   413
@param aFmt    A format list.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   414
@param ...     A variable number of parameters.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   415
*/
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   416
EXPORT_C void RTest::Panic(TInt anError,TRefByValue<const TDesC> aFmt,...)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   417
	{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   418
	// Print an error message, an error and then panic.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   419
	TestOverflowTruncate overflow;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   420
	VA_LIST list;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   421
	VA_START(list, aFmt);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   422
	TBuf<0x100> aBuf;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   423
	aBuf.AppendFormat(_L("RTEST: "));
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   424
	aBuf.AppendFormatList(aFmt, list, &overflow);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   425
	aBuf.AppendFormat(_L(" Failed with error %d\n"), anError);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   426
	Printf(aBuf);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   427
	if (!iLogging)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   428
		Getch();
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   429
	::Panic(ERTestFailed);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   430
	}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   431
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   432
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   433
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   434
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   435
/**
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   436
Prints an error message, and raises a USER 84 panic.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   437
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   438
@param aFmt    A format list.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   439
@param ...     A variable number of parameters.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   440
*/
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   441
EXPORT_C void RTest::Panic(TRefByValue<const TDesC> aFmt,...)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   442
	{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   443
	// Print an error message and then panic.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   444
	TestOverflowTruncate overflow;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   445
	VA_LIST list;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   446
	VA_START(list, aFmt);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   447
	TBuf<0x100> aBuf;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   448
	aBuf.AppendFormat(_L("RTEST: "));
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   449
	aBuf.AppendFormatList(aFmt, list, &overflow);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   450
	Printf(aBuf);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   451
	if (!iLogging)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   452
		Getch();
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   453
	::Panic(ERTestFailed);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   454
	}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   455
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   456
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   457
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   458
_LIT(KLitNL, "\n");
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   459
_LIT(KLitCRNL, "\r\n");
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   460
/**
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   461
Prints text to the console.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   462
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   463
If the logging flag is set, the string
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   464
is also written to the debug output as represented by an RDebug object.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   465
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   466
@param aFmt    A format list.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   467
@param ...     A variable number of parameters.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   468
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   469
@see RTest::SetLogged()
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   470
@see Rtest::Logged()
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   471
@see RDebug
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   472
*/
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   473
EXPORT_C void RTest::Printf(TRefByValue<const TDesC> aFmt,...)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   474
	{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   475
	// Print to a console screen.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   476
	TestOverflowTruncate overflow;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   477
	VA_LIST list;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   478
	VA_START(list, aFmt);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   479
	TBuf<0x100> buf;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   480
	buf.AppendFormatList(aFmt, list, &overflow);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   481
	CheckConsoleCreated();
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   482
	iConsole->Write(buf);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   483
	
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   484
	if (iLogging)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   485
		{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   486
		TPtrC ptr(buf);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   487
		TInt newline;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   488
		while ((newline = ptr.Locate('\n')) != KErrNotFound)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   489
			{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   490
			RDebug::RawPrint(ptr.Left(newline));
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   491
			if (newline==0 || ptr[newline-1]!='\r')
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   492
				RDebug::RawPrint(KLitCRNL); // bare nl, replace with crnl
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   493
			else
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   494
				RDebug::RawPrint(KLitNL); // crnl, already printed cr
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   495
			if (newline+1<ptr.Length())
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   496
				ptr.Set(ptr.Mid(newline+1));
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   497
			else
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   498
				return; // newline was end of string
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   499
			}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   500
		RDebug::RawPrint(ptr);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   501
		}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   502
	}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   503
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   504
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   505
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   506
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   507
/**
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   508
Gets an input key stroke.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   509
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   510
@return The input key code.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   511
*/
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   512
EXPORT_C TKeyCode RTest::Getch()
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   513
	{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   514
	// Get a key from the console.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   515
	CheckConsoleCreated();
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   516
	return(iConsole->Getch());
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   517
	}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   518
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   519
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   520
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   521
EXPORT_C TInt RTest::CloseHandleAndWaitForDestruction(RHandleBase& aH)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   522
	{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   523
#ifndef __TOOLS2__
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   524
	TRequestStatus s;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   525
	aH.NotifyDestruction(s);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   526
	aH.Close();
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   527
	TUint32 initial = User::NTickCount();
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   528
	TInt r = KErrNone;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   529
	if (s == KErrNoMemory)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   530
		r = KErrNoMemory;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   531
	while (s == KRequestPending)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   532
		{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   533
		TUint32 now = User::NTickCount();
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   534
		if ((now - initial) > 5000)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   535
			{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   536
			User::CancelMiscNotifier(s);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   537
			r = KErrTimedOut;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   538
			break;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   539
			}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   540
		User::AfterHighRes(1000);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   541
		}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   542
	User::WaitForRequest(s);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   543
	return r;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   544
#else
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   545
	return KErrNone;
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   546
#endif // __TOOLS2__
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   547
	}
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   548
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
   549