summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJannis Voelker <jannis.voelker@basyskom.com>2017-11-16 10:59:50 +0100
committerFrank Meerkoetter <frank.meerkoetter@basyskom.com>2017-11-27 22:02:01 +0000
commit347abc58451cc5abffbc42e84349bcc1fa9cab78 (patch)
treeba01bb9a619465b3d1650a7be1ac0ff66e5e3017 /tests
parentab961e4e9edff13c98ce14923eb8bf749100da2a (diff)
Add support for the QualifiedName type
QualifiedName is mainly used for the BrowseName attribute. It can also be used as type for the value attribute of a variable node. This patch adds support for QualifiedName values to both backends. QualifiedName scalar and array variable nodes are added to the test server, the scalar and array tests are extended to verify correct value conversion. Change-Id: Ic678c7c774d6594fde8088450d00bfc829ea9743 Reviewed-by: Frank Meerkoetter <frank.meerkoetter@basyskom.com> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qopcuaclient/tst_client.cpp28
-rw-r--r--tests/open62541-testserver/main.cpp2
-rw-r--r--tests/open62541-testserver/testserver.cpp34
3 files changed, 64 insertions, 0 deletions
diff --git a/tests/auto/qopcuaclient/tst_client.cpp b/tests/auto/qopcuaclient/tst_client.cpp
index 2b490c1..0f7e6c6 100644
--- a/tests/auto/qopcuaclient/tst_client.cpp
+++ b/tests/auto/qopcuaclient/tst_client.cpp
@@ -902,6 +902,15 @@ void Tst_QOpcUaClient::writeArray()
success = node->setValue(list, QOpcUa::NodeId);
QVERIFY(success == true);
+ list.clear();
+ list.append(QVariant::fromValue(QOpcUa::QQualifiedName(0, "Test0")));
+ list.append(QVariant::fromValue(QOpcUa::QQualifiedName(1, "Test1")));
+ list.append(QVariant::fromValue(QOpcUa::QQualifiedName(2, "Test2")));
+ node.reset(opcuaClient->node("ns=2;s=Demo.Static.Arrays.QualifiedName"));
+ QVERIFY(node != 0);
+ success = node->setValue(list, QOpcUa::QualifiedName);
+ QVERIFY(success == true);
+
if (opcuaClient->backend() == QLatin1String("freeopcua"))
QSKIP("XmlElement support is not yet implemented in the freeopcua library");
@@ -1088,6 +1097,15 @@ void Tst_QOpcUaClient::readArray()
QCOMPARE(nodeIdArray.toList()[1].toString(), QStringLiteral("ns=0;i=1"));
QCOMPARE(nodeIdArray.toList()[2].toString(), QStringLiteral("ns=0;i=2"));
+ QScopedPointer<QOpcUaNode> qualifiedNameArrayNode(opcuaClient->node("ns=2;s=Demo.Static.Arrays.QualifiedName"));
+ QVERIFY(nodeIdArrayNode != 0);
+ QVariant qualifiedNameArray = qualifiedNameArrayNode->value();
+ QVERIFY(qualifiedNameArray.type() == QVariant::List);
+ QVERIFY(qualifiedNameArray.toList().length() == 3);
+ QVERIFY(qualifiedNameArray.toList()[0].value<QOpcUa::QQualifiedName>() == QOpcUa::QQualifiedName(0, "Test0"));
+ QVERIFY(qualifiedNameArray.toList()[1].value<QOpcUa::QQualifiedName>() == QOpcUa::QQualifiedName(1, "Test1"));
+ QVERIFY(qualifiedNameArray.toList()[2].value<QOpcUa::QQualifiedName>() == QOpcUa::QQualifiedName(2, "Test2"));
+
if (opcuaClient->backend() == QLatin1String("freeopcua"))
QSKIP("XmlElement support is not yet implemented in the freeopcua backend");
@@ -1200,6 +1218,11 @@ void Tst_QOpcUaClient::writeScalar()
success = nodeIdNode->setValue("ns=42;s=Test", QOpcUa::NodeId);
QVERIFY(success == true);
+ QScopedPointer<QOpcUaNode> qualifiedNameNode(opcuaClient->node("ns=2;s=Demo.Static.Scalar.QualifiedName"));
+ QVERIFY(qualifiedNameNode != 0);
+ success = qualifiedNameNode->setValue(QVariant::fromValue(QOpcUa::QQualifiedName(0, QLatin1String("Test0"))), QOpcUa::QualifiedName);
+ QVERIFY(success == true);
+
if (opcuaClient->backend() == QLatin1String("freeopcua"))
QSKIP("XmlElement support is not yet implemented in the freeopcua backend");
@@ -1353,6 +1376,11 @@ void Tst_QOpcUaClient::readScalar()
QCOMPARE(nodeIdScalar.type(), QVariant::String);
QCOMPARE(nodeIdScalar.toString(), QStringLiteral("ns=42;s=Test"));
+ node.reset(opcuaClient->node("ns=2;s=Demo.Static.Scalar.QualifiedName"));
+ QVERIFY(node != 0);
+ QCOMPARE(node->type(), QOpcUa::Types::QualifiedName);
+ QVERIFY(node->value().value<QOpcUa::QQualifiedName>() == QOpcUa::QQualifiedName(0, "Test0"));
+
if (opcuaClient->backend() == QLatin1String("freeopcua"))
QSKIP("XmlElement support is not yet implemented in the freeopcua backend");
diff --git a/tests/open62541-testserver/main.cpp b/tests/open62541-testserver/main.cpp
index b93360a..f703dc3 100644
--- a/tests/open62541-testserver/main.cpp
+++ b/tests/open62541-testserver/main.cpp
@@ -94,6 +94,7 @@ int main(int argc, char **argv)
server.addVariable<UA_NodeId, QString, UA_TYPES_NODEID>(testFolder, "ns=2;s=Demo.Static.Arrays.NodeId", "NodeIdArrayTest", QString());
server.addVariable<UA_Guid, QUuid, UA_TYPES_GUID>(testFolder, "ns=2;s=Demo.Static.Arrays.Guid", "GuidArrayTest", QUuid());
server.addVariable<UA_XmlElement, QString, UA_TYPES_XMLELEMENT>(testFolder, "ns=2;s=Demo.Static.Arrays.XmlElement", "XmlElementArrayTest", QString());
+ server.addVariable<UA_QualifiedName, QPair<quint16, QString>, UA_TYPES_QUALIFIEDNAME>(testFolder, "ns=2;s=Demo.Static.Arrays.QualifiedName", "QualifiedNameArrayTest", QPair<quint16, QString>());
server.addVariable<UA_Boolean, bool, UA_TYPES_BOOLEAN>(testFolder, "ns=2;s=Demo.Static.Scalar.Boolean", "BoolScalarTest", true);
server.addVariable<UA_Byte, uchar, UA_TYPES_BYTE>(testFolder, "ns=2;s=Demo.Static.Scalar.Byte", "ByteScalarTest", 0);
@@ -115,6 +116,7 @@ int main(int argc, char **argv)
server.addVariable<UA_String, QString, UA_TYPES_STRING>(testStringIdsFolder, "ns=3;s=theStringId", "theStringId", QString());
server.addVariable<UA_Guid, QUuid, UA_TYPES_GUID>(testFolder, "ns=2;s=Demo.Static.Scalar.Guid", "GuidScalarTest", QUuid());
server.addVariable<UA_XmlElement, QString, UA_TYPES_XMLELEMENT>(testFolder, "ns=2;s=Demo.Static.Scalar.XmlElement", "XmlElementScalarTest", QString());
+ server.addVariable<UA_QualifiedName, QPair<quint16, QString>, UA_TYPES_QUALIFIEDNAME>(testFolder, "ns=2;s=Demo.Static.Scalar.QualifiedName", "QualifiedNameScalarTest", QPair<quint16, QString>());
UA_NodeId testGuidIdsFolder = server.addFolder("ns=3;s=testGuidIdsFolder", "testGuidIdsFolder");
server.addVariable<UA_String, QString, UA_TYPES_STRING>(testGuidIdsFolder, "ns=3;g=08081e75-8e5e-319b-954f-f3a7613dc29b", "theGuidId", QString());
diff --git a/tests/open62541-testserver/testserver.cpp b/tests/open62541-testserver/testserver.cpp
index f77556d..ec6332a 100644
--- a/tests/open62541-testserver/testserver.cpp
+++ b/tests/open62541-testserver/testserver.cpp
@@ -428,6 +428,40 @@ UA_NodeId TestServer::addVariable<UA_String, QString, UA_TYPES_XMLELEMENT>(const
return resultId;
}
+template <>
+UA_NodeId TestServer::addVariable<UA_QualifiedName, QPair<quint16, QString>, UA_TYPES_QUALIFIEDNAME>(const UA_NodeId &folder, const QString &variableNode,
+ const QString &description, QPair<quint16, QString> value)
+{
+ UA_NodeId variableNodeId = Open62541Utils::nodeIdFromQString(variableNode);
+
+ UA_VariableAttributes attr = UA_VariableAttributes_default;
+ UA_QualifiedName uaValue;
+ uaValue.name = UA_String_fromChars(value.second.toUtf8().constData());
+ UA_Variant_setScalar(&attr.value, &uaValue, &UA_TYPES[UA_TYPES_QUALIFIEDNAME]);
+ attr.description = UA_LOCALIZEDTEXT_ALLOC("en_US", description.toUtf8().constData());
+ attr.displayName = UA_LOCALIZEDTEXT_ALLOC("en_US", variableNode.toUtf8().constData());
+ attr.dataType = UA_TYPES[UA_TYPES_QUALIFIEDNAME].typeId;
+ attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
+
+ UA_QualifiedName variableName = UA_QUALIFIEDNAME_ALLOC(variableNodeId.namespaceIndex, variableNode.toUtf8().constData());
+
+ UA_NodeId resultId;
+ UA_StatusCode result = UA_Server_addVariableNode(m_server,
+ variableNodeId,
+ folder,
+ UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
+ variableName,
+ UA_NODEID_NULL,
+ attr,
+ NULL,
+ &resultId);
+ if (result != UA_STATUSCODE_GOOD) {
+ qWarning() << "Could not add variable:" << result;
+ return UA_NODEID_NULL;
+ }
+ return resultId;
+}
+
template UA_NodeId TestServer::addVariable<UA_Double, double, UA_TYPES_DOUBLE>(const UA_NodeId &, const QString &, const QString &, double);
template UA_NodeId TestServer::addVariable<UA_Boolean, bool, UA_TYPES_BOOLEAN>(const UA_NodeId &, const QString &, const QString &, bool);
template UA_NodeId TestServer::addVariable<UA_Byte, uchar, UA_TYPES_BYTE>(const UA_NodeId &, const QString &, const QString &, uchar);