From 4d41da669d443ecaffb344964a272630ccdca634 Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Thu, 21 Nov 2024 00:39:29 +0100 Subject: CppunitTest_sc_tiledrendering2: move to tiledrendering folder In preparation for a follow-up commit Change-Id: I8e7852b1861d6879e0dcda8c6fddd947bec3c959 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176876 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- sc/CppunitTest_sc_tiledrendering2.mk | 2 +- sc/qa/unit/tiledrendering/data/chart.ods | Bin 0 -> 16569 bytes sc/qa/unit/tiledrendering/data/multi-selection.ods | Bin 0 -> 8400 bytes sc/qa/unit/tiledrendering/tiledrendering2.cxx | 219 +++++++++++++++++++++ sc/qa/unit/tiledrendering2/data/chart.ods | Bin 16569 -> 0 bytes .../unit/tiledrendering2/data/multi-selection.ods | Bin 8400 -> 0 bytes sc/qa/unit/tiledrendering2/tiledrendering2.cxx | 219 --------------------- 7 files changed, 220 insertions(+), 220 deletions(-) create mode 100644 sc/qa/unit/tiledrendering/data/chart.ods create mode 100644 sc/qa/unit/tiledrendering/data/multi-selection.ods create mode 100644 sc/qa/unit/tiledrendering/tiledrendering2.cxx delete mode 100644 sc/qa/unit/tiledrendering2/data/chart.ods delete mode 100644 sc/qa/unit/tiledrendering2/data/multi-selection.ods delete mode 100644 sc/qa/unit/tiledrendering2/tiledrendering2.cxx diff --git a/sc/CppunitTest_sc_tiledrendering2.mk b/sc/CppunitTest_sc_tiledrendering2.mk index d360780428a6..9acb0bffe924 100644 --- a/sc/CppunitTest_sc_tiledrendering2.mk +++ b/sc/CppunitTest_sc_tiledrendering2.mk @@ -14,7 +14,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,sc_tiledrendering2)) $(eval $(call gb_CppunitTest_use_common_precompiled_header,sc_tiledrendering2)) $(eval $(call gb_CppunitTest_add_exception_objects,sc_tiledrendering2, \ - sc/qa/unit/tiledrendering2/tiledrendering2 \ + sc/qa/unit/tiledrendering/tiledrendering2 \ )) $(eval $(call gb_CppunitTest_use_libraries,sc_tiledrendering2, \ diff --git a/sc/qa/unit/tiledrendering/data/chart.ods b/sc/qa/unit/tiledrendering/data/chart.ods new file mode 100644 index 000000000000..dcd1194811d7 Binary files /dev/null and b/sc/qa/unit/tiledrendering/data/chart.ods differ diff --git a/sc/qa/unit/tiledrendering/data/multi-selection.ods b/sc/qa/unit/tiledrendering/data/multi-selection.ods new file mode 100644 index 000000000000..9436aaf93c26 Binary files /dev/null and b/sc/qa/unit/tiledrendering/data/multi-selection.ods differ diff --git a/sc/qa/unit/tiledrendering/tiledrendering2.cxx b/sc/qa/unit/tiledrendering/tiledrendering2.cxx new file mode 100644 index 000000000000..878379b089fe --- /dev/null +++ b/sc/qa/unit/tiledrendering/tiledrendering2.cxx @@ -0,0 +1,219 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 + +using namespace com::sun::star; + +namespace +{ +class Test : public UnoApiXmlTest +{ +public: + Test(); + void setUp() override; + void tearDown() override; + + ScModelObj* createDoc(const char* pName); +}; + +Test::Test() + : UnoApiXmlTest(u"/sc/qa/unit/tiledrendering/data/"_ustr) +{ +} + +void Test::setUp() +{ + UnoApiXmlTest::setUp(); + + comphelper::LibreOfficeKit::setActive(true); +} + +void Test::tearDown() +{ + if (mxComponent.is()) + { + mxComponent->dispose(); + mxComponent.clear(); + } + + comphelper::LibreOfficeKit::resetCompatFlag(); + + comphelper::LibreOfficeKit::setActive(false); + + UnoApiXmlTest::tearDown(); +} + +ScModelObj* Test::createDoc(const char* pName) +{ + loadFromFile(OUString::createFromAscii(pName)); + + ScModelObj* pModelObj = comphelper::getFromUnoTunnel(mxComponent); + CPPUNIT_ASSERT(pModelObj); + pModelObj->initializeForTiledRendering(uno::Sequence()); + return pModelObj; +} + +/// A view callback tracks callbacks invoked on one specific view. +class ViewCallback final +{ + SfxViewShell* mpViewShell; + int mnView; + +public: + std::map m_aStateChanges; + tools::Rectangle m_aCellCursorBounds; + TestLokCallbackWrapper m_callbackWrapper; + + ViewCallback() + : m_callbackWrapper(&callback, this) + { + mpViewShell = SfxViewShell::Current(); + mpViewShell->setLibreOfficeKitViewCallback(&m_callbackWrapper); + mnView = SfxLokHelper::getView(); + m_callbackWrapper.setLOKViewId(mnView); + } + + ~ViewCallback() + { + if (mpViewShell) + { + SfxLokHelper::setView(mnView); + mpViewShell->setLibreOfficeKitViewCallback(nullptr); + } + } + + static void callback(int nType, const char* pPayload, void* pData) + { + static_cast(pData)->callbackImpl(nType, pPayload); + } + + void callbackImpl(int nType, const char* pPayload) + { + switch (nType) + { + case LOK_CALLBACK_CELL_CURSOR: + { + uno::Sequence aSeq = comphelper::string::convertCommaSeparated( + OUString::createFromAscii(pPayload)); + m_aCellCursorBounds = tools::Rectangle(); + if (aSeq.getLength() >= 4) + { + m_aCellCursorBounds.SetLeft(aSeq[0].toInt32()); + m_aCellCursorBounds.SetTop(aSeq[1].toInt32()); + m_aCellCursorBounds.setWidth(aSeq[2].toInt32()); + m_aCellCursorBounds.setHeight(aSeq[3].toInt32()); + } + } + break; + case LOK_CALLBACK_STATE_CHANGED: + { + std::stringstream aStream(pPayload); + if (!aStream.str().starts_with("{")) + { + break; + } + + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + auto it = aTree.find("commandName"); + if (it == aTree.not_found()) + { + break; + } + + std::string aCommandName = it->second.get_value(); + m_aStateChanges[aCommandName] = aTree; + } + break; + } + } +}; + +CPPUNIT_TEST_FIXTURE(Test, testSidebarLocale) +{ + ScModelObj* pModelObj = createDoc("chart.ods"); + int nView1 = SfxLokHelper::getView(); + ViewCallback aView1; + SfxViewShell* pView1 = SfxViewShell::Current(); + pView1->SetLOKLocale(u"en-US"_ustr); + SfxLokHelper::createView(); + ViewCallback aView2; + SfxViewShell* pView2 = SfxViewShell::Current(); + pView2->SetLOKLocale(u"de-DE"_ustr); + TestLokCallbackWrapper::InitializeSidebar(); + Scheduler::ProcessEventsToIdle(); + aView2.m_aStateChanges.clear(); + + pModelObj->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONDOWN, /*x=*/1, /*y=*/1, /*count=*/2, + /*buttons=*/1, /*modifier=*/0); + pModelObj->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONUP, /*x=*/1, /*y=*/1, /*count=*/2, + /*buttons=*/1, /*modifier=*/0); + SfxLokHelper::setView(nView1); + Scheduler::ProcessEventsToIdle(); + + auto it = aView2.m_aStateChanges.find(".uno:Sidebar"); + CPPUNIT_ASSERT(it != aView2.m_aStateChanges.end()); + std::string aLocale = it->second.get("locale"); + CPPUNIT_ASSERT_EQUAL(std::string("de-DE"), aLocale); +} + +CPPUNIT_TEST_FIXTURE(Test, testCopyMultiSelection) +{ + // Given a document with A1 and A3 as selected cells: + ScModelObj* pModelObj = createDoc("multi-selection.ods"); + ViewCallback aView1; + // Get the center of A3: + uno::Sequence aPropertyValues = { + comphelper::makePropertyValue(u"ToPoint"_ustr, u"$A$3"_ustr), + }; + dispatchCommand(mxComponent, u".uno:GoToCell"_ustr, aPropertyValues); + Point aPoint = aView1.m_aCellCursorBounds.Center(); + // Go to A1: + aPropertyValues = { + comphelper::makePropertyValue(u"ToPoint"_ustr, u"$A$1"_ustr), + }; + dispatchCommand(mxComponent, u".uno:GoToCell"_ustr, aPropertyValues); + // Ctrl-click on A3: + int nCtrl = KEY_MOD1; + pModelObj->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONDOWN, aPoint.getX(), aPoint.getY(), 1, + MOUSE_LEFT, nCtrl); + + // When getting the selection: + uno::Reference xTransferable = pModelObj->getSelection(); + + // Make sure we get A1+A3 instead of an error: + CPPUNIT_ASSERT(xTransferable.is()); + + // Also make sure that just 2 cells is classified as a simple selection: + uno::Reference xTransferable2(xTransferable, uno::UNO_QUERY); + CPPUNIT_ASSERT(xTransferable2.is()); + // Without the fix, the text selection was complex. + CPPUNIT_ASSERT(!xTransferable2->isComplex()); +} +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/unit/tiledrendering2/data/chart.ods b/sc/qa/unit/tiledrendering2/data/chart.ods deleted file mode 100644 index dcd1194811d7..000000000000 Binary files a/sc/qa/unit/tiledrendering2/data/chart.ods and /dev/null differ diff --git a/sc/qa/unit/tiledrendering2/data/multi-selection.ods b/sc/qa/unit/tiledrendering2/data/multi-selection.ods deleted file mode 100644 index 9436aaf93c26..000000000000 Binary files a/sc/qa/unit/tiledrendering2/data/multi-selection.ods and /dev/null differ diff --git a/sc/qa/unit/tiledrendering2/tiledrendering2.cxx b/sc/qa/unit/tiledrendering2/tiledrendering2.cxx deleted file mode 100644 index b6f084738b43..000000000000 --- a/sc/qa/unit/tiledrendering2/tiledrendering2.cxx +++ /dev/null @@ -1,219 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * 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 - -using namespace com::sun::star; - -namespace -{ -class Test : public UnoApiXmlTest -{ -public: - Test(); - void setUp() override; - void tearDown() override; - - ScModelObj* createDoc(const char* pName); -}; - -Test::Test() - : UnoApiXmlTest(u"/sc/qa/unit/tiledrendering2/data/"_ustr) -{ -} - -void Test::setUp() -{ - UnoApiXmlTest::setUp(); - - comphelper::LibreOfficeKit::setActive(true); -} - -void Test::tearDown() -{ - if (mxComponent.is()) - { - mxComponent->dispose(); - mxComponent.clear(); - } - - comphelper::LibreOfficeKit::resetCompatFlag(); - - comphelper::LibreOfficeKit::setActive(false); - - UnoApiXmlTest::tearDown(); -} - -ScModelObj* Test::createDoc(const char* pName) -{ - loadFromFile(OUString::createFromAscii(pName)); - - ScModelObj* pModelObj = comphelper::getFromUnoTunnel(mxComponent); - CPPUNIT_ASSERT(pModelObj); - pModelObj->initializeForTiledRendering(uno::Sequence()); - return pModelObj; -} - -/// A view callback tracks callbacks invoked on one specific view. -class ViewCallback final -{ - SfxViewShell* mpViewShell; - int mnView; - -public: - std::map m_aStateChanges; - tools::Rectangle m_aCellCursorBounds; - TestLokCallbackWrapper m_callbackWrapper; - - ViewCallback() - : m_callbackWrapper(&callback, this) - { - mpViewShell = SfxViewShell::Current(); - mpViewShell->setLibreOfficeKitViewCallback(&m_callbackWrapper); - mnView = SfxLokHelper::getView(); - m_callbackWrapper.setLOKViewId(mnView); - } - - ~ViewCallback() - { - if (mpViewShell) - { - SfxLokHelper::setView(mnView); - mpViewShell->setLibreOfficeKitViewCallback(nullptr); - } - } - - static void callback(int nType, const char* pPayload, void* pData) - { - static_cast(pData)->callbackImpl(nType, pPayload); - } - - void callbackImpl(int nType, const char* pPayload) - { - switch (nType) - { - case LOK_CALLBACK_CELL_CURSOR: - { - uno::Sequence aSeq = comphelper::string::convertCommaSeparated( - OUString::createFromAscii(pPayload)); - m_aCellCursorBounds = tools::Rectangle(); - if (aSeq.getLength() >= 4) - { - m_aCellCursorBounds.SetLeft(aSeq[0].toInt32()); - m_aCellCursorBounds.SetTop(aSeq[1].toInt32()); - m_aCellCursorBounds.setWidth(aSeq[2].toInt32()); - m_aCellCursorBounds.setHeight(aSeq[3].toInt32()); - } - } - break; - case LOK_CALLBACK_STATE_CHANGED: - { - std::stringstream aStream(pPayload); - if (!aStream.str().starts_with("{")) - { - break; - } - - boost::property_tree::ptree aTree; - boost::property_tree::read_json(aStream, aTree); - auto it = aTree.find("commandName"); - if (it == aTree.not_found()) - { - break; - } - - std::string aCommandName = it->second.get_value(); - m_aStateChanges[aCommandName] = aTree; - } - break; - } - } -}; - -CPPUNIT_TEST_FIXTURE(Test, testSidebarLocale) -{ - ScModelObj* pModelObj = createDoc("chart.ods"); - int nView1 = SfxLokHelper::getView(); - ViewCallback aView1; - SfxViewShell* pView1 = SfxViewShell::Current(); - pView1->SetLOKLocale(u"en-US"_ustr); - SfxLokHelper::createView(); - ViewCallback aView2; - SfxViewShell* pView2 = SfxViewShell::Current(); - pView2->SetLOKLocale(u"de-DE"_ustr); - TestLokCallbackWrapper::InitializeSidebar(); - Scheduler::ProcessEventsToIdle(); - aView2.m_aStateChanges.clear(); - - pModelObj->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONDOWN, /*x=*/1, /*y=*/1, /*count=*/2, - /*buttons=*/1, /*modifier=*/0); - pModelObj->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONUP, /*x=*/1, /*y=*/1, /*count=*/2, - /*buttons=*/1, /*modifier=*/0); - SfxLokHelper::setView(nView1); - Scheduler::ProcessEventsToIdle(); - - auto it = aView2.m_aStateChanges.find(".uno:Sidebar"); - CPPUNIT_ASSERT(it != aView2.m_aStateChanges.end()); - std::string aLocale = it->second.get("locale"); - CPPUNIT_ASSERT_EQUAL(std::string("de-DE"), aLocale); -} - -CPPUNIT_TEST_FIXTURE(Test, testCopyMultiSelection) -{ - // Given a document with A1 and A3 as selected cells: - ScModelObj* pModelObj = createDoc("multi-selection.ods"); - ViewCallback aView1; - // Get the center of A3: - uno::Sequence aPropertyValues = { - comphelper::makePropertyValue(u"ToPoint"_ustr, u"$A$3"_ustr), - }; - dispatchCommand(mxComponent, u".uno:GoToCell"_ustr, aPropertyValues); - Point aPoint = aView1.m_aCellCursorBounds.Center(); - // Go to A1: - aPropertyValues = { - comphelper::makePropertyValue(u"ToPoint"_ustr, u"$A$1"_ustr), - }; - dispatchCommand(mxComponent, u".uno:GoToCell"_ustr, aPropertyValues); - // Ctrl-click on A3: - int nCtrl = KEY_MOD1; - pModelObj->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONDOWN, aPoint.getX(), aPoint.getY(), 1, - MOUSE_LEFT, nCtrl); - - // When getting the selection: - uno::Reference xTransferable = pModelObj->getSelection(); - - // Make sure we get A1+A3 instead of an error: - CPPUNIT_ASSERT(xTransferable.is()); - - // Also make sure that just 2 cells is classified as a simple selection: - uno::Reference xTransferable2(xTransferable, uno::UNO_QUERY); - CPPUNIT_ASSERT(xTransferable2.is()); - // Without the fix, the text selection was complex. - CPPUNIT_ASSERT(!xTransferable2->isComplex()); -} -} - -CPPUNIT_PLUGIN_IMPLEMENT(); - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3