diff options
author | Pranav Kant <pranavk@collabora.co.uk> | 2017-02-20 18:21:44 +0530 |
---|---|---|
committer | Pranav Kant <pranavk@collabora.co.uk> | 2017-02-20 19:41:33 +0530 |
commit | 1654980341cff652de65d3b2aed52230e781e63a (patch) | |
tree | 92bcc663158acf6b67434a2a8fb0c6093125e37b /sd | |
parent | 266e7ab8bedf0e4b515b194a563b36430d0c24e0 (diff) |
sd lok: Unit tests for comments api
Change-Id: I88a5cbc952a1ddc2f8ccd5f34b86bf797916171c
Diffstat (limited to 'sd')
-rw-r--r-- | sd/qa/unit/tiledrendering/tiledrendering.cxx | 111 |
1 files changed, 108 insertions, 3 deletions
diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx index 2013bfe949c8..c70bdd5024b9 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(); |