diff options
author | Pranav Kant <pranavk@collabora.co.uk> | 2017-02-17 15:56:41 +0530 |
---|---|---|
committer | pranavk <pranavk@collabora.co.uk> | 2017-02-17 11:53:50 +0000 |
commit | b7640cbb4b34df2cb05c6fbe60346bca96846924 (patch) | |
tree | 6e4d33dbc9b27d58d6ad5c0b27c116d35ba1bf53 /sw | |
parent | afd762249d6e6ea6d6e99204708f0f75a2d0b5a8 (diff) |
sw lok: Move this test to sw/
Change-Id: I9bf901a4c8ffbdd54a98ff043ea1e658aeb62839
Reviewed-on: https://gerrit.libreoffice.org/34364
Reviewed-by: pranavk <pranavk@collabora.co.uk>
Tested-by: pranavk <pranavk@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/tiledrendering/tiledrendering.cxx | 108 |
1 files changed, 107 insertions, 1 deletions
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 0a55c6c83e2f..9b25ba7e2b4e 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -81,7 +81,7 @@ public: void testPaintCallbacks(); void testUndoRepairResult(); void testRedoRepairResult(); - + void testCommentsCallbacks(); CPPUNIT_TEST_SUITE(SwTiledRenderingTest); CPPUNIT_TEST(testRegisterCallback); @@ -126,6 +126,7 @@ public: CPPUNIT_TEST(testPaintCallbacks); CPPUNIT_TEST(testUndoRepairResult); CPPUNIT_TEST(testRedoRepairResult); + CPPUNIT_TEST(testCommentsCallbacks); CPPUNIT_TEST_SUITE_END(); @@ -651,6 +652,7 @@ public: bool m_bViewLock; /// Set if any callback was invoked. bool m_bCalled; + boost::property_tree::ptree m_aCommentCallbackResult; ViewCallback() : m_bOwnCursorInvalidated(false), @@ -757,6 +759,14 @@ public: m_bViewLock = aTree.get_child("rectangle").get_value<std::string>() != "EMPTY"; } 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; } } }; @@ -1669,6 +1679,102 @@ void SwTiledRenderingTest::testRedoRepairResult() comphelper::LibreOfficeKit::setActive(false); } +void SwTiledRenderingTest::testCommentsCallbacks() +{ + comphelper::LibreOfficeKit::setActive(); + // Comments callback are emitted only if tiled annotations are off + comphelper::LibreOfficeKit::setTiledAnnotations(false); + + SwXTextDocument* pXTextDocument = createDoc(); + ViewCallback aView1; + SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1); + int nView1 = SfxLokHelper::getView(); + + // Crete a second view + SfxLokHelper::createView(); + pXTextDocument->initializeForTiledRendering({}); + ViewCallback aView2; + SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2); + + SfxLokHelper::setView(nView1); + + // Add a new comment + uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence( + { + {"Text", uno::makeAny(OUString("Comment"))}, + {"Author", uno::makeAny(OUString("LOK User1"))}, + })); + comphelper::dispatchCommand(".uno:InsertAnnotation", aPropertyValues); + 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 nCommentId1 = aView1.m_aCommentCallbackResult.get<int>("id"); + + // Reply to a comment just added + aPropertyValues = comphelper::InitPropertySequence( + { + {"Id", uno::makeAny(OUString::number(nCommentId1))}, + {"Text", uno::makeAny(OUString("Reply comment"))}, + }); + comphelper::dispatchCommand(".uno:ReplyComment", aPropertyValues); + Scheduler::ProcessEventsToIdle(); + + // We received a LOK_CALLBACK_COMMENT callback with comment 'Add' action and linked to its parent comment + 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(nCommentId1, aView1.m_aCommentCallbackResult.get<int>("parent")); + CPPUNIT_ASSERT_EQUAL(nCommentId1, aView2.m_aCommentCallbackResult.get<int>("parent")); + CPPUNIT_ASSERT_EQUAL(std::string("Reply comment"), aView1.m_aCommentCallbackResult.get<std::string>("text")); + CPPUNIT_ASSERT_EQUAL(std::string("Reply comment"), aView2.m_aCommentCallbackResult.get<std::string>("text")); + int nCommentId2 = aView1.m_aCommentCallbackResult.get<int>("id"); + + // Edit the previously added comment + aPropertyValues = comphelper::InitPropertySequence( + { + {"Id", uno::makeAny(OUString::number(nCommentId2))}, + {"Text", uno::makeAny(OUString("Edited comment"))}, + }); + comphelper::dispatchCommand(".uno:EditAnnotation", aPropertyValues); + 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")); + // parent is unchanged still + CPPUNIT_ASSERT_EQUAL(nCommentId1, aView1.m_aCommentCallbackResult.get<int>("parent")); + CPPUNIT_ASSERT_EQUAL(nCommentId1, aView2.m_aCommentCallbackResult.get<int>("parent")); + 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")); + + // Delete the reply comment just added + aPropertyValues = comphelper::InitPropertySequence( + { + {"Id", uno::makeAny(OUString::number(nCommentId2))}, + }); + comphelper::dispatchCommand(".uno:DeleteComment", aPropertyValues); + 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(nCommentId2, aView1.m_aCommentCallbackResult.get<int>("id")); + CPPUNIT_ASSERT_EQUAL(nCommentId2, aView2.m_aCommentCallbackResult.get<int>("id")); + + // .uno:ViewAnnotations returns total of 1 comment + OUString aPostIts = pXTextDocument->getPostIts(); + std::stringstream aStream(aPostIts.toUtf8().getStr()); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aTree.get_child("comments").size()); + + mxComponent->dispose(); + mxComponent.clear(); + comphelper::LibreOfficeKit::setTiledAnnotations(true); + comphelper::LibreOfficeKit::setActive(false); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest); CPPUNIT_PLUGIN_IMPLEMENT(); |