comphelper/qa/unit/propertyvalue.cxx | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
New commits: commit 94c0664d54d9979dac61cf6e78e0110282f8703e Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri Oct 18 12:57:34 2024 +0200 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Mon Oct 21 15:06:10 2024 +0200 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/+/175128 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/comphelper/qa/unit/propertyvalue.cxx b/comphelper/qa/unit/propertyvalue.cxx index 4470b28f503a..a7cb204fc5e2 100644 --- a/comphelper/qa/unit/propertyvalue.cxx +++ b/comphelper/qa/unit/propertyvalue.cxx @@ -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(OUString("ADDIN ZOTERO_ITEM new command 1"), 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);