summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/DiscoveryTest.qml
blob: dbc6adaa18b42fd3fbb32ce8fc00b7f38417daf0 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt OPC UA module.
**
** $QT_BEGIN_LICENSE:LGPL3$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or later as published by the Free
** Software Foundation and appearing in the file LICENSE.GPL included in
** the packaging of this file. Please review the following information to
** ensure the GNU General Public License version 2.0 requirements will be
** met: http://www.gnu.org/licenses/gpl-2.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

import QtQuick 2.3
import QtTest 1.0
import QtOpcUa 5.13 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);
    }

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

    CompletionLoggingTestCase {
        name: parent.parent.testName + ": " + backendName + ": Fetch data from discovery server using default connection"
        when: shouldRun

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

        QtOpcUa.ServerDiscovery {
            // uses default connection
            id: myServers1
        }

        QtOpcUa.EndpointDiscovery {
            // uses default connection
            id: myEndpoints1
        }

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

        SignalSpy {
            id: serversChangedSpy1
            target: myServers1
            signalName: "serversChanged"
        }

        SignalSpy {
            id: serversCountSpy1
            target: myServers1
            signalName: "countChanged"
        }

        SignalSpy {
            id: serversStatusSpy1
            target: myServers1
            signalName: "statusChanged"
        }

        SignalSpy {
            id: endpointsChangedSpy1
            target: myEndpoints1
            signalName: "endpointsChanged"
        }

        SignalSpy {
            id: endpointsCountSpy1
            target: myEndpoints1
            signalName: "countChanged"
        }

        SignalSpy {
            id: endpointsStatusSpy1
            target: myEndpoints1
            signalName: "statusChanged"
        }

        SignalSpy {
            id: connectedSpy1
            target: node1
            signalName: "readyToUseChanged"
        }

        function test_nodeTest() {
            compare(myServers1.count, 0);

            myServers1.discoveryUrl = OPCUA_DISCOVERY_URL;

            serversStatusSpy1.wait();
            compare(myServers1.status.status, QtOpcUa.Status.GoodCompletesAsynchronously);

            tryVerify(function() { return myServers1.count > 0;});
            compare(serversCountSpy1.count, 1);
            compare(serversChangedSpy1.count, 2);
            compare(myServers1.count, 1);
            verify(myServers1.at(0).discoveryUrls[0].startsWith("opc.tcp://"));

            compare(myEndpoints1.count, 0);

            myEndpoints1.serverUrl = myServers1.at(0).discoveryUrls[0];
            endpointsStatusSpy1.wait();
            compare(myEndpoints1.status.status, QtOpcUa.Status.GoodCompletesAsynchronously);
            compare(endpointsCountSpy1.count, 0);
            if (endpointsStatusSpy1.count == 1)
                endpointsStatusSpy1.wait();
            compare(endpointsStatusSpy1.count, 2);
            compare(endpointsChangedSpy1.count, 2);

            tryVerify(function() { return myEndpoints1.count > 0;});
            if (SERVER_SUPPORTS_SECURITY)
                compare(myEndpoints1.count, 7);
            else
                compare(myEndpoints1.count, 1);
            verify(myEndpoints1.at(0).endpointUrl.startsWith("opc.tcp://"));
            compare(myEndpoints1.at(0).securityPolicy, "http://opcfoundation.org/UA/SecurityPolicy#None");

            connection1.connectToEndpoint(myEndpoints1.at(0));

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

    CompletionLoggingTestCase {
        name: parent.parent.testName + ": " + backendName + ": Fetch data from discovery server using specified connection"
        when: shouldRun

        QtOpcUa.Connection {
            id: connection2
            backend: backendName
        }

        QtOpcUa.ServerDiscovery {
            connection: connection2
            id: myServers2
        }

        QtOpcUa.EndpointDiscovery {
            id: myEndpoints2
            connection: connection2
        }

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

        SignalSpy {
            id: serversChangedSpy2
            target: myServers2
            signalName: "serversChanged"
        }

        SignalSpy {
            id: serversCountSpy2
            target: myServers2
            signalName: "countChanged"
        }

        SignalSpy {
            id: serversStatusSpy2
            target: myServers2
            signalName: "statusChanged"
        }

        SignalSpy {
            id: endpointsChangedSpy2
            target: myEndpoints2
            signalName: "endpointsChanged"
        }

        SignalSpy {
            id: endpointsCountSpy2
            target: myEndpoints2
            signalName: "countChanged"
        }

        SignalSpy {
            id: endpointsStatusSpy2
            target: myEndpoints2
            signalName: "statusChanged"
        }

        SignalSpy {
            id: connectedSpy2
            target: node2
            signalName: "readyToUseChanged"
        }

        function test_nodeTest() {
            compare(myServers2.count, 0);

            myServers2.discoveryUrl = OPCUA_DISCOVERY_URL;

            serversStatusSpy2.wait();
            compare(myServers2.status.status, QtOpcUa.Status.GoodCompletesAsynchronously);

            tryVerify(function() { return myServers2.count > 0;});
            compare(serversStatusSpy2.count, 2);
            compare(serversChangedSpy2.count, 2);
            compare(myServers2.count, 1);
            verify(myServers2.at(0).discoveryUrls[0].startsWith("opc.tcp://"));

            myEndpoints2.serverUrl = myServers2.at(0).discoveryUrls[0];
            endpointsStatusSpy2.wait();
            compare(myEndpoints2.status.status, QtOpcUa.Status.GoodCompletesAsynchronously);

            tryVerify(function() { return myEndpoints2.count > 0;});
            compare(endpointsCountSpy2.count, 1);
            compare(endpointsStatusSpy2.count, 2);
            compare(endpointsChangedSpy2.count, 2);
            if (SERVER_SUPPORTS_SECURITY)
                compare(myEndpoints2.count, 7);
            else
                compare(myEndpoints2.count, 1);
            verify(myEndpoints2.at(0).endpointUrl.startsWith("opc.tcp://"));
            compare(myEndpoints2.at(0).securityPolicy, "http://opcfoundation.org/UA/SecurityPolicy#None");

            connection2.connectToEndpoint(myEndpoints2.at(0));

            connectedSpy2.wait();
            compare(node2.value, "Value", "");
            compare(node2.browseName, "theStringId");
        }
    }
}