summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/test/unoapi_property_testers.hxx61
-rw-r--r--test/Library_test.mk1
-rw-r--r--test/source/unoapi_property_testers.cxx102
3 files changed, 164 insertions, 0 deletions
diff --git a/include/test/unoapi_property_testers.hxx b/include/test/unoapi_property_testers.hxx
new file mode 100644
index 000000000000..c0c7cc86dd70
--- /dev/null
+++ b/include/test/unoapi_property_testers.hxx
@@ -0,0 +1,61 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_TEST_SHEET_UNOAPIPROPERTYHELPER_HXX
+#define INCLUDED_TEST_SHEET_UNOAPIPROPERTYHELPER_HXX
+
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/uno/Reference.hxx>
+
+#include <sal/config.h>
+#include <test/testdllapi.hxx>
+
+namespace apitest
+{
+/** @brief Tester for test property type 'boolean' 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.
+ */
+void OOO_DLLPUBLIC_TEST testBooleanProperty(
+ css::uno::Reference<css::beans::XPropertySet>& xPropertySet, const OUString& name);
+
+/** @brief Tester for test 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
+testLongProperty(css::uno::Reference<css::beans::XPropertySet>& xPropertySet, const OUString& name,
+ const sal_Int32& nValue);
+
+/** @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.
+ * @param name Name of property to test.
+ * @param nValue Value to use when setting a new value.
+ */
+void OOO_DLLPUBLIC_TEST
+testShortProperty(css::uno::Reference<css::beans::XPropertySet>& xPropertySet, const OUString& name,
+ const sal_Int16& nValue);
+
+/** @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.
+ * @param name Name of property to test.
+ * @param rValue Value to use when setting a new value.
+ */
+void OOO_DLLPUBLIC_TEST
+testStringProperty(css::uno::Reference<css::beans::XPropertySet>& xPropertySet,
+ const OUString& name, const OUString& rValue);
+}
+#endif // INCLUDED_TEST_SHEET_UNOAPIPROPERTYHELPER_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/test/Library_test.mk b/test/Library_test.mk
index c3fcdd020f1b..47d0ffbec381 100644
--- a/test/Library_test.mk
+++ b/test/Library_test.mk
@@ -47,6 +47,7 @@ $(eval $(call gb_Library_add_exception_objects,test,\
test/source/mtfxmldump \
test/source/primitive2dxmldump \
test/source/screenshot_test \
+ test/source/unoapi_property_testers \
))
# vim: set noet sw=4 ts=4:
diff --git a/test/source/unoapi_property_testers.cxx b/test/source/unoapi_property_testers.cxx
new file mode 100644
index 000000000000..e84ab8d7e7ab
--- /dev/null
+++ b/test/source/unoapi_property_testers.cxx
@@ -0,0 +1,102 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <test/unoapi_property_testers.hxx>
+
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/uno/Reference.hxx>
+
+#include <cppunit/extensions/HelperMacros.h>
+
+using namespace com::sun::star;
+using namespace com::sun::star::uno;
+
+namespace apitest
+{
+void testBooleanProperty(uno::Reference<beans::XPropertySet>& xPropertySet, const OUString& name)
+{
+ uno::Any aNewValue;
+
+ bool bPropertyGet = false;
+ bool bPropertySet = false;
+
+ OString msgGet
+ = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
+ CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= bPropertyGet);
+
+ aNewValue <<= !bPropertyGet;
+ xPropertySet->setPropertyValue(name, aNewValue);
+ CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= bPropertySet);
+ OString msgSet
+ = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), !bPropertyGet, bPropertySet);
+}
+
+void testLongProperty(uno::Reference<beans::XPropertySet>& xPropertySet, const OUString& name,
+ const sal_Int32& nValue = 42)
+{
+ 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
+ = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), nValue, nPropertySet);
+}
+
+void testShortProperty(uno::Reference<beans::XPropertySet>& xPropertySet, const OUString& name,
+ const sal_Int16& nValue = 42)
+{
+ 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
+ = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), nValue, nPropertySet);
+}
+
+void testStringProperty(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
+ = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), rValue, sPropertySet);
+}
+}
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */