diff options
author | Vasily Melenchuk <vasily.melenchuk@cib.de> | 2018-10-15 16:14:02 +0200 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-10-16 12:35:28 +0200 |
commit | 48d22544be09bf63ded8eb48d1f8252b456f7fd5 (patch) | |
tree | 008bac42a20651889adc416078ca56f6929b6e95 /sw/qa/extras/unowriter | |
parent | f3961ea18cf4f80d231f6bc63320af1454d1e7e9 (diff) |
sw: merge test suites sw_unoapi and sw_unowriter
Both test suites have the same propose "Test to assert
UNO API call results of Writer" so better to keep them
together.
Change-Id: I0ef7c28856a374dca3edcec73fd98a96c5067527
Reviewed-on: https://gerrit.libreoffice.org/61794
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sw/qa/extras/unowriter')
-rw-r--r-- | sw/qa/extras/unowriter/data/xautotextgroup.odt | bin | 0 -> 11151 bytes | |||
-rw-r--r-- | sw/qa/extras/unowriter/unowriter.cxx | 230 |
2 files changed, 217 insertions, 13 deletions
diff --git a/sw/qa/extras/unowriter/data/xautotextgroup.odt b/sw/qa/extras/unowriter/data/xautotextgroup.odt Binary files differnew file mode 100644 index 000000000000..e1cb9e7ea052 --- /dev/null +++ b/sw/qa/extras/unowriter/data/xautotextgroup.odt diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx index 96945d25a40f..933e17b928bb 100644 --- a/sw/qa/extras/unowriter/unowriter.cxx +++ b/sw/qa/extras/unowriter/unowriter.cxx @@ -10,6 +10,14 @@ #include <swmodeltestbase.hxx> #include <com/sun/star/awt/FontSlant.hpp> #include <com/sun/star/text/TextContentAnchorType.hpp> +#include <com/sun/star/text/AutoTextContainer.hpp> +#include <com/sun/star/text/XAutoTextGroup.hpp> +#include <com/sun/star/rdf/URI.hpp> +#include <com/sun/star/rdf/URIs.hpp> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::text; namespace { @@ -20,18 +28,55 @@ char const DATA_DIRECTORY[] = "/sw/qa/extras/unowriter/data/"; class SwUnoWriter : public SwModelTestBase { public: - void testDefaultCharStyle(); - void testGraphicDesciptorURL(); - void testGraphicDesciptorURLBitmap(); - - CPPUNIT_TEST_SUITE(SwUnoWriter); - CPPUNIT_TEST(testDefaultCharStyle); - CPPUNIT_TEST(testGraphicDesciptorURL); - CPPUNIT_TEST(testGraphicDesciptorURLBitmap); - CPPUNIT_TEST_SUITE_END(); + SwUnoWriter() + : SwModelTestBase(DATA_DIRECTORY, "writer8") + { + } }; -void SwUnoWriter::testDefaultCharStyle() +/** + * Macro to declare a new test with preloaded file + * (similar to DECLARE_SW_ROUNDTRIP_TEST) + */ +#define DECLARE_UNOAPI_TEST_FILE(TestName, filename) \ + class TestName : public SwUnoWriter \ + { \ + protected: \ + virtual OUString getTestName() override { return OUString(#TestName); } \ + \ + public: \ + CPPUNIT_TEST_SUITE(TestName); \ + CPPUNIT_TEST(loadAndTest); \ + CPPUNIT_TEST_SUITE_END(); \ + void loadAndTest() \ + { \ + load(mpTestDocumentPath, filename); \ + runTest(); \ + } \ + void runTest(); \ + }; \ + CPPUNIT_TEST_SUITE_REGISTRATION(TestName); \ + void TestName::runTest() + +/** + * Macro to declare a new test without loading any files + */ +#define DECLARE_UNOAPI_TEST(TestName) \ + class TestName : public SwUnoWriter \ + { \ + protected: \ + virtual OUString getTestName() override { return OUString(#TestName); } \ + \ + public: \ + CPPUNIT_TEST_SUITE(TestName); \ + CPPUNIT_TEST(runTest); \ + CPPUNIT_TEST_SUITE_END(); \ + void runTest(); \ + }; \ + CPPUNIT_TEST_SUITE_REGISTRATION(TestName); \ + void TestName::runTest() + +DECLARE_UNOAPI_TEST(testDefaultCharStyle) { // Create a new document, type a character, set its char style to Emphasis // and assert the style was set. @@ -57,7 +102,7 @@ void SwUnoWriter::testDefaultCharStyle() getProperty<awt::FontSlant>(xCursorProps, "CharPosture")); } -void SwUnoWriter::testGraphicDesciptorURL() +DECLARE_UNOAPI_TEST(testGraphicDesciptorURL) { loadURL("private:factory/swriter", nullptr); @@ -84,7 +129,7 @@ void SwUnoWriter::testGraphicDesciptorURL() CPPUNIT_ASSERT(xGraphic.is()); } -void SwUnoWriter::testGraphicDesciptorURLBitmap() +DECLARE_UNOAPI_TEST(testGraphicDesciptorURLBitmap) { loadURL("private:factory/swriter", nullptr); @@ -115,7 +160,166 @@ void SwUnoWriter::testGraphicDesciptorURLBitmap() CPPUNIT_ASSERT(xGraphic.is()); } -CPPUNIT_TEST_SUITE_REGISTRATION(SwUnoWriter); +static bool ensureAutoTextExistsByTitle(const Reference<XAutoTextGroup>& autoTextGroup, + const OUString& autoTextName) +{ + uno::Sequence<OUString> aTitles(autoTextGroup->getTitles()); + for (const auto& rTitle : aTitles) + { + if (rTitle == autoTextName) + return true; + } + return false; +} + +static bool ensureAutoTextExistsByName(const Reference<XAutoTextGroup>& autoTextGroup, + const OUString& autoTextName) +{ + uno::Sequence<OUString> aTitles(autoTextGroup->getElementNames()); + for (const auto& rTitle : aTitles) + { + if (rTitle == autoTextName) + return true; + } + return false; +} + +DECLARE_UNOAPI_TEST_FILE(testXAutoTextGroup, "xautotextgroup.odt") +{ + Reference<XAutoTextContainer> xAutoTextContainer + = AutoTextContainer::create(comphelper::getProcessComponentContext()); + + uno::Reference<text::XTextRange> xTextRange = getRun(getParagraph(1), 1); + + const OUString sGroupName = "TestGroup*1"; + const OUString sTextName = "TEST"; + const OUString sTextNameNew = "TESTRENAMED"; + const OUString sTextTitle = "Test Auto Text"; + const OUString sTextTitleNew = "Test Auto Text Renamed"; + + // Create new temporary group + Reference<XAutoTextGroup> xAutoTextGroup(xAutoTextContainer->insertNewByName(sGroupName), + uno::UNO_QUERY); + CPPUNIT_ASSERT_MESSAGE("AutoTextGroup was not found!", xAutoTextGroup.is()); + + // Insert new element and ensure it exists + Reference<XAutoTextEntry> xAutoTextEntry + = xAutoTextGroup->insertNewByName(sTextName, sTextTitle, xTextRange); + CPPUNIT_ASSERT_MESSAGE("AutoText was not inserted!", xAutoTextEntry.is()); + CPPUNIT_ASSERT_MESSAGE("Can't find newly created AutoText by title!", + ensureAutoTextExistsByTitle(xAutoTextGroup, sTextTitle)); + CPPUNIT_ASSERT_MESSAGE("Can't find newly created AutoText by name!", + ensureAutoTextExistsByName(xAutoTextGroup, sTextName)); + + // Insert once again the same should throw an exception + CPPUNIT_ASSERT_THROW_MESSAGE("We expect an exception on insertion of same AutoText", + xAutoTextGroup->insertNewByName(sTextName, sTextTitle, xTextRange), + container::ElementExistException); + + // Rename it & ensure everything is ok + xAutoTextGroup->renameByName(sTextName, sTextNameNew, sTextTitleNew); + CPPUNIT_ASSERT_MESSAGE("Can't find renamed AutoText by title!", + ensureAutoTextExistsByTitle(xAutoTextGroup, sTextTitleNew)); + CPPUNIT_ASSERT_MESSAGE("Can't find renamed AutoText by name!", + ensureAutoTextExistsByName(xAutoTextGroup, sTextNameNew)); + // Not found by old names + CPPUNIT_ASSERT_MESSAGE("Found AutoText by old title!", + !ensureAutoTextExistsByTitle(xAutoTextGroup, sTextTitle)); + CPPUNIT_ASSERT_MESSAGE("Found AutoText by old name!", + !ensureAutoTextExistsByName(xAutoTextGroup, sTextName)); + + // Rename not existing should throw an exception + CPPUNIT_ASSERT_THROW_MESSAGE( + "We expect an exception on renaming not-exising AutoText", + xAutoTextGroup->renameByName(sTextName, sTextNameNew, sTextTitleNew), + container::ElementExistException); + + // Remove it and ensure it does not exist + xAutoTextGroup->removeByName(sTextNameNew); + CPPUNIT_ASSERT_MESSAGE("AutoText was not removed!", + !ensureAutoTextExistsByTitle(xAutoTextGroup, sTextTitleNew)); + CPPUNIT_ASSERT_MESSAGE("AutoText was not removed!", + !ensureAutoTextExistsByName(xAutoTextGroup, sTextNameNew)); + + // Remove non-existing element should throw an exception + CPPUNIT_ASSERT_THROW_MESSAGE("We expect an exception on removing not-existing AutoText", + xAutoTextGroup->removeByName(sTextName), + container::NoSuchElementException); + + // Remove our temporary group + xAutoTextContainer->removeByName(sGroupName); +} + +DECLARE_UNOAPI_TEST(testXURI) +{ + Reference<XComponentContext> xContext(::comphelper::getProcessComponentContext()); + + // createKnown() + Reference<rdf::XURI> xURIcreateKnown(rdf::URI::createKnown(xContext, rdf::URIs::ODF_PREFIX), + UNO_SET_THROW); + CPPUNIT_ASSERT(xURIcreateKnown.is()); + CPPUNIT_ASSERT_EQUAL(OUString("http://docs.oasis-open.org/ns/office/1.2/meta/odf#"), + xURIcreateKnown->getNamespace()); + CPPUNIT_ASSERT_EQUAL(OUString("prefix"), xURIcreateKnown->getLocalName()); + CPPUNIT_ASSERT_EQUAL(OUString("http://docs.oasis-open.org/ns/office/1.2/meta/odf#prefix"), + xURIcreateKnown->getStringValue()); + + // createKnown() with invalid constant + CPPUNIT_ASSERT_THROW_MESSAGE("We expect an exception on invalid constant", + rdf::URI::createKnown(xContext, 12345), + lang::IllegalArgumentException); + + // create() + Reference<rdf::XURI> xURIcreate(rdf::URI::create(xContext, "http://example.com/url#somedata"), + UNO_SET_THROW); + CPPUNIT_ASSERT_EQUAL(OUString("http://example.com/url#"), xURIcreate->getNamespace()); + CPPUNIT_ASSERT_EQUAL(OUString("somedata"), xURIcreate->getLocalName()); + CPPUNIT_ASSERT_EQUAL(OUString("http://example.com/url#somedata"), xURIcreate->getStringValue()); + + // create() without local name splitted with "/" + Reference<rdf::XURI> xURIcreate2(rdf::URI::create(xContext, "http://example.com/url"), + UNO_SET_THROW); + CPPUNIT_ASSERT_EQUAL(OUString("http://example.com/"), xURIcreate2->getNamespace()); + CPPUNIT_ASSERT_EQUAL(OUString("url"), xURIcreate2->getLocalName()); + CPPUNIT_ASSERT_EQUAL(OUString("http://example.com/url"), xURIcreate2->getStringValue()); + + // create() without prefix + Reference<rdf::XURI> xURIcreate3(rdf::URI::create(xContext, "#somedata"), UNO_SET_THROW); + CPPUNIT_ASSERT_EQUAL(OUString("#"), xURIcreate3->getNamespace()); + CPPUNIT_ASSERT_EQUAL(OUString("somedata"), xURIcreate3->getLocalName()); + CPPUNIT_ASSERT_EQUAL(OUString("#somedata"), xURIcreate3->getStringValue()); + + // create() with invalid URI + CPPUNIT_ASSERT_THROW_MESSAGE("We expect an exception on invalid URI", + rdf::URI::create(xContext, "some junk and not URI"), + lang::IllegalArgumentException); + + // createNS() + Reference<rdf::XURI> xURIcreateNS( + rdf::URI::createNS(xContext, "http://example.com/url#", "somedata"), UNO_SET_THROW); + CPPUNIT_ASSERT_EQUAL(OUString("http://example.com/url#"), xURIcreateNS->getNamespace()); + CPPUNIT_ASSERT_EQUAL(OUString("somedata"), xURIcreateNS->getLocalName()); + CPPUNIT_ASSERT_EQUAL(OUString("http://example.com/url#somedata"), + xURIcreateNS->getStringValue()); + + // TODO: What's going on here? Is such usecase valid? + Reference<rdf::XURI> xURIcreateNS2( + rdf::URI::createNS(xContext, "http://example.com/url", "somedata"), UNO_SET_THROW); + CPPUNIT_ASSERT_EQUAL(OUString("http://example.com/"), xURIcreateNS2->getNamespace()); + CPPUNIT_ASSERT_EQUAL(OUString("urlsomedata"), xURIcreateNS2->getLocalName()); + CPPUNIT_ASSERT_EQUAL(OUString("http://example.com/urlsomedata"), + xURIcreateNS2->getStringValue()); + + // createNS() some invalid cases + CPPUNIT_ASSERT_THROW_MESSAGE("We expect an exception on invalid URI", + rdf::URI::createNS(xContext, "bla", "bla"), + lang::IllegalArgumentException); + + CPPUNIT_ASSERT_THROW_MESSAGE("We expect an exception on invalid URI", + rdf::URI::createNS(xContext, OUString(), OUString()), + lang::IllegalArgumentException); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |