1 /*
2  *  Created by Phil on 6th April 2013.
3  *  Copyright 2013 Two Blue Cubes Ltd. All rights reserved.
4  *
5  *  Distributed under the Boost Software License, Version 1.0. (See accompanying
6  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7  */
8 #ifndef TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_HPP_INCLUDED
9 #define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_HPP_INCLUDED
10 
11 #include "catch_legacy_reporter_adapter.h"
12 
13 namespace Catch
14 {
LegacyReporterAdapter(Ptr<IReporter> const & legacyReporter)15     LegacyReporterAdapter::LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter )
16     :   m_legacyReporter( legacyReporter )
17     {}
~LegacyReporterAdapter()18     LegacyReporterAdapter::~LegacyReporterAdapter() {}
19 
getPreferences() const20     ReporterPreferences LegacyReporterAdapter::getPreferences() const {
21         ReporterPreferences prefs;
22         prefs.shouldRedirectStdOut = m_legacyReporter->shouldRedirectStdout();
23         return prefs;
24     }
25 
noMatchingTestCases(std::string const &)26     void LegacyReporterAdapter::noMatchingTestCases( std::string const& ) {}
testRunStarting(TestRunInfo const &)27     void LegacyReporterAdapter::testRunStarting( TestRunInfo const& ) {
28         m_legacyReporter->StartTesting();
29     }
testGroupStarting(GroupInfo const & groupInfo)30     void LegacyReporterAdapter::testGroupStarting( GroupInfo const& groupInfo ) {
31         m_legacyReporter->StartGroup( groupInfo.name );
32     }
testCaseStarting(TestCaseInfo const & testInfo)33     void LegacyReporterAdapter::testCaseStarting( TestCaseInfo const& testInfo ) {
34         m_legacyReporter->StartTestCase( testInfo );
35     }
sectionStarting(SectionInfo const & sectionInfo)36     void LegacyReporterAdapter::sectionStarting( SectionInfo const& sectionInfo ) {
37         m_legacyReporter->StartSection( sectionInfo.name, sectionInfo.description );
38     }
assertionStarting(AssertionInfo const &)39     void LegacyReporterAdapter::assertionStarting( AssertionInfo const& ) {
40         // Not on legacy interface
41     }
42 
assertionEnded(AssertionStats const & assertionStats)43     bool LegacyReporterAdapter::assertionEnded( AssertionStats const& assertionStats ) {
44         if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) {
45             for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end();
46                     it != itEnd;
47                     ++it ) {
48                 if( it->type == ResultWas::Info ) {
49                     ResultBuilder rb( it->macroName.c_str(), it->lineInfo, "", ResultDisposition::Normal );
50                     rb << it->message;
51                     rb.setResultType( ResultWas::Info );
52                     AssertionResult result = rb.build();
53                     m_legacyReporter->Result( result );
54                 }
55             }
56         }
57         m_legacyReporter->Result( assertionStats.assertionResult );
58         return true;
59     }
sectionEnded(SectionStats const & sectionStats)60     void LegacyReporterAdapter::sectionEnded( SectionStats const& sectionStats ) {
61         if( sectionStats.missingAssertions )
62             m_legacyReporter->NoAssertionsInSection( sectionStats.sectionInfo.name );
63         m_legacyReporter->EndSection( sectionStats.sectionInfo.name, sectionStats.assertions );
64     }
testCaseEnded(TestCaseStats const & testCaseStats)65     void LegacyReporterAdapter::testCaseEnded( TestCaseStats const& testCaseStats ) {
66         m_legacyReporter->EndTestCase
67             (   testCaseStats.testInfo,
68                 testCaseStats.totals,
69                 testCaseStats.stdOut,
70                 testCaseStats.stdErr );
71     }
testGroupEnded(TestGroupStats const & testGroupStats)72     void LegacyReporterAdapter::testGroupEnded( TestGroupStats const& testGroupStats ) {
73         if( testGroupStats.aborting )
74             m_legacyReporter->Aborted();
75         m_legacyReporter->EndGroup( testGroupStats.groupInfo.name, testGroupStats.totals );
76     }
testRunEnded(TestRunStats const & testRunStats)77     void LegacyReporterAdapter::testRunEnded( TestRunStats const& testRunStats ) {
78         m_legacyReporter->EndTesting( testRunStats.totals );
79     }
skipTest(TestCaseInfo const &)80     void LegacyReporterAdapter::skipTest( TestCaseInfo const& ) {
81     }
82 }
83 
84 #endif // TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_H_INCLUDED
85