[Libreoffice-commits] .: test/source

Kohei Yoshida kohei at kemper.freedesktop.org
Mon Apr 30 13:48:47 PDT 2012


 test/source/beans/xpropertyset.cxx |   67 +++++++++++++++++++++++++++++--------
 1 file changed, 53 insertions(+), 14 deletions(-)

New commits:
commit d55837cc6ab736dd78b965e13c96d41d59dca1b6
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Mon Apr 30 16:47:51 2012 -0400

    Implemented test for XPropertySet::setPropertyValue().
    
    Also cover all UNO primitive types in isPropertyValueChangeable().
    
    Change-Id: I21a1809ed2a6b58f68ef82252f513991e0f012af

diff --git a/test/source/beans/xpropertyset.cxx b/test/source/beans/xpropertyset.cxx
index ffa1a01..96283d2 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<beans::XPropertySet> 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<sal_Bool>();
             xPropSet->setPropertyValue(rName, makeAny(!bOld));
-            any = xPropSet->getPropertyValue(rName);
-            sal_Bool bNew = any.get<sal_Bool>();
-
-            return bOld != bNew;
+        }
+        else if (type == getCppuType<sal_Int8>())
+        {
+            // 8-bit integer
+            sal_Int8 nOld = any.get<sal_Int8>();
+            sal_Int8 nNew = nOld + 1;
+            xPropSet->setPropertyValue(rName, makeAny(nNew));
+        }
+        else if (type == getCppuType<sal_Int16>())
+        {
+            // 16-bit integer
+            sal_Int16 nOld = any.get<sal_Int16>();
+            sal_Int16 nNew = nOld + 2;
+            xPropSet->setPropertyValue(rName, makeAny(nNew));
+        }
+        else if (type == getCppuType<sal_Int32>())
+        {
+            // 32-bit integer
+            sal_Int32 nOld = any.get<sal_Int32>();
+            sal_Int32 nNew = nOld + 3;
+            xPropSet->setPropertyValue(rName, makeAny(nNew));
+        }
+        else if (type == getCppuType<sal_Int64>())
+        {
+            // 64-bit integer
+            sal_Int64 nOld = any.get<sal_Int64>();
+            sal_Int64 nNew = nOld + 4;
+            xPropSet->setPropertyValue(rName, makeAny(nNew));
+        }
+        else if (type == getCppuType<float>())
+        {
+            // single precision
+            float fOld = any.get<float>();
+            float fNew = fOld + 1.2;
+            xPropSet->setPropertyValue(rName, makeAny(fNew));
+        }
+        else if (type == getCppuType<double>())
+        {
+            // double precision
+            double fOld = any.get<double>();
+            double fNew = fOld + 1.3;
+            xPropSet->setPropertyValue(rName, makeAny(fNew));
         }
         else if (type == getCppuType<rtl::OUString>())
         {
@@ -127,16 +168,14 @@ bool XPropertySet::isPropertyValueChangeable(const rtl::OUString& rName)
             rtl::OUString aOld = any.get<rtl::OUString>();
             rtl::OUString aNew = aOld + rtl::OUString("foo");
             xPropSet->setPropertyValue(rName, makeAny(aNew));
-            any = xPropSet->getPropertyValue(rName);
-            rtl::OUString aTest = any.get<rtl::OUString>();
-            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&)
     {


More information about the Libreoffice-commits mailing list