diff -r 000000000000 -r 3e07fef1e154 testexecfw/symbianunittestfw/sutfw/sutfwcore/sutfwoutput/src/symbianunittestoutputasxml.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testexecfw/symbianunittestfw/sutfw/sutfwcore/sutfwoutput/src/symbianunittestoutputasxml.cpp Mon Mar 08 15:03:44 2010 +0800 @@ -0,0 +1,152 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include "symbianunittestresult.h" +#include "symbianunittestfailure.h" +#include "symbianunittestfileoutputwriter.h" +#include "symbianunittestoutputasxml.h" + + +_LIT8( KXmlResultOpenTag, "\r\n" ); +_LIT8( KXmlResultCloseTag, "\r\n" ); +_LIT8( KXmlPassedTestsTag, "\t\r\n" ); +_LIT8( KXmlFailedTestsOpenTag, "\t\r\n" ); +_LIT8( KXmlFailedTestsCloseTag, "\t\r\n" ); +_LIT8( KXmlFailureOpenTag, "\t\t\r\n" ); +_LIT8( KXmlFailureCloseTag, "\t\t\r\n" ); +_LIT8( KXmlTestNameOpenTag, "\t\t\t\r\n" ); +_LIT8( KXmlTestNameCloseTag, "\r\n\t\t\t\r\n" ); +_LIT8( KXmlFileNameOpenTag, "\t\t\t\r\n" ); +_LIT8( KXmlFileNameCloseTag, "\r\n\t\t\t\r\n" ); +_LIT8( KXmlLineNumberOpenTag, "\t\t\t%d\r\n" ); +_LIT8( KXmlLineNumberCloseTag, "\r\n\t\t\t\r\n" ); +_LIT8( KXmlReasonOpenTag, "\t\t\t\r\n" ); +_LIT8( KXmlReasonCloseTag, "\r\n\t\t\t\r\n" ); + + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +CSymbianUnitTestOutputAsXml* CSymbianUnitTestOutputAsXml::NewL( + const TDesC& aFileName ) + { + CSymbianUnitTestOutputAsXml* self = + new( ELeave )CSymbianUnitTestOutputAsXml; + CleanupStack::PushL( self ); + self->ConstructL( aFileName ); + CleanupStack::Pop( self ); + return self; + } + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +CSymbianUnitTestOutputAsXml::CSymbianUnitTestOutputAsXml() + { + } + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +CSymbianUnitTestOutputAsXml::~CSymbianUnitTestOutputAsXml() + { + } + +// ----------------------------------------------------------------------------- +// From CSymbianUnitTestOutputFormatter +// ----------------------------------------------------------------------------- +// +const TDesC& CSymbianUnitTestOutputAsXml::FileExtension() const + { + return KXmlOutput; + } + +// ----------------------------------------------------------------------------- +// From CSymbianUnitTestOutputFormatter +// ----------------------------------------------------------------------------- +// +void CSymbianUnitTestOutputAsXml::PrintHeaderL( + CSymbianUnitTestResult& aResult ) + { + iOutputWriter->WriteL( KXmlResultOpenTag, aResult.TestCount() ); + } + +// ----------------------------------------------------------------------------- +// From CSymbianUnitTestOutputFormatter +// ----------------------------------------------------------------------------- +// +void CSymbianUnitTestOutputAsXml::PrintPassedTestsL( + CSymbianUnitTestResult& aResult ) + { + iOutputWriter->WriteL( KXmlPassedTestsTag, aResult.PassedTestCount() ); + } + +// ----------------------------------------------------------------------------- +// From CSymbianUnitTestOutputFormatter +// ----------------------------------------------------------------------------- +// +void CSymbianUnitTestOutputAsXml::PrintFailedTestsL( + CSymbianUnitTestResult& aResult ) + { + iOutputWriter->WriteL( KXmlFailedTestsOpenTag, aResult.Failures().Count() ); + for ( TInt i=0; i < aResult.Failures().Count(); i++ ) + { + iOutputWriter->WriteL( KXmlFailureOpenTag ); + PrintFailureDetailsL( *( aResult.Failures()[ i ] ) ); + iOutputWriter->WriteL( KXmlFailureCloseTag ); + } + iOutputWriter->WriteL( KXmlFailedTestsCloseTag ); + } + +// ----------------------------------------------------------------------------- +// From CSymbianUnitTestOutputFormatter +// ----------------------------------------------------------------------------- +// +void CSymbianUnitTestOutputAsXml::PrintFooterL() + { + iOutputWriter->WriteL( KXmlResultCloseTag ); + } + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +void CSymbianUnitTestOutputAsXml::PrintFailureDetailsL( + CSymbianUnitTestFailure& aTestFailure ) + { + iOutputWriter->WriteL( KXmlTestNameOpenTag ); + iOutputWriter->WriteL( aTestFailure.TestName() ); + iOutputWriter->WriteL( KXmlTestNameCloseTag ); + if ( aTestFailure.FileName().Length() > 0 ) + { + iOutputWriter->WriteL( KXmlFileNameOpenTag ); + iOutputWriter->WriteL( aTestFailure.FileName() ); + iOutputWriter->WriteL( KXmlFileNameCloseTag ); + } + TInt lineNumber( aTestFailure.LineNumber() ); + if ( lineNumber >= 0 ) + { + iOutputWriter->WriteL( KXmlLineNumberOpenTag, lineNumber ); + iOutputWriter->WriteL( KXmlLineNumberCloseTag ); + } + iOutputWriter->WriteL( KXmlReasonOpenTag ); + iOutputWriter->WriteL( aTestFailure.FailureMessage() ); + iOutputWriter->WriteL( KXmlReasonCloseTag ); + }