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/container/xelementaccess.hxx>
12 #include <test/container/xindexaccess.hxx>
13 #include <test/container/xnameaccess.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>
22 #include <com/sun/star/text/XReferenceMarksSupplier.hpp>
24 #include <comphelper/processfactory.hxx>
27 using namespace css::uno
;
32 * Initial tests for SwXReferenceMarks.
34 class SwXReferenceMarks final
: public UnoApiTest
,
35 public apitest::XElementAccess
,
36 public apitest::XIndexAccess
,
37 public apitest::XNameAccess
41 : UnoApiTest(u
""_ustr
)
42 , XElementAccess(cppu::UnoType
<text::XTextContent
>::get())
44 , XNameAccess(u
"SwXReferenceMarks2"_ustr
)
48 Reference
<XInterface
> init() override
50 loadFromURL(u
"private:factory/swriter"_ustr
);
51 Reference
<text::XTextDocument
> xTextDocument(mxComponent
, UNO_QUERY_THROW
);
52 Reference
<lang::XMultiServiceFactory
> xMSF(xTextDocument
, UNO_QUERY_THROW
);
54 Reference
<text::XText
> xText
= xTextDocument
->getText();
55 Reference
<text::XTextCursor
> xCursor
= xText
->createTextCursor();
58 Reference
<XInterface
> xRefMark1
59 = xMSF
->createInstance(u
"com.sun.star.text.ReferenceMark"_ustr
);
60 Reference
<container::XNamed
> xNamed1(xRefMark1
, UNO_QUERY_THROW
);
61 xNamed1
->setName(u
"SwXReferenceMarks1"_ustr
);
63 Reference
<text::XTextContent
> xTextContent1(xRefMark1
, UNO_QUERY_THROW
);
64 xText
->insertTextContent(xCursor
, xTextContent1
, false);
67 Reference
<XInterface
> xRefMark2
68 = xMSF
->createInstance(u
"com.sun.star.text.ReferenceMark"_ustr
);
69 Reference
<container::XNamed
> xNamed2(xRefMark2
, UNO_QUERY_THROW
);
70 xNamed2
->setName(u
"SwXReferenceMarks2"_ustr
);
72 Reference
<text::XTextContent
> xTextContent2(xRefMark2
, UNO_QUERY_THROW
);
73 xText
->insertTextContent(xCursor
, xTextContent2
, false);
75 // Getting ReferenceMarks from Text Document
76 Reference
<text::XReferenceMarksSupplier
> xRefMarkSupp(xTextDocument
, UNO_QUERY_THROW
);
78 return Reference
<XInterface
>(xRefMarkSupp
->getReferenceMarks(), UNO_QUERY_THROW
);
81 CPPUNIT_TEST_SUITE(SwXReferenceMarks
);
82 CPPUNIT_TEST(testGetElementType
);
83 CPPUNIT_TEST(testHasElements
);
84 CPPUNIT_TEST(testGetCount
);
85 CPPUNIT_TEST(testGetByIndex
);
86 CPPUNIT_TEST(testGetByName
);
87 CPPUNIT_TEST(testGetElementNames
);
88 CPPUNIT_TEST(testHasByName
);
89 CPPUNIT_TEST_SUITE_END();
92 CPPUNIT_TEST_SUITE_REGISTRATION(SwXReferenceMarks
);
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */