Blame SOURCES/0270-lok-Unit-test-for-LOK_CALLBACK_UNO_COMMAND_RESULT.patch

135360
From 8e7c77d0706c4a2870de61948364667b575ff027 Mon Sep 17 00:00:00 2001
135360
From: Jan Holesovsky <kendy@collabora.com>
135360
Date: Tue, 3 Nov 2015 16:43:03 +0100
135360
Subject: [PATCH 270/398] lok: Unit test for LOK_CALLBACK_UNO_COMMAND_RESULT.
135360
135360
Change-Id: I917d47478504dc6fafd3fc675fe8458690c7cc2a
135360
(cherry picked from commit a4988d227c3933721098b2a61a087ec18eaa6c8e)
135360
---
135360
 desktop/qa/desktop_lib/test_desktop_lib.cxx | 36 +++++++++++++++++++++++++++++
135360
 1 file changed, 36 insertions(+)
135360
135360
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
index 29b0aedd4dfa..15fe123fdc37 100644
135360
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
@@ -19,6 +19,7 @@
135360
 #include <comphelper/lok.hxx>
135360
 #include <comphelper/dispatchcommand.hxx>
135360
 #include <comphelper/propertysequence.hxx>
135360
+#include <osl/conditn.hxx>
135360
 #include <svl/srchitem.hxx>
135360
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
135360
 #include <unotools/tempfile.hxx>
135360
@@ -67,6 +68,7 @@ public:
135360
     void testSaveAsCalc();
135360
     void testPasteWriter();
135360
     void testRowColumnHeaders();
135360
+    void testCommandResult();
135360
 
135360
     CPPUNIT_TEST_SUITE(DesktopLOKTest);
135360
     CPPUNIT_TEST(testGetStyles);
135360
@@ -80,12 +82,17 @@ public:
135360
     CPPUNIT_TEST(testSaveAsCalc);
135360
     CPPUNIT_TEST(testPasteWriter);
135360
     CPPUNIT_TEST(testRowColumnHeaders);
135360
+    CPPUNIT_TEST(testCommandResult);
135360
     CPPUNIT_TEST_SUITE_END();
135360
 
135360
     uno::Reference<lang::XComponent> mxComponent;
135360
     OString m_aTextSelection;
135360
     std::vector<OString> m_aSearchResultSelection;
135360
     std::vector<int> m_aSearchResultPart;
135360
+
135360
+    // for testCommandResult
135360
+    osl::Condition m_aCommandResultCondition;
135360
+    OString m_aCommandResult;
135360
 };
135360
 
135360
 LibLODocument_Impl* DesktopLOKTest::loadDoc(const char* pName, LibreOfficeKitDocumentType eType)
135360
@@ -149,6 +156,12 @@ void DesktopLOKTest::callbackImpl(int nType, const char* pPayload)
135360
         }
135360
     }
135360
     break;
135360
+    case LOK_CALLBACK_UNO_COMMAND_RESULT:
135360
+    {
135360
+        m_aCommandResult = pPayload;
135360
+        m_aCommandResultCondition.set();
135360
+    }
135360
+    break;
135360
     }
135360
 }
135360
 
135360
@@ -378,6 +391,29 @@ void DesktopLOKTest::testRowColumnHeaders()
135360
     }
135360
 }
135360
 
135360
+void DesktopLOKTest::testCommandResult()
135360
+{
135360
+    LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
135360
+    pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this);
135360
+
135360
+    // the postUnoCommand() is supposed to be async, let's test it safely
135360
+    // [no idea if it is async in reality - most probably we are operating
135360
+    // under some solar mutex or something anyway ;-) - but...]
135360
+    m_aCommandResultCondition.reset();
135360
+
135360
+    pDocument->pClass->postUnoCommand(pDocument, ".uno:Bold", 0, true);
135360
+
135360
+    TimeValue aTimeValue = { 2 , 0 }; // 2 seconds max
135360
+    m_aCommandResultCondition.wait(aTimeValue);
135360
+
135360
+    boost::property_tree::ptree aTree;
135360
+    std::stringstream aStream(m_aCommandResult.getStr());
135360
+    boost::property_tree::read_json(aStream, aTree);
135360
+
135360
+    CPPUNIT_ASSERT_EQUAL(aTree.get_child("commandName").get_value<std::string>(), std::string(".uno:Bold"));
135360
+    CPPUNIT_ASSERT_EQUAL(aTree.get_child("success").get_value<bool>(), true);
135360
+}
135360
+
135360
 CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
135360
 
135360
 CPPUNIT_PLUGIN_IMPLEMENT();
135360
-- 
135360
2.12.0
135360