Commit 04152763 authored by Ragnar Thomsen's avatar Ragnar Thomsen

Add unittests for multi-volume archives in cli7z and clirar

The unittests check whether multi-volume archives are detected, parsed
correctly and also that the number of volumes is correct.

An error was fixed in the UNRAR4 parser, so the number of volumes is
detected corectly.

Other unittests for the recent p7zip v16.02 were also added.
parent 690a0043
......@@ -100,6 +100,9 @@ void Cli7zTest::testList_data()
{
QTest::addColumn<QString>("outputTextFile");
QTest::addColumn<int>("expectedEntriesCount");
QTest::addColumn<bool>("isMultiVolume");
// Is zero for non-multi-volume archives:
QTest::addColumn<int>("numberOfVolumes");
// Index of some entry to be tested.
QTest::addColumn<int>("someEntryIndex");
// Entry metadata.
......@@ -109,34 +112,48 @@ void Cli7zTest::testList_data()
QTest::addColumn<qulonglong>("expectedSize");
QTest::addColumn<QString>("expectedTimestamp");
// p7zip version 16.02 tests
QTest::newRow("normal-file-1602")
<< QFINDTESTDATA("data/archive-with-symlink-1602.txt") << 10 << false << 0
<< 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
<< 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
<< 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
<< QFINDTESTDATA("data/archive-with-symlink-1514.txt") << 10 << false << 0
<< 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
<< QFINDTESTDATA("data/archive-encrypted-1514.txt") << 9 << false << 0
<< 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
<< QFINDTESTDATA("data/archive-with-symlink-1509.txt") << 10 << false << 0
<< 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
<< QFINDTESTDATA("data/archive-encrypted-1509.txt") << 9 << false << 0
<< 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
<< QFINDTESTDATA("data/archive-with-symlink-9381.txt") << 10 << false << 0
<< 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
<< QFINDTESTDATA("data/archive-encrypted-9381.txt") << 9 << false << 0
<< 3 << QStringLiteral("testarchive/dir1/file1.txt") << false << true << (qulonglong) 32 << QStringLiteral("2015-05-17T19:41:48");
}
......@@ -159,6 +176,12 @@ void Cli7zTest::testList()
QCOMPARE(signalSpy.count(), expectedEntriesCount);
QFETCH(bool, isMultiVolume);
QCOMPARE(plugin->isMultiVolume(), isMultiVolume);
QFETCH(int, numberOfVolumes);
QCOMPARE(plugin->numberOfVolumes(), numberOfVolumes);
QFETCH(int, someEntryIndex);
QVERIFY(someEntryIndex < signalSpy.count());
ArchiveEntry entry = qvariant_cast<ArchiveEntry>(signalSpy.at(someEntryIndex).at(0));
......
7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,8 CPUs x64)
Scanning the drive for archives:
1 file, 276 bytes (1 KiB)
Listing archive: testpassfiles.7z
--
Path = testpassfiles.7z
Type = 7z
Physical Size = 276
Headers Size = 212
Method = LZMA2:12 7zAES
Solid = +
Blocks = 1
----------
Path = file1.txt
Size = 32
Packed Size = 64
Modified = 2016-03-02 22:37:55
Attributes = A_ -rw-rw-r--
CRC = 034EE5C7
Encrypted = +
Method = LZMA2:12 7zAES:19
Block = 0
Path = file2.txt
Size = 14
Packed Size =
Modified = 2016-03-02 22:37:55
Attributes = A_ -rw-rw-r--
CRC = A5BA4A7B
Encrypted = +
Method = LZMA2:12 7zAES:19
Block = 0
Path = file3.txt
Size = 32
Packed Size =
Modified = 2016-03-02 22:37:54
Attributes = A_ -rw-rw-r--
CRC = 99D12E31
Encrypted = +
Method = LZMA2:12 7zAES:19
Block = 0
Path = file4.txt
Size = 32
Packed Size =
Modified = 2016-03-02 22:37:50
Attributes = A_ -rw-rw-r--
CRC = A04F9191
Encrypted = +
Method = LZMA2:12 7zAES:19
Block = 0
7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,8 CPUs x64)
Scanning the drive for archives:
1 file, 1048576 bytes (1024 KiB)
Listing archive: testmultivol.7z.001
--
Path = testmultivol.7z.001
Type = Split
Physical Size = 1048576
Volumes = 5
Total Physical Size = 4194711
----
Path = testmultivol.7z
Size = 4194711
--
Path = testmultivol.7z
Type = 7z
Physical Size = 4194711
Headers Size = 181
Method = LZMA2:22
Solid = +
Blocks = 1
----------
Path = largefile1
Size = 2097152
Packed Size = 4194530
Modified = 2016-07-17 11:25:56
Attributes = A_ -rw-rw-r--
CRC = 147E8FFD
Encrypted = -
Method = LZMA2:22
Block = 0
Path = largefile2
Size = 2097152
Packed Size =
Modified = 2016-07-17 11:26:19
Attributes = A_ -rw-rw-r--
CRC = 934DAE71
Encrypted = -
Method = LZMA2:22
Block = 0
7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,8 CPUs x64)
Scanning the drive for archives:
1 file, 371 bytes (1 KiB)
Listing archive: testlink.7z
--
Path = testlink.7z
Type = 7z
Physical Size = 371
Headers Size = 310
Method = LZMA2:12
Solid = +
Blocks = 1
----------
Path = testarchive
Size = 0
Packed Size = 0
Modified = 2016-03-23 08:46:21
Attributes = D_ drwxrwxr-x
CRC =
Encrypted = -
Method =
Block =
Path = testarchive/dir1
Size = 0
Packed Size = 0
Modified = 2015-05-14 01:45:24
Attributes = D_ drwxrwxr-x
CRC =
Encrypted = -
Method =
Block =
Path = testarchive/dir2
Size = 0
Packed Size = 0
Modified = 2015-05-14 01:43:41
Attributes = D_ drwxrwxr-x
CRC =
Encrypted = -
Method =
Block =
Path = testarchive/dir1/file1.txt
Size = 32
Packed Size = 61
Modified = 2015-05-17 20:41:48
Attributes = A_ -rw-rw-r--
CRC = 034EE5C7
Encrypted = -
Method = LZMA2:12
Block = 0
Path = testarchive/dir2/file2.txt
Size = 32
Packed Size =
Modified = 2015-05-17 20:41:48
Attributes = A_ -rw-rw-r--
CRC = D49ECBCA
Encrypted = -
Method = LZMA2:12
Block = 0
Path = testarchive/file1.txt
Size = 43
Packed Size =
Modified = 2015-09-13 14:05:45
Attributes = A_ -rw-rw-r--
CRC = 94E02716
Encrypted = -
Method = LZMA2:12
Block = 0
Path = testarchive/file2.txt
Size = 32
Packed Size =
Modified = 2015-05-18 14:57:37
Attributes = A_ -rw-rw-r--
CRC = D49ECBCA
Encrypted = -
Method = LZMA2:12
Block = 0
Path = testarchive/file3.txt
Size = 32
Packed Size =
Modified = 2015-05-13 17:26:42
Attributes = A_ -rw-rw-r--
CRC = 99D12E31
Encrypted = -
Method = LZMA2:12
Block = 0
Path = testarchive/file4.txt
Size = 32
Packed Size =
Modified = 2015-07-26 18:53:21
Attributes = A_ -rw-rw-r--
CRC = A04F9191
Encrypted = -
Method = LZMA2:12
Block = 0
Path = testarchive/linktofile1.txt
Size = 9
Packed Size =
Modified = 2016-03-23 08:46:21
Attributes = A_ lrwxrwxrwx
CRC = 2D212004
Encrypted = -
Method = LZMA2:12
Block = 0
......@@ -101,6 +101,9 @@ void CliRarTest::testList_data()
{
QTest::addColumn<QString>("outputTextFile");
QTest::addColumn<int>("expectedEntriesCount");
QTest::addColumn<bool>("isMultiVolume");
// Is zero for non-multi-volume archives:
QTest::addColumn<int>("numberOfVolumes");
// Index of some entry to be tested.
QTest::addColumn<int>("someEntryIndex");
// Entry metadata.
......@@ -115,47 +118,57 @@ void CliRarTest::testList_data()
// Unrar 5 tests
QTest::newRow("normal-file-unrar5")
<< QFINDTESTDATA("data/archive-with-symlink-unrar5.txt") << 8
<< QFINDTESTDATA("data/archive-with-symlink-unrar5.txt") << 8 << false << 0
<< 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") << 8
<< QFINDTESTDATA("data/archive-with-symlink-unrar5.txt") << 8 << false << 0
<< 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") << 7
<< QFINDTESTDATA("data/archive-encrypted-unrar5.txt") << 7 << false << 0
<< 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") << 3
<< QFINDTESTDATA("data/archive-recovery-record-unrar5.txt") << 3 << false << 0
<< 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") << 8
<< QFINDTESTDATA("data/archive-corrupt-file-header-unrar5.txt") << 8 << false << 0
<< 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") << 6 << true << 5
<< 5 << QStringLiteral("largefile2") << false << false << QString() << (qulonglong) 2097152 << (qulonglong) 11231 << QStringLiteral("2016-07-17T11:26:19");
// Unrar 4 tests
QTest::newRow("normal-file-unrar4")
<< QFINDTESTDATA("data/archive-with-symlink-unrar4.txt") << 8
<< QFINDTESTDATA("data/archive-with-symlink-unrar4.txt") << 8 << false << 0
<< 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") << 8
<< QFINDTESTDATA("data/archive-with-symlink-unrar4.txt") << 8 << false << 0
<< 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") << 7
<< QFINDTESTDATA("data/archive-encrypted-unrar4.txt") << 7 << false << 0
<< 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") << 3
<< QFINDTESTDATA("data/archive-recovery-record-unrar4.txt") << 3 << false << 0
<< 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") << 8
<< QFINDTESTDATA("data/archive-corrupt-file-header-unrar4.txt") << 8 << false << 0
<< 6 << QStringLiteral("dir1/") << true << false << QString() << (qulonglong) 0 << (qulonglong) 0 << QStringLiteral("2015-05-14T01:45:00");
//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") << 6 << true << 5
<< 5 << QStringLiteral("largefile2") << false << false << QString() << (qulonglong) 2097152 << (qulonglong) 11231 << QStringLiteral("2016-07-17T11:26:00");
/*
* Check that the plugin will not crash when reading corrupted archives, which
* have lines such as "Unexpected end of archive" or "??? - the file header is
......@@ -164,7 +177,7 @@ void CliRarTest::testList_data()
* See bug 262857 and commit 2042997013432cdc6974f5b26d39893a21e21011.
*/
QTest::newRow("corrupt-archive-unrar3")
<< QFINDTESTDATA("data/archive-corrupt-file-header-unrar3.txt") << 1
<< QFINDTESTDATA("data/archive-corrupt-file-header-unrar3.txt") << 1 << true << 1
<< 0 << QStringLiteral("some-file.ext") << false << false << QString() << (qulonglong) 732522496 << (qulonglong) 14851208 << QStringLiteral("2010-10-29T20:47:00");
}
......@@ -187,6 +200,12 @@ void CliRarTest::testList()
QCOMPARE(signalSpy.count(), expectedEntriesCount);
QFETCH(bool, isMultiVolume);
QCOMPARE(rarPlugin->isMultiVolume(), isMultiVolume);
QFETCH(int, numberOfVolumes);
QCOMPARE(rarPlugin->numberOfVolumes(), numberOfVolumes);
QFETCH(int, someEntryIndex);
QVERIFY(someEntryIndex < signalSpy.count());
ArchiveEntry entry = qvariant_cast<ArchiveEntry>(signalSpy.at(someEntryIndex).at(0));
......
UNRAR 4.20 freeware Copyright (c) 1993-2012 Alexander Roshal
Volume testmultivol.part1.rar
Pathname/Comment
Size Packed Ratio Date Time Attr CRC Meth Ver
Host OS Solid Old
-------------------------------------------------------------------------------
largefile1
2097152 1048494 --> 17-07-16 11:25 -rw-rw-r-- D1D888DB m3g 2.9
Unix No No
-------------------------------------------------------------------------------
1 2097152 1048494 49% volume 1
Volume testmultivol.part2.rar
Pathname/Comment
Size Packed Ratio Date Time Attr CRC Meth Ver
Host OS Solid Old
-------------------------------------------------------------------------------
largefile1
2097152 1048494 <-> 17-07-16 11:25 -rw-rw-r-- 034C76D1 m3g 2.9
Unix No No
-------------------------------------------------------------------------------
0 0 1048494 0% volume 2
Volume testmultivol.part3.rar
Pathname/Comment
Size Packed Ratio Date Time Attr CRC Meth Ver
Host OS Solid Old
-------------------------------------------------------------------------------
largefile1
2097152 5613 <-- 17-07-16 11:25 -rw-rw-r-- 147E8FFD m3g 2.9
Unix No No
largefile2
2097152 1042837 --> 17-07-16 11:26 -rw-rw-r-- 0B319F93 m3g 2.9
Unix No No
-------------------------------------------------------------------------------
1 2097152 1048450 49% volume 3
Volume testmultivol.part4.rar
Pathname/Comment
Size Packed Ratio Date Time Attr CRC Meth Ver
Host OS Solid Old
-------------------------------------------------------------------------------
largefile2
2097152 1048492 <-> 17-07-16 11:26 -rw-rw-r-- BE13353A m3g 2.9
Unix No No
-------------------------------------------------------------------------------
0 0 1048492 0% volume 4
Volume testmultivol.part5.rar
Pathname/Comment
Size Packed Ratio Date Time Attr CRC Meth Ver
Host OS Solid Old
-------------------------------------------------------------------------------
largefile2
2097152 11231 <-- 17-07-16 11:26 -rw-rw-r-- 934DAE71 m3g 2.9
Unix No No
-------------------------------------------------------------------------------
0 0 11231 0% volume 5
2 4194304 4205161 100%
UNRAR 5.40 beta 2 freeware Copyright (c) 1993-2016 Alexander Roshal
Archive: testmultivol.part1.rar
Details: RAR 4, volume
Name: largefile1
Type: File
Size: 2097152
Packed size: 1048494
Ratio: -->
mtime: 2016-07-17 11:25:56,000
Attributes: -rw-rw-r--
Pack-CRC32: D1D888DB
Host OS: Unix
Compression: RAR 3.0(v29) -m3 -md=4M
Archive: testmultivol.part2.rar
Details: RAR 4, volume
Name: largefile1
Type: File
Size: 2097152
Packed size: 1048494
Ratio: <->
mtime: 2016-07-17 11:25:56,000
Attributes: -rw-rw-r--
Pack-CRC32: 034C76D1
Host OS: Unix
Compression: RAR 3.0(v29) -m3 -md=4M
Archive: testmultivol.part3.rar
Details: RAR 4, volume
Name: largefile1
Type: File
Size: 2097152
Packed size: 5613
Ratio: <--
mtime: 2016-07-17 11:25:56,000
Attributes: -rw-rw-r--
CRC32: 147E8FFD
Host OS: Unix
Compression: RAR 3.0(v29) -m3 -md=4M
Name: largefile2
Type: File
Size: 2097152
Packed size: 1042837
Ratio: -->
mtime: 2016-07-17 11:26:19,000
Attributes: -rw-rw-r--
Pack-CRC32: 0B319F93
Host OS: Unix
Compression: RAR 3.0(v29) -m3 -md=4M
Archive: testmultivol.part4.rar
Details: RAR 4, volume
Name: largefile2
Type: File
Size: 2097152
Packed size: 1048492
Ratio: <->
mtime: 2016-07-17 11:26:19,000
Attributes: -rw-rw-r--
Pack-CRC32: BE13353A
Host OS: Unix
Compression: RAR 3.0(v29) -m3 -md=4M
Archive: testmultivol.part5.rar
Details: RAR 4, volume
Name: largefile2
Type: File
Size: 2097152
Packed size: 11231
Ratio: <--
mtime: 2016-07-17 11:26:19,000
Attributes: -rw-rw-r--
CRC32: 934DAE71
Host OS: Unix
Compression: RAR 3.0(v29) -m3 -md=4M
......@@ -310,7 +310,7 @@ void CliPlugin::handleUnrar4Line(const QString &line) {
if (rxCommentEnd.match(line).hasMatch()) {
if (line.startsWith(QLatin1String("Volume"))) {
if (line.startsWith(QLatin1String("Volume "))) {
m_numberOfVolumes++;
if (!m_isMultiVolume) {
m_isMultiVolume = true;
......@@ -343,6 +343,8 @@ void CliPlugin::handleUnrar4Line(const QString &line) {
// Horizontal line indicates end of header.
if (line.startsWith(QStringLiteral("--------------------"))) {
m_parseState = ParseStateEntryFileName;
} else if (line.startsWith(QLatin1String("Volume "))) {
m_numberOfVolumes++;
}
return;
}
......
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