12#include <com/sun/star/beans/Property.hpp>
13#include <com/sun/star/beans/PropertyAttribute.hpp>
14#include <com/sun/star/beans/PropertyChangeEvent.hpp>
15#include <com/sun/star/beans/XPropertyChangeListener.hpp>
16#include <com/sun/star/beans/XPropertySet.hpp>
17#include <com/sun/star/beans/XVetoableChangeListener.hpp>
18#include <com/sun/star/lang/EventObject.hpp>
19#include <com/sun/star/util/DateTime.hpp>
20#include <com/sun/star/util/XComplexColor.hpp>
22#include <com/sun/star/uno/Any.hxx>
23#include <com/sun/star/uno/Reference.hxx>
24#include <com/sun/star/uno/Type.h>
30#include <cppunit/TestAssert.h>
33using namespace css::uno;
44class MockedPropertyChangeListener :
public ::cppu::WeakImplHelper<beans::XPropertyChangeListener>
47 MockedPropertyChangeListener()
54 virtual void SAL_CALL propertyChange(
const beans::PropertyChangeEvent& )
override
59 virtual void SAL_CALL disposing(
const lang::EventObject& )
override {}
62class MockedVetoableChangeListener :
public ::cppu::WeakImplHelper<beans::XVetoableChangeListener>
65 MockedVetoableChangeListener()
72 virtual void SAL_CALL vetoableChange(
const beans::PropertyChangeEvent& )
override
77 virtual void SAL_CALL disposing(
const lang::EventObject& )
override {}
83 uno::Reference<beans::XPropertySet> xPropSet(
init(), uno::UNO_QUERY_THROW);
84 uno::Reference<beans::XPropertySetInfo> xPropInfo = xPropSet->getPropertySetInfo();
90 xPropSet->addPropertyChangeListener(
91 aName, uno::Reference<beans::XPropertyChangeListener>(xListener));
95 CPPUNIT_ASSERT(xListener->m_bListenerCalled);
97 xListener->m_bListenerCalled =
false;
98 xPropSet->removePropertyChangeListener(
99 aName, uno::Reference<beans::XPropertyChangeListener>(xListener));
101 CPPUNIT_ASSERT(!xListener->m_bListenerCalled);
107 uno::Reference<beans::XPropertySet> xPropSet(
init(), uno::UNO_QUERY_THROW);
108 uno::Reference<beans::XPropertySetInfo> xPropInfo = xPropSet->getPropertySetInfo();
114 xPropSet->addVetoableChangeListener(
115 aName, uno::Reference<beans::XVetoableChangeListener>(xListener));
119 CPPUNIT_ASSERT(xListener->m_bListenerCalled);
121 xListener->m_bListenerCalled =
false;
122 xPropSet->removeVetoableChangeListener(
123 aName, uno::Reference<beans::XVetoableChangeListener>(xListener));
125 CPPUNIT_ASSERT(!xListener->m_bListenerCalled);
131 uno::Reference<beans::XPropertySet> xPropSet(
init(), UNO_QUERY_THROW);
132 uno::Reference<beans::XPropertySetInfo> xPropInfo = xPropSet->getPropertySetInfo();
150 CPPUNIT_ASSERT(bSuccess);
157 uno::Reference<beans::XPropertySet> xPropSet(
init(), UNO_QUERY_THROW);
163 CPPUNIT_ASSERT(bSuccess);
170 CPPUNIT_ASSERT(bSuccess);
180 uno::Reference<beans::XPropertySet> xPropSet(
init(), UNO_QUERY_THROW);
188 bool bOld =
any.get<
bool>();
189 xPropSet->setPropertyValue(rName,
Any(!bOld));
196 xPropSet->setPropertyValue(rName,
Any(nNew));
201 sal_Int16 nOld =
any.get<sal_Int16>();
202 sal_Int16 nNew = nOld + 1;
203 xPropSet->setPropertyValue(rName,
Any(nNew));
208 sal_Int32 nOld =
any.get<sal_Int32>();
209 sal_Int32 nNew = nOld + 3;
210 xPropSet->setPropertyValue(rName,
Any(nNew));
215 sal_Int64 nOld =
any.get<sal_Int64>();
216 sal_Int64 nNew = nOld + 4;
217 xPropSet->setPropertyValue(rName,
Any(nNew));
222 float fOld =
any.get<
float>();
223 float fNew = fOld + 1.2;
224 xPropSet->setPropertyValue(rName,
Any(fNew));
229 double fOld =
any.get<
double>();
230 double fNew = fOld + 1.3;
231 xPropSet->setPropertyValue(rName,
Any(fNew));
236 OUString aOld =
any.get<OUString>();
237 OUString aNew = aOld +
"foo";
238 xPropSet->setPropertyValue(rName,
Any(aNew));
243 util::DateTime aDT =
any.get<util::DateTime>();
245 xPropSet->setPropertyValue(rName,
Any(aDT));
249 auto xComplexColor =
any.get<uno::Reference<util::XComplexColor>>();
251 xPropSet->setPropertyValue(rName,
256 std::cout <<
"Unknown type:\n"
258 <<
type.getTypeName()
262 CPPUNIT_ASSERT_MESSAGE(
263 "XPropertySet::isPropertyValueChangeable: unknown type in Any tested.",
false);
266 uno::Any anyTest = xPropSet->getPropertyValue(rName);
267 return any != anyTest;
269 catch (
const uno::Exception&)
271 std::cout <<
"Exception thrown while retrieving with property: " << rName <<
"\n";
272 CPPUNIT_ASSERT_MESSAGE(
"XPropertySet::isPropertyValueChangeable: exception thrown while "
273 "retrieving the property value.",
285 const uno::Sequence<beans::Property> aProps = xPropInfo->getProperties();
290 std::set<OUString> aSkip;
291 aSkip.insert(
"PrinterName");
292 aSkip.insert(
"CharRelief");
293 aSkip.insert(
"IsLayerMode");
295 for (
const beans::Property& aProp : aProps)
297 if (aSkip.count(aProp.Name) > 0)
300 if ((aProp.Attributes & beans::PropertyAttribute::READONLY) != 0)
306 if ((aProp.Attributes & beans::PropertyAttribute::MAYBEVOID) != 0)
309 bool bBound = (aProp.Attributes & beans::PropertyAttribute::BOUND) != 0;
310 bool bConstrained = (aProp.Attributes & beans::PropertyAttribute::CONSTRAINED) != 0;
313 if (bBound && bCanChange)
316 if (bConstrained && bCanChange)
327 const OUString& rName)
331 xPropSet->getPropertyValue(rName);
334 catch (
const uno::Exception&)
void fillPropsToTest(const css::uno::Reference< css::beans::XPropertySetInfo > &xPropInfo)
void testGetPropertyValue()
PropsToTest maPropsToTest
bool isPropertyValueChangeable(const OUString &rName)
void testPropertyChangeListener()
void testVetoableChangeListener()
void testSetPropertyValue()
void testGetPropertySetInfo()
virtual css::uno::Reference< css::uno::XInterface > init()=0
static bool getSinglePropertyValue(const css::uno::Reference< css::beans::XPropertySet > &xPropSet, const OUString &rName)
std::set< OUString > m_IgnoreValue
virtual bool isPropertyIgnored(const OUString &rName)
model::ComplexColor getFromXComplexColor(uno::Reference< util::XComplexColor > const &rxColor)
uno::Reference< util::XComplexColor > createXComplexColor(model::ComplexColor const &rColor)
std::vector< OUString > readonly
std::vector< OUString > normal
std::vector< OUString > bound
std::vector< OUString > constrained