File: menutest.cpp

package info (click to toggle)
purpose 5.116.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,880 kB
  • sloc: cpp: 4,575; sh: 32; makefile: 17
file content (74 lines) | stat: -rw-r--r-- 2,187 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
/*
    SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com>

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

#include <QJsonArray>
#include <QJsonObject>
#include <QSignalSpy>
#include <QStandardPaths>
#include <qtest.h>

#include "menutest.h"
#include <purpose/alternativesmodel.h>
#include <purpose/menu.h>

QTEST_MAIN(MenuTest)

static QAction *saveAsAction(Purpose::Menu *menu)
{
    const auto actions = menu->actions();
    for (QAction *action : actions) {
        if (action->property("pluginId") == QLatin1String("saveasplugin")) {
            return action;
        }
    }

    Q_ASSERT(!"Couldn't find the saveas plugin");
    return nullptr;
}

void MenuTest::initTestCase()
{
    // To let ctest exit, we shouldn't start kio_http_cache_cleaner
    qputenv("KIO_DISABLE_CACHE_CLEANER", "yes");
}

void MenuTest::runJobTest()
{
    Purpose::Menu *menu = new Purpose::Menu;
    Purpose::AlternativesModel *model = menu->model();
    model->setDisabledPlugins({});

    const QString tempfile = m_tempDir.path() + QStringLiteral("/purposetest");
    QFile::remove(tempfile);
    const QJsonObject input = QJsonObject{{QStringLiteral("urls"), QJsonArray{QStringLiteral("http://kde.org")}},
                                          {QStringLiteral("mimeType"), QStringLiteral("dummy/thing")},
                                          {QStringLiteral("destinationPath"), QUrl::fromLocalFile(tempfile).url()}};
    model->setInputData(input);
    model->setPluginType(QStringLiteral("Export"));
    menu->reload();

    int error = -1;
    QJsonObject output;
    connect(menu, &Purpose::Menu::finished, menu, [&error, &output](const QJsonObject &_output, int _error, const QString &errorMessage) {
        error = _error;
        output = _output;
        if (error != 0) {
            qDebug() << "job failed with error" << errorMessage;
        }
    });

    QAction *action = saveAsAction(menu);
    QSignalSpy s(menu, &Purpose::Menu::finished);
    action->trigger();
    QVERIFY(s.count() || s.wait());
    QCOMPARE(error, 0);
    QCOMPARE(output.count(), 1);
    QVERIFY(QFile::remove(tempfile));

    delete menu;
}

#include "moc_menutest.cpp"