Kaydet (Commit) 666edd05 authored tarafından Jan Holesovsky's avatar Jan Holesovsky

lok: Unit test for jsonToPropertyValuesVector.

Change-Id: I3e0623cc68838c650edbd03cc89bf3fcb8098ff8
Reviewed-on: https://gerrit.libreoffice.org/56149
Tested-by: Jenkins
Reviewed-by: 's avatarJan Holesovsky <kendy@collabora.com>
üst 87674a28
# -*- 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:
......@@ -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
......
......@@ -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
......
/* -*- 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: */
......@@ -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')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment