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 
10 #include <cppuhelper/implbase.hxx>
11 #include <test/lang/xcomponent.hxx>
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 
19 using namespace css;
20 using namespace css::uno;
21 namespace
22 {
23 struct 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 
37 namespace apitest
38 {
39 void XComponent::testAddEventListener()
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 
48 void XComponent::testRemoveEventListener()
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 
58 void XComponent::testDispose()
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 
67 void XComponent::testDisposedByDesktopTerminate()
68 {
69  Reference<lang::XComponent> xComponent(init(), uno::UNO_QUERY_THROW);
70  rtl::Reference<TestEventListener> pListenerAdded(new TestEventListener());
71  xComponent->addEventListener(pListenerAdded);
72  triggerDesktopTerminate();
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: */
FILE * init(int, char **)