sc/qa/unit/tiledrendering/data/numlocale.xlsx |binary sc/qa/unit/tiledrendering/tiledrendering.cxx | 77 +++++++++++++++++++++++++- 2 files changed, 76 insertions(+), 1 deletion(-)
New commits: commit 00c790b36b48732a80b56d0b33c765abc53cf624 Author: Szymon Kłos <[email protected]> AuthorDate: Tue Apr 30 09:51:18 2024 +0200 Commit: Szymon Kłos <[email protected]> CommitDate: Tue May 7 07:56:07 2024 +0200 lok: test number formats with different locale This is followup for the fix in commit 7836cb7e90d0214cac08228f5e527322ed6f955c lok: save correct number format in multi-lang session Change-Id: I6016425d37b1ee1707ed8920811e8741c9267ee7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166910 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Szymon Kłos <[email protected]> diff --git a/sc/qa/unit/tiledrendering/data/numlocale.xlsx b/sc/qa/unit/tiledrendering/data/numlocale.xlsx new file mode 100644 index 000000000000..c69f74e32301 Binary files /dev/null and b/sc/qa/unit/tiledrendering/data/numlocale.xlsx differ diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx index 65844f2546f8..53a558b6ea52 100644 --- a/sc/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx @@ -25,6 +25,8 @@ #include <sfx2/dispatch.hxx> #include <sfx2/viewfrm.hxx> #include <svl/stritem.hxx> +#include <svl/numformat.hxx> +#include <svl/zformat.hxx> #include <comphelper/lok.hxx> #include <comphelper/propertyvalue.hxx> @@ -44,6 +46,7 @@ #include <test/lokcallback.hxx> #include <osl/file.hxx> #include <unotools/tempfile.hxx> +#include <unotools/syslocaleoptions.hxx> #include <chrono> #include <cstddef> @@ -181,6 +184,7 @@ public: void testExtendedAreasDontOverlap(); void testEditShapeText(); void testCopyMultiSelection(); + void testNumberFormatLocaleMultiUser(); CPPUNIT_TEST_SUITE(ScTiledRenderingTest); CPPUNIT_TEST(testRowColumnHeaders); @@ -263,6 +267,7 @@ public: CPPUNIT_TEST(testExtendedAreasDontOverlap); CPPUNIT_TEST(testEditShapeText); CPPUNIT_TEST(testCopyMultiSelection); + CPPUNIT_TEST(testNumberFormatLocaleMultiUser); CPPUNIT_TEST_SUITE_END(); private: @@ -305,7 +310,7 @@ void ScTiledRenderingTest::tearDown() UnoApiXmlTest::tearDown(); } -ScModelObj* ScTiledRenderingTest::createDoc(const char* pName) +ScModelObj* ScTiledRenderingTest::createDoc(const char* pName)//, const char* pLang = nullptr) { loadFromURL(OUString::createFromAscii(pName)); @@ -4162,6 +4167,76 @@ void ScTiledRenderingTest::testCopyMultiSelection() CPPUNIT_ASSERT(!xTransferable2->isComplex()); } +void ScTiledRenderingTest::testNumberFormatLocaleMultiUser() +{ + { + // setup core language to FR as it will be the first session + SvtSysLocaleOptions aLocalOptions; + aLocalOptions.SetLocaleConfigString("fr-FR"); + aLocalOptions.SetUILocaleConfigString("fr-FR"); + aLocalOptions.Commit(); + + loadFromURL(u"numlocale.xlsx"); + + ScModelObj* pModelObj = comphelper::getFromUnoTunnel<ScModelObj>(mxComponent); + CPPUNIT_ASSERT(pModelObj); + + pModelObj->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>()); + ScDocument* pDoc = pModelObj->GetDocument(); + + int nViewFR = SfxLokHelper::getView(); + ViewCallback aView1; + SfxViewShell* pViewFR = SfxViewShell::Current(); + pViewFR->SetLOKLocale("fr-FR"); + + // modify G12 with FR and use French keywords in the format + SfxLokHelper::setView(nViewFR); + + sal_Int32 nCheckPos; + SvNumFormatType nType; + sal_uInt32 nFormat; + OUString aNumberFormat("JJ/MM/AAAA"); + SvNumberFormatter* pFormatter = pDoc->GetFormatTable(); + pFormatter->PutEntry(aNumberFormat, nCheckPos, nType, nFormat); + ScAddress aCellPos1(/*nColP=*/6, /*nRowP=*/11, /*nTabP=*/0); + pDoc->SetNumberFormat(aCellPos1, nFormat); + + Scheduler::ProcessEventsToIdle(); + } + + { + // now setup DE language in core + SvtSysLocaleOptions aLocalOptions; + aLocalOptions.SetLocaleConfigString("de-DE"); + aLocalOptions.SetUILocaleConfigString("de-DE"); + aLocalOptions.Commit(); + + // save and reopen + // .uno:Save modifies the original file, make a copy first + saveAndReload("Calc MS Excel 2007 VBA XML"); + + ScModelObj* pModelObj = comphelper::getFromUnoTunnel<ScModelObj>(mxComponent); + CPPUNIT_ASSERT(pModelObj); + + ScTabViewShell* pView = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current()); + CPPUNIT_ASSERT(pView); + + Scheduler::ProcessEventsToIdle(); + + uno::Sequence<beans::PropertyValue> aArgs; + dispatchCommand(mxComponent, ".uno:Save", aArgs); + + Scheduler::ProcessEventsToIdle(); + + ScDocument* pDoc = pModelObj->GetDocument(); + + // verify that format is correct (German), doesn't have any "string" inside + sal_uInt32 nNumberFormat = pDoc->GetNumberFormat(/*col=*/6, /*row=*/11, /*tab=*/0); + const SvNumberformat* pNumberFormat = pDoc->GetFormatTable()->GetEntry(nNumberFormat); + CPPUNIT_ASSERT_EQUAL(OUString("TT.MM.JJ"), pNumberFormat->GetFormatstring()); + } +} + } CPPUNIT_TEST_SUITE_REGISTRATION(ScTiledRenderingTest);
