1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2019 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_Proxy_MultiProcess: public QObject |
50 | { |
51 | Q_OBJECT |
52 | |
53 | public: |
54 | enum ObjectMode { NullPointer, ObjectPointer }; |
55 | Q_ENUM(ObjectMode) |
56 | |
57 | private slots: |
58 | void initTestCase() |
59 | { |
60 | } |
61 | |
62 | void cleanup() |
63 | { |
64 | // wait for delivery of RemoveObject events to the source |
65 | QTest::qWait(ms: 200); |
66 | } |
67 | |
68 | void testRun_data() |
69 | { |
70 | QTest::addColumn<bool>(name: "templated" ); |
71 | QTest::addColumn<ObjectMode>(name: "objectMode" ); |
72 | QTest::newRow(dataTag: "non-templated, subobject" ) << false << ObjectPointer; |
73 | QTest::newRow(dataTag: "templated, subobject" ) << true << ObjectPointer; |
74 | QTest::newRow(dataTag: "non-templated, nullptr" ) << false << NullPointer; |
75 | QTest::newRow(dataTag: "templated, nullptr" ) << true << NullPointer; |
76 | } |
77 | |
78 | void testRun() |
79 | { |
80 | QFETCH(bool, templated); |
81 | QFETCH(ObjectMode, objectMode); |
82 | |
83 | qDebug() << "Starting server process" ; |
84 | QProcess serverProc; |
85 | serverProc.setProcessChannelMode(QProcess::ForwardedChannels); |
86 | QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); |
87 | env.insert(name: "ObjectMode" , value: QVariant::fromValue(value: objectMode).toString()); |
88 | if (templated) { |
89 | env.insert(name: "TEMPLATED_REMOTING" , value: "true" ); |
90 | } |
91 | serverProc.setProcessEnvironment(env); |
92 | serverProc.start(program: findExecutable(executableName: "proxy_multiprocess_server" , paths: { |
93 | QCoreApplication::applicationDirPath() + "/../server/" |
94 | }), arguments: QStringList()); |
95 | QVERIFY(serverProc.waitForStarted()); |
96 | |
97 | // wait for server start |
98 | QTest::qWait(ms: 200); |
99 | |
100 | |
101 | qDebug() << "Starting client process" ; |
102 | QProcess clientProc; |
103 | clientProc.setProcessChannelMode(QProcess::ForwardedChannels); |
104 | clientProc.setProcessEnvironment(env); |
105 | clientProc.start(program: findExecutable(executableName: "proxy_multiprocess_client" , paths: { |
106 | QCoreApplication::applicationDirPath() + "/../client/" |
107 | }), arguments: QStringList()); |
108 | QVERIFY(clientProc.waitForStarted()); |
109 | |
110 | // wait for client start |
111 | QTest::qWait(ms: 200); |
112 | |
113 | |
114 | qDebug() << "Starting proxy process" ; |
115 | QProcess proxyProc; |
116 | proxyProc.setProcessChannelMode(QProcess::ForwardedChannels); |
117 | proxyProc.start(program: findExecutable(executableName: "proxy" , paths: { |
118 | QCoreApplication::applicationDirPath() + "/../proxy/" |
119 | }), arguments: QStringList()); |
120 | QVERIFY(proxyProc.waitForStarted()); |
121 | |
122 | // wait for proxy start |
123 | QTest::qWait(ms: 200); |
124 | |
125 | |
126 | QVERIFY(clientProc.waitForFinished()); |
127 | QVERIFY(proxyProc.waitForFinished()); |
128 | QVERIFY(serverProc.waitForFinished()); |
129 | |
130 | QCOMPARE(serverProc.exitCode(), 0); |
131 | QCOMPARE(proxyProc.exitCode(), 0); |
132 | QCOMPARE(clientProc.exitCode(), 0); |
133 | } |
134 | }; |
135 | |
136 | QTEST_MAIN(tst_Proxy_MultiProcess) |
137 | |
138 | #include "tst_proxy_multiprocess.moc" |
139 | |