nss: upgrade to release 3.73
[LibreOffice.git] / test / source / sheet / xactivationbroadcaster.cxx
blob93fa5ab93689df940d2f6994ec86e1c97d802634
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.
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 */
10 #include <test/sheet/xactivationbroadcaster.hxx>
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>
19 #include <cppuhelper/implbase.hxx>
20 #include <rtl/ref.hxx>
22 #include <cppunit/TestAssert.h>
24 using namespace com::sun::star;
25 using namespace com::sun::star::uno;
27 namespace apitest
29 namespace
31 class MockedActivationEventListener : public ::cppu::WeakImplHelper<sheet::XActivationEventListener>
33 public:
34 MockedActivationEventListener()
35 : mbListenerCalled(false)
38 bool mbListenerCalled;
39 virtual void SAL_CALL
40 activeSpreadsheetChanged(const sheet::ActivationEvent& /* xEvent */) override
42 mbListenerCalled = true;
44 virtual void SAL_CALL disposing(const lang::EventObject& /* xEventObj */) override {}
48 void XActivationBroadcaster::testAddRemoveActivationEventListener()
50 uno::Reference<sheet::XActivationBroadcaster> xAB(init(), UNO_QUERY_THROW);
51 xAB->addActivationEventListener(nullptr);
53 rtl::Reference<MockedActivationEventListener> xListener = new MockedActivationEventListener();
54 xAB->addActivationEventListener(
55 uno::Reference<sheet::XActivationEventListener>(xListener.get()));
57 uno::Reference<sheet::XSpreadsheetView> xView(xAB, UNO_QUERY_THROW);
58 uno::Reference<sheet::XSpreadsheet> xSheet1(xView->getActiveSheet(), UNO_SET_THROW);
59 uno::Reference<sheet::XSpreadsheet> xSheet2(getXSpreadsheet(1), UNO_QUERY_THROW);
61 xView->setActiveSheet(xSheet2);
63 CPPUNIT_ASSERT_MESSAGE("Listener wasn't called", xListener->mbListenerCalled);
65 xAB->removeActivationEventListener(
66 uno::Reference<sheet::XActivationEventListener>(xListener.get()));
67 xView->setActiveSheet(xSheet1);
68 CPPUNIT_ASSERT_MESSAGE("Listener still called after removal", xListener->mbListenerCalled);
70 } // namespace apitest
72 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */