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)
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!
{ // 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 };
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;
......@@ -54,23 +62,15 @@ public:
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)
{}
{
}
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
......@@ -132,8 +128,7 @@ public:
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;
......@@ -194,13 +189,23 @@ 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