desktop/inc/lib/init.hxx                    |   12 +++++++++---
 desktop/qa/desktop_lib/test_desktop_lib.cxx |   18 ++++++++++++++++--
 2 files changed, 25 insertions(+), 5 deletions(-)

New commits:
commit 18470cb6bff9f682b3b86495d80e9ad54c9b5567
Author:     Luboš Luňák <l.lu...@collabora.com>
AuthorDate: Fri Dec 10 18:15:17 2021 +0100
Commit:     Luboš Luňák <l.lu...@collabora.com>
CommitDate: Tue Dec 14 14:47:23 2021 +0100

    fix handling of the "EMPTY" LOK tile invalidation
    
    The LOK_CALLBACK_INVALIDATE_TILES documentation says that
    invalidate-all message should say "EMPTY", which wasn't converted
    properly from the MaxTwips rectangle representation. Doing that
    now needs also changing the testTileInvalidationCompression() test,
    but that should be a fix of the test, and conceptually it should
    be the same.
    
    Change-Id: I58fcc56ee56d9f6fcdb9298938e8aa7e3609d6db
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126651
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lu...@collabora.com>

diff --git a/desktop/inc/lib/init.hxx b/desktop/inc/lib/init.hxx
index 5ebda0a245d6..1ba7e54ff976 100644
--- a/desktop/inc/lib/init.hxx
+++ b/desktop/inc/lib/init.hxx
@@ -42,13 +42,18 @@ namespace desktop {
         tools::Rectangle m_aRectangle;
         int m_nPart;
 
+        // This is the "EMPTY" rectangle, which somewhat confusingly actually 
means
+        // to drop all rectangles (see LOK_CALLBACK_INVALIDATE_TILES 
documentation),
+        // and so it is actually an infinite rectangle and not an empty one.
+        constexpr static tools::Rectangle emptyAllRectangle = {0, 0, 
SfxLokHelper::MaxTwips, SfxLokHelper::MaxTwips};
+
         RectangleAndPart()
             : m_nPart(INT_MIN)  // -1 is reserved to mean "all parts".
         {
         }
 
         RectangleAndPart(const tools::Rectangle* pRect, int nPart)
-            : m_aRectangle( pRect ? *pRect : tools::Rectangle(0, 0, 
SfxLokHelper::MaxTwips, SfxLokHelper::MaxTwips))
+            : m_aRectangle( pRect ? *pRect : emptyAllRectangle)
             , m_nPart(nPart)
         {
         }
@@ -56,9 +61,10 @@ namespace desktop {
         OString toString() const
         {
             if (m_nPart >= -1)
-                return m_aRectangle.toString() + ", " + 
OString::number(m_nPart);
+                return (isInfinite() ? "EMPTY" : m_aRectangle.toString())
+                    + ", " + OString::number(m_nPart);
             else
-                return m_aRectangle.toString();
+                return (isInfinite() ? "EMPTY" : m_aRectangle.toString());
         }
 
         /// Infinite Rectangle is both sides are
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx 
b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 5c17f880e2de..c1b1cc34cbf9 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -1764,7 +1764,7 @@ void DesktopLOKTest::testTileInvalidationCompression()
 
         size_t i = 0;
         CPPUNIT_ASSERT_EQUAL(int(LOK_CALLBACK_INVALIDATE_TILES), 
std::get<0>(notifs[i]));
-        CPPUNIT_ASSERT_EQUAL(std::string("0, 0, 1000000000, 1000000000, 0"), 
std::get<1>(notifs[i++]));
+        CPPUNIT_ASSERT_EQUAL(std::string("EMPTY, 0"), 
std::get<1>(notifs[i++]));
     }
 }
 
@@ -1855,7 +1855,7 @@ void DesktopLOKTest::testBinaryCallback()
 
     const tools::Rectangle rect1(Point(10,15),Size(20,25));
     const std::string rect1String(rect1.toString().getStr());
-    // Very that using queue() and libreOfficeKitViewInvalidateTilesCallback() 
has the same result.
+    // Verify that using queue() and 
libreOfficeKitViewInvalidateTilesCallback() has the same result.
     {
         std::vector<std::tuple<int, std::string>> notifs;
         std::unique_ptr<CallbackFlushHandler> handler(new 
CallbackFlushHandler(pDocument, callbackBinaryCallbackTest, &notifs));
@@ -1882,6 +1882,20 @@ void DesktopLOKTest::testBinaryCallback()
         CPPUNIT_ASSERT_EQUAL(int(LOK_CALLBACK_INVALIDATE_TILES), 
std::get<0>(notifs[0]));
         CPPUNIT_ASSERT_EQUAL(rect1String, std::get<1>(notifs[0]));
     }
+    // Verify that the "EMPTY" invalidation gets converted properly.
+    {
+        std::vector<std::tuple<int, std::string>> notifs;
+        std::unique_ptr<CallbackFlushHandler> handler(new 
CallbackFlushHandler(pDocument, callbackBinaryCallbackTest, &notifs));
+        handler->setViewId(SfxLokHelper::getView());
+
+        handler->libreOfficeKitViewInvalidateTilesCallback(nullptr, INT_MIN);
+
+        Scheduler::ProcessEventsToIdle();
+
+        CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), notifs.size());
+        CPPUNIT_ASSERT_EQUAL(int(LOK_CALLBACK_INVALIDATE_TILES), 
std::get<0>(notifs[0]));
+        CPPUNIT_ASSERT_EQUAL(std::string("EMPTY"), std::get<1>(notifs[0]));
+    }
 }
 
 void DesktopLOKTest::testDialogInput()

Reply via email to