[Libreoffice-commits] core.git: cppuhelper/source postprocess/qa

Stephan Bergmann sbergman at redhat.com
Fri Oct 27 08:42:10 UTC 2017


 cppuhelper/source/servicemanager.cxx |   10 +++++-----
 cppuhelper/source/servicemanager.hxx |   11 +++++++++++
 postprocess/qa/services.cxx          |    7 +++++++
 3 files changed, 23 insertions(+), 5 deletions(-)

New commits:
commit 11cf64b7303d3c6bd2620d6c711c9845775f2d3d
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Oct 27 10:37:26 2017 +0200

    Better fix for CppunitTest_services
    
    ...than 25313923b08018bd837cfe3fc99a5e141602cafc "Fix CppunitTest_services for
    constructor-based implementations..." (which this commit reverts again).  My
    claim that "the 'factory' would be the object itself" is nonsense, it would
    rather be an ImplementationWrapper (but one that was freshly created for each
    ServiceManager::createContentEnumeration).
    
    Change-Id: I85c683cff6f9ba78d0f8567a53f8fcbc56fe55cf

diff --git a/cppuhelper/source/servicemanager.cxx b/cppuhelper/source/servicemanager.cxx
index 1478010d3434..8aa294ca0720 100644
--- a/cppuhelper/source/servicemanager.cxx
+++ b/cppuhelper/source/servicemanager.cxx
@@ -1172,15 +1172,15 @@ cppuhelper::ServiceManager::createContentEnumeration(
                 impl->factory1 = new ImplementationWrapper(this, *i);
                 impl->status = Data::Implementation::STATUS_WRAPPER;
             }
+            if (impl->constructor != nullptr && !impl->factory1.is()) {
+                impl->factory1 = new ImplementationWrapper(this, *i);
+            }
         }
         if (impl->factory1.is()) {
             factories.push_back(css::uno::Any(impl->factory1));
-        } else if (impl->factory2.is()) {
-            factories.push_back(css::uno::Any(impl->factory2));
         } else {
-            css::uno::Reference< css::lang::XSingleComponentFactory > factory(
-                    new ImplementationWrapper(this, *i));
-            factories.push_back(css::uno::Any(factory));
+            assert(impl->factory2.is());
+            factories.push_back(css::uno::Any(impl->factory2));
         }
     }
     return new ContentEnumeration(factories);
diff --git a/cppuhelper/source/servicemanager.hxx b/cppuhelper/source/servicemanager.hxx
index 2b1193e9a8d8..9838841403c1 100644
--- a/cppuhelper/source/servicemanager.hxx
+++ b/cppuhelper/source/servicemanager.hxx
@@ -150,6 +150,17 @@ public:
 
             enum Status { STATUS_NEW, STATUS_WRAPPER, STATUS_LOADED };
 
+            // Logically, exactly one of constructor, factory1, factory2 should
+            // be set.  However, there are two exceptions:  For one, when
+            // constructor is set, ServiceManager::createContentEnumeration will
+            // store the necessary ImplementationWrapper in factory1 (so that
+            // multiple calls to createContentEnumeration will return the same
+            // wrapper).  For another, when factory1 should be set but status is
+            // STATUS_NEW, factory1 is not yet set (and when status is
+            // STATUS_WRAPPER, factory1 is merely set to an
+            // ImplementationWrapper---also due to a
+            // ServiceManager::createContentEnumeration call---and will be
+            // loaded later).
             std::shared_ptr< ImplementationInfo > info;
             WrapperConstructorFn constructor;
             css::uno::Reference< css::lang::XSingleComponentFactory > factory1;
diff --git a/postprocess/qa/services.cxx b/postprocess/qa/services.cxx
index 78dee9ed3ad1..0ab677339d9d 100644
--- a/postprocess/qa/services.cxx
+++ b/postprocess/qa/services.cxx
@@ -209,6 +209,13 @@ void Test::test() {
                     k = impls.insert(
                             std::make_pair(name, Implementation(j, servs)))
                         .first;
+                } else {
+                    CPPUNIT_ASSERT_MESSAGE(
+                        (OString(
+                            "multiple implementations named \"" + msg(name)
+                            + "\"")
+                         .getStr()),
+                        bool(j == k->second.factory));
                 }
                 CPPUNIT_ASSERT_MESSAGE(
                     (OString(


More information about the Libreoffice-commits mailing list