Add UNO API property tester for common read-only properties.

Add UNO API property tester for read-only properties 'double', 'long',
'short' and 'string'.

Change-Id: I7177e133972058b0272a3cf8493521fbfbcade32
Reviewed-on: https://gerrit.libreoffice.org/52142
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Jens Carl <j.carl43@gmx.de>
diff --git a/test/inc/unoapi_property_testers.hxx b/test/inc/unoapi_property_testers.hxx
index 43e0f50..616ab3b 100644
--- a/test/inc/unoapi_property_testers.hxx
+++ b/test/inc/unoapi_property_testers.hxx
@@ -44,6 +44,16 @@ void OOO_DLLPUBLIC_TEST
testDoubleProperty(css::uno::Reference<css::beans::XPropertySet>& xPropertySet,
                   const OUString& name, const double& dValue = 42.0);

/** @brief Tester for read-only property type 'double' of a @see com::sun::star::beans::XPropertySet.
 *
 * @param   xPropertySet    The property set, which contains the property to test against.
 * @param   name            Name of property to test.
 * @param   nValue          Value to use when setting a new value.
 */
void OOO_DLLPUBLIC_TEST
testDoubleReadonlyProperty(css::uno::Reference<css::beans::XPropertySet>& xPropertySet,
                           const OUString& name, const double& dValue = 42.0);

/** @brief Tester for property type 'long' of a @see com::sun::star::beans::XPropertySet.
 *
 * @param   xPropertySet    The property set, which contains the property to test against.
@@ -54,6 +64,16 @@ void OOO_DLLPUBLIC_TEST
testLongProperty(css::uno::Reference<css::beans::XPropertySet>& xPropertySet, const OUString& name,
                 const sal_Int32& nValue = 42);

/** @brief Tester for read-only property type 'long' of a @see com::sun::star::beans::XPropertySet.
 *
 * @param   xPropertySet    The property set, which contains the property to test against.
 * @param   name            Name of property to test.
 * @param   nValue          Value to use when setting a new value.
 */
void OOO_DLLPUBLIC_TEST
testLongReadonlyProperty(css::uno::Reference<css::beans::XPropertySet>& xPropertySet,
                         const OUString& name, const sal_Int32& nValue = 42);

/** @brief Tester for property type 'short' of a @see com::sun::star::beans::XPropertySet.
 *
 * @param   xPropertySet    The property set, which contains the property to test against.
@@ -64,6 +84,16 @@ void OOO_DLLPUBLIC_TEST
testShortProperty(css::uno::Reference<css::beans::XPropertySet>& xPropertySet, const OUString& name,
                  const sal_Int16& nValue = 42);

/** @brief Tester for read-only property type 'short' of a @see com::sun::star::beans::XPropertySet.
 *
 * @param   xPropertySet    The property set, which contains the property to test against.
 * @param   name            Name of property to test.
 * @param   nValue          Value to use when setting a new value.
 */
void OOO_DLLPUBLIC_TEST
testShortReadonlyProperty(css::uno::Reference<css::beans::XPropertySet>& xPropertySet,
                          const OUString& name, const sal_Int16& nValue = 42);

/** @brief Tester for property type 'string' of a @see com::sun::star::beans::XPropertySet.
 *
 * @param   xPropertySet    The property set, which contains the property to test against.
@@ -73,7 +103,17 @@ testShortProperty(css::uno::Reference<css::beans::XPropertySet>& xPropertySet, c
void OOO_DLLPUBLIC_TEST
testStringProperty(css::uno::Reference<css::beans::XPropertySet>& xPropertySet,
                   const OUString& name, const OUString& rValue);
}

/** @brief Tester for read-only property type 'string' of a @see com::sun::star::beans::XPropertySet.
 *
 * @param   xPropertySet    The property set, which contains the property to test against.
 * @param   name            Name of property to test.
 * @param   rValue          Value to use when setting a new value.
 */
void OOO_DLLPUBLIC_TEST
testStringReadonlyProperty(css::uno::Reference<css::beans::XPropertySet>& xPropertySet,
                           const OUString& name, const OUString& rValue);
} // namespace apitest
#endif // INCLUDED_TEST_INC_UNOAPIPROPERTYTESTERS_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/test/source/unoapi_property_testers.cxx b/test/source/unoapi_property_testers.cxx
index 14f4b31..6758936 100644
--- a/test/source/unoapi_property_testers.cxx
+++ b/test/source/unoapi_property_testers.cxx
@@ -63,19 +63,38 @@ void testDoubleProperty(uno::Reference<beans::XPropertySet>& xPropertySet, const
{
    uno::Any aNewValue;

    double nPropertyGet;
    double nPropertySet;
    double dPropertyGet;
    double dPropertySet;

    OString msgGet
        = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
    CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= nPropertyGet);
    CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= dPropertyGet);

    aNewValue <<= dValue;
    xPropertySet->setPropertyValue(name, aNewValue);
    CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= nPropertySet);
    CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= dPropertySet);
    OString msgSet
        = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(msgSet.getStr(), dValue, nPropertySet, 0.5);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(msgSet.getStr(), dValue, dPropertySet, 0.5);
}

void testDoubleReadonlyProperty(uno::Reference<beans::XPropertySet>& xPropertySet,
                                const OUString& name, const double& dValue)
{
    uno::Any aNewValue;

    double dPropertyGet;
    double dPropertySet;

    OString msgGet
        = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
    CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= dPropertyGet);

    aNewValue <<= dValue;
    xPropertySet->setPropertyValue(name, aNewValue);
    CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= dPropertySet);
    OString msgSet = "Able to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(msgSet.getStr(), dPropertyGet, dPropertySet, 0.5);
}

void testLongProperty(uno::Reference<beans::XPropertySet>& xPropertySet, const OUString& name,
@@ -98,6 +117,25 @@ void testLongProperty(uno::Reference<beans::XPropertySet>& xPropertySet, const O
    CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), nValue, nPropertySet);
}

void testLongReadonlyProperty(uno::Reference<beans::XPropertySet>& xPropertySet,
                              const OUString& name, const sal_Int32& nValue)
{
    uno::Any aNewValue;

    sal_Int32 nPropertyGet;
    sal_Int32 nPropertySet;

    OString msgGet
        = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
    CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= nPropertyGet);

    aNewValue <<= nValue;
    xPropertySet->setPropertyValue(name, aNewValue);
    CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= nPropertySet);
    OString msgSet = "Able to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
    CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), nPropertyGet, nPropertySet);
}

void testShortProperty(uno::Reference<beans::XPropertySet>& xPropertySet, const OUString& name,
                       const sal_Int16& nValue)
{
@@ -118,6 +156,25 @@ void testShortProperty(uno::Reference<beans::XPropertySet>& xPropertySet, const 
    CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), nValue, nPropertySet);
}

void testShortReadonlyProperty(uno::Reference<beans::XPropertySet>& xPropertySet,
                               const OUString& name, const sal_Int16& nValue)
{
    uno::Any aNewValue;

    sal_Int16 nPropertyGet;
    sal_Int16 nPropertySet;

    OString msgGet
        = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
    CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= nPropertyGet);

    aNewValue <<= nValue;
    xPropertySet->setPropertyValue(name, aNewValue);
    CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= nPropertySet);
    OString msgSet = "Able to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
    CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), nPropertyGet, nPropertySet);
}

void testStringProperty(uno::Reference<beans::XPropertySet>& xPropertySet, const OUString& name,
                        const OUString& rValue)
{
@@ -137,5 +194,25 @@ void testStringProperty(uno::Reference<beans::XPropertySet>& xPropertySet, const
        = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
    CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), rValue, sPropertySet);
}

void testStringReadonlyProperty(uno::Reference<beans::XPropertySet>& xPropertySet,
                                const OUString& name, const OUString& rValue)
{
    uno::Any aNewValue;

    OUString sPropertyGet;
    OUString sPropertySet;

    OString msgGet
        = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
    CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= sPropertyGet);

    aNewValue <<= rValue;
    xPropertySet->setPropertyValue(name, aNewValue);
    CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= sPropertySet);
    OString msgSet = "Able to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
    CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), sPropertyGet, sPropertySet);
}
} // namespace apitest

/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */