Commit 42db4263 authored by Marco Amagliani's avatar Marco Amagliani

Merge from dev/amaglim. Many fixes related to the test system. Added an...

Merge from dev/amaglim. Many fixes related to the test system. Added an interface for Ostreams and used it for the debug and test system. Also improved the checksum reports.

[git-p4: depot-paths = "//ReForm/ReForm/main/Base/": change = 14067]
parent 4e152d24
...@@ -11,10 +11,10 @@ ...@@ -11,10 +11,10 @@
#ifndef BASE_CODELINK_HH_INCLUDED #ifndef BASE_CODELINK_HH_INCLUDED
#define BASE_CODELINK_HH_INCLUDED #define BASE_CODELINK_HH_INCLUDED
#include <string.h>
namespace Base { namespace Base {
class IOutputStream;
//! Convenient wrapper around a preprocessor source code link //! Convenient wrapper around a preprocessor source code link
struct CodeLink struct CodeLink
{ {
...@@ -31,25 +31,7 @@ struct CodeLink ...@@ -31,25 +31,7 @@ struct CodeLink
int line; int line;
}; };
// TODO: Replace StreamT w. IOutputStream, move to a .cc file, hide <string.h>! IOutputStream& operator<<(IOutputStream& _os, const CodeLink& _lnk);
template <class StreamT>
StreamT& operator<<(StreamT& _os, const CodeLink& _lnk)
{
#ifdef WIN32
const char path_sep = '\\';
#else//!WIN32
const char path_sep = '/';
#endif//WIN32
auto flnm_pntr = strrchr(_lnk.file, path_sep);
if (flnm_pntr == nullptr)
flnm_pntr = _lnk.file;
else
++flnm_pntr;
return _os << " @ [" << _lnk.fnct << "() in "
<< flnm_pntr << ":" << _lnk.line << "]";
}
}//namespace Base }//namespace Base
......
...@@ -15,9 +15,9 @@ ...@@ -15,9 +15,9 @@
#include <Base/Utils/BaseError.hh> #include <Base/Utils/BaseError.hh>
#include <Base/Debug/DebOut.hh> #include <Base/Debug/DebOut.hh>
namespace Debug { namespace Base {
inline Stream& operator<<(Stream& _ds, const Base::Error& _err) inline IOutputStream& operator<<(IOutputStream& _ds, const Base::Error& _err)
{ {
_ds << "\"" << _err.message() << "\""; _ds << "\"" << _err.message() << "\"";
return _ds; return _ds;
......
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
#else // DEB_ON #else // DEB_ON
#include "Base/Utils/IOutputStream.hh"
#include <string> #include <string>
#include <vector> #include <vector>
#include <array> #include <array>
...@@ -46,21 +48,6 @@ const char* const WARNING = "WARNING"; ...@@ -46,21 +48,6 @@ const char* const WARNING = "WARNING";
class Stream; class Stream;
struct Command
{
enum Type
{
END = 0x01,
END_LF = 0x03,
END_ERR = 0x07
};
Type cmd;
Command(Type _cmd) : cmd(_cmd) {}
};
// Class used to maintain Stream's CallStack // Class used to maintain Stream's CallStack
// This does not currently contain a pointer to the file streamer used // This does not currently contain a pointer to the file streamer used
// but might do in future. // but might do in future.
...@@ -84,15 +71,15 @@ public: ...@@ -84,15 +71,15 @@ public:
Stream& stream(); Stream& stream();
Command end() const { return Command::END; } Base::Command end() const { return Base::Command::END; }
Command end_lf() const { return Command::END_LF; } Base::Command end_lf() const { return Base::Command::END_LF; }
Command end_err() const { return Command::END_ERR; } Base::Command end_err() const { return Base::Command::END_ERR; }
}; };
//! This is a private implementation for Stream //! This is a private implementation for Stream
class File; class File;
class Stream class Stream : public Base::IOutputStream
{ {
public: public:
enum Flags enum Flags
...@@ -114,11 +101,12 @@ public: ...@@ -114,11 +101,12 @@ public:
const std::string& string() const; const std::string& string() const;
const char* c_str() const { return string().c_str(); } const char* c_str() const { return string().c_str(); }
Stream& print(const int); Base::IOutputStream& print(const int);
Stream& print(const double); Base::IOutputStream& print(const size_t);
Stream& print(const char* const, bool fork = true); Base::IOutputStream& print(const double);
Stream& print(const char); Base::IOutputStream& print(const char* const);
Stream& print(const Command&); Base::IOutputStream& print(const char);
Base::IOutputStream& print(const Base::Command&);
private: private:
File* dfile_; File* dfile_;
...@@ -134,64 +122,6 @@ private: ...@@ -134,64 +122,6 @@ private:
friend class Controller; friend class Controller;
}; };
Stream& operator<<(Stream& _ds, const int i);
Stream& operator<<(Stream& _ds, const double d);
Stream& operator<<(Stream& _ds, const size_t i);
Stream& operator<<(Stream& _ds, const unsigned int i);
Stream& operator<<(Stream& _ds, const float d);
Stream& operator<<(Stream& _ds, const char c);
Stream& operator<<(Stream& _ds, const char* const s);
Stream& operator<<(Stream& _ds, const std::string& s);
Stream& operator<<(Stream& _ds, const Command& co);
inline Stream& operator<<(Stream& _ds, const Command::Type _cmd_type)
{
return _ds << Command(_cmd_type);
}
// Stream operator for std::vector<>
template< typename ElementT>
Stream& operator<<(Stream& _ds, const std::vector<ElementT>& _vec)
{
_ds << "[ ";
for (const auto el : _vec)
_ds << el << " ";
_ds << "]";
return _ds;
}
// Stream operator for std::array<>
template< typename ElementT, size_t _el_nmbr>
Stream& operator<<(Stream& _ds, const std::array<ElementT, _el_nmbr>& _vec)
{
_ds << "[ ";
for (const auto el : _vec)
_ds << el << " ";
_ds << "]";
return _ds;
}
// Stream operator for fixed size arrays
template <typename ElementT, size_t _el_nmbr>
Stream& operator<<(Stream& _ds, const ElementT(&_arr)[_el_nmbr])
{
_ds << "[ ";
for (const auto el : _arr)
_ds << el << " ";
_ds << "]";
return _ds;
}
// Stream std::pair<>
template <typename T0, typename T1>
Stream& operator<<(Stream& _ds, const std::pair<T0, T1>& _pair)
{
_ds << "(" << _pair.first << ", " << _pair.second << ")";
return _ds;
}
extern void warning(const std::string& _wrng, const char* const _fnct, extern void warning(const std::string& _wrng, const char* const _fnct,
const char* const _file, const int _line); const char* const _file, const int _line);
extern void error(const std::string& _err, const char* const _fnct, extern void error(const std::string& _err, const char* const _fnct,
......
...@@ -403,7 +403,14 @@ public: ...@@ -403,7 +403,14 @@ public:
} }
} }
void print(int _i) void print(const size_t _i)
{
char buffer[128];
sprintf_s(buffer, sizeof(buffer), "%lu", _i);
print(buffer);
}
void print(const int _i)
{ {
char buffer[64]; char buffer[64];
sprintf_s(buffer, sizeof(buffer), "%i", _i); sprintf_s(buffer, sizeof(buffer), "%i", _i);
...@@ -434,18 +441,18 @@ public: ...@@ -434,18 +441,18 @@ public:
print(buffer); print(buffer);
} }
void print(const Command& _co) void print(const Base::Command& _co)
{ {
switch (_co.cmd) switch (_co.cmd)
{ {
case Command::END : case Base::Command::END :
if (is_html()) print_direct("</FONT>"); if (is_html()) print_direct("</FONT>");
break; break;
case Command::END_ERR : case Base::Command::END_ERR :
// Powerdown DEB_error font // Powerdown DEB_error font
// if (is_html()) print_direct("</BLINK>"); // if (is_html()) print_direct("</BLINK>");
// fall through // fall through
case Command::END_LF : case Base::Command::END_LF :
if (is_html()) print_direct("</FONT>"); if (is_html()) print_direct("</FONT>");
line_break(); line_break();
...@@ -810,7 +817,7 @@ void warning(const std::string& _wrng, const char* const _fnct, ...@@ -810,7 +817,7 @@ void warning(const std::string& _wrng, const char* const _fnct,
{ {
Base::CodeLink code_link(_fnct, _file, _line); Base::CodeLink code_link(_fnct, _file, _line);
TEST_only(Test::Checksum::Debug::warning.record(_wrng, code_link)); TEST_only(Test::Checksum::Debug::warning.record(_wrng, code_link));
global_stream() << WARNING << ": " << _wrng << code_link << Command::END_LF; global_stream() << WARNING << ": " << _wrng << code_link << Base::Command::END_LF;
} }
void error(const std::string& _err, const char* const _fnct, void error(const std::string& _err, const char* const _fnct,
...@@ -818,7 +825,7 @@ void error(const std::string& _err, const char* const _fnct, ...@@ -818,7 +825,7 @@ void error(const std::string& _err, const char* const _fnct,
{ {
Base::CodeLink code_link(_fnct, _file, _line); Base::CodeLink code_link(_fnct, _file, _line);
TEST_only(Test::Checksum::Debug::error.record(_err, code_link)); TEST_only(Test::Checksum::Debug::error.record(_err, code_link));
global_stream() << ERROR << ": " << _err << code_link << Command::END_ERR; global_stream() << ERROR << ": " << _err << code_link << Base::Command::END_ERR;
} }
#undef TRIGGER_POINT #undef TRIGGER_POINT
...@@ -988,82 +995,42 @@ Stream::~Stream() ...@@ -988,82 +995,42 @@ Stream::~Stream()
const std::string& Stream::string() const { return dfile()->string(); } const std::string& Stream::string() const { return dfile()->string(); }
Stream& Stream::print(const int _i) Base::IOutputStream& Stream::print(const int _i)
{
dfile_->print(_i);
return *this;
};
Base::IOutputStream& Stream::print(const size_t _i)
{ {
dfile_->print(_i); dfile_->print(_i);
return *this; return *this;
}; };
Stream& Stream::print(const double _d) Base::IOutputStream& Stream::print(const double _d)
{ {
dfile_->print(_d); dfile_->print(_d);
return *this; return *this;
}; };
Stream& Stream::print(const char* _s, bool _fork) Base::IOutputStream& Stream::print(const char* _s)
{ {
dfile_->print(_s, _fork); dfile_->print(_s);
return *this; return *this;
}; };
Stream& Stream::print(const char _c) Base::IOutputStream& Stream::print(const char _c)
{ {
dfile_->print(_c); dfile_->print(_c);
return *this; return *this;
}; };
Stream& Stream::print(const Command& _co) Base::IOutputStream& Stream::print(const Base::Command& _co)
{ {
dfile_->print(_co); dfile_->print(_co);
return *this; return *this;
}; };
Stream& operator<<(Stream& _ds, const int _i)
{
return _ds.print(_i);
}
Stream& operator<<(Stream& _ds, const double _d)
{
return _ds.print(_d);
}
Stream& operator<<(Stream& _ds, const char* const _s)
{
return _ds.print(_s);
}
Stream& operator<<(Stream& _ds, const char _c)
{
return _ds.print(_c);
}
Stream& operator<<(Stream& _ds, const size_t _i)
{
return _ds.print((int)_i);
}
Stream& operator<<(Stream& _ds, const unsigned int _i)
{
return _ds.print((int)_i);
}
Stream& operator<<(Stream& _ds, const float _f)
{
return _ds.print((double)_f);
}
Stream& operator<<(Stream& _ds, const std::string& _s)
{
return _ds.print(_s.c_str());
}
Stream& operator<<(Stream& _ds, const Command& _co)
{
return _ds.print(_co);
}
Stream& operator<<(Stream& _ds, const ThrowInfo& _thrw_info)
{
_ds << "thrown by " << _thrw_info.fnct_ << "() in " << _thrw_info.modl_ <<
" file " << _thrw_info.file_ << " @ line " << _thrw_info.line_;
return _ds;
}
// ================================================== // ==================================================
// Controller member funcs (currently all static) // Controller member funcs (currently all static)
// ================================================== // ==================================================
......
...@@ -6,7 +6,6 @@ set(my_headers ...@@ -6,7 +6,6 @@ set(my_headers
${CMAKE_CURRENT_SOURCE_DIR}/types.hh ${CMAKE_CURRENT_SOURCE_DIR}/types.hh
${CMAKE_CURRENT_SOURCE_DIR}/TestResult.hh ${CMAKE_CURRENT_SOURCE_DIR}/TestResult.hh
${CMAKE_CURRENT_SOURCE_DIR}/ReadValuesT.hh ${CMAKE_CURRENT_SOURCE_DIR}/ReadValuesT.hh
${CMAKE_CURRENT_SOURCE_DIR}/StreamContainerT.hh
PARENT_SCOPE PARENT_SCOPE
) )
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include "Base/Code/CodeLink.hh" #include "Base/Code/CodeLink.hh"
#include "Base/Debug/DebOut.hh" #include "Base/Debug/DebOut.hh"
#include <algorithm>
namespace Test { namespace Test {
namespace Checksum { namespace Checksum {
namespace Debug { namespace Debug {
...@@ -24,21 +26,22 @@ namespace Debug { ...@@ -24,21 +26,22 @@ namespace Debug {
void Event::record(const std::string& _evnt, const Base::CodeLink& _lnk) void Event::record(const std::string& _evnt, const Base::CodeLink& _lnk)
{ {
Result res(name() == ::Debug::ERROR ? Result::ERROR : Result::WARNING); Result res(name() == ::Debug::ERROR ? Result::ERROR : Result::WARNING);
IChecksum::record(res) << "#" << nmbr_++ << ": " << _evnt << _lnk << std::endl; IChecksum::record(res) << "#" << nmbr_++ << ": " << _evnt << " reported "
<< _lnk << Base::LF;
} }
void Event::record_number() const void Event::record_number() const
{ {
Result res(nmbr_ == 0 ? Result::OK : // the checksum will appear in all cases Result res(nmbr_ == 0 ? Result::OK : // the checksum will appear in all cases
(name() == ::Debug::ERROR ? Result::ERROR : Result::WARNING)); (name() == ::Debug::ERROR ? Result::ERROR : Result::WARNING));
IChecksum::record(res) << " total#: " << nmbr_ << std::endl; IChecksum::record(res) << " total#: " << nmbr_ << Base::LF;
} }
Severity Event::compare( Severity Event::compare(
IStream& _str0, IStream& _str0,
IStream& _str1, IStream& _str1,
OStream& _os, OStream& _os,
const Path* /*_dir0 */, const Path* /*_dir0*/,
const Path* /*_dir1*/ const Path* /*_dir1*/
) const ) const
{ {
...@@ -52,7 +55,17 @@ Severity Event::compare( ...@@ -52,7 +55,17 @@ Severity Event::compare(
return 0; return 0;
} }
_os << "Diff: L={" << line0 << "}; R={" << line1 << "}"; std::string diff;
diff.resize((std::max(line0.length(), line1.length())));
for (int i = 0; i < diff.size(); ++i)
{
diff[i] = i < line0.length() && i < line1.length() && line0[i] == line1[i] ?
' ' : '*';
}
_os << Base::LF <<
"\tL: " << line0 << Base::LF <<
"\tR: " << line1 << Base::LF <<
"\tD: " << diff;
return 1; return 1;
} }
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "ChecksumLogValueT.hh" #include "ChecksumLogValueT.hh"
#include "ReadValuesT.hh" #include "ReadValuesT.hh"
#include "StreamContainerT.hh"
#include "Base/Debug/DebOut.hh" #include "Base/Debug/DebOut.hh"
...@@ -27,12 +26,6 @@ namespace Checksum { ...@@ -27,12 +26,6 @@ namespace Checksum {
namespace { // ChecksumLog locals namespace { // ChecksumLog locals
template <typename ValueT>
std::ostream& operator<<(std::ostream& _out_str, const std::vector<ValueT>& _vals)
{
return write_container(_out_str, _vals);
}
#define ARITHMETICTYPE(ValueT) \ #define ARITHMETICTYPE(ValueT) \
typename std::enable_if<std::is_arithmetic<ValueT>::value, ValueT>::type typename std::enable_if<std::is_arithmetic<ValueT>::value, ValueT>::type
...@@ -85,7 +78,7 @@ Severity LogValueT<ValueT, CompareT>::compare(IStream& _str0, IStream& _str1, ...@@ -85,7 +78,7 @@ Severity LogValueT<ValueT, CompareT>::compare(IStream& _str0, IStream& _str1,
template <typename ValueT, class CompareT> template <typename ValueT, class CompareT>
void LogValueT<ValueT, CompareT>::record(const Result& _rep_res, const ValueT& _val) void LogValueT<ValueT, CompareT>::record(const Result& _rep_res, const ValueT& _val)
{ {
IChecksum::record(_rep_res) << _val << std::endl; IChecksum::record(_rep_res) << _val << Base::LF;
} }
}//namespace Checksum }//namespace Checksum
......
...@@ -37,9 +37,9 @@ IChecksum::IChecksum(const char * _name) : name_(_name) ...@@ -37,9 +37,9 @@ IChecksum::IChecksum(const char * _name) : name_(_name)
} }
} }
std::ofstream& IChecksum::record(const Result& _rep_res) const Base::IOutputStream& IChecksum::record(const Result& _rep_res) const
{ {
static std::ofstream test_str(REPORT_FILENAME); static Base::OutputStreamAdaptT<std::ofstream> test_str(REPORT_FILENAME);
test_str << _rep_res << " " << name() << ": "; test_str << _rep_res << " " << name() << ": ";
return test_str; return test_str;
} }
......
...@@ -18,9 +18,9 @@ ...@@ -18,9 +18,9 @@
#else #else
#include <Base/Test/TestResult.hh> #include <Base/Test/TestResult.hh>
#include "Base/Utils/IOutputStream.hh"
#include <map> #include <map>
#include <fstream>
#include <sstream> #include <sstream>
namespace Test { namespace Test {
...@@ -59,7 +59,7 @@ protected: ...@@ -59,7 +59,7 @@ protected:
*/ */
IChecksum(const char* _name); IChecksum(const char* _name);
std::ofstream& record(const Result& _rep_res) const; Base::IOutputStream& record(const Result& _rep_res) const;
private: private:
const char* name_; const char* name_;
......
// (C) Copyright 2016 by Autodesk, Inc.
//
// The information contained herein is confidential, proprietary
// to Autodesk, Inc., and considered a trade secret as defined
// in section 499C of the penal code of the State of California.
// Use of this information by anyone other than authorized
// employees of Autodesk, Inc. is granted only under a written
// non-disclosure agreement, expressly prescribing the scope
// and manner of such use.
#ifndef REFORM_STREAMCONTAINERT_HH_INCLUDE
#define REFORM_STREAMCONTAINERT_HH_INCLUDE
/*!
Generic function to fill a std container from a std stream.
*/
template <typename ContainerT>
std::istream& read_container(std::istream& _in_str, ContainerT& _vals)
{
for (auto& val : _vals)
_in_str >> val;
return _in_str;
}
/*!
Generic function to write a std container in a std stream.
*/
template <typename ContainerT>
std::ostream& write_container(std::ostream& _out_str, ContainerT& _cont)
{
_out_str << '(';
if (_cont.size() > 0)
{
auto it = _cont.cbegin();
_out_str << *it;
while (++it != _cont.cend())
_out_str << ',' << *it;
}
_out_str << ')';
return _out_str;
}
#endif//REFORM_STREAMCONTAINERT_HH_INCLUDE
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#ifdef TEST_ON #ifdef TEST_ON
#include "Base/Utils/IOutputStream.hh"
#include <sstream> #include <sstream>
namespace boost { namespace boost {
...@@ -31,7 +33,7 @@ const char* const REPORT_FILENAME = "report.txt"; ...@@ -31,7 +33,7 @@ const char* const REPORT_FILENAME = "report.txt";
typedef double Severity; typedef double Severity;
// test output stream // test output stream
typedef std::ostringstream OStream; typedef Base::OutputStreamAdaptT<std::ostringstream> OStream;
// test input stream // test input stream
typedef std::istringstream IStream; typedef std::istringstream IStream;
......
...@@ -2,6 +2,7 @@ set(my_headers ...@@ -2,6 +2,7 @@ set(my_headers
${CMAKE_CURRENT_SOURCE_DIR}/BaseError.hh ${CMAKE_CURRENT_SOURCE_DIR}/BaseError.hh
${CMAKE_CURRENT_SOURCE_DIR}/BaseErrorInc.hh ${CMAKE_CURRENT_SOURCE_DIR}/BaseErrorInc.hh
${CMAKE_CURRENT_SOURCE_DIR}/Environment.hh ${CMAKE_CURRENT_SOURCE_DIR}/Environment.hh
${CMAKE_CURRENT_SOURCE_DIR}/IOutputStream.hh
${CMAKE_CURRENT_SOURCE_DIR}/StopWatch.hh ${CMAKE_CURRENT_SOURCE_DIR}/StopWatch.hh
${CMAKE_CURRENT_SOURCE_DIR}/ThrowError.hh ${CMAKE_CURRENT_SOURCE_DIR}/ThrowError.hh