summaryrefslogtreecommitdiff
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
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>
-rw-r--r--include/test/sheet/xactivationbroadcaster.hxx36
-rw-r--r--qadevOOo/Jar_OOoRunner.mk1
-rw-r--r--qadevOOo/objdsc/sc/com.sun.star.comp.office.ScTabViewObj.csv2
-rw-r--r--qadevOOo/tests/java/ifc/sheet/_XActivationBroadcaster.java97
-rw-r--r--sc/qa/extras/sctabviewobj.cxx34
-rw-r--r--test/Library_subsequenttest.mk1
-rw-r--r--test/source/sheet/xactivationbroadcaster.cxx69
7 files changed, 134 insertions, 106 deletions
diff --git a/include/test/sheet/xactivationbroadcaster.hxx b/include/test/sheet/xactivationbroadcaster.hxx
new file mode 100644
index 000000000000..5dc21edc0195
--- /dev/null
+++ b/include/test/sheet/xactivationbroadcaster.hxx
@@ -0,0 +1,36 @@
+/* -*- 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/.
+ */
+
+#ifndef INCLUDED_TEST_SHEET_XACTIVATIONBROADCASTER_HXX
+#define INCLUDED_TEST_SHEET_XACTIVATIONBROADCASTER_HXX
+
+#include <com/sun/star/uno/XInterface.hpp>
+#include <com/sun/star/uno/Reference.hxx>
+
+#include <test/testdllapi.hxx>
+
+namespace apitest
+{
+class OOO_DLLPUBLIC_TEST XActivationBroadcaster
+{
+public:
+ virtual css::uno::Reference<css::uno::XInterface> init() = 0;
+ virtual css::uno::Reference<css::uno::XInterface> getXSpreadsheet(const sal_Int16 nNumber = 0)
+ = 0;
+
+ void testAddRemoveActivationEventListener();
+
+protected:
+ ~XActivationBroadcaster() {}
+};
+} // namespace apitest
+
+#endif // INCLUDED_TEST_SHEET_XACTIVATIONBROADCASTER_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/qadevOOo/Jar_OOoRunner.mk b/qadevOOo/Jar_OOoRunner.mk
index bf742f150711..ca3665894180 100644
--- a/qadevOOo/Jar_OOoRunner.mk
+++ b/qadevOOo/Jar_OOoRunner.mk
@@ -566,7 +566,6 @@ $(eval $(call gb_Jar_add_sourcefiles,OOoRunner,\
qadevOOo/tests/java/ifc/sheet/_SheetSortDescriptor \
qadevOOo/tests/java/ifc/sheet/_SpreadsheetDocument \
qadevOOo/tests/java/ifc/sheet/_TableAutoFormatField \
- qadevOOo/tests/java/ifc/sheet/_XActivationBroadcaster \
qadevOOo/tests/java/ifc/sheet/_XArrayFormulaRange \
qadevOOo/tests/java/ifc/sheet/_XCellRangeData \
qadevOOo/tests/java/ifc/sheet/_XCellRangeFormula \
diff --git a/qadevOOo/objdsc/sc/com.sun.star.comp.office.ScTabViewObj.csv b/qadevOOo/objdsc/sc/com.sun.star.comp.office.ScTabViewObj.csv
index e13c05bfda4e..35e1186c0e10 100644
--- a/qadevOOo/objdsc/sc/com.sun.star.comp.office.ScTabViewObj.csv
+++ b/qadevOOo/objdsc/sc/com.sun.star.comp.office.ScTabViewObj.csv
@@ -15,8 +15,6 @@
"ScTabViewObj";"com::sun::star::sheet::XCellRangeReferrer";"getReferredCells()"
"ScTabViewObj";"com::sun::star::container::XElementAccess";"getElementType()"
"ScTabViewObj";"com::sun::star::container::XElementAccess";"hasElements()"
-"ScTabViewObj";"com::sun::star::sheet::XActivationBroadcaster#optional";"addActivationEventListener()"
-"ScTabViewObj";"com::sun::star::sheet::XActivationBroadcaster#optional";"removeActivationEventListener()"
"ScTabViewObj";"com::sun::star::sheet::XRangeSelection";"startRangeSelection()"
"ScTabViewObj";"com::sun::star::sheet::XRangeSelection";"abortRangeSelection()"
"ScTabViewObj";"com::sun::star::sheet::XRangeSelection";"addRangeSelectionListener()"
diff --git a/qadevOOo/tests/java/ifc/sheet/_XActivationBroadcaster.java b/qadevOOo/tests/java/ifc/sheet/_XActivationBroadcaster.java
deleted file mode 100644
index 5d2d15dc6628..000000000000
--- a/qadevOOo/tests/java/ifc/sheet/_XActivationBroadcaster.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * 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/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-package ifc.sheet;
-
-import com.sun.star.sheet.XActivationBroadcaster;
-import com.sun.star.sheet.XActivationEventListener;
-import com.sun.star.sheet.XSpreadsheet;
-import com.sun.star.sheet.XSpreadsheetView;
-import com.sun.star.uno.UnoRuntime;
-
-import lib.MultiMethodTest;
-import lib.Status;
-import lib.StatusException;
-
-
-public class _XActivationBroadcaster extends MultiMethodTest {
- public XActivationBroadcaster oObj;
- protected boolean listenerCalled = false;
- protected XSpreadsheetView xSpreadsheetView = null;
- protected XActivationEventListener listener = null;
- protected XSpreadsheet two = null;
-
- public void _addActivationEventListener() {
-
- log.println("trying to add an invalid listener");
- oObj.addActivationEventListener(listener);
- log.println(".... OK");
-
- log.println("adding a valid listener");
- listener = new MyListener();
- oObj.addActivationEventListener(listener);
-
- XSpreadsheet org = xSpreadsheetView.getActiveSheet();
- xSpreadsheetView.setActiveSheet(two);
-
- if (!listenerCalled) {
- log.println("Listener wasn't called");
- }
-
- xSpreadsheetView.setActiveSheet(org);
- tRes.tested("addActivationEventListener()", listenerCalled);
- }
-
- public void _removeActivationEventListener() {
- requiredMethod("addActivationEventListener()");
- listenerCalled = false;
- oObj.removeActivationEventListener(listener);
-
- XSpreadsheet org = xSpreadsheetView.getActiveSheet();
- xSpreadsheetView.setActiveSheet(two);
-
- if (listenerCalled) {
- log.println("Listener was called even though it is removed");
- }
-
- xSpreadsheetView.setActiveSheet(org);
- tRes.tested("removeActivationEventListener()", !listenerCalled);
- }
-
- @Override
- public void before() {
- xSpreadsheetView = UnoRuntime.queryInterface(
- XSpreadsheetView.class,
- tEnv.getTestObject());
-
- two = (XSpreadsheet) tEnv.getObjRelation("Sheet");
-
- if ((xSpreadsheetView == null) || (two == null)) {
- throw new StatusException(Status.failed(
- "precondition for test is missing"));
- }
- }
-
- protected class MyListener implements XActivationEventListener {
- public void activeSpreadsheetChanged(com.sun.star.sheet.ActivationEvent activationEvent) {
- listenerCalled = true;
- }
-
- public void disposing(com.sun.star.lang.EventObject eventObject) {
- }
- }
-} \ No newline at end of file
diff --git a/sc/qa/extras/sctabviewobj.cxx b/sc/qa/extras/sctabviewobj.cxx
index 8217c4e915a9..6f3f3b01ae16 100644
--- a/sc/qa/extras/sctabviewobj.cxx
+++ b/sc/qa/extras/sctabviewobj.cxx
@@ -9,15 +9,16 @@
#include <test/calc_unoapi_test.hxx>
#include <test/sheet/spreadsheetviewsettings.hxx>
+#include <test/sheet/xactivationbroadcaster.hxx>
#include <test/sheet/xspreadsheetview.hxx>
#include <test/sheet/xviewfreezable.hxx>
#include <test/sheet/xviewsplitable.hxx>
+#include <com/sun/star/container/XIndexAccess.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
#include <com/sun/star/sheet/XSpreadsheet.hpp>
-#include <com/sun/star/sheet/XViewSplitable.hpp>
#include <com/sun/star/uno/XInterface.hpp>
#include <com/sun/star/uno/Reference.hxx>
@@ -25,10 +26,11 @@
using namespace css;
using namespace css::uno;
-namespace sc_apitest {
-
+namespace sc_apitest
+{
class ScTabViewObj : public CalcUnoApiTest,
public apitest::SpreadsheetViewSettings,
+ public apitest::XActivationBroadcaster,
public apitest::XSpreadsheetView,
public apitest::XViewFreezable,
public apitest::XViewSplitable
@@ -37,6 +39,8 @@ public:
ScTabViewObj();
virtual uno::Reference< uno::XInterface > init() override;
+ virtual uno::Reference<uno::XInterface> getXSpreadsheet(const sal_Int16 nNumber = 0) override;
+
virtual void setUp() override;
virtual void tearDown() override;
@@ -45,6 +49,9 @@ public:
// SpreadsheetViewSettings
CPPUNIT_TEST(testSpreadsheetViewSettingsProperties);
+ // XActivationBroadcaster
+ CPPUNIT_TEST(testAddRemoveActivationEventListener);
+
// XSpreadsheetView
CPPUNIT_TEST(testGetSetActiveSheet);
@@ -67,12 +74,27 @@ ScTabViewObj::ScTabViewObj()
uno::Reference< uno::XInterface > ScTabViewObj::init()
{
- uno::Reference< sheet::XSpreadsheetDocument > xSheetDoc(mxComponent, uno::UNO_QUERY_THROW);
- uno::Reference< frame::XModel > xModel(xSheetDoc, uno::UNO_QUERY_THROW);
+ uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW);
+ CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is());
+
+ uno::Reference<frame::XModel> xModel(xDoc, uno::UNO_QUERY_THROW);
return xModel->getCurrentController();
}
+uno::Reference<uno::XInterface> ScTabViewObj::getXSpreadsheet(const sal_Int16 nNumber)
+{
+ uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW);
+ CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is());
+
+ uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_QUERY_THROW);
+ xSheets->insertNewByName("Sheet2", 2);
+ uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), UNO_QUERY_THROW);
+ uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(nNumber), UNO_QUERY_THROW);
+
+ return xSheet;
+}
+
void ScTabViewObj::setUp()
{
CalcUnoApiTest::setUp();
@@ -87,7 +109,7 @@ void ScTabViewObj::tearDown()
CPPUNIT_TEST_SUITE_REGISTRATION(ScTabViewObj);
-} // end namespace
+} // namespace sc_apitest
CPPUNIT_PLUGIN_IMPLEMENT();
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: */