[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.1' - 2 commits - desktop/CppunitTest_desktop_app.mk desktop/inc desktop/qa desktop/source include/LibreOfficeKit libreofficekit/qa vcl/source

Jan Holesovsky kendy at collabora.com
Fri Mar 24 20:07:19 UTC 2017


 desktop/CppunitTest_desktop_app.mk          |    1 
 desktop/inc/lib/init.hxx                    |    5 +
 desktop/qa/desktop_lib/test_desktop_lib.cxx |   30 +++++++++
 desktop/source/lib/init.cxx                 |   60 ++++++++++++++++++
 include/LibreOfficeKit/LibreOfficeKit.hxx   |    4 +
 libreofficekit/qa/data/empty.ods            |binary
 libreofficekit/qa/unit/tiledrendering.cxx   |   89 ++++++++++++++++++++++++++++
 vcl/source/app/svapp.cxx                    |    9 ++
 8 files changed, 197 insertions(+), 1 deletion(-)

New commits:
commit 87ab932064218ce209a05a34db1be5b69776a2f4
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Fri Mar 24 16:23:02 2017 +0100

    lok: Unit test for setting of the language during load of the document.
    
    Change-Id: Idf4d3ba6b55be1f885f9d8fc89157e7e498d4e42

diff --git a/libreofficekit/qa/data/empty.ods b/libreofficekit/qa/data/empty.ods
new file mode 100644
index 000000000000..a36d1f97c405
Binary files /dev/null and b/libreofficekit/qa/data/empty.ods differ
diff --git a/libreofficekit/qa/unit/tiledrendering.cxx b/libreofficekit/qa/unit/tiledrendering.cxx
index 0a93c4651d77..ed94e72cbd33 100644
--- a/libreofficekit/qa/unit/tiledrendering.cxx
+++ b/libreofficekit/qa/unit/tiledrendering.cxx
@@ -67,6 +67,7 @@ public:
     void testImpressSlideNames( Office* pOffice );
     void testCalcSheetNames( Office* pOffice );
     void testPaintPartTile( Office* pOffice );
+    void testDocumentLoadLanguage(Office* pOffice);
 #if 0
     void testOverlay( Office* pOffice );
 #endif
@@ -94,6 +95,7 @@ void TiledRenderingTest::runAllTests()
     testImpressSlideNames( pOffice.get() );
     testCalcSheetNames( pOffice.get() );
     testPaintPartTile( pOffice.get() );
+    testDocumentLoadLanguage(pOffice.get());
 #if 0
     testOverlay( pOffice.get() );
 #endif
@@ -212,6 +214,93 @@ void TiledRenderingTest::testPaintPartTile(Office* pOffice)
     pDocument->paintPartTile(aBuffer.data(), /*nPart=*/0, nCanvasWidth, nCanvasHeight, /*nTilePosX=*/0, /*nTilePosY=*/0, /*nTileWidth=*/3840, /*nTileHeight=*/3840);
 }
 
+namespace {
+
+void processEventsToIdle()
+{
+    typedef void (ProcessEventsToIdleFn)(void);
+    static ProcessEventsToIdleFn *processFn = nullptr;
+    if (!processFn)
+    {
+        void *me = dlopen(nullptr, RTLD_NOW);
+        processFn = reinterpret_cast<ProcessEventsToIdleFn *>(dlsym(me, "unit_lok_process_events_to_idle"));
+    }
+
+    CPPUNIT_ASSERT(processFn);
+
+    (*processFn)();
+}
+
+void insertString(Document& rDocument, const std::string& s)
+{
+    for (const char c : s)
+    {
+        rDocument.postKeyEvent(LOK_KEYEVENT_KEYINPUT, c, 0);
+        rDocument.postKeyEvent(LOK_KEYEVENT_KEYUP, c, 0);
+    }
+    processEventsToIdle();
+}
+
+}
+
+void TiledRenderingTest::testDocumentLoadLanguage(Office* pOffice)
+{
+    const string sDocPath = m_sSrcRoot + "/libreofficekit/qa/data/empty.ods";
+    const string sLockFile = m_sSrcRoot +"/libreofficekit/qa/data/.~lock.empty.ods#";
+
+    // FIXME: LOK will fail when trying to open a locked file
+    remove(sLockFile.c_str());
+
+    // first try with the en-US locale
+    std::unique_ptr<Document> pDocument(pOffice->documentLoad(sDocPath.c_str(), "Language=en-US"));
+
+    // assert that '.' is the decimal separator
+    insertString(*pDocument, "1.5");
+
+    pDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, 1027); // right arrow
+    pDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, 1027);
+    processEventsToIdle();
+
+    insertString(*pDocument, "=2*A1");
+
+    pDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, 1280); // enter
+    pDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, 1280);
+    pDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, 1025); // up arrow
+    pDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, 1025);
+    processEventsToIdle();
+
+    // we've got a meaningful result
+    OString aResult = pDocument->getTextSelection("text/plain;charset=utf-8");
+    CPPUNIT_ASSERT_EQUAL(OString("3\n"), aResult);
+
+    pDocument.reset(nullptr);
+
+    // FIXME: LOK will fail when trying to open a locked file
+    remove(sLockFile.c_str());
+
+    // load the file again, now in another language
+    pDocument.reset(pOffice->documentLoad(sDocPath.c_str(), "Language=cs-CZ"));
+
+    // with cs-CZ, the decimal separator is ',' instead, assert that
+    insertString(*pDocument, "1,5");
+
+    pDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, 1027); // right arrow
+    pDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, 1027);
+    processEventsToIdle();
+
+    insertString(*pDocument, "=2*A1");
+
+    pDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, 1280); // enter
+    pDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, 1280);
+    pDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, 1025); // up arrow
+    pDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, 1025);
+    processEventsToIdle();
+
+    // we've got a meaningful result
+    aResult = pDocument->getTextSelection("text/plain;charset=utf-8");
+    CPPUNIT_ASSERT_EQUAL(OString("3\n"), aResult);
+}
+
 #if 0
 static void dumpRGBABitmap( const OUString& rPath, const unsigned char* pBuffer,
                             const int nWidth, const int nHeight )
diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx
index 90de97f23eee..70fd664b52ac 100644
--- a/vcl/source/app/svapp.cxx
+++ b/vcl/source/app/svapp.cxx
@@ -548,6 +548,15 @@ void Scheduler::ProcessEventsToIdle()
     }
 }
 
+extern "C" {
+/// used by unit tests that test only via the LOK API
+SAL_DLLPUBLIC_EXPORT void unit_lok_process_events_to_idle()
+{
+    const SolarMutexGuard aGuard;
+    Scheduler::ProcessEventsToIdle();
+}
+}
+
 void Application::Yield()
 {
     ImplYield(true, false, 0);
commit a9d218fd74f4fd4f934fecbbc16af9111ded5e67
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Mar 23 21:27:18 2017 +0100

    lok: Allow setting of the language during load.
    
    Conflicts:
            desktop/CppunitTest_desktop_app.mk
            desktop/qa/desktop_lib/test_desktop_lib.cxx
            include/LibreOfficeKit/LibreOfficeKit.hxx
    
    Change-Id: I9dbb62950e639376c26122ceb9fcec2982b3ca82

diff --git a/desktop/CppunitTest_desktop_app.mk b/desktop/CppunitTest_desktop_app.mk
index af036f8696cc..d00848814968 100644
--- a/desktop/CppunitTest_desktop_app.mk
+++ b/desktop/CppunitTest_desktop_app.mk
@@ -18,6 +18,7 @@ $(eval $(call gb_CppunitTest_use_libraries,desktop_app, \
     cppu \
     cppuhelper \
     sal \
+    sofficeapp \
     ucbhelper \
     sofficeapp \
 ))
diff --git a/desktop/inc/lib/init.hxx b/desktop/inc/lib/init.hxx
index db281688c2f9..437fcdd6918f 100644
--- a/desktop/inc/lib/init.hxx
+++ b/desktop/inc/lib/init.hxx
@@ -95,6 +95,11 @@ namespace desktop {
             return (mOptionalFeatures & feature) != 0;
         }
     };
+
+    /// Helper function to extract the value from parameters delimited by
+    /// comma, like: Name1=Value1,Name2=Value2,Name3=Value3.
+    /// @param rOptions When exctacted, the Param=Value is removed from it.
+    DESKTOP_DLLPUBLIC OUString extractParameter(OUString& aOptions, const OUString& rName);
 }
 
 #endif
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index ad7cf926f747..6a2cd225f603 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -106,6 +106,7 @@ public:
     void testPaintPartTile();
     void testWriterCommentInsertCursor();
     void testGetFontSubset();
+    void testExtractParameter();
 
     CPPUNIT_TEST_SUITE(DesktopLOKTest);
     CPPUNIT_TEST(testGetStyles);
@@ -140,6 +141,7 @@ public:
     CPPUNIT_TEST(testPaintPartTile);
     CPPUNIT_TEST(testWriterCommentInsertCursor);
     CPPUNIT_TEST(testGetFontSubset);
+    CPPUNIT_TEST(testExtractParameter);
     CPPUNIT_TEST_SUITE_END();
 
     uno::Reference<lang::XComponent> mxComponent;
@@ -1445,6 +1447,34 @@ void DesktopLOKTest::testGetFontSubset()
     comphelper::LibreOfficeKit::setActive(false);
 }
 
+void DesktopLOKTest::testExtractParameter()
+{
+    OUString aOptions("Language=de-DE");
+    OUString aValue = extractParameter(aOptions, "Language");
+    CPPUNIT_ASSERT_EQUAL(OUString("de-DE"), aValue);
+    CPPUNIT_ASSERT_EQUAL(OUString(), aOptions);
+
+    aOptions = "Language=en-US,Something";
+    aValue = extractParameter(aOptions, "Language");
+    CPPUNIT_ASSERT_EQUAL(OUString("en-US"), aValue);
+    CPPUNIT_ASSERT_EQUAL(OUString("Something"), aOptions);
+
+    aOptions = "SomethingElse,Language=cs-CZ";
+    aValue = extractParameter(aOptions, "Language");
+    CPPUNIT_ASSERT_EQUAL(OUString("cs-CZ"), aValue);
+    CPPUNIT_ASSERT_EQUAL(OUString("SomethingElse"), aOptions);
+
+    aOptions = "Something1,Language=hu-HU,Something2";
+    aValue = extractParameter(aOptions, "Language");
+    CPPUNIT_ASSERT_EQUAL(OUString("hu-HU"), aValue);
+    CPPUNIT_ASSERT_EQUAL(OUString("Something1,Something2"), aOptions);
+
+    aOptions = "Something1,Something2=blah,Something3";
+    aValue = extractParameter(aOptions, "Language");
+    CPPUNIT_ASSERT_EQUAL(OUString(), aValue);
+    CPPUNIT_ASSERT_EQUAL(OUString("Something1,Something2=blah,Something3"), aOptions);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 597a225f20b2..7d2df83a60e3 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -432,6 +432,50 @@ int lcl_getViewId(const std::string& payload)
 
 }  // end anonymous namespace
 
+// Could be anonymous in principle, but for the unit testing purposes, we
+// declare it in init.hxx.
+OUString desktop::extractParameter(OUString& rOptions, const OUString& rName)
+{
+    OUString aValue;
+
+    OUString aNameEquals(rName + "=");
+    OUString aCommaNameEquals("," + rName + "=");
+
+    int nIndex = -1;
+    if (rOptions.startsWith(aNameEquals))
+    {
+        size_t nLen = aNameEquals.getLength();
+        int nComma = rOptions.indexOf(",", nLen);
+        if (nComma >= 0)
+        {
+            aValue = rOptions.copy(nLen, nComma - nLen);
+            rOptions = rOptions.copy(nComma + 1);
+        }
+        else
+        {
+            aValue = rOptions.copy(nLen);
+            rOptions.clear();
+        }
+    }
+    else if ((nIndex = rOptions.indexOf(aCommaNameEquals)) >= 0)
+    {
+        size_t nLen = aCommaNameEquals.getLength();
+        int nComma = rOptions.indexOf(",", nIndex + nLen);
+        if (nComma >= 0)
+        {
+            aValue = rOptions.copy(nIndex + nLen, nComma - nIndex - nLen);
+            rOptions = rOptions.copy(0, nIndex) + rOptions.copy(nComma);
+        }
+        else
+        {
+            aValue = rOptions.copy(nIndex + nLen);
+            rOptions = rOptions.copy(0, nIndex);
+        }
+    }
+
+    return aValue;
+}
+
 extern "C"
 {
 
@@ -1057,10 +1101,24 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis,
 
     try
     {
+        // 'Language=...' is an option that LOK consumes by itself, and does
+        // not pass it as a parameter to the filter
+        OUString aOptions = getUString(pOptions);
+        OUString aLanguage = extractParameter(aOptions, "Language");
+
+        if (!aLanguage.isEmpty())
+        {
+            // use with care - it sets it for the entire core, not just the
+            // document
+            SvtSysLocaleOptions aSysLocaleOptions;
+            aSysLocaleOptions.SetLocaleConfigString(aLanguage);
+            aSysLocaleOptions.SetUILocaleConfigString(aLanguage);
+        }
+
         uno::Sequence<css::beans::PropertyValue> aFilterOptions(2);
         aFilterOptions[0] = css::beans::PropertyValue( OUString("FilterOptions"),
                                                        0,
-                                                       uno::makeAny(OUString::createFromAscii(pOptions)),
+                                                       uno::makeAny(aOptions),
                                                        beans::PropertyState_DIRECT_VALUE);
 
         rtl::Reference<LOKInteractionHandler> const pInteraction(
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index eaee8a3c17c2..889f1601568e 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -477,6 +477,10 @@ public:
      *
      * @param pUrl the URL of the document to load
      * @param pFilterOptions options for the import filter, e.g. SkipImages.
+     *        Another useful FilterOption is "Language=...".  It is consumed
+     *        by the documentLoad() itself, and when provided, LibreOfficeKit
+     *        switches the language accordingly first.
+     * @since pFilterOptions argument added in LibreOffice 5.0
      */
     inline Document* documentLoad(const char* pUrl, const char* pFilterOptions = NULL)
     {


More information about the Libreoffice-commits mailing list