sc/qa/unit/tiledrendering/data/decimal-separator.ods |binary sc/qa/unit/tiledrendering2/tiledrendering2.cxx | 183 +++++++++++++++++++ 2 files changed, 183 insertions(+)
New commits: commit 5a3d715524c7b3794a24613ca55062bc2f808fec Author: Gökay Şatır <gokaysa...@collabora.com> AuthorDate: Tue Feb 4 13:56:16 2025 +0300 Commit: Gökay ŞATIR <gokaysa...@gmail.com> CommitDate: Tue Feb 25 11:24:43 2025 +0100 Add a test for decimal separator info. Ensure that decimal separator of the number inside the cell is also sent to the server. Signed-off-by: Gökay Şatır <gokaysa...@collabora.com> Change-Id: I5864b86ae2d1c4a582a86a0f2488f7229be7bdaa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181094 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181776 Tested-by: Miklos Vajna <vmik...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182143 Tested-by: Jenkins diff --git a/sc/qa/unit/tiledrendering/data/decimal-separator.ods b/sc/qa/unit/tiledrendering/data/decimal-separator.ods new file mode 100644 index 000000000000..6f4baedd63f1 Binary files /dev/null and b/sc/qa/unit/tiledrendering/data/decimal-separator.ods differ diff --git a/sc/qa/unit/tiledrendering2/tiledrendering2.cxx b/sc/qa/unit/tiledrendering2/tiledrendering2.cxx new file mode 100644 index 000000000000..5c9e8b539822 --- /dev/null +++ b/sc/qa/unit/tiledrendering2/tiledrendering2.cxx @@ -0,0 +1,183 @@ +/* -*- 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 <test/unoapixml_test.hxx> + +#include <boost/property_tree/json_parser.hpp> + +#include <LibreOfficeKit/LibreOfficeKitEnums.h> +#include <comphelper/lok.hxx> +#include <comphelper/servicehelper.hxx> +#include <comphelper/propertyvalue.hxx> +#include <sfx2/lokhelper.hxx> +#include <test/lokcallback.hxx> +#include <vcl/scheduler.hxx> +#include <tabvwsh.hxx> + +#include <docuno.hxx> + +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("/sc/qa/unit/tiledrendering2/data/") +{ +} + +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<ScModelObj>(mxComponent); + CPPUNIT_ASSERT(pModelObj); + pModelObj->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>()); + return pModelObj; +} + +/// A view callback tracks callbacks invoked on one specific view. +class ViewCallback final +{ + SfxViewShell* mpViewShell; + int mnView; + +public: + std::map<std::string, boost::property_tree::ptree> m_aStateChanges; + std::string decimalSeparator; + 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<ViewCallback*>(pData)->callbackImpl(nType, pPayload); + } + + void callbackImpl(int nType, const char* pPayload) + { + switch (nType) + { + 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<std::string>(); + m_aStateChanges[aCommandName] = aTree; + } + break; + case LOK_CALLBACK_JSDIALOG: + { + std::stringstream aStream(pPayload); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + if (aTree.get_child("jsontype").get_value<std::string>() == "formulabar") + { + if (aTree.find("data") != aTree.not_found()) + { + if (aTree.get_child("data").find("separator") + != aTree.get_child("data").not_found()) + { + decimalSeparator = aTree.get_child("data") + .get_child("separator") + .get_value<std::string>(); + } + } + } + } + break; + } + } +}; + +CPPUNIT_TEST_FIXTURE(Test, testDecimalSeparatorInfo) +{ + createDoc("decimal-separator.ods"); + + ViewCallback aView1; + + // Go to cell A1. + uno::Sequence<beans::PropertyValue> aPropertyValues + = { comphelper::makePropertyValue("ToPoint", OUString("$A$1")) }; + dispatchCommand(mxComponent, ".uno:GoToCell", aPropertyValues); + + // Cell A1 has language set to English. Decimal separator should be ".". + CPPUNIT_ASSERT_EQUAL(std::string("."), aView1.decimalSeparator); + + // Go to cell B1. + aPropertyValues = { comphelper::makePropertyValue("ToPoint", OUString("B$1")) }; + dispatchCommand(mxComponent, ".uno:GoToCell", aPropertyValues); + + // Cell B1 has language set to Turkish. Decimal separator should be ",". + CPPUNIT_ASSERT_EQUAL(std::string(","), aView1.decimalSeparator); +} +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */