Kaydet (Commit) c671b277 authored tarafından Jens Carl's avatar Jens Carl

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/51259Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarJens Carl <j.carl43@gmx.de>
üst 6f487bab
/* -*- 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: */
......@@ -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:
/* -*- 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: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment