LibreOffice Module test (master) 1
xactivationbroadcaster.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
11
12#include <com/sun/star/lang/EventObject.hpp>
13#include <com/sun/star/sheet/ActivationEvent.hpp>
14#include <com/sun/star/sheet/XActivationBroadcaster.hpp>
15#include <com/sun/star/sheet/XActivationEventListener.hpp>
16#include <com/sun/star/sheet/XSpreadsheetView.hpp>
17#include <com/sun/star/uno/Reference.hxx>
18
20#include <rtl/ref.hxx>
21
22#include <cppunit/TestAssert.h>
23
24using namespace com::sun::star;
25using namespace com::sun::star::uno;
26
27namespace apitest
28{
29namespace
30{
31class MockedActivationEventListener : public ::cppu::WeakImplHelper<sheet::XActivationEventListener>
32{
33public:
34 MockedActivationEventListener()
35 : mbListenerCalled(false)
36 {
37 }
39 virtual void SAL_CALL
40 activeSpreadsheetChanged(const sheet::ActivationEvent& /* xEvent */) override
41 {
42 mbListenerCalled = true;
43 }
44 virtual void SAL_CALL disposing(const lang::EventObject& /* xEventObj */) override {}
45};
46}
47
49{
50 uno::Reference<sheet::XActivationBroadcaster> xAB(init(), UNO_QUERY_THROW);
51 xAB->addActivationEventListener(nullptr);
52
53 rtl::Reference<MockedActivationEventListener> xListener = new MockedActivationEventListener();
54 xAB->addActivationEventListener(uno::Reference<sheet::XActivationEventListener>(xListener));
55
56 uno::Reference<sheet::XSpreadsheetView> xView(xAB, UNO_QUERY_THROW);
57 uno::Reference<sheet::XSpreadsheet> xSheet1(xView->getActiveSheet(), UNO_SET_THROW);
58 uno::Reference<sheet::XSpreadsheet> xSheet2(getXSpreadsheet(1), UNO_QUERY_THROW);
59
60 xView->setActiveSheet(xSheet2);
61
62 CPPUNIT_ASSERT_MESSAGE("Listener wasn't called", xListener->mbListenerCalled);
63
64 xAB->removeActivationEventListener(uno::Reference<sheet::XActivationEventListener>(xListener));
65 xView->setActiveSheet(xSheet1);
66 CPPUNIT_ASSERT_MESSAGE("Listener still called after removal", xListener->mbListenerCalled);
67}
68} // namespace apitest
69
70/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
virtual css::uno::Reference< css::uno::XInterface > init()=0
virtual css::uno::Reference< css::uno::XInterface > getXSpreadsheet(const sal_Int16 nNumber=0)=0
bool mbListenerCalled