summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authoranfanite396 <dipamt1729@gmail.com>2023-06-23 22:08:31 +0530
committerTomaž Vajngerl <quikee@gmail.com>2023-07-03 15:37:12 +0200
commit5a3e0414e6f613ea417c4868faceb210274ad0f0 (patch)
tree54ffa01db5a5ce173038bd50488226fe65bb6128 /sw
parenta4e44a55f96fd6bc0be1afe9018944d3d8d3930e (diff)
Move SwXBookmark Java tests to C++
Change-Id: I6a4b62ba6815ba6d88c9ab1b59c7e30556520a1a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153534 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/CppunitTest_sw_apitests.mk1
-rw-r--r--sw/qa/api/SwXBookmark.cxx116
2 files changed, 117 insertions, 0 deletions
diff --git a/sw/CppunitTest_sw_apitests.mk b/sw/CppunitTest_sw_apitests.mk
index c19f0c4e27c1..62a12ae01e79 100644
--- a/sw/CppunitTest_sw_apitests.mk
+++ b/sw/CppunitTest_sw_apitests.mk
@@ -17,6 +17,7 @@ $(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_apitests))
$(eval $(call gb_CppunitTest_add_exception_objects,sw_apitests, \
sw/qa/api/SwXBodyText \
+ sw/qa/api/SwXBookmark \
sw/qa/api/SwXDocumentIndex \
sw/qa/api/SwXDocumentSettings \
sw/qa/api/SwXFootnoteProperties \
diff --git a/sw/qa/api/SwXBookmark.cxx b/sw/qa/api/SwXBookmark.cxx
new file mode 100644
index 000000000000..0d916cfc01de
--- /dev/null
+++ b/sw/qa/api/SwXBookmark.cxx
@@ -0,0 +1,116 @@
+/* -*- 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 <test/bootstrapfixture.hxx>
+#include <test/lang/xcomponent.hxx>
+#include <test/container/xnamed.hxx>
+#include <test/text/xtextcontent.hxx>
+#include <unotest/macros_test.hxx>
+
+#include <com/sun/star/frame/Desktop.hpp>
+
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+
+#include <com/sun/star/text/XTextDocument.hpp>
+#include <com/sun/star/text/XText.hpp>
+
+#include <comphelper/processfactory.hxx>
+
+using namespace css;
+using namespace css::uno;
+
+namespace
+{
+/**
+ * Initial tests for SwXBookmark.
+ */
+class SwXBookmark final : public test::BootstrapFixture,
+ public unotest::MacrosTest,
+ public apitest::XComponent,
+ public apitest::XNamed,
+ public apitest::XTextContent
+{
+public:
+ SwXBookmark();
+ virtual void setUp() override;
+ void tearDown() override;
+
+ Reference<XInterface> init() override;
+ Reference<text::XTextRange> getTextRange() override;
+ Reference<text::XTextContent> getTextContent() override;
+ bool isAttachSupported() override { return true; }
+ Reference<text::XTextDocument> getTextDocument() { return mxTextDocument; }
+ void triggerDesktopTerminate() override { mxDesktop->terminate(); }
+
+ CPPUNIT_TEST_SUITE(SwXBookmark);
+ CPPUNIT_TEST(testDispose);
+ CPPUNIT_TEST(testAddEventListener);
+ CPPUNIT_TEST(testRemoveEventListener);
+ CPPUNIT_TEST(testGetName);
+ CPPUNIT_TEST(testSetName);
+ CPPUNIT_TEST(testAttach);
+ CPPUNIT_TEST(testGetAnchor);
+ CPPUNIT_TEST_SUITE_END();
+
+private:
+ Reference<text::XTextDocument> mxTextDocument;
+ Reference<text::XTextRange> mxTextRange;
+ Reference<text::XTextContent> mxTextContent;
+};
+
+SwXBookmark::SwXBookmark()
+ : XNamed("Bookmark")
+{
+}
+
+void SwXBookmark::setUp()
+{
+ test::BootstrapFixture::setUp();
+
+ mxDesktop.set(frame::Desktop::create(mxComponentContext));
+ mxTextDocument = Reference<text::XTextDocument>(
+ loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"),
+ UNO_QUERY_THROW);
+ CPPUNIT_ASSERT(mxTextDocument.is());
+}
+
+void SwXBookmark::tearDown()
+{
+ if (mxTextDocument.is())
+ mxTextDocument->dispose();
+
+ test::BootstrapFixture::tearDown();
+}
+
+Reference<XInterface> SwXBookmark::init()
+{
+ Reference<lang::XMultiServiceFactory> xMSF(mxTextDocument, UNO_QUERY_THROW);
+
+ Reference<text::XText> xText = getTextDocument()->getText();
+ Reference<text::XTextCursor> xCursor = xText->createTextCursor();
+
+ Reference<text::XTextContent> xBookmark(xMSF->createInstance("com.sun.star.text.Bookmark"),
+ UNO_QUERY_THROW);
+
+ xText->insertTextContent(xCursor, xBookmark, false);
+ mxTextRange = Reference<text::XTextRange>(xCursor, UNO_QUERY_THROW);
+ mxTextContent = Reference<text::XTextContent>(
+ xMSF->createInstance("com.sun.star.text.Bookmark"), UNO_QUERY_THROW);
+
+ return Reference<XInterface>(xBookmark, UNO_QUERY_THROW);
+}
+
+Reference<text::XTextRange> SwXBookmark::getTextRange() { return mxTextRange; }
+
+Reference<text::XTextContent> SwXBookmark::getTextContent() { return mxTextContent; }
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SwXBookmark);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */