[Libreoffice-commits] core.git: sw/CppunitTest_sw_apitests.mk sw/Module_sw.mk sw/qa

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Thu May 10 01:42:28 UTC 2018


 sw/CppunitTest_sw_apitests.mk    |  107 +++++++++++++++++++++++++
 sw/Module_sw.mk                  |    1 
 sw/qa/api/ApiTestBase.hxx        |   30 +++++++
 sw/qa/api/BaseIndexTest.hxx      |  164 +++++++++++++++++++++++++++++++++++++++
 sw/qa/api/DocumentIndexTest.hxx  |   49 +++++++++++
 sw/qa/api/SwXDocumentIndex.cxx   |  125 +++++++++++++++++++++++++++++
 sw/qa/api/XDocumentIndexTest.hxx |   97 +++++++++++++++++++++++
 sw/qa/api/XTextContentTest.hxx   |   62 ++++++++++++++
 8 files changed, 635 insertions(+)

New commits:
commit fe93b771602be86a748ca4e0337a977d7b171d24
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Tue May 8 23:42:24 2018 +0900

    Convert SwXDocumentIndex API qadevOOo tests (incomplete)
    
    Somebody has to start converting this for Writer...
    
    This conversion is still incomplete, but this sets the base of
    for the conversion of qadevOOo to from Java.
    
    Change-Id: I2cadeaaf58fe334a5e1f29dcb8e59c7481a4550d
    Reviewed-on: https://gerrit.libreoffice.org/53989
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/sw/CppunitTest_sw_apitests.mk b/sw/CppunitTest_sw_apitests.mk
new file mode 100644
index 000000000000..fa0fc26e7d20
--- /dev/null
+++ b/sw/CppunitTest_sw_apitests.mk
@@ -0,0 +1,107 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,sw_apitests))
+
+$(eval $(call gb_CppunitTest_use_external,sw_apitests,boost_headers))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sw_apitests, \
+    sw/qa/api/SwXDocumentIndex \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sw_apitests, \
+    basegfx \
+    comphelper \
+    cppu \
+    cppuhelper \
+    drawinglayer \
+    editeng \
+    for \
+    forui \
+    i18nlangtag \
+    msfilter \
+    oox \
+    sal \
+    salhelper \
+    sax \
+    sb \
+    sw \
+    sfx \
+    sot \
+    svl \
+    svt \
+    svx \
+    svxcore \
+    test \
+    tl \
+    tk \
+    ucbhelper \
+    unotest \
+    utl \
+    vbahelper \
+    vcl \
+    xo \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sw_apitests,\
+    -I$(SRCDIR)/sw/inc \
+    $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sw_apitests,\
+    offapi \
+    udkapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sw_apitests))
+$(eval $(call gb_CppunitTest_use_vcl,sw_apitests))
+$(eval $(call gb_CppunitTest_use_configuration,sw_apitests))
+
+$(eval $(call gb_CppunitTest_use_components,sw_apitests,\
+	basic/util/sb \
+	embeddedobj/util/embobj \
+	comphelper/util/comphelp \
+	configmgr/source/configmgr \
+	dbaccess/util/dba \
+	filter/source/config/cache/filterconfig1 \
+	filter/source/storagefilterdetect/storagefd \
+	forms/util/frm \
+	framework/util/fwk \
+	i18npool/util/i18npool \
+	i18npool/source/search/i18nsearch \
+	oox/util/oox \
+	package/source/xstor/xstor \
+	package/util/package2 \
+	sax/source/expatwrap/expwrap \
+	scripting/source/basprov/basprov \
+	scripting/util/scriptframe \
+	sfx2/util/sfx \
+	sot/util/sot \
+	svl/source/fsstor/fsstorage \
+	svl/util/svl \
+	svtools/util/svt \
+	svx/util/svx \
+	sw/util/msword \
+	sw/util/sw \
+	sw/util/swd \
+	sw/util/vbaswobj \
+	toolkit/util/tk \
+	ucb/source/core/ucb1 \
+	ucb/source/ucp/file/ucpfile1 \
+	ucb/source/ucp/tdoc/ucptdoc1 \
+	unotools/util/utl \
+	unoxml/source/rdf/unordf \
+	unoxml/source/service/unoxml \
+	uui/util/uui \
+	xmloff/util/xo \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index 87367d05de5c..1e56264ac8de 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -93,6 +93,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
     CppunitTest_sw_mailmerge \
     CppunitTest_sw_globalfilter \
     CppunitTest_sw_accessible_relation_set \
+    CppunitTest_sw_apitests \
 ))
 
 ifneq ($(ENABLE_HEADLESS),TRUE)
diff --git a/sw/qa/api/ApiTestBase.hxx b/sw/qa/api/ApiTestBase.hxx
new file mode 100644
index 000000000000..76871111ff3f
--- /dev/null
+++ b/sw/qa/api/ApiTestBase.hxx
@@ -0,0 +1,30 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_SW_QA_CORE_APITESTBASE_HXX
+#define INCLUDED_SW_QA_CORE_APITESTBASE_HXX
+
+#include <com/sun/star/uno/XInterface.hpp>
+
+#include <unordered_map>
+
+namespace apitest
+{
+class ApiTestBase
+{
+protected:
+    virtual ~ApiTestBase() {}
+
+    virtual std::unordered_map<OUString, css::uno::Reference<css::uno::XInterface>> init() = 0;
+};
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/api/BaseIndexTest.hxx b/sw/qa/api/BaseIndexTest.hxx
new file mode 100644
index 000000000000..997f91aa948f
--- /dev/null
+++ b/sw/qa/api/BaseIndexTest.hxx
@@ -0,0 +1,164 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_SW_QA_API_BASEINDEXTEST_HXX
+#define INCLUDED_SW_QA_API_BASEINDEXTEST_HXX
+
+#include "ApiTestBase.hxx"
+
+#include <cppunit/TestAssert.h>
+#include <test/unoapi_property_testers.hxx>
+
+#include <com/sun/star/beans/XPropertySet.hpp>
+
+#include <com/sun/star/text/XTextColumns.hpp>
+#include <com/sun/star/text/XTextSection.hpp>
+#include <com/sun/star/graphic/XGraphic.hpp>
+
+#include <vcl/BitmapTools.hxx>
+#include <vcl/graph.hxx>
+#include <vcl/pngwrite.hxx>
+#include <unotools/tempfile.hxx>
+#include <tools/stream.hxx>
+
+namespace apitest
+{
+namespace
+{
+BitmapEx createExampleBitmap()
+{
+    vcl::bitmap::RawBitmap aRawBitmap(Size(4, 4), 24);
+    aRawBitmap.SetPixel(0, 0, COL_LIGHTBLUE);
+    aRawBitmap.SetPixel(0, 1, COL_LIGHTGREEN);
+    aRawBitmap.SetPixel(1, 0, COL_LIGHTRED);
+    aRawBitmap.SetPixel(1, 1, COL_LIGHTMAGENTA);
+    return vcl::bitmap::CreateFromData(std::move(aRawBitmap));
+}
+
+void writerFileWithBitmap(OUString const& rURL)
+{
+    BitmapEx aBitmapEx = createExampleBitmap();
+    SvFileStream aFileStream(rURL, StreamMode::READ | StreamMode::WRITE);
+    vcl::PNGWriter aWriter(aBitmapEx);
+    aWriter.Write(aFileStream);
+    aFileStream.Seek(STREAM_SEEK_TO_BEGIN);
+    aFileStream.Close();
+}
+
+} // end anonymous namespace
+
+class BaseIndexTest : public ApiTestBase
+{
+public:
+    void testBaseIndexProperties()
+    {
+        auto map = init();
+
+        css::uno::Reference<css::beans::XPropertySet> xBaseIndex(map["text::BaseIndex"],
+                                                                 css::uno::UNO_QUERY_THROW);
+        testStringProperty(xBaseIndex, "Title", "Value");
+        testBooleanProperty(xBaseIndex, "IsProtected");
+
+        testStringProperty(xBaseIndex, "ParaStyleHeading", "Value");
+        testStringProperty(xBaseIndex, "ParaStyleLevel1", "Value");
+        testStringOptionalProperty(xBaseIndex, "ParaStyleLevel2");
+        testStringOptionalProperty(xBaseIndex, "ParaStyleLevel3");
+        testStringOptionalProperty(xBaseIndex, "ParaStyleLevel4");
+        testStringOptionalProperty(xBaseIndex, "ParaStyleLevel5");
+        testStringOptionalProperty(xBaseIndex, "ParaStyleLevel6");
+        testStringOptionalProperty(xBaseIndex, "ParaStyleLevel7");
+        testStringOptionalProperty(xBaseIndex, "ParaStyleLevel8");
+        testStringOptionalProperty(xBaseIndex, "ParaStyleLevel9");
+        testStringOptionalProperty(xBaseIndex, "ParaStyleLevel10");
+        testStringOptionalProperty(xBaseIndex, "ParaStyleSeparator");
+
+        //      [property] XTextColumns TextColumns;
+        {
+            OUString name = "TextColumns";
+
+            css::uno::Reference<css::text::XTextColumns> xGetTextColumns;
+            CPPUNIT_ASSERT(xBaseIndex->getPropertyValue(name) >>= xGetTextColumns);
+
+            xGetTextColumns->setColumnCount(xGetTextColumns->getColumnCount() + 1);
+            xBaseIndex->setPropertyValue(name, css::uno::makeAny(xGetTextColumns));
+
+            css::uno::Reference<css::text::XTextColumns> xSetTextColumns;
+            CPPUNIT_ASSERT(xBaseIndex->getPropertyValue(name) >>= xSetTextColumns);
+
+            //CPPUNIT_ASSERT_EQUAL(xGetTextColumns->getColumnCount(), xSetTextColumns->getColumnCount());
+        }
+
+        //      [property] com::sun::star::graphic::XGraphic BackGraphic;
+        //      [property] string BackGraphicURL;
+        {
+            OUString name = "BackGraphicURL";
+            bool bOK = false;
+            try
+            {
+                xBaseIndex->getPropertyValue(name);
+            }
+            catch (css::uno::RuntimeException const& /*ex*/)
+            {
+                bOK = true;
+            }
+            // BackGraphicURL is "set-only" attribute
+            CPPUNIT_ASSERT_MESSAGE("Expected RuntimeException wasn't thrown", bOK);
+
+            utl::TempFile aTempFile;
+            aTempFile.EnableKillingFile();
+            writerFileWithBitmap(aTempFile.GetURL());
+
+            css::uno::Reference<css::graphic::XGraphic> xGraphic;
+            CPPUNIT_ASSERT(xBaseIndex->getPropertyValue("BackGraphic") >>= xGraphic);
+            CPPUNIT_ASSERT(!xGraphic.is());
+
+            xBaseIndex->setPropertyValue(name, css::uno::makeAny(aTempFile.GetURL()));
+
+            CPPUNIT_ASSERT(xBaseIndex->getPropertyValue("BackGraphic") >>= xGraphic);
+            CPPUNIT_ASSERT(xGraphic.is());
+        }
+
+        testStringProperty(xBaseIndex, "BackGraphicFilter", "Value");
+
+        //      [property] com::sun::star::style::GraphicLocation BackGraphicLocation;
+
+        testColorProperty(xBaseIndex, "BackColor");
+        testBooleanProperty(xBaseIndex, "BackTransparent");
+
+        //      [optional, property] com::sun::star::container::XIndexReplace LevelFormat;
+
+        testBooleanOptionalProperty(xBaseIndex, "CreateFromChapter");
+
+        //      [property] com::sun::star::text::XTextSection ContentSection;
+        {
+            OUString name = "ContentSection";
+
+            css::uno::Reference<css::text::XTextSection> xGetTextSection;
+            CPPUNIT_ASSERT_MESSAGE(name.toUtf8().getStr(),
+                                   xBaseIndex->getPropertyValue(name) >>= xGetTextSection);
+            CPPUNIT_ASSERT_EQUAL_MESSAGE(name.toUtf8().getStr(), OUString(""),
+                                         xGetTextSection->getAnchor()->getString());
+        }
+
+        //      [property] com::sun::star::text::XTextSection HeaderSection;
+        {
+            OUString name = "HeaderSection";
+
+            css::uno::Reference<css::text::XTextSection> xGetTextSection;
+            if (xBaseIndex->getPropertyValue(name).hasValue())
+                CPPUNIT_ASSERT_MESSAGE(name.toUtf8().getStr(),
+                                       xBaseIndex->getPropertyValue(name) >>= xGetTextSection);
+        }
+    }
+};
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/api/DocumentIndexTest.hxx b/sw/qa/api/DocumentIndexTest.hxx
new file mode 100644
index 000000000000..0757c1dd492f
--- /dev/null
+++ b/sw/qa/api/DocumentIndexTest.hxx
@@ -0,0 +1,49 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_SW_QA_API_DOCUMENTINDEXTEST_HXX
+#define INCLUDED_SW_QA_API_DOCUMENTINDEXTEST_HXX
+
+#include "ApiTestBase.hxx"
+
+#include <cppunit/TestAssert.h>
+#include <test/unoapi_property_testers.hxx>
+
+#include <com/sun/star/beans/XPropertySet.hpp>
+
+namespace apitest
+{
+class DocumentIndexTest : public ApiTestBase
+{
+public:
+    void testDocumentIndexProperties()
+    {
+        auto map = init();
+
+        css::uno::Reference<css::beans::XPropertySet> xDocumnetIndex(map["text::DocumentIndex"],
+                                                                     css::uno::UNO_QUERY_THROW);
+
+        testBooleanProperty(xDocumnetIndex, "UseAlphabeticalSeparators");
+        testBooleanProperty(xDocumnetIndex, "UseKeyAsEntry");
+        testBooleanProperty(xDocumnetIndex, "UseCombinedEntries");
+        testBooleanProperty(xDocumnetIndex, "IsCaseSensitive");
+        testBooleanProperty(xDocumnetIndex, "UsePP");
+        testBooleanProperty(xDocumnetIndex, "UseDash");
+        testBooleanProperty(xDocumnetIndex, "UseUpperCase");
+        testStringOptionalProperty(xDocumnetIndex, "MainEntryCharacterStyleName");
+        //      [readonly, property] sequence <com::sun::star::text::XDocumentIndexMark> DocumentIndexMarks;
+        //      [property] com::sun::star::lang::Locale  Locale;
+        testStringProperty(xDocumnetIndex, "SortAlgorithm", "Value");
+    }
+};
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/api/SwXDocumentIndex.cxx b/sw/qa/api/SwXDocumentIndex.cxx
new file mode 100644
index 000000000000..297b3a5899d8
--- /dev/null
+++ b/sw/qa/api/SwXDocumentIndex.cxx
@@ -0,0 +1,125 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "BaseIndexTest.hxx"
+#include "DocumentIndexTest.hxx"
+#include "XDocumentIndexTest.hxx"
+#include "XTextContentTest.hxx"
+
+#include <test/bootstrapfixture.hxx>
+#include <unotest/macros_test.hxx>
+
+#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/frame/DispatchHelper.hpp>
+
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+
+#include <com/sun/star/text/XTextDocument.hpp>
+#include <com/sun/star/text/XTextContent.hpp>
+#include <com/sun/star/text/XText.hpp>
+#include <com/sun/star/text/XTextCursor.hpp>
+#include <com/sun/star/text/XDocumentIndex.hpp>
+
+#include <comphelper/processfactory.hxx>
+#include <comphelper/propertysequence.hxx>
+
+using namespace css;
+
+namespace
+{
+/**
+ * Test for Java API test of file com.sun.star.comp.office.SwXDocumentIndex.csv
+ */
+class SwXDocumentIndexTest : public test::BootstrapFixture,
+                             public unotest::MacrosTest,
+                             public apitest::XDocumentIndexTest,
+                             public apitest::BaseIndexTest,
+                             public apitest::DocumentIndexTest,
+                             public apitest::XTextContentTest
+{
+    uno::Reference<uno::XComponentContext> mxComponentContext;
+    uno::Reference<lang::XComponent> mxComponent;
+
+public:
+    virtual void setUp() override;
+    virtual void tearDown() override;
+
+    std::unordered_map<OUString, uno::Reference<uno::XInterface>> init() override;
+
+    CPPUNIT_TEST_SUITE(SwXDocumentIndexTest);
+    CPPUNIT_TEST(testGetServiceName);
+    CPPUNIT_TEST(testUpdate);
+    CPPUNIT_TEST(testBaseIndexProperties);
+    CPPUNIT_TEST(testDocumentIndexProperties);
+    CPPUNIT_TEST(testAttach);
+    CPPUNIT_TEST(testGetAnchor);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+void SwXDocumentIndexTest::setUp()
+{
+    test::BootstrapFixture::setUp();
+
+    mxComponentContext.set(comphelper::getComponentContext(getMultiServiceFactory()));
+    mxDesktop.set(frame::Desktop::create(mxComponentContext));
+}
+
+void SwXDocumentIndexTest::tearDown()
+{
+    if (mxComponent.is())
+        mxComponent->dispose();
+
+    test::BootstrapFixture::tearDown();
+}
+
+std::unordered_map<OUString, uno::Reference<uno::XInterface>> SwXDocumentIndexTest::init()
+{
+    std::unordered_map<OUString, uno::Reference<uno::XInterface>> map;
+
+    mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
+    CPPUNIT_ASSERT(mxComponent.is());
+
+    uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY_THROW);
+    uno::Reference<lang::XMultiServiceFactory> xFactory(xTextDocument, uno::UNO_QUERY_THROW);
+
+    uno::Reference<text::XDocumentIndex> xDocumentIndex(
+        xFactory->createInstance("com.sun.star.text.DocumentIndex"), uno::UNO_QUERY_THROW);
+
+    uno::Reference<text::XTextContent> xTextContent(xDocumentIndex, uno::UNO_QUERY_THROW);
+
+    uno::Reference<text::XText> xText = xTextDocument->getText();
+    uno::Reference<text::XTextCursor> xTextCursor = xText->createTextCursor();
+    CPPUNIT_ASSERT(xTextCursor.is());
+    xText->insertTextContent(xTextCursor, xTextContent, false);
+    xTextCursor->gotoEnd(false);
+
+    uno::Reference<text::XDocumentIndex> xDocumentIndexInstance(
+        xFactory->createInstance("com.sun.star.text.DocumentIndex"), uno::UNO_QUERY_THROW);
+
+    // XDocumentIndexTest
+    map["text::XDocumentIndex"] = xDocumentIndex;
+    map["text::XTextDocument"] = xTextDocument;
+    // BaseIndexTest
+    map["text::BaseIndex"] = xDocumentIndex;
+    // DocumentIndex
+    map["text::DocumentIndex"] = xDocumentIndex;
+    // XTextContentTest
+    map["text::XTextRange"] = xTextCursor;
+    map["text::XTextContent"] = xDocumentIndex;
+    map["text::XTextContent#Instance"] = xDocumentIndexInstance;
+
+    return map;
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SwXDocumentIndexTest);
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/api/XDocumentIndexTest.hxx b/sw/qa/api/XDocumentIndexTest.hxx
new file mode 100644
index 000000000000..65c677864563
--- /dev/null
+++ b/sw/qa/api/XDocumentIndexTest.hxx
@@ -0,0 +1,97 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_SW_QA_API_XDOCUMENTINDEXTEST_HXX
+#define INCLUDED_SW_QA_API_XDOCUMENTINDEXTEST_HXX
+
+#include "ApiTestBase.hxx"
+
+#include <cppunit/TestAssert.h>
+
+#include <test/unoapi_property_testers.hxx>
+
+#include <com/sun/star/text/XTextDocument.hpp>
+#include <com/sun/star/text/XTextContent.hpp>
+#include <com/sun/star/text/XText.hpp>
+#include <com/sun/star/text/XDocumentIndex.hpp>
+
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+
+namespace apitest
+{
+class XDocumentIndexTest : public ApiTestBase
+{
+public:
+    /**
+     * Test calls the method. <p>
+     * Has <b> OK </b> status if the returned service name
+     * is equal to 'com.sun.star.text.DocumentIndex'.
+     */
+    void testGetServiceName()
+    {
+        auto inputMap = init();
+
+        css::uno::Reference<css::text::XDocumentIndex> xDocumentIndex(
+            inputMap["text::XDocumentIndex"], css::uno::UNO_QUERY_THROW);
+        CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.text.DocumentIndex"),
+                             xDocumentIndex->getServiceName());
+    }
+
+    /**
+     * Gets the document from relation and insert a new index mark.
+     * Then it stores the text content of document index before
+     * update and after.<p>
+     *
+     * Has <b> OK </b> status if index content is changed and
+     * new index contains index mark inserted. <p>
+     */
+    void testUpdate()
+    {
+        auto inputMap = init();
+
+        css::uno::Reference<css::text::XDocumentIndex> xDocumentIndex(
+            inputMap["text::XDocumentIndex"], css::uno::UNO_QUERY_THROW);
+        css::uno::Reference<css::text::XTextDocument> xTextDocument(inputMap["text::XTextDocument"],
+                                                                    css::uno::UNO_QUERY_THROW);
+
+        bool bOK = true;
+        try
+        {
+            css::uno::Reference<css::text::XText> xText = xTextDocument->getText();
+            css::uno::Reference<css::text::XTextRange> xTextRange = xText->getEnd();
+            xTextRange->setString("IndexMark");
+            css::uno::Reference<css::lang::XMultiServiceFactory> xFactory(
+                xTextDocument, css::uno::UNO_QUERY_THROW);
+            css::uno::Reference<css::text::XTextContent> xTextContentMark(
+                xFactory->createInstance("com.sun.star.text.DocumentIndexMark"),
+                css::uno::UNO_QUERY_THROW);
+            xText->insertTextContent(xTextRange, xTextContentMark, true);
+        }
+        catch (css::uno::Exception /*exception*/)
+        {
+            bOK = false;
+        }
+
+        CPPUNIT_ASSERT_MESSAGE("Couldn't create the document index mark", bOK);
+
+        OUString sContentBefore = xDocumentIndex->getAnchor()->getString();
+        xDocumentIndex->update();
+        OUString sContentAfter = xDocumentIndex->getAnchor()->getString();
+
+        CPPUNIT_ASSERT_MESSAGE("Before and after shouldn't be equal",
+                               sContentBefore != sContentAfter);
+        CPPUNIT_ASSERT_MESSAGE("Content after should contain string 'IndexMark'",
+                               sContentAfter.indexOf("IndexMark") >= 0);
+    }
+};
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/api/XTextContentTest.hxx b/sw/qa/api/XTextContentTest.hxx
new file mode 100644
index 000000000000..4cb52d29db9b
--- /dev/null
+++ b/sw/qa/api/XTextContentTest.hxx
@@ -0,0 +1,62 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_SW_QA_API_XTEXTCONTENTTEST_HXX
+#define INCLUDED_SW_QA_API_XTEXTCONTENTTEST_HXX
+
+#include "ApiTestBase.hxx"
+
+#include <cppunit/TestAssert.h>
+
+#include <test/unoapi_property_testers.hxx>
+
+#include <com/sun/star/text/XTextContent.hpp>
+#include <com/sun/star/text/XTextRange.hpp>
+
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+
+namespace apitest
+{
+class XTextContentTest : public ApiTestBase
+{
+public:
+    /**
+     * Tries to attach the text content to the test range
+     * gotten with getAnchor(). If relations are found
+     * then they are used for testing. <p>
+     *
+     * The test is OK if the method works without error.
+     */
+    void testAttach()
+    {
+        auto map = init();
+        css::uno::Reference<css::text::XTextContent> xTextContent(
+            map["text::XTextContent#Instance"], css::uno::UNO_QUERY_THROW);
+        css::uno::Reference<css::text::XTextRange> xTextRange(map["text::XTextRange"],
+                                                              css::uno::UNO_QUERY_THROW);
+
+        if (xTextContent.is())
+        {
+            xTextContent->attach(xTextRange);
+        }
+    }
+
+    void testGetAnchor()
+    {
+        auto map = init();
+        css::uno::Reference<css::text::XTextContent> xTextContent(map["text::XTextContent"],
+                                                                  css::uno::UNO_QUERY_THROW);
+        CPPUNIT_ASSERT_EQUAL(OUString(""), xTextContent->getAnchor()->getString());
+    }
+};
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list