diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index 4635d3bb..2ea27530 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -1,4 +1,5 @@ include(ECMAddTests) +add_subdirectory(testhelper) add_subdirectory(kerfuffle) add_subdirectory(plugins) diff --git a/autotests/testhelper/CMakeLists.txt b/autotests/testhelper/CMakeLists.txt new file mode 100644 index 00000000..76a865d7 --- /dev/null +++ b/autotests/testhelper/CMakeLists.txt @@ -0,0 +1,9 @@ +set(RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + +set(TESTHELPER_SOURCES + testhelper.h + testhelper.cpp + ) + +add_library(testhelper STATIC ${TESTHELPER_SOURCES}) +target_link_libraries(testhelper Qt5::Test kerfuffle) diff --git a/autotests/testhelper/testhelper.cpp b/autotests/testhelper/testhelper.cpp new file mode 100644 index 00000000..5f9048f0 --- /dev/null +++ b/autotests/testhelper/testhelper.cpp @@ -0,0 +1,42 @@ +// +// 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); + job->start(); + m_eventLoop.exec(); +} + +QList TestHelper::getEntryList(ReadOnlyArchiveInterface *iface) +{ + QList list = QList(); + ListJob *listJob = new ListJob(iface); + QObject::connect(listJob, &Job::newEntry, [&list](Archive::Entry* entry) { list << entry; }); + startAndWaitForResult(listJob); + delete listJob; + 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()); + } +} diff --git a/autotests/testhelper/testhelper.h b/autotests/testhelper/testhelper.h new file mode 100644 index 00000000..b7df8d20 --- /dev/null +++ b/autotests/testhelper/testhelper.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2010-2011 Raphael Kubo da Costa + * 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 TESTHELPER_H +#define TESTHELPER_H + +#include "kerfuffle/jobs.h" +#include "kerfuffle/archiveentry.h" + +#include +#include + +using namespace Kerfuffle; + +class TestHelper +{ +public: + + static void startAndWaitForResult(KJob *job); + static QList getEntryList(ReadOnlyArchiveInterface *iface); + static QStringList getExpectedEntryPaths(const QList &entryList, const Archive::Entry* destination); + static void verifyEntriesWithDestination(const QList &oldEntries, const Archive::Entry *destination, const QList &newEntries); + +private: + TestHelper() {} + + static QEventLoop m_eventLoop; +}; + + +#endif //TESTHELPER_H