summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJens Carl <j.carl43@gmx.de>2018-04-01 07:20:34 +0000
committerJens Carl <j.carl43@gmx.de>2018-04-02 00:27:19 +0200
commit34568738bbaf1e82dbb53fdf516f4d57416bb5b0 (patch)
treec46a6f16760dc6ed8081b18027c4e752597c8be6 /test
parent783bc62734534b3f01339c9922ff354adec05165 (diff)
tdf#45904 Move _XActivationBroadcaster Java tests to C++
Change-Id: If8f44b24e58663bacb1cf6b2a1ec533e87fb8a38 Reviewed-on: https://gerrit.libreoffice.org/52216 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Jens Carl <j.carl43@gmx.de>
Diffstat (limited to 'test')
-rw-r--r--test/Library_subsequenttest.mk1
-rw-r--r--test/source/sheet/xactivationbroadcaster.cxx69
2 files changed, 70 insertions, 0 deletions
diff --git a/test/Library_subsequenttest.mk b/test/Library_subsequenttest.mk
index d83a964711e0..55b09aaec1e6 100644
--- a/test/Library_subsequenttest.mk
+++ b/test/Library_subsequenttest.mk
@@ -69,6 +69,7 @@ $(eval $(call gb_Library_add_exception_objects,subsequenttest,\
test/source/sheet/spreadsheet \
test/source/sheet/tableautoformat \
test/source/sheet/tablevalidation \
+ test/source/sheet/xactivationbroadcaster \
test/source/sheet/xarealink \
test/source/sheet/xarealinks \
test/source/sheet/xcalculatable \
diff --git a/test/source/sheet/xactivationbroadcaster.cxx b/test/source/sheet/xactivationbroadcaster.cxx
new file mode 100644
index 000000000000..d62c3d0aa272
--- /dev/null
+++ b/test/source/sheet/xactivationbroadcaster.cxx
@@ -0,0 +1,69 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <test/sheet/xactivationbroadcaster.hxx>
+
+#include <com/sun/star/lang/EventObject.hpp>
+#include <com/sun/star/sheet/ActivationEvent.hpp>
+#include <com/sun/star/sheet/XActivationBroadcaster.hpp>
+#include <com/sun/star/sheet/XActivationEventListener.hpp>
+#include <com/sun/star/sheet/XSpreadsheetView.hpp>
+#include <com/sun/star/uno/Reference.hxx>
+
+#include <cppuhelper/implbase.hxx>
+#include <rtl/ref.hxx>
+
+#include <cppunit/extensions/HelperMacros.h>
+
+using namespace com::sun::star;
+using namespace com::sun::star::uno;
+
+namespace apitest
+{
+class MockedActivationEventListener : public ::cppu::WeakImplHelper<sheet::XActivationEventListener>
+{
+public:
+ MockedActivationEventListener()
+ : mbListenerCalled(false)
+ {
+ }
+ bool mbListenerCalled;
+ virtual void SAL_CALL
+ activeSpreadsheetChanged(const sheet::ActivationEvent& /* xEvent */) override
+ {
+ mbListenerCalled = true;
+ }
+ virtual void SAL_CALL disposing(const lang::EventObject& /* xEventObj */) override {}
+};
+
+void XActivationBroadcaster::testAddRemoveActivationEventListener()
+{
+ uno::Reference<sheet::XActivationBroadcaster> xAB(init(), UNO_QUERY_THROW);
+ xAB->addActivationEventListener(nullptr);
+
+ rtl::Reference<MockedActivationEventListener> xListener = new MockedActivationEventListener();
+ xAB->addActivationEventListener(
+ uno::Reference<sheet::XActivationEventListener>(xListener.get()));
+
+ uno::Reference<sheet::XSpreadsheetView> xView(xAB, UNO_QUERY_THROW);
+ uno::Reference<sheet::XSpreadsheet> xSheet1(xView->getActiveSheet(), UNO_QUERY_THROW);
+ uno::Reference<sheet::XSpreadsheet> xSheet2(getXSpreadsheet(1), UNO_QUERY_THROW);
+
+ xView->setActiveSheet(xSheet2);
+
+ CPPUNIT_ASSERT_MESSAGE("Listener wasn't called", xListener->mbListenerCalled);
+
+ xAB->removeActivationEventListener(
+ uno::Reference<sheet::XActivationEventListener>(xListener.get()));
+ xView->setActiveSheet(xSheet1);
+ CPPUNIT_ASSERT_MESSAGE("Listener still called after removal", xListener->mbListenerCalled);
+}
+} // namespace apitest
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */