check_pubsub_publish.c 25 KB

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