Commit ace27733 authored by Vladyslav Batyrenko's avatar Vladyslav Batyrenko
Browse files

[GSoC] Implement AddTo, Rename, Copy, Move, Paste Actions and Jobs

See:
https://phabricator.kde.org/T917
parent e1bc57bc
sudo: required
language: cpp
compiler:
- gcc
- clang
arch:
packages:
- extra-cmake-modules
- kdoctools
- python
- kparts
- kpty
- libarchive
- hicolor-icon-theme
- p7zip
- unzip
- zip
- lrzip
# for GUI tests
- xorg-server-xvfb
# from AUR:
- rar
- unarchiver
script:
- "cmake -DCMAKE_BUILD_TYPE=Debug -DKDE_INSTALL_LIBDIR=lib -DKDE_INSTALL_USE_QT_SYS_PATHS=ON -DCMAKE_INSTALL_PREFIX=/usr ."
- "make"
- "sudo make install"
# run the tests using the xvfb-run wrapper
- "xvfb-run --auto-servernum ctest --output-on-failure"
script:
- "curl -s https://raw.githubusercontent.com/mikkeloscar/arch-travis/master/arch-travis.sh | bash"
......@@ -92,7 +92,7 @@ void BatchExtract::addExtraction(Kerfuffle::Archive* archive)
Kerfuffle::ExtractionOptions options;
options[QStringLiteral("PreservePaths")] = preservePaths();
Kerfuffle::ExtractJob *job = archive->copyFiles(QList<Kerfuffle::Archive::Entry*>(), destination, options);
Kerfuffle::ExtractJob *job = archive->extractFiles(QList<Kerfuffle::Archive::Entry*>(), destination, options);
qCDebug(ARK) << QString(QStringLiteral("Registering job from archive %1, to %2, preservePaths %3")).arg(archive->fileName(), destination, QString::number(preservePaths()));
......
include(ECMAddTests)
add_subdirectory(testhelper)
add_subdirectory(kerfuffle)
add_subdirectory(plugins)
......@@ -9,11 +9,19 @@ target_link_libraries(jsoninterface kerfuffle)
ecm_add_tests(
addtoarchivetest.cpp
archivetest.cpp
extracttest.cpp
addtest.cpp
movetest.cpp
copytest.cpp
createdialogtest.cpp
metadatatest.cpp
mimetypetest.cpp
LINK_LIBRARIES kerfuffle Qt5::Test
LINK_LIBRARIES testhelper kerfuffle Qt5::Test
NAME_PREFIX kerfuffle-)
ecm_add_test(
adddialogtest.cpp
LINK_LIBRARIES kerfuffle Qt5::Test KF5::KIOFileWidgets
NAME_PREFIX kerfuffle-)
ecm_add_tests(
......
/*
* Copyright (c) 2016 Ragnar Thomsen <rthomsen6@gmail.com>
*
* 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 "adddialog.h"
#include "archiveformat.h"
#include "pluginmanager.h"
#include <KCollapsibleGroupBox>
#include <QCheckBox>
#include <QComboBox>
#include <QLineEdit>
#include <QMimeDatabase>
#include <QTest>
using namespace Kerfuffle;
class AddDialogTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testBasicWidgets_data();
void testBasicWidgets();
private:
PluginManager m_pluginManager;
};
void AddDialogTest::testBasicWidgets_data()
{
QTest::addColumn<QString>("mimeType");
QTest::addColumn<bool>("supportsCompLevel");
QTest::addColumn<int>("initialCompLevel");
QTest::addColumn<int>("changeToCompLevel");
QTest::newRow("tar") << QStringLiteral("application/x-tar") << false << -1 << -1;
QTest::newRow("targzip") << QStringLiteral("application/x-compressed-tar") << true << 3 << 7;
QTest::newRow("tarbzip") << QStringLiteral("application/x-bzip-compressed-tar") << true << 3 << 7;
QTest::newRow("tarZ") << QStringLiteral("application/x-tarz") << false << -1 << -1;
QTest::newRow("tarxz") << QStringLiteral("application/x-xz-compressed-tar") << true << 3 << 7;
QTest::newRow("tarlzma") << QStringLiteral("application/x-lzma-compressed-tar") << true << 3 << 7;
QTest::newRow("tarlzop") << QStringLiteral("application/x-tzo") << true << 3 << 7;
QTest::newRow("tarlzip") << QStringLiteral("application/x-lzip-compressed-tar") << true << 3 << 7;
const auto writeMimeTypes = m_pluginManager.supportedWriteMimeTypes();
if (writeMimeTypes.contains(QStringLiteral("application/zip"))) {
QTest::newRow("zip") << QStringLiteral("application/zip") << true << 3 << 7;
} else {
qDebug() << "zip format not available, skipping test.";
}
if (writeMimeTypes.contains(QStringLiteral("application/x-7z-compressed"))) {
QTest::newRow("7z") << QStringLiteral("application/x-7z-compressed") << true << 3 << 7;
} else {
qDebug() << "7z format not available, skipping test.";
}
if (writeMimeTypes.contains(QStringLiteral("application/x-rar"))) {
QTest::newRow("rar") << QStringLiteral("application/x-rar") << true << 2 << 5;
} else {
qDebug() << "rar format not available, skipping test.";
}
if (writeMimeTypes.contains(QStringLiteral("application/x-lrzip-compressed-tar"))) {
QTest::newRow("tarlrzip") << QStringLiteral("application/x-lrzip-compressed-tar") << true << 3 << 7;
} else {
qDebug() << "tar.lrzip format not available, skipping test.";
}
}
void AddDialogTest::testBasicWidgets()
{
QFETCH(QString, mimeType);
const QMimeType mime = QMimeDatabase().mimeTypeForName(mimeType);
QFETCH(bool, supportsCompLevel);
QFETCH(int, initialCompLevel);
QFETCH(int, changeToCompLevel);
AddDialog *dialog = new AddDialog(Q_NULLPTR, QString(), QUrl(), mime);
dialog->slotOpenOptions();
auto collapsibleCompression = dialog->optionsDialog->findChild<KCollapsibleGroupBox*>(QStringLiteral("collapsibleCompression"));
QVERIFY(collapsibleCompression);
if (supportsCompLevel) {
// Test that collapsiblegroupbox is enabled for mimetypes that support compression levels.
QVERIFY(collapsibleCompression->isEnabled());
auto compLevelSlider = dialog->optionsDialog->findChild<QSlider*>(QStringLiteral("compLevelSlider"));
QVERIFY(compLevelSlider);
const KPluginMetaData metadata = PluginManager().preferredPluginFor(mime)->metaData();
const ArchiveFormat archiveFormat = ArchiveFormat::fromMetadata(mime, metadata);
QVERIFY(archiveFormat.isValid());
// Test that min/max of slider are correct.
QCOMPARE(compLevelSlider->minimum(), archiveFormat.minCompressionLevel());
QCOMPARE(compLevelSlider->maximum(), archiveFormat.maxCompressionLevel());
// Test that the slider is set to default compression level.
QCOMPARE(compLevelSlider->value(), archiveFormat.defaultCompressionLevel());
// Set the compression level slider.
compLevelSlider->setValue(changeToCompLevel);
} else {
// Test that collapsiblegroupbox is disabled for mimetypes that don't support compression levels.
QVERIFY(!collapsibleCompression->isEnabled());
}
dialog->optionsDialog->accept();
dialog->accept();
if (supportsCompLevel) {
// Test that the value set by slider is exported from AddDialog.
QCOMPARE(dialog->compressionOptions()[QStringLiteral("CompressionLevel")].toInt(), changeToCompLevel);
}
// Test that passing a compression level in ctor works.
CompressionOptions opts;
opts[QStringLiteral("CompressionLevel")] = initialCompLevel;
dialog = new AddDialog(Q_NULLPTR, QString(), QUrl(), mime, opts);
dialog->slotOpenOptions();
if (supportsCompLevel) {
auto compLevelSlider = dialog->optionsDialog->findChild<QSlider*>(QStringLiteral("compLevelSlider"));
QVERIFY(compLevelSlider);
// Test that slider is set to the compression level supplied in ctor.
QCOMPARE(compLevelSlider->value(), initialCompLevel);
}
dialog->optionsDialog->accept();
dialog->accept();
}
QTEST_MAIN(AddDialogTest)
#include "adddialogtest.moc"
/*
* Copyright (c) 2016 Vladyslav Batyrenko <mvlabat@gmail.com>
*
* 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 "autotests/testhelper/testhelper.h"
using namespace Kerfuffle;
class AddTest : public QObject
{
Q_OBJECT
private:
void addAllFormatsRows(const QString testName, const QString archiveName, QList<Archive::Entry*> entries, Archive::Entry *destination) {
QStringList formats = QStringList()
<< QStringLiteral("7z")
<< QStringLiteral("rar")
<< QStringLiteral("tar.bz2")
<< QStringLiteral("zip");
foreach (QString format, formats) {
const QString testNameWithFormat = testName + QStringLiteral(" (") + format + QStringLiteral(")");
QTest::newRow(testNameWithFormat.toUtf8())
<< archiveName + QLatin1Char('.') + format
<< entries
<< destination;
}
}
private Q_SLOTS:
void testAdding_data();
void testAdding();
};
QTEST_GUILESS_MAIN(AddTest)
void AddTest::testAdding_data()
{
QTest::addColumn<QString>("archiveName");
QTest::addColumn<QList<Archive::Entry*>>("files");
QTest::addColumn<Archive::Entry*>("destination");
addAllFormatsRows(QStringLiteral("without destination"),
QStringLiteral("test"),
QList<Archive::Entry*> {
new Archive::Entry(this, QStringLiteral("textfile1.txt")),
new Archive::Entry(this, QStringLiteral("textfile2.txt")),
},
new Archive::Entry(this));
addAllFormatsRows(QStringLiteral("with destination, files"),
QStringLiteral("test"),
QList<Archive::Entry*> {
new Archive::Entry(this, QStringLiteral("textfile1.txt")),
new Archive::Entry(this, QStringLiteral("textfile2.txt")),
},
new Archive::Entry(this, QStringLiteral("empty_dir/")));
addAllFormatsRows(QStringLiteral("with destination, directory"),
QStringLiteral("test"),
QList<Archive::Entry*> {
new Archive::Entry(this, QStringLiteral("testdir/")),
},
new Archive::Entry(this, QStringLiteral("empty_dir/")));
addAllFormatsRows(QStringLiteral("without destination, directory 2"),
QStringLiteral("test"),
QList<Archive::Entry*> {
new Archive::Entry(this, QStringLiteral("testdir2/")),
},
new Archive::Entry(this));
addAllFormatsRows(QStringLiteral("with destination, directory 2"),
QStringLiteral("test"),
QList<Archive::Entry*> {
new Archive::Entry(this, QStringLiteral("testdir2/")),
},
new Archive::Entry(this, QStringLiteral("empty_dir/")));
}
void AddTest::testAdding()
{
QTemporaryDir temporaryDir;
QFETCH(QString, archiveName);
const QString archivePath = temporaryDir.path() + QLatin1Char('/') + archiveName;
Q_ASSERT(QFile::copy(QFINDTESTDATA(QStringLiteral("data/") + archiveName), archivePath));
Archive *archive = Archive::create(archivePath, this);
QVERIFY(archive);
if (!archive->isValid()) {
QSKIP("Could not find a plugin to handle the archive. Skipping test.", SkipSingle);
}
QFETCH(QList<Archive::Entry*>, files);
QFETCH(Archive::Entry*, destination);
QList<Archive::Entry*> oldEntries = TestHelper::getEntryList(archive);
CompressionOptions options = CompressionOptions();
options.insert(QStringLiteral("GlobalWorkDir"), QFINDTESTDATA("data"));
AddJob *addJob = archive->addFiles(files, destination, options);
TestHelper::startAndWaitForResult(addJob);
QList<Archive::Entry*> resultedEntries = TestHelper::getEntryList(archive);
TestHelper::verifyAddedEntriesWithDestination(files, destination, oldEntries, resultedEntries);
archive->deleteLater();
}
#include "addtest.moc"
......@@ -40,6 +40,7 @@ private Q_SLOTS:
void testCompressHere_data();
void testCompressHere();
void testCreateEncryptedArchive();
};
void AddToArchiveTest::testCompressHere_data()
......@@ -135,6 +136,23 @@ void AddToArchiveTest::testCompressHere()
QVERIFY(QFile(archive->fileName()).remove());
}
void AddToArchiveTest::testCreateEncryptedArchive()
{
Archive *archive = Archive::create(QStringLiteral("foo.zip"));
QVERIFY(archive);
if (!archive->isValid()) {
QSKIP("Could not find a plugin to handle the archive. Skipping test.", SkipSingle);
}
QCOMPARE(archive->encryptionType(), Archive::Unencrypted);
archive->encrypt(QStringLiteral("1234"), false);
QCOMPARE(archive->encryptionType(), Archive::Encrypted);
archive->deleteLater();
}
QTEST_MAIN(AddToArchiveTest)
#include "addtoarchivetest.moc"
/*
* Copyright (c) 2016 Vladyslav Batyrenko <mvlabat@gmail.com>
*
* 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 "autotests/testhelper/testhelper.h"
using namespace Kerfuffle;
class CopyTest : public QObject
{
Q_OBJECT
private:
void addAllFormatsRows(const QString testName, const QString archiveName, QList<Archive::Entry*> entries, Archive::Entry *destination) {
QStringList formats = QStringList()
<< QStringLiteral("7z")
<< QStringLiteral("rar")
<< QStringLiteral("tar.bz2")
<< QStringLiteral("zip");
foreach (QString format, formats) {
const QString testNameWithFormat = testName + QStringLiteral(" (") + format + QStringLiteral(")");
QTest::newRow(testNameWithFormat.toUtf8())
<< archiveName + QLatin1Char('.') + format
<< entries
<< destination;
}
}
private Q_SLOTS:
void testCopying_data();
void testCopying();
};
QTEST_GUILESS_MAIN(CopyTest)
void CopyTest::testCopying_data()
{
QTest::addColumn<QString>("archiveName");
QTest::addColumn<QList<Archive::Entry*>>("files");
QTest::addColumn<Archive::Entry*>("destination");
addAllFormatsRows(QStringLiteral("copy a single file"),
QStringLiteral("test"),
QList<Archive::Entry*> {
new Archive::Entry(this, QStringLiteral("a.txt")),
},
new Archive::Entry(this, QStringLiteral("empty_dir/")));
addAllFormatsRows(QStringLiteral("copy several files"),
QStringLiteral("test"),
QList<Archive::Entry*> {
new Archive::Entry(this, QStringLiteral("a.txt")),
new Archive::Entry(this, QStringLiteral("b.txt")),
},
new Archive::Entry(this, QStringLiteral("empty_dir/")));
addAllFormatsRows(QStringLiteral("copy a root directory"),
QStringLiteral("test"),
QList<Archive::Entry*> {
new Archive::Entry(this, QStringLiteral("dir1/")),
new Archive::Entry(this, QStringLiteral("dir1/dir/")),
new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
new Archive::Entry(this, QStringLiteral("dir1/a.txt")),
new Archive::Entry(this, QStringLiteral("dir1/b.txt")),
},
new Archive::Entry(this, QStringLiteral("empty_dir/")));
addAllFormatsRows(QStringLiteral("copy a root directory 2"),
QStringLiteral("test"),
QList<Archive::Entry*> {
new Archive::Entry(this, QStringLiteral("dir2/")),
new Archive::Entry(this, QStringLiteral("dir2/dir/")),
new Archive::Entry(this, QStringLiteral("dir2/dir/a.txt")),
new Archive::Entry(this, QStringLiteral("dir2/dir/b.txt")),
},
new Archive::Entry(this, QStringLiteral("empty_dir/")));
addAllFormatsRows(QStringLiteral("copy a root directory 3"),
QStringLiteral("test"),
QList<Archive::Entry*> {
new Archive::Entry(this, QStringLiteral("dir2/")),
new Archive::Entry(this, QStringLiteral("dir2/dir/")),
new Archive::Entry(this, QStringLiteral("dir2/dir/a.txt")),
new Archive::Entry(this, QStringLiteral("dir2/dir/b.txt")),
},
new Archive::Entry(this, QStringLiteral("dir1/")));
addAllFormatsRows(QStringLiteral("copy a directory"),
QStringLiteral("test"),
QList<Archive::Entry*> {
new Archive::Entry(this, QStringLiteral("dir1/dir/")),
new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
},
new Archive::Entry(this, QStringLiteral("empty_dir/")));
addAllFormatsRows(QStringLiteral("copy several directories"),
QStringLiteral("test"),
QList<Archive::Entry*> {
new Archive::Entry(this, QStringLiteral("dir1/")),
new Archive::Entry(this, QStringLiteral("dir1/dir/")),
new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
new Archive::Entry(this, QStringLiteral("dir1/a.txt")),
new Archive::Entry(this, QStringLiteral("dir1/b.txt")),
new Archive::Entry(this, QStringLiteral("dir2/")),
new Archive::Entry(this, QStringLiteral("dir2/dir/")),
new Archive::Entry(this, QStringLiteral("dir2/dir/a.txt")),
new Archive::Entry(this, QStringLiteral("dir2/dir/b.txt")),
},
new Archive::Entry(this, QStringLiteral("empty_dir/")));
addAllFormatsRows(QStringLiteral("copy several entries"),
QStringLiteral("test"),
QList<Archive::Entry*> {
new Archive::Entry(this, QStringLiteral("dir1/dir/")),
new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
new Archive::Entry(this, QStringLiteral("dir1/a.txt")),
new Archive::Entry(this, QStringLiteral("dir1/b.txt")),
},
new Archive::Entry(this, QStringLiteral("empty_dir/")));
addAllFormatsRows(QStringLiteral("copy a directory inside itself"),
QStringLiteral("test"),
QList<Archive::Entry*> {
new Archive::Entry(this, QStringLiteral("dir1/")),
new Archive::Entry(this, QStringLiteral("dir1/dir/")),
new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
new Archive::Entry(this, QStringLiteral("dir1/a.txt")),
new Archive::Entry(this, QStringLiteral("dir1/b.txt")),
},
new Archive::Entry(this, QStringLiteral("dir1/")));
addAllFormatsRows(QStringLiteral("copy a directory to the root"),
QStringLiteral("test"),
QList<Archive::Entry*> {
new Archive::Entry(this, QStringLiteral("dir1/dir/")),
new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
},
new Archive::Entry(this, QStringLiteral("")));
}
void CopyTest::testCopying()