Simplify required check reporter interactions

Was able to remove ThrowingTestReporter::SetDecorated and
::GetDecorated by changing RequiredCheckTestReporter to accept
its TestResults by reference. This simple change removed
several if-checks and some functions.
This commit is contained in:
Patrick Johnmeyer 2016-02-04 23:00:52 -06:00
parent 57fc32c114
commit 5eec0a255f
5 changed files with 9 additions and 24 deletions

View file

@ -8,7 +8,7 @@
#endif
#ifndef UNITTEST_NO_EXCEPTIONS
#define REQUIRE for(UnitTest::RequiredCheckTestReporter decoratedReporter(UnitTest::CurrentTest::Results()); decoratedReporter.Next(); )
#define REQUIRE for(UnitTest::RequiredCheckTestReporter decoratedReporter(*UnitTest::CurrentTest::Results()); decoratedReporter.Next(); )
#endif
#ifdef UNITTEST_NO_EXCEPTIONS

View file

@ -5,21 +5,18 @@
namespace UnitTest {
RequiredCheckTestReporter::RequiredCheckTestReporter(TestResults* results)
RequiredCheckTestReporter::RequiredCheckTestReporter(TestResults& results)
: m_results(results)
, m_throwingReporter(0)
, m_originalTestReporter(results.m_testReporter)
, m_throwingReporter(results.m_testReporter)
, m_continue(0)
{
if(m_results)
{
m_throwingReporter.SetDecorated(m_results->m_testReporter);
m_results->m_testReporter = &m_throwingReporter;
}
m_results.m_testReporter = &m_throwingReporter;
}
RequiredCheckTestReporter::~RequiredCheckTestReporter()
{
if(m_results) m_results->m_testReporter = m_throwingReporter.GetDecorated();
m_results.m_testReporter = m_originalTestReporter;
}
bool RequiredCheckTestReporter::Next()

View file

@ -13,13 +13,14 @@ namespace UnitTest {
class UNITTEST_LINKAGE RequiredCheckTestReporter
{
public:
explicit RequiredCheckTestReporter(TestResults* results);
explicit RequiredCheckTestReporter(TestResults& results);
~RequiredCheckTestReporter();
bool Next();
private:
TestResults* m_results;
TestResults& m_results;
TestReporter* m_originalTestReporter;
ThrowingTestReporter m_throwingReporter;
int m_continue;
};

View file

@ -36,14 +36,4 @@ namespace UnitTest {
if(m_decoratedReporter) m_decoratedReporter->ReportSummary(totalTestCount, failedTestCount, failureCount, secondsElapsed);
}
TestReporter* ThrowingTestReporter::GetDecorated() const
{
return m_decoratedReporter;
}
void ThrowingTestReporter::SetDecorated(TestReporter* reporter)
{
m_decoratedReporter = reporter;
}
}

View file

@ -18,9 +18,6 @@ namespace UnitTest {
virtual void ReportTestFinish(TestDetails const& test, float secondsElapsed);
virtual void ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed);
TestReporter* GetDecorated() const;
void SetDecorated(TestReporter* reporter);
private:
TestReporter* m_decoratedReporter;
};