MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / testSequential

Method testSequential

lib/QuaZip/qztest/testquazip.cpp:425–471  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

423#endif
424
425void 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}

Callers

nothing calls this directly

Calls 8

listenMethod · 0.80
goToFirstFileMethod · 0.80
getCurrentFileInfoMethod · 0.80
setAutoCloseMethod · 0.45
openMethod · 0.45
isOpenMethod · 0.45
writeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected