diff options
-rw-r--r-- | desktop/qa/data/sheets.ods | bin | 8898 -> 9669 bytes | |||
-rw-r--r-- | desktop/qa/desktop_lib/test_desktop_lib.cxx | 57 | ||||
-rw-r--r-- | sc/qa/unit/tiledrendering/tiledrendering.cxx | 93 |
3 files changed, 149 insertions, 1 deletions
diff --git a/desktop/qa/data/sheets.ods b/desktop/qa/data/sheets.ods Binary files differindex 0acf86541ba9..3f43fa3a3d78 100644 --- a/desktop/qa/data/sheets.ods +++ b/desktop/qa/data/sheets.ods diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 5eb1d8fc4a61..90b918e91150 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 c3e67418509d..025139dcec77 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); |