Commit e539ad9b authored by Martin Marinov's avatar Martin Marinov

Enforce containment of test checksums in namespace Test::Checksum

parent 4f8bd49e
// (C) Copyright 2019 by Autodesk, Inc.
// (C) Copyright 2020 by Autodesk, Inc.
#ifdef DEB_ON
......@@ -9,28 +9,29 @@
#include "Base/Code/CodeLink.hh"
#include "Base/Test/ChecksumDebugEvent.hh"
namespace Debug {
namespace Debug
{
void warning(const std::string& _wrng, const Base::CodeLink& _lnk)
{
TEST(Test::Checksum::Debug::warning, record(_wrng, _lnk));
TEST(Debug::warning, record(_wrng, _lnk));
Stream strm(File::modify());
strm << WARNING << ": " << _wrng << ' ' << _lnk << Base::ENDL;
}
void error(const std::string& _err, const Base::CodeLink& _lnk)
{
TEST(Test::Checksum::Debug::error, record(_err, _lnk));
TEST(Debug::error, record(_err, _lnk));
Stream strm(File::modify());
strm << ERROR << ": " << _err << ' ' << _lnk << Base::ENDL;
}
//////////////////////////////////////////////////////////////////////////
Enter::Enter(const char* const _flnm, const char* const _fnct,
int& _nmbr, int& _lvl)
: flnm_(_flnm), fnct_(_fnct), outs_(0), strm_(File::modify())
{// TODO: for thread-safety we will need to make the constructor body atomic!
Enter::Enter(
const char* const _flnm, const char* const _fnct, int& _nmbr, int& _lvl)
: flnm_(_flnm), fnct_(_fnct), outs_(0), strm_(File::modify())
{ // TODO: for thread-safety we will need to make the constructor body atomic!
strm_.file_.enter(this);
nmbr_ = _nmbr++;
......@@ -42,10 +43,7 @@ Enter::Enter(const char* const _flnm, const char* const _fnct,
id_ = ++id_cnt;
}
Enter::~Enter()
{
strm_.file_.exit();
}
Enter::~Enter() { strm_.file_.exit(); }
Stream& Enter::stream()
{
......@@ -59,8 +57,7 @@ Stream& Enter::stream()
//////////////////////////////////////////////////////////////////////////
Stream::Stream(const Stream& _othr) : file_(_othr.file_) {}
Stream& Stream::operator = (const Stream&) { return *this; }
Stream& Stream::operator=(const Stream&) { return *this; }
Base::IOutputStream& Stream::print(const int _i)
{
......@@ -98,6 +95,6 @@ Base::IOutputStream& Stream::print(const char _c)
return *this;
};
}//namespace Debug
} // namespace Debug
#endif // DEB_ON
......@@ -15,13 +15,21 @@
#include <map>
#include <sstream>
namespace Test {
namespace Checksum {
namespace Test
{
namespace Checksum
{
//! Enumerate the checksum levels
enum Level { L_NONE, L_STABLE, L_PRIME, L_ALL };
//! Enumerate the checksum levels
enum Level
{
L_NONE,
L_STABLE,
L_PRIME,
L_ALL
};
extern Level run_lvl; //<! The checksum run level
const char* const LEVEL_TEXT[4] = { "NONE", "STABLE", "PRIME", "ALL" };
const char* const LEVEL_TEXT[4] = {"NONE", "STABLE", "PRIME", "ALL"};
//! typedef String, this is used a lot in this namespace
typedef std::string String;
......@@ -37,40 +45,32 @@ struct Record
};
//! The difference found by the IChecksum::compare() operation
class Difference
class Difference
{
public:
enum Type
{
EQUAL, // result is bitwise identical
UNKNOWN, // non-negligible difference, but of unknown quality
IMPROVED, // result is better
EQUAL, // result is bitwise identical
UNKNOWN, // non-negligible difference, but of unknown quality
IMPROVED, // result is better
NEGLEGIBLE, // result is negligibly different
SUSPICIOUS, // result is different, and the new result might be worse
REGRESSED, // result is worse
WORKED, // result works now, but used to fail
FAILED // result fails now, but used to work
REGRESSED, // result is worse
WORKED, // result works now, but used to fail
FAILED // result fails now, but used to work
};
static const char* const type_text(const Type _type)
{
static const char dscr[][32] =
{
"EQUAL",
"UNKNOWN",
"IMPROVED",
"NEGLEGIBLE",
"SUSPICIOUS",
"REGRESSED",
"WORKED",
"FAILED"
};
static const char dscr[][32] = {"EQUAL", "UNKNOWN", "IMPROVED",
"NEGLEGIBLE", "SUSPICIOUS", "REGRESSED", "WORKED", "FAILED"};
return dscr[_type];
}
Difference(const Type _type = EQUAL, const String& _dscr = String())
: type_(_type), dscr_(_dscr)
{}
: type_(_type), dscr_(_dscr)
{
}
const Type type() const { return type_; }
bool equal() const { return type() == EQUAL; }
......@@ -98,15 +98,12 @@ public:
return *this;
}
const String& description() const
{
return dscr_;
}
const String& description() const { return dscr_; }
const char* const type_text() const { return type_text(type_); }
friend Base::IOutputStream& operator<<(Base::IOutputStream& _os,
Difference& _diff)
friend Base::IOutputStream& operator<<(
Base::IOutputStream& _os, Difference& _diff)
{
// TODO: use string description array
return _os << _diff.type_text() << " " << _diff.dscr_;
......@@ -119,7 +116,6 @@ private:
String dscr_;
};
/*!
Base class for test checksums. Whatever check we want to add in the test system,
it must be an instance of a class derived from Checksum. All derived classes
......@@ -128,12 +124,11 @@ must be instantiated as global variables.
class Object
{
public:
//! Checksum name.
//! Checksum name.
const char* const name() const { return name_; }
//! Add a record the checksum (generic version)
template <typename T>
void record(const Result& _rslt, const T& _data)
template <typename T> void record(const Result& _rslt, const T& _data)
{
Base::OStringStream strm;
strm << _data;
......@@ -146,15 +141,15 @@ public:
/*!
Compare two existing records (old and new).
Returns a qualification and a description of the difference.
The default implementation has some intelligence in comparing the record
results, but compares the the data simply as strings (no parsing).
The default implementation has some intelligence in comparing the record
results, but compares the the data simply as strings (no parsing).
*/
virtual Difference compare(
const Path& _old_path, //!<[in] Path to the left record
const Record& _old_rcrd, //!<[in] "Left" record
const Path& _new_path, //!<[in] Path to the right record
const Record& _new_rcrd //!<[in] "Right" record
) const;
const Path& _old_path, //!<[in] Path to the left record
const Record& _old_rcrd, //!<[in] "Left" record
const Path& _new_path, //!<[in] Path to the right record
const Record& _new_rcrd //!<[in] "Right" record
) const;
//! Get if the checksum should be run
bool allow() const { return lvl_ <= run_lvl; }
......@@ -184,23 +179,33 @@ private:
};
/*!
Definition of the checksums registry. It is a map from a string (that is the
Definition of the checksums registry. It is a map from a string (that is the
checksum name to an IChecksum.
*/
typedef std::map<String, Object*> Registry;
typedef std::map<String, Object*> Registry;
/*!
Function to get a static map with all the registered checksums.
*/
const Registry& registry();
}//namespace Checksum
}//namespace Test
} // namespace Checksum
} // namespace Test
#define TEST(CHKSM, RCRD) { if (CHKSM.allow()) { CHKSM.RCRD; } }
#define TEST_if(CNDT, CHKSM, RCRD) { if (CNDT) TEST(CHKSM, RCRD) }
#define TEST(CHKSM, RCRD) \
{ \
if (Test::Checksum::CHKSM.allow()) \
{ \
Test::Checksum::CHKSM.RCRD; \
} \
}
#endif//TEST_ON
#define TEST_if(CNDT, CHKSM, RCRD) \
{ \
if (CNDT) \
TEST(CHKSM, RCRD) \
}
#endif // TEST_ON
#endif//BASE_ICHECKSUM_HH_INCLUDE
#endif // BASE_ICHECKSUM_HH_INCLUDE
......@@ -30,8 +30,7 @@ public:
}//namespace Checksum
}//namespace Test
#define TEST_CHECKSUM_FILE(VRBL, NAME) \
Test::Checksum::File VRBL(NAME"-file", Test::Checksum::File::TAG_USED)
#define TEST_CHECKSUM_FILE(VRBL, NAME) File VRBL(NAME"-file", File::TAG_USED)
#else//TEST_ON
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment