From 8e7c77d0706c4a2870de61948364667b575ff027 Mon Sep 17 00:00:00 2001 From: Jan Holesovsky Date: Tue, 3 Nov 2015 16:43:03 +0100 Subject: [PATCH 270/398] lok: Unit test for LOK_CALLBACK_UNO_COMMAND_RESULT. Change-Id: I917d47478504dc6fafd3fc675fe8458690c7cc2a (cherry picked from commit a4988d227c3933721098b2a61a087ec18eaa6c8e) --- desktop/qa/desktop_lib/test_desktop_lib.cxx | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 29b0aedd4dfa..15fe123fdc37 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -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 mxComponent; OString m_aTextSelection; std::vector m_aSearchResultSelection; std::vector 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(".uno:Bold")); + CPPUNIT_ASSERT_EQUAL(aTree.get_child("success").get_value(), true); +} + CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest); CPPUNIT_PLUGIN_IMPLEMENT(); -- 2.12.0