ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

file_reporter.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2003, 2004
00003  * Zdenek Nemec
00004  *
00005  * This material is provided "as is", with absolutely no warranty expressed
00006  * or implied. Any use is at your own risk.
00007  *
00008  * Permission to use or copy this software for any purpose is hereby granted
00009  * without fee, provided the above notices are retained on all copies.
00010  * Permission to modify the code and to distribute modified code is granted,
00011  * provided the above notices are retained, and a notice that the code was
00012  * modified is included with the above copyright notice.
00013  *
00014  */
00015 
00016 /* $Id$ */
00017 
00018 #ifndef _CPPUNITMINIFILEREPORTERINTERFACE_H_
00019 #define _CPPUNITMINIFILEREPORTERINTERFACE_H_
00020 
00021 #include <stdio.h>
00022 
00023 #include "cppunit_timer.h"
00024 
00025 //
00026 // CppUnit mini file(stream) reporter
00027 //
00028 class FileReporter : public CPPUNIT_NS::Reporter {
00029 private:
00030   FileReporter(const FileReporter&);
00031   FileReporter& operator=(const FileReporter&);
00032 public:
00033   // reporting to stderr
00034   explicit FileReporter(bool doMonitor = false):
00035       m_numErrors(0), m_numIgnored(0), m_numExplicit(0), m_numTests(0), _myStream(false),
00036       m_failed(false), m_doMonitor(doMonitor)
00037   { _file = stderr; }
00038 
00039   // reporting to the file with the given name
00040   explicit FileReporter(const char* file, bool doMonitor = false):
00041       m_numErrors(0), m_numIgnored(0), m_numExplicit(0), m_numTests(0), _myStream(true),
00042       m_failed(false), m_doMonitor(doMonitor)
00043   {
00044 #ifndef _STLP_USE_SAFE_STRING_FUNCTIONS
00045     _file = fopen(file, "w");
00046 #else
00047     fopen_s(&_file, file, "w");
00048 #endif
00049   }
00050 
00051   // reporting to the given file
00052   explicit FileReporter(FILE* stream, bool doMonitor = false):
00053       m_numErrors(0), m_numIgnored(0), m_numExplicit(0), m_numTests(0), _myStream(false),
00054       m_failed(false), m_doMonitor(doMonitor)
00055   { _file = stream; }
00056 
00057   virtual ~FileReporter() {
00058     if (_myStream)
00059       fclose(_file);
00060     else
00061       fflush(_file);
00062   }
00063 
00064   virtual void error(const char *in_macroName, const char *in_macro, const char *in_file, int in_line) {
00065     // Error might be called several times between 2 progress calls, we shouldn't however consider
00066     // that a test failed twice so we simply keep the info that test failed, number of failed tests
00067     // is computed later in end method.
00068     m_failed = true;
00069     fprintf(_file, "\n\n%s(%d) : %s(%s);", in_file, in_line, in_macroName, in_macro);
00070   }
00071 
00072   virtual void message( const char *msg )
00073   { fprintf(_file, "\n\t%s", msg ); }
00074 
00075   virtual void progress(const char *in_className, const char *in_shortTestName, bool ignored, bool explicitTest) {
00076     if (m_doMonitor) {
00077       m_globalTimer.restart();
00078       m_testTimer.start();
00079     }
00080     ++m_numTests;
00081     m_failed = false;
00082     if (ignored)
00083       ++m_numIgnored;
00084     fprintf(_file, "%s::%s", in_className, in_shortTestName);
00085     if (ignored) {
00086       const char *ignoredReason;
00087       if (explicitTest) {
00088         ++m_numExplicit;
00089         ignoredReason = " EXPLICIT";
00090       }
00091       else
00092         ignoredReason = " IGNORED";
00093 
00094       fprintf(_file, "%s", ignoredReason);
00095     }
00096   }
00097 
00098   virtual void end() {
00099     if (m_doMonitor) {
00100       m_globalTimer.stop();
00101       m_testTimer.stop();
00102       fprintf(_file, " %f msec", m_testTimer.elapsedMilliseconds());
00103     }
00104     if (m_failed) {
00105       ++m_numErrors;
00106     }
00107     fprintf(_file, "\n");
00108   }
00109 
00110   virtual void printSummary() {
00111     if (m_numErrors > 0) {
00112       fprintf(_file, "\nThere were errors! %d of %d tests", m_numErrors, m_numTests);
00113     }
00114     else {
00115       fprintf(_file, "\nOK %d tests", m_numTests);
00116     }
00117 
00118     if (m_numIgnored > 0) {
00119       fprintf(_file, ", %d ignored", m_numIgnored);
00120     }
00121 
00122     if (m_numExplicit > 0) {
00123       fprintf(_file, " (%d explicit)", m_numExplicit);
00124     }
00125 
00126     if (m_doMonitor) {
00127       fprintf(_file, " %f msec", m_globalTimer.elapsedMilliseconds());
00128     }
00129 
00130     fprintf(_file, "\n\n");
00131   }
00132 private:
00133   int m_numErrors;
00134   int m_numIgnored;
00135   int m_numExplicit;
00136   int m_numTests;
00137   // flag whether we own '_file' and are thus responsible for releasing it in the destructor
00138   bool  _myStream;
00139   bool m_failed;
00140   bool m_doMonitor;
00141   Timer m_globalTimer, m_testTimer;
00142   FILE* _file;
00143 };
00144 
00145 #endif /*_CPPUNITMINIFILEREPORTERINTERFACE_H_*/

Generated on Fri May 25 2012 04:33:48 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.