4 * Copyright (c) 2003, 2004
7 * This material is provided "as is", with absolutely no warranty expressed
8 * or implied. Any use is at your own risk.
10 * Permission to use or copy this software for any purpose is hereby granted
11 * without fee, provided the above notices are retained on all copies.
12 * Permission to modify the code and to distribute modified code is granted,
13 * provided the above notices are retained, and a notice that the code was
14 * modified is included with the above copyright notice.
20 #ifndef CDS_CPPUNIT_MINIFILEREPORTERINTERFACE_H_
21 #define CDS_CPPUNIT_MINIFILEREPORTERINTERFACE_H_
25 #include <cds/os/timer.h>
27 namespace CppUnitMini {
28 typedef cds::OS::Timer Timer;
30 // CppUnit mini file(stream) reporter
32 class FileReporter : public CppUnitMini::Reporter {
34 FileReporter(const FileReporter&);
35 FileReporter& operator=(const FileReporter&);
37 // reporting to stderr
38 explicit FileReporter(bool doMonitor = false):
39 m_numErrors(0), m_numIgnored(0), m_numExplicit(0), m_numTests(0), _myStream(false),
40 m_failed(false), m_doMonitor(doMonitor)
43 // reporting to the file with the given name
44 explicit FileReporter(const char* file, bool doMonitor = false):
45 m_numErrors(0), m_numIgnored(0), m_numExplicit(0), m_numTests(0), _myStream(true),
46 m_failed(false), m_doMonitor(doMonitor)
48 #ifndef _STLP_USE_SAFE_STRING_FUNCTIONS
49 _file = fopen(file, "w");
51 fopen_s(&_file, file, "w");
55 // reporting to the given file
56 explicit FileReporter(FILE* stream, bool doMonitor = false):
57 m_numErrors(0), m_numIgnored(0), m_numExplicit(0), m_numTests(0), _myStream(false),
58 m_failed(false), m_doMonitor(doMonitor)
61 virtual ~FileReporter() {
68 virtual void error(const char *in_macroName, const char *in_macro, const char *in_file, int in_line) {
69 // Error might be called several times between 2 progress calls, we shouldn't however consider
70 // that a test failed twice so we simply keep the info that test failed, number of failed tests
71 // is computed later in end method.
73 fprintf(_file, "\n\n%s(%d) : %s(%s);", in_file, in_line, in_macroName, in_macro);
77 virtual void message( const char *msg )
78 { fprintf(_file, "\n\t%s", msg ); fflush(_file); }
80 virtual void progress(const char *in_className, const char *in_shortTestName, bool ignored, bool explicitTest) {
88 fprintf(_file, "%s::%s", in_className, in_shortTestName);
90 const char *ignoredReason;
93 ignoredReason = " EXPLICIT";
96 ignoredReason = " IGNORED";
98 fprintf(_file, "%s", ignoredReason);
104 fprintf(_file, " %f msec", m_testTimer.duration());
109 fprintf(_file, "\n");
113 virtual void printSummary() {
114 if (m_numErrors > 0) {
115 fprintf(_file, "\nThere were errors! %d of %d tests", m_numErrors, m_numTests);
118 fprintf(_file, "\nOK %d tests", m_numTests);
121 if (m_numIgnored > 0) {
122 fprintf(_file, ", %d ignored", m_numIgnored);
125 if (m_numExplicit > 0) {
126 fprintf(_file, " (%d explicit)", m_numExplicit);
129 fprintf(_file, "\n\n");
137 // flag whether we own '_file' and are thus responsible for releasing it in the destructor
145 #endif // #ifndef CDS_CPPUNIT_MINIFILEREPORTERINTERFACE_H_