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 @@
#ifndef BASE_CODELINK_HH_INCLUDED
#define BASE_CODELINK_HH_INCLUDED
#include <string.h>
namespace Base {
class IOutputStream;
//! Convenient wrapper around a preprocessor source code link
struct CodeLink
{
......@@ -31,25 +31,7 @@ struct CodeLink
int line;
};
// TODO: Replace StreamT w. IOutputStream, move to a .cc file, hide <string.h>!
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 << "]";
}
IOutputStream& operator<<(IOutputStream& _os, const CodeLink& _lnk);
}//namespace Base
......
......@@ -15,9 +15,9 @@
#include <Base/Utils/BaseError.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() << "\"";
return _ds;
......
......@@ -32,6 +32,8 @@
#else // DEB_ON
#include "Base/Utils/IOutputStream.hh"
#include <string>
#include <vector>
#include <array>
......@@ -46,21 +48,6 @@ const char* const WARNING = "WARNING";
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
// This does not currently contain a pointer to the file streamer used
// but might do in future.
......@@ -84,15 +71,15 @@ public:
Stream& stream();
Command end() const { return Command::END; }
Command end_lf() const { return Command::END_LF; }
Command end_err() const { return Command::END_ERR; }
Base::Command end() const { return Base::Command::END; }
Base::Command end_lf() const { return Base::Command::END_LF; }
Base::Command end_err() const { return Base::Command::END_ERR; }
};
//! This is a private implementation for Stream
class File;
class Stream
class Stream : public Base::IOutputStream
{
public:
enum Flags
......@@ -114,11 +101,12 @@ public:
const std::string& string() const;
const char* c_str() const { return string().c_str(); }
Stream& print(const int);
Stream& print(const double);
Stream& print(const char* const, bool fork = true);
Stream& print(const char);
Stream& print(const Command&);
Base::IOutputStream& print(const int);
Base::IOutputStream& print(const size_t);
Base::IOutputStream& print(const double);
Base::IOutputStream& print(const char* const);
Base::IOutputStream& print(const char);
Base::IOutputStream& print(const Base::Command&);
private:
File* dfile_;
......@@ -134,64 +122,6 @@ private:
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,
const char* const _file, const int _line);
extern void error(const std::string& _err, const char* const _fnct,
......
......@@ -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];
sprintf_s(buffer, sizeof(buffer), "%i", _i);
......@@ -434,18 +441,18 @@ public:
print(buffer);
}
void print(const Command& _co)
void print(const Base::Command& _co)
{
switch (_co.cmd)
{
case Command::END :
case Base::Command::END :
if (is_html()) print_direct("</FONT>");
break;
case Command::END_ERR :
case Base::Command::END_ERR :
// Powerdown DEB_error font
// if (is_html()) print_direct("</BLINK>");
// fall through
case Command::END_LF :
case Base::Command::END_LF :
if (is_html()) print_direct("</FONT>");
line_break();
......@@ -810,7 +817,7 @@ void warning(const std::string& _wrng, const char* const _fnct,
{
Base::CodeLink code_link(_fnct, _file, _line);
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,
......@@ -818,7 +825,7 @@ void error(const std::string& _err, const char* const _fnct,
{
Base::CodeLink code_link(_fnct, _file, _line);
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
......@@ -988,82 +995,42 @@ Stream::~Stream()
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);
return *this;
};
Stream& Stream::print(const double _d)
Base::IOutputStream& Stream::print(const double _d)
{
dfile_->print(_d);
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;
};
Stream& Stream::print(const char _c)
Base::IOutputStream& Stream::print(const char _c)
{
dfile_->print(_c);
return *this;
};
Stream& Stream::print(const Command& _co)
Base::IOutputStream& Stream::print(const Base::Command& _co)
{
dfile_->print(_co);
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)
// ==================================================
......
......@@ -6,7 +6,6 @@ set(my_headers
${CMAKE_CURRENT_SOURCE_DIR}/types.hh
${CMAKE_CURRENT_SOURCE_DIR}/TestResult.hh
${CMAKE_CURRENT_SOURCE_DIR}/ReadValuesT.hh
${CMAKE_CURRENT_SOURCE_DIR}/StreamContainerT.hh
PARENT_SCOPE
)
......
......@@ -15,6 +15,8 @@
#include "Base/Code/CodeLink.hh"
#include "Base/Debug/DebOut.hh"
#include <algorithm>
namespace Test {
namespace Checksum {
namespace Debug {
......@@ -24,21 +26,22 @@ namespace Debug {
void Event::record(const std::string& _evnt, const Base::CodeLink& _lnk)
{
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
{
Result res(nmbr_ == 0 ? Result::OK : // the checksum will appear in all cases
(name() == ::Debug::ERROR ? Result::ERROR : Result::WARNING));
IChecksum::record(res) << " total#: " << nmbr_ << std::endl;
IChecksum::record(res) << " total#: " << nmbr_ << Base::LF;
}
Severity Event::compare(
IStream& _str0,
IStream& _str1,
OStream& _os,
const Path* /*_dir0 */,
const Path* /*_dir0*/,
const Path* /*_dir1*/
) const
{
......@@ -52,7 +55,17 @@ Severity Event::compare(
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;
}
......
......@@ -12,7 +12,6 @@
#include "ChecksumLogValueT.hh"
#include "ReadValuesT.hh"
#include "StreamContainerT.hh"
#include "Base/Debug/DebOut.hh"
......@@ -27,12 +26,6 @@ namespace Checksum {
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) \
typename std::enable_if<std::is_arithmetic<ValueT>::value, ValueT>::type
......@@ -85,7 +78,7 @@ Severity LogValueT<ValueT, CompareT>::compare(IStream& _str0, IStream& _str1,
template <typename ValueT, class CompareT>
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
......
......@@ -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() << ": ";
return test_str;
}
......
......@@ -18,9 +18,9 @@
#else
#include <Base/Test/TestResult.hh>
#include "Base/Utils/IOutputStream.hh"
#include <map>
#include <fstream>
#include <sstream>
namespace Test {
......@@ -59,7 +59,7 @@ protected:
*/
IChecksum(const char* _name);
std::ofstream& record(const Result& _rep_res) const;
Base::IOutputStream& record(const Result& _rep_res) const;
private:
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 @@
#ifdef TEST_ON
#include "Base/Utils/IOutputStream.hh"
#include <sstream>
namespace boost {
......@@ -31,7 +33,7 @@ const char* const REPORT_FILENAME = "report.txt";
typedef double Severity;
// test output stream
typedef std::ostringstream OStream;
typedef Base::OutputStreamAdaptT<std::ostringstream> OStream;
// test input stream
typedef std::istringstream IStream;
......
......@@ -2,6 +2,7 @@ set(my_headers
${CMAKE_CURRENT_SOURCE_DIR}/BaseError.hh
${CMAKE_CURRENT_SOURCE_DIR}/BaseErrorInc.hh
${CMAKE_CURRENT_SOURCE_DIR}/Environment.hh
${CMAKE_CURRENT_SOURCE_DIR}/IOutputStream.hh
${CMAKE_CURRENT_SOURCE_DIR}/StopWatch.hh
${CMAKE_CURRENT_SOURCE_DIR}/ThrowError.hh
PARENT_SCOPE
......@@ -10,6 +11,7 @@ set(my_headers
set(my_sources
${CMAKE_CURRENT_SOURCE_DIR}/BaseError.cc
${CMAKE_CURRENT_SOURCE_DIR}/Environment.cc
${CMAKE_CURRENT_SOURCE_DIR}/IOutputStream.cc
${CMAKE_CURRENT_SOURCE_DIR}/StopWatch.cc
PARENT_SCOPE
)
// (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.
#include "Base/Security/Mandatory.hh"
#include "IOutputStream.hh"
#include "Base/Code/CodeLink.hh"
#include "Base/Utils/ThrowError.hh"
#include <boost/filesystem.hpp>
#include <string>
namespace Base {
IOutputStream& operator<<(IOutputStream& _ds, const int _i)
{
return _ds.print(_i);
}
IOutputStream& operator<<(IOutputStream& _ds, const double _d)
{
return _ds.print(_d);
}
IOutputStream& operator<<(IOutputStream& _ds, const char* const _s)
{
return _ds.print(_s);
}
IOutputStream& operator<<(IOutputStream& _ds, const char _c)
{
return _ds.print(_c);
}
IOutputStream& operator<<(IOutputStream& _ds, const size_t _i)
{
return _ds.print(_i);
}
IOutputStream& operator<<(IOutputStream& _ds, const unsigned int _i)
{
return _ds.print(size_t(_i));
}
IOutputStream& operator<<(IOutputStream& _ds, const float _f)
{
return _ds.print((double)_f);
}
IOutputStream& operator<<(IOutputStream& _ds, const std::string& _s)
{
return _ds.print(_s.c_str());
}
IOutputStream& operator<<(IOutputStream& _ds, const Command& _co)
{
return _ds.print(_co);
}
IOutputStream& operator<<(IOutputStream& _ds, const boost::filesystem::path& _path)
{
return _ds << '\"' << _path.string().c_str() << '\"';
}
IOutputStream& operator<<(IOutputStream& _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
#ifdef DEB_ON
namespace Debug {
Base::IOutputStream& operator<<(Base::IOutputStream& _ds,
const ThrowInfo& _thrw_info)
{
return _ds << "thrown in " << _thrw_info.modl << " " << _thrw_info.lnk;
}
}//namespace Debug
#endif//DEB_ON
// (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 BASE_IOUTPUTSTREAM_HH_INCLUDE
#define BASE_IOUTPUTSTREAM_HH_INCLUDE
#include <string>
#include <vector>
#include <array>
namespace boost {
namespace filesystem {
class path;
}
}
namespace Base {
struct Command
{
enum Type
{
END = 0x01,
END_LF = 0x03,
END_ERR = 0x07
};
Type cmd;
Command(Type _cmd) : cmd(_cmd) {}
};
// use Base::ENDL to stream endline to IOutputStream (same as std::endl)
const Command ENDL = Command::END_LF;
const Command LF = Command::END_LF;
class IOutputStream
{
public:
virtual ~IOutputStream() {}
virtual IOutputStream& print(const char) = 0;