[Libreoffice-commits] core.git: vcl/unx

Luboš Luňák l.lunak at collabora.com
Sat Apr 26 16:01:58 PDT 2014


 vcl/unx/kde4/tst_exclude_posted_events.hxx    |   20 ++-
 vcl/unx/kde4/tst_exclude_socket_notifiers.hxx |  133 ++++++++------------------
 2 files changed, 54 insertions(+), 99 deletions(-)

New commits:
commit 145f2e970f46a3a3e5456b122d71f17c3abe878f
Author: Luboš Luňák <l.lunak at collabora.com>
Date:   Sun Apr 27 00:56:00 2014 +0200

    avoid several 200ms delays in Qt tests
    
    Since the tests are run during LO startup, this is not such a good idea.
    Also redo the socket notifier test which seems a bit of an overkill
    when a mere pipe will do (and I'm not sure TCP sockets would have
    the data available the moment it's written to).
    
    Change-Id: I6a436b286d20ceecf859f9028af98da03c2561b7

diff --git a/vcl/unx/kde4/tst_exclude_posted_events.hxx b/vcl/unx/kde4/tst_exclude_posted_events.hxx
index 777907c..7127505 100644
--- a/vcl/unx/kde4/tst_exclude_posted_events.hxx
+++ b/vcl/unx/kde4/tst_exclude_posted_events.hxx
@@ -23,48 +23,50 @@
 
 #include <qcoreapplication.h>
 #include <qeventloop.h>
-#include <qtimer.h>
+
+namespace
+{
 
 const QEvent::Type eventType = QEvent::User;
 
-class Test
+class TestExcludePostedEvents
     : public QObject
 {
     Q_OBJECT
     public:
-        Test();
+        TestExcludePostedEvents();
         virtual bool event( QEvent* e );
         bool processed;
 };
 
-Test::Test()
+TestExcludePostedEvents::TestExcludePostedEvents()
     : processed( false )
 {
 }
 
-bool Test::event( QEvent* e )
+bool TestExcludePostedEvents::event( QEvent* e )
 {
     if( e->type() == eventType )
         processed = true;
     return QObject::event( e );
 }
 
+}
+
 #define QVERIFY(a) \
     if (!a) return 1;
 
 static int tst_excludePostedEvents()
 {
-    Test test;
+    TestExcludePostedEvents test;
     QCoreApplication::postEvent( &test, new QEvent( eventType ));
     QEventLoop loop;
-    QTimer::singleShot(200, &loop, SLOT(quit()));
     loop.processEvents(QEventLoop::ExcludeUserInputEvents
         | QEventLoop::ExcludeSocketNotifiers
 //        | QEventLoop::WaitForMoreEvents
         | QEventLoop::X11ExcludeTimers);
     QVERIFY( !test.processed );
-    QTimer::singleShot(200, &loop, SLOT(quit()));
-        loop.exec();
+    loop.processEvents();
     QVERIFY( test.processed );
     return 0;
 }
diff --git a/vcl/unx/kde4/tst_exclude_socket_notifiers.hxx b/vcl/unx/kde4/tst_exclude_socket_notifiers.hxx
index 297cdf2..acf4d36 100644
--- a/vcl/unx/kde4/tst_exclude_socket_notifiers.hxx
+++ b/vcl/unx/kde4/tst_exclude_socket_notifiers.hxx
@@ -23,109 +23,62 @@
 
 #include <qcoreapplication.h>
 #include <qeventloop.h>
-#include <qthread.h>
-#include <qtimer.h>
-#include <QtNetwork/qtcpserver.h>
-#include <QtNetwork/qtcpsocket.h>
+#include <qsocketnotifier.h>
+#include <unistd.h>
 
-// This is also used by a configure check.
-#ifndef SAL_OVERRIDE
-#define SAL_OVERRIDE
-#endif
+namespace
+{
 
-class SocketEventsTester: public QObject
+class TestExcludeSocketNotifiers
+    : public QObject
 {
     Q_OBJECT
-public:
-    SocketEventsTester()
-    {
-        socket = 0;
-        server = 0;
-        dataSent = false;
-        testResult = false;
-        dataArrived = false;
-    }
-    ~SocketEventsTester()
-    {
-        delete socket;
-        delete server;
-    }
-    bool init()
-    {
-        bool ret = false;
-        server = new QTcpServer();
-        socket = new QTcpSocket();
-        connect(server, SIGNAL(newConnection()), this, SLOT(sendHello()));
-        connect(socket, SIGNAL(readyRead()), this, SLOT(sendAck()), Qt::DirectConnection);
-        if((ret = server->listen(QHostAddress::LocalHost, 0))) {
-            socket->connectToHost(server->serverAddress(), server->serverPort());
-            socket->waitForConnected();
-        }
-        return ret;
-    }
+    public:
+        TestExcludeSocketNotifiers( const int* pipes );
+        ~TestExcludeSocketNotifiers();
+        bool received;
+    public slots:
+        void slotReceived();
+    private:
+        const int* pipes;
+};
 
-    QTcpSocket *socket;
-    QTcpServer *server;
-    bool dataSent;
-    bool testResult;
-    bool dataArrived;
-public slots:
-    void sendAck()
-    {
-        dataArrived = true;
-    }
-    void sendHello()
-    {
-        char data[10] ="HELLO";
-        qint64 size = sizeof(data);
+TestExcludeSocketNotifiers::TestExcludeSocketNotifiers( const int* pipes )
+    : received( false )
+    , pipes( pipes )
+{
+}
 
-        QTcpSocket *serverSocket = server->nextPendingConnection();
-        serverSocket->write(data, size);
-        dataSent = serverSocket->waitForBytesWritten(-1);
-        QEventLoop loop;
-        //allow the TCP/IP stack time to loopback the data, so our socket is ready to read
-        QTimer::singleShot(200, &loop, SLOT(quit()));
-        loop.exec(QEventLoop::ExcludeSocketNotifiers);
-        testResult = dataArrived;
-        //check the deferred event is processed
-        QTimer::singleShot(200, &loop, SLOT(quit()));
-        loop.exec();
-        serverSocket->close();
-        QThread::currentThread()->exit(0);
-    }
-};
+TestExcludeSocketNotifiers::~TestExcludeSocketNotifiers()
+{
+    close( pipes[ 0 ] );
+    close( pipes[ 1 ] );
+}
 
-class SocketTestThread : public QThread
+void TestExcludeSocketNotifiers::slotReceived()
 {
-    Q_OBJECT
-public:
-    SocketTestThread():QThread(0),testResult(false){};
-    virtual void run() SAL_OVERRIDE
-    {
-        SocketEventsTester *tester = new SocketEventsTester();
-        if (tester->init())
-            exec();
-        dataSent = tester->dataSent;
-        testResult = tester->testResult;
-        dataArrived = tester->dataArrived;
-        delete tester;
-    }
-    bool dataSent;
-    bool testResult;
-    bool dataArrived;
-};
+    received = true;
+}
+
+}
 
 #define QVERIFY(a) \
     if (!a) return 1;
 
 static int tst_processEventsExcludeSocket()
 {
-    SocketTestThread thread;
-    thread.start();
-    QVERIFY(thread.wait());
-    QVERIFY(thread.dataSent);
-    QVERIFY(!thread.testResult);
-    QVERIFY(thread.dataArrived);
+    int pipes[ 2 ];
+    if( pipe( pipes ) < 0 )
+        return 1;
+    TestExcludeSocketNotifiers test( pipes );
+    QSocketNotifier notifier( pipes[ 0 ], QSocketNotifier::Read );
+    QObject::connect( &notifier, SIGNAL( activated( int )), &test, SLOT( slotReceived()));
+    char dummy = 'a';
+    write( pipes[ 1 ], &dummy, 1 );
+    QEventLoop loop;
+    loop.processEvents( QEventLoop::ExcludeSocketNotifiers );
+    QVERIFY( !test.received );
+    loop.processEvents();
+    QVERIFY( test.received );
     return 0;
 }
-


More information about the Libreoffice-commits mailing list