summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2018-06-19 00:00:05 +0200
committerJan Holesovsky <kendy@collabora.com>2018-06-19 13:55:53 +0200
commitf4e8bbe596cb337c36c3e80b53cac3f4beb85685 (patch)
tree693b2678fc0e49d10e0e4fe679d529520a6d9cab
parent1664de4d0b02bd99a14048244cdb8c1d7db3007a (diff)
lok: Unit test for jsonToPropertyValuesVector.
Change-Id: I3e0623cc68838c650edbd03cc89bf3fcb8098ff8
-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.cxx77
-rw-r--r--desktop/source/lib/init.cxx2
5 files changed, 132 insertions, 1 deletions
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')