LibreOffice Module test (master) 1
xcomponent.cxx
Go to the documentation of this file.
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
12#include <rtl/ref.hxx>
13
14#include <com/sun/star/lang/XComponent.hpp>
15#include <com/sun/star/lang/XEventListener.hpp>
16
17#include <cppunit/TestAssert.h>
18
19using namespace css;
20using namespace css::uno;
21namespace
22{
23struct TestEventListener final : ::cppu::WeakImplHelper<lang::XEventListener>
24{
25 bool m_hasDisposingCalled;
26 TestEventListener()
27 : m_hasDisposingCalled(false)
28 {
29 }
30 virtual void SAL_CALL disposing(const lang::EventObject&) override
31 {
32 m_hasDisposingCalled = true;
33 }
34};
35}
36
37namespace apitest
38{
40{
41 Reference<lang::XComponent> xComponent(init(), uno::UNO_QUERY_THROW);
42 rtl::Reference<TestEventListener> pListenerAdded(new TestEventListener());
43 xComponent->addEventListener(pListenerAdded);
44 xComponent->dispose();
45 CPPUNIT_ASSERT_EQUAL(true, pListenerAdded->m_hasDisposingCalled);
46}
47
49{
50 Reference<lang::XComponent> xComponent(init(), uno::UNO_QUERY_THROW);
51 rtl::Reference<TestEventListener> pListenerAddedAndRemoved(new TestEventListener());
52 xComponent->addEventListener(pListenerAddedAndRemoved);
53 xComponent->removeEventListener(pListenerAddedAndRemoved);
54 xComponent->dispose();
55 CPPUNIT_ASSERT_EQUAL(false, pListenerAddedAndRemoved->m_hasDisposingCalled);
56}
57
59{
60 Reference<lang::XComponent> xComponent(init(), uno::UNO_QUERY_THROW);
61 rtl::Reference<TestEventListener> pListenerAdded(new TestEventListener());
62 xComponent->addEventListener(pListenerAdded);
63 xComponent->dispose();
64 CPPUNIT_ASSERT_EQUAL(true, pListenerAdded->m_hasDisposingCalled);
65}
66
68{
69 Reference<lang::XComponent> xComponent(init(), uno::UNO_QUERY_THROW);
70 rtl::Reference<TestEventListener> pListenerAdded(new TestEventListener());
71 xComponent->addEventListener(pListenerAdded);
73 CPPUNIT_ASSERT_EQUAL(true, pListenerAdded->m_hasDisposingCalled);
74}
75} // namespace apitest
76
77/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
void testAddEventListener()
Definition: xcomponent.cxx:39
void testRemoveEventListener()
Definition: xcomponent.cxx:48
virtual void triggerDesktopTerminate()=0
void testDisposedByDesktopTerminate()
Definition: xcomponent.cxx:67
virtual css::uno::Reference< css::uno::XInterface > init()=0