2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 this list of conditions and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * Copyright (c) 2003, 2004
35 * This material is provided "as is", with absolutely no warranty expressed
36 * or implied. Any use is at your own risk.
38 * Permission to use or copy this software for any purpose is hereby granted
39 * without fee, provided the above notices are retained on all copies.
40 * Permission to modify the code and to distribute modified code is granted,
41 * provided the above notices are retained, and a notice that the code was
42 * modified is included with the above copyright notice.
48 #ifndef CDS_CPPUNIT_MINIFILEREPORTERINTERFACE_H_
49 #define CDS_CPPUNIT_MINIFILEREPORTERINTERFACE_H_
53 #include <cds/os/timer.h>
55 namespace CppUnitMini {
56 typedef cds::OS::Timer Timer;
58 // CppUnit mini file(stream) reporter
60 class FileReporter : public CppUnitMini::Reporter {
62 FileReporter(const FileReporter&);
63 FileReporter& operator=(const FileReporter&);
65 // reporting to stderr
66 explicit FileReporter(bool doMonitor = false):
67 m_numErrors(0), m_numIgnored(0), m_numExplicit(0), m_numTests(0), _myStream(false),
68 m_failed(false), m_doMonitor(doMonitor)
71 // reporting to the file with the given name
72 explicit FileReporter(const char* file, bool doMonitor = false):
73 m_numErrors(0), m_numIgnored(0), m_numExplicit(0), m_numTests(0), _myStream(true),
74 m_failed(false), m_doMonitor(doMonitor)
76 #ifndef _STLP_USE_SAFE_STRING_FUNCTIONS
77 _file = fopen(file, "w");
79 fopen_s(&_file, file, "w");
83 // reporting to the given file
84 explicit FileReporter(FILE* stream, bool doMonitor = false):
85 m_numErrors(0), m_numIgnored(0), m_numExplicit(0), m_numTests(0), _myStream(false),
86 m_failed(false), m_doMonitor(doMonitor)
89 virtual ~FileReporter() {
96 virtual void error(const char *in_macroName, const char *in_macro, const char *in_file, int in_line) {
97 // Error might be called several times between 2 progress calls, we shouldn't however consider
98 // that a test failed twice so we simply keep the info that test failed, number of failed tests
99 // is computed later in end method.
101 fprintf(_file, "\n\n%s(%d) : %s(%s);", in_file, in_line, in_macroName, in_macro);
105 virtual void message( const char *msg )
106 { fprintf(_file, "\n\t%s", msg ); fflush(_file); }
108 virtual void progress(const char *in_className, const char *in_shortTestName, bool ignored, bool explicitTest) {
116 fprintf(_file, "%s::%s", in_className, in_shortTestName);
118 const char *ignoredReason;
121 ignoredReason = " EXPLICIT";
124 ignoredReason = " IGNORED";
126 fprintf(_file, "%s", ignoredReason);
132 fprintf(_file, " %f msec", m_testTimer.duration());
137 fprintf(_file, "\n");
141 virtual void printSummary() {
142 if (m_numErrors > 0) {
143 fprintf(_file, "\nThere were errors! %d of %d tests", m_numErrors, m_numTests);
146 fprintf(_file, "\nOK %d tests", m_numTests);
149 if (m_numIgnored > 0) {
150 fprintf(_file, ", %d ignored", m_numIgnored);
153 if (m_numExplicit > 0) {
154 fprintf(_file, " (%d explicit)", m_numExplicit);
157 fprintf(_file, "\n\n");
165 // flag whether we own '_file' and are thus responsible for releasing it in the destructor
173 #endif // #ifndef CDS_CPPUNIT_MINIFILEREPORTERINTERFACE_H_