Skip to content

Commit d833ab9

Browse files
committed
Extract testDisposedByDesktopTerminate from CppunitTest_sw_apitests
It is not guaranteed that SwXTextTable runs last during CppunitTest_sw_apitests, and e.g. building with --enable-lto on Linux caused SwXTextField to be run after SwXTextTable. But then testDisposedByDesktopTerminate had already shut down all the relevant global state, so the SwXTextField tests would fail. TerminateTest is a faithful copy of the original SwXTextTable testDisposedByDesktopTerminate behavior, but I do not know how much of that (if anything at all) is actually test-worthy. (For example, parts of TerminateTest::init may not be relevant, or the original SwXTextTable testDisposedByDesktopTerminate may even only have been there to clean up after other tests and not to actually test anything by itself, cf. 20ed81f "Make individual tests clean up after themselves".) Change-Id: Ib95b7fa6888f55a27236a779c453a6d04122a527 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90774 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <[email protected]>
1 parent f7efe5a commit d833ab9

File tree

4 files changed

+122
-8
lines changed

4 files changed

+122
-8
lines changed

sw/CppunitTest_sw_apiterminate.mk

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; 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+
$(eval $(call gb_CppunitTest_CppunitTest,sw_apiterminate))
11+
12+
$(eval $(call gb_CppunitTest_add_exception_objects,sw_apiterminate, \
13+
sw/qa/api/terminate \
14+
))
15+
16+
$(eval $(call gb_CppunitTest_use_api,sw_apiterminate, \
17+
offapi \
18+
udkapi \
19+
))
20+
21+
$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_apiterminate))
22+
23+
$(eval $(call gb_CppunitTest_use_configuration,sw_apiterminate))
24+
25+
$(eval $(call gb_CppunitTest_use_libraries,sw_apiterminate, \
26+
comphelper \
27+
cppu \
28+
sal \
29+
subsequenttest \
30+
test \
31+
unotest \
32+
))
33+
34+
$(eval $(call gb_CppunitTest_use_rdb,sw_apiterminate,services))
35+
36+
$(eval $(call gb_CppunitTest_use_vcl,sw_apiterminate))
37+
38+
$(eval $(call gb_CppunitTest_use_uiconfigs,sw_apiterminate, \
39+
svx \
40+
))
41+
42+
$(eval $(call gb_CppunitTest_use_ure,sw_apiterminate))
43+
44+
# vim: set noet sw=4 ts=4:

sw/Module_sw.mk

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
102102
CppunitTest_sw_mailmerge \
103103
CppunitTest_sw_globalfilter \
104104
CppunitTest_sw_accessible_relation_set \
105+
CppunitTest_sw_apiterminate \
105106
CppunitTest_sw_apitests \
106107
CppunitTest_sw_unowriter \
107108
CppunitTest_sw_core_text \

sw/qa/api/SwXTextTable.cxx

+1-8
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ struct SwXTextTable final : public test::BootstrapFixture,
4444
CPPUNIT_TEST_SUITE(SwXTextTable);
4545
CPPUNIT_TEST(testAddEventListener);
4646
CPPUNIT_TEST(testRemoveEventListener);
47-
CPPUNIT_TEST(testDisposedByDesktopTerminate);
4847
CPPUNIT_TEST_SUITE_END();
4948

5049
private:
@@ -62,13 +61,7 @@ void SwXTextTable::tearDown()
6261
{
6362
if (component_.is())
6463
{
65-
try
66-
{
67-
component_->dispose();
68-
}
69-
catch (css::lang::DisposedException&) // thrown by testDisposedByDesktopTerminate
70-
{
71-
}
64+
component_->dispose();
7265
}
7366
}
7467

sw/qa/api/terminate.cxx

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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

Comments
 (0)