|
| 1 | +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ |
| 2 | +/* |
| 3 | + * This file is part of the LibreOffice project. |
| 4 | + * |
| 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 | + */ |
| 9 | + |
| 10 | +#include <sal/config.h> |
| 11 | + |
| 12 | +#include <cppunit/TestAssert.h> |
| 13 | +#include <cppunit/extensions/HelperMacros.h> |
| 14 | +#include <cppunit/plugin/TestPlugIn.h> |
| 15 | + |
| 16 | +#include <com/sun/star/frame/Desktop.hpp> |
| 17 | +#include <com/sun/star/lang/XMultiServiceFactory.hpp> |
| 18 | +#include <com/sun/star/text/XText.hpp> |
| 19 | +#include <com/sun/star/text/XTextCursor.hpp> |
| 20 | +#include <com/sun/star/text/XTextDocument.hpp> |
| 21 | +#include <com/sun/star/text/XTextTable.hpp> |
| 22 | +#include <com/sun/star/uno/Reference.hxx> |
| 23 | +#include <com/sun/star/uno/XInterface.hpp> |
| 24 | +#include <comphelper/processfactory.hxx> |
| 25 | +#include <test/bootstrapfixture.hxx> |
| 26 | +#include <test/lang/xcomponent.hxx> |
| 27 | +#include <unotest/macros_test.hxx> |
| 28 | + |
| 29 | +class TerminateTest final : public test::BootstrapFixture, |
| 30 | + public unotest::MacrosTest, |
| 31 | + public apitest::XComponent |
| 32 | +{ |
| 33 | +public: |
| 34 | + void setUp() override; |
| 35 | + |
| 36 | + css::uno::Reference<css::uno::XInterface> init() override; |
| 37 | + |
| 38 | + void triggerDesktopTerminate() override; |
| 39 | + |
| 40 | + CPPUNIT_TEST_SUITE(TerminateTest); |
| 41 | + CPPUNIT_TEST(testDisposedByDesktopTerminate); |
| 42 | + CPPUNIT_TEST_SUITE_END(); |
| 43 | +}; |
| 44 | + |
| 45 | +void TerminateTest::setUp() |
| 46 | +{ |
| 47 | + test::BootstrapFixture::setUp(); |
| 48 | + mxDesktop.set( |
| 49 | + css::frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory()))); |
| 50 | +} |
| 51 | + |
| 52 | +css::uno::Reference<css::uno::XInterface> TerminateTest::init() |
| 53 | +{ |
| 54 | + auto const component |
| 55 | + = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"); |
| 56 | + CPPUNIT_ASSERT(component.is()); |
| 57 | + css::uno::Reference<css::text::XTextDocument> xTextDocument(component, |
| 58 | + css::uno::UNO_QUERY_THROW); |
| 59 | + css::uno::Reference<css::lang::XMultiServiceFactory> xMSF(component, css::uno::UNO_QUERY_THROW); |
| 60 | + css::uno::Reference<css::text::XText> xText = xTextDocument->getText(); |
| 61 | + css::uno::Reference<css::text::XTextCursor> xCursor = xText->createTextCursor(); |
| 62 | + css::uno::Reference<css::text::XTextTable> xTable( |
| 63 | + xMSF->createInstance("com.sun.star.text.TextTable"), css::uno::UNO_QUERY_THROW); |
| 64 | + xTable->initialize(4, 3); |
| 65 | + xText->insertTextContent(xCursor, xTable, false); |
| 66 | + CPPUNIT_ASSERT(xCursor.is()); |
| 67 | + return css::uno::Reference<css::uno::XInterface>(xTable, css::uno::UNO_QUERY_THROW); |
| 68 | +} |
| 69 | + |
| 70 | +void TerminateTest::triggerDesktopTerminate() { mxDesktop->terminate(); } |
| 71 | + |
| 72 | +CPPUNIT_TEST_SUITE_REGISTRATION(TerminateTest); |
| 73 | + |
| 74 | +CPPUNIT_PLUGIN_IMPLEMENT(); |
| 75 | + |
| 76 | +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |
0 commit comments