sc/qa/unit/tiledrendering/data/numlocale.xlsx |binary
 sc/qa/unit/tiledrendering/tiledrendering.cxx  |   87 ++++++++++++++++++++++++--
 2 files changed, 83 insertions(+), 4 deletions(-)

New commits:
commit c1c32bbbe24ebd4be00c9c3bb38de1dc748bd2b6
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Tue Apr 30 09:51:18 2024 +0200
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Tue Apr 30 15:55:57 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/+/166921
    Tested-by: Jenkins
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>

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 651df397cc71..6236307016f2 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx
@@ -21,6 +21,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>
@@ -37,8 +39,7 @@
 #include <tools/json_writer.hxx>
 #include <postit.hxx>
 #include <test/lokcallback.hxx>
-
-#include <cstddef>
+#include <unotools/syslocaleoptions.hxx>
 
 #include <attrib.hxx>
 #include <scitems.hxx>
@@ -141,13 +142,21 @@ void ScTiledRenderingTest::tearDown()
     UnoApiXmlTest::tearDown();
 }
 
-ScModelObj* ScTiledRenderingTest::createDoc(const char* pName)
+ScModelObj* ScTiledRenderingTest::createDoc(const char* pName)//, const char* 
pLang = nullptr)
 {
     loadFromFile(OUString::createFromAscii(pName));
 
     ScModelObj* pModelObj = 
comphelper::getFromUnoTunnel<ScModelObj>(mxComponent);
     CPPUNIT_ASSERT(pModelObj);
-    
pModelObj->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
+
+    auto aProperties = uno::Sequence<beans::PropertyValue>();//pLang ? 1 : 0);
+    // if (pLang)
+    // {
+    //     aProperties[0] = beans::PropertyValue(
+    //         "Language", -1, OUString::createFromAscii(pLang), 
beans::PropertyState_DIRECT_VALUE);
+    // }
+
+    pModelObj->initializeForTiledRendering(aProperties);
     return pModelObj;
 }
 
@@ -3889,6 +3898,76 @@ CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, 
testEditShapeText)
     CPPUNIT_ASSERT_MESSAGE("Text is not visible", aBitmapBefore != 
aBitmapAfter);
 }
 
+CPPUNIT_TEST_FIXTURE(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();
+
+        loadFromFile(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_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to