tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / sw / qa / api / SwXReferenceMark.cxx
blob92e547c8ab980208b1013ae88a717eb21b31f0e3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <test/unoapi_test.hxx>
11 #include <test/lang/xcomponent.hxx>
12 #include <test/text/xtextcontent.hxx>
13 #include <test/container/xnamed.hxx>
15 #include <com/sun/star/frame/Desktop.hpp>
17 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
19 #include <com/sun/star/text/XTextDocument.hpp>
20 #include <com/sun/star/text/XText.hpp>
21 #include <com/sun/star/container/XNamed.hpp>
23 using namespace css;
24 using namespace css::uno;
26 namespace
28 /**
29 * Initial tests for SwXReferenceMark.
31 class SwXReferenceMark final : public UnoApiTest,
32 public apitest::XComponent,
33 public apitest::XTextContent,
34 public apitest::XNamed
37 public:
38 SwXReferenceMark()
39 : UnoApiTest(u""_ustr)
40 , XNamed(u"SwXReferenceMark"_ustr)
44 Reference<XInterface> init() override
46 loadFromURL(u"private:factory/swriter"_ustr);
47 Reference<text::XTextDocument> xTextDocument(mxComponent, UNO_QUERY_THROW);
48 Reference<lang::XMultiServiceFactory> xMSF(mxComponent, UNO_QUERY_THROW);
50 Reference<text::XText> xText = xTextDocument->getText();
51 Reference<text::XTextCursor> xCursor = xText->createTextCursor();
53 Reference<XInterface> xRefMark
54 = xMSF->createInstance(u"com.sun.star.text.ReferenceMark"_ustr);
55 Reference<container::XNamed> xNamed(xRefMark, UNO_QUERY_THROW);
56 xNamed->setName(u"SwXReferenceMark"_ustr);
58 Reference<text::XTextContent> xTextContent(xRefMark, UNO_QUERY_THROW);
59 xText->insertTextContent(xCursor, xTextContent, false);
61 mxTextRange = Reference<text::XTextRange>(xCursor, uno::UNO_QUERY_THROW);
62 mxTextContent = Reference<text::XTextContent>(
63 xMSF->createInstance(u"com.sun.star.text.ReferenceMark"_ustr), UNO_QUERY_THROW);
65 return xRefMark;
68 Reference<text::XTextRange> getTextRange() override { return mxTextRange; };
69 Reference<text::XTextContent> getTextContent() override { return mxTextContent; };
70 bool isAttachSupported() override { return true; }
71 void triggerDesktopTerminate() override { mxDesktop->terminate(); };
73 CPPUNIT_TEST_SUITE(SwXReferenceMark);
74 CPPUNIT_TEST(testAttach);
75 CPPUNIT_TEST(testGetAnchor);
76 CPPUNIT_TEST(testDispose);
77 CPPUNIT_TEST(testAddEventListener);
78 CPPUNIT_TEST(testRemoveEventListener);
79 CPPUNIT_TEST(testGetName);
80 CPPUNIT_TEST(testSetName);
81 CPPUNIT_TEST_SUITE_END();
83 private:
84 Reference<text::XTextRange> mxTextRange;
85 Reference<text::XTextContent> mxTextContent;
88 CPPUNIT_TEST_SUITE_REGISTRATION(SwXReferenceMark);
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */