1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <test/unoapi_test.hxx>
11 #include <test/lang/xcomponent.hxx>
12 #include <test/container/xnamed.hxx>
13 #include <test/text/xtextcontent.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>
23 using namespace css::uno
;
28 * Initial tests for SwXBookmark.
30 class SwXBookmark final
: public UnoApiTest
,
31 public apitest::XComponent
,
32 public apitest::XNamed
,
33 public apitest::XTextContent
37 : UnoApiTest(u
""_ustr
)
38 , XNamed(u
"Bookmark"_ustr
)
42 Reference
<XInterface
> init() override
44 loadFromURL(u
"private:factory/swriter"_ustr
);
45 Reference
<text::XTextDocument
> xTextDocument(mxComponent
, UNO_QUERY_THROW
);
46 Reference
<lang::XMultiServiceFactory
> xMSF(mxComponent
, UNO_QUERY_THROW
);
48 Reference
<text::XText
> xText
= xTextDocument
->getText();
49 Reference
<text::XTextCursor
> xCursor
= xText
->createTextCursor();
51 Reference
<text::XTextContent
> xBookmark(
52 xMSF
->createInstance(u
"com.sun.star.text.Bookmark"_ustr
), UNO_QUERY_THROW
);
54 xText
->insertTextContent(xCursor
, xBookmark
, false);
55 mxTextRange
= Reference
<text::XTextRange
>(xCursor
, UNO_QUERY_THROW
);
56 mxTextContent
= Reference
<text::XTextContent
>(
57 xMSF
->createInstance(u
"com.sun.star.text.Bookmark"_ustr
), UNO_QUERY_THROW
);
59 return Reference
<XInterface
>(xBookmark
, UNO_QUERY_THROW
);
62 Reference
<text::XTextRange
> getTextRange() override
{ return mxTextRange
; };
63 Reference
<text::XTextContent
> getTextContent() override
{ return mxTextContent
; };
64 bool isAttachSupported() override
{ return true; }
65 void triggerDesktopTerminate() override
{ mxDesktop
->terminate(); }
67 CPPUNIT_TEST_SUITE(SwXBookmark
);
68 CPPUNIT_TEST(testDispose
);
69 CPPUNIT_TEST(testAddEventListener
);
70 CPPUNIT_TEST(testRemoveEventListener
);
71 CPPUNIT_TEST(testGetName
);
72 CPPUNIT_TEST(testSetName
);
73 CPPUNIT_TEST(testAttach
);
74 CPPUNIT_TEST(testGetAnchor
);
75 CPPUNIT_TEST_SUITE_END();
78 Reference
<text::XTextRange
> mxTextRange
;
79 Reference
<text::XTextContent
> mxTextContent
;
82 CPPUNIT_TEST_SUITE_REGISTRATION(SwXBookmark
);
85 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */