2010-11-10 00:24:00 +01:00
|
|
|
/*
|
|
|
|
* catch_reporter_xml.hpp
|
|
|
|
* Catch
|
|
|
|
*
|
|
|
|
* Created by Phil on 28/10/2010.
|
|
|
|
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
|
|
|
*
|
|
|
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#ifndef TWOBLUECUBES_CATCH_REPORTER_XML_HPP_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_REPORTER_XML_HPP_INCLUDED
|
|
|
|
|
2011-06-02 09:49:47 +02:00
|
|
|
#include "../internal/catch_capture.hpp"
|
|
|
|
#include "../internal/catch_interfaces_reporter.h"
|
|
|
|
#include "../internal/catch_reporter_registrars.hpp"
|
|
|
|
#include "../internal/catch_xmlwriter.hpp"
|
2010-11-10 00:24:00 +01:00
|
|
|
|
|
|
|
namespace Catch
|
|
|
|
{
|
2010-12-31 23:07:47 +01:00
|
|
|
class XmlReporter : public Catch::IReporter
|
2010-11-10 00:24:00 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-18 10:20:06 +01:00
|
|
|
XmlReporter
|
|
|
|
(
|
|
|
|
const IReporterConfig& config
|
|
|
|
)
|
|
|
|
: m_config( config )
|
2010-11-10 00:24:00 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-18 10:20:06 +01:00
|
|
|
static std::string getDescription
|
|
|
|
()
|
2010-11-10 00:24:00 +01:00
|
|
|
{
|
|
|
|
return "Reports test results as an XML document";
|
|
|
|
}
|
|
|
|
|
2010-12-31 23:07:47 +01:00
|
|
|
private: // IReporter
|
2010-11-10 00:24:00 +01:00
|
|
|
|
2010-12-10 21:01:40 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-18 10:20:06 +01:00
|
|
|
virtual void StartTesting
|
|
|
|
()
|
2010-12-10 21:01:40 +01:00
|
|
|
{
|
|
|
|
m_xml = XmlWriter( m_config.stream() );
|
2011-04-12 08:39:45 +02:00
|
|
|
m_xml.startElement( "Catch" );
|
2011-04-12 09:07:39 +02:00
|
|
|
if( !m_config.getName().empty() )
|
|
|
|
m_xml.writeAttribute( "name", m_config.getName() );
|
2010-12-10 21:01:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-18 10:20:06 +01:00
|
|
|
virtual void EndTesting
|
|
|
|
(
|
|
|
|
std::size_t succeeded,
|
|
|
|
std::size_t failed
|
|
|
|
)
|
2010-12-10 21:01:40 +01:00
|
|
|
{
|
|
|
|
m_xml.scopedElement( "OverallResults" )
|
|
|
|
.writeAttribute( "successes", succeeded )
|
|
|
|
.writeAttribute( "failures", failed );
|
2011-04-12 08:38:23 +02:00
|
|
|
m_xml.endElement();
|
2010-12-10 21:01:40 +01:00
|
|
|
}
|
2010-11-29 20:40:44 +01:00
|
|
|
|
2010-12-10 21:01:40 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-18 10:20:06 +01:00
|
|
|
virtual void StartGroup
|
|
|
|
(
|
|
|
|
const std::string& groupName
|
|
|
|
)
|
2010-12-10 21:01:40 +01:00
|
|
|
{
|
|
|
|
m_xml.startElement( "Group" )
|
|
|
|
.writeAttribute( "name", groupName );
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-18 10:20:06 +01:00
|
|
|
virtual void EndGroup
|
|
|
|
(
|
|
|
|
const std::string& /*groupName*/,
|
|
|
|
std::size_t succeeded,
|
|
|
|
std::size_t failed
|
|
|
|
)
|
2010-12-10 21:01:40 +01:00
|
|
|
{
|
|
|
|
m_xml.scopedElement( "OverallResults" )
|
|
|
|
.writeAttribute( "successes", succeeded )
|
|
|
|
.writeAttribute( "failures", failed );
|
|
|
|
m_xml.endElement();
|
|
|
|
}
|
2010-11-29 20:40:44 +01:00
|
|
|
|
2010-12-10 21:01:40 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
virtual void StartSection( const std::string& sectionName, const std::string description )
|
|
|
|
{
|
|
|
|
m_xml.startElement( "Section" )
|
|
|
|
.writeAttribute( "name", sectionName )
|
|
|
|
.writeAttribute( "description", description );
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2010-12-28 18:21:29 +01:00
|
|
|
virtual void EndSection( const std::string& /*sectionName*/, std::size_t succeeded, std::size_t failed )
|
2010-12-10 21:01:40 +01:00
|
|
|
{
|
|
|
|
m_xml.scopedElement( "OverallResults" )
|
|
|
|
.writeAttribute( "successes", succeeded )
|
|
|
|
.writeAttribute( "failures", failed );
|
|
|
|
m_xml.endElement();
|
|
|
|
}
|
2010-11-29 20:40:44 +01:00
|
|
|
|
2010-11-10 00:24:00 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
virtual void StartTestCase( const Catch::TestCaseInfo& testInfo )
|
|
|
|
{
|
2010-12-10 21:01:40 +01:00
|
|
|
m_xml.startElement( "TestCase" ).writeAttribute( "name", testInfo.getName() );
|
2010-11-10 00:24:00 +01:00
|
|
|
m_currentTestSuccess = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
virtual void Result( const Catch::ResultInfo& resultInfo )
|
|
|
|
{
|
2010-12-27 23:05:13 +01:00
|
|
|
if( !m_config.includeSuccessfulResults() && resultInfo.getResultType() == ResultWas::Ok )
|
2010-11-10 00:24:00 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if( resultInfo.hasExpression() )
|
|
|
|
{
|
2010-12-10 21:01:40 +01:00
|
|
|
m_xml.startElement( "Expression" )
|
|
|
|
.writeAttribute( "success", resultInfo.ok() )
|
|
|
|
.writeAttribute( "filename", resultInfo.getFilename() )
|
|
|
|
.writeAttribute( "line", resultInfo.getLine() );
|
|
|
|
|
|
|
|
m_xml.scopedElement( "Original" )
|
|
|
|
.writeText( resultInfo.getExpression() );
|
|
|
|
m_xml.scopedElement( "Expanded" )
|
|
|
|
.writeText( resultInfo.getExpandedExpression() );
|
2011-04-19 19:53:24 +02:00
|
|
|
m_currentTestSuccess &= resultInfo.ok();
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
2010-12-10 21:01:40 +01:00
|
|
|
|
2010-11-10 00:24:00 +01:00
|
|
|
switch( resultInfo.getResultType() )
|
|
|
|
{
|
|
|
|
case ResultWas::ThrewException:
|
2010-12-10 21:01:40 +01:00
|
|
|
m_xml.scopedElement( "Exception" )
|
2011-04-22 20:22:14 +02:00
|
|
|
.writeAttribute( "filename", resultInfo.getFilename() )
|
|
|
|
.writeAttribute( "line", resultInfo.getLine() )
|
2010-12-10 21:01:40 +01:00
|
|
|
.writeText( resultInfo.getMessage() );
|
2010-11-10 00:24:00 +01:00
|
|
|
m_currentTestSuccess = false;
|
|
|
|
break;
|
|
|
|
case ResultWas::Info:
|
2010-12-10 21:01:40 +01:00
|
|
|
m_xml.scopedElement( "Info" )
|
|
|
|
.writeText( resultInfo.getMessage() );
|
2010-11-10 00:24:00 +01:00
|
|
|
break;
|
|
|
|
case ResultWas::Warning:
|
2010-12-10 21:01:40 +01:00
|
|
|
m_xml.scopedElement( "Warning" )
|
|
|
|
.writeText( resultInfo.getMessage() );
|
2010-11-10 00:24:00 +01:00
|
|
|
break;
|
|
|
|
case ResultWas::ExplicitFailure:
|
2010-12-10 21:01:40 +01:00
|
|
|
m_xml.scopedElement( "Failure" )
|
|
|
|
.writeText( resultInfo.getMessage() );
|
2010-11-10 00:24:00 +01:00
|
|
|
m_currentTestSuccess = false;
|
|
|
|
break;
|
2010-12-28 15:42:46 +01:00
|
|
|
default:
|
|
|
|
break;
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
|
|
|
if( resultInfo.hasExpression() )
|
2010-12-10 21:01:40 +01:00
|
|
|
m_xml.endElement();
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-14 09:26:58 +01:00
|
|
|
virtual void EndTestCase( const Catch::TestCaseInfo&, std::size_t /* succeeded */, std::size_t /* failed */, const std::string& /*stdOut*/, const std::string& /*stdErr*/ )
|
2010-11-10 00:24:00 +01:00
|
|
|
{
|
2010-12-10 21:01:40 +01:00
|
|
|
m_xml.scopedElement( "OverallResult" ).writeAttribute( "success", m_currentTestSuccess );
|
|
|
|
m_xml.endElement();
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2010-12-31 23:07:47 +01:00
|
|
|
const IReporterConfig& m_config;
|
2010-11-10 00:24:00 +01:00
|
|
|
bool m_currentTestSuccess;
|
2010-12-10 21:01:40 +01:00
|
|
|
XmlWriter m_xml;
|
2010-11-10 00:24:00 +01:00
|
|
|
};
|
|
|
|
|
2011-02-16 20:02:09 +01:00
|
|
|
INTERNAL_CATCH_REGISTER_REPORTER( "xml", XmlReporter )
|
2010-12-31 17:12:48 +01:00
|
|
|
|
2010-11-10 00:24:00 +01:00
|
|
|
} // end namespace Catch
|
|
|
|
|
2010-12-28 15:42:46 +01:00
|
|
|
#endif // TWOBLUECUBES_CATCH_REPORTER_XML_HPP_INCLUDED
|