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/lang/xserviceinfo.hxx>
13 #include <test/text/baseindex.hxx>
14 #include <test/text/textdocumentindex.hxx>
15 #include <test/text/xdocumentindex.hxx>
16 #include <test/text/xtextcontent.hxx>
18 #include <com/sun/star/frame/Desktop.hpp>
20 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
22 #include <com/sun/star/text/XTextDocument.hpp>
23 #include <com/sun/star/text/XTextContent.hpp>
24 #include <com/sun/star/text/XText.hpp>
25 #include <com/sun/star/text/XTextCursor.hpp>
26 #include <com/sun/star/text/XTextRange.hpp>
27 #include <com/sun/star/text/XDocumentIndex.hpp>
30 using namespace css::uno
;
35 * Test for Java API test of file com.sun.star.comp.office.SwXDocumentIndex.csv
37 class SwXDocumentIndex final
: public UnoApiTest
,
38 public apitest::XServiceInfo
,
39 public apitest::XDocumentIndex
,
40 public apitest::BaseIndex
,
41 public apitest::TextDocumentIndex
,
42 public apitest::XTextContent
,
43 public apitest::XComponent
45 Reference
<text::XTextDocument
> mxTextDocument
;
46 Reference
<text::XTextRange
> mxTextRange
;
47 Reference
<text::XTextContent
> mxTextContent
;
51 // : apitest::XServiceInfo("SwXDocumentIndex", "com.sun.star.text.BaseIndex"){};
53 : UnoApiTest(u
""_ustr
)
54 , apitest::XServiceInfo(u
"SwXDocumentIndex"_ustr
, u
"com.sun.star.text.BaseIndex"_ustr
)
58 Reference
<XInterface
> init() override
60 loadFromURL(u
"private:factory/swriter"_ustr
);
61 mxTextDocument
= Reference
<text::XTextDocument
>(mxComponent
, UNO_QUERY_THROW
);
62 Reference
<lang::XMultiServiceFactory
> xMSF(mxTextDocument
, UNO_QUERY_THROW
);
63 Reference
<text::XDocumentIndex
> xDocumentIndex(
64 xMSF
->createInstance(u
"com.sun.star.text.DocumentIndex"_ustr
), UNO_QUERY_THROW
);
66 auto xText
= getTextDocument()->getText();
67 auto xTextCursor
= xText
->createTextCursor();
68 CPPUNIT_ASSERT(xTextCursor
.is());
69 xText
->insertTextContent(xTextCursor
, xDocumentIndex
, false);
70 xTextCursor
->gotoEnd(false);
72 mxTextRange
= Reference
<text::XTextRange
>(xTextCursor
, UNO_QUERY_THROW
);
73 mxTextContent
= Reference
<text::XTextContent
>(
74 xMSF
->createInstance(u
"com.sun.star.text.DocumentIndex"_ustr
), UNO_QUERY_THROW
);
76 return xDocumentIndex
;
79 Reference
<text::XTextRange
> getTextRange() override
{ return mxTextRange
; };
80 Reference
<text::XTextContent
> getTextContent() override
{ return mxTextContent
; };
81 bool isAttachSupported() override
{ return true; }
82 Reference
<text::XTextDocument
> getTextDocument() override
{ return mxTextDocument
; }
83 void triggerDesktopTerminate() override
{}
85 CPPUNIT_TEST_SUITE(SwXDocumentIndex
);
86 CPPUNIT_TEST(testGetImplementationName
);
87 CPPUNIT_TEST(testGetSupportedServiceNames
);
88 CPPUNIT_TEST(testSupportsService
);
89 CPPUNIT_TEST(testUpdate
);
90 CPPUNIT_TEST(testBaseIndexProperties
);
91 CPPUNIT_TEST(testDocumentIndexProperties
);
92 CPPUNIT_TEST(testAttach
);
93 CPPUNIT_TEST(testGetAnchor
);
94 CPPUNIT_TEST(testAddEventListener
);
95 CPPUNIT_TEST(testRemoveEventListener
);
96 CPPUNIT_TEST_SUITE_END();
99 CPPUNIT_TEST_SUITE_REGISTRATION(SwXDocumentIndex
);
102 CPPUNIT_PLUGIN_IMPLEMENT();
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */