From fbecbb6872db7c40c8d632955589223a6c456475 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Sat, 11 Jul 2020 21:18:34 +0200 Subject: add test for editing of annotations (using .uno:EditAnnotation) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ic798ab94bb63a3ae80882e77cf1582d875e27d4b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98583 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- desktop/qa/data/BlankDrawDocument.odg | Bin 0 -> 8183 bytes desktop/qa/desktop_lib/test_desktop_lib.cxx | 68 ++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 desktop/qa/data/BlankDrawDocument.odg (limited to 'desktop') diff --git a/desktop/qa/data/BlankDrawDocument.odg b/desktop/qa/data/BlankDrawDocument.odg new file mode 100644 index 000000000000..19ae49d63b36 Binary files /dev/null and b/desktop/qa/data/BlankDrawDocument.odg differ diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index a75e5ea805cf..4eeb728599b7 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -50,6 +50,7 @@ #include #include #include +#include #include #include @@ -159,6 +160,7 @@ public: void testCommentsCalc(); void testCommentsImpress(); void testCommentsCallbacksWriter(); + void testCommentsAddEditDeleteDraw(); void testRunMacro(); void testExtractParameter(); void testGetSignatureState_NonSigned(); @@ -218,6 +220,7 @@ public: CPPUNIT_TEST(testCommentsCalc); CPPUNIT_TEST(testCommentsImpress); CPPUNIT_TEST(testCommentsCallbacksWriter); + CPPUNIT_TEST(testCommentsAddEditDeleteDraw); CPPUNIT_TEST(testRunMacro); CPPUNIT_TEST(testExtractParameter); CPPUNIT_TEST(testGetSignatureState_Signed); @@ -2286,6 +2289,71 @@ void DesktopLOKTest::testCommentsCallbacksWriter() CPPUNIT_ASSERT_EQUAL(static_cast(5), aTree.get_child("comments").size()); } +namespace +{ + +void addParameter(tools::JsonWriter& rJson, const char* sName, OString const & type, OString const & value) +{ + auto testNode = rJson.startNode(sName); + rJson.put("type", type); + rJson.put("value", value); +} + +} + +void DesktopLOKTest::testCommentsAddEditDeleteDraw() +{ + // Comments callback are emitted only if tiled annotations are off + comphelper::LibreOfficeKit::setTiledAnnotations(false); + LibLODocument_Impl* pDocument = loadDoc("BlankDrawDocument.odg"); + pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}"); + ViewCallback aView1(pDocument); + + // Add a new comment + OString aCommandArgs; + { + tools::JsonWriter aJson; + addParameter(aJson, "Text", "string", "Comment"); + addParameter(aJson, "Author", "string", "LOK User1"); + aCommandArgs = aJson.extractAsOString(); + } + + pDocument->pClass->postUnoCommand(pDocument, ".uno:InsertAnnotation", aCommandArgs.getStr(), false); + Scheduler::ProcessEventsToIdle(); + + // We received a LOK_CALLBACK_COMMENT callback with comment 'Add' action + CPPUNIT_ASSERT_EQUAL(std::string("Add"), aView1.m_aCommentCallbackResult.get("action")); + int nCommentId1 = aView1.m_aCommentCallbackResult.get("id"); + + // Edit the previously added comment + { + tools::JsonWriter aJson; + addParameter(aJson, "Id", "string", OString::number(nCommentId1)); + addParameter(aJson, "Text", "string", "Edited comment"); + aCommandArgs = aJson.extractAsOString(); + } + + pDocument->pClass->postUnoCommand(pDocument, ".uno:EditAnnotation", aCommandArgs.getStr(), false); + Scheduler::ProcessEventsToIdle(); + + // We received a LOK_CALLBACK_COMMENT callback with comment 'Modify' action + CPPUNIT_ASSERT_EQUAL(std::string("Modify"), aView1.m_aCommentCallbackResult.get("action")); + CPPUNIT_ASSERT_EQUAL(nCommentId1, aView1.m_aCommentCallbackResult.get("id")); + + // Delete Comment + { + tools::JsonWriter aJson; + addParameter(aJson, "Id", "string", OString::number(nCommentId1)); + aCommandArgs = aJson.extractAsOString(); + } + pDocument->pClass->postUnoCommand(pDocument, ".uno:DeleteAnnotation", aCommandArgs.getStr(), false); + Scheduler::ProcessEventsToIdle(); + + // We received a LOK_CALLBACK_COMMENT callback with comment 'Remove' action + CPPUNIT_ASSERT_EQUAL(std::string("Remove"), aView1.m_aCommentCallbackResult.get("action")); + CPPUNIT_ASSERT_EQUAL(nCommentId1, aView1.m_aCommentCallbackResult.get("id")); +} + void DesktopLOKTest::testRunMacro() { LibLibreOffice_Impl aOffice; -- cgit