[Libreoffice-commits] core.git: include/test test/Library_test.mk test/source
Jens Carl
j.carl43 at gmx.de
Sun Mar 18 04:53:28 UTC 2018
include/test/unoapi_property_testers.hxx | 61 ++++++++++++++++++
test/Library_test.mk | 1
test/source/unoapi_property_testers.cxx | 102 +++++++++++++++++++++++++++++++
3 files changed, 164 insertions(+)
New commits:
commit c671b277275d2173b8235bcda1aa3f17dbe6deb5
Author: Jens Carl <j.carl43 at gmx.de>
Date: Wed Mar 14 08:31:03 2018 +0000
Create UNO API property testers for common types
Create UNO API property testers for common, so it's possible to share/use
them between all the UNO API service property tests.
Testers are available for the types 'boolean', 'long', 'short', and
'string'.
Change-Id: Ia36dba98c774695b3ba6ac9d9917af9fb20efdba
Reviewed-on: https://gerrit.libreoffice.org/51259
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Jens Carl <j.carl43 at gmx.de>
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: */
More information about the Libreoffice-commits
mailing list