Commit fb7a78b8 authored by Martin Marinov's avatar Martin Marinov

Add Test::Checksum::IssueNumber to refactor common checksum code

parent a7db159d
......@@ -3,6 +3,7 @@ set(my_headers
${CMAKE_CURRENT_SOURCE_DIR}/ChecksumCondition.hh
${CMAKE_CURRENT_SOURCE_DIR}/ChecksumDebugEvent.hh
${CMAKE_CURRENT_SOURCE_DIR}/ChecksumFile.hh
${CMAKE_CURRENT_SOURCE_DIR}/ChecksumIssueNumber.hh
${CMAKE_CURRENT_SOURCE_DIR}/ChecksumNumberT.hh
${CMAKE_CURRENT_SOURCE_DIR}/types.hh
${CMAKE_CURRENT_SOURCE_DIR}/TestResult.hh
......@@ -15,5 +16,6 @@ set(my_sources
${CMAKE_CURRENT_SOURCE_DIR}/ChecksumCondition.cc
${CMAKE_CURRENT_SOURCE_DIR}/ChecksumDebugEvent.cc
${CMAKE_CURRENT_SOURCE_DIR}/ChecksumFile.cc
${CMAKE_CURRENT_SOURCE_DIR}/ChecksumIssueNumber.cc
PARENT_SCOPE
)
// (C) Copyright 2020 by Autodesk, Inc.
#ifdef TEST_ON
#include "ChecksumIssueNumber.hh"
#include "TestResult.hh"
#include <sstream>
namespace Test
{
namespace Checksum
{
void IssueNumber::record(const size_t _issue_nmbr, const Result _bad_rslt)
{
Object::record(_issue_nmbr == 0 ? Result::OK : _bad_rslt, _issue_nmbr);
}
Difference IssueNumber::compare_data(
const String& _old, const String& _new) const
{
std::istringstream strm_old(_old), strm_new(_new);
size_t val_old, val_new;
strm_old >> val_old;
strm_new >> val_new;
if (val_new < val_old)
return Difference::IMPROVED;
else if (val_new > val_old)
return Difference::REGRESSED;
else
return Difference::EQUAL;
}
} // namespace Checksum
} // namespace Test
#endif // TEST_ON
// (C) Copyright 2020 by Autodesk, Inc.
#ifndef BASE_CHECKSUM_ISSUE_NUMBER_HH_INCLUDED
#define BASE_CHECKSUM_ISSUE_NUMBER_HH_INCLUDED
#include <Base/Test/Checksum.hh>
#if defined(TEST_ON)
namespace Test
{
namespace Checksum
{
//! Checksum that records and compares a number of issues in a test
class IssueNumber : public Object
{
protected:
//! Constructor
IssueNumber(const char* const _name, const Level _lvl = L_ALL)
: Object(_name, _lvl)
{
}
//! Record an error (or warning) if the issue number > 0
void record(const size_t _issue_nmbr, const Result _bad_rslt = Result::ERROR);
//! Implements a smart comparison for this type of test checksum
Difference compare_data(const String& _old, const String& _new) const final;
};
} // namespace Checksum
} // namespace Test
#endif // defined(TEST_ON)
#endif//BASE_CHECKSUM_ISSUE_NUMBER_HH_INCLUDED
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