From d55837cc6ab736dd78b965e13c96d41d59dca1b6 Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Mon, 30 Apr 2012 16:47:51 -0400 Subject: Implemented test for XPropertySet::setPropertyValue(). Also cover all UNO primitive types in isPropertyValueChangeable(). Change-Id: I21a1809ed2a6b58f68ef82252f513991e0f012af --- test/source/beans/xpropertyset.cxx | 67 ++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 14 deletions(-) (limited to 'test/source/beans/xpropertyset.cxx') diff --git a/test/source/beans/xpropertyset.cxx b/test/source/beans/xpropertyset.cxx index ffa1a01cefff..96283d26fc22 100644 --- a/test/source/beans/xpropertyset.cxx +++ b/test/source/beans/xpropertyset.cxx @@ -69,9 +69,12 @@ void XPropertySet::testAddVetoableChangeListener() void XPropertySet::testSetPropertyValue() { testGetPropertySetInfo(); - uno::Reference xPropSet(init(), UNO_QUERY_THROW); - // TODO: implement this. + for (size_t i = 0, n = maPropsToTest.normal.size(); i < n; ++i) + { + bool bSuccess = isPropertyValueChangeable(maPropsToTest.normal[i]); + CPPUNIT_ASSERT(bSuccess); + } } void XPropertySet::testGetPropertyValue() @@ -116,10 +119,48 @@ bool XPropertySet::isPropertyValueChangeable(const rtl::OUString& rName) // boolean type sal_Bool bOld = any.get(); xPropSet->setPropertyValue(rName, makeAny(!bOld)); - any = xPropSet->getPropertyValue(rName); - sal_Bool bNew = any.get(); - - return bOld != bNew; + } + else if (type == getCppuType()) + { + // 8-bit integer + sal_Int8 nOld = any.get(); + sal_Int8 nNew = nOld + 1; + xPropSet->setPropertyValue(rName, makeAny(nNew)); + } + else if (type == getCppuType()) + { + // 16-bit integer + sal_Int16 nOld = any.get(); + sal_Int16 nNew = nOld + 2; + xPropSet->setPropertyValue(rName, makeAny(nNew)); + } + else if (type == getCppuType()) + { + // 32-bit integer + sal_Int32 nOld = any.get(); + sal_Int32 nNew = nOld + 3; + xPropSet->setPropertyValue(rName, makeAny(nNew)); + } + else if (type == getCppuType()) + { + // 64-bit integer + sal_Int64 nOld = any.get(); + sal_Int64 nNew = nOld + 4; + xPropSet->setPropertyValue(rName, makeAny(nNew)); + } + else if (type == getCppuType()) + { + // single precision + float fOld = any.get(); + float fNew = fOld + 1.2; + xPropSet->setPropertyValue(rName, makeAny(fNew)); + } + else if (type == getCppuType()) + { + // double precision + double fOld = any.get(); + double fNew = fOld + 1.3; + xPropSet->setPropertyValue(rName, makeAny(fNew)); } else if (type == getCppuType()) { @@ -127,16 +168,14 @@ bool XPropertySet::isPropertyValueChangeable(const rtl::OUString& rName) rtl::OUString aOld = any.get(); rtl::OUString aNew = aOld + rtl::OUString("foo"); xPropSet->setPropertyValue(rName, makeAny(aNew)); - any = xPropSet->getPropertyValue(rName); - rtl::OUString aTest = any.get(); - return aOld != aTest; + } + else + { + CPPUNIT_ASSERT_MESSAGE("XPropertySet::isChangeable: unknown type in Any tested.", false); } - // TODO: add more primitive types to cover. For specialized types, - // the client code should provide the test code to change their values - // by overwriting this method. - - CPPUNIT_ASSERT_MESSAGE("XPropertySet::isChangeable: unknown type in Any tested.", false); + uno::Any anyTest = xPropSet->getPropertyValue(rName); + return any != anyTest; } catch (const uno::Exception&) { -- cgit v1.2.1