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

Pranav Kant pranavk at collabora.co.uk
Mon Feb 20 14:12:22 UTC 2017


 desktop/qa/data/blank_presentation.odp       |binary
 desktop/qa/desktop_lib/test_desktop_lib.cxx  |   60 ++++++++++++++
 sd/qa/unit/tiledrendering/tiledrendering.cxx |  111 ++++++++++++++++++++++++++-
 3 files changed, 168 insertions(+), 3 deletions(-)

New commits:
commit 65cfa0eed38ceeb4e96c97b76772bb191129fd83
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Mon Feb 20 19:33:22 2017 +0530

    desktop: unit test to for sd ViewAnnotations command
    
    Change-Id: Ib830ff786f12d9edc791623dead74b3eeeabad71

diff --git a/desktop/qa/data/blank_presentation.odp b/desktop/qa/data/blank_presentation.odp
index 157901f..a7d57a4 100644
Binary files a/desktop/qa/data/blank_presentation.odp and b/desktop/qa/data/blank_presentation.odp differ
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 90b918e..061905e 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -105,6 +105,7 @@ public:
     void testGetFontSubset();
     void testCommentsWriter();
     void testCommentsCalc();
+    void testCommentsImpress();
 
     CPPUNIT_TEST_SUITE(DesktopLOKTest);
     CPPUNIT_TEST(testGetStyles);
@@ -141,6 +142,7 @@ public:
     CPPUNIT_TEST(testGetFontSubset);
     CPPUNIT_TEST(testCommentsWriter);
     CPPUNIT_TEST(testCommentsCalc);
+    CPPUNIT_TEST(testCommentsImpress);
     CPPUNIT_TEST_SUITE_END();
 
     uno::Reference<lang::XComponent> mxComponent;
@@ -1937,6 +1939,64 @@ void DesktopLOKTest::testCommentsCalc()
     comphelper::LibreOfficeKit::setActive(false);
 }
 
+
+void DesktopLOKTest::testCommentsImpress()
+{
+    comphelper::LibreOfficeKit::setActive();
+    // Disable tiled rendering for comments
+    comphelper::LibreOfficeKit::setTiledAnnotations(false);
+
+    LibLODocument_Impl* pDocument = loadDoc("blank_presentation.odp");
+    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(rComment.second.get<int>("id") > 0);
+                CPPUNIT_ASSERT_EQUAL(std::string("This is comment1"), rComment.second.get<std::string>("text"));
+                CPPUNIT_ASSERT_EQUAL(std::string("LOK User1"), rComment.second.get<std::string>("author"));
+                css::util::DateTime aDateTime;
+                OUString aDateTimeString = OUString::createFromAscii(rComment.second.get<std::string>("dateTime").c_str());
+                CPPUNIT_ASSERT(utl::ISO8601parseDateTime(aDateTimeString, aDateTime));
+            }
+            break;
+            case 1:
+            {
+                CPPUNIT_ASSERT(rComment.second.get<int>("id") > 0);
+                CPPUNIT_ASSERT_EQUAL(std::string("This is comment2"), rComment.second.get<std::string>("text"));
+                CPPUNIT_ASSERT_EQUAL(std::string("LOK User2"), rComment.second.get<std::string>("author"));
+                css::util::DateTime aDateTime;
+                OUString aDateTimeString = OUString::createFromAscii(rComment.second.get<std::string>("dateTime").c_str());
+                CPPUNIT_ASSERT(utl::ISO8601parseDateTime(aDateTimeString, aDateTime));
+            }
+            break;
+        }
+
+        ++nIdx;
+    }
+
+    // We checked all the comments
+    CPPUNIT_ASSERT_EQUAL(2, nIdx);
+
+    comphelper::LibreOfficeKit::setTiledAnnotations(true);
+    comphelper::LibreOfficeKit::setActive(false);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
commit 1654980341cff652de65d3b2aed52230e781e63a
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Mon Feb 20 18:21:44 2017 +0530

    sd lok: Unit tests for comments api
    
    Change-Id: I88a5cbc952a1ddc2f8ccd5f34b86bf797916171c

diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx
index 2013bfe..c70bdd5 100644
--- a/sd/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx
@@ -34,6 +34,7 @@
 #include <comphelper/lok.hxx>
 #include <svx/svdotable.hxx>
 #include <svx/svdoutl.hxx>
+#include <unotools/datetime.hxx>
 
 #include <DrawDocShell.hxx>
 #include <ViewShellBase.hxx>
@@ -89,6 +90,7 @@ public:
     void testTdf104405();
     void testTdf81754();
     void testTdf105502();
+    void testCommentCallbacks();
 
     CPPUNIT_TEST_SUITE(SdTiledRenderingTest);
     CPPUNIT_TEST(testRegisterCallback);
@@ -122,11 +124,12 @@ public:
     CPPUNIT_TEST(testTdf104405);
     CPPUNIT_TEST(testTdf81754);
     CPPUNIT_TEST(testTdf105502);
+    CPPUNIT_TEST(testCommentCallbacks);
 
     CPPUNIT_TEST_SUITE_END();
 
 private:
-    SdXImpressDocument* createDoc(const char* pName);
+    SdXImpressDocument* createDoc(const char* pName, const uno::Sequence<beans::PropertyValue>& rArguments = uno::Sequence<beans::PropertyValue>());
     static void callback(int nType, const char* pPayload, void* pData);
     void callbackImpl(int nType, const char* pPayload);
     xmlDocPtr parseXmlDump();
@@ -173,14 +176,14 @@ void SdTiledRenderingTest::tearDown()
     test::BootstrapFixture::tearDown();
 }
 
-SdXImpressDocument* SdTiledRenderingTest::createDoc(const char* pName)
+SdXImpressDocument* SdTiledRenderingTest::createDoc(const char* pName, const uno::Sequence<beans::PropertyValue>& rArguments)
 {
     if (mxComponent.is())
         mxComponent->dispose();
     mxComponent = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY) + OUString::createFromAscii(pName), "com.sun.star.presentation.PresentationDocument");
     SdXImpressDocument* pImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
     CPPUNIT_ASSERT(pImpressDocument);
-    pImpressDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
+    pImpressDocument->initializeForTiledRendering(rArguments);
     return pImpressDocument;
 }
 
@@ -898,6 +901,7 @@ public:
     std::map<int, bool> m_aViewCursorInvalidations;
     std::map<int, bool> m_aViewCursorVisibilities;
     bool m_bViewSelectionSet;
+    boost::property_tree::ptree m_aCommentCallbackResult;
 
     ViewCallback()
         : m_bGraphicSelectionInvalidated(false),
@@ -975,6 +979,14 @@ public:
             m_bViewSelectionSet = true;
         }
         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;
         }
     }
 };
@@ -1559,6 +1571,99 @@ void SdTiledRenderingTest::testTdf105502()
     comphelper::LibreOfficeKit::setActive(false);
 }
 
+void SdTiledRenderingTest::testCommentCallbacks()
+{
+    // Load the document.
+    comphelper::LibreOfficeKit::setActive();
+    // Set the tield annotations off
+    comphelper::LibreOfficeKit::setTiledAnnotations(false);
+
+    SdXImpressDocument* pXImpressDocument = createDoc("dummy.odp", comphelper::InitPropertySequence(
+    {
+        {".uno:Author", uno::makeAny(OUString("LOK User1"))},
+    }));
+    ViewCallback aView1;
+    int nView1 = SfxLokHelper::getView();
+    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
+
+    SfxLokHelper::createView();
+    uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence(
+    {
+        {".uno:Author", uno::makeAny(OUString("LOK User2"))},
+    }));
+    pXImpressDocument->initializeForTiledRendering(aArgs);
+    ViewCallback aView2;
+    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
+    int nView2 = SfxLokHelper::getView();
+
+    SfxLokHelper::setView(nView1);
+
+    // Add a new comment
+    aArgs = comphelper::InitPropertySequence(
+    {
+        {"Text", uno::makeAny(OUString("Comment"))},
+    });
+    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"));
+    int nComment1 = aView1.m_aCommentCallbackResult.get<int>("id");
+    CPPUNIT_ASSERT_EQUAL(nComment1, aView2.m_aCommentCallbackResult.get<int>("id"));
+    css::util::DateTime aDateTime;
+    OUString aDateTimeString = OUString::createFromAscii(aView1.m_aCommentCallbackResult.get<std::string>("dateTime").c_str());
+    CPPUNIT_ASSERT(utl::ISO8601parseDateTime(aDateTimeString, aDateTime));
+    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"));
+
+    // Reply to a just added comment
+    SfxLokHelper::setView(nView2);
+    aArgs = comphelper::InitPropertySequence(
+    {
+        {"Id", uno::makeAny(OUString::number(nComment1))},
+        {"Text", uno::makeAny(OUString("Reply to comment"))},
+    });
+    comphelper::dispatchCommand(".uno:ReplyToAnnotation", 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(nComment1, aView1.m_aCommentCallbackResult.get<int>("id"));
+    CPPUNIT_ASSERT_EQUAL(nComment1, aView2.m_aCommentCallbackResult.get<int>("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"));
+    OUString aReplyTextView1 = OUString::createFromAscii(aView1.m_aCommentCallbackResult.get<std::string>("text").c_str());
+    OUString aReplyTextView2 = OUString::createFromAscii(aView2.m_aCommentCallbackResult.get<std::string>("text").c_str());
+    CPPUNIT_ASSERT(aReplyTextView1.startsWith("Reply to LOK User1"));
+    CPPUNIT_ASSERT(aReplyTextView1.endsWith("Reply to comment"));
+    CPPUNIT_ASSERT(aReplyTextView2.startsWith("Reply to LOK User1"));
+    CPPUNIT_ASSERT(aReplyTextView2.endsWith("Reply to comment"));
+
+    // Delete the comment
+    aArgs = comphelper::InitPropertySequence(
+    {
+        {"Id", uno::makeAny(OUString::number(nComment1))},
+    });
+    comphelper::dispatchCommand(".uno:DeleteAnnotation", 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(nComment1, aView1.m_aCommentCallbackResult.get<int>("id"));
+    CPPUNIT_ASSERT_EQUAL(nComment1, aView2.m_aCommentCallbackResult.get<int>("id"));
+
+    mxComponent->dispose();
+    mxComponent.clear();
+
+    comphelper::LibreOfficeKit::setTiledAnnotations(true);
+    comphelper::LibreOfficeKit::setActive(false);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SdTiledRenderingTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();


More information about the Libreoffice-commits mailing list