Commit 8b324a9e authored by David Faure's avatar David Faure
Browse files

Re-enable compilation of the unittest and port it away from KRun

parent 73a66c2b
......@@ -20,7 +20,7 @@ include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDECompilerSettings NO_POLICY_SCOPE)
include(ECMInstallIcons)
include(ECMMarkAsTest)
include(ECMAddTests)
include(GenerateExportHeader)
include(ECMQtDeclareLoggingCategory)
include(ECMSetupVersion)
......
......@@ -22,8 +22,10 @@
#include <KActionCollection>
#include <KActionMenu>
#include <KDialogJobUiDelegate>
#include <KFileItem>
#include <KIconLoader>
#include <KIO/CommandLauncherJob>
#include <KLocalizedString>
#include <KMessageBox>
#include <KPluginFactory>
......@@ -34,7 +36,6 @@
#include <KParts/PartManager>
#include <KParts/ReadOnlyPart>
#include <KParts/SelectorInterface>
#include <KRun>
#include <KToggleAction>
#include <KToolInvocation>
......@@ -144,7 +145,11 @@ void KGetPlugin::showPopup()
void KGetPlugin::slotShowDrop()
{
if (!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kget")) {
KRun::runCommand("kget --showDropTarget --hideMainWindow", "kget", "kget", partWidget(parent()));
const QString command = QStringLiteral("kget --showDropTarget --hideMainWindow");
auto *job = new KIO::CommandLauncherJob(command);
job->setDesktopName(QStringLiteral("org.kde.kget"));
job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, partWidget(parent())));
job->start();
} else {
OrgKdeKgetMainInterface kgetInterface("org.kde.kget", "/KGet", QDBusConnection::sessionBus());
kgetInterface.setDropTargetVisible(m_dropTargetAction->isChecked());
......
......@@ -3,9 +3,7 @@ include_directories(
)
#===========KGet===========
if(CMAKE_BUILD_TYPE MATCHES debugfull)
ENABLE_TESTING()
if(BUILD_TESTING)
add_definitions(-DDO_KGET_TEST)
set(kget_test_transfers_SRCS
testkget.cpp
......@@ -17,12 +15,11 @@ if(CMAKE_BUILD_TYPE MATCHES debugfull)
qt5_add_dbus_interface(kget_test_transfers_SRCS ../dbus/org.kde.kget.transfer.xml transfer_interface)
qt5_add_dbus_interface(kget_test_transfers_SRCS ../dbus/org.kde.kget.verifier.xml verifier_interface)
#REACTIVATE
#add_executable(kget_test_transfers ${kget_test_transfers_SRCS})
#add_test(kget_test_transfers kget_test_transfers)
add_executable(kget_test_transfers ${kget_test_transfers_SRCS})
# TODO enable it in ctest once it's fixed to not popup a "first run" messagebox on first start.
# This probably needs a --testmode command-line argument (and QStandardPaths::setTestModeEnabled(true) on both sides)
#ecm_mark_as_test(kget_test_transfers)
#target_link_libraries(kget_test_transfers Qt5::Test KF5::KIOCore kgetcore)
target_link_libraries(kget_test_transfers Qt5::Test KF5::KIOCore kgetcore)
#===========Verifier===========
......@@ -68,4 +65,4 @@ if(CMAKE_BUILD_TYPE MATCHES debugfull)
target_link_libraries(filedeletertest KF5::KIOCore Qt5::Test)
endif(CMAKE_BUILD_TYPE MATCHES debugfull)
endif()
......@@ -19,14 +19,16 @@
#include "transfer_interface.h"
#include "verifier_interface.h"
#include <KIO/CommandLauncherJob>
#include <KDialogJobUiDelegate>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusPendingReply>
#include <QList>
#include <KRun>
#include <QTemporaryDir>
#include <qtest_kde.h>
#include <QTest>
//FIXME not working fine if files or transfers are existing already
QHash<QString, int> Commands::s_stringCommands;
......@@ -541,7 +543,11 @@ void Commands::slotBrokenPieces(const QStringList &offsets, qulonglong length)
TestTransfers::TestTransfers()
{
if(!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kget")) {
KRun::runCommand("kget --showDropTarget --hideMainWindow", "kget", "kget", nullptr);
const QString command = QStringLiteral("kget --showDropTarget --hideMainWindow");
auto *job = new KIO::CommandLauncherJob(command);
job->setDesktopName(QStringLiteral("org.kde.kget"));
job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, nullptr));
job->start();
}
m_dir.reset(new QTemporaryDir());
......@@ -584,22 +590,20 @@ TestTransfers::TestTransfers()
QString TestTransfers::tempDir() const
{
return m_dir->name();
return m_dir->path();
}
void TestTransfers::parseFile()
{
QFile file(QString::fromLocal8Bit(KDESRCDIR) + "/kget-test.xml");
if (!file.open(QIODevice::ReadOnly)) {
QFAIL("XML file not found.");
}
const QString xmlFile = QFINDTESTDATA("kget-test.xml");
QVERIFY(!xmlFile.isEmpty());
QFile file(xmlFile);
QVERIFY(file.open(QIODevice::ReadOnly));
QDomDocument doc;
if (!doc.setContent(&file)) {
file.close();
QFAIL("Not able to set content.");
}
file.close();
for (QDomElement elem = doc.firstChildElement("tests").firstChildElement("transfer"); !elem.isNull(); elem = elem.nextSiblingElement("transfer")) {
const QString source = elem.attribute("source");
......@@ -630,7 +634,7 @@ void TestTransfers::createTransfer()
OrgKdeKgetMainInterface kgetInterface("org.kde.kget", "/KGet", QDBusConnection::sessionBus());
foreach (Commands *command, m_commands) {
QDBusPendingReply<QStringList> reply = kgetInterface.addTransfer(command->source(), tempDir() + KUrl(command->source()).fileName(), false);
QDBusPendingReply<QStringList> reply = kgetInterface.addTransfer(command->source(), tempDir() + QUrl::fromLocalFile(command->source()).fileName(), false);
reply.waitForFinished();
if (reply.value().size()) {
......@@ -647,8 +651,6 @@ void TestTransfers::createTransfer()
void TestTransfers::simpleTest()
{
QVERIFY(1 == 1);
parseFile();
createTransfer();
......@@ -669,7 +671,5 @@ void TestTransfers::simpleTest()
}
}
QTEST_KDEMAIN(TestTransfers, GUI)
QTEST_MAIN(TestTransfers)
......@@ -61,9 +61,9 @@ class Commands : public QObject
};
protected:
void timerEvent(QTimerEvent *event);
void timerEvent(QTimerEvent *event) override;
private slots:
private Q_SLOTS:
void slotVerified(bool verified);
void slotBrokenPieces(const QStringList &offsets, qulonglong length);
void slotChangedEvent(int event);
......@@ -89,10 +89,10 @@ class TestTransfers: public QObject
QString tempDir() const;
public slots:
public Q_SLOTS:
void createTransfer();
private slots:
private Q_SLOTS:
void simpleTest();
private:
......
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