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;
CPPUNIT_NS_BEGIN
template<> struct assertion_traits<SvxBorderLineStyle>
{
static bool equal( SvxBorderLineStyle x, SvxBorderLineStyle y )
{
return x == y;
}
static std::string toString( SvxBorderLineStyle x )
template<> inline std::string CPPUNIT_NS::assertion_traits<SvxBorderLineStyle>::toString(
SvxBorderLineStyle const & x )
{
OStringStream ost;
ost << static_cast<unsigned int>(x);
return ost.str();
}
};
CPPUNIT_NS_END
namespace {

View File

@@ -19,85 +19,60 @@
#include <cppunit/TestAssert.h>
CPPUNIT_NS_BEGIN
/** @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
* @see com::sun::star::awt::Point.
*/
template <> struct assertion_traits<css::awt::Point>
{
static bool equal(const css::awt::Point& x, const css::awt::Point& y) { return x == y; }
static std::string toString(const css::awt::Point& x)
template <>
inline std::string CPPUNIT_NS::assertion_traits<css::awt::Point>::toString(const css::awt::Point& x)
{
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.
*
* This specialization from @c struct @c assertion_traits<> helps to compare
* @see com::sun::star::awt::Size.
*/
template <> struct assertion_traits<css::awt::Size>
{
static bool equal(const css::awt::Size& x, const css::awt::Size& y) { return x == y; }
static std::string toString(const css::awt::Size& x)
template <>
inline std::string CPPUNIT_NS::assertion_traits<css::awt::Size>::toString(const css::awt::Size& x)
{
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.
*
* This specialization from @c struct @c assertion_traits<> helps to compare
* @see com::sun::star::table::CellAddress.
*/
template <> struct assertion_traits<css::table::CellAddress>
{
static bool equal(const css::table::CellAddress& x, const css::table::CellAddress& y)
{
return x == y;
}
static std::string toString(const css::table::CellAddress& x)
template <>
inline std::string
CPPUNIT_NS::assertion_traits<css::table::CellAddress>::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.
*
* This specialization from @c struct @c assertion_traits<> helps to compare
* @see com::sun::star::table::CellRangeAddress.
*/
template <> struct assertion_traits<css::table::CellRangeAddress>
{
static bool equal(const css::table::CellRangeAddress& x, const css::table::CellRangeAddress& y)
{
return x == y;
}
static std::string toString(const css::table::CellRangeAddress& x)
template <>
inline std::string CPPUNIT_NS::assertion_traits<css::table::CellRangeAddress>::toString(
const css::table::CellRangeAddress& x)
{
OStringStream ost;
ost << "Sheet: " << x.Sheet << " StartColumn: " << x.StartColumn
<< " StartRow: " << x.StartRow << " EndColumn: " << x.EndColumn
<< " EndRow: " << x.EndRow;
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

View File

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

View File

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

View File

@@ -27,15 +27,11 @@ bool rtl_string_unittest_invalid_concat = false;
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>
{
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
return x.name();
}
namespace test::ostring {

View File

@@ -26,15 +26,11 @@ extern bool rtl_string_unittest_invalid_concat;
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>
{
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
return x.name();
}
namespace test::oustring {

View File

@@ -21,17 +21,9 @@
using namespace com::sun::star;
using namespace com::sun::star::uno;
CPPUNIT_NS_BEGIN
template<> struct assertion_traits<uno::Sequence< sheet::SubTotalColumn > >
{
static bool equal(const uno::Sequence< sheet::SubTotalColumn >& x,
const uno::Sequence< sheet::SubTotalColumn >& y)
{
return x == y;
}
static std::string toString(const uno::Sequence< sheet::SubTotalColumn >& x)
template<> inline std::string
CPPUNIT_NS::assertion_traits<uno::Sequence< sheet::SubTotalColumn > >::toString(
const uno::Sequence< sheet::SubTotalColumn >& x)
{
OStringStream ost;
ost << "Sequence: Length: " << x.getLength() << "\n";
@@ -41,9 +33,6 @@ template<> struct assertion_traits<uno::Sequence< sheet::SubTotalColumn > >
//ost << "Column: " << element->Column << " Function: " << element->Function << "\n";
return ost.str();
}
};
CPPUNIT_NS_END
namespace apitest {

View File

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