/**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of Qt Creator. ** ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3 as published by the Free Software ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT ** included in the packaging of this file. Please review the following ** information to ensure the GNU General Public License requirements will ** be met: https://www.gnu.org/licenses/gpl-3.0.html. ** ****************************************************************************/ #include #include #include using namespace Core::Internal; static const char TEST_XML1[] = "" "" " Synchronizes translator's ts files with the program code" " Synchronisiert die ts-Übersetzungsdateien mit dem Programmcode" " Update translations (lupdate)" " Übersetzungen aktualisieren (lupdate)" " Linguist" " Linguist" " 1" " " " %{QT_INSTALL_BINS}/lupdate" " lupdate" " %{CurrentProjectFilePath}" " %{CurrentProjectPath}" " " ""; static const char TEST_XML2[] = "" "" " Sorts the selected text" " Sortiert den ausgewählten Text" " Sort" " Sortieren" " Text" " Text" " " " sort" " %{CurrentSelection}" " %{CurrentPath}" " " ""; static const char TEST_XML3[] = "" "" " Opens the current file in vi" " Öffnet die aktuelle Datei in vi" " Edit with vi" " In vi öffnen" " Text" " Text" " " " xterm" " -geom %{EditorCharWidth}x%{EditorCharHeight}+%{EditorXPos}+%{EditorYPos} -e vi %{CurrentFilePath} +%{EditorLine} +\"normal %{EditorColumn}|\"" " %{CurrentPath}" " " ""; static const char TEST_XML_LANG[] = "" "" " Hi" " Hallo" " Grüezi" " Hallo" " Hi" " Grüezi" " Grüezi" " Hi" " Hallo" " " " foo" " " ""; class ExternaltoolTest : public QObject { Q_OBJECT private Q_SLOTS: void testRead1(); void testRead2(); void testRead3(); void testReadLocale(); }; void ExternaltoolTest::testRead1() { QString error; ExternalTool *tool = ExternalTool::createFromXml(QByteArray(TEST_XML1), &error); QVERIFY(tool != 0); QVERIFY(error.isEmpty()); QCOMPARE(tool->id(), QString::fromLatin1("lupdate")); QVERIFY(tool->description().startsWith(QLatin1String("Synchronizes tran"))); QCOMPARE(tool->displayName(), QString::fromLatin1("Update translations (lupdate)")); QCOMPARE(tool->displayCategory(), QString::fromLatin1("Linguist")); QCOMPARE(tool->order(), 1); QCOMPARE(tool->executables().size(), 2); QCOMPARE(tool->executables().at(0), QString::fromLatin1("%{QT_INSTALL_BINS}/lupdate")); QCOMPARE(tool->executables().at(1), QString::fromLatin1("lupdate")); QCOMPARE(tool->arguments(), QString::fromLatin1("%{CurrentProjectFilePath}")); QCOMPARE(tool->input(), QString()); QCOMPARE(tool->workingDirectory(), QString::fromLatin1("%{CurrentProjectPath}")); QCOMPARE(tool->outputHandling(), ExternalTool::ShowInPane); QCOMPARE(tool->errorHandling(), ExternalTool::Ignore); delete tool; } void ExternaltoolTest::testRead2() { QString error; ExternalTool *tool = ExternalTool::createFromXml(QByteArray(TEST_XML2), &error); QVERIFY(tool != 0); QVERIFY(error.isEmpty()); QCOMPARE(tool->id(), QString::fromLatin1("sort")); QVERIFY(tool->description().startsWith(QLatin1String("Sorts the"))); QCOMPARE(tool->displayName(), QString::fromLatin1("Sort")); QCOMPARE(tool->displayCategory(), QString::fromLatin1("Text")); QCOMPARE(tool->order(), -1); QCOMPARE(tool->executables().size(), 1); QCOMPARE(tool->executables().at(0), QString::fromLatin1("sort")); QCOMPARE(tool->arguments(), QString()); QCOMPARE(tool->input(), QString::fromLatin1("%{CurrentSelection}")); QCOMPARE(tool->workingDirectory(), QString::fromLatin1("%{CurrentPath}")); QCOMPARE(tool->outputHandling(), ExternalTool::ReplaceSelection); QCOMPARE(tool->errorHandling(), ExternalTool::ShowInPane); delete tool; } void ExternaltoolTest::testRead3() { QString error; ExternalTool *tool = ExternalTool::createFromXml(QByteArray(TEST_XML3), &error); QVERIFY(tool != 0); QVERIFY(error.isEmpty()); QCOMPARE(tool->id(), QString::fromLatin1("vi")); QVERIFY(tool->description().startsWith(QLatin1String("Opens the"))); QCOMPARE(tool->displayName(), QString::fromLatin1("Edit with vi")); QCOMPARE(tool->displayCategory(), QString::fromLatin1("Text")); QCOMPARE(tool->order(), -1); QCOMPARE(tool->executables().size(), 1); QCOMPARE(tool->executables().at(0), QString::fromLatin1("xterm")); QVERIFY(tool->arguments().startsWith(QLatin1String("-geom %{"))); QCOMPARE(tool->input(), QString()); QCOMPARE(tool->workingDirectory(), QString::fromLatin1("%{CurrentPath}")); QCOMPARE(tool->outputHandling(), ExternalTool::ShowInPane); QCOMPARE(tool->modifiesCurrentDocument(), true); QCOMPARE(tool->errorHandling(), ExternalTool::ShowInPane); delete tool; } void ExternaltoolTest::testReadLocale() { QString error; ExternalTool *tool; tool = ExternalTool::createFromXml(QByteArray(TEST_XML_LANG), &error); QVERIFY(tool != 0); QVERIFY(error.isEmpty()); QCOMPARE(tool->description(), QString::fromLatin1("Hi")); QCOMPARE(tool->displayName(), QString::fromLatin1("Hi")); QCOMPARE(tool->displayCategory(), QString::fromLatin1("Hi")); delete tool; tool = ExternalTool::createFromXml(QByteArray(TEST_XML_LANG), &error, QLatin1String("uk")); QVERIFY(tool != 0); QVERIFY(error.isEmpty()); QCOMPARE(tool->description(), QString::fromLatin1("Hi")); QCOMPARE(tool->displayName(), QString::fromLatin1("Hi")); QCOMPARE(tool->displayCategory(), QString::fromLatin1("Hi")); delete tool; tool = ExternalTool::createFromXml(QByteArray(TEST_XML_LANG), &error, QLatin1String("de_DE.UTF-8")); QVERIFY(tool != 0); QVERIFY(error.isEmpty()); QCOMPARE(tool->description(), QString::fromLatin1("Hallo")); QCOMPARE(tool->displayName(), QString::fromLatin1("Hallo")); QCOMPARE(tool->displayCategory(), QString::fromLatin1("Hallo")); delete tool; tool = ExternalTool::createFromXml(QByteArray(TEST_XML_LANG), &error, QLatin1String("de_CH")); QVERIFY(tool != 0); QVERIFY(error.isEmpty()); QCOMPARE(tool->description(), QString::fromLatin1("Grüezi")); QCOMPARE(tool->displayName(), QString::fromLatin1("Grüezi")); QCOMPARE(tool->displayCategory(), QString::fromLatin1("Grüezi")); delete tool; } QTEST_APPLESS_MAIN(ExternaltoolTest); #include "tst_externaltooltest.moc"