1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2017 Ford Motor Company |
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 <QMetaType> |
31 | #include <QProcess> |
32 | #include <QStandardPaths> |
33 | |
34 | namespace { |
35 | |
36 | QString findExecutable(const QString &executableName, const QStringList &paths) |
37 | { |
38 | const auto path = QStandardPaths::findExecutable(executableName, paths); |
39 | if (!path.isEmpty()) { |
40 | return path; |
41 | } |
42 | |
43 | qWarning() << "Could not find executable:" << executableName << "in any of" << paths; |
44 | return QString(); |
45 | } |
46 | |
47 | } |
48 | |
49 | class tst_Integration_MultiProcess: public QObject |
50 | { |
51 | Q_OBJECT |
52 | |
53 | private slots: |
54 | void initTestCase() |
55 | { |
56 | QLoggingCategory::setFilterRules("qt.remoteobjects.warning=false" ); |
57 | } |
58 | |
59 | void cleanup() |
60 | { |
61 | // wait for delivery of RemoveObject events to the source |
62 | QTest::qWait(ms: 200); |
63 | } |
64 | |
65 | void testRun_data() |
66 | { |
67 | QTest::addColumn<bool>(name: "templated" ); |
68 | QTest::newRow(dataTag: "non-templated enableRemoting" ) << false; |
69 | QTest::newRow(dataTag: "templated enableRemoting" ) << true; |
70 | } |
71 | |
72 | void testRun() |
73 | { |
74 | QFETCH(bool, templated); |
75 | |
76 | qDebug() << "Starting server process" ; |
77 | QProcess serverProc; |
78 | serverProc.setProcessChannelMode(QProcess::ForwardedChannels); |
79 | if (templated) { |
80 | QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); |
81 | env.insert(name: "TEMPLATED_REMOTING" , value: "true" ); |
82 | serverProc.setProcessEnvironment(env); |
83 | } |
84 | serverProc.start(program: findExecutable(executableName: "integration_multiprocess_server" , paths: { |
85 | QCoreApplication::applicationDirPath() + "/../server/" |
86 | }), arguments: QStringList()); |
87 | QVERIFY(serverProc.waitForStarted()); |
88 | |
89 | // wait for server start |
90 | QTest::qWait(ms: 200); |
91 | |
92 | qDebug() << "Starting client process" ; |
93 | QProcess clientProc; |
94 | clientProc.setProcessChannelMode(QProcess::ForwardedChannels); |
95 | clientProc.start(program: findExecutable(executableName: "integration_multiprocess_client" , paths: { |
96 | QCoreApplication::applicationDirPath() + "/../client/" |
97 | }), arguments: QStringList()); |
98 | QVERIFY(clientProc.waitForStarted()); |
99 | |
100 | QVERIFY(clientProc.waitForFinished()); |
101 | QVERIFY(serverProc.waitForFinished()); |
102 | |
103 | QCOMPARE(serverProc.exitCode(), 0); |
104 | QCOMPARE(clientProc.exitCode(), 0); |
105 | } |
106 | }; |
107 | |
108 | QTEST_MAIN(tst_Integration_MultiProcess) |
109 | |
110 | #include "tst_integration_multiprocess.moc" |
111 | |