summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJannis Voelker <jannis.voelker@basyskom.com>2018-02-20 09:16:38 +0100
committerMaurice Kalinowski <maurice.kalinowski@qt.io>2018-03-16 05:57:17 +0000
commitd4c3634267488aed7ef9badd5f269aedcc38af1f (patch)
tree7680d55172e305cbc118095ef909650c88b31f67 /tests
parent61f6ad6a5c16c46e4e56471a2306de7c72deca52 (diff)
Fix and extend support for modifyMonitoring in open62541
The open62541 backend now supports all parameters enumerated in QOpcUaMonitoringParameters::Parameter. Change-Id: I04bc55b57661ec9dcbeceac87b68d3324bc22dec 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.cpp209
1 files changed, 193 insertions, 16 deletions
diff --git a/tests/auto/qopcuaclient/tst_client.cpp b/tests/auto/qopcuaclient/tst_client.cpp
index 5326817..6eb6ee6 100644
--- a/tests/auto/qopcuaclient/tst_client.cpp
+++ b/tests/auto/qopcuaclient/tst_client.cpp
@@ -231,6 +231,13 @@ private slots:
void subscriptionIndexRange();
defineDataMethod(subscriptionDataChangeFilter_data)
void subscriptionDataChangeFilter();
+ defineDataMethod(modifyPublishingMode_data)
+ void modifyPublishingMode();
+ defineDataMethod(modifyMonitoringMode_data)
+ void modifyMonitoringMode();
+ defineDataMethod(modifyMonitoredItem_data)
+ void modifyMonitoredItem();
+
defineDataMethod(stringCharset_data)
void stringCharset();
@@ -670,20 +677,6 @@ void Tst_QOpcUaClient::dataChangeSubscription()
QCOMPARE(node->monitoringStatus(QOpcUa::NodeAttribute::Value).publishingInterval(), 200.0);
QCOMPARE(node->monitoringStatus(QOpcUa::NodeAttribute::DisplayName).publishingInterval(), 200.0);
-
- monitoringModifiedSpy.clear();
- QOpcUaMonitoringParameters::DataChangeFilter filter;
- filter.deadbandType = QOpcUaMonitoringParameters::DataChangeFilter::DeadbandType::Absolute;
- filter.trigger = QOpcUaMonitoringParameters::DataChangeFilter::DataChangeTrigger::StatusValue;
- filter.deadbandValue = 10;
- node->modifyMonitoring(QOpcUa::NodeAttribute::Value, QOpcUaMonitoringParameters::Parameter::Filter, QVariant::fromValue(filter));
- monitoringModifiedSpy.wait();
- QVERIFY(monitoringModifiedSpy.size() == 1);
- QVERIFY(monitoringModifiedSpy.at(0).at(0).value<QOpcUa::NodeAttribute>() == QOpcUa::NodeAttribute::Value);
- QVERIFY(monitoringModifiedSpy.at(0).at(1).value<QOpcUaMonitoringParameters::Parameters>() & QOpcUaMonitoringParameters::Parameter::Filter);
- QEXPECT_FAIL("", "Modifying monitored items is not yet supported by open62541/uacpp", Continue);
- QVERIFY(monitoringModifiedSpy.at(0).at(2).value<QOpcUa::UaStatusCode>() == QOpcUa::UaStatusCode::Good);
-
} else {
qDebug() << "Modifying monitoring settings is not supported by the freeopcua backend";
}
@@ -1869,15 +1862,79 @@ void Tst_QOpcUaClient::subscriptionDataChangeFilter()
QVERIFY(doubleNode != 0);
QOpcUaMonitoringParameters p(100);
+
+ QSignalSpy monitoringEnabledSpy(doubleNode.data(), &QOpcUaNode::enableMonitoringFinished);
+ QSignalSpy monitoringDisabledSpy(doubleNode.data(), &QOpcUaNode::disableMonitoringFinished);
+ QSignalSpy dataChangeSpy(doubleNode.data(), &QOpcUaNode::attributeUpdated);
+ QSignalSpy monitoringModifiedSpy(doubleNode.data(), &QOpcUaNode::monitoringStatusChanged);
+
+ WRITE_VALUE_ATTRIBUTE(doubleNode, 1.0, QOpcUa::Types::Double);
+
+ doubleNode->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
+ QCOMPARE(dataChangeSpy.size(), 1);
+ dataChangeSpy.clear();
+
+ WRITE_VALUE_ATTRIBUTE(doubleNode, 1.5, QOpcUa::Types::Double);
+
+ dataChangeSpy.wait();
+ QCOMPARE(dataChangeSpy.size(), 1); // Data change without filter
+ QCOMPARE(doubleNode->attribute(QOpcUa::NodeAttribute::Value), 1.5);
+ dataChangeSpy.clear();
+
QOpcUaMonitoringParameters::DataChangeFilter filter;
filter.deadbandType = QOpcUaMonitoringParameters::DataChangeFilter::DeadbandType::Absolute;
filter.trigger = QOpcUaMonitoringParameters::DataChangeFilter::DataChangeTrigger::StatusValue;
filter.deadbandValue = 1.0;
- p.setDataChangeFilter(filter);
+ doubleNode->modifyDataChangeFilter(QOpcUa::NodeAttribute::Value, filter);
+ monitoringModifiedSpy.wait();
+ QVERIFY(monitoringModifiedSpy.size() == 1);
+ QVERIFY(monitoringModifiedSpy.at(0).at(0).value<QOpcUa::NodeAttribute>() == QOpcUa::NodeAttribute::Value);
+ QVERIFY(monitoringModifiedSpy.at(0).at(1).value<QOpcUaMonitoringParameters::Parameters>() & QOpcUaMonitoringParameters::Parameter::Filter);
+ QVERIFY(monitoringModifiedSpy.at(0).at(2).value<QOpcUa::UaStatusCode>() == QOpcUa::UaStatusCode::Good);
+
+ WRITE_VALUE_ATTRIBUTE(doubleNode, 2.0, QOpcUa::Types::Double);
+
+ dataChangeSpy.wait();
+ QCOMPARE(dataChangeSpy.size(), 0); // Filter is active and delta is < 1
+
+ WRITE_VALUE_ATTRIBUTE(doubleNode, 3.0, QOpcUa::Types::Double);
+
+ dataChangeSpy.wait();
+ QCOMPARE(dataChangeSpy.size(), 1); // delta == 1, a data change is expected
+ QCOMPARE(doubleNode->attribute(QOpcUa::NodeAttribute::Value), 3.0);
+
+ doubleNode->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::modifyPublishingMode()
+{
+ QFETCH(QOpcUaClient *, opcuaClient);
+ OpcuaConnector connector(opcuaClient, m_endpoint);
+
+ if (opcuaClient->backend() == QLatin1String("freeopcua"))
+ QSKIP("Modification of monitoring is not supported in the freeopcua plugin");
+ if (opcuaClient->backend() == QLatin1String("uacpp"))
+ QSKIP("Modification of monitoring is not supported in the unified automation plugin");
+
+ QScopedPointer<QOpcUaNode> doubleNode(opcuaClient->node("ns=2;s=Demo.Static.Scalar.Double"));
+ QVERIFY(doubleNode != 0);
+
+ QOpcUaMonitoringParameters p(100);
QSignalSpy monitoringEnabledSpy(doubleNode.data(), &QOpcUaNode::enableMonitoringFinished);
QSignalSpy monitoringDisabledSpy(doubleNode.data(), &QOpcUaNode::disableMonitoringFinished);
QSignalSpy dataChangeSpy(doubleNode.data(), &QOpcUaNode::attributeUpdated);
+ QSignalSpy monitoringStatusSpy(doubleNode.data(), &QOpcUaNode::monitoringStatusChanged);
WRITE_VALUE_ATTRIBUTE(doubleNode, 1.0, QOpcUa::Types::Double);
@@ -1894,13 +1951,133 @@ void Tst_QOpcUaClient::subscriptionDataChangeFilter()
WRITE_VALUE_ATTRIBUTE(doubleNode, 1.5, QOpcUa::Types::Double);
dataChangeSpy.wait();
+ QCOMPARE(dataChangeSpy.size(), 1);
+ dataChangeSpy.clear();
+
+ doubleNode->modifyMonitoring(QOpcUa::NodeAttribute::Value, QOpcUaMonitoringParameters::Parameter::PublishingEnabled, false);
+ monitoringStatusSpy.wait();
+ QCOMPARE(monitoringStatusSpy.size(), 1);
+ QCOMPARE(monitoringStatusSpy.at(0).at(2).value<QOpcUa::UaStatusCode>(), QOpcUa::UaStatusCode::Good);
+
+ WRITE_VALUE_ATTRIBUTE(doubleNode, 3.0, QOpcUa::Types::Double);
+
+ dataChangeSpy.wait();
QCOMPARE(dataChangeSpy.size(), 0);
+ doubleNode->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::modifyMonitoringMode()
+{
+ QFETCH(QOpcUaClient *, opcuaClient);
+ OpcuaConnector connector(opcuaClient, m_endpoint);
+
+ if (opcuaClient->backend() == QLatin1String("freeopcua"))
+ QSKIP("Modification of monitoring is not supported in the freeopcua plugin");
+ if (opcuaClient->backend() == QLatin1String("uacpp"))
+ QSKIP("Modification of monitoring is not supported in the unified automation plugin");
+
+ QScopedPointer<QOpcUaNode> doubleNode(opcuaClient->node("ns=2;s=Demo.Static.Scalar.Double"));
+ QVERIFY(doubleNode != 0);
+
+ QOpcUaMonitoringParameters p(100);
+
+ QSignalSpy monitoringEnabledSpy(doubleNode.data(), &QOpcUaNode::enableMonitoringFinished);
+ QSignalSpy monitoringDisabledSpy(doubleNode.data(), &QOpcUaNode::disableMonitoringFinished);
+ QSignalSpy dataChangeSpy(doubleNode.data(), &QOpcUaNode::attributeUpdated);
+ QSignalSpy monitoringStatusSpy(doubleNode.data(), &QOpcUaNode::monitoringStatusChanged);
+
+ WRITE_VALUE_ATTRIBUTE(doubleNode, 1.0, QOpcUa::Types::Double);
+
+ doubleNode->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
+ QCOMPARE(dataChangeSpy.size(), 1);
+ dataChangeSpy.clear();
+
+ WRITE_VALUE_ATTRIBUTE(doubleNode, 1.5, QOpcUa::Types::Double);
+
+ dataChangeSpy.wait();
+ QCOMPARE(dataChangeSpy.size(), 1);
+ dataChangeSpy.clear();
+
+ doubleNode->modifyMonitoring(QOpcUa::NodeAttribute::Value, QOpcUaMonitoringParameters::Parameter::MonitoringMode,
+ QVariant::fromValue(QOpcUaMonitoringParameters::MonitoringMode::Disabled));
+ monitoringStatusSpy.wait();
+ QCOMPARE(monitoringStatusSpy.size(), 1);
+ QCOMPARE(monitoringStatusSpy.at(0).at(2).value<QOpcUa::UaStatusCode>(), QOpcUa::UaStatusCode::Good);
+
+ WRITE_VALUE_ATTRIBUTE(doubleNode, 3.0, QOpcUa::Types::Double);
+
+ dataChangeSpy.wait();
+ QCOMPARE(dataChangeSpy.size(), 0);
+
+ doubleNode->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::modifyMonitoredItem()
+{
+ QFETCH(QOpcUaClient *, opcuaClient);
+ OpcuaConnector connector(opcuaClient, m_endpoint);
+
+ if (opcuaClient->backend() == QLatin1String("freeopcua"))
+ QSKIP("Modification of monitoring is not supported in the freeopcua plugin");
+ if (opcuaClient->backend() == QLatin1String("uacpp"))
+ QSKIP("Modification of monitoring is not supported in the unified automation plugin");
+
+
+ QScopedPointer<QOpcUaNode> doubleNode(opcuaClient->node("ns=2;s=Demo.Static.Scalar.Double"));
+ QVERIFY(doubleNode != 0);
+
+ QOpcUaMonitoringParameters p(100);
+
+ QSignalSpy monitoringEnabledSpy(doubleNode.data(), &QOpcUaNode::enableMonitoringFinished);
+ QSignalSpy monitoringDisabledSpy(doubleNode.data(), &QOpcUaNode::disableMonitoringFinished);
+ QSignalSpy dataChangeSpy(doubleNode.data(), &QOpcUaNode::attributeUpdated);
+ QSignalSpy monitoringStatusSpy(doubleNode.data(), &QOpcUaNode::monitoringStatusChanged);
+
+ WRITE_VALUE_ATTRIBUTE(doubleNode, 1.0, QOpcUa::Types::Double);
+
+ doubleNode->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
+ QCOMPARE(dataChangeSpy.size(), 1);
+ dataChangeSpy.clear();
+
+ WRITE_VALUE_ATTRIBUTE(doubleNode, 1.5, QOpcUa::Types::Double);
+
+ dataChangeSpy.wait();
+ QCOMPARE(dataChangeSpy.size(), 1);
+ QCOMPARE(dataChangeSpy.at(0).at(1).value<double>(), 1.5);
+ dataChangeSpy.clear();
+
+ doubleNode->modifyMonitoring(QOpcUa::NodeAttribute::Value, QOpcUaMonitoringParameters::Parameter::SamplingInterval, 50.0);
+ monitoringStatusSpy.wait();
+ QCOMPARE(monitoringStatusSpy.size(), 1);
+ QCOMPARE(monitoringStatusSpy.at(0).at(2).value<QOpcUa::UaStatusCode>(), QOpcUa::UaStatusCode::Good);
+ QCOMPARE(monitoringStatusSpy.at(0).at(0).value<QOpcUa::NodeAttribute>(), QOpcUa::NodeAttribute::Value);
+ QVERIFY(monitoringStatusSpy.at(0).at(1).value<QOpcUaMonitoringParameters::Parameters>() & QOpcUaMonitoringParameters::Parameter::SamplingInterval);
+
WRITE_VALUE_ATTRIBUTE(doubleNode, 3.0, QOpcUa::Types::Double);
dataChangeSpy.wait();
QCOMPARE(dataChangeSpy.size(), 1);
- QCOMPARE(doubleNode->attribute(QOpcUa::NodeAttribute::Value), 3.0);
doubleNode->disableMonitoring(QOpcUa::NodeAttribute::Value);
monitoringDisabledSpy.wait();