From 81260b12666853bb9c21da487657e169cac6d4d9 Mon Sep 17 00:00:00 2001 From: Jens Carl Date: Fri, 29 Jun 2018 02:47:08 +0000 Subject: tdf#45904 Move _XDocumentAuditing Java test to C++ Change-Id: Ic03e42c9c2ff27579b442dc8d1408deaea839ec4 Reviewed-on: https://gerrit.libreoffice.org/56644 Tested-by: Jenkins Reviewed-by: Jens Carl --- test/source/sheet/xdocumentauditing.cxx | 141 ++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 test/source/sheet/xdocumentauditing.cxx (limited to 'test/source') diff --git a/test/source/sheet/xdocumentauditing.cxx b/test/source/sheet/xdocumentauditing.cxx new file mode 100644 index 000000000000..7b1565a62a43 --- /dev/null +++ b/test/source/sheet/xdocumentauditing.cxx @@ -0,0 +1,141 @@ +/* -*- 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 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XDocumentAuditing::dispatch(const uno::Reference& xFrame, + const uno::Sequence& rArguments) +{ + uno::Reference xContext = ::comphelper::getProcessComponentContext(); + uno::Reference xDispatchHelper(frame::DispatchHelper::create(xContext), + UNO_QUERY_THROW); + CPPUNIT_ASSERT(xDispatchHelper.is()); + + uno::Reference xDispatchProvider(xFrame, UNO_QUERY_THROW); + CPPUNIT_ASSERT(xDispatchProvider.is()); + + xDispatchHelper->executeDispatch(xDispatchProvider, ".uno:AutoRefreshArrows", "", 0, + rArguments); +} + +bool XDocumentAuditing::hasRightAmountOfShapes(const uno::Reference& xDrawPage, + const sal_Int32& nElementCount, + const sal_Int32& nShapes) +{ + const sal_Int32 nCount = xDrawPage->getCount(); + if (nCount != nElementCount + nShapes) + return false; + else + { + if (nShapes >= 0) + { + for (sal_Int32 i = nElementCount; i < nCount; i++) + { + uno::Reference xShape(xDrawPage->getByIndex(i), UNO_QUERY_THROW); + m_Position = xShape->getPosition(); + } + } + } + return true; +} + +void XDocumentAuditing::testRefreshArrows() +{ + uno::Reference xDocumentAuditing(init(), UNO_QUERY_THROW); + + uno::Reference xDoc(xDocumentAuditing, UNO_QUERY_THROW); + uno::Reference xSheets(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference xIA(xSheets, UNO_QUERY_THROW); + uno::Reference xSheet1(xIA->getByIndex(0), UNO_QUERY_THROW); + uno::Reference xSheet2(xIA->getByIndex(1), UNO_QUERY_THROW); + + uno::Reference xDPS(xDocumentAuditing, UNO_QUERY_THROW); + uno::Reference xDrawPage(xDPS->getDrawPages()->getByIndex(1), + UNO_QUERY_THROW); + + sal_Int32 nDrawPageElementCount = 0; + if (xDrawPage->hasElements()) + nDrawPageElementCount = xDrawPage->getCount(); + + uno::Sequence aPropertyValue(1); + uno::Any aValue; + aValue <<= false; + aPropertyValue[0].Name = "AutoRefreshArrows"; + aPropertyValue[0].Value = aValue; + uno::Reference xModel(xDocumentAuditing, UNO_QUERY_THROW); + dispatch(xModel->getCurrentController()->getFrame(), aPropertyValue); + + xSheet1->getCellByPosition(6, 6)->setValue(9); + uno::Reference xNA1(xSheet1, UNO_QUERY_THROW); + OUString sSheet1Name = xNA1->getName(); + + xSheet2->getCellByPosition(6, 6)->setValue(16); + xSheet2->getCellByPosition(6, 7)->setFormula("= SQRT(G7)"); + + uno::Reference xSheetAuditing(xSheet2, UNO_QUERY_THROW); + xSheetAuditing->showPrecedents(table::CellAddress(1, 6, 7)); + bool bResult = hasRightAmountOfShapes(xDrawPage, nDrawPageElementCount, 1); + CPPUNIT_ASSERT_MESSAGE("Wrong amount of shapes on page", bResult); + awt::Point Position0 = m_Position; + + CPPUNIT_ASSERT_DOUBLES_EQUAL(4, xSheet2->getCellByPosition(6, 7)->getValue(), 0.1); + xSheet2->getCellByPosition(6, 7)->setFormula("= SQRT(" + sSheet1Name + ".G7)"); + CPPUNIT_ASSERT_DOUBLES_EQUAL(3, xSheet2->getCellByPosition(6, 7)->getValue(), 0.1); + + bResult = hasRightAmountOfShapes(xDrawPage, nDrawPageElementCount, 1); + CPPUNIT_ASSERT_MESSAGE("Wrong amount of shapes on page", bResult); + awt::Point Position1 = m_Position; + + CPPUNIT_ASSERT_MESSAGE("Arrow has been refreshed", + Position0.X == Position1.X && Position0.Y == Position1.Y); + + xDocumentAuditing->refreshArrows(); + + bResult = hasRightAmountOfShapes(xDrawPage, nDrawPageElementCount, 1); + CPPUNIT_ASSERT_MESSAGE("Wrong amount of shapes on page", bResult); + awt::Point Position2 = m_Position; + + CPPUNIT_ASSERT_MESSAGE("Arrow has not been refreshed", + Position1.X != Position2.X || Position1.Y != Position2.Y); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ -- cgit