summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJannis Voelker <jannis.voelker@basyskom.com>2017-12-13 08:32:41 +0100
committerFrank Meerkoetter <frank.meerkoetter@basyskom.com>2018-01-05 18:41:19 +0000
commit89fefd3c82a7bdd9a81d2da9058de3780e563f88 (patch)
treea776af816c303f228d4ffe3b2c58884a2cf26463 /tests
parent199563889d14098158e3d76fa5bc3a8c0b07f937 (diff)
Add support for index ranges in read and write operations
This patch adds index range support to readAttributes and writeAttribute in QOpcUaNode. In readAttributes, the index range is applied to all attributes. Change-Id: I38b929a0c5c050fbd6f8eace614bbafc50e67a2c Reviewed-by: Alex Blasche <alexander.blasche@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 507f071..87576f6 100644
--- a/tests/auto/qopcuaclient/tst_client.cpp
+++ b/tests/auto/qopcuaclient/tst_client.cpp
@@ -195,6 +195,10 @@ private slots:
void writeScalar();
defineDataMethod(readScalar_data)
void readScalar();
+ defineDataMethod(indexRange_data)
+ void indexRange();
+ defineDataMethod(invalidIndexRange_data)
+ void invalidIndexRange();
defineDataMethod(stringCharset_data)
void stringCharset();
@@ -1574,6 +1578,56 @@ void Tst_QOpcUaClient::readScalar()
QCOMPARE(xmlElementScalar.toString(), xmlElements[0]);
}
+void Tst_QOpcUaClient::indexRange()
+{
+ QFETCH(QOpcUaClient *, opcuaClient);
+ OpcuaConnector connector(opcuaClient, m_endpoint);
+
+ QScopedPointer<QOpcUaNode> node(opcuaClient->node("ns=2;s=Demo.Static.Arrays.Int32"));
+
+ QVariantList list({0, 1, 2, 3, 4, 5, 6, 7});
+
+ WRITE_VALUE_ATTRIBUTE(node, list, QOpcUa::Types::Int32);
+
+ QSignalSpy writeFinishedSpy(node.data(), &QOpcUaNode::attributeWritten);
+
+ node->writeAttributeRange(QOpcUaNode::NodeAttribute::Value, QVariantList({10, 11, 12, 13}), "0:3", QOpcUa::Types::Int32);
+ writeFinishedSpy.wait();
+ QCOMPARE(writeFinishedSpy.size(), 1);
+ QCOMPARE(writeFinishedSpy.at(0).at(1).value<QOpcUa::UaStatusCode>(), QOpcUa::UaStatusCode::Good);
+
+ QSignalSpy readFinishedSpy(node.data(), &QOpcUaNode::readFinished);
+ node->readAttributeRange(QOpcUaNode::NodeAttribute::Value, "0:6");
+ readFinishedSpy.wait();
+ QCOMPARE(readFinishedSpy.count(), 1);
+ QCOMPARE(node->attribute(QOpcUaNode::NodeAttribute::Value), QVariantList({10, 11, 12, 13, 4, 5, 6}));
+}
+
+void Tst_QOpcUaClient::invalidIndexRange()
+{
+ QFETCH(QOpcUaClient *, opcuaClient);
+ OpcuaConnector connector(opcuaClient, m_endpoint);
+
+ QScopedPointer<QOpcUaNode> node(opcuaClient->node("ns=2;s=Demo.Static.Arrays.Int32"));
+
+ QVariantList list({0, 1, 2, 3, 4, 5, 6, 7});
+
+ WRITE_VALUE_ATTRIBUTE(node, list, QOpcUa::Types::Int32);
+
+ QSignalSpy writeFinishedSpy(node.data(), &QOpcUaNode::attributeWritten);
+
+ node->writeAttributeRange(QOpcUaNode::NodeAttribute::Value, QVariantList({10, 11, 12, 13}), "notavalidrange", QOpcUa::Types::Int32);
+ writeFinishedSpy.wait();
+ QCOMPARE(writeFinishedSpy.size(), 1);
+ QCOMPARE(writeFinishedSpy.at(0).at(1).value<QOpcUa::UaStatusCode>(), QOpcUa::UaStatusCode::BadIndexRangeInvalid);
+
+ QSignalSpy readFinishedSpy(node.data(), &QOpcUaNode::readFinished);
+ node->readAttributeRange(QOpcUaNode::NodeAttribute::Value, "notavalidrange");
+ readFinishedSpy.wait();
+ QCOMPARE(readFinishedSpy.count(), 1);
+ QCOMPARE(node->attributeError(QOpcUaNode::NodeAttribute::Value), QOpcUa::UaStatusCode::BadIndexRangeInvalid);
+}
+
void Tst_QOpcUaClient::stringCharset()
{
QFETCH(QOpcUaClient *, opcuaClient);