IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
UnitTestLog.h
1 // UnitTestLog.h:
3 // --------------
4 //
14 
15 #ifndef __IPSDKUNITTESTTOOLS_UNITTESTLOG_H__
16 #define __IPSDKUNITTESTTOOLS_UNITTESTLOG_H__
17 
18 // suppression warnings
19 // warning C4275: non dll-interface class 'boost::noncopyable_::noncopyable' used as base for dll-interface class 'ipsdk::UnitTestLog'
20 // warning C4251: 'ipsdk::unittest::UnitTestLog::_outputHtmlFileName' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll-interface to be used by clients of class 'ipsdk::unittest::UnitTestLog'
21 #pragma warning (push)
22 #pragma warning (disable : 4275 4251)
23 
26 #include <IPSDKUtil/BaseTypes.h>
27 #include <IPSDKUtil/Tools/Chrono.h>
28 #include <boost/test/unit_test_log_formatter.hpp>
29 #include <boost/noncopyable.hpp>
30 #include <boost/filesystem/path.hpp>
31 #include <boost/filesystem/fstream.hpp>
32 #include <boost/shared_ptr.hpp>
33 
34 namespace ipsdk {
35 namespace unittest {
36 
37 class UnitTestResult;
38 class PythonUnitTestManager;
39 
42 
43 class IPSDKUNITTESTTOOLS_API UnitTestLog : public boost::unit_test::unit_test_log_formatter,
44  public boost::noncopyable
45 {
46  // friend class for protected members access
47  friend class PythonUnitTestManager;
48 
49 public:
52  UnitTestLog();
53  ~UnitTestLog();
55 
56 // methods
57 public:
59  bool isInit() const;
60 
64  void initCpp(const boost::filesystem::path& outputHtmlFilePath,
65  const boost::filesystem::path& outputResultFilePath,
66  const boost::filesystem::path& logResourceDir,
67  const bool bDisplayReport);
68 
72  void initPython(const boost::filesystem::path& outputHtmlFilePath,
73  const boost::filesystem::path& outputResultFilePath,
74  const boost::filesystem::path& logResourceDir,
75  const ipUInt32 pythonMajorVersion,
76  const ipUInt32 pythonMinorVersion,
77  const bool bDisplayReport);
78 
81  const boost::filesystem::path& getOutputHtmlFilePath() const;
82 
85  const boost::filesystem::path& getOutputResultFilePath() const;
86 
89  void notifyTestStart();
90 
93  void notifyTestSuiteStart(const std::string& testSuiteName);
94 
97  void notifyTestCaseStart(const std::string& testCaseName);
98 
101  void notifyTestSuccess(const std::string& testFilePath,
102  const ipUInt32 testLineIdx,
103  const std::string& testMsg);
104 
107  void notifyTestWarning(const std::string& testFilePath,
108  const ipUInt32 testLineIdx,
109  const std::string& testMsg);
110 
113  void notifyTestFailure(const std::string& testFilePath,
114  const ipUInt32 testLineIdx,
115  const std::string& testMsg);
116 
119  void notifyTestCrash(const std::string& testMsg);
120 
123  void notifyTestException(const std::string& lastCheckPointFilePath,
124  const ipUInt32 lastCheckPointLineIdx,
125  const std::string& exceptionFunctionName,
126  const std::string& exceptionFilePath,
127  const ipUInt32 exceptionLineIdx,
128  const std::string& exceptionMsg);
129 
132  void notifyTestCaseEnd();
133 
136  void notifyTestSuiteEnd();
137 
140  void notifyTestEnd();
141 
142 private:
145  void notifyTestEntry(const std::string& testInfoStr,
146  const std::string& testFilePath,
147  const ipUInt32 testLineIdx,
148  const std::string& testMsg);
149 
152  void log_start(std::ostream& os,
153  boost::unit_test::counter_t);
154 
157  void log_finish(std::ostream& os);
158 
161  void log_build_info(std::ostream& os, bool b);
162 
165  void test_unit_start(std::ostream& os,
166  const boost::unit_test::test_unit& unitTest);
167 
170  void test_unit_finish(std::ostream& os,
171  const boost::unit_test::test_unit& unitTest,
172  unsigned long elapsed);
173 
176  void test_unit_skipped(std::ostream& os,
177  const boost::unit_test::test_unit& unitTest);
178 
181  void log_entry_start(std::ostream& os,
182  const boost::unit_test::log_entry_data& data,
183  log_entry_types let);
184 
187  void log_entry_value(std::ostream& os,
188  boost::unit_test::const_string value);
189 
192  void log_entry_finish(std::ostream& os);
193 
199  void log_exception_start(std::ostream& os,
200  const boost::unit_test::log_checkpoint_data& data,
201  const boost::execution_exception& e);
202 
205  void log_exception_finish(std::ostream& os) {}
206 
210  void entry_context_start(std::ostream& os, boost::unit_test::log_level l) {}
211 
216  void log_entry_context(std::ostream& os, boost::unit_test::log_level l, boost::unit_test::const_string value) {}
217 
219  void entry_context_finish(std::ostream& os, boost::unit_test::log_level l) {}
220 
221 // attributes
222 protected:
224  boost::filesystem::path _outputHtmlFilePath;
225 
227  boost::filesystem::path _outputResultFilePath;
228 
230  boost::filesystem::path _logResourceDir;
231 
233  std::string _testLanguage;
234 
236  boost::filesystem::ofstream _ofs;
237 
240 
243 
246 
249 
252 
255 
257  std::string _curTestValueStr;
258 
260  std::string _curTestInfoStr;
261 
263  std::string _curTestFileName;
264 
265  // current test suite name
266  std::string _curTestSuiteName;
267 
268  // current test case name
269  std::string _curTestCaseName;
270 
273 
276 
279 
282 
285 
287  typedef boost::shared_ptr<UnitTestResult> UnitTestResultPtr;
288 
291 
295 
297  bool _bInit;
298 
299 };
300 
303 
304 inline bool
306 {
307  return _bInit;
308 }
309 
312 
313 } // end of namespace unittest
314 } // end of namespace ipsdk
315 
316 #pragma warning (pop)
317 
318 #endif // __IPSDKUNITTESTTOOLS_UNITTESTLOG_H__
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
IPSDKUNITTESTTOOLS_API void notifyTestSuiteStart(const std::string &testSuiteName)
function allowing to notify of test suite start
boost::shared_ptr< UnitTestResult > UnitTestResultPtr
shared pointer to unit test result serializable object
Definition: UnitTestLog.h:287
boost::filesystem::path _outputHtmlFilePath
complete output file path for html file
Definition: UnitTestLog.h:224
IPSDKUNITTESTTOOLS_API void notifyTestWarning(const std::string &testFilePath, const ipUInt32 testLineIdx, const std::string &testMsg)
function allowing to notify of warning for a given test
IPSDKUNITTESTTOOLS_API void notifyTestFailure(const std::string &testFilePath, const ipUInt32 testLineIdx, const std::string &testMsg)
function allowing to notify of failure of a given test
bool _bDisplayReport
flag indicating whether report should be displayed after tests ending
Definition: UnitTestLog.h:284
IPSDKUNITTESTTOOLS_API void notifyTestEnd()
function allowing to notify of test end
Predefined types for unit tests management.
bool _bTestCaseClosed
Definition: UnitTestLog.h:294
boost::filesystem::path _logResourceDir
path to resource directory
Definition: UnitTestLog.h:230
ipUInt32 _nbTestsInCurCase
number of tests in the current test case
Definition: UnitTestLog.h:248
ipUInt32 _nbErrors
number of errors
Definition: UnitTestLog.h:251
boost::filesystem::path _outputResultFilePath
complete output file path for result file
Definition: UnitTestLog.h:227
bool _bInit
object initilization flag
Definition: UnitTestLog.h:297
Chrono _testCaseChrono
elapsed time for current test case
Definition: UnitTestLog.h:281
std::string _curTestInfoStr
current test output info string
Definition: UnitTestLog.h:260
Base types for multiplatform compatibility.
#define IPSDKUNITTESTTOOLS_API
Import/Export macro for library IPSDKUnitTestTools.
Definition: IPSDKUnitTestToolsExports.h:27
IPSDKUNITTESTTOOLS_API void notifyTestCaseStart(const std::string &testCaseName)
function allowing to notify of test case start
Definition of import/export macro for library.
Custom log formatter for unit tests.
Definition: UnitTestLog.h:43
Chronometer class for library processing time evaluation.
Definition: Chrono.h:33
UnitTestResultPtr _pUnitTestResult
unit test result serializable object
Definition: UnitTestLog.h:290
ipUInt32 _nbWarnings
number of warnings
Definition: UnitTestLog.h:254
std::string _curTestFileName
current test file name
Definition: UnitTestLog.h:263
ipUInt32 _curTestLineIdx
current test line index
Definition: UnitTestLog.h:272
ipUInt32 _nbTestCases
number of test cases
Definition: UnitTestLog.h:242
ipUInt32 _nbTests
number of tests
Definition: UnitTestLog.h:245
Chrono _testSuiteChrono
elapsed time for current test suite
Definition: UnitTestLog.h:278
IPSDKUNITTESTTOOLS_API void notifyTestSuiteEnd()
function allowing to notify of test suite end
IPSDKUNITTESTTOOLS_API void notifyTestCaseEnd()
function allowing to notify of test case end
std::string _curTestValueStr
current test output value string
Definition: UnitTestLog.h:257
ipUInt32 _nbTestSuites
number of test suites
Definition: UnitTestLog.h:239
std::string _testLanguage
language associated to tests
Definition: UnitTestLog.h:233
Chrono _testsChrono
elapsed time for tests
Definition: UnitTestLog.h:275
IPSDKUNITTESTTOOLS_API void notifyTestException(const std::string &lastCheckPointFilePath, const ipUInt32 lastCheckPointLineIdx, const std::string &exceptionFunctionName, const std::string &exceptionFilePath, const ipUInt32 exceptionLineIdx, const std::string &exceptionMsg)
function allowing to notify of exception during unit test
bool isInit() const
retrieve object initialization flag
Definition: UnitTestLog.h:305
boost::filesystem::ofstream _ofs
output stream for html file
Definition: UnitTestLog.h:236
IPSDKUNITTESTTOOLS_API void notifyTestSuccess(const std::string &testFilePath, const ipUInt32 testLineIdx, const std::string &testMsg)
function allowing to notify of success of a given test
uint32_t ipUInt32
Base types definition.
Definition: BaseTypes.h:53