[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - desktop/CppunitTest_desktop_lokinit.mk desktop/inc desktop/Module_desktop.mk desktop/qa desktop/source
Jan Holesovsky
kendy at collabora.com
Wed Jun 20 19:36:11 UTC 2018
desktop/CppunitTest_desktop_lokinit.mk | 47 +++++++++++++++++++
desktop/Module_desktop.mk | 1
desktop/inc/lib/init.hxx | 6 ++
desktop/qa/unit/desktop-lok-init.cxx | 78 +++++++++++++++++++++++++++++++++
desktop/source/lib/init.cxx | 2
5 files changed, 133 insertions(+), 1 deletion(-)
New commits:
commit fc5e70050a6a9abf4eec1688eae7d53db6816483
Author: Jan Holesovsky <kendy at collabora.com>
Date: Tue Jun 19 00:00:05 2018 +0200
lok: Unit test for jsonToPropertyValuesVector.
Change-Id: I3e0623cc68838c650edbd03cc89bf3fcb8098ff8
Reviewed-on: https://gerrit.libreoffice.org/56149
Tested-by: Jenkins
Reviewed-by: Jan Holesovsky <kendy at collabora.com>
(cherry picked from commit 666edd059b360b38add0acd959ea7e2ab5c7c5fd)
Reviewed-on: https://gerrit.libreoffice.org/56204
Tested-by: Jan Holesovsky <kendy at collabora.com>
diff --git a/desktop/CppunitTest_desktop_lokinit.mk b/desktop/CppunitTest_desktop_lokinit.mk
new file mode 100644
index 000000000000..fb9e71bccfe2
--- /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 e18b23126dff..12c5e53e0a1e 100644
--- a/desktop/Module_desktop.mk
+++ b/desktop/Module_desktop.mk
@@ -137,6 +137,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 78b3437f4ef4..cb8afa899b76 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/lang/XComponent.hpp>
#include <desktop/dllapi.h>
@@ -98,6 +100,10 @@ namespace desktop {
/// comma, like: Name1=Value1,Name2=Value2,Name3=Value3.
/// @param rOptions When extracted, 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..fa751bb64eaa
--- /dev/null
+++ b/desktop/qa/unit/desktop-lok-init.cxx
@@ -0,0 +1,78 @@
+/* -*- 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));
+ }
+}
+} // namespace
+
+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 df318560aacd..60f6d5e0f18b 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -295,7 +295,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')
More information about the Libreoffice-commits
mailing list