|
@@ -7,7 +7,6 @@
|
|
|
|
|
|
#include <string.h>
|
|
|
#include <math.h>
|
|
|
-#include <src_generated/ua_types_generated.h>
|
|
|
#include "src_generated/ua_types_generated.h"
|
|
|
#include "ua_types.h"
|
|
|
#include "src_generated/ua_types_generated_encoding_binary.h"
|
|
@@ -21,10 +20,6 @@
|
|
|
#include "ua_config_default.h"
|
|
|
#include "thread_wrapper.h"
|
|
|
|
|
|
-
|
|
|
-UA_NodeId connection1, connection2, writerGroup1, writerGroup2, writerGroup3,
|
|
|
- publishedDataSet1, publishedDataSet2, dataSetWriter1, dataSetWriter2, dataSetWriter3;
|
|
|
-
|
|
|
UA_Server *server = NULL;
|
|
|
UA_ServerConfig *config = NULL;
|
|
|
UA_Boolean running;
|
|
@@ -86,15 +81,7 @@ findSingleChildNode(UA_QualifiedName targetName,
|
|
|
return resultNodeId;
|
|
|
}
|
|
|
|
|
|
-START_TEST(AddNewPubSubConnectionUsingTheInformationModelMethod){
|
|
|
- UA_StatusCode retVal;
|
|
|
- UA_Client *client = UA_Client_new(UA_ClientConfig_default);
|
|
|
- retVal = UA_Client_connect(client, "opc.tcp://localhost:4840");
|
|
|
- if(retVal != UA_STATUSCODE_GOOD) {
|
|
|
- UA_Client_delete(client);
|
|
|
- }
|
|
|
- ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
|
|
|
-
|
|
|
+static UA_NodeId addPubSubConnection(void){
|
|
|
UA_Variant publisherId;
|
|
|
UA_Variant_init(&publisherId);
|
|
|
UA_UInt32 publisherIdValue = 13245;
|
|
@@ -137,33 +124,52 @@ START_TEST(AddNewPubSubConnectionUsingTheInformationModelMethod){
|
|
|
callMethodRequest.objectId = UA_NODEID_NUMERIC(0, UA_NS0ID_PUBLISHSUBSCRIBE);
|
|
|
callMethodRequest.methodId = UA_NODEID_NUMERIC(0, UA_NS0ID_PUBLISHSUBSCRIBE_ADDCONNECTION);
|
|
|
|
|
|
+ UA_NodeId connectionId = UA_NODEID_NULL;
|
|
|
UA_CallMethodResult result;
|
|
|
UA_CallMethodResult_init(&result);
|
|
|
result = UA_Server_call(server, &callMethodRequest);
|
|
|
ck_assert_int_eq(1, result.outputArgumentsSize);
|
|
|
ck_assert_int_eq(result.statusCode, UA_STATUSCODE_GOOD);
|
|
|
- UA_NodeId createdConnection;
|
|
|
if(result.outputArguments->type == &UA_TYPES[UA_TYPES_NODEID])
|
|
|
- createdConnection = *((UA_NodeId *) result.outputArguments->data);
|
|
|
+ connectionId = *((UA_NodeId *) result.outputArguments->data);
|
|
|
+ UA_ExtensionObject_deleteMembers(&eo);
|
|
|
+ callMethodRequest.inputArguments = NULL;
|
|
|
+ callMethodRequest.inputArgumentsSize = 0;
|
|
|
+ UA_CallMethodRequest_deleteMembers(&callMethodRequest);
|
|
|
+ UA_CallMethodResult_deleteMembers(&result);
|
|
|
+ return connectionId;
|
|
|
+}
|
|
|
+
|
|
|
+START_TEST(AddNewPubSubConnectionUsingTheInformationModelMethod){
|
|
|
+ UA_StatusCode retVal;
|
|
|
+ UA_Client *client = UA_Client_new(UA_ClientConfig_default);
|
|
|
+ retVal = UA_Client_connect(client, "opc.tcp://localhost:4840");
|
|
|
+ if(retVal != UA_STATUSCODE_GOOD) {
|
|
|
+ UA_Client_delete(client);
|
|
|
+ }
|
|
|
+ ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
|
|
|
+
|
|
|
+ UA_NodeId createdConnection = addPubSubConnection();
|
|
|
UA_LocalizedText connectionDisplayName;
|
|
|
UA_LocalizedText_init(&connectionDisplayName);
|
|
|
retVal = UA_Server_readDisplayName(server, createdConnection, &connectionDisplayName);
|
|
|
ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
|
|
|
- ck_assert_str_eq((const char *) connectionDisplayName.text.data, "Model Connection 1");
|
|
|
+ UA_String compareText = UA_STRING("Model Connection 1");
|
|
|
+ ck_assert(UA_String_equal(&connectionDisplayName.text, &compareText) == UA_TRUE);
|
|
|
//todo browse and check childs
|
|
|
|
|
|
UA_Variant serverPubSubConnectionValues;
|
|
|
UA_Variant_init(&serverPubSubConnectionValues);
|
|
|
- /*UA_NodeId connectionAddress = findSingleChildNode(UA_QUALIFIEDNAME(0, "Address"),
|
|
|
- UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
|
|
|
- createdConnection);*/
|
|
|
UA_NodeId connectionPublisherId = findSingleChildNode(UA_QUALIFIEDNAME(0, "PublisherId"),
|
|
|
UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY),
|
|
|
createdConnection);
|
|
|
ck_assert_int_eq(UA_Server_readValue(server, connectionPublisherId, &serverPubSubConnectionValues),
|
|
|
UA_STATUSCODE_GOOD);
|
|
|
- ck_assert_uint_eq(*((UA_UInt32 *) serverPubSubConnectionValues.data), publisherIdValue);
|
|
|
-
|
|
|
+ ck_assert_uint_eq(*((UA_UInt32 *) serverPubSubConnectionValues.data), 13245);
|
|
|
+ UA_Variant_deleteMembers(&serverPubSubConnectionValues);
|
|
|
+ UA_Client_disconnect(client);
|
|
|
+ UA_Client_delete(client);
|
|
|
+ UA_LocalizedText_deleteMembers(&connectionDisplayName);
|
|
|
} END_TEST
|
|
|
|
|
|
START_TEST(AddAndRemovePublishedDataSetFolders){
|
|
@@ -200,11 +206,13 @@ START_TEST(AddAndRemovePublishedDataSetFolders){
|
|
|
UA_LocalizedText_init(&connectionDisplayName);
|
|
|
retVal = UA_Server_readDisplayName(server, createdFolder, &connectionDisplayName);
|
|
|
ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
|
|
|
- ck_assert_str_eq((const char *) connectionDisplayName.text.data, "TestFolder");
|
|
|
+ UA_String compareText = UA_STRING("TestFolder");
|
|
|
+ ck_assert(UA_String_equal(&connectionDisplayName.text, &compareText) == UA_TRUE);
|
|
|
retVal = UA_Server_readNodeId(server, createdFolder, &createdFolder);
|
|
|
ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
|
|
|
+ UA_CallMethodResult_deleteMembers(&result);
|
|
|
+ UA_LocalizedText_deleteMembers(&connectionDisplayName);
|
|
|
|
|
|
- //TODO add folder inside the created folder
|
|
|
//create folder inside the new folder
|
|
|
folderName = UA_STRING("TestFolder2");
|
|
|
UA_Variant_init(&inputArguments);
|
|
@@ -224,9 +232,11 @@ START_TEST(AddAndRemovePublishedDataSetFolders){
|
|
|
UA_LocalizedText_init(&connectionDisplayName);
|
|
|
retVal = UA_Server_readDisplayName(server, createdFolder2, &connectionDisplayName);
|
|
|
ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
|
|
|
- ck_assert_str_eq((const char *) connectionDisplayName.text.data, "TestFolder2");
|
|
|
+ compareText = UA_STRING("TestFolder2");
|
|
|
+ ck_assert(UA_String_equal(&connectionDisplayName.text, &compareText) == UA_TRUE);
|
|
|
retVal = UA_Server_readNodeId(server, createdFolder2, &createdFolder2);
|
|
|
ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
|
|
|
+ UA_CallMethodResult_deleteMembers(&result);
|
|
|
|
|
|
//delete the folder
|
|
|
UA_Variant_init(&inputArguments);
|
|
@@ -244,16 +254,122 @@ START_TEST(AddAndRemovePublishedDataSetFolders){
|
|
|
retVal = UA_Server_readNodeId(server, createdFolder, NULL);
|
|
|
ck_assert_int_eq(retVal, UA_STATUSCODE_BADNODEIDUNKNOWN);
|
|
|
|
|
|
-
|
|
|
+ UA_CallMethodResult_deleteMembers(&result);
|
|
|
+ UA_Client_disconnect(client);
|
|
|
+ UA_Client_delete(client);
|
|
|
+ UA_LocalizedText_deleteMembers(&connectionDisplayName);
|
|
|
} END_TEST
|
|
|
|
|
|
+START_TEST(AddAndRemovePublishedDataSetItems){
|
|
|
+ UA_StatusCode retVal;
|
|
|
+ UA_Client *client = UA_Client_new(UA_ClientConfig_default);
|
|
|
+ retVal = UA_Client_connect(client, "opc.tcp://localhost:4840");
|
|
|
+ if(retVal != UA_STATUSCODE_GOOD) {
|
|
|
+ UA_Client_delete(client);
|
|
|
+ }
|
|
|
+ ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
|
|
|
+
|
|
|
+ UA_Variant *inputArguments = (UA_Variant *) UA_calloc(4, (sizeof(UA_Variant)));
|
|
|
+
|
|
|
+ UA_String pdsName = UA_STRING("Test PDS");
|
|
|
+ UA_Variant_setScalar(&inputArguments[0], &pdsName, &UA_TYPES[UA_TYPES_STRING]);
|
|
|
+
|
|
|
+ UA_String *fieldNameAliases = (UA_String *) UA_calloc(2, sizeof(UA_String));
|
|
|
+ fieldNameAliases[0] = UA_STRING("field1");
|
|
|
+ fieldNameAliases[1] = UA_STRING("field2");
|
|
|
+ UA_Variant_setArray(&inputArguments[1], fieldNameAliases, 2, &UA_TYPES[UA_TYPES_STRING]);
|
|
|
+
|
|
|
+ UA_DataSetFieldFlags *dataSetFieldFlags = (UA_DataSetFieldFlags *) UA_calloc(2, sizeof(UA_DataSetFieldFlags));
|
|
|
+ dataSetFieldFlags[0] = UA_DATASETFIELDFLAGS_PROMOTEDFIELD;
|
|
|
+ dataSetFieldFlags[1] = UA_DATASETFIELDFLAGS_PROMOTEDFIELD;
|
|
|
+ UA_Variant_setArray(&inputArguments[2], dataSetFieldFlags, 2, &UA_TYPES[UA_TYPES_DATASETFIELDFLAGS]);
|
|
|
+
|
|
|
+ UA_PublishedVariableDataType *variablesToAdd = (UA_PublishedVariableDataType *) UA_calloc(2, sizeof(UA_PublishedVariableDataType));
|
|
|
+ variablesToAdd[0].publishedVariable = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_LOCALTIME);
|
|
|
+ variablesToAdd[0].attributeId = UA_ATTRIBUTEID_VALUE;
|
|
|
+ variablesToAdd[1].publishedVariable = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERREDUNDANCY_CURRENTSERVERID);
|
|
|
+ variablesToAdd[1].attributeId = UA_ATTRIBUTEID_VALUE;
|
|
|
+ UA_Variant_setArray(&inputArguments[3], variablesToAdd, 2, &UA_TYPES[UA_TYPES_PUBLISHEDVARIABLEDATATYPE]);
|
|
|
+
|
|
|
+ UA_CallMethodRequest callMethodRequest;
|
|
|
+ UA_CallMethodRequest_init(&callMethodRequest);
|
|
|
+ callMethodRequest.inputArgumentsSize = 4;
|
|
|
+ callMethodRequest.inputArguments = inputArguments;
|
|
|
+ callMethodRequest.objectId = UA_NODEID_NUMERIC(0, UA_NS0ID_PUBLISHSUBSCRIBE_PUBLISHEDDATASETS);
|
|
|
+ callMethodRequest.methodId = UA_NODEID_NUMERIC(0, UA_NS0ID_DATASETFOLDERTYPE_ADDPUBLISHEDDATAITEMS);
|
|
|
+
|
|
|
+ UA_CallMethodResult result;
|
|
|
+ UA_CallMethodResult_init(&result);
|
|
|
+ result = UA_Server_call(server, &callMethodRequest);
|
|
|
+ ck_assert_int_eq(3, result.outputArgumentsSize);
|
|
|
+ ck_assert_int_eq(result.statusCode, UA_STATUSCODE_GOOD);
|
|
|
+
|
|
|
+ //TODO checked correctness of created items
|
|
|
+ UA_CallMethodResult_deleteMembers(&result);
|
|
|
+ UA_free(inputArguments);
|
|
|
+ UA_free(fieldNameAliases);
|
|
|
+ UA_free(dataSetFieldFlags);
|
|
|
+ UA_free(variablesToAdd);
|
|
|
+ UA_Client_disconnect(client);
|
|
|
+ UA_Client_delete(client);
|
|
|
+} END_TEST
|
|
|
+
|
|
|
+START_TEST(AddAndRemoveWriterGroups){
|
|
|
+ UA_StatusCode retVal;
|
|
|
+ UA_Client *client = UA_Client_new(UA_ClientConfig_default);
|
|
|
+ retVal = UA_Client_connect(client, "opc.tcp://localhost:4840");
|
|
|
+ if(retVal != UA_STATUSCODE_GOOD) {
|
|
|
+ UA_Client_delete(client);
|
|
|
+ }
|
|
|
+ ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
|
|
|
+ UA_NodeId createdConnection = addPubSubConnection();
|
|
|
+
|
|
|
+ UA_Variant *inputArgument = (UA_Variant *) UA_calloc(1, (sizeof(UA_Variant)));
|
|
|
+ UA_WriterGroupDataType writerGroupDataType;
|
|
|
+ UA_WriterGroupDataType_init(&writerGroupDataType);
|
|
|
+ writerGroupDataType.name = UA_STRING("TestWriterGroup");
|
|
|
+ writerGroupDataType.enabled = UA_TRUE;
|
|
|
+ writerGroupDataType.publishingInterval = 500;
|
|
|
+ writerGroupDataType.writerGroupId = 1234;
|
|
|
+ UA_Variant_setScalar(inputArgument, &writerGroupDataType, &UA_TYPES[UA_TYPES_WRITERGROUPDATATYPE]);
|
|
|
+
|
|
|
+ UA_CallMethodRequest callMethodRequest;
|
|
|
+ UA_CallMethodRequest_init(&callMethodRequest);
|
|
|
+ callMethodRequest.inputArgumentsSize = 1;
|
|
|
+ callMethodRequest.inputArguments = inputArgument;
|
|
|
+ callMethodRequest.objectId = createdConnection;
|
|
|
+ callMethodRequest.methodId = UA_NODEID_NUMERIC(0, UA_NS0ID_PUBSUBCONNECTIONTYPE_ADDWRITERGROUP);
|
|
|
+
|
|
|
+ UA_CallMethodResult result;
|
|
|
+ UA_CallMethodResult_init(&result);
|
|
|
+ result = UA_Server_call(server, &callMethodRequest);
|
|
|
+ ck_assert_int_eq(result.statusCode, UA_STATUSCODE_GOOD);
|
|
|
+ ck_assert_int_eq(1, result.outputArgumentsSize);
|
|
|
+
|
|
|
+ UA_NodeId createdWriterGroup;
|
|
|
+ if(result.outputArguments->type == &UA_TYPES[UA_TYPES_NODEID])
|
|
|
+ createdWriterGroup = *((UA_NodeId *) result.outputArguments->data);
|
|
|
+ UA_LocalizedText writerGroupDisplayName;
|
|
|
+ UA_LocalizedText_init(&writerGroupDisplayName);
|
|
|
+ retVal = UA_Server_readDisplayName(server, createdWriterGroup, &writerGroupDisplayName);
|
|
|
+ ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
|
|
|
+ UA_String compareText = UA_STRING("TestWriterGroup");
|
|
|
+ ck_assert(UA_String_equal(&writerGroupDisplayName.text, &compareText) == UA_TRUE);
|
|
|
+ UA_free(inputArgument);
|
|
|
+ UA_CallMethodResult_deleteMembers(&result);
|
|
|
+ UA_Client_disconnect(client);
|
|
|
+ UA_Client_delete(client);
|
|
|
+ UA_LocalizedText_deleteMembers(&writerGroupDisplayName);
|
|
|
+} END_TEST
|
|
|
+
|
|
|
int main(void) {
|
|
|
TCase *tc_add_pubsub_informationmodel_methods_connection = tcase_create("PubSub connection delete and creation using the information model methods");
|
|
|
tcase_add_checked_fixture(tc_add_pubsub_informationmodel_methods_connection, setup, teardown);
|
|
|
tcase_add_test(tc_add_pubsub_informationmodel_methods_connection, AddNewPubSubConnectionUsingTheInformationModelMethod);
|
|
|
tcase_add_test(tc_add_pubsub_informationmodel_methods_connection, AddAndRemovePublishedDataSetFolders);
|
|
|
-
|
|
|
-
|
|
|
+ tcase_add_test(tc_add_pubsub_informationmodel_methods_connection, AddAndRemovePublishedDataSetItems);
|
|
|
+ tcase_add_test(tc_add_pubsub_informationmodel_methods_connection, AddAndRemoveWriterGroups);
|
|
|
+ //TODO TestCase add publishedDataItems and removePublishedDataItems, writergroup remove
|
|
|
|
|
|
Suite *s = suite_create("PubSub CRUD configuration by the information model functions");
|
|
|
suite_add_tcase(s, tc_add_pubsub_informationmodel_methods_connection);
|