os/security/cryptomgmtlibs/securitytestfw/test/rtestwrapper/rtestwrapper.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptomgmtlibs/securitytestfw/test/rtestwrapper/rtestwrapper.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,161 @@
     1.4 +/*
     1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +* Wrapper for RTest which logs to a file, coun1ts failures (without panicing) and
    1.19 +* generates a final result line the ONB will parse.
    1.20 +*
    1.21 +*/
    1.22 +
    1.23 +
    1.24 +
    1.25 +
    1.26 +/**
    1.27 + @file
    1.28 +*/
    1.29 +#include "rtestwrapper.h"
    1.30 +#include <e32base.h>
    1.31 +#include <f32file.h>
    1.32 +
    1.33 +class CTestConsole: public CConsoleBase
    1.34 +	{
    1.35 +public:
    1.36 +	static CTestConsole* NewL(CConsoleBase* aCon, const TDesC &aFileName);
    1.37 +	TInt Create(const TDesC16& aTitle,TSize aSize) {return iCon->Create(aTitle,aSize);};
    1.38 +	void Read(TRequestStatus& aStatus) {iCon->Read(aStatus);};
    1.39 +	void ReadCancel(void) {iCon->ReadCancel();};
    1.40 +	void Write(const TDesC16& aString);
    1.41 +	TPoint CursorPos(void) const {return iCon->CursorPos();};
    1.42 +	void SetCursorPosAbs(const TPoint& aPos) {iCon->SetCursorPosAbs(aPos);};
    1.43 +	void SetCursorPosRel(const TPoint& aPos) {iCon->SetCursorPosRel(aPos);};
    1.44 +	void SetCursorHeight(TInt aHeight) {iCon->SetCursorHeight(aHeight);};
    1.45 +	void SetTitle(const TDesC16& aTitle) {iCon->SetTitle(aTitle);};
    1.46 +	void ClearScreen(void) {iCon->ClearScreen();};
    1.47 +	void ClearToEndOfLine(void) {iCon->ClearToEndOfLine();};
    1.48 +	TSize ScreenSize(void) const {return iCon->ScreenSize();};
    1.49 +	TKeyCode KeyCode(void) const {return iCon->KeyCode();};
    1.50 +	TUint KeyModifiers(void) const {return iCon->KeyModifiers();};
    1.51 +	~CTestConsole(void);
    1.52 +private:
    1.53 +	void ConstructL(const TDesC &aFileName);
    1.54 +	CTestConsole(void);
    1.55 +	CConsoleBase* iCon;
    1.56 +	RFs iFs;
    1.57 +	RFile iFile;
    1.58 +	};
    1.59 +
    1.60 +CTestConsole* CTestConsole::NewL(CConsoleBase* aCon, const TDesC &aFileName)
    1.61 +	{
    1.62 +	CTestConsole* self;
    1.63 +	self=new (ELeave) CTestConsole;
    1.64 +	CleanupStack::PushL(self);
    1.65 +	self->iCon=aCon;
    1.66 +	self->ConstructL(aFileName);
    1.67 +	CleanupStack::Pop(self);
    1.68 +	return self;
    1.69 +	}
    1.70 +
    1.71 +void CTestConsole::ConstructL(const TDesC &aFileName)
    1.72 +	{
    1.73 +	User::LeaveIfError(iFs.Connect());
    1.74 +	(void) iFs.Delete(aFileName);
    1.75 +	User::LeaveIfError(iFile.Create(iFs, aFileName, EFileShareAny | EFileWrite));
    1.76 +	}
    1.77 +
    1.78 +
    1.79 +CTestConsole::CTestConsole(void):CConsoleBase()
    1.80 +	{
    1.81 +	}
    1.82 +
    1.83 +CTestConsole::~CTestConsole(void)
    1.84 +
    1.85 +	{
    1.86 +	delete iCon;
    1.87 +	iFile.Close();
    1.88 +	iFs.Close();
    1.89 +	}
    1.90 +
    1.91 +void CTestConsole::Write(const TDesC16& aString)
    1.92 +
    1.93 +	{
    1.94 +	iCon->Write(aString);
    1.95 +	TUint8 space[200];
    1.96 +	TPtr8 ptr(space,200);
    1.97 +	ptr.Copy(aString);
    1.98 +	iFile.Write(ptr);
    1.99 +	}
   1.100 +
   1.101 +EXPORT_C RTestWrapper::RTestWrapper(const TDesC &aTitle,TInt aThrowaway,const TText* anOtherThrowaway)
   1.102 +	: RTest(aTitle, aThrowaway, anOtherThrowaway),
   1.103 +	  iNestLevel(0),
   1.104 +	  iTestCount(0),
   1.105 +	  iThisTestFailed(EFalse),
   1.106 +	  iFailedCount(0),
   1.107 +	  iTitle(aTitle)
   1.108 +	{
   1.109 +	}
   1.110 +
   1.111 +EXPORT_C void RTestWrapper::operator()(TInt aResult,TInt aLineNum,const TText* aFileName)
   1.112 +	{
   1.113 +	if(!aResult)
   1.114 +		{
   1.115 +		RTest::Printf(_L("RTEST: Test FAILED %s:%d\n"), aFileName, aLineNum);
   1.116 +		if(!iThisTestFailed)
   1.117 +			{
   1.118 +			++iFailedCount;
   1.119 +			}
   1.120 +		iThisTestFailed = ETrue;
   1.121 +		}
   1.122 +	}
   1.123 +
   1.124 +EXPORT_C void RTestWrapper::Title(const TDesC &aFileName)
   1.125 +	{
   1.126 +	//	CheckConsoleCreated(); // Can not use this because they forgot to export it!
   1.127 +	RTest::Title(); // Make sure console is created before we try and wrap it
   1.128 +	CConsoleBase *console(0);
   1.129 +	TRAPD(err, console = CTestConsole::NewL(RTest::Console(), aFileName));
   1.130 +	if(err == KErrNone)
   1.131 +	{
   1.132 +		RTest::SetConsole(console);
   1.133 +	}
   1.134 +
   1.135 +	RTest::Title();
   1.136 +	}
   1.137 +
   1.138 +
   1.139 +EXPORT_C void RTestWrapper::Start(const TDesC16 &aHeading)
   1.140 +	{
   1.141 +	RTest::Start(aHeading);
   1.142 +	++iNestLevel;
   1.143 +	++iTestCount;
   1.144 +	iThisTestFailed = EFalse;
   1.145 +	}
   1.146 +
   1.147 +EXPORT_C void RTestWrapper::Next(const TDesC16 &aHeading)
   1.148 +	{
   1.149 +	RTest::Next(aHeading);
   1.150 +	++iTestCount;
   1.151 +	iThisTestFailed = EFalse;
   1.152 +	}
   1.153 +
   1.154 +EXPORT_C void RTestWrapper::End()
   1.155 +	{
   1.156 +	RTest::End();
   1.157 +	--iNestLevel;
   1.158 +	if(iNestLevel == 0)
   1.159 +		{
   1.160 +		RTest::Printf(_L("\r\n%d tests failed out of %d\r\n"), iFailedCount, iTestCount);
   1.161 +		}
   1.162 +	}
   1.163 +
   1.164 +// End of file