diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-11-25 16:32:37 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-11-25 17:52:36 +0100 |
commit | 1e83197fdd4263ca4817a6ac16f274aaee3e66fd (patch) | |
tree | 90bb75aaba4193b79bc09078fbcaa8cdb08d38f0 /comphelper | |
parent | fd05a0f9ccebaee6f0175281fdeb6fe3f3168fd2 (diff) |
comphelper: support property values arrays in JsonToPropertyValues()
Needed for an uncoming .uno:TextFormFields uno command where one of the
parameters has the []com.sun.star.beans.PropertyValues type at an UNO
level, and we can't provide JSON at the moment that would express that.
Change-Id: I288a540b2fcac0e5a4a82bca235199c559ba2d0c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143302
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/qa/unit/propertyvalue.cxx | 71 | ||||
-rw-r--r-- | comphelper/source/misc/sequenceashashmap.cxx | 14 |
2 files changed, 85 insertions, 0 deletions
diff --git a/comphelper/qa/unit/propertyvalue.cxx b/comphelper/qa/unit/propertyvalue.cxx index 40f60bb0463d..738022917e9d 100644 --- a/comphelper/qa/unit/propertyvalue.cxx +++ b/comphelper/qa/unit/propertyvalue.cxx @@ -14,9 +14,12 @@ #include <cppunit/extensions/HelperMacros.h> #include <comphelper/propertyvalue.hxx> +#include <comphelper/propertysequence.hxx> #include <cppu/unotype.hxx> #include <o3tl/any.hxx> +using namespace com::sun::star; + namespace { class MakePropertyValueTest : public CppUnit::TestFixture @@ -25,6 +28,7 @@ class MakePropertyValueTest : public CppUnit::TestFixture CPPUNIT_TEST(testLvalue); CPPUNIT_TEST(testRvalue); CPPUNIT_TEST(testBitField); + CPPUNIT_TEST(testJson); CPPUNIT_TEST_SUITE_END(); void testLvalue() @@ -52,6 +56,73 @@ class MakePropertyValueTest : public CppUnit::TestFixture CPPUNIT_ASSERT_EQUAL(cppu::UnoType<bool>::get(), v.Value.getValueType()); CPPUNIT_ASSERT_EQUAL(false, *o3tl::doAccess<bool>(v.Value)); } + + void testJson() + { + std::vector<beans::PropertyValue> aRet = comphelper::JsonToPropertyValues(R"json( +{ + "FieldType": { + "type": "string", + "value": "vnd.oasis.opendocument.field.UNHANDLED" + }, + "FieldCommandPrefix": { + "type": "string", + "value": "ADDIN ZOTERO_ITEM" + }, + "Fields": { + "type": "[][]com.sun.star.beans.PropertyValue", + "value": [ + { + "FieldType": { + "type": "string", + "value": "vnd.oasis.opendocument.field.UNHANDLED" + }, + "FieldCommand": { + "type": "string", + "value": "ADDIN ZOTERO_ITEM new command 1" + }, + "Fields": { + "type": "string", + "value": "new result 1" + } + }, + { + "FieldType": { + "type": "string", + "value": "vnd.oasis.opendocument.field.UNHANDLED" + }, + "FieldCommandPrefix": { + "type": "string", + "value": "ADDIN ZOTERO_ITEM new command 2" + }, + "Fields": { + "type": "string", + "value": "new result 2" + } + } + ] + } +} +)json"); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aRet.size()); + beans::PropertyValue aFirst = aRet[0]; + CPPUNIT_ASSERT_EQUAL(OUString("FieldType"), aFirst.Name); + CPPUNIT_ASSERT_EQUAL(OUString("vnd.oasis.opendocument.field.UNHANDLED"), + aFirst.Value.get<OUString>()); + beans::PropertyValue aSecond = aRet[1]; + CPPUNIT_ASSERT_EQUAL(OUString("FieldCommandPrefix"), aSecond.Name); + CPPUNIT_ASSERT_EQUAL(OUString("ADDIN ZOTERO_ITEM"), aSecond.Value.get<OUString>()); + beans::PropertyValue aThird = aRet[2]; + CPPUNIT_ASSERT_EQUAL(OUString("Fields"), aThird.Name); + uno::Sequence<uno::Sequence<beans::PropertyValue>> aSeqs; + aThird.Value >>= aSeqs; + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), aSeqs.getLength()); + uno::Sequence<beans::PropertyValue> aFirstSeq = aSeqs[0]; + CPPUNIT_ASSERT_EQUAL(OUString("FieldType"), aFirstSeq[0].Name); + CPPUNIT_ASSERT_EQUAL(OUString("FieldCommand"), aFirstSeq[1].Name); + CPPUNIT_ASSERT_EQUAL(OUString("ADDIN ZOTERO_ITEM new command 1"), + aFirstSeq[1].Value.get<OUString>()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(MakePropertyValueTest); diff --git a/comphelper/source/misc/sequenceashashmap.cxx b/comphelper/source/misc/sequenceashashmap.cxx index 34a6a0c8a580..b18202aab5f5 100644 --- a/comphelper/source/misc/sequenceashashmap.cxx +++ b/comphelper/source/misc/sequenceashashmap.cxx @@ -31,6 +31,7 @@ #include <comphelper/propertysequence.hxx> #include <sal/log.hxx> #include <o3tl/string_view.hxx> +#include <comphelper/sequence.hxx> using namespace com::sun::star; @@ -366,6 +367,19 @@ std::vector<css::beans::PropertyValue> JsonToPropertyValues(const OString& rJson aValue.Value <<= aSeq; } } + else if (rType == "[][]com.sun.star.beans.PropertyValue") + { + aNodeValue = rPair.second.get_child("value", aNodeNull); + std::vector<uno::Sequence<beans::PropertyValue>> aSeqs; + for (const auto& rItem : aNodeValue) + { + std::stringstream s; + boost::property_tree::write_json(s, rItem.second); + std::vector<beans::PropertyValue> aPropertyValues = JsonToPropertyValues(s.str().c_str()); + aSeqs.push_back(comphelper::containerToSequence(aPropertyValues)); + } + aValue.Value <<= comphelper::containerToSequence(aSeqs); + } else SAL_WARN("comphelper", "JsonToPropertyValues: unhandled type '" << rType << "'"); aArguments.push_back(aValue); |