From 9cb1b33a4afacdb5b5c10542d1d0626a531a769d Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Mon, 24 Oct 2022 14:51:01 +0200 Subject: CppunitTest_xmloff_style: inherit from UnoApiTest Change-Id: If0f956336581438927ab3e01a50374c15b43bcd2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141763 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- xmloff/CppunitTest_xmloff_style.mk | 1 + xmloff/qa/unit/style.cxx | 108 +++++++++++-------------------------- 2 files changed, 33 insertions(+), 76 deletions(-) (limited to 'xmloff') diff --git a/xmloff/CppunitTest_xmloff_style.mk b/xmloff/CppunitTest_xmloff_style.mk index 8d603833c7a8..3d0d6b730e0c 100644 --- a/xmloff/CppunitTest_xmloff_style.mk +++ b/xmloff/CppunitTest_xmloff_style.mk @@ -23,6 +23,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,xmloff_style, \ $(eval $(call gb_CppunitTest_use_libraries,xmloff_style, \ comphelper \ cppu \ + subsequenttest \ embobj \ sal \ test \ diff --git a/xmloff/qa/unit/style.cxx b/xmloff/qa/unit/style.cxx index 7c9053df6b6b..f2a2bd80e352 100644 --- a/xmloff/qa/unit/style.cxx +++ b/xmloff/qa/unit/style.cxx @@ -11,8 +11,7 @@ #include -#include -#include +#include #include #include @@ -32,38 +31,17 @@ using namespace ::com::sun::star; -constexpr OUStringLiteral DATA_DIRECTORY = u"/xmloff/qa/unit/data/"; - /// Covers xmloff/source/style/ fixes. -class XmloffStyleTest : public test::BootstrapFixture, - public unotest::MacrosTest, - public XmlTestTools +class XmloffStyleTest : public UnoApiTest, public XmlTestTools { -private: - uno::Reference mxComponent; - public: - void setUp() override; - void tearDown() override; + XmloffStyleTest(); void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) override; - uno::Reference& getComponent() { return mxComponent; } - void load(std::u16string_view rURL); - void save(const OUString& rFilterName, utl::TempFileNamed& rTempFile); }; -void XmloffStyleTest::setUp() +XmloffStyleTest::XmloffStyleTest() + : UnoApiTest("/xmloff/qa/unit/data/") { - test::BootstrapFixture::setUp(); - - mxDesktop.set(frame::Desktop::create(mxComponentContext)); -} - -void XmloffStyleTest::tearDown() -{ - if (mxComponent.is()) - mxComponent->dispose(); - - test::BootstrapFixture::tearDown(); } void XmloffStyleTest::registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) @@ -71,27 +49,11 @@ void XmloffStyleTest::registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) XmlTestTools::registerODFNamespaces(pXmlXpathCtx); } -void XmloffStyleTest::load(std::u16string_view rFileName) -{ - OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + rFileName; - mxComponent = loadFromDesktop(aURL); -} - -void XmloffStyleTest::save(const OUString& rFilterName, utl::TempFileNamed& rTempFile) -{ - uno::Reference xStorable(mxComponent, uno::UNO_QUERY); - utl::MediaDescriptor aMediaDescriptor; - aMediaDescriptor["FilterName"] <<= rFilterName; - rTempFile.EnableKillingFile(); - xStorable->storeToURL(rTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); - validate(rTempFile.GetFileName(), test::ODF); -} - CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testFillImageBase64) { // Load a flat ODG that has base64-encoded bitmap as a fill style. - load(u"fill-image-base64.fodg"); - uno::Reference xFactory(getComponent(), uno::UNO_QUERY); + loadFromURL(u"fill-image-base64.fodg"); + uno::Reference xFactory(mxComponent, uno::UNO_QUERY); uno::Reference xBitmaps( xFactory->createInstance("com.sun.star.drawing.BitmapTable"), uno::UNO_QUERY); @@ -122,16 +84,10 @@ struct XmlFont CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testFontSorting) { // Given an empty document with default fonts (Liberation Sans, Lucida Sans, etc): - getComponent() = loadFromDesktop("private:factory/swriter"); + mxComponent = loadFromDesktop("private:factory/swriter"); // When saving that document to ODT: - uno::Reference xStorable(getComponent(), uno::UNO_QUERY); - utl::TempFileNamed aTempFile; - aTempFile.EnableKillingFile(); - uno::Sequence aStoreProps = comphelper::InitPropertySequence({ - { "FilterName", uno::Any(OUString("writer8")) }, - }); - xStorable->storeToURL(aTempFile.GetURL(), aStoreProps); + utl::TempFileNamed aTempFile = save("writer8"); // Then make sure elements are sorted (by style:name="..."): uno::Reference xNameAccess @@ -193,10 +149,10 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testRtlGutter) { // Given a document with a gutter margin and an RTL writing mode: // When loading that document from ODF: - load(u"rtl-gutter.fodt"); + loadFromURL(u"rtl-gutter.fodt"); // Then make sure the page style's RtlGutter property is true. - uno::Reference xStyleFamiliesSupplier(getComponent(), + uno::Reference xStyleFamiliesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xStyleFamilies = xStyleFamiliesSupplier->getStyleFamilies(); @@ -216,9 +172,7 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testWritingModeBTLR) // Load document. It has a frame style with writing-mode bt-lr. // In ODF 1.3 extended it is written as loext:writing-mode="bt-lr". // In ODF 1.3 strict, there must not be an attribute at all. - getComponent() = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY) - + "tdf150407_WritingModeBTLR_style.odt", - "com.sun.star.text.TextDocument"); + loadFromURL(u"tdf150407_WritingModeBTLR_style.odt"); Resetter _([]() { std::shared_ptr pBatch( @@ -234,8 +188,8 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testWritingModeBTLR) comphelper::ConfigurationChanges::create()); officecfg::Office::Common::Save::ODF::DefaultVersion::set(3, pBatch); pBatch->commit(); - utl::TempFileNamed aTempFile; - save("writer8", aTempFile); + utl::TempFileNamed aTempFile = save("writer8"); + validate(aTempFile.GetFileName(), test::ODF); // With applied fix for tdf150407 still loext:writing-mode="bt-lr" has to be written. std::unique_ptr pStream = parseExportStream(aTempFile, "styles.xml"); @@ -248,14 +202,16 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testWritingModeBTLR) "style:graphic-properties", "writing-mode", "bt-lr"); } + + loadFromURL(u"tdf150407_WritingModeBTLR_style.odt"); // Save to ODF 1.3 strict. { std::shared_ptr pBatch( comphelper::ConfigurationChanges::create()); officecfg::Office::Common::Save::ODF::DefaultVersion::set(10, pBatch); pBatch->commit(); - utl::TempFileNamed aTempFile; - save("writer8", aTempFile); + utl::TempFileNamed aTempFile = save("writer8"); + validate(aTempFile.GetFileName(), test::ODF); // Without the fix an faulty 'writing-mode="bt-lr"' attribute was written in productive build. // A debug build fails assertion in SvXMLNamespaceMap::GetQNameByKey(). @@ -273,9 +229,7 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testPosRelBottomMargin) // Load document. It has a frame position with vertical position relative to bottom margin. // In ODF 1.3 extended it is written as loext:vertical-rel="page-content-bottom". // In ODF 1.3 strict, there must not be an attribute at all. - getComponent() = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY) - + "tdf150407_PosRelBottomMargin.docx", - "com.sun.star.text.TextDocument"); + loadFromURL(u"tdf150407_PosRelBottomMargin.docx"); Resetter _([]() { std::shared_ptr pBatch( @@ -291,8 +245,8 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testPosRelBottomMargin) comphelper::ConfigurationChanges::create()); officecfg::Office::Common::Save::ODF::DefaultVersion::set(3, pBatch); pBatch->commit(); - utl::TempFileNamed aTempFile; - save("writer8", aTempFile); + utl::TempFileNamed aTempFile = save("writer8"); + validate(aTempFile.GetFileName(), test::ODF); // With applied fix for tdf150407 still loext:vertical-rel="page-content-bottom" has to be // written. @@ -308,14 +262,16 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testPosRelBottomMargin) "style:graphic-properties", "vertical-rel", "page-content-bottom"); } + + loadFromURL(u"tdf150407_PosRelBottomMargin.docx"); // Save to ODF 1.3 strict. { std::shared_ptr pBatch( comphelper::ConfigurationChanges::create()); officecfg::Office::Common::Save::ODF::DefaultVersion::set(10, pBatch); pBatch->commit(); - utl::TempFileNamed aTempFile; - save("writer8", aTempFile); + utl::TempFileNamed aTempFile = save("writer8"); + validate(aTempFile.GetFileName(), test::ODF); // Without the fix an faulty 'vertical-rel="page-content-bottom"' attribute was written in // productive build. A debug build fails assertion in SvXMLNamespaceMap::GetQNameByKey(). @@ -333,9 +289,7 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testPosRelTopMargin) // Load document. It has a frame position with vertical position relative to top margin. // In ODF 1.3 extended it is written as loext:vertical-rel="page-content-top". // In ODF 1.3 strict, there must not be an attribute at all. - getComponent() = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY) - + "tdf150407_PosRelTopMargin.docx", - "com.sun.star.text.TextDocument"); + loadFromURL(u"tdf150407_PosRelTopMargin.docx"); Resetter _([]() { std::shared_ptr pBatch( @@ -351,8 +305,8 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testPosRelTopMargin) comphelper::ConfigurationChanges::create()); officecfg::Office::Common::Save::ODF::DefaultVersion::set(3, pBatch); pBatch->commit(); - utl::TempFileNamed aTempFile; - save("writer8", aTempFile); + utl::TempFileNamed aTempFile = save("writer8"); + validate(aTempFile.GetFileName(), test::ODF); // With applied fix for tdf150407 still loext:vertical-rel="page-content-top has to be // written. @@ -368,14 +322,16 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testPosRelTopMargin) "style:graphic-properties", "vertical-rel", "page-content-top"); } + + loadFromURL(u"tdf150407_PosRelTopMargin.docx"); // Save to ODF 1.3 strict. { std::shared_ptr pBatch( comphelper::ConfigurationChanges::create()); officecfg::Office::Common::Save::ODF::DefaultVersion::set(10, pBatch); pBatch->commit(); - utl::TempFileNamed aTempFile; - save("writer8", aTempFile); + utl::TempFileNamed aTempFile = save("writer8"); + validate(aTempFile.GetFileName(), test::ODF); // Without the fix an faulty 'vertical-rel="page-content-top"' attribute was written in // productive build. A debug build fails assertion in SvXMLNamespaceMap::GetQNameByKey(). -- cgit