Kaydet (Commit) e4600ec9 authored tarafından Bjoern Michaelsen's avatar Bjoern Michaelsen Kaydeden (comit) Björn Michaelsen

Component test

Change-Id: I03785b3126671629011d5e62925a5658ab5ec2f7
Reviewed-on: https://gerrit.libreoffice.org/69067
Tested-by: Jenkins
Reviewed-by: 's avatarBjörn Michaelsen <bjoern.michaelsen@libreoffice.org>
üst 05643dc6
/* -*- 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: */
...@@ -16,6 +16,7 @@ $(eval $(call gb_CppunitTest_use_external,sw_apitests,boost_headers)) ...@@ -16,6 +16,7 @@ $(eval $(call gb_CppunitTest_use_external,sw_apitests,boost_headers))
$(eval $(call gb_CppunitTest_add_exception_objects,sw_apitests, \ $(eval $(call gb_CppunitTest_add_exception_objects,sw_apitests, \
sw/qa/api/SwXDocumentIndex \ sw/qa/api/SwXDocumentIndex \
sw/qa/api/DocumentSettings \ sw/qa/api/DocumentSettings \
sw/qa/api/SwXTextTable \
)) ))
$(eval $(call gb_CppunitTest_use_libraries,sw_apitests, \ $(eval $(call gb_CppunitTest_use_libraries,sw_apitests, \
...@@ -41,6 +42,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_apitests, \ ...@@ -41,6 +42,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_apitests, \
svt \ svt \
svx \ svx \
svxcore \ svxcore \
subsequenttest \
test \ test \
tl \ tl \
tk \ tk \
......
/* -*- 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: */
...@@ -57,6 +57,7 @@ $(eval $(call gb_Library_add_exception_objects,subsequenttest,\ ...@@ -57,6 +57,7 @@ $(eval $(call gb_Library_add_exception_objects,subsequenttest,\
test/source/drawing/captionshape \ test/source/drawing/captionshape \
test/source/drawing/xdrawpages \ test/source/drawing/xdrawpages \
test/source/lang/xserviceinfo \ test/source/lang/xserviceinfo \
test/source/lang/xcomponent \
test/source/sheet/cellarealink \ test/source/sheet/cellarealink \
test/source/sheet/cellproperties \ test/source/sheet/cellproperties \
test/source/sheet/databaseimportdescriptor \ test/source/sheet/databaseimportdescriptor \
......
/* -*- 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: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment