summaryrefslogtreecommitdiff
path: root/vcl/unx
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2014-04-27 00:56:00 +0200
committerLuboš Luňák <l.lunak@collabora.com>2014-04-27 01:01:27 +0200
commit145f2e970f46a3a3e5456b122d71f17c3abe878f (patch)
tree6bc79bfa8d155b1c8b8368ff3dfcea1e0052b7d6 /vcl/unx
parentef2ad2fb1f373eca85562fefa0a4572f05ee4d9e (diff)
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
Diffstat (limited to 'vcl/unx')
-rw-r--r--vcl/unx/kde4/tst_exclude_posted_events.hxx20
-rw-r--r--vcl/unx/kde4/tst_exclude_socket_notifiers.hxx133
2 files changed, 54 insertions, 99 deletions
diff --git a/vcl/unx/kde4/tst_exclude_posted_events.hxx b/vcl/unx/kde4/tst_exclude_posted_events.hxx
index 777907cd34e0..712750545462 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 297cdf29a6d2..acf4d361d177 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;
}
-