diff options
author | Bjoern Michaelsen <bjoern.michaelsen@libreoffice.org> | 2019-03-12 00:05:22 +0100 |
---|---|---|
committer | Björn Michaelsen <bjoern.michaelsen@libreoffice.org> | 2019-03-16 23:36:10 +0100 |
commit | e4600ec9339e4a301e50874b1bafb87f55a54a80 (patch) | |
tree | 85ee1e4f2d1cfc8c68104cb4e3bd503613d7c804 | |
parent | 05643dc615f2e68cbe19bc26bebcfba30d801f1f (diff) |
Component test
Change-Id: I03785b3126671629011d5e62925a5658ab5ec2f7
Reviewed-on: https://gerrit.libreoffice.org/69067
Tested-by: Jenkins
Reviewed-by: Björn Michaelsen <bjoern.michaelsen@libreoffice.org>
-rw-r--r-- | include/test/lang/xcomponent.hxx | 39 | ||||
-rw-r--r-- | sw/CppunitTest_sw_apitests.mk | 2 | ||||
-rw-r--r-- | sw/qa/api/SwXTextTable.cxx | 81 | ||||
-rw-r--r-- | test/Library_subsequenttest.mk | 1 | ||||
-rw-r--r-- | test/source/lang/xcomponent.cxx | 71 |
5 files changed, 194 insertions, 0 deletions
diff --git a/include/test/lang/xcomponent.hxx b/include/test/lang/xcomponent.hxx new file mode 100644 index 000000000000..347a36e2925c --- /dev/null +++ b/include/test/lang/xcomponent.hxx @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_TEST_LANG_XCOMPONENT_HXX +#define INCLUDED_TEST_LANG_XCOMPONENT_HXX + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/XInterface.hpp> + +#include <test/testdllapi.hxx> + +namespace apitest +{ +class OOO_DLLPUBLIC_TEST XComponent +{ +public: + virtual css::uno::Reference<css::uno::XInterface> init() = 0; + virtual void triggerDesktopTerminate() = 0; + + void testAddEventListener(); + void testRemoveEventListener(); + void testDisposedByDesktopTerminate(); + +protected: + ~XComponent() {} +}; + +} // namespace apitest + +#endif // INCLUDED_TEST_LANG_XCOMPONENT_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sw/CppunitTest_sw_apitests.mk b/sw/CppunitTest_sw_apitests.mk index b601b948d82f..1f850da50efc 100644 --- a/sw/CppunitTest_sw_apitests.mk +++ b/sw/CppunitTest_sw_apitests.mk @@ -16,6 +16,7 @@ $(eval $(call gb_CppunitTest_use_external,sw_apitests,boost_headers)) $(eval $(call gb_CppunitTest_add_exception_objects,sw_apitests, \ sw/qa/api/SwXDocumentIndex \ sw/qa/api/DocumentSettings \ + sw/qa/api/SwXTextTable \ )) $(eval $(call gb_CppunitTest_use_libraries,sw_apitests, \ @@ -41,6 +42,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_apitests, \ svt \ svx \ svxcore \ + subsequenttest \ test \ tl \ tk \ diff --git a/sw/qa/api/SwXTextTable.cxx b/sw/qa/api/SwXTextTable.cxx new file mode 100644 index 000000000000..e35de37c0024 --- /dev/null +++ b/sw/qa/api/SwXTextTable.cxx @@ -0,0 +1,81 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "XTextContentTest.hxx" + +#include <test/bootstrapfixture.hxx> +#include <test/lang/xcomponent.hxx> +#include <unotest/macros_test.hxx> + +#include <com/sun/star/frame/Desktop.hpp> +//#include <com/sun/star/frame/DispatchHelper.hpp> + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextTable.hpp> +#include <com/sun/star/text/XTextCursor.hpp> + +#include <comphelper/processfactory.hxx> + +using namespace css; +using namespace css::uno; + +namespace +{ +/** + * Initial tests for SwXTextTable. + */ +struct SwXTextTable final : public test::BootstrapFixture, + public unotest::MacrosTest, + public apitest::XComponent +{ + virtual void setUp() override; + + Reference<XInterface> init() override; + void triggerDesktopTerminate() override; + + CPPUNIT_TEST_SUITE(SwXTextTable); + CPPUNIT_TEST(testAddEventListener); + CPPUNIT_TEST(testRemoveEventListener); + CPPUNIT_TEST(testDisposedByDesktopTerminate); + CPPUNIT_TEST_SUITE_END(); +}; + +void SwXTextTable::setUp() +{ + test::BootstrapFixture::setUp(); + mxDesktop.set( + frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory()))); +} + +void SwXTextTable::triggerDesktopTerminate() { mxDesktop->terminate(); } + +Reference<XInterface> SwXTextTable::init() +{ + auto xComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"); + CPPUNIT_ASSERT(xComponent.is()); + Reference<text::XTextDocument> xTextDocument(xComponent, UNO_QUERY_THROW); + Reference<lang::XMultiServiceFactory> xMSF(xComponent, UNO_QUERY_THROW); + Reference<text::XText> xText = xTextDocument->getText(); + Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + Reference<text::XTextTable> xTable(xMSF->createInstance("com.sun.star.text.TextTable"), + UNO_QUERY_THROW); + xTable->initialize(4, 3); + xText->insertTextContent(xCursor, xTable, false); + CPPUNIT_ASSERT(xCursor.is()); + return Reference<XInterface>(xTable, UNO_QUERY_THROW); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(SwXTextTable); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/Library_subsequenttest.mk b/test/Library_subsequenttest.mk index 086e24b82b51..a1ea3349978f 100644 --- a/test/Library_subsequenttest.mk +++ b/test/Library_subsequenttest.mk @@ -57,6 +57,7 @@ $(eval $(call gb_Library_add_exception_objects,subsequenttest,\ test/source/drawing/captionshape \ test/source/drawing/xdrawpages \ test/source/lang/xserviceinfo \ + test/source/lang/xcomponent \ test/source/sheet/cellarealink \ test/source/sheet/cellproperties \ test/source/sheet/databaseimportdescriptor \ diff --git a/test/source/lang/xcomponent.cxx b/test/source/lang/xcomponent.cxx new file mode 100644 index 000000000000..386fa45f232f --- /dev/null +++ b/test/source/lang/xcomponent.cxx @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <cppuhelper/implbase.hxx> +#include <test/lang/xcomponent.hxx> + +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XEventListener.hpp> + +#include <cppunit/extensions/HelperMacros.h> + +using namespace css; +using namespace css::uno; +namespace +{ +struct TestEventListener final : ::cppu::WeakImplHelper<lang::XEventListener> +{ + bool m_hasDisposingCalled; + TestEventListener() + : m_hasDisposingCalled(false) + { + } + virtual void SAL_CALL disposing(const lang::EventObject&) override + { + m_hasDisposingCalled = true; + } +}; +} + +namespace apitest +{ +void XComponent::testAddEventListener() +{ + Reference<lang::XComponent> xComponent(init(), uno::UNO_QUERY_THROW); + auto pListenerAdded(new TestEventListener()); + Reference<lang::XEventListener> xListenerAdded(pListenerAdded); + xComponent->addEventListener(xListenerAdded); + xComponent->dispose(); + CPPUNIT_ASSERT_EQUAL(true, pListenerAdded->m_hasDisposingCalled); +} + +void XComponent::testRemoveEventListener() +{ + Reference<lang::XComponent> xComponent(init(), uno::UNO_QUERY_THROW); + auto pListenerAddedAndRemoved(new TestEventListener()); + Reference<lang::XEventListener> xListenerAddedAndRemoved(pListenerAddedAndRemoved); + xComponent->addEventListener(xListenerAddedAndRemoved); + xComponent->removeEventListener(xListenerAddedAndRemoved); + xComponent->dispose(); + CPPUNIT_ASSERT_EQUAL(false, pListenerAddedAndRemoved->m_hasDisposingCalled); +} + +void XComponent::testDisposedByDesktopTerminate() +{ + Reference<lang::XComponent> xComponent(init(), uno::UNO_QUERY_THROW); + auto pListenerAdded(new TestEventListener()); + Reference<lang::XEventListener> xListenerAdded(pListenerAdded); + xComponent->addEventListener(xListenerAdded); + triggerDesktopTerminate(); + CPPUNIT_ASSERT_EQUAL(true, pListenerAdded->m_hasDisposingCalled); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |