cid#1640468 Dereference after null check
[LibreOffice.git] / sw / qa / api / SwXFootnotes.cxx
blob36ff83966da341b8c076a941f87ffdd2ae95564c
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/container/xelementaccess.hxx>
12 #include <test/container/xindexaccess.hxx>
14 #include <com/sun/star/frame/Desktop.hpp>
16 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
18 #include <com/sun/star/text/XFootnote.hpp>
19 #include <com/sun/star/text/XFootnotesSupplier.hpp>
20 #include <com/sun/star/text/XTextDocument.hpp>
21 #include <com/sun/star/text/XText.hpp>
23 #include <comphelper/processfactory.hxx>
25 using namespace css;
26 using namespace css::uno;
28 namespace
30 /**
31 * Initial tests for SwXFootnotes.
33 class SwXFootnotes final : public UnoApiTest,
34 public apitest::XElementAccess,
35 public apitest::XIndexAccess
37 public:
38 SwXFootnotes()
39 : UnoApiTest(u""_ustr)
40 , XElementAccess(cppu::UnoType<text::XFootnote>::get())
41 , XIndexAccess(1)
45 Reference<XInterface> init() override
47 loadFromURL(u"private:factory/swriter"_ustr);
48 Reference<text::XTextDocument> xTextDocument(mxComponent, UNO_QUERY_THROW);
49 Reference<lang::XMultiServiceFactory> xMSF(mxComponent, UNO_QUERY_THROW);
51 Reference<text::XFootnote> xFootnote(
52 xMSF->createInstance(u"com.sun.star.text.Footnote"_ustr), UNO_QUERY_THROW);
54 Reference<text::XText> xText = xTextDocument->getText();
55 Reference<text::XTextCursor> xCursor = xText->createTextCursor();
57 xText->insertTextContent(xCursor, xFootnote, false);
59 Reference<text::XFootnotesSupplier> xSupplier(xTextDocument, UNO_QUERY_THROW);
61 return Reference<XInterface>(xSupplier->getFootnotes(), UNO_QUERY_THROW);
64 CPPUNIT_TEST_SUITE(SwXFootnotes);
65 CPPUNIT_TEST(testGetElementType);
66 CPPUNIT_TEST(testHasElements);
67 CPPUNIT_TEST(testGetCount);
68 CPPUNIT_TEST(testGetByIndex);
69 CPPUNIT_TEST_SUITE_END();
72 CPPUNIT_TEST_SUITE_REGISTRATION(SwXFootnotes);
75 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */