diff --git a/comphelper/qa/unit/propertyvalue.cxx b/comphelper/qa/unit/propertyvalue.cxx index 4523bb49d352..0b747dd60894 100644 --- a/comphelper/qa/unit/propertyvalue.cxx +++ b/comphelper/qa/unit/propertyvalue.cxx @@ -13,6 +13,8 @@ #include #include +#include + #include #include #include @@ -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()); } + + 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 aRet = comphelper::JsonToPropertyValues(aJson); + + // Then make sure we can construct an awt::Size: + CPPUNIT_ASSERT_EQUAL(static_cast(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(); + CPPUNIT_ASSERT_EQUAL(static_cast(42), aSize.Width); + CPPUNIT_ASSERT_EQUAL(static_cast(43), aSize.Height); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(MakePropertyValueTest);