File: jobguitest.cpp

package info (click to toggle)
kio 5.116.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 41,496 kB
  • sloc: cpp: 123,468; xml: 528; ansic: 466; ruby: 60; sh: 21; makefile: 13
file content (84 lines) | stat: -rw-r--r-- 2,110 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
    This file is part of the KDE project
    SPDX-FileCopyrightText: 2011 David Faure <faure@kde.org>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/

#include "kiotesthelper.h" // createTestFile etc.
#include <QApplication>
#include <QTest>
#include <kio/copyjob.h>
#include <kio/deletejob.h>
#include <kio/paste.h>

#include <QClipboard>
#include <QMimeData>

static QString otherTmpDir()
{
#ifdef Q_OS_WIN
    return QDir::tempPath() + "/jobtest/";
#else
    // This one needs to be on another partition
    return QStringLiteral("/tmp/jobtest/");
#endif
}

class JobGuiTest : public QObject
{
    Q_OBJECT

public Q_SLOTS:
    void initTestCase()
    {
        // Start with a clean base dir
        cleanupTestCase();
        homeTmpDir(); // create it
        if (!QFile::exists(otherTmpDir())) {
            bool ok = QDir().mkdir(otherTmpDir());
            if (!ok) {
                qFatal("Couldn't create %s", qPrintable(homeTmpDir()));
            }
        }
    }

    void cleanupTestCase()
    {
        delDir(homeTmpDir());
        delDir(otherTmpDir());
    }

    void pasteFileToOtherPartition()
    {
        const QString filePath = homeTmpDir() + "fileFromHome";
        const QString dest = otherTmpDir() + "fileFromHome_copied";
        QFile::remove(dest);
        createTestFile(filePath);

        QMimeData *mimeData = new QMimeData;
        QUrl fileUrl = QUrl::fromLocalFile(filePath);
        mimeData->setUrls(QList<QUrl>{fileUrl});
        QApplication::clipboard()->setMimeData(mimeData);

        KIO::Job *job = KIO::pasteClipboard(QUrl::fromLocalFile(otherTmpDir()), static_cast<QWidget *>(nullptr));
        job->setUiDelegate(nullptr);
        bool ok = job->exec();
        QVERIFY(ok);

        QVERIFY(QFile::exists(dest));
        QVERIFY(QFile::exists(filePath)); // still there
    }

private:
    static void delDir(const QString &pathOrUrl)
    {
        KIO::Job *job = KIO::del(QUrl::fromLocalFile(pathOrUrl), KIO::HideProgressInfo);
        job->setUiDelegate(nullptr);
        job->exec();
    }
};

QTEST_MAIN(JobGuiTest)

#include "jobguitest.moc"