tests/auto/qudpsocket/tst_qudpsocket.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
   293     QCOMPARE(peter.writeDatagram(peterMessage.data(), peterMessage.length(),
   293     QCOMPARE(peter.writeDatagram(peterMessage.data(), peterMessage.length(),
   294                                 pualAddress, paul.localPort()), qint64(peterMessage.length()));
   294                                 pualAddress, paul.localPort()), qint64(peterMessage.length()));
   295     QCOMPARE(paul.writeDatagram(paulMessage.data(), paulMessage.length(),
   295     QCOMPARE(paul.writeDatagram(paulMessage.data(), paulMessage.length(),
   296                                peterAddress, peter.localPort()), qint64(paulMessage.length()));
   296                                peterAddress, peter.localPort()), qint64(paulMessage.length()));
   297 
   297 
   298     QVERIFY(peter.waitForReadyRead(5000));
   298     QVERIFY(peter.waitForReadyRead(9000));
   299     QVERIFY(paul.waitForReadyRead(5000));
   299     QVERIFY(paul.waitForReadyRead(9000));
   300     char peterBuffer[16*1024];
   300     char peterBuffer[16*1024];
   301     char paulBuffer[16*1024];
   301     char paulBuffer[16*1024];
   302     if (success) {
   302     if (success) {
   303         QCOMPARE(peter.readDatagram(peterBuffer, sizeof(peterBuffer)), qint64(paulMessage.length()));
   303         QCOMPARE(peter.readDatagram(peterBuffer, sizeof(peterBuffer)), qint64(paulMessage.length()));
   304         QCOMPARE(paul.readDatagram(paulBuffer, sizeof(peterBuffer)), qint64(peterMessage.length()));
   304         QCOMPARE(paul.readDatagram(paulBuffer, sizeof(peterBuffer)), qint64(peterMessage.length()));
   717 #else
   717 #else
   718 
   718 
   719     QProcess serverProcess;
   719     QProcess serverProcess;
   720     serverProcess.start(QLatin1String("clientserver/clientserver server 1 1"),
   720     serverProcess.start(QLatin1String("clientserver/clientserver server 1 1"),
   721                         QIODevice::ReadWrite | QIODevice::Text);
   721                         QIODevice::ReadWrite | QIODevice::Text);
       
   722     QVERIFY2(serverProcess.waitForStarted(3000),
       
   723              qPrintable("Failed to start subprocess: " + serverProcess.errorString()));
   722 
   724 
   723     // Wait until the server has started and reports success.
   725     // Wait until the server has started and reports success.
   724     while (!serverProcess.canReadLine())
   726     while (!serverProcess.canReadLine())
   725         QVERIFY(serverProcess.waitForReadyRead(3000));
   727         QVERIFY(serverProcess.waitForReadyRead(3000));
   726     QByteArray serverGreeting = serverProcess.readLine();
   728     QByteArray serverGreeting = serverProcess.readLine();
   730 
   732 
   731     QProcess clientProcess;
   733     QProcess clientProcess;
   732     clientProcess.start(QString::fromLatin1("clientserver/clientserver connectedclient %1 %2")
   734     clientProcess.start(QString::fromLatin1("clientserver/clientserver connectedclient %1 %2")
   733                         .arg(QLatin1String("127.0.0.1")).arg(serverPort),
   735                         .arg(QLatin1String("127.0.0.1")).arg(serverPort),
   734                         QIODevice::ReadWrite | QIODevice::Text);
   736                         QIODevice::ReadWrite | QIODevice::Text);
       
   737     QVERIFY2(clientProcess.waitForStarted(3000),
       
   738              qPrintable("Failed to start subprocess: " + clientProcess.errorString()));
       
   739 
   735     // Wait until the server has started and reports success.
   740     // Wait until the server has started and reports success.
   736     while (!clientProcess.canReadLine())
   741     while (!clientProcess.canReadLine())
   737         QVERIFY(clientProcess.waitForReadyRead(3000));
   742         QVERIFY(clientProcess.waitForReadyRead(3000));
   738     QByteArray clientGreeting = clientProcess.readLine();
   743     QByteArray clientGreeting = clientProcess.readLine();
   739     QCOMPARE(clientGreeting, QByteArray("ok\n"));
   744     QCOMPARE(clientGreeting, QByteArray("ok\n"));
   777 #else
   782 #else
   778 
   783 
   779     QProcess serverProcess;
   784     QProcess serverProcess;
   780     serverProcess.start(QLatin1String("clientserver/clientserver server 1 1"),
   785     serverProcess.start(QLatin1String("clientserver/clientserver server 1 1"),
   781                         QIODevice::ReadWrite | QIODevice::Text);
   786                         QIODevice::ReadWrite | QIODevice::Text);
       
   787     QVERIFY2(serverProcess.waitForStarted(3000),
       
   788              qPrintable("Failed to start subprocess: " + serverProcess.errorString()));
   782 
   789 
   783     // Wait until the server has started and reports success.
   790     // Wait until the server has started and reports success.
   784     while (!serverProcess.canReadLine())
   791     while (!serverProcess.canReadLine())
   785         QVERIFY(serverProcess.waitForReadyRead(3000));
   792         QVERIFY(serverProcess.waitForReadyRead(3000));
   786     QByteArray serverGreeting = serverProcess.readLine();
   793     QByteArray serverGreeting = serverProcess.readLine();
   790 
   797 
   791     QProcess clientProcess;
   798     QProcess clientProcess;
   792     clientProcess.start(QString::fromLatin1("clientserver/clientserver unconnectedclient %1 %2")
   799     clientProcess.start(QString::fromLatin1("clientserver/clientserver unconnectedclient %1 %2")
   793                         .arg(QLatin1String("127.0.0.1")).arg(serverPort),
   800                         .arg(QLatin1String("127.0.0.1")).arg(serverPort),
   794                         QIODevice::ReadWrite | QIODevice::Text);
   801                         QIODevice::ReadWrite | QIODevice::Text);
       
   802     QVERIFY2(clientProcess.waitForStarted(3000),
       
   803              qPrintable("Failed to start subprocess: " + clientProcess.errorString()));
       
   804 
   795     // Wait until the server has started and reports success.
   805     // Wait until the server has started and reports success.
   796     while (!clientProcess.canReadLine())
   806     while (!clientProcess.canReadLine())
   797         QVERIFY(clientProcess.waitForReadyRead(3000));
   807         QVERIFY(clientProcess.waitForReadyRead(3000));
   798     QByteArray clientGreeting = clientProcess.readLine();
   808     QByteArray clientGreeting = clientProcess.readLine();
   799     QCOMPARE(clientGreeting, QByteArray("ok\n"));
   809     QCOMPARE(clientGreeting, QByteArray("ok\n"));