From 3b4e8a4eea459afb89c9faa34668d883f9969278 Mon Sep 17 00:00:00 2001 From: Le Philousophe Date: Tue, 29 Aug 2023 12:26:21 +0200 Subject: [PATCH] TEST: Add CxxTest ValueTraits for String This allows pretty printing them when there is an assertion failure --- test/common/str-helper.h | 23 +++++++++++++++++++++++ test/common/str.h | 2 ++ 2 files changed, 25 insertions(+) create mode 100644 test/common/str-helper.h diff --git a/test/common/str-helper.h b/test/common/str-helper.h new file mode 100644 index 00000000000..f879d339c86 --- /dev/null +++ b/test/common/str-helper.h @@ -0,0 +1,23 @@ +#ifndef TEST_COMMON_HELPER_H +#define TEST_COMMON_HELPER_H + +#include "common/str.h" + +namespace CxxTest +{ + CXXTEST_TEMPLATE_INSTANTIATION + class ValueTraits + { + ValueTraits &operator=( const ValueTraits & ); + Common::String _str; + + public: + ValueTraits( const Common::String &value ) : _str( value ) {} + ValueTraits( const ValueTraits &other ) : _str( other._str ) {} + const char *asString( void ) const { return _str.c_str(); } + }; + CXXTEST_COPY_CONST_TRAITS( Common::String &); + CXXTEST_COPY_TRAITS( Common::String, const Common::String &); +} + +#endif diff --git a/test/common/str.h b/test/common/str.h index 6827ec91e94..06a066b1387 100644 --- a/test/common/str.h +++ b/test/common/str.h @@ -3,6 +3,8 @@ #include "common/str.h" #include "common/ustr.h" +#include "test/common/str-helper.h" + class StringTestSuite : public CxxTest::TestSuite { public: