check_pubsub_config_freeze.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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_FIXED_SIZE;
  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. //get internal PubSubConnection Pointer
  82. UA_PubSubConnection *pubSubConnection = UA_PubSubConnection_findConnectionbyId(server, connection1);
  83. ck_assert(dataSetWriter->config.configurationFrozen == UA_FALSE);
  84. //Lock the writer group and the child pubsub entities
  85. UA_Server_freezeWriterGroupConfiguration(server, writerGroup1);
  86. ck_assert(dataSetWriter->config.configurationFrozen == UA_TRUE);
  87. ck_assert(dataSetField->config.configurationFrozen == UA_TRUE);
  88. ck_assert(pubSubConnection->config->configurationFrozen == UA_TRUE);
  89. UA_PublishedDataSet *publishedDataSet = UA_PublishedDataSet_findPDSbyId(server, dataSetWriter->connectedDataSet);
  90. ck_assert(publishedDataSet->config.configurationFrozen == UA_TRUE);
  91. UA_DataSetField *dsf;
  92. TAILQ_FOREACH(dsf ,&publishedDataSet->fields , listEntry){
  93. ck_assert(dsf->config.configurationFrozen == UA_TRUE);
  94. }
  95. //set state to disabled and implicit unlock the configuration
  96. UA_Server_unfreezeWriterGroupConfiguration(server, writerGroup1);
  97. } END_TEST
  98. START_TEST(CreateAndLockConfigurationWithExternalAPI) {
  99. //create config
  100. UA_NodeId connection1, writerGroup1, publishedDataSet1, dataSetWriter1, dataSetField1;
  101. UA_PubSubConnectionConfig connectionConfig;
  102. memset(&connectionConfig, 0, sizeof(UA_PubSubConnectionConfig));
  103. connectionConfig.name = UA_STRING("UADP Connection");
  104. UA_NetworkAddressUrlDataType networkAddressUrl = {UA_STRING_NULL, UA_STRING("opc.udp://224.0.0.22:4840/")};
  105. UA_Variant_setScalar(&connectionConfig.address, &networkAddressUrl,
  106. &UA_TYPES[UA_TYPES_NETWORKADDRESSURLDATATYPE]);
  107. connectionConfig.transportProfileUri = UA_STRING("http://opcfoundation.org/UA-Profile/Transport/pubsub-udp-uadp");
  108. UA_Server_addPubSubConnection(server, &connectionConfig, &connection1);
  109. UA_WriterGroupConfig writerGroupConfig;
  110. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  111. writerGroupConfig.name = UA_STRING("WriterGroup 1");
  112. writerGroupConfig.publishingInterval = 10;
  113. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  114. writerGroupConfig.rtLevel = UA_PUBSUB_RT_FIXED_SIZE;
  115. UA_Server_addWriterGroup(server, connection1, &writerGroupConfig, &writerGroup1);
  116. UA_PublishedDataSetConfig pdsConfig;
  117. memset(&pdsConfig, 0, sizeof(UA_PublishedDataSetConfig));
  118. pdsConfig.publishedDataSetType = UA_PUBSUB_DATASET_PUBLISHEDITEMS;
  119. pdsConfig.name = UA_STRING("PublishedDataSet 1");
  120. UA_Server_addPublishedDataSet(server, &pdsConfig, &publishedDataSet1);
  121. UA_DataSetFieldConfig fieldConfig;
  122. memset(&fieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  123. fieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  124. fieldConfig.field.variable.fieldNameAlias = UA_STRING("field 1");
  125. UA_Server_addDataSetField(server, publishedDataSet1, &fieldConfig, &dataSetField1);
  126. UA_DataSetField *dataSetField = UA_DataSetField_findDSFbyId(server, dataSetField1);
  127. ck_assert(dataSetField->config.configurationFrozen == UA_FALSE);
  128. //get internal WG Pointer
  129. UA_WriterGroup *writerGroup = UA_WriterGroup_findWGbyId(server, writerGroup1);
  130. ck_assert(writerGroup->state == UA_PUBSUBSTATE_DISABLED);
  131. UA_DataSetWriterConfig dataSetWriterConfig;
  132. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  133. dataSetWriterConfig.name = UA_STRING("DataSetWriter 1");
  134. UA_Server_addDataSetWriter(server, writerGroup1, publishedDataSet1, &dataSetWriterConfig, &dataSetWriter1);
  135. UA_DataSetWriter *dataSetWriter = UA_DataSetWriter_findDSWbyId(server, dataSetWriter1);
  136. //get internal PubSubConnection Pointer
  137. UA_PubSubConnection *pubSubConnection = UA_PubSubConnection_findConnectionbyId(server, connection1);
  138. ck_assert(dataSetWriter->config.configurationFrozen == UA_FALSE);
  139. //Lock the with the freeze function
  140. UA_Server_freezeWriterGroupConfiguration(server, writerGroup1);
  141. ck_assert(dataSetWriter->config.configurationFrozen == UA_TRUE);
  142. ck_assert(dataSetField->config.configurationFrozen == UA_TRUE);
  143. ck_assert(pubSubConnection->config->configurationFrozen == UA_TRUE);
  144. UA_PublishedDataSet *publishedDataSet = UA_PublishedDataSet_findPDSbyId(server, dataSetWriter->connectedDataSet);
  145. ck_assert(publishedDataSet->config.configurationFrozen == UA_TRUE);
  146. UA_DataSetField *dsf;
  147. TAILQ_FOREACH(dsf ,&publishedDataSet->fields , listEntry){
  148. ck_assert(dsf->config.configurationFrozen == UA_TRUE);
  149. }
  150. //set state to disabled and implicit unlock the configuration
  151. UA_Server_unfreezeWriterGroupConfiguration(server, writerGroup1);
  152. } END_TEST
  153. START_TEST(CreateAndReleaseMultiplePDSLocks) {
  154. //create config
  155. UA_NodeId connection1, writerGroup1, writerGroup2, publishedDataSet1, dataSetWriter1, dataSetWriter2, dataSetWriter3, dataSetField1;
  156. UA_PubSubConnectionConfig connectionConfig;
  157. memset(&connectionConfig, 0, sizeof(UA_PubSubConnectionConfig));
  158. connectionConfig.name = UA_STRING("UADP Connection");
  159. UA_NetworkAddressUrlDataType networkAddressUrl = {UA_STRING_NULL, UA_STRING("opc.udp://224.0.0.22:4840/")};
  160. UA_Variant_setScalar(&connectionConfig.address, &networkAddressUrl,
  161. &UA_TYPES[UA_TYPES_NETWORKADDRESSURLDATATYPE]);
  162. connectionConfig.transportProfileUri = UA_STRING("http://opcfoundation.org/UA-Profile/Transport/pubsub-udp-uadp");
  163. UA_Server_addPubSubConnection(server, &connectionConfig, &connection1);
  164. //Add two writer groups
  165. UA_WriterGroupConfig writerGroupConfig;
  166. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  167. writerGroupConfig.name = UA_STRING("WriterGroup 1");
  168. writerGroupConfig.publishingInterval = 10;
  169. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  170. writerGroupConfig.rtLevel = UA_PUBSUB_RT_FIXED_SIZE;
  171. UA_Server_addWriterGroup(server, connection1, &writerGroupConfig, &writerGroup1);
  172. writerGroupConfig.name = UA_STRING("WriterGroup 2");
  173. UA_Server_addWriterGroup(server, connection1, &writerGroupConfig, &writerGroup2);
  174. UA_PublishedDataSetConfig pdsConfig;
  175. memset(&pdsConfig, 0, sizeof(UA_PublishedDataSetConfig));
  176. pdsConfig.publishedDataSetType = UA_PUBSUB_DATASET_PUBLISHEDITEMS;
  177. pdsConfig.name = UA_STRING("PublishedDataSet 1");
  178. UA_Server_addPublishedDataSet(server, &pdsConfig, &publishedDataSet1);
  179. UA_DataSetFieldConfig fieldConfig;
  180. memset(&fieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  181. fieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  182. fieldConfig.field.variable.fieldNameAlias = UA_STRING("field 1");
  183. UA_Server_addDataSetField(server, publishedDataSet1, &fieldConfig, &dataSetField1);
  184. UA_DataSetField *dataSetField = UA_DataSetField_findDSFbyId(server, dataSetField1);
  185. UA_DataSetWriterConfig dataSetWriterConfig;
  186. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  187. dataSetWriterConfig.name = UA_STRING("DataSetWriter 1");
  188. UA_Server_addDataSetWriter(server, writerGroup1, publishedDataSet1, &dataSetWriterConfig, &dataSetWriter1);
  189. dataSetWriterConfig.name = UA_STRING("DataSetWriter 2");
  190. UA_Server_addDataSetWriter(server, writerGroup1, publishedDataSet1, &dataSetWriterConfig, &dataSetWriter2);
  191. dataSetWriterConfig.name = UA_STRING("DataSetWriter 3");
  192. UA_Server_addDataSetWriter(server, writerGroup2, publishedDataSet1, &dataSetWriterConfig, &dataSetWriter3);
  193. UA_WriterGroup *writerGroup_1 = UA_WriterGroup_findWGbyId(server, writerGroup1);
  194. UA_WriterGroup *writerGroup_2 = UA_WriterGroup_findWGbyId(server, writerGroup2);
  195. UA_PublishedDataSet *publishedDataSet = UA_PublishedDataSet_findPDSbyId(server, publishedDataSet1);
  196. UA_PubSubConnection *pubSubConnection = UA_PubSubConnection_findConnectionbyId(server, connection1);
  197. //freeze configuratoin of both WG
  198. ck_assert(writerGroup_1->config.configurationFrozen == UA_FALSE);
  199. ck_assert(writerGroup_2->config.configurationFrozen == UA_FALSE);
  200. ck_assert(publishedDataSet->config.configurationFrozen == UA_FALSE);
  201. ck_assert(pubSubConnection->config->configurationFrozen == UA_FALSE);
  202. UA_Server_freezeWriterGroupConfiguration(server, writerGroup1);
  203. UA_Server_freezeWriterGroupConfiguration(server, writerGroup2);
  204. ck_assert(writerGroup_1->config.configurationFrozen == UA_TRUE);
  205. ck_assert(writerGroup_2->config.configurationFrozen == UA_TRUE);
  206. ck_assert(publishedDataSet->config.configurationFrozen == UA_TRUE);
  207. ck_assert(pubSubConnection->config->configurationFrozen == UA_TRUE);
  208. //unlock one tree, get sure pds still locked
  209. UA_Server_unfreezeWriterGroupConfiguration(server, writerGroup1);
  210. ck_assert(writerGroup_1->config.configurationFrozen == UA_FALSE);
  211. ck_assert(publishedDataSet->config.configurationFrozen == UA_TRUE);
  212. ck_assert(dataSetField->config.configurationFrozen == UA_TRUE);
  213. UA_Server_unfreezeWriterGroupConfiguration(server, writerGroup2);
  214. ck_assert(publishedDataSet->config.configurationFrozen == UA_FALSE);
  215. ck_assert(dataSetField->config.configurationFrozen == UA_FALSE);
  216. ck_assert(pubSubConnection->config->configurationFrozen == UA_FALSE);
  217. } END_TEST
  218. START_TEST(CreateLockAndEditConfiguration) {
  219. UA_NodeId connection1, writerGroup1, publishedDataSet1, dataSetWriter1;
  220. UA_PubSubConnectionConfig connectionConfig;
  221. memset(&connectionConfig, 0, sizeof(UA_PubSubConnectionConfig));
  222. connectionConfig.name = UA_STRING("UADP Connection");
  223. UA_NetworkAddressUrlDataType networkAddressUrl = {UA_STRING_NULL, UA_STRING("opc.udp://224.0.0.22:4840/")};
  224. UA_Variant_setScalar(&connectionConfig.address, &networkAddressUrl,
  225. &UA_TYPES[UA_TYPES_NETWORKADDRESSURLDATATYPE]);
  226. connectionConfig.transportProfileUri = UA_STRING("http://opcfoundation.org/UA-Profile/Transport/pubsub-udp-uadp");
  227. UA_Server_addPubSubConnection(server, &connectionConfig, &connection1);
  228. UA_WriterGroupConfig writerGroupConfig;
  229. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  230. writerGroupConfig.name = UA_STRING("WriterGroup 1");
  231. writerGroupConfig.publishingInterval = 10;
  232. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  233. writerGroupConfig.rtLevel = UA_PUBSUB_RT_FIXED_SIZE;
  234. UA_Server_addWriterGroup(server, connection1, &writerGroupConfig, &writerGroup1);
  235. UA_PublishedDataSetConfig pdsConfig;
  236. memset(&pdsConfig, 0, sizeof(UA_PublishedDataSetConfig));
  237. pdsConfig.publishedDataSetType = UA_PUBSUB_DATASET_PUBLISHEDITEMS;
  238. pdsConfig.name = UA_STRING("PublishedDataSet 1");
  239. UA_Server_addPublishedDataSet(server, &pdsConfig, &publishedDataSet1);
  240. UA_DataSetFieldConfig fieldConfig;
  241. memset(&fieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  242. fieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  243. fieldConfig.field.variable.fieldNameAlias = UA_STRING("field 1");
  244. UA_NodeId localDataSetField;
  245. UA_Server_addDataSetField(server, publishedDataSet1, &fieldConfig, &localDataSetField);
  246. //get internal WG Pointer
  247. UA_WriterGroup *writerGroup = UA_WriterGroup_findWGbyId(server, writerGroup1);
  248. ck_assert(writerGroup->state == UA_PUBSUBSTATE_DISABLED);
  249. UA_DataSetWriterConfig dataSetWriterConfig;
  250. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  251. dataSetWriterConfig.name = UA_STRING("DataSetWriter 1");
  252. UA_Server_addDataSetWriter(server, writerGroup1, publishedDataSet1, &dataSetWriterConfig, &dataSetWriter1);
  253. UA_DataSetWriter *dataSetWriter = UA_DataSetWriter_findDSWbyId(server, dataSetWriter1);
  254. ck_assert(dataSetWriter->config.configurationFrozen == UA_FALSE);
  255. //Lock the writer group and the child pubsub entities
  256. UA_Server_freezeWriterGroupConfiguration(server, writerGroup1);
  257. //call not allowed configuration methods
  258. UA_DataSetFieldResult fieldRemoveResult = UA_Server_removeDataSetField(server, localDataSetField);
  259. ck_assert(fieldRemoveResult.result == UA_STATUSCODE_BADCONFIGURATIONERROR);
  260. ck_assert(UA_Server_removePublishedDataSet(server, publishedDataSet1) == UA_STATUSCODE_BADCONFIGURATIONERROR);
  261. UA_Server_unfreezeWriterGroupConfiguration(server, writerGroup1);
  262. fieldRemoveResult = UA_Server_removeDataSetField(server, localDataSetField);
  263. ck_assert(fieldRemoveResult.result == UA_STATUSCODE_GOOD);
  264. } END_TEST
  265. START_TEST(CreateConfigWithStaticFieldSource) {
  266. UA_NodeId connection1, writerGroup1, publishedDataSet1, dataSetWriter1;
  267. UA_PubSubConnectionConfig connectionConfig;
  268. memset(&connectionConfig, 0, sizeof(UA_PubSubConnectionConfig));
  269. connectionConfig.name = UA_STRING("UADP Connection");
  270. UA_NetworkAddressUrlDataType networkAddressUrl = {UA_STRING_NULL, UA_STRING("opc.udp://224.0.0.22:4840/")};
  271. UA_Variant_setScalar(&connectionConfig.address, &networkAddressUrl,
  272. &UA_TYPES[UA_TYPES_NETWORKADDRESSURLDATATYPE]);
  273. connectionConfig.transportProfileUri = UA_STRING("http://opcfoundation.org/UA-Profile/Transport/pubsub-udp-uadp");
  274. UA_Server_addPubSubConnection(server, &connectionConfig, &connection1);
  275. UA_WriterGroupConfig writerGroupConfig;
  276. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  277. writerGroupConfig.name = UA_STRING("WriterGroup 1");
  278. writerGroupConfig.publishingInterval = 10;
  279. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  280. writerGroupConfig.rtLevel = UA_PUBSUB_RT_FIXED_SIZE;
  281. UA_Server_addWriterGroup(server, connection1, &writerGroupConfig, &writerGroup1);
  282. UA_PublishedDataSetConfig pdsConfig;
  283. memset(&pdsConfig, 0, sizeof(UA_PublishedDataSetConfig));
  284. pdsConfig.publishedDataSetType = UA_PUBSUB_DATASET_PUBLISHEDITEMS;
  285. pdsConfig.name = UA_STRING("PublishedDataSet 1");
  286. UA_Server_addPublishedDataSet(server, &pdsConfig, &publishedDataSet1);
  287. UA_UInt32 *intValue = UA_UInt32_new();
  288. UA_Variant variant;
  289. memset(&variant, 0, sizeof(UA_Variant));
  290. UA_Variant_setScalar(&variant, intValue, &UA_TYPES[UA_TYPES_UINT32]);
  291. UA_DataValue staticValueSource;
  292. memset(&staticValueSource, 0, sizeof(staticValueSource));
  293. staticValueSource.value = variant;
  294. UA_DataSetFieldConfig fieldConfig;
  295. memset(&fieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  296. fieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  297. fieldConfig.field.variable.fieldNameAlias = UA_STRING("field 1");
  298. fieldConfig.field.variable.staticValueSourceEnabled = UA_TRUE;
  299. fieldConfig.field.variable.staticValueSource.value = variant;
  300. UA_NodeId localDataSetField;
  301. UA_Server_addDataSetField(server, publishedDataSet1, &fieldConfig, &localDataSetField);
  302. UA_DataSetWriterConfig dataSetWriterConfig;
  303. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  304. dataSetWriterConfig.name = UA_STRING("DataSetWriter 1");
  305. UA_Server_addDataSetWriter(server, writerGroup1, publishedDataSet1, &dataSetWriterConfig, &dataSetWriter1);
  306. UA_DataValue_deleteMembers(&staticValueSource);
  307. } END_TEST
  308. int main(void) {
  309. TCase *tc_lock_configuration = tcase_create("Create and Lock");
  310. tcase_add_checked_fixture(tc_lock_configuration, setup, teardown);
  311. tcase_add_test(tc_lock_configuration, CreateAndLockConfiguration);
  312. tcase_add_test(tc_lock_configuration, CreateAndLockConfigurationWithExternalAPI);
  313. tcase_add_test(tc_lock_configuration, CreateAndReleaseMultiplePDSLocks);
  314. tcase_add_test(tc_lock_configuration, CreateLockAndEditConfiguration);
  315. tcase_add_test(tc_lock_configuration, CreateConfigWithStaticFieldSource);
  316. Suite *s = suite_create("PubSub RT configuration lock mechanism");
  317. suite_add_tcase(s, tc_lock_configuration);
  318. SRunner *sr = srunner_create(s);
  319. srunner_set_fork_status(sr, CK_NOFORK);
  320. srunner_run_all(sr,CK_NORMAL);
  321. int number_failed = srunner_ntests_failed(sr);
  322. srunner_free(sr);
  323. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  324. }