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.category = QStringLiteral("Git Tools"); | ||||
48 | tool.name = QStringLiteral("git cola"); | ||||
49 | tool.icon = QStringLiteral("git-cola"); | ||||
50 | tool.executable = QStringLiteral("git-cola"); | ||||
51 | tool.arguments = QStringLiteral("none"); | ||||
52 | tool.input = QStringLiteral("in"); | ||||
53 | tool.workingDir = QStringLiteral("/usr/bin"); | ||||
54 | tool.mimetypes = QStringList{ QStringLiteral("everything") }; | ||||
55 | tool.hasexec = true; | ||||
56 | tool.actionName = QStringLiteral("asdf"); | ||||
57 | tool.cmdname = QStringLiteral("git-cola"); | ||||
58 | tool.saveMode = KateExternalTool::SaveMode::None; | ||||
59 | | ||||
60 | tool.save(cg); | ||||
61 | | ||||
62 | KateExternalTool clonedTool; | ||||
63 | clonedTool.load(cg); | ||||
64 | QCOMPARE(tool, clonedTool); | ||||
65 | } | ||||
66 | | ||||
67 | void ExternalToolTest::testRunListDirectory() | ||||
68 | { | ||||
69 | std::unique_ptr<KateExternalTool> tool(new KateExternalTool()); | ||||
70 | tool->category = QStringLiteral("Tools"); | ||||
71 | tool->name = QStringLiteral("ls"); | ||||
72 | tool->icon = QStringLiteral("none"); | ||||
73 | tool->executable = QStringLiteral("ls"); | ||||
74 | tool->arguments = QStringLiteral("/usr"); | ||||
75 | tool->workingDir = QStringLiteral("/tmp"); | ||||
76 | tool->mimetypes = QStringList{}; | ||||
77 | tool->hasexec = true; | ||||
78 | tool->actionName = QStringLiteral("ls"); | ||||
79 | tool->cmdname = QStringLiteral("ls"); | ||||
80 | tool->saveMode = KateExternalTool::SaveMode::None; | ||||
81 | std::unique_ptr<KateExternalTool> tool2(new KateExternalTool(*tool)); | ||||
82 | | ||||
83 | // 1. /tmp $ ls /usr | ||||
84 | KateToolRunner runner1(std::move(tool), nullptr); | ||||
85 | runner1.run(); | ||||
86 | runner1.waitForFinished(); | ||||
87 | QVERIFY(runner1.outputData().contains(QStringLiteral("bin"))); | ||||
88 | | ||||
89 | // 2. /usr $ ls | ||||
90 | tool2->arguments.clear(); | ||||
91 | tool2->workingDir = QStringLiteral("/usr"); | ||||
92 | KateToolRunner runner2(std::move(tool2), nullptr); | ||||
93 | runner2.run(); | ||||
94 | runner2.waitForFinished(); | ||||
95 | QVERIFY(runner2.outputData().contains(QStringLiteral("bin"))); | ||||
96 | | ||||
97 | // 1. and 2. must give the same result | ||||
98 | QCOMPARE(runner1.outputData(), runner2.outputData()); | ||||
99 | } | ||||
100 | | ||||
101 | void ExternalToolTest::testRunTac() | ||||
102 | { | ||||
103 | std::unique_ptr<KateExternalTool> tool(new KateExternalTool()); | ||||
104 | tool->name = QStringLiteral("tac"); | ||||
105 | tool->executable = QStringLiteral("tac"); | ||||
106 | tool->input = QStringLiteral("a\nb\nc\n"); | ||||
107 | tool->saveMode = KateExternalTool::SaveMode::None; | ||||
108 | | ||||
109 | // run tac to reverse order | ||||
110 | KateToolRunner runner(std::move(tool), nullptr); | ||||
111 | runner.run(); | ||||
112 | runner.waitForFinished(); | ||||
113 | QCOMPARE(runner.outputData(), QStringLiteral("c\nb\na\n")); | ||||
114 | } | ||||
115 | | ||||
116 | // kate: space-indent on; indent-width 4; replace-tabs on; |