diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-07-11 21:18:34 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2020-07-12 10:36:12 +0200 |
commit | fbecbb6872db7c40c8d632955589223a6c456475 (patch) | |
tree | 8da3200e8b135e8493b14002421fe7d6e619f074 | |
parent | allow .uno:EditAnnotation also for Draw not just Impress (diff) | |
download | core-fbecbb6872db7c40c8d632955589223a6c456475.tar.gz core-fbecbb6872db7c40c8d632955589223a6c456475.zip |
add test for editing of annotations (using .uno:EditAnnotation)
Change-Id: Ic798ab94bb63a3ae80882e77cf1582d875e27d4b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98583
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r-- | desktop/qa/data/BlankDrawDocument.odg | bin | 0 -> 8183 bytes | |||
-rw-r--r-- | desktop/qa/desktop_lib/test_desktop_lib.cxx | 68 | ||||
-rw-r--r-- | sd/qa/unit/tiledrendering/data/dummy.odg | bin | 0 -> 8183 bytes | |||
-rw-r--r-- | sd/qa/unit/tiledrendering/tiledrendering.cxx | 56 |
4 files changed, 121 insertions, 3 deletions
diff --git a/desktop/qa/data/BlankDrawDocument.odg b/desktop/qa/data/BlankDrawDocument.odg Binary files differnew file mode 100644 index 000000000000..19ae49d63b36 --- /dev/null +++ b/desktop/qa/data/BlankDrawDocument.odg 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 <cairo.h> #include <config_features.h> #include <config_mpl.h> +#include <tools/json_writer.hxx> #include <lib/init.hxx> #include <svx/svxids.hrc> @@ -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<size_t>(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<std::string>("action")); + int nCommentId1 = aView1.m_aCommentCallbackResult.get<int>("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<std::string>("action")); + CPPUNIT_ASSERT_EQUAL(nCommentId1, aView1.m_aCommentCallbackResult.get<int>("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<std::string>("action")); + CPPUNIT_ASSERT_EQUAL(nCommentId1, aView1.m_aCommentCallbackResult.get<int>("id")); +} + void DesktopLOKTest::testRunMacro() { LibLibreOffice_Impl aOffice; diff --git a/sd/qa/unit/tiledrendering/data/dummy.odg b/sd/qa/unit/tiledrendering/data/dummy.odg Binary files differnew file mode 100644 index 000000000000..19ae49d63b36 --- /dev/null +++ b/sd/qa/unit/tiledrendering/data/dummy.odg diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx index 647d01dbe2b1..4cc1f841c423 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -111,7 +111,8 @@ public: void testTdf81754(); void testTdf105502(); void testCommentCallbacks(); - void testCommentChange(); + void testCommentChangeImpress(); + void testCommentChangeDraw(); void testMultiViewInsertDeletePage(); void testDisableUndoRepair(); void testDocumentRepair(); @@ -162,7 +163,8 @@ public: CPPUNIT_TEST(testTdf81754); CPPUNIT_TEST(testTdf105502); CPPUNIT_TEST(testCommentCallbacks); - CPPUNIT_TEST(testCommentChange); + CPPUNIT_TEST(testCommentChangeImpress); + CPPUNIT_TEST(testCommentChangeDraw); CPPUNIT_TEST(testMultiViewInsertDeletePage); CPPUNIT_TEST(testDisableUndoRepair); CPPUNIT_TEST(testDocumentRepair); @@ -1809,7 +1811,7 @@ void SdTiledRenderingTest::testCommentCallbacks() comphelper::LibreOfficeKit::setTiledAnnotations(true); } -void SdTiledRenderingTest::testCommentChange() +void SdTiledRenderingTest::testCommentChangeImpress() { uno::Sequence<beans::PropertyValue> aArgs; @@ -1857,6 +1859,54 @@ void SdTiledRenderingTest::testCommentChange() comphelper::LibreOfficeKit::setTiledAnnotations(true); } +void SdTiledRenderingTest::testCommentChangeDraw() +{ + uno::Sequence<beans::PropertyValue> aArgs; + + // Load the document. + // Set the tiled annotations off + comphelper::LibreOfficeKit::setTiledAnnotations(false); + + createDoc("dummy.odg", comphelper::InitPropertySequence( + { + {".uno:Author", uno::makeAny(OUString("LOK User1"))}, + })); + + ViewCallback aView1; + + // Add a new comment + aArgs = comphelper::InitPropertySequence( + { + {"Text", uno::makeAny(OUString("Comment"))}, + }); + comphelper::dispatchCommand(".uno:InsertAnnotation", aArgs); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(std::string("Add"), aView1.m_aCommentCallbackResult.get<std::string>("action")); + + int nComment1 = aView1.m_aCommentCallbackResult.get<int>("id"); + + CPPUNIT_ASSERT(!aView1.m_aCommentCallbackResult.get<std::string>("parthash").empty()); + CPPUNIT_ASSERT_EQUAL(std::string("Comment"), aView1.m_aCommentCallbackResult.get<std::string>("text")); + CPPUNIT_ASSERT_EQUAL(std::string("0, 0, 0, 0"), aView1.m_aCommentCallbackResult.get<std::string>("rectangle")); + + // Edit this annotation now + aArgs = comphelper::InitPropertySequence( + { + {"Id", uno::makeAny(OUString::number(nComment1))}, + {"PositionX", uno::makeAny(sal_Int32(10))}, + {"PositionY", uno::makeAny(sal_Int32(20))} + }); + comphelper::dispatchCommand(".uno:EditAnnotation", aArgs); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(std::string("Modify"), aView1.m_aCommentCallbackResult.get<std::string>("action")); + CPPUNIT_ASSERT_EQUAL(std::string("Comment"), aView1.m_aCommentCallbackResult.get<std::string>("text")); + CPPUNIT_ASSERT_EQUAL(std::string("10, 20, 0, 0"), aView1.m_aCommentCallbackResult.get<std::string>("rectangle")); + + comphelper::LibreOfficeKit::setTiledAnnotations(true); +} + void SdTiledRenderingTest::testMultiViewInsertDeletePage() { // Load the document. |