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>
21#include <com/sun/star/uno/Any.hxx>
22#include <com/sun/star/uno/Reference.hxx>
23#include <com/sun/star/uno/Type.h>
28#include <cppunit/TestAssert.h>
31using namespace css::uno;
42class MockedPropertyChangeListener :
public ::cppu::WeakImplHelper<beans::XPropertyChangeListener>
45 MockedPropertyChangeListener()
52 virtual void SAL_CALL propertyChange(
const beans::PropertyChangeEvent& )
override
57 virtual void SAL_CALL disposing(
const lang::EventObject& )
override {}
60class MockedVetoableChangeListener :
public ::cppu::WeakImplHelper<beans::XVetoableChangeListener>
63 MockedVetoableChangeListener()
70 virtual void SAL_CALL vetoableChange(
const beans::PropertyChangeEvent& )
override
75 virtual void SAL_CALL disposing(
const lang::EventObject& )
override {}
81 uno::Reference<beans::XPropertySet> xPropSet(
init(), uno::UNO_QUERY_THROW);
82 uno::Reference<beans::XPropertySetInfo> xPropInfo = xPropSet->getPropertySetInfo();
88 xPropSet->addPropertyChangeListener(
89 aName, uno::Reference<beans::XPropertyChangeListener>(xListener));
93 CPPUNIT_ASSERT(xListener->m_bListenerCalled);
95 xListener->m_bListenerCalled =
false;
96 xPropSet->removePropertyChangeListener(
97 aName, uno::Reference<beans::XPropertyChangeListener>(xListener));
99 CPPUNIT_ASSERT(!xListener->m_bListenerCalled);
105 uno::Reference<beans::XPropertySet> xPropSet(
init(), uno::UNO_QUERY_THROW);
106 uno::Reference<beans::XPropertySetInfo> xPropInfo = xPropSet->getPropertySetInfo();
112 xPropSet->addVetoableChangeListener(
113 aName, uno::Reference<beans::XVetoableChangeListener>(xListener));
117 CPPUNIT_ASSERT(xListener->m_bListenerCalled);
119 xListener->m_bListenerCalled =
false;
120 xPropSet->removeVetoableChangeListener(
121 aName, uno::Reference<beans::XVetoableChangeListener>(xListener));
123 CPPUNIT_ASSERT(!xListener->m_bListenerCalled);
129 uno::Reference<beans::XPropertySet> xPropSet(
init(), UNO_QUERY_THROW);
130 uno::Reference<beans::XPropertySetInfo> xPropInfo = xPropSet->getPropertySetInfo();
148 CPPUNIT_ASSERT(bSuccess);
155 uno::Reference<beans::XPropertySet> xPropSet(
init(), UNO_QUERY_THROW);
161 CPPUNIT_ASSERT(bSuccess);
168 CPPUNIT_ASSERT(bSuccess);
178 uno::Reference<beans::XPropertySet> xPropSet(
init(), UNO_QUERY_THROW);
186 bool bOld =
any.get<
bool>();
187 xPropSet->setPropertyValue(rName,
Any(!bOld));
194 xPropSet->setPropertyValue(rName,
Any(nNew));
199 sal_Int16 nOld =
any.get<sal_Int16>();
200 sal_Int16 nNew = nOld + 1;
201 xPropSet->setPropertyValue(rName,
Any(nNew));
206 sal_Int32 nOld =
any.get<sal_Int32>();
207 sal_Int32 nNew = nOld + 3;
208 xPropSet->setPropertyValue(rName,
Any(nNew));
213 sal_Int64 nOld =
any.get<sal_Int64>();
214 sal_Int64 nNew = nOld + 4;
215 xPropSet->setPropertyValue(rName,
Any(nNew));
220 float fOld =
any.get<
float>();
221 float fNew = fOld + 1.2;
222 xPropSet->setPropertyValue(rName,
Any(fNew));
227 double fOld =
any.get<
double>();
228 double fNew = fOld + 1.3;
229 xPropSet->setPropertyValue(rName,
Any(fNew));
234 OUString aOld =
any.get<OUString>();
235 OUString aNew = aOld +
"foo";
236 xPropSet->setPropertyValue(rName,
Any(aNew));
241 util::DateTime aDT =
any.get<util::DateTime>();
243 xPropSet->setPropertyValue(rName,
Any(aDT));
247 std::cout <<
"Unknown type:\n"
249 <<
type.getTypeName()
253 CPPUNIT_ASSERT_MESSAGE(
254 "XPropertySet::isPropertyValueChangeable: unknown type in Any tested.",
false);
257 uno::Any anyTest = xPropSet->getPropertyValue(rName);
258 return any != anyTest;
260 catch (
const uno::Exception&)
262 std::cout <<
"Exception thrown while retrieving with property: " << rName <<
"\n";
263 CPPUNIT_ASSERT_MESSAGE(
"XPropertySet::isPropertyValueChangeable: exception thrown while "
264 "retrieving the property value.",
276 const uno::Sequence<beans::Property> aProps = xPropInfo->getProperties();
281 std::set<OUString> aSkip;
282 aSkip.insert(
"PrinterName");
283 aSkip.insert(
"CharRelief");
284 aSkip.insert(
"IsLayerMode");
286 for (
const beans::Property& aProp : aProps)
288 if (aSkip.count(aProp.Name) > 0)
291 if ((aProp.Attributes & beans::PropertyAttribute::READONLY) != 0)
297 if ((aProp.Attributes & beans::PropertyAttribute::MAYBEVOID) != 0)
300 bool bBound = (aProp.Attributes & beans::PropertyAttribute::BOUND) != 0;
301 bool bConstrained = (aProp.Attributes & beans::PropertyAttribute::CONSTRAINED) != 0;
304 if (bBound && bCanChange)
307 if (bConstrained && bCanChange)
318 const OUString& rName)
322 xPropSet->getPropertyValue(rName);
325 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)
std::vector< OUString > readonly
std::vector< OUString > normal
std::vector< OUString > bound
std::vector< OUString > constrained