[Libreoffice-commits] core.git: 2 commits - comphelper/qa vcl/inc vcl/osx vcl/unx

Noel Grandin noel at peralex.com
Mon Jan 25 00:07:31 PST 2016


 comphelper/qa/container/comphelper_ifcontainer.cxx |   68 ---------------------
 comphelper/qa/container/testifcontainer.cxx        |   51 ++++++++++-----
 vcl/inc/osx/salinst.h                              |    2 
 vcl/inc/unx/gendisp.hxx                            |    5 -
 vcl/inc/unx/gtk/gtkdata.hxx                        |    6 -
 vcl/osx/salinst.cxx                                |   27 ++++----
 vcl/unx/generic/app/gendisp.cxx                    |   62 +++++--------------
 vcl/unx/gtk/gtkdata.cxx                            |   33 ++++------
 8 files changed, 86 insertions(+), 168 deletions(-)

New commits:
commit 11cbce37f5817c506f6d13fdd2d578b7a5480fcf
Author: Noel Grandin <noel at peralex.com>
Date:   Mon Jan 25 09:59:54 2016 +0200

    cleanup OInterfaceContainer2 unit tests
    
    remove unused code and actually hook up the tests
    in testifcontainer.cxx
    
    Change-Id: I9694ebe44f1e8eed3d72373d62424345f899c8e6

diff --git a/comphelper/qa/container/comphelper_ifcontainer.cxx b/comphelper/qa/container/comphelper_ifcontainer.cxx
index ba9af49..733a7e0 100644
--- a/comphelper/qa/container/comphelper_ifcontainer.cxx
+++ b/comphelper/qa/container/comphelper_ifcontainer.cxx
@@ -34,8 +34,6 @@ using namespace com::sun::star;
 using namespace com::sun::star::uno;
 using namespace com::sun::star::lang;
 
-class ContainerListener;
-
 struct ContainerStats {
     int m_nAlive;
     int m_nDisposed;
@@ -131,72 +129,6 @@ namespace comphelper_ifcontainer
             delete pContainer;
         }
 
-        template < typename ContainerType, typename ContainedType >
-        void doContainerTest(const ContainedType *pTypes)
-        {
-            ContainerStats aStats;
-            ContainerType *pContainer;
-            pContainer = new ContainerType(m_aGuard);
-
-            int i;
-            Reference<XEventListener> xRefs[nTests * 2];
-
-            // add these interfaces
-            for (i = 0; i < nTests * 2; i++)
-            {
-                xRefs[i] = new ContainerListener(&aStats);
-                pContainer->addInterface(pTypes[i / 2], xRefs[i]);
-            }
-
-            // check it is all there
-            for (i = 0; i < nTests; i++)
-            {
-                cppu::OInterfaceContainerHelper *pHelper;
-
-                pHelper = pContainer->getContainer(pTypes[i]);
-
-                CPPUNIT_ASSERT_MESSAGE("no helper", pHelper != nullptr);
-                Sequence<Reference< XInterface > > aSeq = pHelper->getElements();
-                CPPUNIT_ASSERT_MESSAGE("wrong num elements", aSeq.getLength() == 2);
-                CPPUNIT_ASSERT_MESSAGE("match", aSeq[0] == xRefs[i*2]);
-                CPPUNIT_ASSERT_MESSAGE("match", aSeq[1] == xRefs[i*2+1]);
-            }
-
-            // remove every other interface
-            for (i = 0; i < nTests; i++)
-                pContainer->removeInterface(pTypes[i], xRefs[i*2+1]);
-
-            // check it is half there
-            for (i = 0; i < nTests; i++)
-            {
-                cppu::OInterfaceContainerHelper *pHelper;
-
-                pHelper = pContainer->getContainer(pTypes[i]);
-
-                CPPUNIT_ASSERT_MESSAGE("no helper", pHelper != nullptr);
-                Sequence<Reference< XInterface > > aSeq = pHelper->getElements();
-                CPPUNIT_ASSERT_MESSAGE("wrong num elements", aSeq.getLength() == 1);
-                CPPUNIT_ASSERT_MESSAGE("match", aSeq[0] == xRefs[i*2]);
-            }
-
-            // remove the 1st half of the rest
-            for (i = 0; i < nTests / 2; i++)
-                pContainer->removeInterface(pTypes[i], xRefs[i*2]);
-
-            // check it is half there
-            for (i = 0; i < nTests / 2; i++)
-            {
-                cppu::OInterfaceContainerHelper *pHelper;
-
-                pHelper = pContainer->getContainer(pTypes[i]);
-                CPPUNIT_ASSERT_MESSAGE("no helper", pHelper != nullptr);
-                Sequence<Reference< XInterface > > aSeq = pHelper->getElements();
-                CPPUNIT_ASSERT_MESSAGE("wrong num elements", aSeq.getLength() == 0);
-            }
-
-            delete pContainer;
-        }
-
         // Automatic registration code
         CPPUNIT_TEST_SUITE(IfTest);
         CPPUNIT_TEST(testCreateDispose);
diff --git a/comphelper/qa/container/testifcontainer.cxx b/comphelper/qa/container/testifcontainer.cxx
index 12ec7e3..85e06c2 100644
--- a/comphelper/qa/container/testifcontainer.cxx
+++ b/comphelper/qa/container/testifcontainer.cxx
@@ -17,21 +17,34 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include "cppunit/TestAssert.h"
+#include "cppunit/TestFixture.h"
+#include "cppunit/extensions/HelperMacros.h"
+#include "cppunit/plugin/TestPlugIn.h"
 #include <osl/mutex.hxx>
-
-#include <cppuhelper/interfacecontainer.hxx>
+#include <comphelper/interfacecontainer2.hxx>
 #include <cppuhelper/implbase1.hxx>
-
 #include <com/sun/star/beans/XVetoableChangeListener.hpp>
 
-using namespace ::cppu;
 using namespace ::osl;
 using namespace ::com::sun::star::lang;
 using namespace ::com::sun::star::beans;
 using namespace ::com::sun::star::uno;
 
+namespace
+{
 
-class TestListener : public WeakImplHelper1< XVetoableChangeListener >
+class TestInterfaceContainer2: public CppUnit::TestFixture
+{
+public:
+    void test1();
+
+    CPPUNIT_TEST_SUITE(TestInterfaceContainer2);
+    CPPUNIT_TEST(test1);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+class TestListener : public cppu::WeakImplHelper1< XVetoableChangeListener >
 {
 public:
     // Methods
@@ -47,12 +60,12 @@ public:
         }
 };
 
-void test_interfacecontainer()
+void TestInterfaceContainer2::test1()
 {
     Mutex mutex;
 
     {
-        OInterfaceContainerHelper helper( mutex );
+        comphelper::OInterfaceContainerHelper2 helper( mutex );
 
         Reference< XVetoableChangeListener > r1 = new TestListener();
         Reference< XVetoableChangeListener > r2 = new TestListener();
@@ -66,7 +79,7 @@ void test_interfacecontainer()
     }
 
     {
-        OInterfaceContainerHelper helper( mutex );
+        comphelper::OInterfaceContainerHelper2 helper( mutex );
 
         Reference< XVetoableChangeListener > r1 = new TestListener();
         Reference< XVetoableChangeListener > r2 = new TestListener();
@@ -76,7 +89,7 @@ void test_interfacecontainer()
         helper.addInterface( r2 );
         helper.addInterface( r3 );
 
-        OInterfaceIteratorHelper iterator( helper );
+        comphelper::OInterfaceIteratorHelper2 iterator( helper );
 
         while( iterator.hasMoreElements() )
             static_cast<XVetoableChangeListener*>(iterator.next())->vetoableChange( PropertyChangeEvent() );
@@ -85,7 +98,7 @@ void test_interfacecontainer()
     }
 
     {
-        OInterfaceContainerHelper helper( mutex );
+        comphelper::OInterfaceContainerHelper2 helper( mutex );
 
         Reference< XVetoableChangeListener > r1 = new TestListener();
         Reference< XVetoableChangeListener > r2 = new TestListener();
@@ -95,7 +108,7 @@ void test_interfacecontainer()
         helper.addInterface( r2 );
         helper.addInterface( r3 );
 
-        OInterfaceIteratorHelper iterator( helper );
+        comphelper::OInterfaceIteratorHelper2 iterator( helper );
 
         static_cast<XVetoableChangeListener*>(iterator.next())->vetoableChange( PropertyChangeEvent() );
         iterator.remove();
@@ -104,12 +117,12 @@ void test_interfacecontainer()
         static_cast<XVetoableChangeListener*>(iterator.next())->vetoableChange( PropertyChangeEvent() );
         iterator.remove();
 
-        OSL_ASSERT( helper.getLength() == 0 );
+        CPPUNIT_ASSERT( helper.getLength() == 0 );
         helper.disposeAndClear( EventObject() );
     }
 
     {
-        OInterfaceContainerHelper helper( mutex );
+        comphelper::OInterfaceContainerHelper2 helper( mutex );
 
         Reference< XVetoableChangeListener > r1 = new TestListener();
         Reference< XVetoableChangeListener > r2 = new TestListener();
@@ -120,7 +133,7 @@ void test_interfacecontainer()
         helper.addInterface( r3 );
 
         {
-            OInterfaceIteratorHelper iterator( helper );
+            comphelper::OInterfaceIteratorHelper2 iterator( helper );
             while( iterator.hasMoreElements() )
             {
                 Reference< XVetoableChangeListener > r = static_cast<XVetoableChangeListener*>(iterator.next());
@@ -128,13 +141,13 @@ void test_interfacecontainer()
                     iterator.remove();
             }
         }
-        OSL_ASSERT( helper.getLength() == 2 );
+        CPPUNIT_ASSERT( helper.getLength() == 2 );
         {
-            OInterfaceIteratorHelper iterator( helper );
+            comphelper::OInterfaceIteratorHelper2 iterator( helper );
             while( iterator.hasMoreElements() )
             {
                 Reference< XVetoableChangeListener > r = static_cast<XVetoableChangeListener*>(iterator.next());
-                OSL_ASSERT( r != r1 && ( r == r2 || r == r3 ) );
+                CPPUNIT_ASSERT( r != r1 && ( r == r2 || r == r3 ) );
             }
         }
 
@@ -142,4 +155,8 @@ void test_interfacecontainer()
     }
 }
 
+CPPUNIT_TEST_SUITE_REGISTRATION(TestInterfaceContainer2);
+
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 3dc37e975ee79c4fd4215cb14a074f1fb5a35ca4
Author: Noel Grandin <noelgrandin at gmail.com>
Date:   Sat Jan 23 08:28:22 2016 +0200

    more usage of C++ osl::Mutex, osl::MutexGuard
    
    Change-Id: Ibdc54fdccf70a9d60ad0fdcb9898bcd6d7bda368

diff --git a/vcl/inc/osx/salinst.h b/vcl/inc/osx/salinst.h
index 4a6d12f..972ad7b 100644
--- a/vcl/inc/osx/salinst.h
+++ b/vcl/inc/osx/salinst.h
@@ -71,7 +71,7 @@ public:
     bool                                    mbWaitingYield;
     int                                     mnActivePrintJobs;
     std::list< SalUserEvent >               maUserEvents;
-    oslMutex                                maUserEventListMutex;
+    osl::Mutex                              maUserEventListMutex;
     oslCondition                            maWaitingYieldCond;
 
     typedef std::list<const ApplicationEvent*> AppEventList;
diff --git a/vcl/inc/unx/gendisp.hxx b/vcl/inc/unx/gendisp.hxx
index 4f341da..fd39952 100644
--- a/vcl/inc/unx/gendisp.hxx
+++ b/vcl/inc/unx/gendisp.hxx
@@ -31,7 +31,7 @@
 class SalFrame;
 class VCL_DLLPUBLIC SalGenericDisplay
 {
-    oslMutex m_aEventGuard;
+    mutable osl::Mutex m_aEventGuard;
     struct SalUserEvent
     {
         SalFrame*  m_pFrame;
@@ -53,8 +53,7 @@ public:
                  SalGenericDisplay();
     virtual      ~SalGenericDisplay();
 
-    inline void  EventGuardAcquire() { osl_acquireMutex( m_aEventGuard ); }
-    inline void  EventGuardRelease() { osl_releaseMutex( m_aEventGuard ); }
+    inline osl::Mutex& getEventGuardMutex() { return m_aEventGuard; }
 
     void registerFrame( SalFrame* pFrame );
     virtual void deregisterFrame( SalFrame* pFrame );
diff --git a/vcl/inc/unx/gtk/gtkdata.hxx b/vcl/inc/unx/gtk/gtkdata.hxx
index 6783e32..3e90b2f3 100644
--- a/vcl/inc/unx/gtk/gtkdata.hxx
+++ b/vcl/inc/unx/gtk/gtkdata.hxx
@@ -97,10 +97,10 @@ public:
 
 class GtkData : public SalGenericData
 {
-    GSource *m_pUserEvent;
-    oslMutex m_aDispatchMutex;
+    GSource *    m_pUserEvent;
+    osl::Mutex   m_aDispatchMutex;
     oslCondition m_aDispatchCondition;
-    bool blockIdleTimeout;
+    bool         blockIdleTimeout;
 
 public:
     GtkData( SalInstance *pInstance );
diff --git a/vcl/osx/salinst.cxx b/vcl/osx/salinst.cxx
index 41ad480..2e3fdad 100644
--- a/vcl/osx/salinst.cxx
+++ b/vcl/osx/salinst.cxx
@@ -349,13 +349,13 @@ void DestroySalInstance( SalInstance* pInst )
 }
 
 AquaSalInstance::AquaSalInstance()
+ : maUserEventListMutex()
 {
     mpSalYieldMutex = new SalYieldMutex;
     mpSalYieldMutex->acquire();
     ::comphelper::SolarMutex::setSolarMutex( mpSalYieldMutex );
     maMainThread = osl::Thread::getCurrentIdentifier();
     mbWaitingYield = false;
-    maUserEventListMutex = osl_createMutex();
     mnActivePrintJobs = 0;
     maWaitingYieldCond = osl_createCondition();
 }
@@ -365,7 +365,6 @@ AquaSalInstance::~AquaSalInstance()
     ::comphelper::SolarMutex::setSolarMutex( nullptr );
     mpSalYieldMutex->release();
     delete mpSalYieldMutex;
-    osl_destroyMutex( maUserEventListMutex );
     osl_destroyCondition( maWaitingYieldCond );
 }
 
@@ -391,10 +390,10 @@ void AquaSalInstance::wakeupYield()
 
 void AquaSalInstance::PostUserEvent( AquaSalFrame* pFrame, sal_uInt16 nType, void* pData )
 {
-    osl_acquireMutex( maUserEventListMutex );
-    maUserEvents.push_back( SalUserEvent( pFrame, pData, nType ) );
-    osl_releaseMutex( maUserEventListMutex );
-
+    {
+        osl::MutexGuard g( maUserEventListMutex );
+        maUserEvents.push_back( SalUserEvent( pFrame, pData, nType ) );
+    }
     // notify main loop that an event has arrived
     wakeupYield();
 }
@@ -582,17 +581,17 @@ SalYieldResult AquaSalInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents
         sal_uLong nCount = ReleaseYieldMutex();
 
         // get one user event
-        osl_acquireMutex( maUserEventListMutex );
         SalUserEvent aEvent( nullptr, nullptr, 0 );
-        if( ! maUserEvents.empty() )
         {
-            aEvent = maUserEvents.front();
-            maUserEvents.pop_front();
+            osl::MutexGuard g( maUserEventListMutex );
+            if( ! maUserEvents.empty() )
+            {
+                aEvent = maUserEvents.front();
+                maUserEvents.pop_front();
+            }
+            else
+                bDispatchUser = false;
         }
-        else
-            bDispatchUser = false;
-        osl_releaseMutex( maUserEventListMutex );
-
         AcquireYieldMutex( nCount );
 
         // dispatch it
diff --git a/vcl/unx/generic/app/gendisp.cxx b/vcl/unx/generic/app/gendisp.cxx
index 565d417..129a83b 100644
--- a/vcl/unx/generic/app/gendisp.cxx
+++ b/vcl/unx/generic/app/gendisp.cxx
@@ -22,16 +22,13 @@
 #include <unx/geninst.h>
 
 SalGenericDisplay::SalGenericDisplay()
+ : m_aEventGuard()
 {
     m_pCapture = nullptr;
-    m_aEventGuard = osl_createMutex();
 }
 
 SalGenericDisplay::~SalGenericDisplay()
 {
-    if (m_aEventGuard)
-        osl_destroyMutex( m_aEventGuard );
-    m_aEventGuard = nullptr;
 }
 
 void SalGenericDisplay::registerFrame( SalFrame* pFrame )
@@ -41,8 +38,8 @@ void SalGenericDisplay::registerFrame( SalFrame* pFrame )
 
 void SalGenericDisplay::deregisterFrame( SalFrame* pFrame )
 {
-    if( osl_acquireMutex( m_aEventGuard ) )
     {
+        osl::MutexGuard g( m_aEventGuard );
         std::list< SalUserEvent >::iterator it = m_aUserEvents.begin();
         while ( it != m_aUserEvents.end() )
         {
@@ -56,10 +53,7 @@ void SalGenericDisplay::deregisterFrame( SalFrame* pFrame )
             else
                 ++it;
         }
-        osl_releaseMutex( m_aEventGuard );
     }
-    else
-        OSL_FAIL( "SalGenericDisplay::deregisterFrame !acquireMutex\n" );
 
     m_aFrames.remove( pFrame );
 }
@@ -76,8 +70,8 @@ bool SalGenericDisplay::DispatchInternalEvent()
     SalFrame* pFrame = nullptr;
     sal_uInt16 nEvent = 0;
 
-    if( osl_acquireMutex( m_aEventGuard ) )
     {
+        osl::MutexGuard g( m_aEventGuard );
         if( !m_aUserEvents.empty() )
         {
             pFrame	= m_aUserEvents.front().m_pFrame;
@@ -86,10 +80,7 @@ bool SalGenericDisplay::DispatchInternalEvent()
 
             m_aUserEvents.pop_front();
         }
-        osl_releaseMutex( m_aEventGuard );
     }
-    else
-        OSL_FAIL( "SalGenericDisplay::Yield !acquireMutex\n" );
 
     if( pFrame )
         pFrame->CallCallback( nEvent, pData );
@@ -99,54 +90,37 @@ bool SalGenericDisplay::DispatchInternalEvent()
 
 void SalGenericDisplay::SendInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent )
 {
-    if( osl_acquireMutex( m_aEventGuard ) )
-    {
-        m_aUserEvents.push_back( SalUserEvent( pFrame, pData, nEvent ) );
+    osl::MutexGuard g( m_aEventGuard );
 
-        PostUserEvent(); // wakeup the concrete mainloop
+    m_aUserEvents.push_back( SalUserEvent( pFrame, pData, nEvent ) );
 
-        osl_releaseMutex( m_aEventGuard );
-    }
-    else
-        OSL_FAIL( "SalGenericDisplay::SendInternalEvent !acquireMutex\n" );
+    PostUserEvent(); // wakeup the concrete mainloop
 }
 
 void SalGenericDisplay::CancelInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent )
 {
-    if( osl_acquireMutex( m_aEventGuard ) )
+    osl::MutexGuard g( m_aEventGuard );
+    if( ! m_aUserEvents.empty() )
     {
-        if( ! m_aUserEvents.empty() )
+        std::list< SalUserEvent >::iterator it = m_aUserEvents.begin();
+        while (it != m_aUserEvents.end())
         {
-            std::list< SalUserEvent >::iterator it = m_aUserEvents.begin();
-            while (it != m_aUserEvents.end())
+            if( it->m_pFrame    == pFrame   &&
+                it->m_pData     == pData    &&
+                it->m_nEvent    == nEvent )
             {
-                if( it->m_pFrame    == pFrame   &&
-                    it->m_pData     == pData    &&
-                    it->m_nEvent    == nEvent )
-                {
-                    it = m_aUserEvents.erase( it );
-                }
-                else
-                    ++it;
+                it = m_aUserEvents.erase( it );
             }
+            else
+                ++it;
         }
-
-        osl_releaseMutex( m_aEventGuard );
     }
-    else
-        OSL_FAIL( "SalGenericDisplay::CancelInternalEvent !acquireMutex\n" );
 }
 
 bool SalGenericDisplay::HasUserEvents() const
 {
-    bool bRet = false;
-    if( osl_acquireMutex( m_aEventGuard ) )
-    {
-        if( !m_aUserEvents.empty() )
-            bRet = true;
-        osl_releaseMutex( m_aEventGuard );
-    }
-    return bRet;
+    osl::MutexGuard g( m_aEventGuard );
+    return !m_aUserEvents.empty();
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/gtk/gtkdata.cxx b/vcl/unx/gtk/gtkdata.cxx
index f0ce4f4..e6121f7 100644
--- a/vcl/unx/gtk/gtkdata.cxx
+++ b/vcl/unx/gtk/gtkdata.cxx
@@ -525,10 +525,10 @@ GtkData::GtkData( SalInstance *pInstance )
 #else
     : SalGenericData( SAL_DATA_GTK, pInstance )
 #endif
+    , m_aDispatchMutex()
     , blockIdleTimeout( false )
 {
     m_pUserEvent = nullptr;
-    m_aDispatchMutex = osl_createMutex();
     m_aDispatchCondition = osl_createCondition();
 }
 
@@ -557,7 +557,7 @@ GtkData::~GtkData()
      // up anyway before the condition they're waiting on gets destroyed.
     osl_setCondition( m_aDispatchCondition );
 
-    osl_acquireMutex( m_aDispatchMutex );
+    osl::MutexGuard g( m_aDispatchMutex );
     if (m_pUserEvent)
     {
         g_source_destroy (m_pUserEvent);
@@ -565,8 +565,6 @@ GtkData::~GtkData()
         m_pUserEvent = nullptr;
     }
     osl_destroyCondition( m_aDispatchCondition );
-    osl_releaseMutex( m_aDispatchMutex );
-    osl_destroyMutex( m_aDispatchMutex );
 #if defined(GDK_WINDOWING_X11)
     if (GDK_IS_X11_DISPLAY(gdk_display_get_default()))
         XSetIOErrorHandler(aOrigXIOErrorHandler);
@@ -593,7 +591,7 @@ SalYieldResult GtkData::Yield( bool bWait, bool bHandleAllCurrentEvents )
     {
         // release YieldMutex (and re-acquire at block end)
         SalYieldMutexReleaser aReleaser;
-        if( osl_tryToAcquireMutex( m_aDispatchMutex ) )
+        if( m_aDispatchMutex.tryToAcquire() )
             bDispatchThread = true;
         else if( ! bWait )
         {
@@ -627,7 +625,7 @@ SalYieldResult GtkData::Yield( bool bWait, bool bHandleAllCurrentEvents )
 
     if( bDispatchThread )
     {
-        osl_releaseMutex( m_aDispatchMutex );
+        m_aDispatchMutex.release();
         if( bWasEvent )
             osl_setCondition( m_aDispatchCondition ); // trigger non dispatch thread yields
     }
@@ -969,22 +967,21 @@ gboolean GtkData::userEventFn( gpointer data )
     if (pDisplay)
     {
         OSL_ASSERT(static_cast<const SalGenericDisplay *>(pThis->GetGtkDisplay()) == pDisplay);
-        pThis->GetGtkDisplay()->EventGuardAcquire();
-
-        if( !pThis->GetGtkDisplay()->HasUserEvents() )
         {
-            if( pThis->m_pUserEvent )
+            osl::MutexGuard g (pThis->GetGtkDisplay()->getEventGuardMutex());
+
+            if( !pThis->GetGtkDisplay()->HasUserEvents() )
             {
-                g_source_unref (pThis->m_pUserEvent);
-                pThis->m_pUserEvent = nullptr;
+                if( pThis->m_pUserEvent )
+                {
+                    g_source_unref (pThis->m_pUserEvent);
+                    pThis->m_pUserEvent = nullptr;
+                }
+                bContinue = FALSE;
             }
-            bContinue = FALSE;
+            else
+                bContinue = TRUE;
         }
-        else
-            bContinue = TRUE;
-
-        pThis->GetGtkDisplay()->EventGuardRelease();
-
         pThis->GetGtkDisplay()->DispatchInternalEvent();
     }
 


More information about the Libreoffice-commits mailing list