comphelper: test uno::Any parsing from JSON

Fails with commit cccbf8608f3b76651993bc8576c672367c228fa2 (feat(json):
Allow serializing any, 2024-10-16) reverted.

Change-Id: Ifd59f9921f89cc4f52a21a597f433684c715f186
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176044
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
This commit is contained in:
Miklos Vajna 2024-10-18 12:57:34 +02:00
parent c8d59dad00
commit ad3f929a73

View file

@ -13,6 +13,8 @@
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <com/sun/star/awt/Size.hpp>
#include <comphelper/propertyvalue.hxx>
#include <comphelper/propertysequence.hxx>
#include <cppu/unotype.hxx>
@ -29,6 +31,7 @@ class MakePropertyValueTest : public CppUnit::TestFixture
CPPUNIT_TEST(testRvalue);
CPPUNIT_TEST(testBitField);
CPPUNIT_TEST(testJson);
CPPUNIT_TEST(testJsonAwtSize);
CPPUNIT_TEST_SUITE_END();
void testLvalue()
@ -123,6 +126,44 @@ class MakePropertyValueTest : public CppUnit::TestFixture
CPPUNIT_ASSERT_EQUAL(u"ADDIN ZOTERO_ITEM new command 1"_ustr,
aFirstSeq[1].Value.get<OUString>());
}
void testJsonAwtSize()
{
// Given a list of beans::PropertyValues in JSON:
OString aJson = R"json(
{
"mykey": {
"type": "any",
"value": {
"type": "com.sun.star.awt.Size",
"value": {
"Width": {
"type": "long",
"value": 42
},
"Height": {
"type": "long",
"value": 43
}
}
}
}
}
)json"_ostr;
// When parsing that:
std::vector<beans::PropertyValue> aRet = comphelper::JsonToPropertyValues(aJson);
// Then make sure we can construct an awt::Size:
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aRet.size());
beans::PropertyValue aFirst = aRet[0];
CPPUNIT_ASSERT_EQUAL(OUString("mykey"), aFirst.Name);
// Without the accompanying fix in place, this test would have failed with:
// - Cannot extract an Any(void) to com.sun.star.awt.Size
auto aSize = aFirst.Value.get<awt::Size>();
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(42), aSize.Width);
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(43), aSize.Height);
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(MakePropertyValueTest);