summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/AuthorizationTest.qml
blob: de9d1907195977d02520ecddfba76c1d52df2010 (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
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
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

import QtQuick
import QtTest
import QtOpcUa as QtOpcUa

Item {
    property string backendName
    property int completedTestCases: 0
    property int availableTestCases: 0
    property bool completed: completedTestCases == availableTestCases
    property bool shouldRun: false

    onShouldRunChanged: {
        if (shouldRun)
            console.log("Running", parent.testName, "with", backendName);
    }

    CompletionLoggingTestCase {
        name: parent.parent.testName + ": " + backendName + ": Username authentication"

        QtOpcUa.Connection {
            id: connection
            backend: backendName
            defaultConnection: true
        }

        QtOpcUa.ServerDiscovery {
            id: serverDiscovery
            onServersChanged: {
                if (!count)
                    return;
                endpointDiscovery.serverUrl = at(0).discoveryUrls[0];
            }
        }

        QtOpcUa.EndpointDiscovery {
            id: endpointDiscovery
            onEndpointsChanged: {
                if (!count)
                    return;
                connection.connectToEndpoint(at(0));
            }
        }

        Component.onCompleted: {
            for (var i in children) {
                if (children[i].objectName == "TestCase")
                    availableTestCases += 1;
            }
            serverDiscovery.discoveryUrl = OPCUA_DISCOVERY_URL;
        }

        QtOpcUa.ValueNode {
              connection: connection
              nodeId: QtOpcUa.NodeId {
                  ns: "Test Namespace"
                  identifier: "s=theStringId"
              }
              id: node1
        }

        SignalSpy {
            id: connection1ConnectedSpy
            target: connection
            signalName: "connectedChanged"
        }

        SignalSpy {
            id: node1ValueChangedSpy
            target: node1
            signalName: "valueChanged"
        }

        function test_nodeTest() {
            var authInfo = connection.authenticationInformation;
            authInfo.setUsernameAuthentication("user1", "password");
            connection.authenticationInformation = authInfo;

            serverDiscovery.discoveryUrl = OPCUA_DISCOVERY_URL;

            connection1ConnectedSpy.wait();
            verify(connection.connected);

            node1ValueChangedSpy.wait();
            verify(node1ValueChangedSpy.count > 0);

            compare(node1.value, "Value", "");
            compare(node1.browseName, "theStringId");
        }
    }
}