File: tst_proxy_multiprocess.cpp

package info (click to toggle)
qt6-remoteobjects 6.9.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,812 kB
  • sloc: cpp: 20,883; sh: 29; makefile: 26
file content (100 lines) | stat: -rw-r--r-- 3,047 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright (C) 2019 Ford Motor Company
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#include <QtTest/QtTest>
#include <QMetaType>
#include <QProcess>

#include "../../../shared/testutils.h"

class tst_Proxy_MultiProcess: public QObject
{
    Q_OBJECT

public:
    enum ObjectMode { NullPointer, ObjectPointer };
    Q_ENUM(ObjectMode)

private slots:
    void initTestCase()
    {
        QVERIFY(TestUtils::init("tst"));
    }

    void cleanup()
    {
        // wait for delivery of RemoveObject events to the source
        QTest::qWait(200);
    }

    void testRun_data()
    {
        QTest::addColumn<bool>("templated");
        QTest::addColumn<ObjectMode>("objectMode");
        QTest::newRow("non-templated, subobject") << false << ObjectPointer;
        QTest::newRow("templated, subobject") << true << ObjectPointer;
        QTest::newRow("non-templated, nullptr") << false << NullPointer;
        QTest::newRow("templated, nullptr") << true << NullPointer;
    }

    void testRun()
    {
#ifdef Q_OS_ANDROID
        QSKIP("QProcess doesn't support running user bundled binaries on Android");
#endif
        QFETCH(bool, templated);
        QFETCH(ObjectMode, objectMode);

        qDebug() << "Starting server process";
        QProcess serverProc;
        serverProc.setProcessChannelMode(QProcess::ForwardedChannels);
        QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
        env.insert("ObjectMode", QVariant::fromValue(objectMode).toString());
        if (templated) {
            env.insert("TEMPLATED_REMOTING", "true");
        }
        serverProc.setProcessEnvironment(env);
        serverProc.start(TestUtils::findExecutable("proxy_multiprocess_server", "/server"),
                         QStringList());
        QVERIFY(serverProc.waitForStarted());

        // wait for server start
        QTest::qWait(200);


        qDebug() << "Starting client process";
        QProcess clientProc;
        clientProc.setProcessChannelMode(QProcess::ForwardedChannels);
        clientProc.setProcessEnvironment(env);
        clientProc.start(TestUtils::findExecutable("proxy_multiprocess_client", "/client"),
                         QStringList());
        QVERIFY(clientProc.waitForStarted());

        // wait for client start
        QTest::qWait(200);


        qDebug() << "Starting proxy process";
        QProcess proxyProc;
        proxyProc.setProcessChannelMode(QProcess::ForwardedChannels);
        proxyProc.start(TestUtils::findExecutable("proxy", "/proxy"),
                        QStringList());
        QVERIFY(proxyProc.waitForStarted());

        // wait for proxy start
        QTest::qWait(200);


        QVERIFY(clientProc.waitForFinished());
        QVERIFY(proxyProc.waitForFinished());
        QVERIFY(serverProc.waitForFinished());

        QCOMPARE(serverProc.exitCode(), 0);
        QCOMPARE(proxyProc.exitCode(), 0);
        QCOMPARE(clientProc.exitCode(), 0);
    }
};

QTEST_MAIN(tst_Proxy_MultiProcess)

#include "tst_proxy_multiprocess.moc"