File: test_executecompositejob.cpp

package info (click to toggle)
kdevelop 4%3A24.12.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 71,888 kB
  • sloc: cpp: 290,869; python: 3,626; javascript: 3,518; sh: 1,316; ansic: 703; xml: 401; php: 95; lisp: 66; makefile: 31; sed: 12
file content (77 lines) | stat: -rw-r--r-- 2,297 bytes parent folder | download | duplicates (2)
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
/*
    SPDX-FileCopyrightText: 2014 Milian Wolff <mail@milianw.de>
    SPDX-FileCopyrightText: 2023 Igor Kushnir <igorkuo@gmail.com>

    SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/

#include "test_executecompositejob.h"

#include <util/executecompositejob.h>

#include <QStandardPaths>
#include <QStringList>
#include <QTest>

#include <utility>

using namespace KDevelop;

class TestJob : public KJob
{
    void start() override
    {
    }
};

class TestCompositeJob : public ExecuteCompositeJob
{
public:
    using ExecuteCompositeJob::ExecuteCompositeJob;
    using ExecuteCompositeJob::subjobs;
};

void TestExecuteCompositeJob::initTestCase()
{
    QStandardPaths::setTestModeEnabled(true);
}

void TestExecuteCompositeJob::create_data()
{
    QTest::addColumn<QStringList>("subjobNames");
    QTest::addColumn<QString>("expectedCompositeJobName");

    QTest::newRow("no subjobs") << QStringList{} << "";
    QTest::newRow("empty-named subjob") << QStringList{""} << "";
    QTest::newRow("named subjob") << QStringList{"run as"} << "run as";
    QTest::newRow("two empty-named subjobs") << QStringList{"", ""} << "";
    QTest::newRow("empty-named and named") << QStringList{"", "pick"} << "pick";
    QTest::newRow("named and empty-named") << QStringList{"take", ""} << "take";
    QTest::newRow("two named subjobs") << QStringList{"x", "y"} << "x";
    QTest::newRow("three empty-named subjobs") << QStringList{"", "", ""} << "";
    QTest::newRow("empty-named and two named") << QStringList{"", "y", "x"} << "y";
}

void TestExecuteCompositeJob::create()
{
    QFETCH(const QStringList, subjobNames);
    QFETCH(const QString, expectedCompositeJobName);

    QList<KJob*> subjobs;
    for (auto& name : subjobNames) {
        subjobs.push_back(new TestJob);
        subjobs.back()->setObjectName(name);
    }
    QCOMPARE(subjobs.size(), subjobNames.size());

    TestCompositeJob compositeJob(nullptr, std::as_const(subjobs));
    QCOMPARE(compositeJob.subjobs(), subjobs);
    QCOMPARE(compositeJob.objectName(), expectedCompositeJobName);
    for (auto& subjob : std::as_const(subjobs)) {
        QCOMPARE(subjob->parent(), &compositeJob);
    }
}

QTEST_GUILESS_MAIN(TestExecuteCompositeJob)

#include "moc_test_executecompositejob.cpp"