https://bugs.documentfoundation.org/show_bug.cgi?id=154757
Bug ID: 154757
Summary: CPP unit tests: provide message converters to allow
use of O(U)Strings as _MESSAGE argument
Product: LibreOffice
Version: unspecified
Hardware: All
OS: All
Status: UNCONFIRMED
Keywords: difficultyBeginner, easyHack, skillCpp
Severity: normal
Priority: medium
Component: LibreOffice
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected]
In CPP unit tests, that use cppunit [1], there are helpful assertion macros
with _MESSAGE, like CPPUNIT_ASSERT_MESSAGE. These take a string as the first
argument, which is output when the test fails, providing additional context,
often useful in loops.
See e.g. testTdf154319 in sw/qa/extras/ooxmlimport/ooxmlimport2.cxx, which
constructs the message, showing which property in which level is being tested,
so that the failure provides enough context.
However, it's impossible to use our string types (and their familiar
operations, like concatenations and number conversions) as the message. The use
of OString requires passing C-style pointer from getStr call; OUString requires
conversion to UTF-8-encoded OString first; and concatenations need to be
explicitly converted to OString, too, like in testTdf112118_DOCX
(sw/qa/extras/ooxmlexport/ooxmlexport11.cxx).
cppunit uses overloads of CPPUNIT_NS::message_to_string to convert the message
argument to std::string.
The task is to provide appropriate conversion overloads for OString and
OUString, and then simplify the places in tests that currently do the
conversions themselves. The suggested place where these overloads could be
placed is include/o3tl/cppunittraitshelper.hxx.
The result should, for example, convert the current code in testTdf112118_DOCX
from
> CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(sStage + " margin
> width").getStr(),
> side.nMargin, nMargin);
into
> CPPUNIT_ASSERT_EQUAL_MESSAGE(sStage + " margin width",
> side.nMargin, nMargin);
[1] https://git.libreoffice.org/cppunit
--
You are receiving this mail because:
You are the assignee for the bug.