| 423 | #endif |
| 424 | |
| 425 | void TestQuaZip::testSequential() |
| 426 | { |
| 427 | QTcpServer server; |
| 428 | QVERIFY(server.listen(QHostAddress(QHostAddress::LocalHost))); |
| 429 | quint16 port = server.serverPort(); |
| 430 | QTcpSocket socket; |
| 431 | socket.connectToHost(QHostAddress(QHostAddress::LocalHost), port); |
| 432 | QVERIFY(socket.waitForConnected()); |
| 433 | QVERIFY(server.waitForNewConnection(30000)); |
| 434 | QTcpSocket *client = server.nextPendingConnection(); |
| 435 | QuaZip zip(&socket); |
| 436 | zip.setAutoClose(false); |
| 437 | QVERIFY(zip.open(QuaZip::mdCreate)); |
| 438 | QVERIFY(socket.isOpen()); |
| 439 | QuaZipFile zipFile(&zip); |
| 440 | QuaZipNewInfo info("test.txt"); |
| 441 | QVERIFY(zipFile.open(QIODevice::WriteOnly, info, NULL, 0, 0)); |
| 442 | QCOMPARE(zipFile.write("test"), static_cast<qint64>(4)); |
| 443 | zipFile.close(); |
| 444 | zip.close(); |
| 445 | QVERIFY(socket.isOpen()); |
| 446 | socket.disconnectFromHost(); |
| 447 | QVERIFY(socket.waitForDisconnected()); |
| 448 | QVERIFY(client->waitForReadyRead()); |
| 449 | QByteArray received = client->readAll(); |
| 450 | #ifdef QUAZIP_QZTEST_QUAZIP_DEBUG_SOCKET |
| 451 | QFile debug("testSequential.zip"); |
| 452 | debug.open(QIODevice::WriteOnly); |
| 453 | debug.write(received); |
| 454 | debug.close(); |
| 455 | #endif |
| 456 | client->close(); |
| 457 | QBuffer buffer(&received); |
| 458 | QuaZip receivedZip(&buffer); |
| 459 | QVERIFY(receivedZip.open(QuaZip::mdUnzip)); |
| 460 | QVERIFY(receivedZip.goToFirstFile()); |
| 461 | QuaZipFileInfo64 receivedInfo; |
| 462 | QVERIFY(receivedZip.getCurrentFileInfo(&receivedInfo)); |
| 463 | QCOMPARE(receivedInfo.name, QString::fromLatin1("test.txt")); |
| 464 | QCOMPARE(receivedInfo.uncompressedSize, static_cast<quint64>(4)); |
| 465 | QuaZipFile receivedFile(&receivedZip); |
| 466 | QVERIFY(receivedFile.open(QIODevice::ReadOnly)); |
| 467 | QByteArray receivedText = receivedFile.readAll(); |
| 468 | QCOMPARE(receivedText, QByteArray("test")); |
| 469 | receivedFile.close(); |
| 470 | receivedZip.close(); |
| 471 | } |
nothing calls this directly
no test coverage detected