summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAleksandar Sasha Babic <aleksandar.babic@nokia.com>2009-05-07 11:20:12 (GMT)
committerAleksandar Sasha Babic <aleksandar.babic@nokia.com>2009-05-07 11:20:12 (GMT)
commite28d875b9f77a0a7cab7d2de649e850b016066f2 (patch)
treec70239df5e8906c0a6342724183f3dbaf6c796a8 /tests
parentead212aff40b2edbefb1a10ba14f0afed7236995 (diff)
downloadQt-e28d875b9f77a0a7cab7d2de649e850b016066f2.zip
Qt-e28d875b9f77a0a7cab7d2de649e850b016066f2.tar.gz
Qt-e28d875b9f77a0a7cab7d2de649e850b016066f2.tar.bz2
Any event can make us pass the line:
QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents) so we have to make sure that we wait for te right one to happen.
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qsocketnotifier/tst_qsocketnotifier.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/tests/auto/qsocketnotifier/tst_qsocketnotifier.cpp b/tests/auto/qsocketnotifier/tst_qsocketnotifier.cpp
index 629285f..bb88f42 100644
--- a/tests/auto/qsocketnotifier/tst_qsocketnotifier.cpp
+++ b/tests/auto/qsocketnotifier/tst_qsocketnotifier.cpp
@@ -70,9 +70,10 @@ tst_QSocketNotifier::~tst_QSocketNotifier()
class UnexpectedDisconnectTester : public QObject
{
Q_OBJECT
+ int sequence;
+
public:
QNativeSocketEngine *readEnd1, *readEnd2;
- int sequence;
UnexpectedDisconnectTester(QNativeSocketEngine *s1, QNativeSocketEngine *s2)
: readEnd1(s1), readEnd2(s2), sequence(0)
@@ -85,17 +86,25 @@ public:
connect(notifier2, SIGNAL(activated(int)), SLOT(handleActivated()));
}
+ const int getSequence() {
+ return sequence;
+ }
+
+ void incSequence() {
+ ++sequence;
+ }
+
public slots:
void handleActivated()
{
char data1[1], data2[1];
- ++sequence;
- if (sequence == 1) {
+ incSequence();
+ if (getSequence() == 1) {
// read from both ends
(void) readEnd1->read(data1, sizeof(data1));
(void) readEnd2->read(data2, sizeof(data2));
emit finished();
- } else if (sequence == 2) {
+ } else if (getSequence() == 2) {
QCOMPARE(readEnd2->read(data2, sizeof(data2)), qint64(-2));
QVERIFY(readEnd2->isValid());
}
@@ -155,7 +164,12 @@ void tst_QSocketNotifier::unexpectedDisconnection()
writeEnd2->flush();
UnexpectedDisconnectTester tester(&readEnd1, &readEnd2);
- QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents);
+
+ do {
+ // we have to wait until sequence value changes
+ // as any event can make us jump out processing
+ QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents);
+ } while(tester.getSequence() <= 0);
QVERIFY(readEnd1.state() == QAbstractSocket::ConnectedState);
QVERIFY(readEnd2.state() == QAbstractSocket::ConnectedState);
@@ -163,7 +177,7 @@ void tst_QSocketNotifier::unexpectedDisconnection()
qWarning("### Windows returns 1 activation, Unix returns 2.");
QCOMPARE(tester.sequence, 1);
#else
- QCOMPARE(tester.sequence, 2);
+ QCOMPARE(tester.getSequence(), 2);
#endif
readEnd1.close();