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/bootstrapfixture.hxx>
11 #include <test/lang/xserviceinfo.hxx>
12 #include <test/lang/xcomponent.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>
17 #include <unotest/macros_test.hxx>
19 #include <com/sun/star/frame/Desktop.hpp>
21 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
23 #include <com/sun/star/text/XTextDocument.hpp>
24 #include <com/sun/star/text/XTextContent.hpp>
25 #include <com/sun/star/text/XText.hpp>
26 #include <com/sun/star/text/XTextCursor.hpp>
27 #include <com/sun/star/text/XTextRange.hpp>
28 #include <com/sun/star/text/XDocumentIndex.hpp>
35 * Test for Java API test of file com.sun.star.comp.office.SwXDocumentIndex.csv
37 class SwXDocumentIndex final
: public test::BootstrapFixture
,
38 public unotest::MacrosTest
,
39 public apitest::XDocumentIndex
,
40 public apitest::BaseIndex
,
41 public apitest::TextDocumentIndex
,
42 public apitest::XTextContent
,
43 public apitest::XServiceInfo
,
44 public apitest::XComponent
46 uno::Reference
<text::XTextDocument
> mxTextDocument
;
47 uno::Reference
<text::XTextRange
> mxTextRange
;
48 uno::Reference
<text::XTextContent
> mxTextContent
;
51 virtual void setUp() override
;
52 virtual void tearDown() override
;
55 : apitest::XServiceInfo("SwXDocumentIndex", "com.sun.star.text.BaseIndex"){};
56 uno::Reference
<uno::XInterface
> init() override
;
57 uno::Reference
<text::XTextRange
> getTextRange() override
;
58 uno::Reference
<text::XTextContent
> getTextContent() override
;
59 bool isAttachSupported() override
{ return true; }
60 uno::Reference
<text::XTextDocument
> getTextDocument() override
{ return mxTextDocument
; }
61 void triggerDesktopTerminate() override
{}
63 CPPUNIT_TEST_SUITE(SwXDocumentIndex
);
64 CPPUNIT_TEST(testGetImplementationName
);
65 CPPUNIT_TEST(testGetSupportedServiceNames
);
66 CPPUNIT_TEST(testSupportsService
);
67 CPPUNIT_TEST(testUpdate
);
68 CPPUNIT_TEST(testBaseIndexProperties
);
69 CPPUNIT_TEST(testDocumentIndexProperties
);
70 CPPUNIT_TEST(testAttach
);
71 CPPUNIT_TEST(testGetAnchor
);
72 CPPUNIT_TEST(testAddEventListener
);
73 CPPUNIT_TEST(testRemoveEventListener
);
74 CPPUNIT_TEST_SUITE_END();
77 void SwXDocumentIndex::setUp()
79 test::BootstrapFixture::setUp();
81 mxDesktop
.set(frame::Desktop::create(mxComponentContext
));
82 mxTextDocument
= uno::Reference
<text::XTextDocument
>(
83 loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"),
84 uno::UNO_QUERY_THROW
);
85 CPPUNIT_ASSERT(mxTextDocument
.is());
88 void SwXDocumentIndex::tearDown()
90 if (mxTextDocument
.is())
91 mxTextDocument
->dispose();
93 test::BootstrapFixture::tearDown();
96 uno::Reference
<uno::XInterface
> SwXDocumentIndex::init()
98 uno::Reference
<lang::XMultiServiceFactory
> xMSF(mxTextDocument
, uno::UNO_QUERY_THROW
);
99 uno::Reference
<text::XDocumentIndex
> xDocumentIndex(
100 xMSF
->createInstance("com.sun.star.text.DocumentIndex"), uno::UNO_QUERY_THROW
);
101 auto xText
= getTextDocument()->getText();
102 auto xTextCursor
= xText
->createTextCursor();
103 CPPUNIT_ASSERT(xTextCursor
.is());
104 xText
->insertTextContent(xTextCursor
, xDocumentIndex
, false);
105 xTextCursor
->gotoEnd(false);
106 mxTextRange
= uno::Reference
<text::XTextRange
>(xTextCursor
, uno::UNO_QUERY_THROW
);
107 mxTextContent
= uno::Reference
<text::XTextContent
>(
108 xMSF
->createInstance("com.sun.star.text.DocumentIndex"), uno::UNO_QUERY_THROW
);
109 return xDocumentIndex
;
112 uno::Reference
<text::XTextRange
> SwXDocumentIndex::getTextRange() { return mxTextRange
; }
114 uno::Reference
<text::XTextContent
> SwXDocumentIndex::getTextContent() { return mxTextContent
; }
116 CPPUNIT_TEST_SUITE_REGISTRATION(SwXDocumentIndex
);
119 CPPUNIT_PLUGIN_IMPLEMENT();
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */