[Libreoffice-commits] .: 2 commits - sc/qa test/inc test/Library_subsequenttest.mk test/Package_inc.mk test/source

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


 sc/qa/extras/sceditfieldobj-cell.cxx   |   11 +
 sc/qa/extras/sceditfieldobj-header.cxx |   10 +
 test/Library_subsequenttest.mk         |    1 
 test/Package_inc.mk                    |    1 
 test/inc/test/beans/xpropertyset.hxx   |   86 +++++++++++++
 test/source/beans/xpropertyset.cxx     |  211 +++++++++++++++++++++++++++++++++
 6 files changed, 316 insertions(+), 4 deletions(-)

New commits:
commit 8ac758d5490c53df5e8ec539c37af062bedc72fa
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Mon Apr 30 16:17:05 2012 -0400

    Test for XPropertySet.  This is still work-in-progress.
    
    Change-Id: Icf8ddddb9a45435968bc43d8bc7a033ce5cfd702

diff --git a/sc/qa/extras/sceditfieldobj-cell.cxx b/sc/qa/extras/sceditfieldobj-cell.cxx
index e7ad2ed..ab3217a 100644
--- a/sc/qa/extras/sceditfieldobj-cell.cxx
+++ b/sc/qa/extras/sceditfieldobj-cell.cxx
@@ -27,6 +27,7 @@
  */
 
 #include <test/unoapi_test.hxx>
+#include <test/beans/xpropertyset.hxx>
 #include <test/text/xtextfield.hxx>
 #include <test/text/xtextcontent.hxx>
 
@@ -38,11 +39,11 @@
 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
 #include <com/sun/star/sheet/XSpreadsheet.hpp>
 
-#define NUMBER_OF_TESTS 3
+#define NUMBER_OF_TESTS 5
 
 namespace sc_apitest {
 
-class ScEditFieldObj_Cell : public UnoApiTest, apitest::XTextField, apitest::XTextContent
+class ScEditFieldObj_Cell : public UnoApiTest, apitest::XTextField, apitest::XTextContent, apitest::XPropertySet
 {
 public:
     ScEditFieldObj_Cell();
@@ -55,8 +56,14 @@ public:
     virtual bool isAttachSupported() { return true; }
 
     CPPUNIT_TEST_SUITE(ScEditFieldObj_Cell);
+
+    // XPropertySet
+    CPPUNIT_TEST(testGetPropertySetInfo);
+    CPPUNIT_TEST(testGetPropertyValue);
+
     // XTextField
     CPPUNIT_TEST(testGetPresentation);
+
     // XTextContent
     CPPUNIT_TEST(testGetAnchor);
     CPPUNIT_TEST(testAttach);
diff --git a/sc/qa/extras/sceditfieldobj-header.cxx b/sc/qa/extras/sceditfieldobj-header.cxx
index 44bdeb5..e11dfde 100644
--- a/sc/qa/extras/sceditfieldobj-header.cxx
+++ b/sc/qa/extras/sceditfieldobj-header.cxx
@@ -27,6 +27,7 @@
  */
 
 #include <test/unoapi_test.hxx>
+#include <test/beans/xpropertyset.hxx>
 #include <test/text/xtextfield.hxx>
 #include <test/text/xtextcontent.hxx>
 
@@ -41,11 +42,11 @@
 #include <com/sun/star/sheet/XSpreadsheet.hpp>
 #include <com/sun/star/sheet/XHeaderFooterContent.hpp>
 
-#define NUMBER_OF_TESTS 2
+#define NUMBER_OF_TESTS 4
 
 namespace sc_apitest {
 
-class ScEditFieldObj_Header : public UnoApiTest, apitest::XTextContent
+class ScEditFieldObj_Header : public UnoApiTest, apitest::XTextContent, apitest::XPropertySet
 {
 public:
     ScEditFieldObj_Header();
@@ -58,6 +59,11 @@ public:
     virtual bool isAttachSupported() { return false; }
 
     CPPUNIT_TEST_SUITE(ScEditFieldObj_Header);
+
+    // XPropertySet
+    CPPUNIT_TEST(testGetPropertySetInfo);
+    CPPUNIT_TEST(testGetPropertyValue);
+
     // XTextContent
     CPPUNIT_TEST(testGetAnchor);
     CPPUNIT_TEST(testAttach);
commit 8bffba8222f1edecd4664ea0ef5e686a369ca72f
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Mon Apr 30 16:15:29 2012 -0400

    Started porting the XPropertySet test code.
    
    Not all its tests have been converted.  This is work-in-progress.
    
    Change-Id: I90a789852e05a214440e4f87011b6de3d3d4d08a

diff --git a/test/Library_subsequenttest.mk b/test/Library_subsequenttest.mk
index a7c5e41..e10df28 100644
--- a/test/Library_subsequenttest.mk
+++ b/test/Library_subsequenttest.mk
@@ -62,6 +62,7 @@ $(eval $(call gb_Library_use_external,subsequenttest,cppunit))
 
 $(eval $(call gb_Library_add_exception_objects,subsequenttest,\
     test/source/unoapi_test \
+    test/source/beans/xpropertyset \
     test/source/container/xelementaccess \
     test/source/container/xindexaccess \
     test/source/container/xnamecontainer \
diff --git a/test/Package_inc.mk b/test/Package_inc.mk
index aac4b38..474eb6d 100644
--- a/test/Package_inc.mk
+++ b/test/Package_inc.mk
@@ -30,6 +30,7 @@ $(eval $(call gb_Package_add_file,test_inc,inc/test/xmldiff.hxx,test/xmldiff.hxx
 $(eval $(call gb_Package_add_file,test_inc,inc/test/bootstrapfixture.hxx,test/bootstrapfixture.hxx))
 $(eval $(call gb_Package_add_file,test_inc,inc/test/testdllapi.hxx,test/testdllapi.hxx))
 $(eval $(call gb_Package_add_file,test_inc,inc/test/unoapi_test.hxx,test/unoapi_test.hxx))
+$(eval $(call gb_Package_add_file,test_inc,inc/test/beans/xpropertyset.hxx,test/beans/xpropertyset.hxx))
 $(eval $(call gb_Package_add_file,test_inc,inc/test/sheet/xdatapilotdescriptor.hxx,test/sheet/xdatapilotdescriptor.hxx))
 $(eval $(call gb_Package_add_file,test_inc,inc/test/sheet/xcellrangesquery.hxx,test/sheet/xcellrangesquery.hxx))
 $(eval $(call gb_Package_add_file,test_inc,inc/test/sheet/xnamedranges.hxx,test/sheet/xnamedranges.hxx))
diff --git a/test/inc/test/beans/xpropertyset.hxx b/test/inc/test/beans/xpropertyset.hxx
new file mode 100644
index 0000000..7479541
--- /dev/null
+++ b/test/inc/test/beans/xpropertyset.hxx
@@ -0,0 +1,86 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ *   Copyright (C) 2012 Kohei Yoshida <kohei.yoshida at suse.com>
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#ifndef __TEST_BEANS_XPROPERTYSET_HXX__
+#define __TEST_BEANS_XPROPERTYSET_HXX__
+
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/beans/XPropertySetInfo.hpp>
+
+#include "test/testdllapi.hxx"
+
+#include <vector>
+
+using namespace com::sun::star;
+
+namespace apitest {
+
+class OOO_DLLPUBLIC_TEST XPropertySet
+{
+public:
+    virtual ~XPropertySet();
+
+    virtual uno::Reference<uno::XInterface> init() = 0;
+
+    void testGetPropertySetInfo();
+    void testAddPropertyChangeListener();
+    void testAddVetoableChangeListener();
+    void testSetPropertyValue();
+    void testGetPropertyValue();
+    void testRemovePropertyChangeListener();
+    void testRemoveVetoableChangeListener();
+
+protected:
+    virtual bool isChangeable(const rtl::OUString& rName);
+
+private:
+    void fillPropsToTest(const uno::Reference<beans::XPropertySetInfo>& xPropInfo);
+    static bool getSinglePropertyValue(
+        const uno::Reference<beans::XPropertySet>& xPropSet, const rtl::OUString& rName);
+
+    struct PropsToTest
+    {
+        std::vector<rtl::OUString> constrained;
+        std::vector<rtl::OUString> bound;
+        std::vector<rtl::OUString> normal;
+        std::vector<rtl::OUString> readonly;
+
+        bool initialized;
+
+        PropsToTest();
+    };
+
+    PropsToTest maPropsToTest;
+};
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/test/source/beans/xpropertyset.cxx b/test/source/beans/xpropertyset.cxx
new file mode 100644
index 0000000..1c83390
--- /dev/null
+++ b/test/source/beans/xpropertyset.cxx
@@ -0,0 +1,211 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ *   Copyright (C) 2012 Kohei Yoshida <kohei.yoshida at suse.com>
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#include "test/beans/xpropertyset.hxx"
+#include "cppunit/extensions/HelperMacros.h"
+
+#include <com/sun/star/uno/Type.h>
+#include <com/sun/star/beans/PropertyAttribute.hpp>
+
+#include <set>
+
+using namespace com::sun::star::uno;
+
+namespace apitest {
+
+XPropertySet::~XPropertySet() {}
+
+XPropertySet::PropsToTest::PropsToTest() : initialized(false) {}
+
+void XPropertySet::testGetPropertySetInfo()
+{
+    uno::Reference<beans::XPropertySet> xPropSet(init(), UNO_QUERY_THROW);
+    uno::Reference<beans::XPropertySetInfo> xPropInfo = xPropSet->getPropertySetInfo();
+    if (xPropInfo.is())
+    {
+        fillPropsToTest(xPropInfo);
+    }
+    else
+    {
+        // TODO: Add a means for the client code to populate the PropsToTest.
+    }
+}
+
+void XPropertySet::testAddPropertyChangeListener()
+{
+    // TODO: implement this.
+}
+
+void XPropertySet::testAddVetoableChangeListener()
+{
+    // TODO: implement this.
+}
+
+void XPropertySet::testSetPropertyValue()
+{
+    testGetPropertySetInfo();
+
+    // TODO: implement this.
+}
+
+void XPropertySet::testGetPropertyValue()
+{
+    testGetPropertySetInfo();
+    uno::Reference<beans::XPropertySet> xPropSet(init(), UNO_QUERY_THROW);
+
+    // Check read-only properties.
+    for (size_t i = 0, n = maPropsToTest.readonly.size(); i < n; ++i)
+    {
+        bool bSuccess = getSinglePropertyValue(xPropSet, maPropsToTest.readonly[i]);
+        CPPUNIT_ASSERT(bSuccess);
+    }
+
+    // Check writable properties.
+    for (size_t i = 0, n = maPropsToTest.normal.size(); i < n; ++i)
+    {
+        bool bSuccess = getSinglePropertyValue(xPropSet, maPropsToTest.readonly[i]);
+        CPPUNIT_ASSERT(bSuccess);
+    }
+}
+
+void XPropertySet::testRemovePropertyChangeListener()
+{
+    // TODO: implement this.
+}
+
+void XPropertySet::testRemoveVetoableChangeListener()
+{
+    // TODO: implement this.
+}
+
+bool XPropertySet::isChangeable(const rtl::OUString& rName)
+{
+    uno::Reference<beans::XPropertySet> xPropSet(init(), UNO_QUERY_THROW);
+    try
+    {
+        uno::Any any = xPropSet->getPropertyValue(rName);
+        uno::Type type = any.getValueType();
+        if (type == getCppuType<sal_Bool>())
+        {
+            // 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<rtl::OUString>())
+        {
+            // string type
+            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;
+        }
+
+        // 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);
+    }
+    catch (const uno::Exception&)
+    {
+        CPPUNIT_ASSERT_MESSAGE("XPropertySet::isChangeable: exception thrown while retrieving the property value.", false);
+    }
+
+    return false;
+}
+
+void XPropertySet::fillPropsToTest(const uno::Reference<beans::XPropertySetInfo>& xPropInfo)
+{
+    if (maPropsToTest.initialized)
+        return;
+
+    uno::Sequence<beans::Property> aProps = xPropInfo->getProperties();
+
+    // some properties should not be changed in a unspecific way.
+    // TODO: Maybe we should mark these properties read-only, instead of
+    // giving them a special treatment here?
+    std::set<rtl::OUString> aSkip;
+    aSkip.insert("PrinterName");
+    aSkip.insert("CharRelief");
+    aSkip.insert("IsLayerMode");
+
+    for (sal_Int32 i = 0; i < aProps.getLength(); ++i)
+    {
+        beans::Property aProp = aProps[i];
+        if (aSkip.count(aProp.Name) > 0)
+            continue;
+
+        if ((aProp.Attributes & beans::PropertyAttribute::READONLY) != 0)
+        {
+            maPropsToTest.readonly.push_back(aProp.Name);
+            continue;
+        }
+
+        if ((aProp.Attributes & beans::PropertyAttribute::MAYBEVOID) != 0)
+            continue;
+
+        bool bBound       = (aProp.Attributes & beans::PropertyAttribute::BOUND) != 0;
+        bool bConstrained = (aProp.Attributes & beans::PropertyAttribute::CONSTRAINED) != 0;
+        bool bCanChange = isChangeable(aProp.Name);
+
+        if (bBound && bCanChange)
+            maPropsToTest.bound.push_back(aProp.Name);
+
+        if (bConstrained && bCanChange)
+            maPropsToTest.constrained.push_back(aProp.Name);
+
+        if (bCanChange)
+            maPropsToTest.normal.push_back(aProp.Name);
+    }
+
+    maPropsToTest.initialized = true;
+}
+
+bool XPropertySet::getSinglePropertyValue(
+    const uno::Reference<beans::XPropertySet>& xPropSet, const rtl::OUString& rName)
+{
+    try
+    {
+        xPropSet->getPropertyValue(rName);
+        return true;
+    }
+    catch (const uno::Exception&)
+    {
+    }
+    return false;
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list