check_pubsub_publish.c 23 KB

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