From c671b277275d2173b8235bcda1aa3f17dbe6deb5 Mon Sep 17 00:00:00 2001 From: Jens Carl Date: Wed, 14 Mar 2018 08:31:03 +0000 Subject: 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 Reviewed-by: Jens Carl --- test/source/unoapi_property_testers.cxx | 102 ++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 test/source/unoapi_property_testers.cxx (limited to 'test/source') 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 + +#include +#include +#include + +#include + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void testBooleanProperty(uno::Reference& 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& 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& 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& 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: */ -- cgit