Commit e539ad9b authored by Martin Marinov's avatar Martin Marinov
Browse files

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 #ifdef DEB_ON
...@@ -9,28 +9,29 @@ ...@@ -9,28 +9,29 @@
#include "Base/Code/CodeLink.hh" #include "Base/Code/CodeLink.hh"
#include "Base/Test/ChecksumDebugEvent.hh" #include "Base/Test/ChecksumDebugEvent.hh"
namespace Debug { namespace Debug
{
void warning(const std::string& _wrng, const Base::CodeLink& _lnk) 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()); Stream strm(File::modify());
strm << WARNING << ": " << _wrng << ' ' << _lnk << Base::ENDL; strm << WARNING << ": " << _wrng << ' ' << _lnk << Base::ENDL;
} }
void error(const std::string& _err, const Base::CodeLink& _lnk) 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()); Stream strm(File::modify());
strm << ERROR << ": " << _err << ' ' << _lnk << Base::ENDL; strm << ERROR << ": " << _err << ' ' << _lnk << Base::ENDL;
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
Enter::Enter(const char* const _flnm, const char* const _fnct, Enter::Enter(
int& _nmbr, int& _lvl) const char* const _flnm, const char* const _fnct, int& _nmbr, int& _lvl)
: flnm_(_flnm), fnct_(_fnct), outs_(0), strm_(File::modify()) : 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); strm_.file_.enter(this);
nmbr_ = _nmbr++; nmbr_ = _nmbr++;
...@@ -42,10 +43,7 @@ Enter::Enter(const char* const _flnm, const char* const _fnct, ...@@ -42,10 +43,7 @@ Enter::Enter(const char* const _flnm, const char* const _fnct,
id_ = ++id_cnt; id_ = ++id_cnt;
} }
Enter::~Enter() Enter::~Enter() { strm_.file_.exit(); }
{
strm_.file_.exit();
}
Stream& Enter::stream() Stream& Enter::stream()
{ {
...@@ -59,8 +57,7 @@ Stream& Enter::stream() ...@@ -59,8 +57,7 @@ Stream& Enter::stream()
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
Stream::Stream(const Stream& _othr) : file_(_othr.file_) {} 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) Base::IOutputStream& Stream::print(const int _i)
{ {
...@@ -98,6 +95,6 @@ Base::IOutputStream& Stream::print(const char _c) ...@@ -98,6 +95,6 @@ Base::IOutputStream& Stream::print(const char _c)
return *this; return *this;
}; };
}//namespace Debug } // namespace Debug
#endif // DEB_ON #endif // DEB_ON
...@@ -15,13 +15,21 @@ ...@@ -15,13 +15,21 @@
#include <map> #include <map>
#include <sstream> #include <sstream>
namespace Test { namespace Test
namespace Checksum { {
namespace Checksum
{
//! Enumerate the checksum levels //! 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 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 String, this is used a lot in this namespace
typedef std::string String; typedef std::string String;
...@@ -54,23 +62,15 @@ public: ...@@ -54,23 +62,15 @@ public:
static const char* const type_text(const Type _type) static const char* const type_text(const Type _type)
{ {
static const char dscr[][32] = static const char dscr[][32] = {"EQUAL", "UNKNOWN", "IMPROVED",
{ "NEGLEGIBLE", "SUSPICIOUS", "REGRESSED", "WORKED", "FAILED"};
"EQUAL",
"UNKNOWN",
"IMPROVED",
"NEGLEGIBLE",
"SUSPICIOUS",
"REGRESSED",
"WORKED",
"FAILED"
};
return dscr[_type]; return dscr[_type];
} }
Difference(const Type _type = EQUAL, const String& _dscr = String()) Difference(const Type _type = EQUAL, const String& _dscr = String())
: type_(_type), dscr_(_dscr) : type_(_type), dscr_(_dscr)
{} {
}
const Type type() const { return type_; } const Type type() const { return type_; }
bool equal() const { return type() == EQUAL; } bool equal() const { return type() == EQUAL; }
...@@ -98,15 +98,12 @@ public: ...@@ -98,15 +98,12 @@ public:
return *this; return *this;
} }
const String& description() const const String& description() const { return dscr_; }
{
return dscr_;
}
const char* const type_text() const { return type_text(type_); } const char* const type_text() const { return type_text(type_); }
friend Base::IOutputStream& operator<<(Base::IOutputStream& _os, friend Base::IOutputStream& operator<<(
Difference& _diff) Base::IOutputStream& _os, Difference& _diff)
{ {
// TODO: use string description array // TODO: use string description array
return _os << _diff.type_text() << " " << _diff.dscr_; return _os << _diff.type_text() << " " << _diff.dscr_;
...@@ -119,7 +116,6 @@ private: ...@@ -119,7 +116,6 @@ private:
String dscr_; String dscr_;
}; };
/*! /*!
Base class for test checksums. Whatever check we want to add in the test system, 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 it must be an instance of a class derived from Checksum. All derived classes
...@@ -132,8 +128,7 @@ public: ...@@ -132,8 +128,7 @@ public:
const char* const name() const { return name_; } const char* const name() const { return name_; }
//! Add a record the checksum (generic version) //! Add a record the checksum (generic version)
template <typename T> template <typename T> void record(const Result& _rslt, const T& _data)
void record(const Result& _rslt, const T& _data)
{ {
Base::OStringStream strm; Base::OStringStream strm;
strm << _data; strm << _data;
...@@ -194,13 +189,23 @@ Function to get a static map with all the registered checksums. ...@@ -194,13 +189,23 @@ Function to get a static map with all the registered checksums.
*/ */
const Registry& registry(); const Registry& registry();
}//namespace Checksum } // namespace Checksum
}//namespace Test } // namespace Test
#define TEST(CHKSM, RCRD) { if (CHKSM.allow()) { CHKSM.RCRD; } } #define TEST(CHKSM, RCRD) \
#define TEST_if(CNDT, CHKSM, RCRD) { if (CNDT) 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: ...@@ -30,8 +30,7 @@ public:
}//namespace Checksum }//namespace Checksum
}//namespace Test }//namespace Test
#define TEST_CHECKSUM_FILE(VRBL, NAME) \ #define TEST_CHECKSUM_FILE(VRBL, NAME) File VRBL(NAME"-file", File::TAG_USED)
Test::Checksum::File VRBL(NAME"-file", Test::Checksum::File::TAG_USED)
#else//TEST_ON #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