mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Added check macro that outputs hex digits
This commit is contained in:
parent
ccfce560ae
commit
648d5bf527
@ -54,6 +54,27 @@
|
||||
}) \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define UNITTEST_CHECK_EQUAL_HEX(expected, actual) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UNITTEST_IMPL_TRY \
|
||||
({ \
|
||||
UnitTest::CheckEqualHex(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
}) \
|
||||
UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \
|
||||
UNITTEST_IMPL_CATCH (std::exception, e, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream UnitTest_message; \
|
||||
UnitTest_message << "Unhandled exception (" << e.what() << ") in CHECK_EQUAL(" #expected ", " #actual ")"; \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
UnitTest_message.GetText()); \
|
||||
}) \
|
||||
UNITTEST_IMPL_CATCH_ALL \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
"Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \
|
||||
}) \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define UNITTEST_CHECK_CLOSE(expected, actual, tolerance) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UNITTEST_IMPL_TRY \
|
||||
@ -151,6 +172,12 @@
|
||||
#define CHECK_EQUAL UNITTEST_CHECK_EQUAL
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_EQUAL_HEX
|
||||
#error CHECK_EQUAL_HEX already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_EQUAL instead
|
||||
#else
|
||||
#define CHECK_EQUAL_HEX UNITTEST_CHECK_EQUAL_HEX
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_CLOSE
|
||||
#error CHECK_CLOSE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_CLOSE instead
|
||||
#else
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
#include "Config.h"
|
||||
#include "TestResults.h"
|
||||
#include "MemoryOutStream.h"
|
||||
#include<iomanip>
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
@ -37,6 +38,18 @@ namespace UnitTest {
|
||||
}
|
||||
}
|
||||
|
||||
template< typename Expected, typename Actual >
|
||||
void CheckEqualHex(TestResults& results, Expected const& expected, Actual const& actual, TestDetails const& details)
|
||||
{
|
||||
if (!(expected == actual))
|
||||
{
|
||||
UnitTest::MemoryOutStream stream;
|
||||
stream << std::hex << std::uppercase << std::setfill('0') << "Expected 0x" << std::setw(2 * sizeof(Expected)) << expected << " but was 0x" << std::setw(2 * sizeof(Actual)) << actual;
|
||||
|
||||
results.OnTestFailure(details, stream.GetText());
|
||||
}
|
||||
}
|
||||
|
||||
UNITTEST_LINKAGE void CheckEqual(TestResults& results, char const* expected, char const* actual, TestDetails const& details);
|
||||
|
||||
UNITTEST_LINKAGE void CheckEqual(TestResults& results, char* expected, char* actual, TestDetails const& details);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user