desktop/qa/desktop_lib/test_desktop_lib.cxx | 45 ++++++++++++++++++++++++++++ desktop/source/lib/init.cxx | 6 ++- 2 files changed, 49 insertions(+), 2 deletions(-)
New commits: commit b846b03c709130564527da8d264660a131361221 Author: Jan Holesovsky <[email protected]> Date: Tue Nov 3 16:52:46 2015 +0100 lok: Fix crash due to non-initialized callback. Yay for unit tests! :-) Change-Id: I06b3f929b53d5c03f5722acfdaf0eaf841325e34 diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index cc48f13..8a1947e 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -394,16 +394,25 @@ void DesktopLOKTest::testRowColumnHeaders() void DesktopLOKTest::testCommandResult() { LibLODocument_Impl* pDocument = loadDoc("blank_text.odt"); - pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this); // the postUnoCommand() is supposed to be async, let's test it safely // [no idea if it is async in reality - most probably we are operating // under some solar mutex or something anyway ;-) - but...] - m_aCommandResultCondition.reset(); + TimeValue aTimeValue = { 2 , 0 }; // 2 seconds max + // nothing is triggered when we have no callback yet, we just time out on + // the condition var. + m_aCommandResultCondition.reset(); pDocument->pClass->postUnoCommand(pDocument, ".uno:Bold", 0, true); + m_aCommandResultCondition.wait(aTimeValue); - TimeValue aTimeValue = { 2 , 0 }; // 2 seconds max + CPPUNIT_ASSERT(m_aCommandResult.isEmpty()); + + // but we get some real values when the callback is set up + pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this); + + m_aCommandResultCondition.reset(); + pDocument->pClass->postUnoCommand(pDocument, ".uno:Bold", 0, true); m_aCommandResultCondition.wait(aTimeValue); boost::property_tree::ptree aTree; diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index ca06d50..b81a6f8 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -269,8 +269,10 @@ static void doc_setView(LibreOfficeKitDocument* pThis, int nId); static int doc_getView(LibreOfficeKitDocument* pThis); static int doc_getViews(LibreOfficeKitDocument* pThis); -LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XComponent> &xComponent) : - mxComponent( xComponent ) +LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XComponent> &xComponent) + : mxComponent(xComponent) + , mpCallback(nullptr) + , mpCallbackData(nullptr) { if (!(m_pDocumentClass = gDocumentClass.lock())) { commit a4988d227c3933721098b2a61a087ec18eaa6c8e Author: Jan Holesovsky <[email protected]> Date: Tue Nov 3 16:43:03 2015 +0100 lok: Unit test for LOK_CALLBACK_UNO_COMMAND_RESULT. Change-Id: I917d47478504dc6fafd3fc675fe8458690c7cc2a diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index cbd18f7..cc48f13 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -19,6 +19,7 @@ #include <comphelper/lok.hxx> #include <comphelper/dispatchcommand.hxx> #include <comphelper/propertysequence.hxx> +#include <osl/conditn.hxx> #include <svl/srchitem.hxx> #include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <unotools/tempfile.hxx> @@ -67,6 +68,7 @@ public: void testSaveAsCalc(); void testPasteWriter(); void testRowColumnHeaders(); + void testCommandResult(); CPPUNIT_TEST_SUITE(DesktopLOKTest); CPPUNIT_TEST(testGetStyles); @@ -80,12 +82,17 @@ public: CPPUNIT_TEST(testSaveAsCalc); CPPUNIT_TEST(testPasteWriter); CPPUNIT_TEST(testRowColumnHeaders); + CPPUNIT_TEST(testCommandResult); CPPUNIT_TEST_SUITE_END(); uno::Reference<lang::XComponent> mxComponent; OString m_aTextSelection; std::vector<OString> m_aSearchResultSelection; std::vector<int> m_aSearchResultPart; + + // for testCommandResult + osl::Condition m_aCommandResultCondition; + OString m_aCommandResult; }; LibLODocument_Impl* DesktopLOKTest::loadDoc(const char* pName, LibreOfficeKitDocumentType eType) @@ -149,6 +156,12 @@ void DesktopLOKTest::callbackImpl(int nType, const char* pPayload) } } break; + case LOK_CALLBACK_UNO_COMMAND_RESULT: + { + m_aCommandResult = pPayload; + m_aCommandResultCondition.set(); + } + break; } } @@ -378,6 +391,29 @@ void DesktopLOKTest::testRowColumnHeaders() } } +void DesktopLOKTest::testCommandResult() +{ + LibLODocument_Impl* pDocument = loadDoc("blank_text.odt"); + pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this); + + // the postUnoCommand() is supposed to be async, let's test it safely + // [no idea if it is async in reality - most probably we are operating + // under some solar mutex or something anyway ;-) - but...] + m_aCommandResultCondition.reset(); + + pDocument->pClass->postUnoCommand(pDocument, ".uno:Bold", 0, true); + + TimeValue aTimeValue = { 2 , 0 }; // 2 seconds max + m_aCommandResultCondition.wait(aTimeValue); + + boost::property_tree::ptree aTree; + std::stringstream aStream(m_aCommandResult.getStr()); + boost::property_tree::read_json(aStream, aTree); + + CPPUNIT_ASSERT_EQUAL(aTree.get_child("commandName").get_value<std::string>(), std::string(".uno:Bold")); + CPPUNIT_ASSERT_EQUAL(aTree.get_child("success").get_value<bool>(), true); +} + CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest); CPPUNIT_PLUGIN_IMPLEMENT(); _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
