Kaydet (Commit) 34568738 authored tarafından Jens Carl's avatar Jens Carl

tdf#45904 Move _XActivationBroadcaster Java tests to C++

Change-Id: If8f44b24e58663bacb1cf6b2a1ec533e87fb8a38
Reviewed-on: https://gerrit.libreoffice.org/52216Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarJens Carl <j.carl43@gmx.de>
üst 783bc627
/* -*- 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: */
......@@ -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 \
......
......@@ -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()"
......
/*
* 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
......@@ -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();
......
......@@ -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 \
......
/* -*- 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: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment