File indexing completed on 2024-05-12 05:42:59

0001 #include <QtTest/QtTest>
0002 #include <QProcess>
0003 
0004 #include <cutehmi/console/autogen/cutehmi.dirs.hpp>
0005 
0006 namespace cutehmi {
0007 namespace console {
0008 
0009 class test_cutehmi_console:
0010     public QObject
0011 {
0012         Q_OBJECT
0013 
0014     private slots:
0015         void initTestCase();
0016 
0017         void helpOption();
0018 
0019         void versionOption();
0020 
0021     private:
0022         QString m_installDir;
0023         QString m_programPath;
0024 };
0025 
0026 void test_cutehmi_console::initTestCase()
0027 {
0028     m_installDir = qEnvironmentVariable("CUTEHMI_INSTALL_DIR");
0029     QVERIFY(!m_installDir.isEmpty());
0030 
0031     QString toolsInstallSubdir = CUTEHMI_DIRS_TOOLS_INSTALL_SUBDIR;
0032     m_programPath = m_installDir;
0033     if (!toolsInstallSubdir.isEmpty())
0034         m_programPath += "/" + toolsInstallSubdir;
0035     m_programPath +=  "/cutehmi.console.0";
0036 #ifndef CUTEHMI_NDEBUG
0037     m_programPath += ".debug";
0038 #endif
0039 }
0040 
0041 void test_cutehmi_console::helpOption()
0042 {
0043     QList<QStringList> argumentsList;
0044     argumentsList << QStringList({"--help"})
0045             << QStringList({"--h"});
0046 
0047     for (auto && arguments : argumentsList) {
0048         QProcess process;
0049         process.start(m_programPath, arguments);
0050         process.waitForFinished(1000);
0051         QCOMPARE(process.error(), QProcess::UnknownError);
0052         QVERIFY(!process.readAllStandardError().contains("Unknown option"));
0053         QVERIFY(!process.readAllStandardOutput().isEmpty());
0054         QCOMPARE(process.exitStatus(), QProcess::NormalExit);
0055         QCOMPARE(process.exitCode(), EXIT_SUCCESS);
0056     }
0057 }
0058 
0059 void test_cutehmi_console::versionOption()
0060 {
0061     QList<QStringList> argumentsList;
0062     argumentsList << QStringList({"--version"})
0063             << QStringList({"--v"});
0064 
0065     for (auto && arguments : argumentsList) {
0066         QProcess process;
0067         process.start(m_programPath, arguments);
0068         process.waitForFinished(1000);
0069         QCOMPARE(process.error(), QProcess::UnknownError);
0070         QVERIFY(!process.readAllStandardError().contains("Unknown option"));
0071         QVERIFY(!process.readAllStandardOutput().isEmpty());
0072         QCOMPARE(process.exitStatus(), QProcess::NormalExit);
0073         QCOMPARE(process.exitCode(), EXIT_SUCCESS);
0074     }
0075 }
0076 
0077 }
0078 }
0079 
0080 QTEST_MAIN(cutehmi::console::test_cutehmi_console)
0081 #include "test_cutehmi_console.moc"
0082 
0083 //(c)C: Copyright © 2020-2024, Michał Policht <michal@policht.pl>. All rights reserved.
0084 //(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
0085 //(c)C: This file is a part of CuteHMI.
0086 //(c)C: CuteHMI is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
0087 //(c)C: CuteHMI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
0088 //(c)C: You should have received a copy of the GNU Lesser General Public License along with CuteHMI.  If not, see <https://www.gnu.org/licenses/>.
0089 //(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
0090 //(c)C: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
0091 //(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
0092 //(c)C: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.