diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2024-10-03 11:40:13 +0500 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2024-10-05 10:06:44 +0200 |
commit | a6a69211230226ac8b6c17d016fc19eb8ee11261 (patch) | |
tree | 321a5c4a7657baa966185d3757595ff6107d820a /include/test | |
parent | 95e2bdf97d987c845927bd44210547fd3c2f2387 (diff) |
Use good old string literals in assertXPath and friends
These are only sent to an external API expecting char*-like strings,
or for comparison. Having every assertXPath having three of _[ou]str
is too much syntactic noise, making the unit tests almost unreadable.
Change-Id: Ic004a36ea75e7bfe0b96f405c40f926a957b51cc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174416
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'include/test')
-rw-r--r-- | include/test/cppunitasserthelper.hxx | 7 | ||||
-rw-r--r-- | include/test/xmltesttools.hxx | 97 |
2 files changed, 76 insertions, 28 deletions
diff --git a/include/test/cppunitasserthelper.hxx b/include/test/cppunitasserthelper.hxx index 0fd3806b65fe..1f5679ef334c 100644 --- a/include/test/cppunitasserthelper.hxx +++ b/include/test/cppunitasserthelper.hxx @@ -74,6 +74,13 @@ inline std::string CPPUNIT_NS::assertion_traits<css::table::CellRangeAddress>::t return ost.str(); } +template <> +inline std::string +CPPUNIT_NS::assertion_traits<std::u16string_view>::toString(std::u16string_view const& x) +{ + return std::string(OUStringToOString(x, RTL_TEXTENCODING_UTF8)); +} + #endif // INCLUDED_TEST_CPPUNITASSERTHELPER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/test/xmltesttools.hxx b/include/test/xmltesttools.hxx index aa20257ff472..8f5df7c77465 100644 --- a/include/test/xmltesttools.hxx +++ b/include/test/xmltesttools.hxx @@ -47,70 +47,111 @@ protected: virtual void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx); // Caller must call xmlXPathFreeObject: - xmlXPathObjectPtr getXPathNode(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath); + xmlXPathObjectPtr getXPathNode(const xmlDocUniquePtr& pXmlDoc, const char* pXPath); /** * Same as the assertXPath(), but don't assert: return the string instead. */ - OUString getXPath(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OString& rAttribute); + OUString getXPath(const xmlDocUniquePtr& pXmlDoc, const char* pXPath, const char* pAttribute); + OUString getXPath(const xmlDocUniquePtr& pXmlDoc, const OString& sXPath, const char* pAttribute) + { + return getXPath(pXmlDoc, sXPath.getStr(), pAttribute); + } /** * Same as the assertXPathContent(), but don't assert: return the string instead. */ - OUString getXPathContent(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath); + OUString getXPathContent(const xmlDocUniquePtr& pXmlDoc, const char* pXPath); + OUString getXPathContent(const xmlDocUniquePtr& pXmlDoc, const OString& sXPath) + { + return getXPathContent(pXmlDoc, sXPath.getStr()); + } /** - * Get the position of the child named rName of the parent node specified by rXPath. + * Get the position of the child named rName of the parent node specified by pXPath. * Useful for checking relative order of elements. */ - int getXPathPosition(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, std::string_view rChildName); + int getXPathPosition(const xmlDocUniquePtr& pXmlDoc, const char* pXPath, const char* pChildName); /** - * Get the number of the nodes returned by the rXPath. + * Get the number of the nodes returned by the pXPath. */ - int countXPathNodes(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath); + int countXPathNodes(const xmlDocUniquePtr& pXmlDoc, const char* pXPath); + int countXPathNodes(const xmlDocUniquePtr& pXmlDoc, const OString& sXPath) + { + return countXPathNodes(pXmlDoc, sXPath.getStr()); + } /** - * Assert that rXPath exists, returns exactly one node, and the rXPath's attribute's value + * Assert that pXPath exists, returns exactly one node, and the pXPath's attribute's value * equals to the rExpected value. */ - void assertXPath(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OString& rAttribute, - const OUString& rExpectedValue); - void assertXPathAttrs(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, - const std::vector<std::pair<OString, OUString>>& aPairVector); + void assertXPath(const xmlDocUniquePtr& pXmlDoc, const char* pXPath, const char* pAttribute, + std::u16string_view rExpectedValue); + void assertXPath(const xmlDocUniquePtr& pXmlDoc, const OString& sXPath, const char* pAttribute, + std::u16string_view rExpectedValue) + { + assertXPath(pXmlDoc, sXPath.getStr(), pAttribute, rExpectedValue); + } + void assertXPathAttrs(const xmlDocUniquePtr& pXmlDoc, const char* pXPath, + const std::vector<std::pair<const char*, std::u16string_view>>& aPairVector); + void assertXPathAttrs(const xmlDocUniquePtr& pXmlDoc, const OString& sXPath, + const std::vector<std::pair<const char*, std::u16string_view>>& aPairVector) + { + assertXPathAttrs(pXmlDoc, sXPath.getStr(), aPairVector); + } /** - * Given a double for the rExpected value, assert that rXPath exists, returns exactly one node, - * and the rXPath's attribute's value matches the rExpected value within tolerance provided + * Given a double for the rExpected value, assert that pXPath exists, returns exactly one node, + * and the pXPath's attribute's value matches the rExpected value within tolerance provided * by delta. This is used to account for HiDPI scaling. */ - void assertXPathDoubleValue(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OString& rAttribute, + void assertXPathDoubleValue(const xmlDocUniquePtr& pXmlDoc, const char* pXPath, const char* pAttribute, double expectedValue, double delta); /** - * Assert that rXPath exists, and returns exactly nNumberOfNodes nodes (1 by default). + * Assert that pXPath exists, and returns exactly nNumberOfNodes nodes (1 by default). * Also useful for checking that we do _not_ export some node (nNumberOfNodes == 0). */ - void assertXPath(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, int nNumberOfNodes = 1); + void assertXPath(const xmlDocUniquePtr& pXmlDoc, const char* pXPath, int nNumberOfNodes = 1); + void assertXPath(const xmlDocUniquePtr& pXmlDoc, const OString& sXPath, int nNumberOfNodes = 1) + { + assertXPath(pXmlDoc, sXPath.getStr(), nNumberOfNodes); + } /** - * Assert that rXPath exists, and its content equals rContent. + * Assert that pXPath exists, and its content equals rContent. */ - void assertXPathContent(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OUString& rContent); + void assertXPathContent(const xmlDocUniquePtr& pXmlDoc, const char* pXPath, std::u16string_view rContent); + void assertXPathContent(const xmlDocUniquePtr& pXmlDoc, const OString& sXPath, + std::u16string_view rContent) + { + assertXPathContent(pXmlDoc, sXPath.getStr(), rContent); + } /** - * Assert that rXPath exists and it has an rNSPrefix=rNSHref namespace definition. + * Assert that pXPath exists and it has an rNSPrefix=rNSHref namespace definition. */ - void assertXPathNSDef(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, std::u16string_view rNSPrefix, - std::u16string_view rNSHref); + void assertXPathNSDef(const xmlDocUniquePtr& pXmlDoc, const char* pXPath, std::string_view rNSPrefix, + std::string_view rNSHref); /** - * Assert that rXPath exists, and has exactly nNumberOfChildNodes child nodes. + * Assert that pXPath exists, and has exactly nNumberOfChildNodes child nodes. * Useful for checking that we do have a no child nodes to a specific node (nNumberOfChildNodes == 0). */ - void assertXPathChildren(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, int nNumberOfChildNodes); + void assertXPathChildren(const xmlDocUniquePtr& pXmlDoc, const char* pXPath, int nNumberOfChildNodes); + void assertXPathChildren(const xmlDocUniquePtr& pXmlDoc, const OString& sXPath, + int nNumberOfChildNodes) + { + assertXPathChildren(pXmlDoc, sXPath.getStr(), nNumberOfChildNodes); + } /** - * Assert that rXPath exists, has exactly 1 result set nodes and does *not* have an attribute named rAttribute. + * Assert that pXPath exists, has exactly 1 result set nodes and does *not* have an attribute named pAttribute. */ - void assertXPathNoAttribute(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OString& rAttribute); + void assertXPathNoAttribute(const xmlDocUniquePtr& pXmlDoc, const char* pXPath, const char* pAttribute); + void assertXPathNoAttribute(const xmlDocUniquePtr& pXmlDoc, const OString& sXPath, + const char* pAttribute) + { + assertXPathNoAttribute(pXmlDoc, sXPath.getStr(), pAttribute); + } /** * Same as the assertXPathNoAttribute(), but don't assert: return the bool instead. */ - bool hasXPathAttribute(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OString& rAttribute); + bool hasXPathAttribute(const xmlDocUniquePtr& pXmlDoc, const char* pXPath, const char* pAttribute); // Assert that the node name of the single node returned by an XPath is as specified, // e.g. to check order of elements, where getXPathPosition is unapplicable - void assertXPathNodeName(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OString& rExpectedName); + void assertXPathNodeName(const xmlDocUniquePtr& pXmlDoc, const char* pXPath, std::string_view rExpectedName); static void registerODFNamespaces(xmlXPathContextPtr& pXmlXpathCtx); static void registerOOXMLNamespaces(xmlXPathContextPtr& pXmlXpathCtx); |