summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJannis Voelker <jannis.voelker@basyskom.com>2018-02-06 14:48:23 +0100
committerJannis Völker <jannis.voelker@basyskom.com>2018-02-28 07:19:38 +0000
commit600ba0dcc3cd731fb55491f81ed533de9f7fb106 (patch)
tree4e3ad9c5c2debaa1fa3152c0e96dba14b38e0c50 /tests
parentf6ecf08115f6615b058cc7800246d5dc6dd54704 (diff)
Unify support for indexRange in monitored items in both backends
This patch adds support for indexRange to the open62541 backend and fixes the return value for arrays with just one element in the freeopcua backend. A test case checking for correct use of the index range is added to tst_client. Change-Id: I94862e48c1fe3380ce5208738d025a9d53720354 Reviewed-by: Alex Blasche <alexander.blasche@qt.io> Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io> Reviewed-by: Frank Meerkoetter <frank.meerkoetter@basyskom.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qopcuaclient/tst_client.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/auto/qopcuaclient/tst_client.cpp b/tests/auto/qopcuaclient/tst_client.cpp
index 732cb06..486a5dc 100644
--- a/tests/auto/qopcuaclient/tst_client.cpp
+++ b/tests/auto/qopcuaclient/tst_client.cpp
@@ -226,6 +226,8 @@ private slots:
void indexRange();
defineDataMethod(invalidIndexRange_data)
void invalidIndexRange();
+ defineDataMethod(subscriptionIndexRange_data)
+ void subscriptionIndexRange();
defineDataMethod(stringCharset_data)
void stringCharset();
@@ -1788,6 +1790,58 @@ void Tst_QOpcUaClient::invalidIndexRange()
QCOMPARE(node->attributeError(QOpcUa::NodeAttribute::Value), QOpcUa::UaStatusCode::BadIndexRangeInvalid);
}
+void Tst_QOpcUaClient::subscriptionIndexRange()
+{
+ QFETCH(QOpcUaClient *, opcuaClient);
+ OpcuaConnector connector(opcuaClient, m_endpoint);
+
+ QScopedPointer<QOpcUaNode> integerArrayNode(opcuaClient->node("ns=2;s=Demo.Static.Arrays.Int32"));
+ QVERIFY(integerArrayNode != 0);
+
+ QOpcUaMonitoringParameters p(100);
+ p.setIndexRange(QStringLiteral("1"));
+ QSignalSpy monitoringEnabledSpy(integerArrayNode.data(), &QOpcUaNode::enableMonitoringFinished);
+ QSignalSpy monitoringDisabledSpy(integerArrayNode.data(), &QOpcUaNode::disableMonitoringFinished);
+ QSignalSpy writeSpy(integerArrayNode.data(), &QOpcUaNode::attributeWritten);
+ QSignalSpy dataChangeSpy(integerArrayNode.data(), &QOpcUaNode::attributeUpdated);
+
+ QVariantList l({0, 1});
+ WRITE_VALUE_ATTRIBUTE(integerArrayNode, l, QOpcUa::Types::Int32);
+ writeSpy.clear();
+
+ integerArrayNode->enableMonitoring(QOpcUa::NodeAttribute::Value, p);
+ monitoringEnabledSpy.wait();
+ QCOMPARE(monitoringEnabledSpy.size(), 1);
+ QCOMPARE(monitoringEnabledSpy.at(0).at(0).value<QOpcUa::NodeAttribute>(), QOpcUa::NodeAttribute::Value);
+ QCOMPARE(monitoringEnabledSpy.at(0).at(1).value<QOpcUa::UaStatusCode>(), QOpcUa::UaStatusCode::Good);
+
+ dataChangeSpy.wait(); // Wait for the initial data change
+ dataChangeSpy.clear();
+ integerArrayNode->writeAttributeRange(QOpcUa::NodeAttribute::Value, 10, "0", QOpcUa::Types::Int32); // Write the first element of the array
+ writeSpy.wait();
+ QCOMPARE(writeSpy.size(), 1);
+ QCOMPARE(writeSpy.at(0).at(0).value<QOpcUa::NodeAttribute>(), QOpcUa::NodeAttribute::Value);
+ QCOMPARE(writeSpy.at(0).at(1).value<QOpcUa::UaStatusCode>(), QOpcUa::UaStatusCode::Good);
+ dataChangeSpy.wait();
+ QCOMPARE(dataChangeSpy.size(), 0);
+
+ writeSpy.clear();
+ integerArrayNode->writeAttributeRange(QOpcUa::NodeAttribute::Value, 10, "1", QOpcUa::Types::Int32); // Write the second element of the array
+ writeSpy.wait();
+ QCOMPARE(writeSpy.size(), 1);
+ QCOMPARE(writeSpy.at(0).at(0).value<QOpcUa::NodeAttribute>(), QOpcUa::NodeAttribute::Value);
+ QCOMPARE(writeSpy.at(0).at(1).value<QOpcUa::UaStatusCode>(), QOpcUa::UaStatusCode::Good);
+ dataChangeSpy.wait();
+ QCOMPARE(dataChangeSpy.size(), 1);
+ QCOMPARE(integerArrayNode->attribute(QOpcUa::NodeAttribute::Value), 10);
+
+ integerArrayNode->disableMonitoring(QOpcUa::NodeAttribute::Value);
+ monitoringDisabledSpy.wait();
+ QCOMPARE(monitoringDisabledSpy.size(), 1);
+ QCOMPARE(monitoringDisabledSpy.at(0).at(0).value<QOpcUa::NodeAttribute>(), QOpcUa::NodeAttribute::Value);
+ QCOMPARE(monitoringDisabledSpy.at(0).at(1).value<QOpcUa::UaStatusCode>(), QOpcUa::UaStatusCode::Good);
+}
+
void Tst_QOpcUaClient::stringCharset()
{
QFETCH(QOpcUaClient *, opcuaClient);