use insert function instead of for loop
[LibreOffice.git] / sw / qa / api / SwXFootnote.cxx
blobd98dfce0b77ac715d86c61f8c6dd013805781532
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <test/unoapi_test.hxx>
11 #include <test/lang/xcomponent.hxx>
12 #include <test/text/footnote.hxx>
13 #include <test/text/xsimpletext.hxx>
14 #include <test/text/xtextrange.hxx>
15 #include <test/text/xtextcontent.hxx>
16 #include <test/text/xtext.hxx>
17 #include <test/text/xfootnote.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/XText.hpp>
25 #include <com/sun/star/text/XFootnote.hpp>
27 #include <comphelper/processfactory.hxx>
29 using namespace css;
30 using namespace css::uno;
32 namespace
34 /**
35 * Initial tests for SwXFootnote.
37 class SwXFootnote final : public UnoApiTest,
38 public apitest::XComponent,
39 public apitest::XSimpleText,
40 public apitest::XTextRange,
41 public apitest::XTextContent,
42 public apitest::XText,
43 public apitest::XFootnote,
44 public apitest::Footnote
46 public:
47 SwXFootnote();
49 Reference<XInterface> init() override;
50 Reference<text::XTextRange> getTextRange() override;
51 Reference<text::XTextContent> getTextContent() override;
52 bool isAttachSupported() override { return true; }
53 void triggerDesktopTerminate() override {}
55 CPPUNIT_TEST_SUITE(SwXFootnote);
56 CPPUNIT_TEST(testDispose);
57 CPPUNIT_TEST(testAddEventListener);
58 CPPUNIT_TEST(testRemoveEventListener);
59 CPPUNIT_TEST(testAttach);
60 CPPUNIT_TEST(testGetAnchor);
61 CPPUNIT_TEST(testCreateTextCursor);
62 CPPUNIT_TEST(testCreateTextCursorByRange);
63 CPPUNIT_TEST(testInsertString);
64 CPPUNIT_TEST(testInsertControlCharacter);
65 CPPUNIT_TEST(testGetEnd);
66 CPPUNIT_TEST(testGetSetString);
67 CPPUNIT_TEST(testGetStart);
68 CPPUNIT_TEST(testGetText);
69 CPPUNIT_TEST(testFootnoteProperties);
70 // CPPUNIT_TEST(testInsertRemoveTextContent);
71 CPPUNIT_TEST(testGetSetLabel);
72 CPPUNIT_TEST_SUITE_END();
74 private:
75 Reference<text::XTextRange> mxTextRange;
76 Reference<text::XTextContent> mxTextContent;
79 SwXFootnote::SwXFootnote()
80 : UnoApiTest(u""_ustr)
84 Reference<XInterface> SwXFootnote::init()
86 loadFromURL(u"private:factory/swriter"_ustr);
87 Reference<text::XTextDocument> xTextDocument(mxComponent, UNO_QUERY_THROW);
88 Reference<lang::XMultiServiceFactory> xMSF(mxComponent, UNO_QUERY_THROW);
89 Reference<text::XFootnote> xFootnote(xMSF->createInstance(u"com.sun.star.text.Footnote"_ustr),
90 UNO_QUERY_THROW);
92 Reference<text::XText> xText = xTextDocument->getText();
93 Reference<text::XTextCursor> xCursor = xText->createTextCursor();
95 xText->insertTextContent(xCursor, xFootnote, false);
97 mxTextRange = Reference<text::XTextRange>(xCursor, UNO_QUERY_THROW);
98 mxTextContent = Reference<text::XTextContent>(
99 xMSF->createInstance(u"com.sun.star.text.Footnote"_ustr), UNO_QUERY_THROW);
101 return Reference<XInterface>(xFootnote, UNO_QUERY_THROW);
104 Reference<text::XTextRange> SwXFootnote::getTextRange() { return mxTextRange; }
106 Reference<text::XTextContent> SwXFootnote::getTextContent() { return mxTextContent; }
108 CPPUNIT_TEST_SUITE_REGISTRATION(SwXFootnote);
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */