File indexing completed on 2024-05-19 05:43:40
0001 #include <QtTest/QtTest> 0002 #include <QProcess> 0003 0004 #include <cutehmi/daemon/autogen/cutehmi.dirs.hpp> 0005 0006 namespace cutehmi { 0007 namespace daemon { 0008 0009 class test_cutehmi_daemon: 0010 public QObject 0011 { 0012 Q_OBJECT 0013 0014 private slots: 0015 void initTestCase(); 0016 0017 void helpOption(); 0018 0019 void versionOption(); 0020 0021 void countDaemonExample(); 0022 0023 private: 0024 QString m_installDir; 0025 QString m_programPath; 0026 }; 0027 0028 void test_cutehmi_daemon::initTestCase() 0029 { 0030 QString m_installDir = qEnvironmentVariable("CUTEHMI_INSTALL_DIR"); 0031 QVERIFY(!m_installDir.isEmpty()); 0032 0033 QString toolsInstallSubdir = CUTEHMI_DIRS_TOOLS_INSTALL_SUBDIR; 0034 if (!toolsInstallSubdir.isEmpty()) 0035 m_installDir += "/" + toolsInstallSubdir; 0036 0037 m_programPath = m_installDir + "/cutehmi.daemon.3"; 0038 #ifndef CUTEHMI_NDEBUG 0039 m_programPath += ".debug"; 0040 #endif 0041 } 0042 0043 void test_cutehmi_daemon::helpOption() 0044 { 0045 QList<QStringList> argumentsList; 0046 argumentsList << QStringList({"--help"}) 0047 << QStringList({"--h"}); 0048 0049 for (auto arguments : argumentsList) { 0050 QProcess process; 0051 process.start(m_programPath, arguments); 0052 process.waitForFinished(1000); 0053 QCOMPARE(process.error(), QProcess::UnknownError); 0054 QVERIFY(!process.readAllStandardError().contains("Unknown option")); 0055 QVERIFY(!process.readAllStandardOutput().isEmpty()); 0056 QCOMPARE(process.exitStatus(), QProcess::NormalExit); 0057 QCOMPARE(process.exitCode(), EXIT_SUCCESS); 0058 } 0059 } 0060 0061 void test_cutehmi_daemon::versionOption() 0062 { 0063 QList<QStringList> argumentsList; 0064 argumentsList << QStringList({"--version"}) 0065 << QStringList({"--v"}); 0066 0067 for (auto arguments : argumentsList) { 0068 QProcess process; 0069 process.start(m_programPath, arguments); 0070 process.waitForFinished(1000); 0071 QCOMPARE(process.error(), QProcess::UnknownError); 0072 QVERIFY(!process.readAllStandardError().contains("Unknown option")); 0073 QVERIFY(!process.readAllStandardOutput().isEmpty()); 0074 QCOMPARE(process.exitStatus(), QProcess::NormalExit); 0075 QCOMPARE(process.exitCode(), EXIT_SUCCESS); 0076 } 0077 } 0078 0079 void test_cutehmi_daemon::countDaemonExample() 0080 { 0081 QProcess process; 0082 QStringList arguments({"--app", "CuteHMI.Examples.CountDaemon.3"}); 0083 process.start(m_programPath, arguments); 0084 QVERIFY(process.waitForFinished()); 0085 0086 QString stdOut = QString::fromLocal8Bit(process.readAllStandardOutput()); 0087 QString stdErr = QString::fromLocal8Bit(process.readAllStandardError()); 0088 0089 QVERIFY(stdErr.contains("I can count")); 0090 0091 QCOMPARE(process.error(), QProcess::UnknownError); 0092 QCOMPARE(process.exitStatus(), QProcess::NormalExit); 0093 QCOMPARE(process.exitCode(), EXIT_SUCCESS); 0094 } 0095 0096 } 0097 } 0098 0099 QTEST_MAIN(cutehmi::daemon::test_cutehmi_daemon) 0100 #include "test_cutehmi_daemon.moc" 0101 0102 //(c)C: Copyright © 2020-2024, Michał Policht <michal@policht.pl>. All rights reserved. 0103 //(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT 0104 //(c)C: This file is a part of CuteHMI. 0105 //(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. 0106 //(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. 0107 //(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/>. 0108 //(c)C: Additionally, this file is licensed under terms of MIT license as expressed below. 0109 //(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: 0110 //(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 0111 //(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.