summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2018-06-19 00:00:05 +0200
committerJan Holesovsky <kendy@collabora.com>2018-06-20 21:33:41 +0200
commit666edd059b360b38add0acd959ea7e2ab5c7c5fd (patch)
tree294d6217f4880e510df0d7f7aed8b2667f99ffde /desktop
parent87674a28893520eb8bb528c7e774a7ed926976cb (diff)
lok: Unit test for jsonToPropertyValuesVector.
Change-Id: I3e0623cc68838c650edbd03cc89bf3fcb8098ff8 Reviewed-on: https://gerrit.libreoffice.org/56149 Tested-by: Jenkins Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Diffstat (limited to 'desktop')
-rw-r--r--desktop/CppunitTest_desktop_lokinit.mk47
-rw-r--r--desktop/Module_desktop.mk1
-rw-r--r--desktop/inc/lib/init.hxx6
-rw-r--r--desktop/qa/unit/desktop-lok-init.cxx78
-rw-r--r--desktop/source/lib/init.cxx2
5 files changed, 133 insertions, 1 deletions
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 878febd603fb..086e51e6ea26 100644
--- a/desktop/Module_desktop.mk
+++ b/desktop/Module_desktop.mk
@@ -139,6 +139,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 a9cc9b8bb90f..a3723158e2c7 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -293,7 +293,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')