| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2021 The Qt Company Ltd. | 
| 4 | ** Contact: https://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the QtRemoteObjects module of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ | 
| 9 | ** Commercial License Usage | 
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 11 | ** accordance with the commercial license agreement provided with the | 
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | 
| 16 | ** | 
| 17 | ** GNU General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU | 
| 19 | ** General Public License version 3 as published by the Free Software | 
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT | 
| 21 | ** included in the packaging of this file. Please review the following | 
| 22 | ** information to ensure the GNU General Public License requirements will | 
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. | 
| 24 | ** | 
| 25 | ** $QT_END_LICENSE$ | 
| 26 | ** | 
| 27 | ****************************************************************************/ | 
| 28 |  | 
| 29 | #include <QtTest/QtTest> | 
| 30 | #include <QStandardPaths> | 
| 31 | #include <QProcess> | 
| 32 |  | 
| 33 |  | 
| 34 | static QString findExecutable(const QString &executableName, const QString &searchPath) | 
| 35 | { | 
| 36 |     const QString path = QStandardPaths::findExecutable(executableName, paths: { searchPath }); | 
| 37 |     if (!path.isEmpty()) | 
| 38 |         return path; | 
| 39 |  | 
| 40 |     qWarning() << "Could not find executable:"  << executableName << "in"  << searchPath; | 
| 41 |     return QString(); | 
| 42 | } | 
| 43 |  | 
| 44 |  | 
| 45 | class tst_Reconnect: public QObject | 
| 46 | { | 
| 47 |     Q_OBJECT | 
| 48 |  | 
| 49 | private slots: | 
| 50 |     void testRun_data() | 
| 51 |     { | 
| 52 |         QTest::addColumn<QString>(name: "url" ); | 
| 53 |         QTest::addRow(format: "local" ) << QStringLiteral("local:replica" ); | 
| 54 |         QTest::addRow(format: "tcp" ) << QStringLiteral("tcp://127.0.0.1:65217" ); | 
| 55 |     } | 
| 56 |  | 
| 57 |     void testRun() | 
| 58 |     { | 
| 59 |         QFETCH(QString, url); | 
| 60 |  | 
| 61 |         QProcess serverProc; | 
| 62 |         serverProc.setProcessChannelMode(QProcess::ForwardedChannels); | 
| 63 |         QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); | 
| 64 |         env.insert(name: "RO_URL" , value: url); | 
| 65 |         serverProc.setProcessEnvironment(env); | 
| 66 |         const QString appDir = QCoreApplication::applicationDirPath(); | 
| 67 |         serverProc.start(program: findExecutable(executableName: "qtro_reconnect_server" , searchPath: appDir + QLatin1String("/../server/" )), arguments: QStringList()); | 
| 68 |         QVERIFY(serverProc.waitForStarted()); | 
| 69 |  | 
| 70 |         QProcess clientProc; | 
| 71 |         clientProc.setProcessChannelMode(QProcess::ForwardedChannels); | 
| 72 |         clientProc.setProcessEnvironment(env); | 
| 73 |         clientProc.start(program: findExecutable(executableName: "qtro_reconnect_client" , searchPath: appDir + QLatin1String("/../client/" )), arguments: QStringList()); | 
| 74 |         qDebug() << "Started server and client process on:"  << url; | 
| 75 |         QVERIFY(clientProc.waitForStarted()); | 
| 76 |  | 
| 77 |         QVERIFY(clientProc.waitForFinished()); | 
| 78 |         QVERIFY(serverProc.waitForFinished()); | 
| 79 |  | 
| 80 |         QCOMPARE(serverProc.exitCode(), 0); | 
| 81 |         QCOMPARE(clientProc.exitCode(), 0); | 
| 82 |     } | 
| 83 | }; | 
| 84 |  | 
| 85 | QTEST_MAIN(tst_Reconnect) | 
| 86 |  | 
| 87 | #include "tst_reconnect.moc" | 
| 88 |  |