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