Only specialize CppUnit::assetion_traits<T>::toString member functions

...not the whole CppUnit::assetion_traits<T> classes (where applicable).  That
avoids spelling out the (identical) equals member functions, and also leaves
around the less and lessEqual member functions, in case they want to be used
after all.

Change-Id: I18f8d6cff0353921ced4952b33a0c85ff8292923
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147165
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Stephan Bergmann
2023-02-16 19:07:56 +01:00
parent 5884a122dc
commit df5995b0bf
8 changed files with 68 additions and 151 deletions

View File

@@ -28,24 +28,13 @@ using namespace ::com::sun::star::table::BorderLineStyle;
using namespace editeng; using namespace editeng;
CPPUNIT_NS_BEGIN template<> inline std::string CPPUNIT_NS::assertion_traits<SvxBorderLineStyle>::toString(
SvxBorderLineStyle const & x )
template<> struct assertion_traits<SvxBorderLineStyle>
{ {
static bool equal( SvxBorderLineStyle x, SvxBorderLineStyle y ) OStringStream ost;
{ ost << static_cast<unsigned int>(x);
return x == y; return ost.str();
} }
static std::string toString( SvxBorderLineStyle x )
{
OStringStream ost;
ost << static_cast<unsigned int>(x);
return ost.str();
}
};
CPPUNIT_NS_END
namespace { namespace {

View File

@@ -19,85 +19,60 @@
#include <cppunit/TestAssert.h> #include <cppunit/TestAssert.h>
CPPUNIT_NS_BEGIN
/** @brief Trait used by CPPUNIT_ASSERT* macros to compare com::sun::star:awt::Point. /** @brief Trait used by CPPUNIT_ASSERT* macros to compare com::sun::star:awt::Point.
* *
* This specialization from @c struct @c assertion_traits<> helps to compare * This specialization from @c struct @c assertion_traits<> helps to compare
* @see com::sun::star::awt::Point. * @see com::sun::star::awt::Point.
*/ */
template <> struct assertion_traits<css::awt::Point> template <>
inline std::string CPPUNIT_NS::assertion_traits<css::awt::Point>::toString(const css::awt::Point& x)
{ {
static bool equal(const css::awt::Point& x, const css::awt::Point& y) { return x == y; } OStringStream ost;
ost << "Point: " << x.X << "." << x.Y << " (coordinate: X.Y)";
static std::string toString(const css::awt::Point& x) return ost.str();
{ }
OStringStream ost;
ost << "Point: " << x.X << "." << x.Y << " (coordinate: X.Y)";
return ost.str();
}
};
/** @brief Trait used by CPPUNIT_ASSERT* macros to compare com::sun::star:awt::Size. /** @brief Trait used by CPPUNIT_ASSERT* macros to compare com::sun::star:awt::Size.
* *
* This specialization from @c struct @c assertion_traits<> helps to compare * This specialization from @c struct @c assertion_traits<> helps to compare
* @see com::sun::star::awt::Size. * @see com::sun::star::awt::Size.
*/ */
template <> struct assertion_traits<css::awt::Size> template <>
inline std::string CPPUNIT_NS::assertion_traits<css::awt::Size>::toString(const css::awt::Size& x)
{ {
static bool equal(const css::awt::Size& x, const css::awt::Size& y) { return x == y; } OStringStream ost;
ost << "Size: " << x.Width << " x " << x.Height << " (Width x Height)";
static std::string toString(const css::awt::Size& x) return ost.str();
{ }
OStringStream ost;
ost << "Size: " << x.Width << " x " << x.Height << " (Width x Height)";
return ost.str();
}
};
/** @brief Trait used by CPPUNIT_ASSERT* macros to compare com::sun::star::table::CellAddress. /** @brief Trait used by CPPUNIT_ASSERT* macros to compare com::sun::star::table::CellAddress.
* *
* This specialization from @c struct @c assertion_traits<> helps to compare * This specialization from @c struct @c assertion_traits<> helps to compare
* @see com::sun::star::table::CellAddress. * @see com::sun::star::table::CellAddress.
*/ */
template <> struct assertion_traits<css::table::CellAddress> template <>
inline std::string
CPPUNIT_NS::assertion_traits<css::table::CellAddress>::toString(const css::table::CellAddress& x)
{ {
static bool equal(const css::table::CellAddress& x, const css::table::CellAddress& y) OStringStream ost;
{ ost << "Sheet: " << x.Sheet << " Column: " << x.Column << " Row: " << x.Row;
return x == y; return ost.str();
} }
static std::string toString(const css::table::CellAddress& x)
{
OStringStream ost;
ost << "Sheet: " << x.Sheet << " Column: " << x.Column << " Row: " << x.Row;
return ost.str();
}
};
/** @brief Trait used by CPPUNIT_ASSERT* macros to compare com::sun::star::table::CellRangeAddress. /** @brief Trait used by CPPUNIT_ASSERT* macros to compare com::sun::star::table::CellRangeAddress.
* *
* This specialization from @c struct @c assertion_traits<> helps to compare * This specialization from @c struct @c assertion_traits<> helps to compare
* @see com::sun::star::table::CellRangeAddress. * @see com::sun::star::table::CellRangeAddress.
*/ */
template <> struct assertion_traits<css::table::CellRangeAddress> template <>
inline std::string CPPUNIT_NS::assertion_traits<css::table::CellRangeAddress>::toString(
const css::table::CellRangeAddress& x)
{ {
static bool equal(const css::table::CellRangeAddress& x, const css::table::CellRangeAddress& y) OStringStream ost;
{ ost << "Sheet: " << x.Sheet << " StartColumn: " << x.StartColumn << " StartRow: " << x.StartRow
return x == y; << " EndColumn: " << x.EndColumn << " EndRow: " << x.EndRow;
} return ost.str();
}
static std::string toString(const css::table::CellRangeAddress& x)
{
OStringStream ost;
ost << "Sheet: " << x.Sheet << " StartColumn: " << x.StartColumn
<< " StartRow: " << x.StartRow << " EndColumn: " << x.EndColumn
<< " EndRow: " << x.EndRow;
return ost.str();
}
};
CPPUNIT_NS_END
#endif // INCLUDED_TEST_CPPUNITASSERTHELPER_HXX #endif // INCLUDED_TEST_CPPUNITASSERTHELPER_HXX

View File

@@ -23,17 +23,11 @@
// gcc 11.2.0 triggers a spurious -Werror=stringop-overread // gcc 11.2.0 triggers a spurious -Werror=stringop-overread
#if !(defined __GNUC__ && __GNUC__ == 11 && __GNUC_MINOR__ == 2) #if !(defined __GNUC__ && __GNUC__ == 11 && __GNUC_MINOR__ == 2)
namespace CppUnit template <>
inline std::string
CppUnit::assertion_traits<std::u16string_view>::toString(std::u16string_view const& x)
{ {
template <> struct assertion_traits<std::u16string_view> return OUStringToOString(x, RTL_TEXTENCODING_UTF8).getStr();
{
static bool equal(std::u16string_view x, std::u16string_view y) { return x == y; }
static std::string toString(std::u16string_view x)
{
return OUStringToOString(x, RTL_TEXTENCODING_UTF8).getStr();
}
};
} }
namespace namespace

View File

@@ -27,24 +27,13 @@
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <limits> #include <limits>
CPPUNIT_NS_BEGIN template<> inline std::string CPPUNIT_NS::assertion_traits<rtl_math_ConversionStatus>::toString(
const rtl_math_ConversionStatus& x )
template<> struct assertion_traits<rtl_math_ConversionStatus>
{ {
static bool equal( const rtl_math_ConversionStatus& x, const rtl_math_ConversionStatus& y ) OStringStream ost;
{ ost << static_cast<unsigned int>(x);
return x == y; return ost.str();
} }
static std::string toString( const rtl_math_ConversionStatus& x )
{
OStringStream ost;
ost << static_cast<unsigned int>(x);
return ost.str();
}
};
CPPUNIT_NS_END
namespace { namespace {

View File

@@ -27,15 +27,11 @@ bool rtl_string_unittest_invalid_concat = false;
using namespace rtl; using namespace rtl;
namespace CppUnit template<> inline std::string CppUnit::assertion_traits<std::type_info>::toString(
std::type_info const & x)
{ {
template<> struct assertion_traits<std::type_info> return x.name();
{ }
static bool equal(std::type_info const & x, std::type_info const & y) { return x == y; }
static std::string toString(std::type_info const & x) { return x.name(); }
};
} // namespace
namespace test::ostring { namespace test::ostring {

View File

@@ -26,15 +26,11 @@ extern bool rtl_string_unittest_invalid_concat;
using namespace rtl; using namespace rtl;
namespace CppUnit template<> inline std::string CppUnit::assertion_traits<std::type_info>::toString(
std::type_info const & x)
{ {
template<> struct assertion_traits<std::type_info> return x.name();
{ }
static bool equal(std::type_info const & x, std::type_info const & y) { return x == y; }
static std::string toString(std::type_info const & x) { return x.name(); }
};
} // namespace
namespace test::oustring { namespace test::oustring {

View File

@@ -21,29 +21,18 @@
using namespace com::sun::star; using namespace com::sun::star;
using namespace com::sun::star::uno; using namespace com::sun::star::uno;
CPPUNIT_NS_BEGIN template<> inline std::string
CPPUNIT_NS::assertion_traits<uno::Sequence< sheet::SubTotalColumn > >::toString(
template<> struct assertion_traits<uno::Sequence< sheet::SubTotalColumn > > const uno::Sequence< sheet::SubTotalColumn >& x)
{ {
static bool equal(const uno::Sequence< sheet::SubTotalColumn >& x, OStringStream ost;
const uno::Sequence< sheet::SubTotalColumn >& y) ost << "Sequence: Length: " << x.getLength() << "\n";
{ for (const auto& rElement : x)
return x == y; ost << "Column: " << rElement.Column << " Function:\n";
} // FIXME: Find a way to print Function
//ost << "Column: " << element->Column << " Function: " << element->Function << "\n";
static std::string toString(const uno::Sequence< sheet::SubTotalColumn >& x) return ost.str();
{ }
OStringStream ost;
ost << "Sequence: Length: " << x.getLength() << "\n";
for (const auto& rElement : x)
ost << "Column: " << rElement.Column << " Function:\n";
// FIXME: Find a way to print Function
//ost << "Column: " << element->Column << " Function: " << element->Function << "\n";
return ost.str();
}
};
CPPUNIT_NS_END
namespace apitest { namespace apitest {

View File

@@ -18,24 +18,13 @@
#define OUSTR_TO_STDSTR( oustr ) std::string( OUStringToOString( oustr, RTL_TEXTENCODING_ASCII_US ).getStr() ) #define OUSTR_TO_STDSTR( oustr ) std::string( OUStringToOString( oustr, RTL_TEXTENCODING_ASCII_US ).getStr() )
CPPUNIT_NS_BEGIN template<> inline std::string CPPUNIT_NS::assertion_traits<INetProtocol>::toString(
const INetProtocol& x )
template<> struct assertion_traits<INetProtocol>
{ {
static bool equal( const INetProtocol& x, const INetProtocol& y ) OStringStream ost;
{ ost << static_cast<unsigned int>(x);
return x == y; return ost.str();
} }
static std::string toString( const INetProtocol& x )
{
OStringStream ost;
ost << static_cast<unsigned int>(x);
return ost.str();
}
};
CPPUNIT_NS_END
namespace tools_urlobj namespace tools_urlobj
{ {