summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJannis Voelker <jannis.voelker@basyskom.com>2018-02-28 12:53:57 +0100
committerJannis Völker <jannis.voelker@basyskom.com>2018-03-06 08:14:00 +0000
commit2b6fc246794fe2c3f88a5e4f3365ec379ed3a20a (patch)
treed14e387b7f8f30830a55127f149bacec18f410b4 /tests
parent53d45c64ce06daedd99b9470b404f550821a832a (diff)
Fix DateTime conversion for uacpp and freeopcua
The OPC UA representation for DateTime is a uint64 containing the milliseconds since 1601-01-01, so the conversion in uacpp is wrong by many years. Freeopcua and uacpp both offer DateTime::toTime_t, but a time_t only has an accuracy of one second. This is why manual conversion like in the open62541 backend must be used. Change-Id: I644f061478dfab5266615ba91f45e179a8c2581a Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qopcuaclient/tst_client.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/auto/qopcuaclient/tst_client.cpp b/tests/auto/qopcuaclient/tst_client.cpp
index 486a5dc..ded212a 100644
--- a/tests/auto/qopcuaclient/tst_client.cpp
+++ b/tests/auto/qopcuaclient/tst_client.cpp
@@ -235,6 +235,9 @@ private slots:
defineDataMethod(namespaceArray_data)
void namespaceArray();
+ defineDataMethod(dateTimeConversion_data)
+ void dateTimeConversion();
+
// This test case restarts the server. It must be run last to avoid
// destroying state required by other test cases.
defineDataMethod(connectionLost_data)
@@ -1926,6 +1929,24 @@ void Tst_QOpcUaClient::namespaceArray()
QCOMPARE(node->attribute(QOpcUa::NodeAttribute::DisplayName).value<QOpcUa::QLocalizedText>().text, "ns=2;s=Demo.Static.Scalar.String");
}
+void Tst_QOpcUaClient::dateTimeConversion()
+{
+ QFETCH(QOpcUaClient *, opcuaClient);
+ OpcuaConnector connector(opcuaClient, m_endpoint);
+
+ QScopedPointer<QOpcUaNode> dateTimeScalarNode(opcuaClient->node("ns=2;s=Demo.Static.Scalar.DateTime"));
+
+ QVERIFY(dateTimeScalarNode != 0);
+
+ QDateTime dt = QDateTime::currentDateTime();
+
+ WRITE_VALUE_ATTRIBUTE(dateTimeScalarNode, dt, QOpcUa::Types::DateTime);
+ READ_MANDATORY_VARIABLE_NODE(dateTimeScalarNode);
+
+ QDateTime result = dateTimeScalarNode->attribute(QOpcUa::NodeAttribute::Value).toDateTime();
+ QVERIFY(dt == result);
+}
+
void Tst_QOpcUaClient::connectionLost()
{
// Restart the test server if necessary