QCoreApplication::processEvents();
QCOMPARE(helper.timerActivated, true);
- QCOMPARE(helper.socketActivated, true);
+ QTRY_COMPARE(helper.socketActivated, true);
}
void tst_QSocketNotifier::posixSockets()
connect(&rn, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop()));
QSignalSpy readSpy(&rn, SIGNAL(activated(int)));
QVERIFY(readSpy.isValid());
- QSocketNotifier wn(posixSocket, QSocketNotifier::Write);
- connect(&wn, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop()));
- QSignalSpy writeSpy(&wn, SIGNAL(activated(int)));
- QVERIFY(writeSpy.isValid());
+ // No write notifier, some systems trigger write notification on socket creation, but not all
QSocketNotifier en(posixSocket, QSocketNotifier::Exception);
connect(&en, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop()));
QSignalSpy errorSpy(&en, SIGNAL(activated(int)));
QTestEventLoop::instance().enterLoop(3);
QCOMPARE(readSpy.count(), 1);
- writeSpy.clear(); //depending on OS, write notifier triggers on creation or not.
QCOMPARE(errorSpy.count(), 0);
char buffer[100];
- qt_safe_read(posixSocket, buffer, 100);
+ int r = qt_safe_read(posixSocket, buffer, 100);
+ QCOMPARE(r, 6);
QCOMPARE(buffer, "hello");
+ QSocketNotifier wn(posixSocket, QSocketNotifier::Write);
+ connect(&wn, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop()));
+ QSignalSpy writeSpy(&wn, SIGNAL(activated(int)));
+ QVERIFY(writeSpy.isValid());
qt_safe_write(posixSocket, "goodbye", 8);
QTestEventLoop::instance().enterLoop(3);
QCOMPARE(readSpy.count(), 1);
QCOMPARE(writeSpy.count(), 1);
QCOMPARE(errorSpy.count(), 0);
+
+ // Write notifier may have fired before the read notifier inside
+ // QTcpSocket, give QTcpSocket a chance to see the incoming data
+ passive->waitForReadyRead(100);
QCOMPARE(passive->readAll(), QByteArray("goodbye",8));
}
qt_safe_close(posixSocket);