Changeset View
Changeset View
Standalone View
Standalone View
addons/externaltools/autotests/externaltooltest.cpp
- This file was added.
1 | /* This file is part of the KDE project | ||||
---|---|---|---|---|---|
2 | * | ||||
3 | * Copyright 2019 Dominik Haumann <dhaumann@kde.org> | ||||
4 | * | ||||
5 | * This library is free software; you can redistribute it and/or | ||||
6 | * modify it under the terms of the GNU Library General Public | ||||
7 | * License as published by the Free Software Foundation; either | ||||
8 | * version 2 of the License, or (at your option) any later version. | ||||
9 | * | ||||
10 | * This library is distributed in the hope that it will be useful, | ||||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
13 | * Library General Public License for more details. | ||||
14 | * | ||||
15 | * You should have received a copy of the GNU Library General Public License | ||||
16 | * along with this library; see the file COPYING.LIB. If not, write to | ||||
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
18 | * Boston, MA 02110-1301, USA. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "externaltooltest.h" | ||||
22 | #include "../kateexternaltool.h" | ||||
23 | #include "../katetoolrunner.h" | ||||
24 | | ||||
25 | #include <QtTest> | ||||
26 | #include <QString> | ||||
27 | | ||||
28 | #include <KConfig> | ||||
29 | #include <KConfigGroup> | ||||
30 | | ||||
31 | QTEST_MAIN(ExternalToolTest) | ||||
32 | | ||||
33 | void ExternalToolTest::initTestCase() | ||||
34 | { | ||||
35 | } | ||||
36 | | ||||
37 | void ExternalToolTest::cleanupTestCase() | ||||
38 | { | ||||
39 | } | ||||
40 | | ||||
41 | void ExternalToolTest::testLoadSave() | ||||
42 | { | ||||
43 | KConfig config; | ||||
44 | KConfigGroup cg(&config, "tool"); | ||||
45 | | ||||
46 | KateExternalTool tool; | ||||
47 | tool.name = QStringLiteral("git cola"); | ||||
48 | tool.icon = QStringLiteral("git-cola"); | ||||
49 | tool.executable = QStringLiteral("git-cola"); | ||||
50 | tool.arguments = QStringLiteral("none"); | ||||
51 | tool.input = QStringLiteral("in"); | ||||
52 | tool.workingDir = QStringLiteral("/usr/bin"); | ||||
53 | tool.mimetypes = QStringList{ QStringLiteral("everything") }; | ||||
54 | tool.hasexec = true; | ||||
55 | tool.actionName = QStringLiteral("asdf"); | ||||
56 | tool.cmdname = QStringLiteral("git-cola"); | ||||
57 | tool.saveMode = KateExternalTool::SaveMode::None; | ||||
58 | | ||||
59 | tool.save(cg); | ||||
60 | | ||||
61 | KateExternalTool clonedTool; | ||||
62 | clonedTool.load(cg); | ||||
63 | QCOMPARE(tool.name, clonedTool.name); | ||||
64 | } | ||||
65 | | ||||
66 | void ExternalToolTest::testRunListDirectory() | ||||
67 | { | ||||
68 | auto tool = new KateExternalTool(); | ||||
69 | tool->name = QStringLiteral("ls"); | ||||
70 | tool->icon = QStringLiteral("none"); | ||||
71 | tool->executable = QStringLiteral("ls"); | ||||
72 | tool->arguments = QStringLiteral("/usr"); | ||||
73 | tool->workingDir = QStringLiteral("/tmp"); | ||||
74 | tool->mimetypes = QStringList{}; | ||||
75 | tool->hasexec = true; | ||||
76 | tool->actionName = QStringLiteral("ls"); | ||||
77 | tool->cmdname = QStringLiteral("ls"); | ||||
78 | tool->saveMode = KateExternalTool::SaveMode::None; | ||||
79 | | ||||
80 | // 1. /tmp $ ls /usr | ||||
81 | KateToolRunner runner1(tool); | ||||
82 | runner1.run(); | ||||
83 | runner1.waitForFinished(); | ||||
84 | QVERIFY(runner1.outputData().contains(QStringLiteral("bin"))); | ||||
85 | | ||||
86 | // 2. /usr $ ls | ||||
87 | auto tool2 = new KateExternalTool(*tool); | ||||
88 | tool2->arguments.clear(); | ||||
89 | tool2->workingDir = QStringLiteral("/usr"); | ||||
90 | KateToolRunner runner2(tool2); | ||||
91 | runner2.run(); | ||||
92 | runner2.waitForFinished(); | ||||
93 | QVERIFY(runner2.outputData().contains(QStringLiteral("bin"))); | ||||
94 | | ||||
95 | // 1. and 2. must give the same result | ||||
96 | QCOMPARE(runner1.outputData(), runner2.outputData()); | ||||
97 | } | ||||
98 | | ||||
99 | // kate: space-indent on; indent-width 4; replace-tabs on; |