check_pubsub_publish_rt_levels.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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/server.h>
  8. #include <open62541/server_config_default.h>
  9. #include <open62541/plugin/pubsub_udp.h>
  10. #include <check.h>
  11. #include <stdio.h>
  12. #include <ua_pubsub.h>
  13. #include <ua_pubsub_networkmessage.h>
  14. UA_Server *server = NULL;
  15. UA_NodeId connectionIdentifier, publishedDataSetIdent, writerGroupIdent, dataSetWriterIdent, dataSetFieldIdent;
  16. static UA_StatusCode
  17. addMinimalPubSubConfiguration(void){
  18. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  19. /* Add one PubSubConnection */
  20. UA_PubSubConnectionConfig connectionConfig;
  21. memset(&connectionConfig, 0, sizeof(connectionConfig));
  22. connectionConfig.name = UA_STRING("UDP-UADP Connection 1");
  23. connectionConfig.transportProfileUri = UA_STRING("http://opcfoundation.org/UA-Profile/Transport/pubsub-udp-uadp");
  24. connectionConfig.enabled = UA_TRUE;
  25. UA_NetworkAddressUrlDataType networkAddressUrl = {UA_STRING_NULL , UA_STRING("opc.udp://224.0.0.22:4840/")};
  26. UA_Variant_setScalar(&connectionConfig.address, &networkAddressUrl, &UA_TYPES[UA_TYPES_NETWORKADDRESSURLDATATYPE]);
  27. connectionConfig.publisherId.numeric = UA_UInt32_random();
  28. retVal = UA_Server_addPubSubConnection(server, &connectionConfig, &connectionIdentifier);
  29. if(retVal != UA_STATUSCODE_GOOD)
  30. return retVal;
  31. /* Add one PublishedDataSet */
  32. UA_PublishedDataSetConfig publishedDataSetConfig;
  33. memset(&publishedDataSetConfig, 0, sizeof(UA_PublishedDataSetConfig));
  34. publishedDataSetConfig.publishedDataSetType = UA_PUBSUB_DATASET_PUBLISHEDITEMS;
  35. publishedDataSetConfig.name = UA_STRING("Demo PDS");
  36. /* Add one DataSetField to the PDS */
  37. UA_AddPublishedDataSetResult addResult = UA_Server_addPublishedDataSet(server, &publishedDataSetConfig, &publishedDataSetIdent);
  38. return addResult.addResult;
  39. }
  40. static void setup(void) {
  41. server = UA_Server_new();
  42. UA_ServerConfig *config = UA_Server_getConfig(server);
  43. UA_ServerConfig_setDefault(config);
  44. config->pubsubTransportLayers = (UA_PubSubTransportLayer*)
  45. UA_malloc(sizeof(UA_PubSubTransportLayer));
  46. config->pubsubTransportLayers[0] = UA_PubSubTransportLayerUDPMP();
  47. config->pubsubTransportLayersSize++;
  48. UA_Server_run_startup(server);
  49. }
  50. static void teardown(void) {
  51. UA_Server_run_shutdown(server);
  52. UA_Server_delete(server);
  53. }
  54. static void receiveSingleMessage(UA_ByteString buffer, UA_PubSubConnection *connection, UA_NetworkMessage *networkMessage) {
  55. if (UA_ByteString_allocBuffer(&buffer, 512) != UA_STATUSCODE_GOOD) {
  56. ck_abort_msg("Message buffer allocation failed!");
  57. }
  58. UA_StatusCode retval =
  59. connection->channel->receive(connection->channel, &buffer, NULL, 1000000);
  60. if(retval != UA_STATUSCODE_GOOD || buffer.length == 0) {
  61. buffer.length = 512;
  62. UA_ByteString_clear(&buffer);
  63. ck_abort_msg("Expected message not received!");
  64. }
  65. memset(networkMessage, 0, sizeof(UA_NetworkMessage));
  66. size_t currentPosition = 0;
  67. UA_NetworkMessage_decodeBinary(&buffer, &currentPosition, networkMessage);
  68. UA_ByteString_clear(&buffer);
  69. }
  70. START_TEST(PublishSingleFieldWithStaticValueSource) {
  71. ck_assert(addMinimalPubSubConfiguration() == UA_STATUSCODE_GOOD);
  72. UA_PubSubConnection *connection = UA_PubSubConnection_findConnectionbyId(server, connectionIdentifier);
  73. if(connection != NULL) {
  74. UA_StatusCode rv = connection->channel->regist(connection->channel, NULL, NULL);
  75. ck_assert(rv == UA_STATUSCODE_GOOD);
  76. }
  77. UA_WriterGroupConfig writerGroupConfig;
  78. memset(&writerGroupConfig, 0, sizeof(UA_WriterGroupConfig));
  79. writerGroupConfig.name = UA_STRING("Demo WriterGroup");
  80. writerGroupConfig.publishingInterval = 10;
  81. writerGroupConfig.enabled = UA_FALSE;
  82. writerGroupConfig.writerGroupId = 100;
  83. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  84. writerGroupConfig.rtLevel = UA_PUBSUB_RT_DIRECT_VALUE_ACCESS;
  85. UA_UadpWriterGroupMessageDataType *wgm = UA_UadpWriterGroupMessageDataType_new();
  86. wgm->networkMessageContentMask = UA_UADPNETWORKMESSAGECONTENTMASK_PAYLOADHEADER;
  87. writerGroupConfig.messageSettings.content.decoded.data = wgm;
  88. writerGroupConfig.messageSettings.content.decoded.type =
  89. &UA_TYPES[UA_TYPES_UADPWRITERGROUPMESSAGEDATATYPE];
  90. writerGroupConfig.messageSettings.encoding = UA_EXTENSIONOBJECT_DECODED;
  91. ck_assert(UA_Server_addWriterGroup(server, connectionIdentifier, &writerGroupConfig, &writerGroupIdent) == UA_STATUSCODE_GOOD);
  92. UA_UadpWriterGroupMessageDataType_delete(wgm);
  93. UA_DataSetWriterConfig dataSetWriterConfig;
  94. memset(&dataSetWriterConfig, 0, sizeof(UA_DataSetWriterConfig));
  95. dataSetWriterConfig.name = UA_STRING("Test DataSetWriter");
  96. dataSetWriterConfig.dataSetWriterId = 62541;
  97. ck_assert(UA_Server_addDataSetWriter(server, writerGroupIdent, publishedDataSetIdent, &dataSetWriterConfig, &dataSetWriterIdent) == UA_STATUSCODE_GOOD);
  98. UA_DataSetFieldConfig dsfConfig;
  99. memset(&dsfConfig, 0, sizeof(UA_DataSetFieldConfig));
  100. /* Create Variant and configure as DataSetField source */
  101. UA_UInt32 intValue = 1000;
  102. UA_Variant variant;
  103. memset(&variant, 0, sizeof(UA_Variant));
  104. UA_Variant_setScalar(&variant, &intValue, &UA_TYPES[UA_TYPES_UINT32]);
  105. UA_DataValue staticValueSource;
  106. memset(&staticValueSource, 0, sizeof(staticValueSource));
  107. staticValueSource.value = variant;
  108. dsfConfig.field.variable.staticValueSourceEnabled = UA_TRUE;
  109. dsfConfig.field.variable.staticValueSource.value = variant;
  110. dsfConfig.field.variable.publishParameters.attributeId = UA_ATTRIBUTEID_VALUE;
  111. ck_assert(UA_Server_addDataSetField(server, publishedDataSetIdent, &dsfConfig, &dataSetFieldIdent).result == UA_STATUSCODE_GOOD);
  112. ck_assert(UA_Server_freezeWriterGroupConfiguration(server, writerGroupIdent) == UA_STATUSCODE_GOOD);
  113. ck_assert(UA_Server_setWriterGroupOperational(server, writerGroupIdent) == UA_STATUSCODE_GOOD);
  114. UA_ByteString buffer;
  115. UA_ByteString_init(&buffer);
  116. UA_NetworkMessage networkMessage;
  117. receiveSingleMessage(buffer, connection, &networkMessage);
  118. ck_assert((*((UA_UInt32 *)networkMessage.payload.dataSetPayload.dataSetMessages->data.keyFrameData.dataSetFields->value.data)) == 1000);
  119. UA_NetworkMessage_deleteMembers(&networkMessage);
  120. } END_TEST
  121. START_TEST(PublishSingleFieldWithDifferentBinarySizes) {
  122. ck_assert(addMinimalPubSubConfiguration() == UA_STATUSCODE_GOOD);
  123. UA_PubSubConnection *connection = UA_PubSubConnection_findConnectionbyId(server, connectionIdentifier);
  124. if(connection != NULL) {
  125. UA_StatusCode rv = connection->channel->regist(connection->channel, NULL, NULL);
  126. ck_assert(rv == UA_STATUSCODE_GOOD);
  127. }
  128. UA_WriterGroupConfig writerGroupConfig;
  129. memset(&writerGroupConfig, 0, sizeof(UA_WriterGroupConfig));
  130. writerGroupConfig.name = UA_STRING("Test WriterGroup");
  131. writerGroupConfig.publishingInterval = 10;
  132. writerGroupConfig.enabled = UA_FALSE;
  133. writerGroupConfig.writerGroupId = 100;
  134. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  135. writerGroupConfig.rtLevel = UA_PUBSUB_RT_DIRECT_VALUE_ACCESS;
  136. UA_UadpWriterGroupMessageDataType *wgm = UA_UadpWriterGroupMessageDataType_new();
  137. wgm->networkMessageContentMask = UA_UADPNETWORKMESSAGECONTENTMASK_PAYLOADHEADER;
  138. writerGroupConfig.messageSettings.content.decoded.data = wgm;
  139. writerGroupConfig.messageSettings.content.decoded.type =
  140. &UA_TYPES[UA_TYPES_UADPWRITERGROUPMESSAGEDATATYPE];
  141. writerGroupConfig.messageSettings.encoding = UA_EXTENSIONOBJECT_DECODED;
  142. ck_assert(UA_Server_addWriterGroup(server, connectionIdentifier, &writerGroupConfig, &writerGroupIdent) == UA_STATUSCODE_GOOD);
  143. UA_UadpWriterGroupMessageDataType_delete(wgm);
  144. UA_DataSetWriterConfig dataSetWriterConfig;
  145. memset(&dataSetWriterConfig, 0, sizeof(UA_DataSetWriterConfig));
  146. dataSetWriterConfig.name = UA_STRING("Demo DataSetWriter");
  147. dataSetWriterConfig.dataSetWriterId = 62541;
  148. ck_assert(UA_Server_addDataSetWriter(server, writerGroupIdent, publishedDataSetIdent, &dataSetWriterConfig, &dataSetWriterIdent) == UA_STATUSCODE_GOOD);
  149. UA_DataSetFieldConfig dsfConfig;
  150. memset(&dsfConfig, 0, sizeof(UA_DataSetFieldConfig));
  151. /* Create Variant and configure as DataSetField source */
  152. UA_String stringValue = UA_STRING_ALLOC("12345");
  153. UA_Variant variant;
  154. memset(&variant, 0, sizeof(UA_Variant));
  155. UA_Variant_setScalar(&variant, &stringValue, &UA_TYPES[UA_TYPES_STRING]);
  156. UA_DataValue staticValueSource;
  157. memset(&staticValueSource, 0, sizeof(staticValueSource));
  158. staticValueSource.value = variant;
  159. dsfConfig.field.variable.staticValueSourceEnabled = UA_TRUE;
  160. dsfConfig.field.variable.staticValueSource.value = variant;
  161. dsfConfig.field.variable.publishParameters.attributeId = UA_ATTRIBUTEID_VALUE;
  162. ck_assert(UA_Server_addDataSetField(server, publishedDataSetIdent, &dsfConfig, &dataSetFieldIdent).result == UA_STATUSCODE_GOOD);
  163. ck_assert(UA_Server_freezeWriterGroupConfiguration(server, writerGroupIdent) == UA_STATUSCODE_GOOD);
  164. ck_assert(UA_Server_setWriterGroupOperational(server, writerGroupIdent) == UA_STATUSCODE_GOOD);
  165. UA_ByteString buffer;
  166. UA_ByteString_init(&buffer);
  167. UA_NetworkMessage networkMessage;
  168. memset(&networkMessage, 0, sizeof(networkMessage));
  169. receiveSingleMessage(buffer, connection, &networkMessage);
  170. UA_String compareString = UA_STRING("12345");
  171. ck_assert(UA_String_equal(((UA_String *) networkMessage.payload.dataSetPayload.dataSetMessages->data.keyFrameData.dataSetFields->value.data), &compareString) == UA_TRUE);
  172. UA_NetworkMessage_deleteMembers(&networkMessage);
  173. compareString = UA_STRING("123456789");
  174. stringValue.data = (UA_Byte *) UA_realloc(stringValue.data, 9);
  175. stringValue.length = 9;
  176. memcpy(stringValue.data, "123456789", 9);
  177. UA_ByteString_init(&buffer);
  178. memset(&networkMessage, 0, sizeof(networkMessage));
  179. ck_assert(UA_Server_setWriterGroupDisabled(server, writerGroupIdent) == UA_STATUSCODE_GOOD);
  180. ck_assert(UA_Server_setWriterGroupOperational(server, writerGroupIdent) == UA_STATUSCODE_GOOD);
  181. receiveSingleMessage(buffer, connection, &networkMessage);
  182. ck_assert(UA_String_equal(((UA_String *) networkMessage.payload.dataSetPayload.dataSetMessages->data.keyFrameData.dataSetFields->value.data), &compareString) == UA_TRUE);
  183. UA_NetworkMessage_deleteMembers(&networkMessage);
  184. UA_String_deleteMembers(&stringValue);
  185. } END_TEST
  186. START_TEST(SetupInvalidPubSubConfigWithStaticValueSource) {
  187. ck_assert(addMinimalPubSubConfiguration() == UA_STATUSCODE_GOOD);
  188. UA_PubSubConnection *connection = UA_PubSubConnection_findConnectionbyId(server, connectionIdentifier);
  189. if(connection != NULL) {
  190. UA_StatusCode rv = connection->channel->regist(connection->channel, NULL, NULL);
  191. ck_assert(rv == UA_STATUSCODE_GOOD);
  192. }
  193. UA_WriterGroupConfig writerGroupConfig;
  194. memset(&writerGroupConfig, 0, sizeof(UA_WriterGroupConfig));
  195. writerGroupConfig.name = UA_STRING("Test WriterGroup");
  196. writerGroupConfig.publishingInterval = 10;
  197. writerGroupConfig.enabled = UA_FALSE;
  198. writerGroupConfig.writerGroupId = 100;
  199. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  200. writerGroupConfig.rtLevel = UA_PUBSUB_RT_DIRECT_VALUE_ACCESS;
  201. UA_UadpWriterGroupMessageDataType *wgm = UA_UadpWriterGroupMessageDataType_new();
  202. wgm->networkMessageContentMask = UA_UADPNETWORKMESSAGECONTENTMASK_PAYLOADHEADER;
  203. writerGroupConfig.messageSettings.content.decoded.data = wgm;
  204. writerGroupConfig.messageSettings.content.decoded.type =
  205. &UA_TYPES[UA_TYPES_UADPWRITERGROUPMESSAGEDATATYPE];
  206. writerGroupConfig.messageSettings.encoding = UA_EXTENSIONOBJECT_DECODED;
  207. ck_assert(UA_Server_addWriterGroup(server, connectionIdentifier, &writerGroupConfig, &writerGroupIdent) == UA_STATUSCODE_GOOD);
  208. UA_UadpWriterGroupMessageDataType_delete(wgm);
  209. UA_DataSetWriterConfig dataSetWriterConfig;
  210. memset(&dataSetWriterConfig, 0, sizeof(UA_DataSetWriterConfig));
  211. dataSetWriterConfig.name = UA_STRING("Demo DataSetWriter");
  212. dataSetWriterConfig.dataSetWriterId = 62541;
  213. UA_DataSetFieldConfig dataSetFieldConfig;
  214. memset(&dataSetFieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  215. dataSetFieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  216. dataSetFieldConfig.field.variable.fieldNameAlias = UA_STRING("Server localtime");
  217. dataSetFieldConfig.field.variable.promotedField = UA_FALSE;
  218. dataSetFieldConfig.field.variable.publishParameters.publishedVariable =
  219. UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_CURRENTTIME);
  220. dataSetFieldConfig.field.variable.publishParameters.attributeId = UA_ATTRIBUTEID_VALUE;
  221. UA_Server_addDataSetField(server, publishedDataSetIdent,
  222. &dataSetFieldConfig, &dataSetFieldIdent);
  223. ck_assert(UA_Server_addDataSetWriter(server, writerGroupIdent, publishedDataSetIdent, &dataSetWriterConfig, &dataSetWriterIdent) == UA_STATUSCODE_BADCONFIGURATIONERROR);
  224. } END_TEST
  225. START_TEST(PublishSingleFieldWithFixedOffsets) {
  226. ck_assert(addMinimalPubSubConfiguration() == UA_STATUSCODE_GOOD);
  227. UA_PubSubConnection *connection = UA_PubSubConnection_findConnectionbyId(server, connectionIdentifier);
  228. if(connection != NULL) {
  229. UA_StatusCode rv = connection->channel->regist(connection->channel, NULL, NULL);
  230. ck_assert(rv == UA_STATUSCODE_GOOD);
  231. }
  232. UA_WriterGroupConfig writerGroupConfig;
  233. memset(&writerGroupConfig, 0, sizeof(UA_WriterGroupConfig));
  234. writerGroupConfig.name = UA_STRING("Demo WriterGroup");
  235. writerGroupConfig.publishingInterval = 10;
  236. writerGroupConfig.enabled = UA_FALSE;
  237. writerGroupConfig.writerGroupId = 100;
  238. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  239. writerGroupConfig.rtLevel = UA_PUBSUB_RT_FIXED_SIZE;
  240. UA_UadpWriterGroupMessageDataType *wgm = UA_UadpWriterGroupMessageDataType_new();
  241. wgm->networkMessageContentMask = UA_UADPNETWORKMESSAGECONTENTMASK_PAYLOADHEADER;
  242. writerGroupConfig.messageSettings.content.decoded.data = wgm;
  243. writerGroupConfig.messageSettings.content.decoded.type =
  244. &UA_TYPES[UA_TYPES_UADPWRITERGROUPMESSAGEDATATYPE];
  245. writerGroupConfig.messageSettings.encoding = UA_EXTENSIONOBJECT_DECODED;
  246. ck_assert(UA_Server_addWriterGroup(server, connectionIdentifier, &writerGroupConfig, &writerGroupIdent) == UA_STATUSCODE_GOOD);
  247. UA_UadpWriterGroupMessageDataType_delete(wgm);
  248. UA_DataSetWriterConfig dataSetWriterConfig;
  249. memset(&dataSetWriterConfig, 0, sizeof(UA_DataSetWriterConfig));
  250. dataSetWriterConfig.name = UA_STRING("Test DataSetWriter");
  251. dataSetWriterConfig.dataSetWriterId = 62541;
  252. ck_assert(UA_Server_addDataSetWriter(server, writerGroupIdent, publishedDataSetIdent, &dataSetWriterConfig, &dataSetWriterIdent) == UA_STATUSCODE_GOOD);
  253. UA_DataSetFieldConfig dsfConfig;
  254. memset(&dsfConfig, 0, sizeof(UA_DataSetFieldConfig));
  255. // Create Variant and configure as DataSetField source
  256. UA_UInt32 *intValue = UA_UInt32_new();
  257. *intValue = (UA_UInt32) 1000;
  258. UA_Variant variant;
  259. memset(&variant, 0, sizeof(UA_Variant));
  260. UA_Variant_setScalar(&variant, intValue, &UA_TYPES[UA_TYPES_UINT32]);
  261. UA_DataValue staticValueSource;
  262. memset(&staticValueSource, 0, sizeof(staticValueSource));
  263. staticValueSource.value = variant;
  264. dsfConfig.field.variable.staticValueSourceEnabled = UA_TRUE;
  265. dsfConfig.field.variable.staticValueSource.value = variant;
  266. dsfConfig.field.variable.publishParameters.attributeId = UA_ATTRIBUTEID_VALUE;
  267. ck_assert(UA_Server_addDataSetField(server, publishedDataSetIdent, &dsfConfig, &dataSetFieldIdent).result == UA_STATUSCODE_GOOD);
  268. ck_assert(UA_Server_freezeWriterGroupConfiguration(server, writerGroupIdent) == UA_STATUSCODE_GOOD);
  269. ck_assert(UA_Server_setWriterGroupOperational(server, writerGroupIdent) == UA_STATUSCODE_GOOD);
  270. UA_ByteString buffer;
  271. UA_ByteString_init(&buffer);
  272. UA_NetworkMessage networkMessage;
  273. receiveSingleMessage(buffer, connection, &networkMessage);
  274. ck_assert((*((UA_UInt32 *)networkMessage.payload.dataSetPayload.dataSetMessages->data.keyFrameData.dataSetFields->value.data)) == 1000);
  275. UA_NetworkMessage_deleteMembers(&networkMessage);
  276. } END_TEST
  277. START_TEST(PublishPDSWithMultipleFieldsAndFixedOffset) {
  278. ck_assert(addMinimalPubSubConfiguration() == UA_STATUSCODE_GOOD);
  279. UA_PubSubConnection *connection = UA_PubSubConnection_findConnectionbyId(server, connectionIdentifier);
  280. if(connection != NULL) {
  281. UA_StatusCode rv = connection->channel->regist(connection->channel, NULL, NULL);
  282. ck_assert(rv == UA_STATUSCODE_GOOD);
  283. }
  284. UA_WriterGroupConfig writerGroupConfig;
  285. memset(&writerGroupConfig, 0, sizeof(UA_WriterGroupConfig));
  286. writerGroupConfig.name = UA_STRING("Demo WriterGroup");
  287. writerGroupConfig.publishingInterval = 10;
  288. writerGroupConfig.enabled = UA_FALSE;
  289. writerGroupConfig.writerGroupId = 100;
  290. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  291. writerGroupConfig.rtLevel = UA_PUBSUB_RT_FIXED_SIZE;
  292. UA_UadpWriterGroupMessageDataType *wgm = UA_UadpWriterGroupMessageDataType_new();
  293. wgm->networkMessageContentMask = UA_UADPNETWORKMESSAGECONTENTMASK_PAYLOADHEADER;
  294. writerGroupConfig.messageSettings.content.decoded.data = wgm;
  295. writerGroupConfig.messageSettings.content.decoded.type =
  296. &UA_TYPES[UA_TYPES_UADPWRITERGROUPMESSAGEDATATYPE];
  297. writerGroupConfig.messageSettings.encoding = UA_EXTENSIONOBJECT_DECODED;
  298. ck_assert(UA_Server_addWriterGroup(server, connectionIdentifier, &writerGroupConfig, &writerGroupIdent) == UA_STATUSCODE_GOOD);
  299. UA_UadpWriterGroupMessageDataType_delete(wgm);
  300. UA_DataSetWriterConfig dataSetWriterConfig;
  301. memset(&dataSetWriterConfig, 0, sizeof(UA_DataSetWriterConfig));
  302. dataSetWriterConfig.name = UA_STRING("Test DataSetWriter");
  303. dataSetWriterConfig.dataSetWriterId = 62541;
  304. ck_assert(UA_Server_addDataSetWriter(server, writerGroupIdent, publishedDataSetIdent, &dataSetWriterConfig, &dataSetWriterIdent) == UA_STATUSCODE_GOOD);
  305. UA_DataSetFieldConfig dsfConfig;
  306. memset(&dsfConfig, 0, sizeof(UA_DataSetFieldConfig));
  307. // Create Variant and configure as DataSetField source
  308. UA_UInt32 *intValue = UA_UInt32_new();
  309. *intValue = (UA_UInt32) 1000;
  310. UA_Variant variant;
  311. memset(&variant, 0, sizeof(UA_Variant));
  312. UA_Variant_setScalar(&variant, intValue, &UA_TYPES[UA_TYPES_UINT32]);
  313. UA_DataValue staticValueSource;
  314. memset(&staticValueSource, 0, sizeof(staticValueSource));
  315. staticValueSource.value = variant;
  316. dsfConfig.field.variable.staticValueSourceEnabled = UA_TRUE;
  317. dsfConfig.field.variable.staticValueSource.value = variant;
  318. dsfConfig.field.variable.publishParameters.attributeId = UA_ATTRIBUTEID_VALUE;
  319. ck_assert(UA_Server_addDataSetField(server, publishedDataSetIdent, &dsfConfig, &dataSetFieldIdent).result == UA_STATUSCODE_GOOD);
  320. UA_UInt32 *intValue2 = UA_UInt32_new();
  321. *intValue2 = (UA_UInt32) 2000;
  322. UA_Variant variant2;
  323. memset(&variant2, 0, sizeof(UA_Variant));
  324. UA_Variant_setScalar(&variant2, intValue2, &UA_TYPES[UA_TYPES_UINT32]);
  325. UA_DataValue staticValueSource2;
  326. memset(&staticValueSource2, 0, sizeof(staticValueSource));
  327. staticValueSource2.value = variant2;
  328. dsfConfig.field.variable.staticValueSource.value = variant2;
  329. ck_assert(UA_Server_addDataSetField(server, publishedDataSetIdent, &dsfConfig, &dataSetFieldIdent).result == UA_STATUSCODE_GOOD);
  330. ck_assert(UA_Server_freezeWriterGroupConfiguration(server, writerGroupIdent) == UA_STATUSCODE_GOOD);
  331. ck_assert(UA_Server_setWriterGroupOperational(server, writerGroupIdent) == UA_STATUSCODE_GOOD);
  332. UA_ByteString buffer;
  333. UA_ByteString_init(&buffer);
  334. UA_NetworkMessage networkMessage;
  335. receiveSingleMessage(buffer, connection, &networkMessage);
  336. ck_assert((*((UA_UInt32 *)networkMessage.payload.dataSetPayload.dataSetMessages->data.keyFrameData.dataSetFields->value.data)) == 1000);
  337. ck_assert(*((UA_UInt32 *) networkMessage.payload.dataSetPayload.dataSetMessages->data.keyFrameData.dataSetFields[1].value.data) == 2000);
  338. UA_NetworkMessage_deleteMembers(&networkMessage);
  339. *intValue = (UA_UInt32) 1001;
  340. *intValue2 = (UA_UInt32) 2001;
  341. UA_ByteString_init(&buffer);
  342. memset(&networkMessage, 0, sizeof(networkMessage));
  343. ck_assert(UA_Server_setWriterGroupDisabled(server, writerGroupIdent) == UA_STATUSCODE_GOOD);
  344. ck_assert(UA_Server_setWriterGroupOperational(server, writerGroupIdent) == UA_STATUSCODE_GOOD);
  345. receiveSingleMessage(buffer, connection, &networkMessage);
  346. ck_assert((*((UA_UInt32 *)networkMessage.payload.dataSetPayload.dataSetMessages->data.keyFrameData.dataSetFields->value.data)) == 1001);
  347. ck_assert(*((UA_UInt32 *) networkMessage.payload.dataSetPayload.dataSetMessages->data.keyFrameData.dataSetFields[1].value.data) == 2001);
  348. UA_NetworkMessage_deleteMembers(&networkMessage);
  349. } END_TEST
  350. int main(void) {
  351. TCase *tc_pubsub_rt_static_value_source = tcase_create("PubSub RT publish with static value sources");
  352. tcase_add_checked_fixture(tc_pubsub_rt_static_value_source, setup, teardown);
  353. tcase_add_test(tc_pubsub_rt_static_value_source, PublishSingleFieldWithStaticValueSource);
  354. tcase_add_test(tc_pubsub_rt_static_value_source, PublishSingleFieldWithDifferentBinarySizes);
  355. tcase_add_test(tc_pubsub_rt_static_value_source, SetupInvalidPubSubConfigWithStaticValueSource);
  356. TCase *tc_pubsub_rt_fixed_offsets = tcase_create("PubSub RT publish with fixed offsets");
  357. tcase_add_checked_fixture(tc_pubsub_rt_fixed_offsets, setup, teardown);
  358. tcase_add_test(tc_pubsub_rt_fixed_offsets, PublishSingleFieldWithFixedOffsets);
  359. tcase_add_test(tc_pubsub_rt_fixed_offsets, PublishPDSWithMultipleFieldsAndFixedOffset);
  360. Suite *s = suite_create("PubSub RT configuration levels");
  361. suite_add_tcase(s, tc_pubsub_rt_static_value_source);
  362. suite_add_tcase(s, tc_pubsub_rt_fixed_offsets);
  363. SRunner *sr = srunner_create(s);
  364. srunner_set_fork_status(sr, CK_NOFORK);
  365. srunner_run_all(sr,CK_NORMAL);
  366. int number_failed = srunner_ntests_failed(sr);
  367. srunner_free(sr);
  368. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  369. }