Exemplo n.º 1
0
void KArchiveTest::testCreateZip()
{
    KZip zip( s_zipFileName );

    QVERIFY( zip.open( QIODevice::WriteOnly ) );

    zip.setExtraField( KZip::NoExtraField );

    zip.setCompression( KZip::NoCompression );
    QByteArray zipMimeType( s_zipMimeType );
    zip.writeFile( "mimetype", "", "", zipMimeType.data(), zipMimeType.size() );
    zip.setCompression( KZip::DeflateCompression );

    writeTestFilesToArchive( &zip );

    QVERIFY( zip.close() );

    QFile zipFile( QFile::encodeName( s_zipFileName ) );
    QFileInfo fileInfo( zipFile );
    QVERIFY( fileInfo.exists() );
    QVERIFY( fileInfo.size() > 300 );

    // Check that the header with no-compression and no-extrafield worked.
    // (This is for the "magic" for koffice documents)
    QVERIFY( zipFile.open( QIODevice::ReadOnly ) );
    QByteArray arr = zipFile.read( 4 );
    QCOMPARE( arr, QByteArray( "PK\003\004" ) );
    QVERIFY( zipFile.seek( 30 ) );
    arr = zipFile.read( 8 );
    QCOMPARE( arr, QByteArray( "mimetype" ) );
    arr = zipFile.read( zipMimeType.size() );
    QCOMPARE( arr, zipMimeType );
}
Exemplo n.º 2
0
/**
 * @dataProvider testCreateTar_data
 */
void KArchiveTest::testCreateTar()
{
    QFETCH(QString, fileName);

    // With    tempfile: 0.7-0.8 ms, 994236 instr. loads
    // Without tempfile:    0.81 ms, 992541 instr. loads
    // Note: use ./karchivetest 2>&1 | grep ms
    //       to avoid being slowed down by the kDebugs.
    QBENCHMARK {

    KTar tar(fileName);
    QVERIFY(tar.open(QIODevice::WriteOnly));

    writeTestFilesToArchive(&tar);

    QVERIFY(tar.close());

    QFileInfo fileInfo(QFile::encodeName(fileName));
    QVERIFY(fileInfo.exists());
    // We can't check for an exact size because of the addLocalFile, whose data is system-dependent
    QVERIFY(fileInfo.size() > 450);

    }

    // NOTE The only .tar test, cleanup here
    QFile::remove(fileName);
}
Exemplo n.º 3
0
void KArchiveTest::testCreateZipError()
{
    // Giving a directory name to kzip must give an error case in close(), see #136630.
    // Otherwise we just lose data.
    KZip zip(QDir::currentPath());

    QVERIFY(zip.open(QIODevice::WriteOnly));

    writeTestFilesToArchive(&zip);

    QVERIFY(!zip.close());
}
Exemplo n.º 4
0
/**
 * @dataProvider testCreate7Zip_data
 */
void KArchiveTest::testCreate7Zip()
{
    QFETCH(QString, fileName);

    QBENCHMARK {

        K7Zip k7zip(fileName);
        QVERIFY(k7zip.open(QIODevice::WriteOnly));

        writeTestFilesToArchive(&k7zip);

        QVERIFY(k7zip.close());

        QFileInfo fileInfo(QFile::encodeName(fileName));
        QVERIFY(fileInfo.exists());
        //qDebug() << "fileInfo.size()" << fileInfo.size();
        // We can't check for an exact size because of the addLocalFile, whose data is system-dependent
        QVERIFY(fileInfo.size() > 390);

    }
}
Exemplo n.º 5
0
/**
 * @dataProvider setupData
 */
void KArchiveTest::testCreateTarXXX()
{
    QFETCH(QString, fileName);

    // With    tempfile: 1.3-1.7 ms, 2555089 instr. loads
    // Without tempfile:    0.87 ms,  987915 instr. loads
    QBENCHMARK {

    KTar tar(fileName);
    QVERIFY(tar.open(QIODevice::WriteOnly));

    writeTestFilesToArchive(&tar);

    QVERIFY(tar.close());

    QFileInfo fileInfo(QFile::encodeName(fileName));
    QVERIFY(fileInfo.exists());
    // We can't check for an exact size because of the addLocalFile, whose data is system-dependent
    QVERIFY(fileInfo.size() > 350);

    }
}