check_pubsub_config_freeze.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. *
  5. * Copyright (c) 2019 Fraunhofer IOSB (Author: Andreas Ebner)
  6. */
  7. #include <open62541/plugin/pubsub_udp.h>
  8. #include <open62541/server_config_default.h>
  9. #include <open62541/server_pubsub.h>
  10. #include <open62541/types_generated_encoding_binary.h>
  11. #include "ua_server_internal.h"
  12. #include <check.h>
  13. #include <stdio.h>
  14. #include <time.h>
  15. UA_Server *server = NULL;
  16. static void setup(void) {
  17. server = UA_Server_new();
  18. UA_ServerConfig *config = UA_Server_getConfig(server);
  19. UA_ServerConfig_setDefault(config);
  20. config->pubsubTransportLayers = (UA_PubSubTransportLayer*)
  21. UA_malloc(sizeof(UA_PubSubTransportLayer));
  22. config->pubsubTransportLayers[0] = UA_PubSubTransportLayerUDPMP();
  23. config->pubsubTransportLayersSize++;
  24. UA_Server_run_startup(server);
  25. }
  26. static void teardown(void) {
  27. UA_Server_run_shutdown(server);
  28. UA_Server_delete(server);
  29. }
  30. START_TEST(CreateAndLockConfiguration) {
  31. //create config
  32. UA_NodeId connection1, writerGroup1, publishedDataSet1, dataSetWriter1, dataSetField1;
  33. UA_PubSubConnectionConfig connectionConfig;
  34. memset(&connectionConfig, 0, sizeof(UA_PubSubConnectionConfig));
  35. connectionConfig.name = UA_STRING("UADP Connection");
  36. UA_NetworkAddressUrlDataType networkAddressUrl = {UA_STRING_NULL, UA_STRING("opc.udp://224.0.0.22:4840/")};
  37. UA_Variant_setScalar(&connectionConfig.address, &networkAddressUrl,
  38. &UA_TYPES[UA_TYPES_NETWORKADDRESSURLDATATYPE]);
  39. connectionConfig.transportProfileUri = UA_STRING("http://opcfoundation.org/UA-Profile/Transport/pubsub-udp-uadp");
  40. UA_Server_addPubSubConnection(server, &connectionConfig, &connection1);
  41. UA_WriterGroupConfig writerGroupConfig;
  42. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  43. writerGroupConfig.name = UA_STRING("WriterGroup 1");
  44. writerGroupConfig.publishingInterval = 10;
  45. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  46. writerGroupConfig.rtLevel = UA_PUBSUB_RT_NONE;
  47. UA_Server_addWriterGroup(server, connection1, &writerGroupConfig, &writerGroup1);
  48. UA_PublishedDataSetConfig pdsConfig;
  49. memset(&pdsConfig, 0, sizeof(UA_PublishedDataSetConfig));
  50. pdsConfig.publishedDataSetType = UA_PUBSUB_DATASET_PUBLISHEDITEMS;
  51. pdsConfig.name = UA_STRING("PublishedDataSet 1");
  52. UA_Server_addPublishedDataSet(server, &pdsConfig, &publishedDataSet1);
  53. UA_DataSetFieldConfig fieldConfig;
  54. memset(&fieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  55. fieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  56. fieldConfig.field.variable.fieldNameAlias = UA_STRING("field 1");
  57. UA_Server_addDataSetField(server, publishedDataSet1, &fieldConfig, &dataSetField1);
  58. UA_DataSetField *dataSetField = UA_DataSetField_findDSFbyId(server, dataSetField1);
  59. ck_assert(dataSetField->config.configurationFrozen == UA_FALSE);
  60. //get internal WG Pointer
  61. UA_WriterGroup *writerGroup = UA_WriterGroup_findWGbyId(server, writerGroup1);
  62. ck_assert(writerGroup->state == UA_PUBSUBSTATE_DISABLED);
  63. UA_DataSetMetaDataType dataSetMetaDataType;
  64. UA_DataSetMetaDataType_init(&dataSetMetaDataType);
  65. ck_assert(UA_Server_getPublishedDataSetMetaData(server, publishedDataSet1, &dataSetMetaDataType) == UA_STATUSCODE_GOOD);
  66. UA_DataSetMetaDataType_deleteMembers(&dataSetMetaDataType);
  67. UA_PublishedDataSetConfig publishedDataSetConfig;
  68. memset(&publishedDataSetConfig, 0, sizeof(UA_PublishedDataSetConfig));
  69. publishedDataSetConfig.publishedDataSetType = UA_PUBSUB_DATASET_PUBLISHEDITEMS_TEMPLATE;
  70. UA_DataSetMetaDataType metaDataType;
  71. UA_DataSetMetaDataType_init(&metaDataType);
  72. publishedDataSetConfig.config.itemsTemplate.metaData = metaDataType;
  73. publishedDataSetConfig.config.itemsTemplate.variablesToAddSize = 1;
  74. publishedDataSetConfig.config.itemsTemplate.variablesToAdd = UA_PublishedVariableDataType_new();
  75. UA_PublishedDataSetConfig_clear(&publishedDataSetConfig);
  76. UA_DataSetWriterConfig dataSetWriterConfig;
  77. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  78. dataSetWriterConfig.name = UA_STRING("DataSetWriter 1");
  79. UA_Server_addDataSetWriter(server, writerGroup1, publishedDataSet1, &dataSetWriterConfig, &dataSetWriter1);
  80. UA_DataSetWriter *dataSetWriter = UA_DataSetWriter_findDSWbyId(server, dataSetWriter1);
  81. ck_assert(dataSetWriter != NULL);
  82. //get internal PubSubConnection Pointer
  83. UA_PubSubConnection *pubSubConnection = UA_PubSubConnection_findConnectionbyId(server, connection1);
  84. ck_assert(pubSubConnection != NULL);
  85. ck_assert(dataSetWriter->config.configurationFrozen == UA_FALSE);
  86. //Lock the writer group and the child pubsub entities
  87. UA_Server_freezeWriterGroupConfiguration(server, writerGroup1);
  88. ck_assert(dataSetWriter->config.configurationFrozen == UA_TRUE);
  89. ck_assert(dataSetField->config.configurationFrozen == UA_TRUE);
  90. ck_assert(pubSubConnection->config->configurationFrozen == UA_TRUE);
  91. UA_PublishedDataSet *publishedDataSet = UA_PublishedDataSet_findPDSbyId(server, dataSetWriter->connectedDataSet);
  92. ck_assert(publishedDataSet->config.configurationFrozen == UA_TRUE);
  93. UA_DataSetField *dsf;
  94. TAILQ_FOREACH(dsf ,&publishedDataSet->fields , listEntry){
  95. ck_assert(dsf->config.configurationFrozen == UA_TRUE);
  96. }
  97. //set state to disabled and implicit unlock the configuration
  98. UA_Server_unfreezeWriterGroupConfiguration(server, writerGroup1);
  99. } END_TEST
  100. START_TEST(CreateAndLockConfigurationWithExternalAPI) {
  101. //create config
  102. UA_NodeId connection1, writerGroup1, publishedDataSet1, dataSetWriter1, dataSetField1;
  103. UA_PubSubConnectionConfig connectionConfig;
  104. memset(&connectionConfig, 0, sizeof(UA_PubSubConnectionConfig));
  105. connectionConfig.name = UA_STRING("UADP Connection");
  106. UA_NetworkAddressUrlDataType networkAddressUrl = {UA_STRING_NULL, UA_STRING("opc.udp://224.0.0.22:4840/")};
  107. UA_Variant_setScalar(&connectionConfig.address, &networkAddressUrl,
  108. &UA_TYPES[UA_TYPES_NETWORKADDRESSURLDATATYPE]);
  109. connectionConfig.transportProfileUri = UA_STRING("http://opcfoundation.org/UA-Profile/Transport/pubsub-udp-uadp");
  110. UA_Server_addPubSubConnection(server, &connectionConfig, &connection1);
  111. UA_WriterGroupConfig writerGroupConfig;
  112. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  113. writerGroupConfig.name = UA_STRING("WriterGroup 1");
  114. writerGroupConfig.publishingInterval = 10;
  115. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  116. writerGroupConfig.rtLevel = UA_PUBSUB_RT_NONE;
  117. UA_Server_addWriterGroup(server, connection1, &writerGroupConfig, &writerGroup1);
  118. UA_PublishedDataSetConfig pdsConfig;
  119. memset(&pdsConfig, 0, sizeof(UA_PublishedDataSetConfig));
  120. pdsConfig.publishedDataSetType = UA_PUBSUB_DATASET_PUBLISHEDITEMS;
  121. pdsConfig.name = UA_STRING("PublishedDataSet 1");
  122. UA_Server_addPublishedDataSet(server, &pdsConfig, &publishedDataSet1);
  123. UA_DataSetFieldConfig fieldConfig;
  124. memset(&fieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  125. fieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  126. fieldConfig.field.variable.fieldNameAlias = UA_STRING("field 1");
  127. UA_Server_addDataSetField(server, publishedDataSet1, &fieldConfig, &dataSetField1);
  128. UA_DataSetField *dataSetField = UA_DataSetField_findDSFbyId(server, dataSetField1);
  129. ck_assert(dataSetField->config.configurationFrozen == UA_FALSE);
  130. //get internal WG Pointer
  131. UA_WriterGroup *writerGroup = UA_WriterGroup_findWGbyId(server, writerGroup1);
  132. ck_assert(writerGroup->state == UA_PUBSUBSTATE_DISABLED);
  133. UA_DataSetWriterConfig dataSetWriterConfig;
  134. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  135. dataSetWriterConfig.name = UA_STRING("DataSetWriter 1");
  136. UA_Server_addDataSetWriter(server, writerGroup1, publishedDataSet1, &dataSetWriterConfig, &dataSetWriter1);
  137. UA_DataSetWriter *dataSetWriter = UA_DataSetWriter_findDSWbyId(server, dataSetWriter1);
  138. ck_assert(dataSetWriter != NULL);
  139. //get internal PubSubConnection Pointer
  140. UA_PubSubConnection *pubSubConnection = UA_PubSubConnection_findConnectionbyId(server, connection1);
  141. ck_assert(dataSetWriter->config.configurationFrozen == UA_FALSE);
  142. //Lock the with the freeze function
  143. UA_Server_freezeWriterGroupConfiguration(server, writerGroup1);
  144. ck_assert(dataSetWriter->config.configurationFrozen == UA_TRUE);
  145. ck_assert(dataSetField->config.configurationFrozen == UA_TRUE);
  146. ck_assert(pubSubConnection->config->configurationFrozen == UA_TRUE);
  147. UA_PublishedDataSet *publishedDataSet = UA_PublishedDataSet_findPDSbyId(server, dataSetWriter->connectedDataSet);
  148. ck_assert(publishedDataSet->config.configurationFrozen == UA_TRUE);
  149. UA_DataSetField *dsf;
  150. TAILQ_FOREACH(dsf ,&publishedDataSet->fields , listEntry){
  151. ck_assert(dsf->config.configurationFrozen == UA_TRUE);
  152. }
  153. //set state to disabled and implicit unlock the configuration
  154. UA_Server_unfreezeWriterGroupConfiguration(server, writerGroup1);
  155. } END_TEST
  156. START_TEST(CreateAndReleaseMultiplePDSLocks) {
  157. //create config
  158. UA_NodeId connection1, writerGroup1, writerGroup2, publishedDataSet1, dataSetWriter1, dataSetWriter2, dataSetWriter3, dataSetField1;
  159. UA_PubSubConnectionConfig connectionConfig;
  160. memset(&connectionConfig, 0, sizeof(UA_PubSubConnectionConfig));
  161. connectionConfig.name = UA_STRING("UADP Connection");
  162. UA_NetworkAddressUrlDataType networkAddressUrl = {UA_STRING_NULL, UA_STRING("opc.udp://224.0.0.22:4840/")};
  163. UA_Variant_setScalar(&connectionConfig.address, &networkAddressUrl,
  164. &UA_TYPES[UA_TYPES_NETWORKADDRESSURLDATATYPE]);
  165. connectionConfig.transportProfileUri = UA_STRING("http://opcfoundation.org/UA-Profile/Transport/pubsub-udp-uadp");
  166. UA_Server_addPubSubConnection(server, &connectionConfig, &connection1);
  167. //Add two writer groups
  168. UA_WriterGroupConfig writerGroupConfig;
  169. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  170. writerGroupConfig.name = UA_STRING("WriterGroup 1");
  171. writerGroupConfig.publishingInterval = 10;
  172. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  173. writerGroupConfig.rtLevel = UA_PUBSUB_RT_NONE;
  174. UA_Server_addWriterGroup(server, connection1, &writerGroupConfig, &writerGroup1);
  175. writerGroupConfig.name = UA_STRING("WriterGroup 2");
  176. UA_Server_addWriterGroup(server, connection1, &writerGroupConfig, &writerGroup2);
  177. UA_PublishedDataSetConfig pdsConfig;
  178. memset(&pdsConfig, 0, sizeof(UA_PublishedDataSetConfig));
  179. pdsConfig.publishedDataSetType = UA_PUBSUB_DATASET_PUBLISHEDITEMS;
  180. pdsConfig.name = UA_STRING("PublishedDataSet 1");
  181. UA_Server_addPublishedDataSet(server, &pdsConfig, &publishedDataSet1);
  182. UA_DataSetFieldConfig fieldConfig;
  183. memset(&fieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  184. fieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  185. fieldConfig.field.variable.fieldNameAlias = UA_STRING("field 1");
  186. UA_Server_addDataSetField(server, publishedDataSet1, &fieldConfig, &dataSetField1);
  187. UA_DataSetField *dataSetField = UA_DataSetField_findDSFbyId(server, dataSetField1);
  188. UA_DataSetWriterConfig dataSetWriterConfig;
  189. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  190. dataSetWriterConfig.name = UA_STRING("DataSetWriter 1");
  191. UA_Server_addDataSetWriter(server, writerGroup1, publishedDataSet1, &dataSetWriterConfig, &dataSetWriter1);
  192. dataSetWriterConfig.name = UA_STRING("DataSetWriter 2");
  193. UA_Server_addDataSetWriter(server, writerGroup1, publishedDataSet1, &dataSetWriterConfig, &dataSetWriter2);
  194. dataSetWriterConfig.name = UA_STRING("DataSetWriter 3");
  195. UA_Server_addDataSetWriter(server, writerGroup2, publishedDataSet1, &dataSetWriterConfig, &dataSetWriter3);
  196. UA_WriterGroup *writerGroup_1 = UA_WriterGroup_findWGbyId(server, writerGroup1);
  197. UA_WriterGroup *writerGroup_2 = UA_WriterGroup_findWGbyId(server, writerGroup2);
  198. UA_PublishedDataSet *publishedDataSet = UA_PublishedDataSet_findPDSbyId(server, publishedDataSet1);
  199. UA_PubSubConnection *pubSubConnection = UA_PubSubConnection_findConnectionbyId(server, connection1);
  200. //freeze configuratoin of both WG
  201. ck_assert(writerGroup_1->config.configurationFrozen == UA_FALSE);
  202. ck_assert(writerGroup_2->config.configurationFrozen == UA_FALSE);
  203. ck_assert(publishedDataSet->config.configurationFrozen == UA_FALSE);
  204. ck_assert(pubSubConnection->config->configurationFrozen == UA_FALSE);
  205. UA_Server_freezeWriterGroupConfiguration(server, writerGroup1);
  206. UA_Server_freezeWriterGroupConfiguration(server, writerGroup2);
  207. ck_assert(writerGroup_1->config.configurationFrozen == UA_TRUE);
  208. ck_assert(writerGroup_2->config.configurationFrozen == UA_TRUE);
  209. ck_assert(publishedDataSet->config.configurationFrozen == UA_TRUE);
  210. ck_assert(pubSubConnection->config->configurationFrozen == UA_TRUE);
  211. //unlock one tree, get sure pds still locked
  212. UA_Server_unfreezeWriterGroupConfiguration(server, writerGroup1);
  213. ck_assert(writerGroup_1->config.configurationFrozen == UA_FALSE);
  214. ck_assert(publishedDataSet->config.configurationFrozen == UA_TRUE);
  215. ck_assert(dataSetField->config.configurationFrozen == UA_TRUE);
  216. UA_Server_unfreezeWriterGroupConfiguration(server, writerGroup2);
  217. ck_assert(publishedDataSet->config.configurationFrozen == UA_FALSE);
  218. ck_assert(dataSetField->config.configurationFrozen == UA_FALSE);
  219. ck_assert(pubSubConnection->config->configurationFrozen == UA_FALSE);
  220. } END_TEST
  221. START_TEST(CreateLockAndEditConfiguration) {
  222. UA_NodeId connection1, writerGroup1, publishedDataSet1, dataSetWriter1;
  223. UA_PubSubConnectionConfig connectionConfig;
  224. memset(&connectionConfig, 0, sizeof(UA_PubSubConnectionConfig));
  225. connectionConfig.name = UA_STRING("UADP Connection");
  226. UA_NetworkAddressUrlDataType networkAddressUrl = {UA_STRING_NULL, UA_STRING("opc.udp://224.0.0.22:4840/")};
  227. UA_Variant_setScalar(&connectionConfig.address, &networkAddressUrl,
  228. &UA_TYPES[UA_TYPES_NETWORKADDRESSURLDATATYPE]);
  229. connectionConfig.transportProfileUri = UA_STRING("http://opcfoundation.org/UA-Profile/Transport/pubsub-udp-uadp");
  230. UA_Server_addPubSubConnection(server, &connectionConfig, &connection1);
  231. UA_WriterGroupConfig writerGroupConfig;
  232. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  233. writerGroupConfig.name = UA_STRING("WriterGroup 1");
  234. writerGroupConfig.publishingInterval = 10;
  235. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  236. writerGroupConfig.rtLevel = UA_PUBSUB_RT_NONE;
  237. UA_Server_addWriterGroup(server, connection1, &writerGroupConfig, &writerGroup1);
  238. UA_PublishedDataSetConfig pdsConfig;
  239. memset(&pdsConfig, 0, sizeof(UA_PublishedDataSetConfig));
  240. pdsConfig.publishedDataSetType = UA_PUBSUB_DATASET_PUBLISHEDITEMS;
  241. pdsConfig.name = UA_STRING("PublishedDataSet 1");
  242. UA_Server_addPublishedDataSet(server, &pdsConfig, &publishedDataSet1);
  243. UA_DataSetFieldConfig fieldConfig;
  244. memset(&fieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  245. fieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  246. fieldConfig.field.variable.fieldNameAlias = UA_STRING("field 1");
  247. UA_NodeId localDataSetField;
  248. UA_Server_addDataSetField(server, publishedDataSet1, &fieldConfig, &localDataSetField);
  249. //get internal WG Pointer
  250. UA_WriterGroup *writerGroup = UA_WriterGroup_findWGbyId(server, writerGroup1);
  251. ck_assert(writerGroup->state == UA_PUBSUBSTATE_DISABLED);
  252. UA_DataSetWriterConfig dataSetWriterConfig;
  253. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  254. dataSetWriterConfig.name = UA_STRING("DataSetWriter 1");
  255. UA_Server_addDataSetWriter(server, writerGroup1, publishedDataSet1, &dataSetWriterConfig, &dataSetWriter1);
  256. UA_DataSetWriter *dataSetWriter = UA_DataSetWriter_findDSWbyId(server, dataSetWriter1);
  257. ck_assert(dataSetWriter != NULL);
  258. ck_assert(dataSetWriter->config.configurationFrozen == UA_FALSE);
  259. //Lock the writer group and the child pubsub entities
  260. UA_Server_freezeWriterGroupConfiguration(server, writerGroup1);
  261. //call not allowed configuration methods
  262. UA_DataSetFieldResult fieldRemoveResult = UA_Server_removeDataSetField(server, localDataSetField);
  263. ck_assert(fieldRemoveResult.result == UA_STATUSCODE_BADCONFIGURATIONERROR);
  264. ck_assert(UA_Server_removePublishedDataSet(server, publishedDataSet1) == UA_STATUSCODE_BADCONFIGURATIONERROR);
  265. UA_Server_unfreezeWriterGroupConfiguration(server, writerGroup1);
  266. fieldRemoveResult = UA_Server_removeDataSetField(server, localDataSetField);
  267. ck_assert(fieldRemoveResult.result == UA_STATUSCODE_GOOD);
  268. } END_TEST
  269. START_TEST(CreateConfigWithStaticFieldSource) {
  270. UA_NodeId connection1, writerGroup1, publishedDataSet1, dataSetWriter1;
  271. UA_PubSubConnectionConfig connectionConfig;
  272. memset(&connectionConfig, 0, sizeof(UA_PubSubConnectionConfig));
  273. connectionConfig.name = UA_STRING("UADP Connection");
  274. UA_NetworkAddressUrlDataType networkAddressUrl = {UA_STRING_NULL, UA_STRING("opc.udp://224.0.0.22:4840/")};
  275. UA_Variant_setScalar(&connectionConfig.address, &networkAddressUrl,
  276. &UA_TYPES[UA_TYPES_NETWORKADDRESSURLDATATYPE]);
  277. connectionConfig.transportProfileUri = UA_STRING("http://opcfoundation.org/UA-Profile/Transport/pubsub-udp-uadp");
  278. UA_Server_addPubSubConnection(server, &connectionConfig, &connection1);
  279. UA_WriterGroupConfig writerGroupConfig;
  280. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  281. writerGroupConfig.name = UA_STRING("WriterGroup 1");
  282. writerGroupConfig.publishingInterval = 10;
  283. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  284. writerGroupConfig.rtLevel = UA_PUBSUB_RT_FIXED_SIZE;
  285. UA_Server_addWriterGroup(server, connection1, &writerGroupConfig, &writerGroup1);
  286. UA_PublishedDataSetConfig pdsConfig;
  287. memset(&pdsConfig, 0, sizeof(UA_PublishedDataSetConfig));
  288. pdsConfig.publishedDataSetType = UA_PUBSUB_DATASET_PUBLISHEDITEMS;
  289. pdsConfig.name = UA_STRING("PublishedDataSet 1");
  290. UA_Server_addPublishedDataSet(server, &pdsConfig, &publishedDataSet1);
  291. UA_UInt32 *intValue = UA_UInt32_new();
  292. UA_Variant variant;
  293. memset(&variant, 0, sizeof(UA_Variant));
  294. UA_Variant_setScalar(&variant, intValue, &UA_TYPES[UA_TYPES_UINT32]);
  295. UA_DataValue staticValueSource;
  296. memset(&staticValueSource, 0, sizeof(staticValueSource));
  297. staticValueSource.value = variant;
  298. UA_DataSetFieldConfig fieldConfig;
  299. memset(&fieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  300. fieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  301. fieldConfig.field.variable.fieldNameAlias = UA_STRING("field 1");
  302. fieldConfig.field.variable.staticValueSourceEnabled = UA_TRUE;
  303. fieldConfig.field.variable.staticValueSource.value = variant;
  304. UA_NodeId localDataSetField;
  305. UA_Server_addDataSetField(server, publishedDataSet1, &fieldConfig, &localDataSetField);
  306. UA_DataSetWriterConfig dataSetWriterConfig;
  307. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  308. dataSetWriterConfig.name = UA_STRING("DataSetWriter 1");
  309. UA_Server_addDataSetWriter(server, writerGroup1, publishedDataSet1, &dataSetWriterConfig, &dataSetWriter1);
  310. UA_DataValue_deleteMembers(&staticValueSource);
  311. } END_TEST
  312. int main(void) {
  313. TCase *tc_lock_configuration = tcase_create("Create and Lock");
  314. tcase_add_checked_fixture(tc_lock_configuration, setup, teardown);
  315. tcase_add_test(tc_lock_configuration, CreateAndLockConfiguration);
  316. tcase_add_test(tc_lock_configuration, CreateAndLockConfigurationWithExternalAPI);
  317. tcase_add_test(tc_lock_configuration, CreateAndReleaseMultiplePDSLocks);
  318. tcase_add_test(tc_lock_configuration, CreateLockAndEditConfiguration);
  319. tcase_add_test(tc_lock_configuration, CreateConfigWithStaticFieldSource);
  320. Suite *s = suite_create("PubSub RT configuration lock mechanism");
  321. suite_add_tcase(s, tc_lock_configuration);
  322. SRunner *sr = srunner_create(s);
  323. srunner_set_fork_status(sr, CK_NOFORK);
  324. srunner_run_all(sr,CK_NORMAL);
  325. int number_failed = srunner_ntests_failed(sr);
  326. srunner_free(sr);
  327. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  328. }