Commit ea2e4d46 authored by Ragnar Thomsen's avatar Ragnar Thomsen
Browse files

Unittest detection of compression method

Unittests for cli7z and clirar were modified to also test correct
detection of compression method.
parent 5f79138b
......@@ -106,6 +106,7 @@ void Cli7zTest::testList_data()
QTest::addColumn<bool>("isMultiVolume");
// Is zero for non-multi-volume archives:
QTest::addColumn<int>("numberOfVolumes");
QTest::addColumn<QStringList>("compressionMethods");
// Index of some entry to be tested.
QTest::addColumn<int>("someEntryIndex");
// Entry metadata.
......@@ -118,45 +119,45 @@ void Cli7zTest::testList_data()
// p7zip version 16.02 tests
QTest::newRow("normal-file-1602")
<< QFINDTESTDATA("data/archive-with-symlink-1602.txt") << 10 << false << 0
<< QFINDTESTDATA("data/archive-with-symlink-1602.txt") << 10 << false << 0 << QStringList{QStringLiteral("LZMA2")}
<< 4 << QStringLiteral("testarchive/dir2/file2.txt") << false << false << (qulonglong) 32 << QStringLiteral("2015-05-17T20:41:48");
QTest::newRow("encrypted-1602")
<< QFINDTESTDATA("data/archive-encrypted-1602.txt") << 4 << false << 0
<< QFINDTESTDATA("data/archive-encrypted-1602.txt") << 4 << false << 0 << QStringList{QStringLiteral("LZMA2"), QStringLiteral("7zAES")}
<< 1 << QStringLiteral("file2.txt") << false << true << (qulonglong) 14 << QStringLiteral("2016-03-02T22:37:55");
QTest::newRow("multi-volume-1602")
<< QFINDTESTDATA("data/archive-multivol-1602.txt") << 2 << true << 5
<< QFINDTESTDATA("data/archive-multivol-1602.txt") << 2 << true << 5 << QStringList{QStringLiteral("LZMA2")}
<< 1 << QStringLiteral("largefile2") << false << false << (qulonglong) 2097152 << QStringLiteral("2016-07-17T11:26:19");
// p7zip version 15.14 tests
QTest::newRow("normal-file-1514")
<< QFINDTESTDATA("data/archive-with-symlink-1514.txt") << 10 << false << 0
<< QFINDTESTDATA("data/archive-with-symlink-1514.txt") << 10 << false << 0 << QStringList{QStringLiteral("LZMA2")}
<< 4 << QStringLiteral("testarchive/dir2/file2.txt") << false << false << (qulonglong) 32 << QStringLiteral("2015-05-17T19:41:48");
QTest::newRow("encrypted-1514")
<< QFINDTESTDATA("data/archive-encrypted-1514.txt") << 9 << false << 0
<< QFINDTESTDATA("data/archive-encrypted-1514.txt") << 9 << false << 0 << QStringList{QStringLiteral("LZMA2"), QStringLiteral("7zAES")}
<< 3 << QStringLiteral("testarchive/dir1/file1.txt") << false << true << (qulonglong) 32 << QStringLiteral("2015-05-17T19:41:48");
// p7zip version 15.09 tests
QTest::newRow("normal-file-1509")
<< QFINDTESTDATA("data/archive-with-symlink-1509.txt") << 10 << false << 0
<< QFINDTESTDATA("data/archive-with-symlink-1509.txt") << 10 << false << 0 << QStringList{QStringLiteral("LZMA2")}
<< 4 << QStringLiteral("testarchive/dir2/file2.txt") << false << false << (qulonglong) 32 << QStringLiteral("2015-05-17T19:41:48");
QTest::newRow("encrypted-1509")
<< QFINDTESTDATA("data/archive-encrypted-1509.txt") << 9 << false << 0
<< QFINDTESTDATA("data/archive-encrypted-1509.txt") << 9 << false << 0 << QStringList{QStringLiteral("LZMA2"), QStringLiteral("7zAES")}
<< 3 << QStringLiteral("testarchive/dir1/file1.txt") << false << true << (qulonglong) 32 << QStringLiteral("2015-05-17T19:41:48");
// p7zip version 9.38.1 tests
QTest::newRow("normal-file-9381")
<< QFINDTESTDATA("data/archive-with-symlink-9381.txt") << 10 << false << 0
<< QFINDTESTDATA("data/archive-with-symlink-9381.txt") << 10 << false << 0 << QStringList{QStringLiteral("LZMA2")}
<< 4 << QStringLiteral("testarchive/dir2/file2.txt") << false << false << (qulonglong) 32 << QStringLiteral("2015-05-17T19:41:48");
QTest::newRow("encrypted-9381")
<< QFINDTESTDATA("data/archive-encrypted-9381.txt") << 9 << false << 0
<< QFINDTESTDATA("data/archive-encrypted-9381.txt") << 9 << false << 0 << QStringList{QStringLiteral("LZMA2"), QStringLiteral("7zAES")}
<< 3 << QStringLiteral("testarchive/dir1/file1.txt") << false << true << (qulonglong) 32 << QStringLiteral("2015-05-17T19:41:48");
}
......@@ -164,7 +165,8 @@ void Cli7zTest::testList()
{
qRegisterMetaType<Archive::Entry*>("Archive::Entry*");
CliPlugin *plugin = new CliPlugin(this, {QStringLiteral("dummy.7z")});
QSignalSpy signalSpy(plugin, &CliPlugin::entry);
QSignalSpy signalSpyEntry(plugin, &CliPlugin::entry);
QSignalSpy signalSpyCompMethod(plugin, &CliPlugin::compressionMethodFound);
QFETCH(QString, outputTextFile);
QFETCH(int, expectedEntriesCount);
......@@ -178,7 +180,7 @@ void Cli7zTest::testList()
QVERIFY(plugin->readListLine(line));
}
QCOMPARE(signalSpy.count(), expectedEntriesCount);
QCOMPARE(signalSpyEntry.count(), expectedEntriesCount);
QFETCH(bool, isMultiVolume);
QCOMPARE(plugin->isMultiVolume(), isMultiVolume);
......@@ -186,9 +188,13 @@ void Cli7zTest::testList()
QFETCH(int, numberOfVolumes);
QCOMPARE(plugin->numberOfVolumes(), numberOfVolumes);
QCOMPARE(signalSpyCompMethod.count(), 1);
QFETCH(QStringList, compressionMethods);
QCOMPARE(signalSpyCompMethod.at(0).at(0).toStringList(), compressionMethods);
QFETCH(int, someEntryIndex);
QVERIFY(someEntryIndex < signalSpy.count());
Archive::Entry *entry = signalSpy.at(someEntryIndex).at(0).value<Archive::Entry*>();
QVERIFY(someEntryIndex < signalSpyEntry.count());
Archive::Entry *entry = signalSpyEntry.at(someEntryIndex).at(0).value<Archive::Entry*>();
QFETCH(QString, expectedName);
QCOMPARE(entry->fullPath(), expectedName);
......
......@@ -107,6 +107,7 @@ void CliRarTest::testList_data()
QTest::addColumn<bool>("isMultiVolume");
// Is zero for non-multi-volume archives:
QTest::addColumn<int>("numberOfVolumes");
QTest::addColumn<QStringList>("compressionMethods");
// Index of some entry to be tested.
QTest::addColumn<int>("someEntryIndex");
// Entry metadata.
......@@ -121,60 +122,64 @@ void CliRarTest::testList_data()
// Unrar 5 tests
QTest::newRow("normal-file-unrar5")
<< QFINDTESTDATA("data/archive-with-symlink-unrar5.txt") << QString() << 8 << false << 0
<< QFINDTESTDATA("data/archive-with-symlink-unrar5.txt") << QString() << 8 << false << 0 << QStringList{QStringLiteral("RAR4")}
<< 2 << QStringLiteral("rartest/file2.txt") << false << false << QString() << (qulonglong) 14 << (qulonglong) 23 << QStringLiteral("2016-03-21T08:57:36");
QTest::newRow("symlink-unrar5")
<< QFINDTESTDATA("data/archive-with-symlink-unrar5.txt") << QString() << 8 << false << 0
<< QFINDTESTDATA("data/archive-with-symlink-unrar5.txt") << QString() << 8 << false << 0 << QStringList{QStringLiteral("RAR4")}
<< 3 << QStringLiteral("rartest/linktofile1.txt") << false << false << QStringLiteral("file1.txt") << (qulonglong) 9 << (qulonglong) 9 << QStringLiteral("2016-03-21T08:58:16");
QTest::newRow("encrypted-unrar5")
<< QFINDTESTDATA("data/archive-encrypted-unrar5.txt") << QString() << 7 << false << 0
<< QFINDTESTDATA("data/archive-encrypted-unrar5.txt") << QString() << 7 << false << 0 << QStringList{QStringLiteral("RAR4")}
<< 2 << QStringLiteral("rartest/file2.txt") << false << true << QString() << (qulonglong) 14 << (qulonglong) 32 << QStringLiteral("2016-03-21T17:03:36");
QTest::newRow("recovery-record-unrar5")
<< QFINDTESTDATA("data/archive-recovery-record-unrar5.txt") << QString() << 3 << false << 0
<< QFINDTESTDATA("data/archive-recovery-record-unrar5.txt") << QString() << 3 << false << 0 << QStringList{QStringLiteral("RAR4")}
<< 0 << QStringLiteral("file1.txt") << false << false << QString() << (qulonglong) 32 << (qulonglong) 33 << QStringLiteral("2015-07-26T19:04:38");
QTest::newRow("corrupt-archive-unrar5")
<< QFINDTESTDATA("data/archive-corrupt-file-header-unrar5.txt") << QString() << 8 << false << 0
<< QFINDTESTDATA("data/archive-corrupt-file-header-unrar5.txt") << QString() << 8 << false << 0 << QStringList{QStringLiteral("RAR4")}
<< 6 << QStringLiteral("dir1/") << true << false << QString() << (qulonglong) 0 << (qulonglong) 0 << QStringLiteral("2015-05-14T01:45:24");
//Note: The number of entries will be the total number of all entries in all volumes, i.e. if a file spans 3 volumes it will count as 3 entries.
QTest::newRow("multivolume-archive-unrar5")
<< QFINDTESTDATA("data/archive-multivol-unrar5.txt") << QString() << 6 << true << 5
<< QFINDTESTDATA("data/archive-multivol-unrar5.txt") << QString() << 6 << true << 5 << QStringList{QStringLiteral("RAR4")}
<< 5 << QStringLiteral("largefile2") << false << false << QString() << (qulonglong) 2097152 << (qulonglong) 11231 << QStringLiteral("2016-07-17T11:26:19");
QTest::newRow("RAR5-open-with-unrar5")
<< QFINDTESTDATA("data/archive-RARv5-unrar5.txt") << QString() << 9 << false << 0 << QStringList{QStringLiteral("RAR5")}
<< 4 << QStringLiteral("testarchive/dir1/file1.txt") << false << false << QString() << (qulonglong) 32 << (qulonglong) 32 << QStringLiteral("2015-05-17T20:41:48");
// Unrar 4 tests
QTest::newRow("normal-file-unrar4")
<< QFINDTESTDATA("data/archive-with-symlink-unrar4.txt") << QString() << 8 << false << 0
<< QFINDTESTDATA("data/archive-with-symlink-unrar4.txt") << QString() << 8 << false << 0 << QStringList{QStringLiteral("RAR4")}
<< 2 << QStringLiteral("rartest/file2.txt") << false << false << QString() << (qulonglong) 14 << (qulonglong) 23 << QStringLiteral("2016-03-21T08:57:00");
QTest::newRow("symlink-unrar4")
<< QFINDTESTDATA("data/archive-with-symlink-unrar4.txt") << QString() << 8 << false << 0
<< QFINDTESTDATA("data/archive-with-symlink-unrar4.txt") << QString() << 8 << false << 0 << QStringList{QStringLiteral("RAR4")}
<< 3 << QStringLiteral("rartest/linktofile1.txt") << false << false << QStringLiteral("file1.txt") << (qulonglong) 9 << (qulonglong) 9 << QStringLiteral("2016-03-21T08:58:00");
QTest::newRow("encrypted-unrar4")
<< QFINDTESTDATA("data/archive-encrypted-unrar4.txt") << QString() << 7 << false << 0
<< QFINDTESTDATA("data/archive-encrypted-unrar4.txt") << QString() << 7 << false << 0 << QStringList{QStringLiteral("RAR4")}
<< 2 << QStringLiteral("rartest/file2.txt") << false << true << QString() << (qulonglong) 14 << (qulonglong) 32 << QStringLiteral("2016-03-21T17:03:00");
QTest::newRow("recovery-record-unrar4")
<< QFINDTESTDATA("data/archive-recovery-record-unrar4.txt") << QString() << 3 << false << 0
<< QFINDTESTDATA("data/archive-recovery-record-unrar4.txt") << QString() << 3 << false << 0 << QStringList{QStringLiteral("RAR4")}
<< 0 << QStringLiteral("file1.txt") << false << false << QString() << (qulonglong) 32 << (qulonglong) 33 << QStringLiteral("2015-07-26T19:04:00");
QTest::newRow("corrupt-archive-unrar4")
<< QFINDTESTDATA("data/archive-corrupt-file-header-unrar4.txt") << QString() << 8 << false << 0
<< QFINDTESTDATA("data/archive-corrupt-file-header-unrar4.txt") << QString() << 8 << false << 0 << QStringList{QStringLiteral("RAR4")}
<< 6 << QStringLiteral("dir1/") << true << false << QString() << (qulonglong) 0 << (qulonglong) 0 << QStringLiteral("2015-05-14T01:45:00");
QTest::newRow("RAR5-open-with-unrar4")
<< QFINDTESTDATA("data/archive-RARv5-unrar4.txt")
<< QStringLiteral("Your unrar executable is version 4.20, which is too old to handle this archive. Please update to a more recent version.")
<< 0 << false << 0 << 0 << QString() << true << false << QString() << (qulonglong) 0 << (qulonglong) 0 << QString();
<< 0 << false << 0 << QStringList() << 0 << QString() << true << false << QString() << (qulonglong) 0 << (qulonglong) 0 << QString();
//Note: The number of entries will be the total number of all entries in all volumes, i.e. if a file spans 3 volumes it will count as 3 entries.
QTest::newRow("multivolume-archive-unrar4")
<< QFINDTESTDATA("data/archive-multivol-unrar4.txt") << QString() << 6 << true << 5
<< QFINDTESTDATA("data/archive-multivol-unrar4.txt") << QString() << 6 << true << 5 << QStringList{QStringLiteral("RAR4")}
<< 5 << QStringLiteral("largefile2") << false << false << QString() << (qulonglong) 2097152 << (qulonglong) 11231 << QStringLiteral("2016-07-17T11:26:00");
// Unrar 3 tests
......@@ -182,7 +187,7 @@ void CliRarTest::testList_data()
QTest::newRow("RAR5-open-with-unrar3")
<< QFINDTESTDATA("data/archive-RARv5-unrar3.txt")
<< QStringLiteral("Unrar reported a non-RAR archive. The installed unrar version (3.71) is old. Try updating your unrar.")
<< 0 << false << 0 << 0 << QString() << true << false << QString() << (qulonglong) 0 << (qulonglong) 0 << QString();
<< 0 << false << 0 << QStringList() << 0 << QString() << true << false << QString() << (qulonglong) 0 << (qulonglong) 0 << QString();
/*
* Check that the plugin will not crash when reading corrupted archives, which
......@@ -192,7 +197,7 @@ void CliRarTest::testList_data()
* See bug 262857 and commit 2042997013432cdc6974f5b26d39893a21e21011.
*/
QTest::newRow("corrupt-archive-unrar3")
<< QFINDTESTDATA("data/archive-corrupt-file-header-unrar3.txt") << QString() << 1 << true << 1
<< QFINDTESTDATA("data/archive-corrupt-file-header-unrar3.txt") << QString() << 1 << true << 1 << QStringList{QStringLiteral("RAR4")}
<< 0 << QStringLiteral("some-file.ext") << false << false << QString() << (qulonglong) 732522496 << (qulonglong) 14851208 << QStringLiteral("2010-10-29T20:47:00");
}
......@@ -201,6 +206,7 @@ void CliRarTest::testList()
qRegisterMetaType<Archive::Entry*>("Archive::Entry*");
CliPlugin *rarPlugin = new CliPlugin(this, {QStringLiteral("dummy.rar")});
QSignalSpy signalSpyEntry(rarPlugin, &CliPlugin::entry);
QSignalSpy signalSpyCompMethod(rarPlugin, &CliPlugin::compressionMethodFound);
QSignalSpy signalSpyError(rarPlugin, &CliPlugin::error);
QFETCH(QString, outputTextFile);
......@@ -232,6 +238,12 @@ void CliRarTest::testList()
QFETCH(int, numberOfVolumes);
QCOMPARE(rarPlugin->numberOfVolumes(), numberOfVolumes);
QVERIFY(signalSpyCompMethod.count() > 0);
QFETCH(QStringList, compressionMethods);
if (!compressionMethods.isEmpty()) {
QCOMPARE(signalSpyCompMethod.at(0).at(0).toStringList(), compressionMethods);
}
QFETCH(int, someEntryIndex);
QVERIFY(someEntryIndex < signalSpyEntry.count());
Archive::Entry *entry = signalSpyEntry.at(someEntryIndex).at(0).value<Archive::Entry*>();
......
UNRAR 5.40 freeware Copyright (c) 1993-2016 Alexander Roshal
Archive: testrar5.rar
Details: RAR 5
Name: testarchive/file4.txt
Type: File
Size: 32
Packed size: 32
Ratio: 100%
mtime: 2015-07-26 18:53:21,000
Attributes: -rw-rw-r--
CRC32: A04F9191
Host OS: Unix
Compression: RAR 5.0(v50) -m0 -md=128K
Name: testarchive/dir2/file2.txt
Type: File
Size: 32
Packed size: 32
Ratio: 100%
mtime: 2015-05-17 20:41:48,000
Attributes: -rw-rw-r--
CRC32: D49ECBCA
Host OS: Unix
Compression: RAR 5.0(v50) -m3 -md=128K
Name: testarchive/file1.txt
Type: File
Size: 43
Packed size: 35
Ratio: 81%
mtime: 2015-09-13 14:05:45,000
Attributes: -rw-rw-r--
CRC32: 94E02716
Host OS: Unix
Compression: RAR 5.0(v50) -m3 -md=128K
Name: testarchive/file2.txt
Type: File
Size: 32
Packed size: 32
Ratio: 100%
mtime: 2015-05-18 14:57:37,000
Attributes: -rw-rw-r--
CRC32: D49ECBCA
Host OS: Unix
Compression: RAR 5.0(v50) -m3 -md=128K
Name: testarchive/dir1/file1.txt
Type: File
Size: 32
Packed size: 32
Ratio: 100%
mtime: 2015-05-17 20:41:48,000
Attributes: -rw-rw-r--
CRC32: 034EE5C7
Host OS: Unix
Compression: RAR 5.0(v50) -m3 -md=128K
Name: testarchive/file3.txt
Type: File
Size: 32
Packed size: 32
Ratio: 100%
mtime: 2015-05-13 17:26:42,000
Attributes: -rw-rw-r--
CRC32: 99D12E31
Host OS: Unix
Compression: RAR 5.0(v50) -m3 -md=128K
Name: testarchive/dir2
Type: Directory
mtime: 2015-05-14 01:43:41,000
Attributes: drwxrwxr-x
CRC32: 00000000
Host OS: Unix
Compression: RAR 5.0(v50) -m0 -md=0K
Name: testarchive/dir1
Type: Directory
mtime: 2015-05-14 01:45:24,000
Attributes: drwxrwxr-x
CRC32: 00000000
Host OS: Unix
Compression: RAR 5.0(v50) -m0 -md=0K
Name: testarchive
Type: Directory
mtime: 2016-10-09 19:01:48,000
Attributes: drwxrwxr-x
CRC32: 00000000
Host OS: Unix
Compression: RAR 5.0(v50) -m0 -md=0K
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment