summaryrefslogtreecommitdiffstats
path: root/tests/auto/repc/signature/state/main.cpp
blob: a802882db976ff1a96925e37d98afac523d61bab (plain)
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
// Copyright (C) 2017 Ford Motor Company
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#include "rep_mismatch_replica.h"

#include <QCoreApplication>
#include <QtRemoteObjects/qremoteobjectnode.h>
#include <QtTest/QtTest>

class tst_State_Process : public QObject
{
    Q_OBJECT

private Q_SLOTS:
    void testMismatch()
    {
        QRemoteObjectNode repNode;
        repNode.connectToNode(QUrl{QStringLiteral("tcp://127.0.0.1:65214")});
        QSharedPointer<TestClassReplica> rep{repNode.acquire<TestClassReplica>()};
        QSignalSpy stateChangedSpy(rep.data(), &QRemoteObjectReplica::stateChanged);
        QTRY_COMPARE(rep->state(), QRemoteObjectReplica::SignatureMismatch);
        QCOMPARE(stateChangedSpy.size(), 1);
        auto args = stateChangedSpy.takeFirst();
        QCOMPARE(args.size(), 2);
        QCOMPARE(args.at(0).toInt(), int(QRemoteObjectReplica::SignatureMismatch));
        QCOMPARE(args.at(1).toInt(), int(QRemoteObjectReplica::Default));
    }

    void testDynamic()
    {
        QRemoteObjectNode repNode;
        repNode.connectToNode(QUrl{QStringLiteral("tcp://127.0.0.1:65214")});
        QSharedPointer<QRemoteObjectDynamicReplica> rep{repNode.acquireDynamic("TestClass")};
        QSignalSpy stateChangedSpy(rep.data(), &QRemoteObjectReplica::stateChanged);
        QTRY_COMPARE(rep->state(), QRemoteObjectReplica::Valid);
        QCOMPARE(stateChangedSpy.size(), 1);
        auto args = stateChangedSpy.takeFirst();
        QCOMPARE(args.size(), 2);
        QCOMPARE(args.at(0).toInt(), int(QRemoteObjectReplica::Valid));
        QCOMPARE(args.at(1).toInt(), int(QRemoteObjectReplica::Uninitialized));
    }
};

QTEST_MAIN(tst_State_Process)

#include "main.moc"