diff --git a/autotests/plugins/CMakeLists.txt b/autotests/plugins/CMakeLists.txt index ee10686d..58cdb32f 100644 --- a/autotests/plugins/CMakeLists.txt +++ b/autotests/plugins/CMakeLists.txt @@ -1,4 +1,5 @@ add_subdirectory(clizipplugin) add_subdirectory(cli7zplugin) add_subdirectory(clirarplugin) add_subdirectory(cliunarchiverplugin) +add_subdirectory(libarchiveplugin) diff --git a/autotests/plugins/cli7zplugin/cli7ztest.cpp b/autotests/plugins/cli7zplugin/cli7ztest.cpp index bd48f3c1..91d07ffa 100644 --- a/autotests/plugins/cli7zplugin/cli7ztest.cpp +++ b/autotests/plugins/cli7zplugin/cli7ztest.cpp @@ -1,435 +1,435 @@ /* * Copyright (c) 2016 Ragnar Thomsen * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "cli7ztest.h" #include #include #include #include #include #include QTEST_GUILESS_MAIN(Cli7zTest) using namespace Kerfuffle; void Cli7zTest::initTestCase() { m_plugin = new Plugin(this); foreach (Plugin *plugin, m_pluginManger.availablePlugins()) { if (plugin->metaData().pluginId() == QStringLiteral("kerfuffle_cli7z")) { m_plugin = plugin; return; } } } void Cli7zTest::testArchive_data() { QTest::addColumn("archivePath"); QTest::addColumn("expectedFileName"); QTest::addColumn("isReadOnly"); QTest::addColumn("isSingleFolder"); QTest::addColumn("expectedEncryptionType"); QTest::addColumn("expectedSubfolderName"); QString archivePath = QFINDTESTDATA("data/one_toplevel_folder.7z"); QTest::newRow("archive with one top-level folder") << archivePath << QFileInfo(archivePath).fileName() << false << true << Archive::Unencrypted << QStringLiteral("A"); } void Cli7zTest::testArchive() { if (!m_plugin->isValid()) { QSKIP("cli7z plugin not available. Skipping test.", SkipSingle); } QFETCH(QString, archivePath); Archive *archive = Archive::create(archivePath, m_plugin, this); QVERIFY(archive); if (!archive->isValid()) { QSKIP("Could not load the cli7z plugin. Skipping test.", SkipSingle); } QFETCH(QString, expectedFileName); QCOMPARE(QFileInfo(archive->fileName()).fileName(), expectedFileName); QFETCH(bool, isReadOnly); QCOMPARE(archive->isReadOnly(), isReadOnly); QFETCH(bool, isSingleFolder); QCOMPARE(archive->isSingleFolderArchive(), isSingleFolder); QFETCH(Archive::EncryptionType, expectedEncryptionType); QCOMPARE(archive->encryptionType(), expectedEncryptionType); QFETCH(QString, expectedSubfolderName); QCOMPARE(archive->subfolderName(), expectedSubfolderName); } void Cli7zTest::testList_data() { QTest::addColumn("outputTextFile"); QTest::addColumn("expectedEntriesCount"); // Index of some entry to be tested. QTest::addColumn("someEntryIndex"); // Entry metadata. QTest::addColumn("expectedName"); QTest::addColumn("isDirectory"); QTest::addColumn("isPasswordProtected"); QTest::addColumn("expectedSize"); QTest::addColumn("expectedTimestamp"); // p7zip version 15.14 tests QTest::newRow("normal-file-1514") << QFINDTESTDATA("data/archive-with-symlink-1514.txt") << 10 << 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 << 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 << 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 << 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 << 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 << 3 << QStringLiteral("testarchive/dir1/file1.txt") << false << true << (qulonglong) 32 << QStringLiteral("2015-05-17T19:41:48"); } void Cli7zTest::testList() { qRegisterMetaType("Archive::Entry*"); CliPlugin *plugin = new CliPlugin(this, {QStringLiteral("dummy.7z")}); QSignalSpy signalSpy(plugin, &CliPlugin::entry); QFETCH(QString, outputTextFile); QFETCH(int, expectedEntriesCount); QFile outputText(outputTextFile); QVERIFY(outputText.open(QIODevice::ReadOnly)); QTextStream outputStream(&outputText); while (!outputStream.atEnd()) { const QString line(outputStream.readLine()); QVERIFY(plugin->readListLine(line)); } QCOMPARE(signalSpy.count(), expectedEntriesCount); QFETCH(int, someEntryIndex); QVERIFY(someEntryIndex < signalSpy.count()); Archive::Entry *entry = signalSpy.at(someEntryIndex).at(0).value(); QFETCH(QString, expectedName); QCOMPARE(entry->property("fullPath").toString(), expectedName); QFETCH(bool, isDirectory); QCOMPARE(entry->isDir(), isDirectory); QFETCH(bool, isPasswordProtected); QCOMPARE(entry->property("isPasswordProtected").toBool(), isPasswordProtected); QFETCH(qulonglong, expectedSize); QCOMPARE(entry->property("size").toULongLong(), expectedSize); QFETCH(QString, expectedTimestamp); QCOMPARE(entry->property("timestamp").toString(), expectedTimestamp); plugin->deleteLater(); } void Cli7zTest::testListArgs_data() { QTest::addColumn("archiveName"); QTest::addColumn("password"); QTest::addColumn("expectedArgs"); QTest::newRow("unencrypted") << QStringLiteral("/tmp/foo.7z") << QString() << QStringList { QStringLiteral("l"), QStringLiteral("-slt"), QStringLiteral("/tmp/foo.7z") }; QTest::newRow("header-encrypted") << QStringLiteral("/tmp/foo.7z") << QStringLiteral("1234") << QStringList { QStringLiteral("l"), QStringLiteral("-slt"), QStringLiteral("-p1234"), QStringLiteral("/tmp/foo.7z") }; } void Cli7zTest::testListArgs() { QFETCH(QString, archiveName); CliPlugin *plugin = new CliPlugin(this, {QVariant(archiveName)}); QVERIFY(plugin); const QStringList listArgs = { QStringLiteral("l"), QStringLiteral("-slt"), QStringLiteral("$PasswordSwitch"), QStringLiteral("$Archive") }; QFETCH(QString, password); const auto replacedArgs = plugin->substituteListVariables(listArgs, password); QFETCH(QStringList, expectedArgs); QCOMPARE(replacedArgs, expectedArgs); plugin->deleteLater(); } void Cli7zTest::testAddArgs_data() { QTest::addColumn("archiveName"); QTest::addColumn("password"); QTest::addColumn("encryptHeader"); QTest::addColumn("compressionLevel"); QTest::addColumn("expectedArgs"); QTest::newRow("unencrypted") << QStringLiteral("/tmp/foo.7z") << QString() << false << 5 << QStringList { QStringLiteral("a"), QStringLiteral("/tmp/foo.7z"), QStringLiteral("-mx=5") }; QTest::newRow("encrypted") << QStringLiteral("/tmp/foo.7z") << QStringLiteral("1234") << false << 5 << QStringList { QStringLiteral("a"), QStringLiteral("/tmp/foo.7z"), QStringLiteral("-p1234"), QStringLiteral("-mx=5") }; QTest::newRow("header-encrypted") << QStringLiteral("/tmp/foo.7z") << QStringLiteral("1234") << true << 5 << QStringList { QStringLiteral("a"), QStringLiteral("/tmp/foo.7z"), QStringLiteral("-p1234"), QStringLiteral("-mhe=on"), QStringLiteral("-mx=5") }; } void Cli7zTest::testAddArgs() { QFETCH(QString, archiveName); CliPlugin *plugin = new CliPlugin(this, {QVariant(archiveName)}); QVERIFY(plugin); const QStringList addArgs = { QStringLiteral("a"), QStringLiteral("$Archive"), QStringLiteral("$PasswordSwitch"), QStringLiteral("$CompressionLevelSwitch"), QStringLiteral("$Files") }; QFETCH(QString, password); QFETCH(bool, encryptHeader); QFETCH(int, compressionLevel); QStringList replacedArgs = plugin->substituteAddVariables(addArgs, {}, password, encryptHeader, compressionLevel); QFETCH(QStringList, expectedArgs); QCOMPARE(replacedArgs, expectedArgs); plugin->deleteLater(); } void Cli7zTest::testExtractArgs_data() { QTest::addColumn("archiveName"); QTest::addColumn>("files"); QTest::addColumn("preservePaths"); QTest::addColumn("password"); QTest::addColumn("expectedArgs"); QTest::newRow("preserve paths, encrypted") << QStringLiteral("/tmp/foo.7z") << QList { new Archive::Entry(this, QStringLiteral("aDir/b.txt"), QStringLiteral("aDir")), new Archive::Entry(this, QStringLiteral("c.txt"), QString()) } << true << QStringLiteral("1234") << QStringList { QStringLiteral("x"), QStringLiteral("-p1234"), QStringLiteral("/tmp/foo.7z"), QStringLiteral("aDir/b.txt"), QStringLiteral("c.txt"), }; QTest::newRow("preserve paths, unencrypted") << QStringLiteral("/tmp/foo.7z") << QList { new Archive::Entry(this, QStringLiteral("aDir/b.txt"), QStringLiteral("aDir")), new Archive::Entry(this, QStringLiteral("c.txt"), QString()) } << true << QString() << QStringList { QStringLiteral("x"), QStringLiteral("/tmp/foo.7z"), QStringLiteral("aDir/b.txt"), QStringLiteral("c.txt"), }; QTest::newRow("without paths, encrypted") << QStringLiteral("/tmp/foo.7z") << QList { new Archive::Entry(this, QStringLiteral("aDir/b.txt"), QStringLiteral("aDir")), new Archive::Entry(this, QStringLiteral("c.txt"), QString()) } << false << QStringLiteral("1234") << QStringList { QStringLiteral("e"), QStringLiteral("-p1234"), QStringLiteral("/tmp/foo.7z"), QStringLiteral("aDir/b.txt"), QStringLiteral("c.txt"), }; QTest::newRow("without paths, unencrypted") << QStringLiteral("/tmp/foo.7z") << QList { new Archive::Entry(this, QStringLiteral("aDir/b.txt"), QStringLiteral("aDir")), new Archive::Entry(this, QStringLiteral("c.txt"), QString()) } << false << QString() << QStringList { QStringLiteral("e"), QStringLiteral("/tmp/foo.7z"), QStringLiteral("aDir/b.txt"), QStringLiteral("c.txt"), }; } void Cli7zTest::testExtractArgs() { QFETCH(QString, archiveName); CliPlugin *plugin = new CliPlugin(this, {QVariant(archiveName)}); QVERIFY(plugin); const QStringList extractArgs = { QStringLiteral("$PreservePathSwitch"), QStringLiteral("$PasswordSwitch"), QStringLiteral("$Archive"), QStringLiteral("$Files") }; QFETCH(QList, files); QFETCH(bool, preservePaths); QFETCH(QString, password); QStringList replacedArgs = plugin->substituteCopyVariables(extractArgs, files, preservePaths, password); QVERIFY(replacedArgs.size() >= extractArgs.size()); QFETCH(QStringList, expectedArgs); QCOMPARE(replacedArgs, expectedArgs); plugin->deleteLater(); } void Cli7zTest::testAdd_data() { QTest::addColumn("archiveName"); QTest::addColumn>("files"); QTest::addColumn("destination"); QTest::newRow("without destination") << QStringLiteral("test.7z") << QList { new Archive::Entry(this, QStringLiteral("a.txt")), new Archive::Entry(this, QStringLiteral("b.txt")), } << new Archive::Entry(this); QTest::newRow("with destination, files") << QStringLiteral("test.7z") << QList { new Archive::Entry(this, QStringLiteral("a.txt")), new Archive::Entry(this, QStringLiteral("b.txt")), } << new Archive::Entry(this, QStringLiteral("dir/")); QTest::newRow("with destination, directory") << QStringLiteral("test.7z") << QList { new Archive::Entry(this, QStringLiteral("dir/")), } << new Archive::Entry(this, QStringLiteral("dir/")); } void Cli7zTest::testAdd() { QTemporaryDir temporaryDir; QFETCH(QString, archiveName); CliPlugin *plugin = new CliPlugin(this, {QVariant(temporaryDir.path() + QLatin1Char('/') + archiveName)}); QVERIFY(plugin); QFETCH(QList, files); QFETCH(Archive::Entry*, destination); CompressionOptions options = CompressionOptions(); options.insert(QStringLiteral("GlobalWorkDir"), QFINDTESTDATA("data")); AddJob *addJob = new AddJob(files, destination, options, plugin); TestHelper::startAndWaitForResult(addJob); - delete addJob; + addJob->deleteLater(); QList resultedEntries = TestHelper::getEntryList(plugin); TestHelper::verifyEntriesWithDestination(files, destination, resultedEntries); plugin->deleteLater(); } diff --git a/autotests/plugins/clirarplugin/CMakeLists.txt b/autotests/plugins/clirarplugin/CMakeLists.txt index b2ec1c4d..afdf46db 100644 --- a/autotests/plugins/clirarplugin/CMakeLists.txt +++ b/autotests/plugins/clirarplugin/CMakeLists.txt @@ -1,14 +1,14 @@ set(RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_SOURCE_DIR}/plugins/clirarplugin/) file(COPY ${CMAKE_BINARY_DIR}/plugins/clirarplugin/kerfuffle_clirar.json DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) ecm_add_test( clirartest.cpp ${CMAKE_SOURCE_DIR}/plugins/clirarplugin/cliplugin.cpp ${CMAKE_BINARY_DIR}/plugins/clirarplugin/ark_debug.cpp - LINK_LIBRARIES kerfuffle Qt5::Test + LINK_LIBRARIES testhelper kerfuffle Qt5::Test TEST_NAME clirartest NAME_PREFIX plugins-) diff --git a/autotests/plugins/clirarplugin/data/a.txt b/autotests/plugins/clirarplugin/data/a.txt new file mode 100644 index 00000000..b72e979f --- /dev/null +++ b/autotests/plugins/clirarplugin/data/a.txt @@ -0,0 +1 @@ +A simple text file. diff --git a/autotests/plugins/clirarplugin/data/b.txt b/autotests/plugins/clirarplugin/data/b.txt new file mode 100644 index 00000000..b72e979f --- /dev/null +++ b/autotests/plugins/clirarplugin/data/b.txt @@ -0,0 +1 @@ +A simple text file. diff --git a/autotests/plugins/clirarplugin/data/dir/a.txt b/autotests/plugins/clirarplugin/data/dir/a.txt new file mode 100644 index 00000000..b72e979f --- /dev/null +++ b/autotests/plugins/clirarplugin/data/dir/a.txt @@ -0,0 +1 @@ +A simple text file. diff --git a/autotests/plugins/clirarplugin/data/dir/b.txt b/autotests/plugins/clirarplugin/data/dir/b.txt new file mode 100644 index 00000000..b72e979f --- /dev/null +++ b/autotests/plugins/clirarplugin/data/dir/b.txt @@ -0,0 +1 @@ +A simple text file. diff --git a/autotests/plugins/cliunarchiverplugin/CMakeLists.txt b/autotests/plugins/cliunarchiverplugin/CMakeLists.txt index c28bba8d..a831936a 100644 --- a/autotests/plugins/cliunarchiverplugin/CMakeLists.txt +++ b/autotests/plugins/cliunarchiverplugin/CMakeLists.txt @@ -1,14 +1,14 @@ set(RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_SOURCE_DIR}/plugins/cliunarchiverplugin/) file(COPY ${CMAKE_BINARY_DIR}/plugins/cliunarchiverplugin/kerfuffle_cliunarchiver.json DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) ecm_add_test( cliunarchivertest.cpp ${CMAKE_SOURCE_DIR}/plugins/cliunarchiverplugin/cliplugin.cpp ${CMAKE_BINARY_DIR}/plugins/cliunarchiverplugin/ark_debug.cpp - LINK_LIBRARIES kerfuffle Qt5::Test + LINK_LIBRARIES testhelper kerfuffle Qt5::Test TEST_NAME cliunarchivertest NAME_PREFIX plugins-) diff --git a/autotests/plugins/clizipplugin/CMakeLists.txt b/autotests/plugins/clizipplugin/CMakeLists.txt index f1a710c6..9efe7bd3 100644 --- a/autotests/plugins/clizipplugin/CMakeLists.txt +++ b/autotests/plugins/clizipplugin/CMakeLists.txt @@ -1,14 +1,14 @@ set(RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_SOURCE_DIR}/plugins/clizipplugin/) file(COPY ${CMAKE_BINARY_DIR}/plugins/clizipplugin/kerfuffle_clizip.json DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) ecm_add_test( cliziptest.cpp ${CMAKE_SOURCE_DIR}/plugins/clizipplugin/cliplugin.cpp ${CMAKE_BINARY_DIR}/plugins/clizipplugin/ark_debug.cpp - LINK_LIBRARIES kerfuffle Qt5::Test + LINK_LIBRARIES testhelper kerfuffle Qt5::Test TEST_NAME cliziptest NAME_PREFIX plugins-) diff --git a/autotests/plugins/clizipplugin/data/a.txt b/autotests/plugins/clizipplugin/data/a.txt new file mode 100644 index 00000000..b72e979f --- /dev/null +++ b/autotests/plugins/clizipplugin/data/a.txt @@ -0,0 +1 @@ +A simple text file. diff --git a/autotests/plugins/clizipplugin/data/b.txt b/autotests/plugins/clizipplugin/data/b.txt new file mode 100644 index 00000000..b72e979f --- /dev/null +++ b/autotests/plugins/clizipplugin/data/b.txt @@ -0,0 +1 @@ +A simple text file. diff --git a/autotests/plugins/clizipplugin/data/dir/a.txt b/autotests/plugins/clizipplugin/data/dir/a.txt new file mode 100644 index 00000000..b72e979f --- /dev/null +++ b/autotests/plugins/clizipplugin/data/dir/a.txt @@ -0,0 +1 @@ +A simple text file. diff --git a/autotests/plugins/clizipplugin/data/dir/b.txt b/autotests/plugins/clizipplugin/data/dir/b.txt new file mode 100644 index 00000000..b72e979f --- /dev/null +++ b/autotests/plugins/clizipplugin/data/dir/b.txt @@ -0,0 +1 @@ +A simple text file. diff --git a/autotests/plugins/libarchiveplugin/CMakeLists.txt b/autotests/plugins/libarchiveplugin/CMakeLists.txt new file mode 100644 index 00000000..52955f38 --- /dev/null +++ b/autotests/plugins/libarchiveplugin/CMakeLists.txt @@ -0,0 +1,15 @@ +set(RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + +include_directories(${CMAKE_SOURCE_DIR}/plugins/libarchive/) + +file(COPY ${CMAKE_BINARY_DIR}/plugins/libarchive/kerfuffle_libarchive.json + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + +ecm_add_test( + libarchivetest.cpp + ${CMAKE_SOURCE_DIR}/plugins/libarchive/libarchiveplugin.cpp + ${CMAKE_SOURCE_DIR}/plugins/libarchive/readwritelibarchiveplugin.cpp + ${CMAKE_BINARY_DIR}/plugins/libarchive/ark_debug.cpp + LINK_LIBRARIES testhelper ${LibArchive_LIBRARIES} kerfuffle Qt5::Test + TEST_NAME libarchivetest + NAME_PREFIX plugins-) diff --git a/autotests/plugins/libarchiveplugin/data/a.txt b/autotests/plugins/libarchiveplugin/data/a.txt new file mode 100644 index 00000000..b72e979f --- /dev/null +++ b/autotests/plugins/libarchiveplugin/data/a.txt @@ -0,0 +1 @@ +A simple text file. diff --git a/autotests/plugins/libarchiveplugin/data/b.txt b/autotests/plugins/libarchiveplugin/data/b.txt new file mode 100644 index 00000000..b72e979f --- /dev/null +++ b/autotests/plugins/libarchiveplugin/data/b.txt @@ -0,0 +1 @@ +A simple text file. diff --git a/autotests/plugins/libarchiveplugin/data/dir/a.txt b/autotests/plugins/libarchiveplugin/data/dir/a.txt new file mode 100644 index 00000000..b72e979f --- /dev/null +++ b/autotests/plugins/libarchiveplugin/data/dir/a.txt @@ -0,0 +1 @@ +A simple text file. diff --git a/autotests/plugins/libarchiveplugin/data/dir/b.txt b/autotests/plugins/libarchiveplugin/data/dir/b.txt new file mode 100644 index 00000000..b72e979f --- /dev/null +++ b/autotests/plugins/libarchiveplugin/data/dir/b.txt @@ -0,0 +1 @@ +A simple text file. diff --git a/autotests/plugins/libarchiveplugin/libarchivetest.cpp b/autotests/plugins/libarchiveplugin/libarchivetest.cpp new file mode 100644 index 00000000..e2c1716e --- /dev/null +++ b/autotests/plugins/libarchiveplugin/libarchivetest.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2016 Elvis Angelaccio + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "libarchivetest.h" + +#include + +#include + +QTEST_GUILESS_MAIN(LibarchiveTest) + +using namespace Kerfuffle; + +void LibarchiveTest::initTestCase() +{ + m_plugin = new Plugin(this); + foreach (Plugin *plugin, m_pluginManger.availablePlugins()) { + if (plugin->metaData().pluginId() == QStringLiteral("kerfuffle_cli7z")) { + m_plugin = plugin; + return; + } + } +} + +void LibarchiveTest::testAdd_data() +{ + QTest::addColumn("archiveName"); + QTest::addColumn>("files"); + QTest::addColumn("destination"); + + QTest::newRow("without destination") + << QStringLiteral("test.7z") + << QList { + new Archive::Entry(this, QStringLiteral("a.txt")), + new Archive::Entry(this, QStringLiteral("b.txt")), + } + << new Archive::Entry(this); + + QTest::newRow("with destination, files") + << QStringLiteral("test.7z") + << QList { + new Archive::Entry(this, QStringLiteral("a.txt")), + new Archive::Entry(this, QStringLiteral("b.txt")), + } + << new Archive::Entry(this, QStringLiteral("dir/")); + + QTest::newRow("with destination, directory") + << QStringLiteral("test.7z") + << QList { + new Archive::Entry(this, QStringLiteral("dir/")), + } + << new Archive::Entry(this, QStringLiteral("dir/")); +} + +void LibarchiveTest::testAdd() +{ + QTemporaryDir temporaryDir; + + QFETCH(QString, archiveName); + ReadWriteLibarchivePlugin *plugin = new ReadWriteLibarchivePlugin(this, {QVariant(temporaryDir.path() + QLatin1Char('/') + archiveName)}); + QVERIFY(plugin); + + QFETCH(QList, files); + QFETCH(Archive::Entry*, destination); + + CompressionOptions options = CompressionOptions(); + options.insert(QStringLiteral("GlobalWorkDir"), QFINDTESTDATA("data")); + AddJob *addJob = new AddJob(files, destination, options, plugin); + TestHelper::startAndWaitForResult(addJob); + addJob->deleteLater(); + + QList resultedEntries = TestHelper::getEntryList(plugin); + TestHelper::verifyEntriesWithDestination(files, destination, resultedEntries); + + plugin->deleteLater(); +} diff --git a/autotests/plugins/libarchiveplugin/libarchivetest.h b/autotests/plugins/libarchiveplugin/libarchivetest.h new file mode 100644 index 00000000..2ae0f069 --- /dev/null +++ b/autotests/plugins/libarchiveplugin/libarchivetest.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2016 Elvis Angelaccio + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LIBARCHIVETEST_H +#define LIBARCHIVETEST_H + +#include "readwritelibarchiveplugin.h" +#include "pluginmanager.h" +#include "autotests/testhelper/testhelper.h" +#include "kerfuffle/jobs.h" + +using namespace Kerfuffle; + +class LibarchiveTest : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void initTestCase(); + void testAdd_data(); + void testAdd(); + +private: + PluginManager m_pluginManger; + Plugin *m_plugin; +}; + +#endif //LIBARCHIVETEST_H diff --git a/autotests/testhelper/testhelper.cpp b/autotests/testhelper/testhelper.cpp index 5f9048f0..ad85dadd 100644 --- a/autotests/testhelper/testhelper.cpp +++ b/autotests/testhelper/testhelper.cpp @@ -1,42 +1,48 @@ // // Created by mvlabat on 7/21/16. // #include "testhelper.h" QEventLoop TestHelper::m_eventLoop; void TestHelper::startAndWaitForResult(KJob *job) { QObject::connect(job, &KJob::result, &m_eventLoop, &QEventLoop::quit); + //qDebug() << 1; job->start(); + //qDebug() << 1; m_eventLoop.exec(); + //qDebug() << 1; } QList TestHelper::getEntryList(ReadOnlyArchiveInterface *iface) { QList list = QList(); ListJob *listJob = new ListJob(iface); QObject::connect(listJob, &Job::newEntry, [&list](Archive::Entry* entry) { list << entry; }); + //qDebug() << 1; startAndWaitForResult(listJob); - delete listJob; + qDebug() << 1; + listJob->deleteLater(); + //qDebug() << 1; return list; } QStringList TestHelper::getExpectedEntryPaths(const QList &entryList, const Archive::Entry *destination) { QStringList expectedPaths = QStringList(); foreach (const Archive::Entry *entry, entryList) { expectedPaths << destination->property("fullPath").toString() + entry->property("fullPath").toString(); } return expectedPaths; } void TestHelper::verifyEntriesWithDestination(const QList &oldEntries, const Archive::Entry *destination, const QList &newEntries) { QStringList expectedPaths = getExpectedEntryPaths(oldEntries, destination); QStringList actualPaths = ReadOnlyArchiveInterface::entryFullPaths(newEntries); foreach (const QString &path, expectedPaths) { QVERIFY2(actualPaths.contains(path), (QStringLiteral("No ") + path + QStringLiteral(" inside the archive")).toStdString().c_str()); } }