Пример #1
0
void TestQuaZip::getFileList()
{
    QFETCH(QString, zipName);
    QFETCH(QStringList, fileNames);
    qSort(fileNames);
    QDir curDir;
    if (curDir.exists(zipName)) {
        if (!curDir.remove(zipName))
            QFAIL("Can't remove zip file");
    }
    if (!createTestFiles(fileNames)) {
        QFAIL("Can't create test file");
    }
    if (!createTestArchive(zipName, fileNames)) {
        QFAIL("Can't create test archive");
    }
    QuaZip testZip(zipName);
    QVERIFY(testZip.open(QuaZip::mdUnzip));
    QVERIFY(testZip.goToFirstFile());
    QString firstFile = testZip.getCurrentFileName();
    QStringList fileList = testZip.getFileNameList();
    qSort(fileList);
    QCOMPARE(fileList, fileNames);
    QHash<QString, QFileInfo> srcInfo;
    foreach (QString fileName, fileNames) {
        srcInfo[fileName] = QFileInfo("tmp/" + fileName);
    }
Пример #2
0
void TestQuaZipDir::operators()
{
    QString zipName = "zipDirOperators.zip";
    QStringList fileNames;
    fileNames << "dir/test.txt" << "root.txt";
    if (!createTestFiles(fileNames)) {
        QFAIL("Couldn't create test files");
    }
    if (!createTestArchive(zipName, fileNames)) {
        QFAIL("Couldn't create test archive");
    }
    removeTestFiles(fileNames);
    QuaZip zip(zipName);
    QDir curDir;
    QVERIFY(zip.open(QuaZip::mdUnzip));
    QuaZipDir dir(&zip, "dir");
    QuaZipDir dir2 = dir; // Copy constructor
    QCOMPARE(dir2.path(), QString::fromLatin1("dir"));
    dir2.cdUp();
    QCOMPARE(dir2.path(), QString::fromLatin1(""));
    QCOMPARE(dir.path(), QString::fromLatin1("dir"));
    dir2 = dir; // operator=()
    QCOMPARE(dir2.path(), QString::fromLatin1("dir"));
    QVERIFY(dir2 == dir); // opertor==
    dir.cd("/");
    QCOMPARE(dir[0], QString::fromLatin1("dir/"));
    QCOMPARE(dir[1], QString::fromLatin1("root.txt"));
    zip.close();
    curDir.remove(zipName);
}
Пример #3
0
void TestQuaZipDir::entryList()
{
    QFETCH(QString, zipName);
    QFETCH(QStringList, fileNames);
    QFETCH(QString, dirName);
    QFETCH(int, filter);
    QFETCH(int, sort);
    QDir::Filters filters = static_cast<QDir::Filters>(filter);
    QDir::SortFlags sorting = static_cast<QDir::SortFlags>(sort);
    QFETCH(QStringList, entries);
    QDir curDir;
    if (!createTestFiles(fileNames)) {
        QFAIL("Couldn't create test files");
    }
    if (!createTestArchive(zipName, fileNames)) {
        QFAIL("Couldn't create test archive");
    }
    removeTestFiles(fileNames);
    QuaZip zip(zipName);
    QVERIFY(zip.open(QuaZip::mdUnzip));
    QuaZipDir dir(&zip, dirName);
    QCOMPARE(dir.entryList(filters, sorting), entries);
    zip.close();
    curDir.remove(zipName);
}
Пример #4
0
void TestQuaZipDir::cd()
{
    QFETCH(QString, zipName);
    QFETCH(QStringList, fileNames);
    QFETCH(QString, dirName);
    QFETCH(QString, targetDirName);
    QFETCH(QString, result);
    QDir curDir;
    if (!createTestFiles(fileNames)) {
        QFAIL("Couldn't create test files");
    }
    if (!createTestArchive(zipName, fileNames)) {
        QFAIL("Couldn't create test archive");
    }
    removeTestFiles(fileNames);
    QuaZip zip(zipName);
    QVERIFY(zip.open(QuaZip::mdUnzip));
    QuaZipDir dir(&zip, dirName);
    if (dirName.startsWith('/')) {
        dirName = dirName.mid(1);
    }
    if (dirName.endsWith('/')) {
        dirName.chop(1);
    }
    QCOMPARE(dir.path(), dirName);
    {
        int lastSlash = dirName.lastIndexOf('/');
        if (lastSlash == -1) {
            // dirName is just a single name
            if (dirName.isEmpty()) {
                QCOMPARE(dir.dirName(), QString::fromLatin1("."));
            } else {
                QCOMPARE(dir.dirName(), dirName);
            }
        } else {
            // dirName is a sequence
            QCOMPARE(dir.dirName(), dirName.mid(lastSlash + 1));
        }
    }
    if (targetDirName == "..") {
        QVERIFY(dir.cdUp());
    } else {
        QVERIFY(dir.cd(targetDirName));
    }
    QCOMPARE(dir.path(), result);
    // Try to go back
    dir.setPath(dirName);
    QCOMPARE(dir.path(), dirName);
    zip.close();
    curDir.remove(zipName);
}
Пример #5
0
void TestQuaZipDir::entryList()
{
    QFETCH(QString, zipName);
    QFETCH(QStringList, fileNames);
    QFETCH(QString, dirName);
    QFETCH(QStringList, nameFilters);
    QFETCH(int, filter);
    QFETCH(int, sort);
    QDir::Filters filters = static_cast<QDir::Filters>(filter);
    QDir::SortFlags sorting = static_cast<QDir::SortFlags>(sort);
    QFETCH(QStringList, entries);
    QFETCH(int, caseSensitivity);
    QDir curDir;
    if (!createTestFiles(fileNames)) {
        QFAIL("Couldn't create test files");
    }
    if (!createTestArchive(zipName, fileNames)) {
        QFAIL("Couldn't create test archive");
    }
    removeTestFiles(fileNames);
    QuaZip zip(zipName);
    QVERIFY(zip.open(QuaZip::mdUnzip));
    QuaZipDir dir(&zip, dirName);
    QVERIFY(dir.exists());
    if (caseSensitivity != -1) {
        dir.setCaseSensitivity(static_cast<QuaZip::CaseSensitivity>(
                                   caseSensitivity));
        QCOMPARE(dir.caseSensitivity(), static_cast<QuaZip::CaseSensitivity>(
                     caseSensitivity));
    }
    QCOMPARE(dir.entryList(nameFilters, filters, sorting), entries);
    // Test default sorting setting.
    dir.setSorting(sorting);
    QCOMPARE(dir.sorting(), sorting);
    QCOMPARE(dir.entryList(nameFilters, filters), entries);
    // Test default name filter setting.
    dir.setNameFilters(nameFilters);
    QCOMPARE(dir.nameFilters(), nameFilters);
    QCOMPARE(dir.entryList(filters), entries);
    // Test default filters.
    dir.setFilter(filters);
    QCOMPARE(dir.filter(), filters);
    QCOMPARE(dir.entryList(), entries);
    QCOMPARE(dir.entryList().count(), static_cast<int>(dir.count()));
    zip.close();
    curDir.remove(zipName);
}
Пример #6
0
void TestQuaZipDir::entryInfoList()
{
    QString zipName = "entryInfoList.zip";
    QStringList fileNames;
    fileNames << "test.txt";
    if (!createTestFiles(fileNames)) {
        QFAIL("Couldn't create test files");
    }
    if (!createTestArchive(zipName, fileNames)) {
        QFAIL("Couldn't create test archive");
    }
    removeTestFiles(fileNames);
    QuaZip zip(zipName);
    QDir curDir;
    QVERIFY(zip.open(QuaZip::mdUnzip));
    QuaZipDir dir(&zip, "/");
    QCOMPARE(dir.entryInfoList().size(), 1);
    QCOMPARE(dir.entryInfoList64().size(), 1);
    zip.close();
    curDir.remove(zipName);
}
Пример #7
0
void TestQuaZipDir::cd()
{
    QFETCH(QString, zipName);
    QFETCH(QStringList, fileNames);
    QFETCH(QString, dirName);
    QFETCH(QString, targetDirName);
    QFETCH(QString, result);
    QDir curDir;
    if (!createTestFiles(fileNames)) {
        QFAIL("Couldn't create test files");
    }
    if (!createTestArchive(zipName, fileNames)) {
        QFAIL("Couldn't create test archive");
    }
    removeTestFiles(fileNames);
    QuaZip zip(zipName);
    QVERIFY(zip.open(QuaZip::mdUnzip));
    QuaZipDir dir(&zip, dirName);
    QVERIFY(dir.cd(targetDirName));
    QCOMPARE(dir.path(), result);
    zip.close();
    curDir.remove(zipName);
}
Пример #8
0
void TestQuaZipDir::filePath()
{
    QString zipName = "entryInfoList.zip";
    QStringList fileNames;
    fileNames << "root.txt" << "dir/test.txt";
    if (!createTestFiles(fileNames)) {
        QFAIL("Couldn't create test files");
    }
    if (!createTestArchive(zipName, fileNames)) {
        QFAIL("Couldn't create test archive");
    }
    removeTestFiles(fileNames);
    QuaZip zip(zipName);
    QDir curDir;
    QVERIFY(zip.open(QuaZip::mdUnzip));
    QuaZipDir dir(&zip);
    QVERIFY(dir.cd("dir"));
    QCOMPARE(dir.relativeFilePath("/root.txt"),
             QString::fromLatin1("../root.txt"));
    QCOMPARE(dir.filePath("test.txt"),
             QString::fromLatin1("dir/test.txt"));
    zip.close();
    curDir.remove(zipName);
}