File indexing completed on 2024-12-22 05:26:51

0001 /*
0002     SPDX-FileCopyrightText: 2011, 2014 Raphael Kubo da Costa <rakuco@FreeBSD.org>
0003     SPDX-FileCopyrightText: 2015, 2016 Ragnar Thomsen <rthomsen6@gmail.com>
0004 
0005     SPDX-License-Identifier: BSD-2-Clause
0006 */
0007 
0008 #include "clirartest.h"
0009 #include "archive_kerfuffle.h"
0010 #include "cliplugin.h"
0011 #include "jobs.h"
0012 #include "testhelper.h"
0013 
0014 #include <QFile>
0015 #include <QSignalSpy>
0016 #include <QStandardPaths>
0017 #include <QTest>
0018 #include <QTextStream>
0019 
0020 QTEST_GUILESS_MAIN(CliRarTest)
0021 
0022 void initLocale()
0023 {
0024     qputenv("LC_ALL", "en_US.utf-8");
0025 }
0026 
0027 Q_CONSTRUCTOR_FUNCTION(initLocale)
0028 
0029 using namespace Kerfuffle;
0030 
0031 void CliRarTest::initTestCase()
0032 {
0033     m_plugin = new Plugin(this);
0034     const auto plugins = m_pluginManger.availablePlugins();
0035     for (Plugin *plugin : plugins) {
0036         if (plugin->metaData().pluginId() == QLatin1String("kerfuffle_clirar")) {
0037             m_plugin = plugin;
0038             return;
0039         }
0040     }
0041 }
0042 
0043 void CliRarTest::testArchive_data()
0044 {
0045     QTest::addColumn<QString>("archivePath");
0046     QTest::addColumn<QString>("expectedFileName");
0047     QTest::addColumn<bool>("isReadOnly");
0048     QTest::addColumn<bool>("isSingleFolder");
0049     QTest::addColumn<Archive::EncryptionType>("expectedEncryptionType");
0050     QTest::addColumn<QString>("expectedSubfolderName");
0051 
0052     const bool hasRar = !QStandardPaths::findExecutable(QStringLiteral("rar")).isEmpty();
0053 
0054     QString archivePath = QFINDTESTDATA("data/one_toplevel_folder.rar");
0055     QTest::newRow("archive with one top-level folder")
0056         << archivePath << QFileInfo(archivePath).fileName() << !hasRar << true << Archive::Unencrypted << QStringLiteral("A");
0057 
0058     archivePath = QFINDTESTDATA("data/locked_archive.rar");
0059     QTest::newRow("locked archive") << archivePath << QFileInfo(archivePath).fileName() << true << false << Archive::Unencrypted
0060                                     << QStringLiteral("locked_archive");
0061 }
0062 
0063 void CliRarTest::testArchive()
0064 {
0065     if (!m_plugin->isValid()) {
0066         QSKIP("clirar plugin not available. Skipping test.", SkipSingle);
0067     }
0068 
0069     QFETCH(QString, archivePath);
0070     auto loadJob = Archive::load(archivePath, m_plugin, this);
0071     QVERIFY(loadJob);
0072 
0073     TestHelper::startAndWaitForResult(loadJob);
0074     auto archive = loadJob->archive();
0075     QVERIFY(archive);
0076 
0077     if (!archive->isValid()) {
0078         QSKIP("Could not load the clirar plugin. Skipping test.", SkipSingle);
0079     }
0080 
0081     QFETCH(QString, expectedFileName);
0082     QCOMPARE(QFileInfo(archive->fileName()).fileName(), expectedFileName);
0083 
0084     QFETCH(bool, isReadOnly);
0085     QCOMPARE(archive->isReadOnly(), isReadOnly);
0086 
0087     QFETCH(bool, isSingleFolder);
0088     QCOMPARE(archive->isSingleFolder(), isSingleFolder);
0089 
0090     QFETCH(Archive::EncryptionType, expectedEncryptionType);
0091     QCOMPARE(archive->encryptionType(), expectedEncryptionType);
0092 
0093     QFETCH(QString, expectedSubfolderName);
0094     QCOMPARE(archive->subfolderName(), expectedSubfolderName);
0095 }
0096 
0097 void CliRarTest::testList_data()
0098 {
0099     QTest::addColumn<QString>("outputTextFile");
0100     QTest::addColumn<QString>("errorMessage");
0101     QTest::addColumn<int>("expectedEntriesCount");
0102     QTest::addColumn<bool>("isMultiVolume");
0103     // Is zero for non-multi-volume archives:
0104     QTest::addColumn<int>("numberOfVolumes");
0105     QTest::addColumn<QStringList>("compressionMethods");
0106     // Index of some entry to be tested.
0107     QTest::addColumn<int>("someEntryIndex");
0108     // Entry metadata.
0109     QTest::addColumn<QString>("expectedName");
0110     QTest::addColumn<bool>("isDirectory");
0111     QTest::addColumn<bool>("isPasswordProtected");
0112     QTest::addColumn<QString>("symlinkTarget");
0113     QTest::addColumn<qulonglong>("expectedSize");
0114     QTest::addColumn<qulonglong>("expectedCompressedSize");
0115     QTest::addColumn<QDateTime>("expectedTimestamp");
0116 
0117     // Unrar 5 tests
0118 
0119     QTest::newRow("normal-file-unrar5") << QFINDTESTDATA("data/archive-with-symlink-unrar5.txt") << QString() << 8 << false << 0
0120                                         << QStringList{QStringLiteral("RAR4")} << 2 << QStringLiteral("rartest/file2.txt") << false << false << QString()
0121                                         << (qulonglong)14 << (qulonglong)23 << QDateTime::fromString(QStringLiteral("2016-03-21T08:57:36"), Qt::ISODateWithMs);
0122 
0123     QTest::newRow("symlink-unrar5") << QFINDTESTDATA("data/archive-with-symlink-unrar5.txt") << QString() << 8 << false << 0
0124                                     << QStringList{QStringLiteral("RAR4")} << 3 << QStringLiteral("rartest/linktofile1.txt") << false << false
0125                                     << QStringLiteral("file1.txt") << (qulonglong)9 << (qulonglong)9
0126                                     << QDateTime::fromString(QStringLiteral("2016-03-21T08:58:16"), Qt::ISODateWithMs);
0127 
0128     QTest::newRow("encrypted-unrar5") << QFINDTESTDATA("data/archive-encrypted-unrar5.txt") << QString() << 7 << false << 0
0129                                       << QStringList{QStringLiteral("RAR4")} << 2 << QStringLiteral("rartest/file2.txt") << false << true << QString()
0130                                       << (qulonglong)14 << (qulonglong)32 << QDateTime::fromString(QStringLiteral("2016-03-21T17:03:36"), Qt::ISODateWithMs);
0131 
0132     QTest::newRow("recovery-record-unrar5") << QFINDTESTDATA("data/archive-recovery-record-unrar5.txt") << QString() << 3 << false << 0
0133                                             << QStringList{QStringLiteral("RAR4")} << 0 << QStringLiteral("file1.txt") << false << false << QString()
0134                                             << (qulonglong)32 << (qulonglong)33
0135                                             << QDateTime::fromString(QStringLiteral("2015-07-26T19:04:38"), Qt::ISODateWithMs);
0136 
0137     QTest::newRow("corrupt-archive-unrar5") << QFINDTESTDATA("data/archive-corrupt-file-header-unrar5.txt") << QString() << 8 << false << 0
0138                                             << QStringList{QStringLiteral("RAR4")} << 6 << QStringLiteral("dir1/") << true << false << QString()
0139                                             << (qulonglong)0 << (qulonglong)0
0140                                             << QDateTime::fromString(QStringLiteral("2015-05-14T01:45:24"), Qt::ISODateWithMs);
0141 
0142     // 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.
0143     QTest::newRow("multivolume-archive-unrar5") << QFINDTESTDATA("data/archive-multivol-unrar5.txt") << QString() << 6 << true << 5
0144                                                 << QStringList{QStringLiteral("RAR4")} << 5 << QStringLiteral("largefile2") << false << false << QString()
0145                                                 << (qulonglong)2097152 << (qulonglong)11231
0146                                                 << QDateTime::fromString(QStringLiteral("2016-07-17T11:26:19"), Qt::ISODateWithMs);
0147 
0148     QTest::newRow("RAR5-open-with-unrar5") << QFINDTESTDATA("data/archive-RARv5-unrar5.txt") << QString() << 9 << false << 0
0149                                            << QStringList{QStringLiteral("RAR5")} << 4 << QStringLiteral("testarchive/dir1/file1.txt") << false << false
0150                                            << QString() << (qulonglong)32 << (qulonglong)32
0151                                            << QDateTime::fromString(QStringLiteral("2015-05-17T20:41:48"), Qt::ISODateWithMs);
0152 
0153     // Unrar 4 tests
0154 
0155     QTest::newRow("normal-file-unrar4") << QFINDTESTDATA("data/archive-with-symlink-unrar4.txt") << QString() << 8 << false << 0
0156                                         << QStringList{QStringLiteral("RAR4")} << 2 << QStringLiteral("rartest/file2.txt") << false << false << QString()
0157                                         << (qulonglong)14 << (qulonglong)23 << QDateTime::fromString(QStringLiteral("2016-03-21T08:57:00"), Qt::ISODateWithMs);
0158 
0159     QTest::newRow("symlink-unrar4") << QFINDTESTDATA("data/archive-with-symlink-unrar4.txt") << QString() << 8 << false << 0
0160                                     << QStringList{QStringLiteral("RAR4")} << 3 << QStringLiteral("rartest/linktofile1.txt") << false << false
0161                                     << QStringLiteral("file1.txt") << (qulonglong)9 << (qulonglong)9
0162                                     << QDateTime::fromString(QStringLiteral("2016-03-21T08:58:00"), Qt::ISODateWithMs);
0163 
0164     QTest::newRow("encrypted-unrar4") << QFINDTESTDATA("data/archive-encrypted-unrar4.txt") << QString() << 7 << false << 0
0165                                       << QStringList{QStringLiteral("RAR4")} << 2 << QStringLiteral("rartest/file2.txt") << false << true << QString()
0166                                       << (qulonglong)14 << (qulonglong)32 << QDateTime::fromString(QStringLiteral("2016-03-21T17:03:00"), Qt::ISODateWithMs);
0167 
0168     QTest::newRow("recovery-record-unrar4") << QFINDTESTDATA("data/archive-recovery-record-unrar4.txt") << QString() << 3 << false << 0
0169                                             << QStringList{QStringLiteral("RAR4")} << 0 << QStringLiteral("file1.txt") << false << false << QString()
0170                                             << (qulonglong)32 << (qulonglong)33
0171                                             << QDateTime::fromString(QStringLiteral("2015-07-26T19:04:00"), Qt::ISODateWithMs);
0172 
0173     QTest::newRow("corrupt-archive-unrar4") << QFINDTESTDATA("data/archive-corrupt-file-header-unrar4.txt") << QString() << 8 << false << 0
0174                                             << QStringList{QStringLiteral("RAR4")} << 6 << QStringLiteral("dir1/") << true << false << QString()
0175                                             << (qulonglong)0 << (qulonglong)0
0176                                             << QDateTime::fromString(QStringLiteral("2015-05-14T01:45:00"), Qt::ISODateWithMs);
0177 
0178     QTest::newRow("RAR5-open-with-unrar4")
0179         << QFINDTESTDATA("data/archive-RARv5-unrar4.txt")
0180         << QStringLiteral("Your unrar executable is version 4.20, which is too old to handle this archive. Please update to a more recent version.") << 0
0181         << false << 0 << QStringList() << 0 << QString() << true << false << QString() << (qulonglong)0 << (qulonglong)0 << QDateTime::currentDateTime();
0182 
0183     // 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.
0184     QTest::newRow("multivolume-archive-unrar4") << QFINDTESTDATA("data/archive-multivol-unrar4.txt") << QString() << 6 << true << 5
0185                                                 << QStringList{QStringLiteral("RAR4")} << 5 << QStringLiteral("largefile2") << false << false << QString()
0186                                                 << (qulonglong)2097152 << (qulonglong)11231
0187                                                 << QDateTime::fromString(QStringLiteral("2016-07-17T11:26:00"), Qt::ISODateWithMs);
0188 
0189     // Unrar 3 tests
0190 
0191     QTest::newRow("RAR5-open-with-unrar3") << QFINDTESTDATA("data/archive-RARv5-unrar3.txt")
0192                                            << QStringLiteral(
0193                                                   "Unrar reported a non-RAR archive. The installed unrar version (3.71) is old. Try updating your unrar.")
0194                                            << 0 << false << 0 << QStringList() << 0 << QString() << true << false << QString() << (qulonglong)0 << (qulonglong)0
0195                                            << QDateTime::currentDateTime();
0196 
0197     /*
0198      * Check that the plugin will not crash when reading corrupted archives, which
0199      * have lines such as "Unexpected end of archive" or "??? - the file header is
0200      * corrupt" instead of a file name and the header string after it.
0201      *
0202      * See bug 262857 and commit 2042997013432cdc6974f5b26d39893a21e21011.
0203      */
0204     QTest::newRow("corrupt-archive-unrar3") << QFINDTESTDATA("data/archive-corrupt-file-header-unrar3.txt") << QString() << 1 << true << 1
0205                                             << QStringList{QStringLiteral("RAR4")} << 0 << QStringLiteral("some-file.ext") << false << false << QString()
0206                                             << (qulonglong)732522496 << (qulonglong)14851208
0207                                             << QDateTime::fromString(QStringLiteral("2010-10-29T20:47:00"), Qt::ISODateWithMs);
0208 }
0209 
0210 void CliRarTest::testList()
0211 {
0212     qRegisterMetaType<Archive::Entry *>("Archive::Entry*");
0213     CliPlugin *rarPlugin = new CliPlugin(this, {QStringLiteral("dummy.rar"), QVariant::fromValue(m_plugin->metaData())});
0214     QSignalSpy signalSpyEntry(rarPlugin, &CliPlugin::entry);
0215     QSignalSpy signalSpyCompMethod(rarPlugin, &CliPlugin::compressionMethodFound);
0216     QSignalSpy signalSpyError(rarPlugin, &CliPlugin::error);
0217 
0218     QFETCH(QString, outputTextFile);
0219     QFETCH(int, expectedEntriesCount);
0220 
0221     QFile outputText(outputTextFile);
0222     QVERIFY(outputText.open(QIODevice::ReadOnly));
0223 
0224     QTextStream outputStream(&outputText);
0225     while (!outputStream.atEnd()) {
0226         const QString line(outputStream.readLine());
0227         if (!rarPlugin->readListLine(line)) {
0228             break;
0229         }
0230     }
0231 
0232     QFETCH(QString, errorMessage);
0233     if (!errorMessage.isEmpty()) {
0234         QCOMPARE(signalSpyError.count(), 1);
0235         QCOMPARE(signalSpyError.at(0).at(0).toString(), errorMessage);
0236         return;
0237     }
0238 
0239     QCOMPARE(signalSpyEntry.count(), expectedEntriesCount);
0240 
0241     QFETCH(bool, isMultiVolume);
0242     QCOMPARE(rarPlugin->isMultiVolume(), isMultiVolume);
0243 
0244     QFETCH(int, numberOfVolumes);
0245     QCOMPARE(rarPlugin->numberOfVolumes(), numberOfVolumes);
0246 
0247     QVERIFY(signalSpyCompMethod.count() > 0);
0248     QFETCH(QStringList, compressionMethods);
0249     if (!compressionMethods.isEmpty()) {
0250         QCOMPARE(signalSpyCompMethod.at(0).at(0).toStringList(), compressionMethods);
0251     }
0252 
0253     QFETCH(int, someEntryIndex);
0254     QVERIFY(someEntryIndex < signalSpyEntry.count());
0255     Archive::Entry *entry = signalSpyEntry.at(someEntryIndex).at(0).value<Archive::Entry *>();
0256 
0257     QFETCH(QString, expectedName);
0258     QCOMPARE(entry->fullPath(), expectedName);
0259 
0260     QFETCH(bool, isDirectory);
0261     QCOMPARE(entry->isDir(), isDirectory);
0262 
0263     QFETCH(bool, isPasswordProtected);
0264     QCOMPARE(entry->property("isPasswordProtected").toBool(), isPasswordProtected);
0265 
0266     QFETCH(QString, symlinkTarget);
0267     QCOMPARE(entry->property("link").toString(), symlinkTarget);
0268 
0269     QFETCH(qulonglong, expectedSize);
0270     QCOMPARE(entry->property("size").toULongLong(), expectedSize);
0271 
0272     QFETCH(qulonglong, expectedCompressedSize);
0273     QCOMPARE(entry->property("compressedSize").toULongLong(), expectedCompressedSize);
0274 
0275     QFETCH(QDateTime, expectedTimestamp);
0276     QCOMPARE(entry->property("timestamp").toDateTime(), expectedTimestamp);
0277 
0278     rarPlugin->deleteLater();
0279 }
0280 
0281 void CliRarTest::testListArgs_data()
0282 {
0283     QTest::addColumn<QString>("archiveName");
0284     QTest::addColumn<QString>("password");
0285     QTest::addColumn<QStringList>("expectedArgs");
0286 
0287     QTest::newRow("unencrypted") << QStringLiteral("/tmp/foo.rar") << QString()
0288                                  << QStringList{QStringLiteral("vt"), QStringLiteral("-v"), QStringLiteral("/tmp/foo.rar")};
0289 
0290     QTest::newRow("header-encrypted") << QStringLiteral("/tmp/foo.rar") << QStringLiteral("1234")
0291                                       << QStringList{QStringLiteral("vt"), QStringLiteral("-v"), QStringLiteral("-p1234"), QStringLiteral("/tmp/foo.rar")};
0292 }
0293 
0294 void CliRarTest::testListArgs()
0295 {
0296     if (!m_plugin->isValid()) {
0297         QSKIP("clirar plugin not available. Skipping test.", SkipSingle);
0298     }
0299 
0300     QFETCH(QString, archiveName);
0301     CliPlugin *plugin = new CliPlugin(this, {QVariant(archiveName), QVariant::fromValue(m_plugin->metaData())});
0302     QVERIFY(plugin);
0303 
0304     QFETCH(QString, password);
0305     const auto replacedArgs = plugin->cliProperties()->listArgs(archiveName, password);
0306 
0307     QFETCH(QStringList, expectedArgs);
0308     QCOMPARE(replacedArgs, expectedArgs);
0309 
0310     plugin->deleteLater();
0311 }
0312 
0313 void CliRarTest::testAddArgs_data()
0314 {
0315     QTest::addColumn<QString>("archiveName");
0316     QTest::addColumn<QString>("password");
0317     QTest::addColumn<bool>("encryptHeader");
0318     QTest::addColumn<int>("compressionLevel");
0319     QTest::addColumn<QString>("compressionMethod");
0320     QTest::addColumn<ulong>("volumeSize");
0321     QTest::addColumn<QStringList>("expectedArgs");
0322 
0323     QTest::newRow("unencrypted") << QStringLiteral("/tmp/foo.rar") << QString() << false << 3 << QStringLiteral("RAR4") << 0UL
0324                                  << QStringList{QStringLiteral("a"), QStringLiteral("-m3"), QStringLiteral("-ma4"), QStringLiteral("/tmp/foo.rar")};
0325 
0326     QTest::newRow("encrypted") << QStringLiteral("/tmp/foo.rar") << QStringLiteral("1234") << false << 3 << QString() << 0UL
0327                                << QStringList{QStringLiteral("a"), QStringLiteral("-p1234"), QStringLiteral("-m3"), QStringLiteral("/tmp/foo.rar")};
0328 
0329     QTest::newRow("header-encrypted") << QStringLiteral("/tmp/foo.rar") << QStringLiteral("1234") << true << 3 << QString() << 0UL
0330                                       << QStringList{QStringLiteral("a"), QStringLiteral("-hp1234"), QStringLiteral("-m3"), QStringLiteral("/tmp/foo.rar")};
0331 
0332     QTest::newRow("multi-volume") << QStringLiteral("/tmp/foo.rar") << QString() << false << 3 << QString() << 2500UL
0333                                   << QStringList{QStringLiteral("a"), QStringLiteral("-m3"), QStringLiteral("-v2500k"), QStringLiteral("/tmp/foo.rar")};
0334     QTest::newRow("comp-method-RAR5") << QStringLiteral("/tmp/foo.rar") << QString() << false << 3 << QStringLiteral("RAR5") << 0UL
0335                                       << QStringList{QStringLiteral("a"), QStringLiteral("-m3"), QStringLiteral("-ma5"), QStringLiteral("/tmp/foo.rar")};
0336 }
0337 
0338 void CliRarTest::testAddArgs()
0339 {
0340     if (!m_plugin->isValid()) {
0341         QSKIP("clirar plugin not available. Skipping test.", SkipSingle);
0342     }
0343 
0344     QFETCH(QString, archiveName);
0345     CliPlugin *plugin = new CliPlugin(this, {QVariant(archiveName), QVariant::fromValue(m_plugin->metaData())});
0346     QVERIFY(plugin);
0347 
0348     QFETCH(QString, password);
0349     QFETCH(bool, encryptHeader);
0350     QFETCH(int, compressionLevel);
0351     QFETCH(QString, compressionMethod);
0352     QFETCH(ulong, volumeSize);
0353 
0354     const auto replacedArgs =
0355         plugin->cliProperties()->addArgs(archiveName, {}, password, encryptHeader, compressionLevel, compressionMethod, QString(), volumeSize);
0356 
0357     QFETCH(QStringList, expectedArgs);
0358     QCOMPARE(replacedArgs, expectedArgs);
0359 
0360     plugin->deleteLater();
0361 }
0362 
0363 void CliRarTest::testExtractArgs_data()
0364 {
0365     QTest::addColumn<QString>("archiveName");
0366     QTest::addColumn<QVector<Archive::Entry *>>("files");
0367     QTest::addColumn<bool>("preservePaths");
0368     QTest::addColumn<QString>("password");
0369     QTest::addColumn<QStringList>("expectedArgs");
0370 
0371     QTest::newRow("preserve paths, encrypted") << QStringLiteral("/tmp/foo.rar")
0372                                                << (QVector<Archive::Entry *>{
0373                                                       new Archive::Entry(this, QStringLiteral("aDir/textfile2.txt"), QStringLiteral("aDir")),
0374                                                       new Archive::Entry(this, QStringLiteral("c.txt"), QString()),
0375                                                   })
0376                                                << true << QStringLiteral("1234")
0377                                                << QStringList{
0378                                                       QStringLiteral("x"),
0379                                                       QStringLiteral("-kb"),
0380                                                       QStringLiteral("-p-"),
0381                                                       QStringLiteral("-p1234"),
0382                                                       QStringLiteral("/tmp/foo.rar"),
0383                                                       QStringLiteral("aDir/textfile2.txt"),
0384                                                       QStringLiteral("c.txt"),
0385                                                   };
0386 
0387     QTest::newRow("preserve paths, unencrypted") << QStringLiteral("/tmp/foo.rar")
0388                                                  << (QVector<Archive::Entry *>{
0389                                                         new Archive::Entry(this, QStringLiteral("aDir/textfile2.txt"), QStringLiteral("aDir")),
0390                                                         new Archive::Entry(this, QStringLiteral("c.txt"), QString()),
0391                                                     })
0392                                                  << true << QString()
0393                                                  << QStringList{
0394                                                         QStringLiteral("x"),
0395                                                         QStringLiteral("-kb"),
0396                                                         QStringLiteral("-p-"),
0397                                                         QStringLiteral("/tmp/foo.rar"),
0398                                                         QStringLiteral("aDir/textfile2.txt"),
0399                                                         QStringLiteral("c.txt"),
0400                                                     };
0401 
0402     QTest::newRow("without paths, encrypted") << QStringLiteral("/tmp/foo.rar")
0403                                               << (QVector<Archive::Entry *>{
0404                                                      new Archive::Entry(this, QStringLiteral("aDir/textfile2.txt"), QStringLiteral("aDir")),
0405                                                      new Archive::Entry(this, QStringLiteral("c.txt"), QString()),
0406                                                  })
0407                                               << false << QStringLiteral("1234")
0408                                               << QStringList{
0409                                                      QStringLiteral("e"),
0410                                                      QStringLiteral("-kb"),
0411                                                      QStringLiteral("-p-"),
0412                                                      QStringLiteral("-p1234"),
0413                                                      QStringLiteral("/tmp/foo.rar"),
0414                                                      QStringLiteral("aDir/textfile2.txt"),
0415                                                      QStringLiteral("c.txt"),
0416                                                  };
0417 
0418     QTest::newRow("without paths, unencrypted") << QStringLiteral("/tmp/foo.rar")
0419                                                 << (QVector<Archive::Entry *>{
0420                                                        new Archive::Entry(this, QStringLiteral("aDir/textfile2.txt"), QStringLiteral("aDir")),
0421                                                        new Archive::Entry(this, QStringLiteral("c.txt"), QString()),
0422                                                    })
0423                                                 << false << QString()
0424                                                 << QStringList{
0425                                                        QStringLiteral("e"),
0426                                                        QStringLiteral("-kb"),
0427                                                        QStringLiteral("-p-"),
0428                                                        QStringLiteral("/tmp/foo.rar"),
0429                                                        QStringLiteral("aDir/textfile2.txt"),
0430                                                        QStringLiteral("c.txt"),
0431                                                    };
0432 }
0433 
0434 void CliRarTest::testExtractArgs()
0435 {
0436     if (!m_plugin->isValid()) {
0437         QSKIP("clirar plugin not available. Skipping test.", SkipSingle);
0438     }
0439 
0440     QFETCH(QString, archiveName);
0441     CliPlugin *plugin = new CliPlugin(this, {QVariant(archiveName), QVariant::fromValue(m_plugin->metaData())});
0442     QVERIFY(plugin);
0443 
0444     QFETCH(QVector<Archive::Entry *>, files);
0445     QStringList filesList;
0446     for (const Archive::Entry *e : std::as_const(files)) {
0447         filesList << e->fullPath(NoTrailingSlash);
0448     }
0449 
0450     QFETCH(bool, preservePaths);
0451     QFETCH(QString, password);
0452 
0453     const auto replacedArgs = plugin->cliProperties()->extractArgs(archiveName, filesList, preservePaths, password);
0454 
0455     QFETCH(QStringList, expectedArgs);
0456     QCOMPARE(replacedArgs, expectedArgs);
0457 
0458     plugin->deleteLater();
0459 }
0460 
0461 #include "moc_clirartest.cpp"