lok: Unit test for comments api
Change-Id: Ieedb50a4d376c1214ea23b56c8cab19c96c159d0 Reviewed-on: https://gerrit.libreoffice.org/33615 Reviewed-by: pranavk <pranavk@collabora.co.uk> Tested-by: pranavk <pranavk@collabora.co.uk>
This commit is contained in:
BIN
desktop/qa/data/comments.odt
Normal file
BIN
desktop/qa/data/comments.odt
Normal file
Binary file not shown.
@@ -33,6 +33,7 @@
|
||||
#include <sfx2/viewsh.hxx>
|
||||
#include <sfx2/viewfrm.hxx>
|
||||
#include <sfx2/bindings.hxx>
|
||||
#include <unotools/datetime.hxx>
|
||||
#include <comphelper/string.hxx>
|
||||
#include <comphelper/scopeguard.hxx>
|
||||
#include <cairo.h>
|
||||
@@ -103,6 +104,8 @@ public:
|
||||
void testPaintPartTile();
|
||||
void testWriterCommentInsertCursor();
|
||||
void testGetFontSubset();
|
||||
void testNoTiledAnnotations();
|
||||
void testCommentsCallbacks();
|
||||
|
||||
CPPUNIT_TEST_SUITE(DesktopLOKTest);
|
||||
CPPUNIT_TEST(testGetStyles);
|
||||
@@ -138,6 +141,8 @@ public:
|
||||
CPPUNIT_TEST(testPaintPartTile);
|
||||
CPPUNIT_TEST(testWriterCommentInsertCursor);
|
||||
CPPUNIT_TEST(testGetFontSubset);
|
||||
CPPUNIT_TEST(testNoTiledAnnotations);
|
||||
CPPUNIT_TEST(testCommentsCallbacks);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
uno::Reference<lang::XComponent> mxComponent;
|
||||
@@ -159,6 +164,7 @@ public:
|
||||
// for testContextMenu{Calc, Writer}
|
||||
osl::Condition m_aContextMenuCondition;
|
||||
boost::property_tree::ptree m_aContextMenuResult;
|
||||
|
||||
};
|
||||
|
||||
LibLODocument_Impl* DesktopLOKTest::loadDoc(const char* pName, LibreOfficeKitDocumentType eType)
|
||||
@@ -1686,6 +1692,7 @@ class ViewCallback
|
||||
public:
|
||||
bool m_bTilesInvalidated;
|
||||
Rectangle m_aOwnCursor;
|
||||
boost::property_tree::ptree m_aCommentCallbackResult;
|
||||
|
||||
ViewCallback()
|
||||
: m_bTilesInvalidated(false)
|
||||
@@ -1719,6 +1726,14 @@ public:
|
||||
m_aOwnCursor.setHeight(aSeq[3].toInt32());
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1833,6 +1848,132 @@ void DesktopLOKTest::testGetFontSubset()
|
||||
comphelper::LibreOfficeKit::setActive(false);
|
||||
}
|
||||
|
||||
void DesktopLOKTest::testNoTiledAnnotations()
|
||||
{
|
||||
comphelper::LibreOfficeKit::setActive();
|
||||
// Disable tiled rendering for comments
|
||||
comphelper::LibreOfficeKit::setTiledAnnotations(false);
|
||||
|
||||
LibLODocument_Impl* pDocument = loadDoc("comments.odt");
|
||||
pDocument->m_pDocumentClass->initializeForRendering(pDocument, nullptr);
|
||||
long nWidth, nHeight;
|
||||
pDocument->m_pDocumentClass->getDocumentSize(pDocument, &nWidth, &nHeight);
|
||||
|
||||
// Document width alongwith without sidebar comes to be < 13000
|
||||
CPPUNIT_ASSERT( nWidth < 13000 );
|
||||
|
||||
// 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 3 comments in the document already
|
||||
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aTree.get_child("comments").size());
|
||||
|
||||
int nComment2Id = 0;
|
||||
// Check if all comment fields have valid data
|
||||
for (boost::property_tree::ptree::value_type& rComment : aTree.get_child("comments"))
|
||||
{
|
||||
CPPUNIT_ASSERT(rComment.second.get<int>("id") > 0);
|
||||
CPPUNIT_ASSERT(!rComment.second.get<std::string>("author").empty());
|
||||
CPPUNIT_ASSERT(!rComment.second.get<std::string>("text").empty());
|
||||
// Has a valid iso 8601 date time string
|
||||
css::util::DateTime aDateTime;
|
||||
OUString aDateTimeString = OUString::createFromAscii(rComment.second.get<std::string>("dateTime").c_str());
|
||||
CPPUNIT_ASSERT(utl::ISO8601parseDateTime(aDateTimeString, aDateTime));
|
||||
|
||||
// This comment has a marked text range
|
||||
if (rComment.second.get<std::string>("text") == "Comment 2")
|
||||
{
|
||||
CPPUNIT_ASSERT(!rComment.second.get<std::string>("textRange").empty());
|
||||
nComment2Id = rComment.second.get<int>("id");
|
||||
}
|
||||
// This is a reply comment
|
||||
else if (rComment.second.get<std::string>("text") == "Reply to Comment 2")
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL(nComment2Id, rComment.second.get<int>("parent"));
|
||||
}
|
||||
}
|
||||
|
||||
comphelper::LibreOfficeKit::setActive(false);
|
||||
}
|
||||
|
||||
void DesktopLOKTest::testCommentsCallbacks()
|
||||
{
|
||||
comphelper::LibreOfficeKit::setActive();
|
||||
// Comments callback are emitted only if tiled annotations are off
|
||||
comphelper::LibreOfficeKit::setTiledAnnotations(false);
|
||||
ViewCallback aView1;
|
||||
ViewCallback aView2;
|
||||
LibLODocument_Impl* pDocument = loadDoc("comments.odt");
|
||||
pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}");
|
||||
pDocument->m_pDocumentClass->registerCallback(pDocument, &ViewCallback::callback, &aView1);
|
||||
pDocument->m_pDocumentClass->createView(pDocument);
|
||||
pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}");
|
||||
pDocument->m_pDocumentClass->registerCallback(pDocument, &ViewCallback::callback, &aView2);
|
||||
|
||||
// Add a new comment
|
||||
OString aCommandArgs("{ \"Text\": { \"type\": \"string\", \"value\": \"Additional comment\" }, \"Author\": { \"type\": \"string\", \"value\": \"LOK User1\" } }");
|
||||
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"));
|
||||
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
|
||||
aCommandArgs = "{ \"Id\": { \"type\": \"long\", \"value\": \"" + OString::number(nCommentId1) + "\" }, \"Text\": { \"type\": \"string\", \"value\": \"Reply comment\" } }";
|
||||
pDocument->pClass->postUnoCommand(pDocument, ".uno:ReplyComment", aCommandArgs.getStr(), false);
|
||||
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");
|
||||
|
||||
// Delete the reply comment just added
|
||||
aCommandArgs = "{ \"Id\": { \"type\": \"long\", \"value\": \"" + OString::number(nCommentId2) + "\" } }";
|
||||
pDocument->pClass->postUnoCommand(pDocument, ".uno:DeleteComment", 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(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"));
|
||||
|
||||
// Reply to nCommentId1 again
|
||||
aCommandArgs = "{ \"Id\": { \"type\": \"long\", \"value\": \"" + OString::number(nCommentId1) + "\" }, \"Text\": { \"type\": \"string\", \"value\": \"Reply comment again\" } }";
|
||||
pDocument->pClass->postUnoCommand(pDocument, ".uno:ReplyComment", aCommandArgs.getStr(), false);
|
||||
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 again"), aView1.m_aCommentCallbackResult.get<std::string>("text"));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("Reply comment again"), aView2.m_aCommentCallbackResult.get<std::string>("text"));
|
||||
|
||||
// .uno:ViewAnnotations returns total of 5 comments
|
||||
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);
|
||||
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(5), aTree.get_child("comments").size());
|
||||
|
||||
comphelper::LibreOfficeKit::setActive(false);
|
||||
}
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
|
||||
|
||||
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||
|
Reference in New Issue
Block a user