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 "BaseIndexTest.hxx"
11 #include "DocumentIndexTest.hxx"
12 #include "XDocumentIndexTest.hxx"
13 #include "XTextContentTest.hxx"
15 #include <test/bootstrapfixture.hxx>
16 #include <unotest/macros_test.hxx>
18 #include <com/sun/star/frame/Desktop.hpp>
19 #include <com/sun/star/frame/DispatchHelper.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/XDocumentIndex.hpp>
29 #include <comphelper/processfactory.hxx>
30 #include <comphelper/propertysequence.hxx>
37 * Test for Java API test of file com.sun.star.comp.office.SwXDocumentIndex.csv
39 class SwXDocumentIndexTest
: public test::BootstrapFixture
,
40 public unotest::MacrosTest
,
41 public apitest::XDocumentIndexTest
,
42 public apitest::BaseIndexTest
,
43 public apitest::DocumentIndexTest
,
44 public apitest::XTextContentTest
46 uno::Reference
<uno::XComponentContext
> mxComponentContext
;
47 uno::Reference
<lang::XComponent
> mxComponent
;
50 virtual void setUp() override
;
51 virtual void tearDown() override
;
53 std::unordered_map
<OUString
, uno::Reference
<uno::XInterface
>> init() override
;
55 CPPUNIT_TEST_SUITE(SwXDocumentIndexTest
);
56 CPPUNIT_TEST(testGetServiceName
);
57 CPPUNIT_TEST(testUpdate
);
58 CPPUNIT_TEST(testBaseIndexProperties
);
59 CPPUNIT_TEST(testDocumentIndexProperties
);
60 CPPUNIT_TEST(testAttach
);
61 CPPUNIT_TEST(testGetAnchor
);
62 CPPUNIT_TEST_SUITE_END();
65 void SwXDocumentIndexTest::setUp()
67 test::BootstrapFixture::setUp();
69 mxComponentContext
.set(comphelper::getComponentContext(getMultiServiceFactory()));
70 mxDesktop
.set(frame::Desktop::create(mxComponentContext
));
73 void SwXDocumentIndexTest::tearDown()
76 mxComponent
->dispose();
78 test::BootstrapFixture::tearDown();
81 std::unordered_map
<OUString
, uno::Reference
<uno::XInterface
>> SwXDocumentIndexTest::init()
83 std::unordered_map
<OUString
, uno::Reference
<uno::XInterface
>> map
;
85 mxComponent
= loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
86 CPPUNIT_ASSERT(mxComponent
.is());
88 uno::Reference
<text::XTextDocument
> xTextDocument(mxComponent
, uno::UNO_QUERY_THROW
);
89 uno::Reference
<lang::XMultiServiceFactory
> xFactory(xTextDocument
, uno::UNO_QUERY_THROW
);
91 uno::Reference
<text::XDocumentIndex
> xDocumentIndex(
92 xFactory
->createInstance("com.sun.star.text.DocumentIndex"), uno::UNO_QUERY_THROW
);
94 uno::Reference
<text::XTextContent
> xTextContent(xDocumentIndex
, uno::UNO_QUERY_THROW
);
96 uno::Reference
<text::XText
> xText
= xTextDocument
->getText();
97 uno::Reference
<text::XTextCursor
> xTextCursor
= xText
->createTextCursor();
98 CPPUNIT_ASSERT(xTextCursor
.is());
99 xText
->insertTextContent(xTextCursor
, xTextContent
, false);
100 xTextCursor
->gotoEnd(false);
102 uno::Reference
<text::XDocumentIndex
> xDocumentIndexInstance(
103 xFactory
->createInstance("com.sun.star.text.DocumentIndex"), uno::UNO_QUERY_THROW
);
105 // XDocumentIndexTest
106 map
["text::XDocumentIndex"] = xDocumentIndex
;
107 map
["text::XTextDocument"] = xTextDocument
;
109 map
["text::BaseIndex"] = xDocumentIndex
;
111 map
["text::DocumentIndex"] = xDocumentIndex
;
113 map
["text::XTextRange"] = xTextCursor
;
114 map
["text::XTextContent"] = xDocumentIndex
;
115 map
["text::XTextContent#Instance"] = xDocumentIndexInstance
;
120 CPPUNIT_TEST_SUITE_REGISTRATION(SwXDocumentIndexTest
);
123 CPPUNIT_PLUGIN_IMPLEMENT();
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */