diff options
author | Jens Carl <j.carl43@gmx.de> | 2018-03-14 08:31:03 +0000 |
---|---|---|
committer | Jens Carl <j.carl43@gmx.de> | 2018-03-18 05:53:07 +0100 |
commit | c671b277275d2173b8235bcda1aa3f17dbe6deb5 (patch) | |
tree | 25aceb2f59e7ca572d0a1785371902c8dfed09b1 /test | |
parent | 6f487baba0a63e775a20911551b83feb82a327f5 (diff) |
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@libreoffice.org>
Reviewed-by: Jens Carl <j.carl43@gmx.de>
Diffstat (limited to 'test')
-rw-r--r-- | test/Library_test.mk | 1 | ||||
-rw-r--r-- | test/source/unoapi_property_testers.cxx | 102 |
2 files changed, 103 insertions, 0 deletions
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: */ |