UTPP
Loading...
Searching...
No Matches
reporter_dbgout.h
Go to the documentation of this file.
1#pragma once
2/*
3 UTPP - A New Generation of UnitTest++
4 (c) Mircea Neacsu 2017-2024
5
6 See LICENSE file for full copyright information.
7*/
8
13
14#include <iomanip>
15
16namespace UnitTest {
17
19class ReporterDbgout : public Reporter
20{
21protected:
22 void SuiteStart (const TestSuite& suite) override;
23 void TestStart (const Test& test) override;
24 void TestFinish (const Test& test) override;
25 int SuiteFinish (const TestSuite& suite) override;
26
27 void ReportFailure (const Failure& failure) override;
28 int Summary () override;
29private:
30#ifdef _UNICODE
31 std::wstring widen (const std::string& s);
32 inline void ODS (std::stringstream& ss) {
33 OutputDebugString (widen (ss.str ()).c_str ());
34 }
35#else
36 inline void ODS (std::stringstream& ss) {
37 OutputDebugString (ss.str ().c_str());
38 }
39#endif
40};
41
42
44inline
46{
48 if (!trace)
49 return;
50
51 std::stringstream ss;
52 ss << "Suite starting: " << suite.name << std::endl;
53 ODS (ss);
54}
55
57inline
59{
61 if (!trace)
62 return;
63 std::stringstream ss;
64 ss << "Test starting: " << test.test_name () << std::endl;
65 ODS (ss);
66}
67
69inline
71{
72 if (trace)
73 {
74 std::stringstream ss;
75 ss << "Test finished: " << test.test_name () << std::endl;
76 ODS (ss);
77 }
79}
80
82inline
84{
85 if (trace)
86 {
87 std::stringstream ss;
88 ss << "Suite finishing: " << suite.name << std::endl;
89 ODS (ss);
90 }
91 return Reporter::SuiteFinish (suite);
92}
93
94
101inline
103{
104 std::stringstream ss;
105 ss << "Failure in ";
106 if (CurrentTest)
107 {
109 ss << "suite " << CurrentSuite << ' ';
110 ss << "test " << CurrentTest->test_name ();
111 }
112 ss << std::endl;
113 ODS (ss);
114
115 ss.clear ();
116 ss.str ("");
117 ss << failure.filename << "(" << failure.line_number << "):"
118 << failure.message << std::endl;
119 ODS (ss);
120 Reporter::ReportFailure (failure);
121}
122
127inline
129{
130 std::stringstream ss;
131 if (total_failed_count > 0)
132 {
133 ss << "FAILURE: " << total_failed_count << " out of "
134 << total_test_count << " tests failed (" << total_failures_count
135 << " failures).";
136 }
137 else
138 {
139 ss << "Success: " << total_test_count << " tests passed.";
140 }
141 ss << std::endl;
142 ODS (ss);
143
144 ss.clear ();
145 ss.str ("");
146 ss.setf (std::ios::fixed);
147 ss << "Run time: " << std::setprecision (2) << total_time_msec / 1000.;
148 ODS (ss);
149
150 return Reporter::Summary ();
151}
152
153#ifdef _UNICODE
155inline
156std::wstring ReporterDbgout::widen (const std::string& s)
157{
158 int nsz = (int)s.size ();
159 int wsz = MultiByteToWideChar (CP_UTF8, 0, s.c_str (), nsz, 0, 0);
160 std::wstring out (wsz, 0);
161 if (wsz)
162 MultiByteToWideChar (CP_UTF8, 0, s.c_str (), nsz, &out[0], wsz);
163 return out;
164}
165#endif
166
167}
A Reporter that sends messages to debug output.
Definition reporter_dbgout.h:20
void SuiteStart(const TestSuite &suite) override
If tracing is enabled, show a suite start message.
Definition reporter_dbgout.h:45
void TestStart(const Test &test) override
If tracing is enabled, show a test start message.
Definition reporter_dbgout.h:58
void ReportFailure(const Failure &failure) override
Definition reporter_dbgout.h:102
int Summary() override
Definition reporter_dbgout.h:128
int SuiteFinish(const TestSuite &suite) override
If tracing is enabled, show a suite finish message.
Definition reporter_dbgout.h:83
void TestFinish(const Test &test) override
If tracing is enabled, show a test finish message.
Definition reporter_dbgout.h:70
int total_failures_count
total number of failures
Definition utpp.h:317
virtual void SuiteStart(const TestSuite &suite)
Invoked at the beginning of a test suite.
Definition utpp.h:581
virtual void TestStart(const Test &test)
Invoked at the beginning of a test.
Definition utpp.h:588
bool trace
true if tracing is enabled
Definition utpp.h:321
virtual void TestFinish(const Test &test)
Invoked at the end of a test.
Definition utpp.h:600
int total_test_count
total number of tests
Definition utpp.h:315
virtual void ReportFailure(const Failure &failure)
Called when a test has failed.
Definition utpp.h:595
virtual int Summary()
Generate results report.
Definition utpp.h:304
int total_failed_count
total number of failed tests
Definition utpp.h:316
virtual int SuiteFinish(const TestSuite &suite)
Invoked at the end of a test suite.
Definition utpp.h:617
int total_time_msec
total running time in milliseconds
Definition utpp.h:318
Representation of a test case.
Definition utpp.h:240
const std::string & test_name() const
Return test name.
Definition utpp.h:544
Definition utpp.h:362
std::string name
Suite name.
Definition utpp.h:389
The failure object records the file name, the line number and a message.
Definition utpp.h:271
int line_number
Line number where the failure has occurred.
Definition utpp.h:274
std::string message
Description of failure.
Definition utpp.h:273
std::string filename
Name of file where a failure has occurred.
Definition utpp.h:272
#define DEFAULT_SUITE
Name of default suite.
Definition utpp.h:54
Test * CurrentTest
Currently executing test.
std::string CurrentSuite
Name of currently running suite.