[Libreoffice-commits] core.git: desktop/qa sc/qa

Pranav Kant pranavk at collabora.co.uk
Fri Feb 17 12:28:38 UTC 2017


 desktop/qa/data/sheets.ods                   |binary
 desktop/qa/desktop_lib/test_desktop_lib.cxx  |   57 ++++++++++++++++
 sc/qa/unit/tiledrendering/tiledrendering.cxx |   93 +++++++++++++++++++++++++++
 3 files changed, 149 insertions(+), 1 deletion(-)

New commits:
commit 0d839366acfd932b8ae1b31b72c5eca4e102834d
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Fri Feb 17 16:40:54 2017 +0530

    sc lok: Unit tests for Comments API
    
    Change-Id: I896c8b25cab6d80d374d273eb3945716bc0694d6
    Reviewed-on: https://gerrit.libreoffice.org/34365
    Reviewed-by: pranavk <pranavk at collabora.co.uk>
    Tested-by: pranavk <pranavk at collabora.co.uk>

diff --git a/desktop/qa/data/sheets.ods b/desktop/qa/data/sheets.ods
index 0acf865..3f43fa3 100644
Binary files a/desktop/qa/data/sheets.ods and b/desktop/qa/data/sheets.ods differ
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 5eb1d8f..90b918e 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -104,6 +104,7 @@ public:
     void testWriterCommentInsertCursor();
     void testGetFontSubset();
     void testCommentsWriter();
+    void testCommentsCalc();
 
     CPPUNIT_TEST_SUITE(DesktopLOKTest);
     CPPUNIT_TEST(testGetStyles);
@@ -139,6 +140,7 @@ public:
     CPPUNIT_TEST(testWriterCommentInsertCursor);
     CPPUNIT_TEST(testGetFontSubset);
     CPPUNIT_TEST(testCommentsWriter);
+    CPPUNIT_TEST(testCommentsCalc);
     CPPUNIT_TEST_SUITE_END();
 
     uno::Reference<lang::XComponent> mxComponent;
@@ -1856,7 +1858,7 @@ void DesktopLOKTest::testCommentsWriter()
 
     int nComment2Id = 0;
     // Check if all comment fields have valid data
-    for (boost::property_tree::ptree::value_type& rComment : aTree.get_child("comments"))
+    for (const auto& rComment : aTree.get_child("comments"))
     {
         CPPUNIT_ASSERT(rComment.second.get<int>("id") > 0);
         CPPUNIT_ASSERT(!rComment.second.get<std::string>("author").empty());
@@ -1879,6 +1881,59 @@ void DesktopLOKTest::testCommentsWriter()
         }
     }
 
+    comphelper::LibreOfficeKit::setTiledAnnotations(true);
+    comphelper::LibreOfficeKit::setActive(false);
+}
+
+
+void DesktopLOKTest::testCommentsCalc()
+{
+    comphelper::LibreOfficeKit::setActive();
+    // Disable tiled rendering for comments
+    comphelper::LibreOfficeKit::setTiledAnnotations(false);
+
+    LibLODocument_Impl* pDocument = loadDoc("sheets.ods");
+    pDocument->m_pDocumentClass->initializeForRendering(pDocument, nullptr);
+
+    // Can we get all the comments using .uno:ViewAnnotations command ?
+    boost::property_tree::ptree aTree;
+    char* pJSON = pDocument->m_pDocumentClass->getCommandValues(pDocument, ".uno:ViewAnnotations");
+    std::stringstream aStream(pJSON);
+    free(pJSON);
+    CPPUNIT_ASSERT(!aStream.str().empty());
+    boost::property_tree::read_json(aStream, aTree);
+    // There are 2 comments in the document already
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aTree.get_child("comments").size());
+
+    // Check if all comment fields have valid data
+    int nIdx = 0;
+    for (const auto& rComment : aTree.get_child("comments"))
+    {
+        switch(nIdx)
+        {
+            case 0:
+            {
+                CPPUNIT_ASSERT_EQUAL(std::string("Sheet5.G15"), rComment.second.get<std::string>("id"));
+                CPPUNIT_ASSERT_EQUAL(std::string("Comment1"), rComment.second.get<std::string>("text"));
+                CPPUNIT_ASSERT_EQUAL(std::string("7650, 3570, 1274, 254"), rComment.second.get<std::string>("cellPos"));
+            }
+            break;
+            case 1:
+            {
+                CPPUNIT_ASSERT_EQUAL(std::string("Sheet5.H18"), rComment.second.get<std::string>("id"));
+                CPPUNIT_ASSERT_EQUAL(std::string("Comment2"), rComment.second.get<std::string>("text"));
+                CPPUNIT_ASSERT_EQUAL(std::string("8925, 4335, 1274, 254"), rComment.second.get<std::string>("cellPos"));
+            }
+            break;
+        }
+
+        ++nIdx;
+    }
+
+    // We checked all the comments
+    CPPUNIT_ASSERT_EQUAL(2, nIdx);
+
+    comphelper::LibreOfficeKit::setTiledAnnotations(true);
     comphelper::LibreOfficeKit::setActive(false);
 }
 
diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx
index c3e6741..025139d 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx
@@ -70,6 +70,7 @@ public:
     void testHideColRow();
     void testInvalidateOnCopyPasteCells();
     void testInvalidateOnInserRowCol();
+    void testCommentCallback();
 
     CPPUNIT_TEST_SUITE(ScTiledRenderingTest);
     CPPUNIT_TEST(testRowColumnSelections);
@@ -91,6 +92,7 @@ public:
     CPPUNIT_TEST(testHideColRow);
     CPPUNIT_TEST(testInvalidateOnCopyPasteCells);
     CPPUNIT_TEST(testInvalidateOnInserRowCol);
+    CPPUNIT_TEST(testCommentCallback);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -399,6 +401,7 @@ public:
     bool m_bInvalidateTiles;
     bool m_bViewLock;
     OString m_sCellFormula;
+    boost::property_tree::ptree m_aCommentCallbackResult;
 
     ViewCallback()
         : m_bOwnCursorInvalidated(false),
@@ -471,6 +474,15 @@ public:
         {
             m_sCellFormula = pPayload;
         }
+        break;
+        case LOK_CALLBACK_COMMENT:
+        {
+            m_aCommentCallbackResult.clear();
+            std::stringstream aStream(pPayload);
+            boost::property_tree::read_json(aStream, m_aCommentCallbackResult);
+            m_aCommentCallbackResult = m_aCommentCallbackResult.get_child("comment");
+        }
+        break;
         }
     }
 };
@@ -1029,6 +1041,87 @@ void ScTiledRenderingTest::testInvalidateOnInserRowCol()
     comphelper::LibreOfficeKit::setActive(false);
 }
 
+void ScTiledRenderingTest::testCommentCallback()
+{
+    // Load a document
+    comphelper::LibreOfficeKit::setActive();
+    // Comments callback are emitted only if tiled annotations are off
+    comphelper::LibreOfficeKit::setTiledAnnotations(false);
+
+    ScModelObj* pModelObj = createDoc("small.ods");
+    ViewCallback aView1;
+    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
+    int nView1 = SfxLokHelper::getView();
+
+    // Create a 2nd view
+    SfxLokHelper::createView();
+    pModelObj->initializeForTiledRendering({});
+    ViewCallback aView2;
+    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
+
+    SfxLokHelper::setView(nView1);
+
+    // Add a new comment
+    uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence(
+    {
+        {"Text", uno::makeAny(OUString("Comment"))},
+        {"Author", uno::makeAny(OUString("LOK User1"))},
+    }));
+    comphelper::dispatchCommand(".uno:InsertAnnotation", aArgs);
+    Scheduler::ProcessEventsToIdle();
+
+    // We received a LOK_CALLBACK_COMMENT callback with comment 'Add' action
+    CPPUNIT_ASSERT_EQUAL(std::string("Add"), aView1.m_aCommentCallbackResult.get<std::string>("action"));
+    CPPUNIT_ASSERT_EQUAL(std::string("Add"), aView2.m_aCommentCallbackResult.get<std::string>("action"));
+    CPPUNIT_ASSERT_EQUAL(std::string("Sheet1.A2"), aView1.m_aCommentCallbackResult.get<std::string>("id"));
+    CPPUNIT_ASSERT_EQUAL(std::string("Sheet1.A2"), aView2.m_aCommentCallbackResult.get<std::string>("id"));
+    CPPUNIT_ASSERT_EQUAL(std::string("LOK User1"), aView1.m_aCommentCallbackResult.get<std::string>("author"));
+    CPPUNIT_ASSERT_EQUAL(std::string("LOK User1"), aView2.m_aCommentCallbackResult.get<std::string>("author"));
+    CPPUNIT_ASSERT_EQUAL(std::string("Comment"), aView1.m_aCommentCallbackResult.get<std::string>("text"));
+    CPPUNIT_ASSERT_EQUAL(std::string("Comment"), aView2.m_aCommentCallbackResult.get<std::string>("text"));
+    CPPUNIT_ASSERT_EQUAL(std::string("0, 255, 1274, 254"), aView1.m_aCommentCallbackResult.get<std::string>("cellPos"));
+    CPPUNIT_ASSERT_EQUAL(std::string("0, 255, 1274, 254"), aView2.m_aCommentCallbackResult.get<std::string>("cellPos"));
+
+    // Edit a comment
+    aArgs = comphelper::InitPropertySequence(
+    {
+        {"Text", uno::makeAny(OUString("Edited comment"))},
+        {"Author", uno::makeAny(OUString("LOK User2"))},
+    });
+    comphelper::dispatchCommand(".uno:EditAnnotation", aArgs);
+    Scheduler::ProcessEventsToIdle();
+
+    // We received a LOK_CALLBACK_COMMENT callback with comment 'Modify' action
+    CPPUNIT_ASSERT_EQUAL(std::string("Modify"), aView1.m_aCommentCallbackResult.get<std::string>("action"));
+    CPPUNIT_ASSERT_EQUAL(std::string("Modify"), aView2.m_aCommentCallbackResult.get<std::string>("action"));
+    CPPUNIT_ASSERT_EQUAL(std::string("Sheet1.A2"), aView1.m_aCommentCallbackResult.get<std::string>("id"));
+    CPPUNIT_ASSERT_EQUAL(std::string("Sheet1.A2"), aView2.m_aCommentCallbackResult.get<std::string>("id"));
+    CPPUNIT_ASSERT_EQUAL(std::string("LOK User2"), aView1.m_aCommentCallbackResult.get<std::string>("author"));
+    CPPUNIT_ASSERT_EQUAL(std::string("LOK User2"), aView2.m_aCommentCallbackResult.get<std::string>("author"));
+    CPPUNIT_ASSERT_EQUAL(std::string("Edited comment"), aView1.m_aCommentCallbackResult.get<std::string>("text"));
+    CPPUNIT_ASSERT_EQUAL(std::string("Edited comment"), aView2.m_aCommentCallbackResult.get<std::string>("text"));
+    CPPUNIT_ASSERT_EQUAL(std::string("0, 255, 1274, 254"), aView1.m_aCommentCallbackResult.get<std::string>("cellPos"));
+    CPPUNIT_ASSERT_EQUAL(std::string("0, 255, 1274, 254"), aView2.m_aCommentCallbackResult.get<std::string>("cellPos"));
+
+    // Delete the comment
+    aArgs = comphelper::InitPropertySequence(
+    {
+    });
+    comphelper::dispatchCommand(".uno:DeleteNote", aArgs);
+    Scheduler::ProcessEventsToIdle();
+
+    // We received a LOK_CALLBACK_COMMENT callback with comment 'Remove' action
+    CPPUNIT_ASSERT_EQUAL(std::string("Remove"), aView1.m_aCommentCallbackResult.get<std::string>("action"));
+    CPPUNIT_ASSERT_EQUAL(std::string("Remove"), aView2.m_aCommentCallbackResult.get<std::string>("action"));
+    CPPUNIT_ASSERT_EQUAL(std::string("Sheet1.A2"), aView1.m_aCommentCallbackResult.get<std::string>("id"));
+    CPPUNIT_ASSERT_EQUAL(std::string("Sheet1.A2"), aView2.m_aCommentCallbackResult.get<std::string>("id"));
+
+    mxComponent->dispose();
+    mxComponent.clear();
+    comphelper::LibreOfficeKit::setTiledAnnotations(true);
+    comphelper::LibreOfficeKit::setActive(false);
+}
+
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(ScTiledRenderingTest);


More information about the Libreoffice-commits mailing list