desktop/CppunitTest_desktop_lokinit.mk |   49 +++++++++++
 desktop/Module_desktop.mk              |    1 
 desktop/inc/lib/init.hxx               |    6 +
 desktop/qa/unit/desktop-lok-init.cxx   |  140 +++++++++++++++++++++++++++++++++
 desktop/source/lib/init.cxx            |   83 ++++++++++++++++++-
 5 files changed, 275 insertions(+), 4 deletions(-)

New commits:
commit 749780c9b5e2922417a7686efc3e4f609bb20264
Author: Jan Holesovsky <ke...@collabora.com>
Date:   Tue Jun 19 01:18:08 2018 +0200

    lok: Unit test for passing table borders via jsonToPropertyValuesVector.
    
    Change-Id: Iadc0d76a1903d76fcd84f316d4796cc1dec13277

diff --git a/desktop/CppunitTest_desktop_lokinit.mk 
b/desktop/CppunitTest_desktop_lokinit.mk
index 91493dee4530..07d235861d90 100644
--- a/desktop/CppunitTest_desktop_lokinit.mk
+++ b/desktop/CppunitTest_desktop_lokinit.mk
@@ -19,6 +19,8 @@ $(eval $(call 
gb_CppunitTest_use_external,desktop_lok_init,boost_headers))
 
 $(eval $(call gb_CppunitTest_use_sdk_api,desktop_lok_init))
 
+$(eval $(call gb_CppunitTest_use_ure,desktop_lok_init))
+
 $(eval $(call gb_CppunitTest_set_include,desktop_lok_init,\
     -I$(SRCDIR)/desktop/source/inc \
     -I$(SRCDIR)/desktop/inc \
diff --git a/desktop/qa/unit/desktop-lok-init.cxx 
b/desktop/qa/unit/desktop-lok-init.cxx
index 07abe887ccfd..69c209e9055e 100644
--- a/desktop/qa/unit/desktop-lok-init.cxx
+++ b/desktop/qa/unit/desktop-lok-init.cxx
@@ -20,10 +20,13 @@
 
 #include <osl/file.hxx>
 #include <rtl/bootstrap.hxx>
-#include <vcl/scheduler.hxx>
+#include <tools/colordata.hxx>
 
 #include <lib/init.hxx>
 
+#include <com/sun/star/table/BorderLine2.hpp>
+#include <com/sun/star/table/BorderLineStyle.hpp>
+
 using namespace css;
 
 /// Unit tests for desktop/source/lib/init.cxx internals.
@@ -35,9 +38,11 @@ public:
     }
 
     void testJsonToPropertyValues();
+    void testJsonToPropertyValuesBorder();
 
     CPPUNIT_TEST_SUITE(LOKInitTest);
     CPPUNIT_TEST(testJsonToPropertyValues);
+    CPPUNIT_TEST(testJsonToPropertyValuesBorder);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -70,6 +75,64 @@ void LOKInitTest::testJsonToPropertyValues()
     assertSequencesEqual(aArgs, 
comphelper::containerToSequence(desktop::jsonToPropertyValuesVector(arguments)));
 }
 
+void LOKInitTest::testJsonToPropertyValuesBorder()
+{
+    const char arguments[] = "{"
+        "\"OuterBorder\": {"
+            "\"type\" : \"[]any\","
+            "\"value\" : ["
+                "{ \"type\" : \"com.sun.star.table.BorderLine2\", \"value\" : 
{ \"Color\" : { \"type\" : \"com.sun.star.util.Color\", \"value\" : 0 }, 
\"InnerLineWidth\" : { \"type\" : \"short\", \"value\" : 0 }, 
\"OuterLineWidth\" : { \"type\" : \"short\", \"value\" : 1 }, \"LineDistance\" 
: { \"type\" : \"short\", \"value\" : 0 },  \"LineStyle\" : { \"type\" : 
\"short\", \"value\" : 0 }, \"LineWidth\" : { \"type\" : \"unsigned long\", 
\"value\" : 1 } } },"
+                "{ \"type\" : \"com.sun.star.table.BorderLine2\", \"value\" : 
{ \"Color\" : { \"type\" : \"com.sun.star.util.Color\", \"value\" : 0 }, 
\"InnerLineWidth\" : { \"type\" : \"short\", \"value\" : 0 }, 
\"OuterLineWidth\" : { \"type\" : \"short\", \"value\" : 1 }, \"LineDistance\" 
: { \"type\" : \"short\", \"value\" : 0 },  \"LineStyle\" : { \"type\" : 
\"short\", \"value\" : 0 }, \"LineWidth\" : { \"type\" : \"unsigned long\", 
\"value\" : 1 } } },"
+                "{ \"type\" : \"com.sun.star.table.BorderLine2\", \"value\" : 
{ \"Color\" : { \"type\" : \"com.sun.star.util.Color\", \"value\" : 0 }, 
\"InnerLineWidth\" : { \"type\" : \"short\", \"value\" : 0 }, 
\"OuterLineWidth\" : { \"type\" : \"short\", \"value\" : 1 }, \"LineDistance\" 
: { \"type\" : \"short\", \"value\" : 0 },  \"LineStyle\" : { \"type\" : 
\"short\", \"value\" : 0 }, \"LineWidth\" : { \"type\" : \"unsigned long\", 
\"value\" : 1 } } },"
+                "{ \"type\" : \"com.sun.star.table.BorderLine2\", \"value\" : 
{ \"Color\" : { \"type\" : \"com.sun.star.util.Color\", \"value\" : 0 }, 
\"InnerLineWidth\" : { \"type\" : \"short\", \"value\" : 0 }, 
\"OuterLineWidth\" : { \"type\" : \"short\", \"value\" : 1 }, \"LineDistance\" 
: { \"type\" : \"short\", \"value\" : 0 },  \"LineStyle\" : { \"type\" : 
\"short\", \"value\" : 0 }, \"LineWidth\" : { \"type\" : \"unsigned long\", 
\"value\" : 1 } } },"
+                "{ \"type\" : \"long\", \"value\" : 0 },"
+                "{ \"type\" : \"long\", \"value\" : 0 },"
+                "{ \"type\" : \"long\", \"value\" : 0 },"
+                "{ \"type\" : \"long\", \"value\" : 0 },"
+                "{ \"type\" : \"long\", \"value\" : 0 }"
+            "]"
+        "},"
+        "\"InnerBorder\":{"
+            "\"type\" : \"[]any\","
+            "\"value\" : ["
+                "{ \"type\" : \"com.sun.star.table.BorderLine2\", \"value\" : 
{ \"Color\" : { \"type\" : \"com.sun.star.util.Color\", \"value\" : 0 }, 
\"InnerLineWidth\" : { \"type\" : \"short\", \"value\" : 0 }, 
\"OuterLineWidth\" : { \"type\" : \"short\", \"value\" : 1 }, \"LineDistance\" 
: { \"type\" : \"short\", \"value\" : 0 },  \"LineStyle\" : { \"type\" : 
\"short\", \"value\" : 0 }, \"LineWidth\" : { \"type\" : \"unsigned long\", 
\"value\" : 1 } } },"
+                "{ \"type\" : \"com.sun.star.table.BorderLine2\", \"value\" : 
{ \"Color\" : { \"type\" : \"com.sun.star.util.Color\", \"value\" : 0 }, 
\"InnerLineWidth\" : { \"type\" : \"short\", \"value\" : 0 }, 
\"OuterLineWidth\" : { \"type\" : \"short\", \"value\" : 1 }, \"LineDistance\" 
: { \"type\" : \"short\", \"value\" : 0 },  \"LineStyle\" : { \"type\" : 
\"short\", \"value\" : 0 }, \"LineWidth\" : { \"type\" : \"unsigned long\", 
\"value\" : 1 } } },"
+                "{ \"type\" : \"short\", \"value\" : 0 },"
+                "{ \"type\" : \"short\", \"value\" : 127 },"
+                "{ \"type\" : \"long\", \"value\" : 0 }"
+            "]"
+        "}}";
+
+    // see SvxBoxItem::QueryValue for details
+    uno::Sequence<uno::Any> aOuterSeq(9);
+    table::BorderLine2 aLine(sal_Int32(COL_BLACK), 0, 1, 0, 
table::BorderLineStyle::SOLID, 1);
+    aOuterSeq[0] = uno::makeAny(aLine); // left
+    aOuterSeq[1] = uno::makeAny(aLine); // right
+    aOuterSeq[2] = uno::makeAny(aLine); // bottom
+    aOuterSeq[3] = uno::makeAny(aLine); // top
+    aOuterSeq[4] = uno::makeAny((sal_Int32)(0));
+    aOuterSeq[5] = uno::makeAny((sal_Int32)(0));
+    aOuterSeq[6] = uno::makeAny((sal_Int32)(0));
+    aOuterSeq[7] = uno::makeAny((sal_Int32)(0));
+    aOuterSeq[8] = uno::makeAny((sal_Int32)(0));
+
+    // see SvxBoxInfoItem::QueryValue() for details
+    uno::Sequence<uno::Any> aInnerSeq(5);
+    aInnerSeq[0] = uno::makeAny(aLine); // horizontal
+    aInnerSeq[1] = uno::makeAny(aLine); // vertical
+    aInnerSeq[2] = uno::makeAny((sal_Int16)(0));
+    aInnerSeq[3] = uno::makeAny((sal_Int16)(0x7F));
+    aInnerSeq[4] = uno::makeAny((sal_Int32)(0));
+
+    uno::Sequence<beans::PropertyValue> aArgs(2);
+    aArgs[0].Name = "OuterBorder";
+    aArgs[0].Value <<= aOuterSeq;
+    aArgs[1].Name = "InnerBorder";
+    aArgs[1].Value <<= aInnerSeq;
+
+    assertSequencesEqual(aArgs, 
comphelper::containerToSequence(desktop::jsonToPropertyValuesVector(arguments)));
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(LOKInitTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
commit f4e8bbe596cb337c36c3e80b53cac3f4beb85685
Author: Jan Holesovsky <ke...@collabora.com>
Date:   Tue Jun 19 00:00:05 2018 +0200

    lok: Unit test for jsonToPropertyValuesVector.
    
    Change-Id: I3e0623cc68838c650edbd03cc89bf3fcb8098ff8

diff --git a/desktop/CppunitTest_desktop_lokinit.mk 
b/desktop/CppunitTest_desktop_lokinit.mk
new file mode 100644
index 000000000000..91493dee4530
--- /dev/null
+++ b/desktop/CppunitTest_desktop_lokinit.mk
@@ -0,0 +1,47 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,desktop_lok_init))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,desktop_lok_init, \
+    desktop/qa/unit/desktop-lok-init \
+))
+
+$(eval $(call gb_CppunitTest_use_external,desktop_lok_init,boost_headers))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,desktop_lok_init))
+
+$(eval $(call gb_CppunitTest_set_include,desktop_lok_init,\
+    -I$(SRCDIR)/desktop/source/inc \
+    -I$(SRCDIR)/desktop/inc \
+    $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,desktop_lok_init, \
+       comphelper \
+       cppu \
+       sal \
+       sofficeapp \
+       vcl \
+       $(gb_UWINAPI) \
+))
+
+ifeq ($(OS),LINUX)
+$(eval $(call gb_CppunitTest_add_libs,desktop_lok_init,\
+    -lm \
+    -ldl \
+    -lpthread \
+))
+endif
+
+$(eval $(call gb_CppunitTest_use_configuration,desktop_lok_init))
+
+# vim: set noet sw=4 ts=4:
diff --git a/desktop/Module_desktop.mk b/desktop/Module_desktop.mk
index 17ec5bf52b12..ca527504ee40 100644
--- a/desktop/Module_desktop.mk
+++ b/desktop/Module_desktop.mk
@@ -143,6 +143,7 @@ $(eval $(call gb_Module_add_check_targets,desktop, \
 ifeq ($(OS),LINUX)
 $(eval $(call gb_Module_add_check_targets,desktop, \
     CppunitTest_desktop_lib \
+    CppunitTest_desktop_lokinit \
 ))
 endif
 
diff --git a/desktop/inc/lib/init.hxx b/desktop/inc/lib/init.hxx
index c8162c1fea2f..2cb76ee3c9e2 100644
--- a/desktop/inc/lib/init.hxx
+++ b/desktop/inc/lib/init.hxx
@@ -16,9 +16,11 @@
 #include <mutex>
 
 #include <osl/thread.h>
+#include <rtl/ref.hxx>
 #include <vcl/idle.hxx>
 #include <LibreOfficeKit/LibreOfficeKit.h>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
+#include <com/sun/star/beans/PropertyValue.hpp>
 #include <com/sun/star/frame/XStorable.hpp>
 #include <com/sun/star/lang/XComponent.hpp>
 
@@ -99,6 +101,10 @@ namespace desktop {
     /// comma, like: Name1=Value1,Name2=Value2,Name3=Value3.
     /// @param rOptions When exctacted, the Param=Value is removed from it.
     DESKTOP_DLLPUBLIC OUString extractParameter(OUString& aOptions, const 
OUString& rName);
+
+    /// Helper function to convert JSON to a vector of PropertyValues.
+    /// Public to be unit-test-able.
+    DESKTOP_DLLPUBLIC std::vector<com::sun::star::beans::PropertyValue> 
jsonToPropertyValuesVector(const char* pJSON);
 }
 
 #endif
diff --git a/desktop/qa/unit/desktop-lok-init.cxx 
b/desktop/qa/unit/desktop-lok-init.cxx
new file mode 100644
index 000000000000..07abe887ccfd
--- /dev/null
+++ b/desktop/qa/unit/desktop-lok-init.cxx
@@ -0,0 +1,77 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <memory>
+#include <boost/property_tree/json_parser.hpp>
+#include <cppunit/TestFixture.h>
+#include <cppunit/plugin/TestPlugIn.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <comphelper/anytostring.hxx>
+#include <comphelper/sequence.hxx>
+#include <cstdlib>
+#include <string>
+#include <stdio.h>
+
+#include <osl/file.hxx>
+#include <rtl/bootstrap.hxx>
+#include <vcl/scheduler.hxx>
+
+#include <lib/init.hxx>
+
+using namespace css;
+
+/// Unit tests for desktop/source/lib/init.cxx internals.
+class LOKInitTest : public ::CppUnit::TestFixture
+{
+public:
+    LOKInitTest()
+    {
+    }
+
+    void testJsonToPropertyValues();
+
+    CPPUNIT_TEST_SUITE(LOKInitTest);
+    CPPUNIT_TEST(testJsonToPropertyValues);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+namespace {
+
+void assertSequencesEqual(const uno::Sequence<beans::PropertyValue>& expected, 
const uno::Sequence<beans::PropertyValue>& actual)
+{
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("The sequences should have the same length", 
expected.getLength(), actual.getLength());
+    for (int i = 0; i < expected.getLength(); ++i)
+    {
+        CPPUNIT_ASSERT_EQUAL(expected[i].Name, actual[i].Name);
+        CPPUNIT_ASSERT_EQUAL(comphelper::anyToString(expected[i].Value), 
comphelper::anyToString(actual[i].Value));
+    }
+}
+
+}
+
+void LOKInitTest::testJsonToPropertyValues()
+{
+    const char arguments[] = "{"
+        "\"FileName\":{"
+            "\"type\":\"string\","
+            "\"value\":\"something.odt\""
+        "}}";
+
+    uno::Sequence<beans::PropertyValue> aArgs(1);
+    aArgs[0].Name = "FileName";
+    aArgs[0].Value <<= OUString("something.odt");
+
+    assertSequencesEqual(aArgs, 
comphelper::containerToSequence(desktop::jsonToPropertyValuesVector(arguments)));
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(LOKInitTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index f6143bad55e3..b0079d0f5f16 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -311,7 +311,7 @@ static uno::Any jsonToUnoAny(const 
boost::property_tree::ptree& aTree)
     return aAny;
 }
 
-static std::vector<beans::PropertyValue> jsonToPropertyValuesVector(const 
char* pJSON)
+std::vector<beans::PropertyValue> desktop::jsonToPropertyValuesVector(const 
char* pJSON)
 {
     std::vector<beans::PropertyValue> aArguments;
     if (pJSON && pJSON[0] != '\0')
commit 1664de4d0b02bd99a14048244cdb8c1d7db3007a
Author: Henry Castro <hcas...@collabora.com>
Date:   Mon Jun 18 08:28:40 2018 -0400

    lokit: add jsonToUnoAny
    
    Change-Id: I79c2fe22fe7f3a8daa121ecaa529b6bca3216bf3

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index f550958ab4f1..f6143bad55e3 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -48,6 +48,9 @@
 #include <com/sun/star/lang/Locale.hpp>
 #include <com/sun/star/lang/XComponent.hpp>
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/reflection/theCoreReflection.hpp>
+#include <com/sun/star/reflection/XIdlClass.hpp>
+#include <com/sun/star/reflection/XIdlReflection.hpp>
 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
 #include <com/sun/star/ucb/XContentProvider.hpp>
 #include <com/sun/star/ucb/XUniversalContentBroker.hpp>
@@ -248,19 +251,79 @@ static OUString getAbsoluteURL(const char* pURL)
     return OUString();
 }
 
+static uno::Any jsonToUnoAny(const boost::property_tree::ptree& aTree)
+{
+    uno::Any aAny;
+    uno::Any aValue;
+    sal_Int32 nFields;
+    uno::TypeClass aTypeClass;
+    uno::Reference< reflection::XIdlField > aField;
+    boost::property_tree::ptree aNodeNull, aNodeValue, aNodeField;
+    const std::string& rType = aTree.get<std::string>("type", "");
+    const std::string& rValue = aTree.get<std::string>("value", "");
+    uno::Sequence< uno::Reference< reflection::XIdlField > > aFields;
+    uno::Reference< reflection:: XIdlClass > xIdlClass =
+        
css::reflection::theCoreReflection::get(comphelper::getProcessComponentContext())->forName(OUString::fromUtf8(rType.c_str()));
+    if (xIdlClass.is())
+    {
+        aTypeClass = xIdlClass->getTypeClass();
+        xIdlClass->createObject(aAny);
+        aFields = xIdlClass->getFields();
+        nFields = aFields.getLength();
+        aNodeValue = aTree.get_child("value", aNodeNull);
+        if (nFields > 0 && aNodeValue != aNodeNull)
+        {
+            for (sal_Int32 itField = 0; itField < nFields; ++itField)
+            {
+                aField = aFields[itField];
+                aNodeField = 
aNodeValue.get_child(aField->getName().toUtf8().getStr(), aNodeNull);
+                if (aNodeField != aNodeNull)
+                {
+                    aValue = jsonToUnoAny(aNodeField);
+                    aField->set(aAny, aValue);
+                }
+            }
+        }
+        else if (!rValue.empty())
+        {
+            if (aTypeClass == uno::TypeClass_VOID)
+                aAny.clear();
+            else if (aTypeClass == uno::TypeClass_BYTE)
+                aAny <<= 
static_cast<sal_Int8>(OString(rValue.c_str()).toInt32());
+            else if (aTypeClass == uno::TypeClass_BOOLEAN)
+                aAny <<= OString(rValue.c_str()).toBoolean();
+            else if (aTypeClass == uno::TypeClass_SHORT)
+                aAny <<= 
static_cast<sal_Int16>(OString(rValue.c_str()).toInt32());
+            else if (aTypeClass == uno::TypeClass_UNSIGNED_SHORT)
+                aAny <<= 
static_cast<sal_uInt16>(OString(rValue.c_str()).toUInt32());
+            else if (aTypeClass == uno::TypeClass_LONG)
+                aAny <<= OString(rValue.c_str()).toInt32();
+            else if (aTypeClass == uno::TypeClass_UNSIGNED_LONG)
+                aAny <<= 
static_cast<sal_uInt32>(OString(rValue.c_str()).toInt32());
+            else if (aTypeClass == uno::TypeClass_FLOAT)
+                aAny <<= OString(rValue.c_str()).toFloat();
+            else if (aTypeClass == uno::TypeClass_DOUBLE)
+                aAny <<= OString(rValue.c_str()).toDouble();
+            else if (aTypeClass == uno::TypeClass_STRING)
+                aAny <<= OUString::fromUtf8(rValue.c_str());
+        }
+    }
+    return aAny;
+}
+
 static std::vector<beans::PropertyValue> jsonToPropertyValuesVector(const 
char* pJSON)
 {
     std::vector<beans::PropertyValue> aArguments;
     if (pJSON && pJSON[0] != '\0')
     {
-        boost::property_tree::ptree aTree;
+        boost::property_tree::ptree aTree, aNodeNull, aNodeValue;
         std::stringstream aStream(pJSON);
         boost::property_tree::read_json(aStream, aTree);
 
         for (const auto& rPair : aTree)
         {
-            const std::string& rType = rPair.second.get<std::string>("type");
-            const std::string& rValue = rPair.second.get<std::string>("value");
+            const std::string& rType = rPair.second.get<std::string>("type", 
"");
+            const std::string& rValue = rPair.second.get<std::string>("value", 
"");
 
             beans::PropertyValue aValue;
             aValue.Name = OUString::fromUtf8(rPair.first.c_str());
@@ -274,6 +337,18 @@ static std::vector<beans::PropertyValue> 
jsonToPropertyValuesVector(const char*
                 aValue.Value <<= OString(rValue.c_str()).toInt32();
             else if (rType == "unsigned short")
                 aValue.Value <<= 
static_cast<sal_uInt16>(OString(rValue.c_str()).toUInt32());
+            else if (rType == "[]any")
+            {
+                aNodeValue = rPair.second.get_child("value", aNodeNull);
+                if (aNodeValue != aNodeNull && aNodeValue.size() > 0)
+                {
+                    sal_Int32 itSeq = 0;
+                    uno::Sequence< uno::Any > aSeq(aNodeValue.size());
+                    for (const auto& rSeqPair : aNodeValue)
+                        aSeq[itSeq++] = jsonToUnoAny(rSeqPair.second);
+                    aValue.Value <<= aSeq;
+                }
+            }
             else
                 SAL_WARN("desktop.lib", "jsonToPropertyValuesVector: unhandled 
type '"<<rType<<"'");
             aArguments.push_back(aValue);
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to