check_pubsub_publish.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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) 2017 - 2018 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_pubsub.h"
  12. #include "ua_server_internal.h"
  13. #include <check.h>
  14. UA_Server *server = NULL;
  15. UA_NodeId connection1, connection2, writerGroup1, writerGroup2, writerGroup3,
  16. publishedDataSet1, publishedDataSet2, dataSetWriter1, dataSetWriter2, dataSetWriter3;
  17. static void setup(void) {
  18. server = UA_Server_new();
  19. UA_ServerConfig *config = UA_Server_getConfig(server);
  20. UA_ServerConfig_setDefault(config);
  21. config->pubsubTransportLayers = (UA_PubSubTransportLayer*)
  22. UA_malloc(sizeof(UA_PubSubTransportLayer));
  23. config->pubsubTransportLayers[0] = UA_PubSubTransportLayerUDPMP();
  24. config->pubsubTransportLayersSize++;
  25. UA_Server_run_startup(server);
  26. //add 2 connections
  27. UA_PubSubConnectionConfig connectionConfig;
  28. memset(&connectionConfig, 0, sizeof(UA_PubSubConnectionConfig));
  29. connectionConfig.name = UA_STRING("UADP Connection");
  30. UA_NetworkAddressUrlDataType networkAddressUrl = {UA_STRING_NULL, UA_STRING("opc.udp://224.0.0.22:4840/")};
  31. UA_Variant_setScalar(&connectionConfig.address, &networkAddressUrl,
  32. &UA_TYPES[UA_TYPES_NETWORKADDRESSURLDATATYPE]);
  33. connectionConfig.transportProfileUri = UA_STRING("http://opcfoundation.org/UA-Profile/Transport/pubsub-udp-uadp");
  34. UA_Server_addPubSubConnection(server, &connectionConfig, &connection1);
  35. UA_Server_addPubSubConnection(server, &connectionConfig, &connection2);
  36. }
  37. static void teardown(void) {
  38. UA_Server_run_shutdown(server);
  39. UA_Server_delete(server);
  40. }
  41. START_TEST(AddWriterGroupWithValidConfiguration){
  42. UA_StatusCode retVal;
  43. UA_WriterGroupConfig writerGroupConfig;
  44. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  45. writerGroupConfig.name = UA_STRING("WriterGroup 1");
  46. writerGroupConfig.publishingInterval = 10;
  47. UA_NodeId localWriterGroup;
  48. retVal = UA_Server_addWriterGroup(server, connection1, &writerGroupConfig, &localWriterGroup);
  49. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  50. size_t writerGroupCount = 0;
  51. UA_WriterGroup *writerGroup;
  52. LIST_FOREACH(writerGroup, &UA_PubSubConnection_findConnectionbyId(server, connection1)->writerGroups, listEntry){
  53. writerGroupCount++;
  54. }
  55. ck_assert_int_eq(writerGroupCount, 1);
  56. } END_TEST
  57. START_TEST(AddRemoveAddWriterGroupWithMinimalValidConfiguration){
  58. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  59. UA_WriterGroupConfig writerGroupConfig;
  60. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  61. writerGroupConfig.name = UA_STRING("WriterGroup 1");
  62. writerGroupConfig.publishingInterval = 10;
  63. UA_NodeId localWriterGroup;
  64. retVal |= UA_Server_addWriterGroup(server, connection1, &writerGroupConfig, &localWriterGroup);
  65. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  66. retVal |= UA_Server_removeWriterGroup(server, localWriterGroup);
  67. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  68. size_t writerGroupCount = 0;
  69. UA_WriterGroup *writerGroup;
  70. LIST_FOREACH(writerGroup, &UA_PubSubConnection_findConnectionbyId(server, connection1)->writerGroups, listEntry){
  71. writerGroupCount++;
  72. }
  73. ck_assert_int_eq(writerGroupCount, 0);
  74. retVal |= UA_Server_addWriterGroup(server, connection1, &writerGroupConfig, &localWriterGroup);
  75. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  76. writerGroupCount = 0;
  77. LIST_FOREACH(writerGroup, &UA_PubSubConnection_findConnectionbyId(server, connection1)->writerGroups, listEntry){
  78. writerGroupCount++;
  79. }
  80. ck_assert_int_eq(writerGroupCount, 1);
  81. retVal |= UA_Server_addWriterGroup(server, connection1, &writerGroupConfig, &localWriterGroup);
  82. writerGroupCount = 0;
  83. LIST_FOREACH(writerGroup, &UA_PubSubConnection_findConnectionbyId(server, connection1)->writerGroups, listEntry){
  84. writerGroupCount++;
  85. }
  86. ck_assert_int_eq(writerGroupCount, 2);
  87. } END_TEST
  88. START_TEST(AddWriterGroupWithNullConfig){
  89. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  90. retVal |= UA_Server_addWriterGroup(server, connection1, NULL, NULL);
  91. size_t writerGroupCount = 0;
  92. UA_WriterGroup *writerGroup;
  93. LIST_FOREACH(writerGroup, &UA_PubSubConnection_findConnectionbyId(server, connection1)->writerGroups, listEntry){
  94. writerGroupCount++;
  95. }
  96. ck_assert_int_eq(writerGroupCount, 0);
  97. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  98. } END_TEST
  99. START_TEST(AddWriterGroupWithInvalidConnectionId){
  100. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  101. UA_WriterGroupConfig writerGroupConfig;
  102. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  103. writerGroupConfig.name = UA_STRING("WriterGroup 1");
  104. writerGroupConfig.publishingInterval = 10;
  105. retVal |= UA_Server_addWriterGroup(server, UA_NODEID_NUMERIC(0, UA_UINT32_MAX), &writerGroupConfig, NULL);
  106. size_t writerGroupCount = 0;
  107. UA_WriterGroup *writerGroup;
  108. LIST_FOREACH(writerGroup, &UA_PubSubConnection_findConnectionbyId(server, connection1)->writerGroups, listEntry){
  109. writerGroupCount++;
  110. }
  111. ck_assert_int_eq(writerGroupCount, 0);
  112. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  113. } END_TEST
  114. START_TEST(GetWriterGroupConfigurationAndCompareValues){
  115. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  116. UA_WriterGroupConfig writerGroupConfig;
  117. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  118. writerGroupConfig.name = UA_STRING("WriterGroup 1");
  119. writerGroupConfig.publishingInterval = 10;
  120. UA_NodeId localWriterGroup;
  121. retVal |= UA_Server_addWriterGroup(server, connection1, &writerGroupConfig, &localWriterGroup);
  122. UA_WriterGroupConfig writerGroupConfigCopy;
  123. retVal |= UA_Server_getWriterGroupConfig(server, localWriterGroup, &writerGroupConfigCopy);
  124. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  125. ck_assert_int_eq(UA_String_equal(&writerGroupConfig.name, &writerGroupConfigCopy.name), UA_TRUE);
  126. //todo remove == for floating point compare
  127. ck_assert(writerGroupConfig.publishingInterval == writerGroupConfig.publishingInterval);
  128. UA_WriterGroupConfig_deleteMembers(&writerGroupConfigCopy);
  129. } END_TEST
  130. static void setupDataSetWriterTestEnvironment(void){
  131. UA_WriterGroupConfig writerGroupConfig;
  132. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  133. writerGroupConfig.name = UA_STRING("WriterGroup 1");
  134. writerGroupConfig.publishingInterval = 10;
  135. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  136. UA_Server_addWriterGroup(server, connection1, &writerGroupConfig, &writerGroup1);
  137. writerGroupConfig.name = UA_STRING("WriterGroup 2");
  138. writerGroupConfig.publishingInterval = 50;
  139. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  140. UA_Server_addWriterGroup(server, connection2, &writerGroupConfig, &writerGroup2);
  141. writerGroupConfig.name = UA_STRING("WriterGroup 3");
  142. writerGroupConfig.publishingInterval = 100;
  143. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  144. UA_Server_addWriterGroup(server, connection2, &writerGroupConfig, &writerGroup3);
  145. UA_PublishedDataSetConfig pdsConfig;
  146. memset(&pdsConfig, 0, sizeof(UA_PublishedDataSetConfig));
  147. pdsConfig.publishedDataSetType = UA_PUBSUB_DATASET_PUBLISHEDITEMS;
  148. pdsConfig.name = UA_STRING("PublishedDataSet 1");
  149. UA_Server_addPublishedDataSet(server, &pdsConfig, &publishedDataSet1);
  150. UA_Server_addPublishedDataSet(server, &pdsConfig, &publishedDataSet2);
  151. }
  152. START_TEST(AddDataSetWriterWithValidConfiguration){
  153. setupDataSetWriterTestEnvironment();
  154. UA_StatusCode retVal;
  155. UA_DataSetWriterConfig dataSetWriterConfig;
  156. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  157. dataSetWriterConfig.name = UA_STRING("DataSetWriter 1 ");
  158. UA_NodeId localDataSetWriter;
  159. retVal = UA_Server_addDataSetWriter(server, writerGroup1, publishedDataSet1, &dataSetWriterConfig, &localDataSetWriter);
  160. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  161. UA_DataSetWriter *dsw1 = UA_DataSetWriter_findDSWbyId(server, localDataSetWriter);
  162. ck_assert_ptr_ne(dsw1, NULL);
  163. UA_WriterGroup *wg1 = UA_WriterGroup_findWGbyId(server, writerGroup1);
  164. ck_assert_ptr_ne(wg1, NULL);
  165. ck_assert_int_eq(wg1->writersCount, 1);
  166. } END_TEST
  167. START_TEST(AddRemoveAddDataSetWriterWithValidConfiguration){
  168. setupDataSetWriterTestEnvironment();
  169. UA_StatusCode retVal;
  170. UA_WriterGroup *wg1 = UA_WriterGroup_findWGbyId(server, writerGroup1);
  171. ck_assert_ptr_ne(wg1, NULL);
  172. UA_DataSetWriterConfig dataSetWriterConfig;
  173. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  174. dataSetWriterConfig.name = UA_STRING("DataSetWriter 1 ");
  175. UA_NodeId dataSetWriter;
  176. ck_assert_int_eq(wg1->writersCount, 0);
  177. retVal = UA_Server_addDataSetWriter(server, writerGroup1, publishedDataSet1, &dataSetWriterConfig, &dataSetWriter);
  178. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  179. ck_assert_int_eq(wg1->writersCount, 1);
  180. retVal = UA_Server_removeDataSetWriter(server, dataSetWriter);
  181. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  182. ck_assert_int_eq(wg1->writersCount, 0);
  183. retVal = UA_Server_addDataSetWriter(server, writerGroup1, publishedDataSet1, &dataSetWriterConfig, &dataSetWriter);
  184. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  185. ck_assert_int_eq(wg1->writersCount, 1);
  186. retVal = UA_Server_addDataSetWriter(server, writerGroup1, publishedDataSet1, &dataSetWriterConfig, &dataSetWriter);
  187. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  188. ck_assert_int_eq(wg1->writersCount, 2);
  189. UA_WriterGroup *wg2 = UA_WriterGroup_findWGbyId(server, writerGroup2);
  190. ck_assert_ptr_ne(wg2, NULL);
  191. retVal = UA_Server_addDataSetWriter(server, writerGroup2, publishedDataSet1, &dataSetWriterConfig, &dataSetWriter);
  192. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  193. ck_assert_int_eq(wg2->writersCount, 1);
  194. } END_TEST
  195. START_TEST(AddDataSetWriterWithNullConfig){
  196. setupDataSetWriterTestEnvironment();
  197. UA_StatusCode retVal;
  198. retVal = UA_Server_addDataSetWriter(server, writerGroup1, publishedDataSet1, NULL, NULL);
  199. UA_WriterGroup *wg1 = UA_WriterGroup_findWGbyId(server, writerGroup1);
  200. ck_assert_ptr_ne(wg1, NULL);
  201. ck_assert_int_eq(wg1->writersCount, 0);
  202. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  203. } END_TEST
  204. START_TEST(AddDataSetWriterWithInvalidPDSId){
  205. setupDataSetWriterTestEnvironment();
  206. UA_StatusCode retVal;
  207. UA_DataSetWriterConfig dataSetWriterConfig;
  208. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  209. dataSetWriterConfig.name = UA_STRING("DataSetWriter 1 ");
  210. retVal = UA_Server_addDataSetWriter(server, writerGroup1, UA_NODEID_NUMERIC(0, UA_UINT32_MAX), &dataSetWriterConfig, NULL);
  211. UA_WriterGroup *wg1 = UA_WriterGroup_findWGbyId(server, writerGroup1);
  212. ck_assert_ptr_ne(wg1, NULL);
  213. ck_assert_int_eq(wg1->writersCount, 0);
  214. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  215. } END_TEST
  216. START_TEST(GetDataSetWriterConfigurationAndCompareValues){
  217. setupDataSetWriterTestEnvironment();
  218. UA_StatusCode retVal;
  219. UA_DataSetWriterConfig dataSetWriterConfig;
  220. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  221. dataSetWriterConfig.name = UA_STRING("DataSetWriter 1 ");
  222. UA_NodeId localDataSetWriter;
  223. retVal = UA_Server_addDataSetWriter(server, writerGroup1, publishedDataSet1, &dataSetWriterConfig, &localDataSetWriter);
  224. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  225. UA_DataSetWriterConfig dataSetWiterConfigCopy;
  226. retVal |= UA_Server_getDataSetWriterConfig(server, localDataSetWriter, &dataSetWiterConfigCopy);
  227. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  228. ck_assert_int_eq(UA_String_equal(&dataSetWiterConfigCopy.name, &dataSetWiterConfigCopy.name), UA_TRUE);
  229. UA_DataSetWriterConfig_deleteMembers(&dataSetWiterConfigCopy);
  230. } END_TEST
  231. static void setupDataSetFieldTestEnvironment(void){
  232. setupDataSetWriterTestEnvironment();
  233. UA_DataSetWriterConfig dataSetWriterConfig;
  234. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  235. dataSetWriterConfig.name = UA_STRING("DataSetWriter 1");
  236. UA_Server_addDataSetWriter(server, writerGroup1, publishedDataSet1, &dataSetWriterConfig, &dataSetWriter1);
  237. dataSetWriterConfig.name = UA_STRING("DataSetWriter 2");
  238. UA_Server_addDataSetWriter(server, writerGroup1, publishedDataSet1, &dataSetWriterConfig, &dataSetWriter2);
  239. dataSetWriterConfig.name = UA_STRING("DataSetWriter 3");
  240. UA_Server_addDataSetWriter(server, writerGroup2, publishedDataSet2, &dataSetWriterConfig, &dataSetWriter3);
  241. }
  242. START_TEST(AddDataSetFieldWithValidConfiguration){
  243. setupDataSetFieldTestEnvironment();
  244. UA_StatusCode retVal;
  245. UA_DataSetFieldConfig fieldConfig;
  246. memset(&fieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  247. fieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  248. fieldConfig.field.variable.fieldNameAlias = UA_STRING("field 1");
  249. UA_NodeId localDataSetField;
  250. UA_PublishedDataSet *pds = UA_PublishedDataSet_findPDSbyId(server, publishedDataSet1);
  251. ck_assert_ptr_ne(pds, NULL);
  252. ck_assert_int_eq(pds->fieldSize, 0);
  253. retVal = UA_Server_addDataSetField(server, publishedDataSet1, &fieldConfig, &localDataSetField).result;
  254. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  255. ck_assert_int_eq(pds->fieldSize, 1);
  256. } END_TEST
  257. START_TEST(AddRemoveAddDataSetFieldWithValidConfiguration){
  258. setupDataSetFieldTestEnvironment();
  259. UA_StatusCode retVal;
  260. UA_DataSetFieldConfig fieldConfig;
  261. memset(&fieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  262. fieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  263. fieldConfig.field.variable.fieldNameAlias = UA_STRING("field 1");
  264. UA_NodeId localDataSetField;
  265. UA_PublishedDataSet *pds1 = UA_PublishedDataSet_findPDSbyId(server, publishedDataSet1);
  266. ck_assert_ptr_ne(pds1, NULL);
  267. ck_assert_int_eq(pds1->fieldSize, 0);
  268. retVal = UA_Server_addDataSetField(server, publishedDataSet1, &fieldConfig, &localDataSetField).result;
  269. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  270. ck_assert_int_eq(pds1->fieldSize, 1);
  271. retVal = UA_Server_removeDataSetField(server, localDataSetField).result;
  272. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  273. ck_assert_int_eq(pds1->fieldSize, 0);
  274. retVal = UA_Server_addDataSetField(server, publishedDataSet1, &fieldConfig, &localDataSetField).result;
  275. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  276. ck_assert_int_eq(pds1->fieldSize, 1);
  277. retVal = UA_Server_addDataSetField(server, publishedDataSet1, &fieldConfig, &localDataSetField).result;
  278. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  279. ck_assert_int_eq(pds1->fieldSize, 2);
  280. UA_PublishedDataSet *pds2 = UA_PublishedDataSet_findPDSbyId(server, publishedDataSet2);
  281. ck_assert_ptr_ne(pds2, NULL);
  282. retVal = UA_Server_addDataSetField(server, publishedDataSet2, &fieldConfig, &localDataSetField).result;
  283. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  284. ck_assert_int_eq(pds2->fieldSize, 1);
  285. } END_TEST
  286. START_TEST(AddDataSetFieldWithNullConfig){
  287. setupDataSetFieldTestEnvironment();
  288. UA_StatusCode retVal;
  289. retVal = UA_Server_addDataSetField(server, publishedDataSet1, NULL, NULL).result;
  290. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  291. UA_PublishedDataSet *pds1 = UA_PublishedDataSet_findPDSbyId(server, publishedDataSet1);
  292. ck_assert_ptr_ne(pds1, NULL);
  293. ck_assert_int_eq(pds1->fieldSize, 0);
  294. } END_TEST
  295. START_TEST(AddDataSetFieldWithInvalidPDSId){
  296. setupDataSetFieldTestEnvironment();
  297. UA_StatusCode retVal;
  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. retVal = UA_Server_addDataSetField(server, UA_NODEID_NUMERIC(0, UA_UINT32_MAX), &fieldConfig, NULL).result;
  303. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  304. UA_PublishedDataSet *pds1 = UA_PublishedDataSet_findPDSbyId(server, publishedDataSet1);
  305. ck_assert_ptr_ne(pds1, NULL);
  306. ck_assert_int_eq(pds1->fieldSize, 0);
  307. } END_TEST
  308. START_TEST(GetDataSetFieldConfigurationAndCompareValues){
  309. setupDataSetFieldTestEnvironment();
  310. UA_StatusCode retVal;
  311. UA_DataSetFieldConfig fieldConfig;
  312. memset(&fieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  313. fieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  314. fieldConfig.field.variable.fieldNameAlias = UA_STRING("field 1");
  315. UA_NodeId dataSetFieldId;
  316. retVal = UA_Server_addDataSetField(server, publishedDataSet1, &fieldConfig, &dataSetFieldId).result;
  317. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  318. UA_DataSetFieldConfig fieldConfigCopy;
  319. retVal |= UA_Server_getDataSetFieldConfig(server, dataSetFieldId, &fieldConfigCopy);
  320. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  321. ck_assert_int_eq(fieldConfig.dataSetFieldType, fieldConfigCopy.dataSetFieldType);
  322. ck_assert_int_eq(UA_String_equal(&fieldConfig.field.variable.fieldNameAlias, &fieldConfigCopy.field.variable.fieldNameAlias), UA_TRUE);
  323. UA_DataSetFieldConfig_deleteMembers(&fieldConfigCopy);
  324. } END_TEST
  325. START_TEST(SinglePublishDataSetField){
  326. UA_WriterGroupConfig writerGroupConfig;
  327. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  328. writerGroupConfig.name = UA_STRING("WriterGroup 1");
  329. writerGroupConfig.publishingInterval = 10;
  330. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  331. UA_Server_addWriterGroup(server, connection1, &writerGroupConfig, &writerGroup1);
  332. writerGroupConfig.name = UA_STRING("WriterGroup 2");
  333. writerGroupConfig.publishingInterval = 50;
  334. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  335. UA_Server_addWriterGroup(server, connection2, &writerGroupConfig, &writerGroup2);
  336. writerGroupConfig.name = UA_STRING("WriterGroup 3");
  337. writerGroupConfig.publishingInterval = 100;
  338. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  339. UA_Server_addWriterGroup(server, connection2, &writerGroupConfig, &writerGroup3);
  340. UA_PublishedDataSetConfig pdsConfig;
  341. memset(&pdsConfig, 0, sizeof(UA_PublishedDataSetConfig));
  342. pdsConfig.publishedDataSetType = UA_PUBSUB_DATASET_PUBLISHEDITEMS;
  343. pdsConfig.name = UA_STRING("PublishedDataSet 1");
  344. UA_Server_addPublishedDataSet(server, &pdsConfig, &publishedDataSet1);
  345. UA_Server_addPublishedDataSet(server, &pdsConfig, &publishedDataSet2);
  346. UA_DataSetWriterConfig dataSetWriterConfig;
  347. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  348. dataSetWriterConfig.name = UA_STRING("DataSetWriter 1");
  349. UA_Server_addDataSetWriter(server, writerGroup1, publishedDataSet1, &dataSetWriterConfig, &dataSetWriter1);
  350. UA_DataSetFieldConfig dataSetFieldConfig;
  351. memset(&dataSetFieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  352. dataSetFieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  353. dataSetFieldConfig.field.variable.fieldNameAlias = UA_STRING("Server localtime");
  354. dataSetFieldConfig.field.variable.promotedField = UA_FALSE;
  355. dataSetFieldConfig.field.variable.publishParameters.publishedVariable = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_LOCALTIME);
  356. dataSetFieldConfig.field.variable.publishParameters.attributeId = UA_ATTRIBUTEID_VALUE;
  357. UA_Server_addDataSetField(server, publishedDataSet1, &dataSetFieldConfig, NULL);
  358. UA_WriterGroup *wg = UA_WriterGroup_findWGbyId(server, writerGroup1);
  359. UA_WriterGroup_publishCallback(server, wg);
  360. } END_TEST
  361. START_TEST(PublishDataSetFieldAsDeltaFrame){
  362. setupDataSetFieldTestEnvironment();
  363. UA_DataSetFieldConfig dataSetFieldConfig;
  364. memset(&dataSetFieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  365. dataSetFieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  366. dataSetFieldConfig.field.variable.fieldNameAlias = UA_STRING("Server localtime");
  367. dataSetFieldConfig.field.variable.promotedField = UA_FALSE;
  368. dataSetFieldConfig.field.variable.publishParameters.publishedVariable = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_LOCALTIME);
  369. dataSetFieldConfig.field.variable.publishParameters.attributeId = UA_ATTRIBUTEID_VALUE;
  370. UA_Server_addDataSetField(server, publishedDataSet1, &dataSetFieldConfig, NULL);
  371. UA_Server_addDataSetField(server, publishedDataSet1, &dataSetFieldConfig, NULL);
  372. UA_WriterGroup *wg = UA_WriterGroup_findWGbyId(server, writerGroup1);
  373. wg->config.maxEncapsulatedDataSetMessageCount = 3;
  374. UA_DataSetWriter *dsw = UA_DataSetWriter_findDSWbyId(server, dataSetWriter1);
  375. dsw->config.keyFrameCount = 3;
  376. UA_WriterGroup_publishCallback(server, wg);
  377. UA_WriterGroup_publishCallback(server, wg);
  378. UA_WriterGroup_publishCallback(server, wg);
  379. UA_WriterGroup_publishCallback(server, wg);
  380. UA_WriterGroup_publishCallback(server, wg);
  381. } END_TEST
  382. int main(void) {
  383. TCase *tc_add_pubsub_writergroup = tcase_create("PubSub WriterGroup items handling");
  384. tcase_add_checked_fixture(tc_add_pubsub_writergroup, setup, teardown);
  385. tcase_add_test(tc_add_pubsub_writergroup, AddWriterGroupWithValidConfiguration);
  386. tcase_add_test(tc_add_pubsub_writergroup, AddRemoveAddWriterGroupWithMinimalValidConfiguration);
  387. tcase_add_test(tc_add_pubsub_writergroup, AddWriterGroupWithNullConfig);
  388. tcase_add_test(tc_add_pubsub_writergroup, AddWriterGroupWithInvalidConnectionId);
  389. tcase_add_test(tc_add_pubsub_writergroup, GetWriterGroupConfigurationAndCompareValues);
  390. TCase *tc_add_pubsub_datasetwriter = tcase_create("PubSub DataSetWriter items handling");
  391. tcase_add_checked_fixture(tc_add_pubsub_datasetwriter, setup, teardown);
  392. tcase_add_test(tc_add_pubsub_datasetwriter, AddDataSetWriterWithValidConfiguration);
  393. tcase_add_test(tc_add_pubsub_datasetwriter, AddRemoveAddDataSetWriterWithValidConfiguration);
  394. tcase_add_test(tc_add_pubsub_datasetwriter, AddDataSetWriterWithNullConfig);
  395. tcase_add_test(tc_add_pubsub_datasetwriter, AddDataSetWriterWithInvalidPDSId);
  396. tcase_add_test(tc_add_pubsub_datasetwriter, GetDataSetWriterConfigurationAndCompareValues);
  397. TCase *tc_add_pubsub_datasetfields = tcase_create("PubSub DataSetField items handling");
  398. tcase_add_checked_fixture(tc_add_pubsub_datasetfields, setup, teardown);
  399. tcase_add_test(tc_add_pubsub_datasetfields, AddDataSetFieldWithValidConfiguration);
  400. tcase_add_test(tc_add_pubsub_datasetfields, AddRemoveAddDataSetFieldWithValidConfiguration);
  401. tcase_add_test(tc_add_pubsub_datasetfields, AddDataSetFieldWithNullConfig);
  402. tcase_add_test(tc_add_pubsub_datasetfields, AddDataSetFieldWithInvalidPDSId);
  403. tcase_add_test(tc_add_pubsub_datasetfields, GetDataSetFieldConfigurationAndCompareValues);
  404. TCase *tc_pubsub_publish = tcase_create("PubSub publish DataSetFields");
  405. tcase_add_checked_fixture(tc_pubsub_publish, setup, teardown);
  406. tcase_add_test(tc_pubsub_publish, SinglePublishDataSetField);
  407. tcase_add_test(tc_pubsub_publish, PublishDataSetFieldAsDeltaFrame);
  408. Suite *s = suite_create("PubSub WriterGroups/Writer/Fields handling and publishing");
  409. suite_add_tcase(s, tc_add_pubsub_writergroup);
  410. suite_add_tcase(s, tc_add_pubsub_datasetwriter);
  411. suite_add_tcase(s, tc_add_pubsub_datasetfields);
  412. suite_add_tcase(s, tc_pubsub_publish);
  413. SRunner *sr = srunner_create(s);
  414. srunner_set_fork_status(sr, CK_NOFORK);
  415. srunner_run_all(sr,CK_NORMAL);
  416. int number_failed = srunner_ntests_failed(sr);
  417. srunner_free(sr);
  418. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  419. }