os/security/cryptomgmtlibs/securitytestfw/test/rtestwrapper/rtestwrapper.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
* Wrapper for RTest which logs to a file, coun1ts failures (without panicing) and
sl@0
    16
* generates a final result line the ONB will parse.
sl@0
    17
*
sl@0
    18
*/
sl@0
    19
sl@0
    20
sl@0
    21
sl@0
    22
sl@0
    23
/**
sl@0
    24
 @file
sl@0
    25
*/
sl@0
    26
#include "rtestwrapper.h"
sl@0
    27
#include <e32base.h>
sl@0
    28
#include <f32file.h>
sl@0
    29
sl@0
    30
class CTestConsole: public CConsoleBase
sl@0
    31
	{
sl@0
    32
public:
sl@0
    33
	static CTestConsole* NewL(CConsoleBase* aCon, const TDesC &aFileName);
sl@0
    34
	TInt Create(const TDesC16& aTitle,TSize aSize) {return iCon->Create(aTitle,aSize);};
sl@0
    35
	void Read(TRequestStatus& aStatus) {iCon->Read(aStatus);};
sl@0
    36
	void ReadCancel(void) {iCon->ReadCancel();};
sl@0
    37
	void Write(const TDesC16& aString);
sl@0
    38
	TPoint CursorPos(void) const {return iCon->CursorPos();};
sl@0
    39
	void SetCursorPosAbs(const TPoint& aPos) {iCon->SetCursorPosAbs(aPos);};
sl@0
    40
	void SetCursorPosRel(const TPoint& aPos) {iCon->SetCursorPosRel(aPos);};
sl@0
    41
	void SetCursorHeight(TInt aHeight) {iCon->SetCursorHeight(aHeight);};
sl@0
    42
	void SetTitle(const TDesC16& aTitle) {iCon->SetTitle(aTitle);};
sl@0
    43
	void ClearScreen(void) {iCon->ClearScreen();};
sl@0
    44
	void ClearToEndOfLine(void) {iCon->ClearToEndOfLine();};
sl@0
    45
	TSize ScreenSize(void) const {return iCon->ScreenSize();};
sl@0
    46
	TKeyCode KeyCode(void) const {return iCon->KeyCode();};
sl@0
    47
	TUint KeyModifiers(void) const {return iCon->KeyModifiers();};
sl@0
    48
	~CTestConsole(void);
sl@0
    49
private:
sl@0
    50
	void ConstructL(const TDesC &aFileName);
sl@0
    51
	CTestConsole(void);
sl@0
    52
	CConsoleBase* iCon;
sl@0
    53
	RFs iFs;
sl@0
    54
	RFile iFile;
sl@0
    55
	};
sl@0
    56
sl@0
    57
CTestConsole* CTestConsole::NewL(CConsoleBase* aCon, const TDesC &aFileName)
sl@0
    58
	{
sl@0
    59
	CTestConsole* self;
sl@0
    60
	self=new (ELeave) CTestConsole;
sl@0
    61
	CleanupStack::PushL(self);
sl@0
    62
	self->iCon=aCon;
sl@0
    63
	self->ConstructL(aFileName);
sl@0
    64
	CleanupStack::Pop(self);
sl@0
    65
	return self;
sl@0
    66
	}
sl@0
    67
sl@0
    68
void CTestConsole::ConstructL(const TDesC &aFileName)
sl@0
    69
	{
sl@0
    70
	User::LeaveIfError(iFs.Connect());
sl@0
    71
	(void) iFs.Delete(aFileName);
sl@0
    72
	User::LeaveIfError(iFile.Create(iFs, aFileName, EFileShareAny | EFileWrite));
sl@0
    73
	}
sl@0
    74
sl@0
    75
sl@0
    76
CTestConsole::CTestConsole(void):CConsoleBase()
sl@0
    77
	{
sl@0
    78
	}
sl@0
    79
sl@0
    80
CTestConsole::~CTestConsole(void)
sl@0
    81
sl@0
    82
	{
sl@0
    83
	delete iCon;
sl@0
    84
	iFile.Close();
sl@0
    85
	iFs.Close();
sl@0
    86
	}
sl@0
    87
sl@0
    88
void CTestConsole::Write(const TDesC16& aString)
sl@0
    89
sl@0
    90
	{
sl@0
    91
	iCon->Write(aString);
sl@0
    92
	TUint8 space[200];
sl@0
    93
	TPtr8 ptr(space,200);
sl@0
    94
	ptr.Copy(aString);
sl@0
    95
	iFile.Write(ptr);
sl@0
    96
	}
sl@0
    97
sl@0
    98
EXPORT_C RTestWrapper::RTestWrapper(const TDesC &aTitle,TInt aThrowaway,const TText* anOtherThrowaway)
sl@0
    99
	: RTest(aTitle, aThrowaway, anOtherThrowaway),
sl@0
   100
	  iNestLevel(0),
sl@0
   101
	  iTestCount(0),
sl@0
   102
	  iThisTestFailed(EFalse),
sl@0
   103
	  iFailedCount(0),
sl@0
   104
	  iTitle(aTitle)
sl@0
   105
	{
sl@0
   106
	}
sl@0
   107
sl@0
   108
EXPORT_C void RTestWrapper::operator()(TInt aResult,TInt aLineNum,const TText* aFileName)
sl@0
   109
	{
sl@0
   110
	if(!aResult)
sl@0
   111
		{
sl@0
   112
		RTest::Printf(_L("RTEST: Test FAILED %s:%d\n"), aFileName, aLineNum);
sl@0
   113
		if(!iThisTestFailed)
sl@0
   114
			{
sl@0
   115
			++iFailedCount;
sl@0
   116
			}
sl@0
   117
		iThisTestFailed = ETrue;
sl@0
   118
		}
sl@0
   119
	}
sl@0
   120
sl@0
   121
EXPORT_C void RTestWrapper::Title(const TDesC &aFileName)
sl@0
   122
	{
sl@0
   123
	//	CheckConsoleCreated(); // Can not use this because they forgot to export it!
sl@0
   124
	RTest::Title(); // Make sure console is created before we try and wrap it
sl@0
   125
	CConsoleBase *console(0);
sl@0
   126
	TRAPD(err, console = CTestConsole::NewL(RTest::Console(), aFileName));
sl@0
   127
	if(err == KErrNone)
sl@0
   128
	{
sl@0
   129
		RTest::SetConsole(console);
sl@0
   130
	}
sl@0
   131
sl@0
   132
	RTest::Title();
sl@0
   133
	}
sl@0
   134
sl@0
   135
sl@0
   136
EXPORT_C void RTestWrapper::Start(const TDesC16 &aHeading)
sl@0
   137
	{
sl@0
   138
	RTest::Start(aHeading);
sl@0
   139
	++iNestLevel;
sl@0
   140
	++iTestCount;
sl@0
   141
	iThisTestFailed = EFalse;
sl@0
   142
	}
sl@0
   143
sl@0
   144
EXPORT_C void RTestWrapper::Next(const TDesC16 &aHeading)
sl@0
   145
	{
sl@0
   146
	RTest::Next(aHeading);
sl@0
   147
	++iTestCount;
sl@0
   148
	iThisTestFailed = EFalse;
sl@0
   149
	}
sl@0
   150
sl@0
   151
EXPORT_C void RTestWrapper::End()
sl@0
   152
	{
sl@0
   153
	RTest::End();
sl@0
   154
	--iNestLevel;
sl@0
   155
	if(iNestLevel == 0)
sl@0
   156
		{
sl@0
   157
		RTest::Printf(_L("\r\n%d tests failed out of %d\r\n"), iFailedCount, iTestCount);
sl@0
   158
		}
sl@0
   159
	}
sl@0
   160
sl@0
   161
// End of file