check_pubsub_subscribe.c 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363
  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 Kalycito Infotech Private Limited
  6. */
  7. #include <open62541/plugin/pubsub_udp.h>
  8. #include <open62541/server_config_default.h>
  9. #include <open62541/server_pubsub.h>
  10. #include <check.h>
  11. #include <time.h>
  12. #include "open62541/types_generated_encoding_binary.h"
  13. #include "ua_pubsub.h"
  14. #include "ua_server_internal.h"
  15. #define UA_SUBSCRIBER_PORT 4801 /* Port for Subscriber*/
  16. #define PUBLISH_INTERVAL 5 /* Publish interval*/
  17. #define PUBLISHER_ID 2234 /* Publisher Id*/
  18. #define DATASET_WRITER_ID 62541 /* DataSet Writer Id*/
  19. #define WRITER_GROUP_ID 100 /* Writer group Id */
  20. #define PUBLISHER_DATA 42 /* Published data */
  21. #define PUBLISHVARIABLE_NODEID 1000 /* Published data nodeId */
  22. #define SUBSCRIBEOBJECT_NODEID 1001 /* Object nodeId */
  23. #define SUBSCRIBEVARIABLE_NODEID 1002 /* Subscribed data nodeId */
  24. #define READERGROUP_COUNT 2 /* Value to add readergroup to connection */
  25. #define CHECK_READERGROUP_COUNT 3 /* Value to check readergroup count */
  26. /* Global declaration for test cases */
  27. UA_Server *server = NULL;
  28. UA_ServerConfig *config = NULL;
  29. UA_NodeId connection_test;
  30. UA_NodeId readerGroupTest;
  31. UA_NodeId publishedDataSetTest;
  32. /* setup() is to create an environment for test cases */
  33. static void setup(void) {
  34. /*Add setup by creating new server with valid configuration */
  35. server = UA_Server_new();
  36. config = UA_Server_getConfig(server);
  37. UA_ServerConfig_setMinimal(config, UA_SUBSCRIBER_PORT, NULL);
  38. UA_Server_run_startup(server);
  39. config->pubsubTransportLayers = (UA_PubSubTransportLayer *) UA_malloc(sizeof(UA_PubSubTransportLayer));
  40. if(!config->pubsubTransportLayers) {
  41. UA_ServerConfig_clean(config);
  42. }
  43. config->pubsubTransportLayers[0] = UA_PubSubTransportLayerUDPMP();
  44. config->pubsubTransportLayersSize++;
  45. /* Add connection to the server */
  46. UA_PubSubConnectionConfig connectionConfig;
  47. memset(&connectionConfig, 0, sizeof(UA_PubSubConnectionConfig));
  48. connectionConfig.name = UA_STRING("UADP Test Connection");
  49. UA_NetworkAddressUrlDataType networkAddressUrl = {UA_STRING_NULL, UA_STRING("opc.udp://224.0.0.22:4801/")};
  50. UA_Variant_setScalar(&connectionConfig.address, &networkAddressUrl,
  51. &UA_TYPES[UA_TYPES_NETWORKADDRESSURLDATATYPE]);
  52. connectionConfig.transportProfileUri = UA_STRING("http://opcfoundation.org/UA-Profile/Transport/pubsub-udp-uadp");
  53. connectionConfig.publisherId.numeric = PUBLISHER_ID;
  54. UA_Server_addPubSubConnection(server, &connectionConfig, &connection_test);
  55. UA_PubSubConnection_regist(server, &connection_test);
  56. }
  57. /* teardown() is to delete the environment set for test cases */
  58. static void teardown(void) {
  59. /*Call server delete functions */
  60. UA_Server_run_shutdown(server);
  61. UA_Server_delete(server);
  62. }
  63. START_TEST(AddReaderGroupWithValidConfiguration) {
  64. /* To test if ReaderGroup has been added to the connection with valid configuration */
  65. UA_StatusCode retVal;
  66. UA_ReaderGroupConfig readerGroupConfig;
  67. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  68. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  69. UA_NodeId localreaderGroup;
  70. retVal = UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  71. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  72. size_t readerGroupCount = 0;
  73. UA_ReaderGroup *readerGroup;
  74. LIST_FOREACH(readerGroup, &UA_PubSubConnection_findConnectionbyId(server, connection_test)->readerGroups, listEntry){
  75. readerGroupCount++;
  76. }
  77. /* Check readerGroup count */
  78. ck_assert_int_eq(readerGroupCount, 1);
  79. /* To Do: RemoveReaderGroup operation should be carried out when UA_Server_delete has been called */
  80. UA_Server_removeReaderGroup(server, localreaderGroup);
  81. } END_TEST
  82. START_TEST(AddReaderGroupWithNullConfig) {
  83. /* Check the status of adding ReaderGroup when NULL configuration is given */
  84. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  85. retVal |= UA_Server_addReaderGroup(server, connection_test, NULL, NULL);
  86. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  87. size_t readerGroupCount = 0;
  88. UA_ReaderGroup *readerGroup;
  89. LIST_FOREACH(readerGroup, &UA_PubSubConnection_findConnectionbyId(server, connection_test)->readerGroups, listEntry){
  90. readerGroupCount++;
  91. }
  92. /* Check readerGroup count */
  93. ck_assert_int_eq(readerGroupCount, 0);
  94. } END_TEST
  95. START_TEST(AddReaderGroupWithInvalidConnectionId) {
  96. /* Check status of adding ReaderGroup with invalid connection identifier */
  97. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  98. UA_ReaderGroupConfig readerGroupConfig;
  99. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  100. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  101. retVal |= UA_Server_addReaderGroup(server, UA_NODEID_NUMERIC(0, UA_UINT32_MAX), &readerGroupConfig, NULL);
  102. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  103. size_t readerGroupCount = 0;
  104. UA_ReaderGroup *readerGroup;
  105. LIST_FOREACH(readerGroup, &UA_PubSubConnection_findConnectionbyId(server, connection_test)->readerGroups, listEntry){
  106. readerGroupCount++;
  107. }
  108. /* Check readerGroup count */
  109. ck_assert_int_eq(readerGroupCount, 0);
  110. } END_TEST
  111. START_TEST(RemoveReaderGroupWithInvalidIdentifier) {
  112. /* Check status of removing ReaderGroup when giving invalid ReaderGroup identifier */
  113. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  114. UA_ReaderGroupConfig readerGroupConfig;
  115. UA_NodeId localreaderGroup;
  116. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  117. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  118. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  119. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  120. /* Delete the added readerGroup */
  121. retVal |= UA_Server_removeReaderGroup(server, UA_NODEID_NUMERIC(0, UA_UINT32_MAX));
  122. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  123. size_t readerGroupCount = 0;
  124. UA_ReaderGroup *readerGroup;
  125. LIST_FOREACH(readerGroup, &UA_PubSubConnection_findConnectionbyId(server, connection_test)->readerGroups, listEntry){
  126. readerGroupCount++;
  127. }
  128. /* Check readerGroup count */
  129. ck_assert_int_eq(readerGroupCount, 1);
  130. UA_Server_removeReaderGroup(server, localreaderGroup);
  131. } END_TEST
  132. START_TEST(AddRemoveMultipleAddReaderGroupWithValidConfiguration) {
  133. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  134. UA_ReaderGroupConfig readerGroupConfig;
  135. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  136. readerGroupConfig.name = UA_STRING("ReaderGroup 1");
  137. UA_NodeId localReaderGroup;
  138. /* Add ReaderGroup */
  139. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localReaderGroup);
  140. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  141. /* Remove added ReaderGroup */
  142. retVal |= UA_Server_removeReaderGroup(server, localReaderGroup);
  143. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  144. size_t readerGroupCount = 0;
  145. UA_ReaderGroup *readerGroup;
  146. LIST_FOREACH(readerGroup, &UA_PubSubConnection_findConnectionbyId(server, connection_test)->readerGroups, listEntry) {
  147. readerGroupCount++;
  148. }
  149. /* Check ReaderGroup Count */
  150. ck_assert_int_eq(readerGroupCount, 0);
  151. /* Add Multiple ReaderGroups */
  152. for (int iterator = 0; iterator <= READERGROUP_COUNT; iterator++) {
  153. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localReaderGroup);
  154. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  155. }
  156. readerGroupCount = 0;
  157. /* Find ReaderGroup count */
  158. LIST_FOREACH(readerGroup, &UA_PubSubConnection_findConnectionbyId(server, connection_test)->readerGroups, listEntry) {
  159. readerGroupCount++;
  160. }
  161. /* Check ReaderGroup Count */
  162. ck_assert_int_eq(readerGroupCount, CHECK_READERGROUP_COUNT);
  163. } END_TEST
  164. /* Check status of updating ReaderGroup with invalid identifier */
  165. /*
  166. START_TEST(UpdateReaderGroupWithInvalidIdentifier) {
  167. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  168. UA_ReaderGroupConfig readerGroupConfig;
  169. UA_NodeId localreaderGroup;
  170. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  171. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  172. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  173. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  174. retVal |= UA_Server_ReaderGroup_updateConfig(server, UA_NODEID_NUMERIC(0, UA_UINT32_MAX), NULL);
  175. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  176. UA_Server_removeReaderGroup(server, localreaderGroup);
  177. } END_TEST
  178. */
  179. START_TEST(GetReaderGroupConfigWithInvalidConfig) {
  180. /* Check status of getting ReaderGroup configuration with invalid configuration */
  181. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  182. UA_ReaderGroupConfig readerGroupConfig;
  183. UA_NodeId localreaderGroup;
  184. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  185. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  186. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  187. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  188. retVal |= UA_Server_ReaderGroup_getConfig(server, UA_NODEID_NUMERIC(0, UA_UINT32_MAX), NULL);
  189. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  190. UA_Server_removeReaderGroup(server, localreaderGroup);
  191. } END_TEST
  192. START_TEST(GetReaderGroupConfigWithInvalidIdentifier) {
  193. /* Check status of getting ReaderGroup configuration with invlaid identifier */
  194. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  195. UA_ReaderGroupConfig readerGroupConfig;
  196. UA_NodeId localreaderGroup;
  197. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  198. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  199. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  200. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  201. retVal |= UA_Server_ReaderGroup_getConfig(server, UA_NODEID_NUMERIC(0, UA_UINT32_MAX), &readerGroupConfig);
  202. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  203. UA_Server_removeReaderGroup(server, localreaderGroup);
  204. } END_TEST
  205. START_TEST(GetReaderGroupConfigWithValidConfig) {
  206. /* Check status of getting ReaderGroup configuration with valid parameters */
  207. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  208. UA_NodeId localreaderGroup;
  209. UA_ReaderGroupConfig readerGroupConfig;
  210. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  211. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  212. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  213. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  214. retVal |= UA_Server_ReaderGroup_getConfig(server, localreaderGroup, &readerGroupConfig);
  215. /* To Do: DeleteMembers of readergroup config has to be a separate function */
  216. UA_String_deleteMembers (&readerGroupConfig.name);
  217. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  218. } END_TEST
  219. START_TEST(AddDataSetReaderWithValidConfiguration) {
  220. /* Check status of adding DataSetReader to ReaderGroup with valid parameters*/
  221. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  222. UA_DataSetReaderConfig dataSetreaderConfig;
  223. UA_NodeId localreaderGroup;
  224. UA_ReaderGroupConfig readerGroupConfig;
  225. UA_NodeId localDataSetreader;
  226. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  227. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  228. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  229. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  230. memset(&dataSetreaderConfig, 0, sizeof(dataSetreaderConfig));
  231. dataSetreaderConfig.name = UA_STRING("DataSetreader Test");
  232. retVal |= UA_Server_addDataSetReader(server, localreaderGroup, &dataSetreaderConfig, &localDataSetreader);
  233. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  234. } END_TEST
  235. START_TEST(AddDataSetReaderWithNullConfig) {
  236. /* Check status of adding DataSetReader to ReaderGroup with invalid parameters */
  237. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  238. UA_DataSetReaderConfig dataSetreaderConfig;
  239. UA_NodeId localreaderGroup;
  240. UA_ReaderGroupConfig readerGroupConfig;
  241. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  242. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  243. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  244. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  245. memset(&dataSetreaderConfig, 0, sizeof(dataSetreaderConfig));
  246. dataSetreaderConfig.name = UA_STRING("DataSetreader Test ");
  247. /* Remove the added DataSetReader */
  248. retVal |= UA_Server_addDataSetReader(server, localreaderGroup, NULL, NULL);
  249. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  250. } END_TEST
  251. START_TEST(RemoveDataSetReaderWithValidConfiguration) {
  252. /* Check status of adding DataSetReader to ReaderGroup with valid parameters */
  253. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  254. UA_DataSetReaderConfig dataSetreaderConfig;
  255. UA_NodeId localreaderGroup;
  256. UA_ReaderGroupConfig readerGroupConfig;
  257. UA_NodeId localDataSetreader;
  258. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  259. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  260. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  261. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  262. memset(&dataSetreaderConfig, 0, sizeof(dataSetreaderConfig));
  263. dataSetreaderConfig.name = UA_STRING("DataSetReader Test ");
  264. retVal |= UA_Server_addDataSetReader(server, localreaderGroup, &dataSetreaderConfig, &localDataSetreader);
  265. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  266. retVal |= UA_Server_removeDataSetReader(server, localDataSetreader);
  267. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  268. } END_TEST
  269. START_TEST(RemoveDataSetReaderWithInvalidIdentifier) {
  270. /* Check status of removing DataSetReader from ReaderGroup with invalid parameters */
  271. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  272. UA_DataSetReaderConfig dataSetreaderConfig;
  273. UA_NodeId localreaderGroup;
  274. UA_ReaderGroupConfig readerGroupConfig;
  275. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  276. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  277. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  278. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  279. memset(&dataSetreaderConfig, 0, sizeof(dataSetreaderConfig));
  280. dataSetreaderConfig.name = UA_STRING("DataSetReader Test ");
  281. retVal |= UA_Server_addDataSetReader(server, localreaderGroup, NULL, NULL);
  282. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  283. /* Remove the added DataSetReader */
  284. retVal |= UA_Server_removeDataSetReader(server, UA_NODEID_NUMERIC(0, UA_UINT32_MAX));
  285. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  286. } END_TEST
  287. START_TEST(AddMultipleDataSetReaderWithValidConfiguration) {
  288. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  289. UA_ReaderGroupConfig readerGroupConfig;
  290. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  291. readerGroupConfig.name = UA_STRING("ReaderGroup 1");
  292. UA_NodeId localReaderGroup;
  293. UA_NodeId localReaderGroup2;
  294. /* DataSetReader configuration */
  295. UA_DataSetReaderConfig readerConfig;
  296. memset (&readerConfig, 0, sizeof(readerConfig));
  297. readerConfig.name = UA_STRING("DataSet Reader 1");
  298. UA_NodeId dataSetReader;
  299. /* Add ReaderGroup */
  300. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localReaderGroup);
  301. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  302. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localReaderGroup2);
  303. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  304. UA_ReaderGroup *readerGroupIdent1 = UA_ReaderGroup_findRGbyId(server, localReaderGroup);
  305. UA_ReaderGroup *readerGroupIdent2 = UA_ReaderGroup_findRGbyId(server, localReaderGroup2);
  306. /* Add DataSetReaders to first ReaderGroup */
  307. retVal = UA_Server_addDataSetReader(server, localReaderGroup, &readerConfig, &dataSetReader);
  308. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  309. ck_assert_int_eq(readerGroupIdent1->readersCount, 1);
  310. retVal = UA_Server_addDataSetReader(server, localReaderGroup, &readerConfig, &dataSetReader);
  311. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  312. ck_assert_int_eq(readerGroupIdent1->readersCount, 2);
  313. /* Add DataSetReaders to second ReaderGroup */
  314. retVal = UA_Server_addDataSetReader(server, localReaderGroup2, &readerConfig, &dataSetReader);
  315. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  316. ck_assert_int_eq(readerGroupIdent2->readersCount, 1);
  317. retVal = UA_Server_addDataSetReader(server, localReaderGroup2, &readerConfig, &dataSetReader);
  318. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  319. ck_assert_int_eq(readerGroupIdent2->readersCount, 2);
  320. } END_TEST
  321. START_TEST(UpdateDataSetReaderConfigWithInvalidId) {
  322. /* Check status of updatting DataSetReader with invalid configuration */
  323. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  324. UA_DataSetReaderConfig dataSetreaderConfig;
  325. UA_NodeId localreaderGroup;
  326. UA_NodeId localDataSetreader;
  327. UA_ReaderGroupConfig readerGroupConfig;
  328. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  329. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  330. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  331. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  332. memset(&dataSetreaderConfig, 0, sizeof(dataSetreaderConfig));
  333. retVal |= UA_Server_addDataSetReader(server, localreaderGroup,
  334. &dataSetreaderConfig, &localDataSetreader);
  335. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  336. retVal |= UA_Server_DataSetReader_updateConfig(server, UA_NODEID_NUMERIC(0, UA_UINT32_MAX),
  337. localreaderGroup, &dataSetreaderConfig );
  338. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  339. } END_TEST
  340. START_TEST(GetDataSetReaderConfigWithValidConfiguration) {
  341. /* Check status of getting DataSetReader with Valid configuration */
  342. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  343. UA_DataSetReaderConfig dataSetreaderConfig;
  344. UA_NodeId localreaderGroup;
  345. UA_NodeId localDataSetreader;
  346. UA_ReaderGroupConfig readerGroupConfig;
  347. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  348. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  349. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  350. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  351. memset(&dataSetreaderConfig, 0, sizeof(dataSetreaderConfig));
  352. retVal |= UA_Server_addDataSetReader(server, localreaderGroup, &dataSetreaderConfig, &localDataSetreader);
  353. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  354. retVal |= UA_Server_DataSetReader_getConfig(server, localDataSetreader, &dataSetreaderConfig);
  355. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  356. } END_TEST
  357. START_TEST(GetDataSetReaderConfigWithInvalidConfiguration) {
  358. /* Check status of getting DataSetReader with Invalid configuration */
  359. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  360. UA_DataSetReaderConfig dataSetreaderConfig;
  361. UA_NodeId localreaderGroup;
  362. UA_NodeId localDataSetreader;
  363. UA_ReaderGroupConfig readerGroupConfig;
  364. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  365. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  366. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  367. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  368. memset(&dataSetreaderConfig, 0, sizeof(dataSetreaderConfig));
  369. retVal |= UA_Server_addDataSetReader(server, localreaderGroup, &dataSetreaderConfig, &localDataSetreader);
  370. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  371. retVal |= UA_Server_DataSetReader_getConfig(server, localDataSetreader, NULL);
  372. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  373. } END_TEST
  374. START_TEST(GetDataSetReaderConfigWithInvalidIdentifier) {
  375. /* Check status of getting DataSetReader with Invalid Identifier */
  376. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  377. UA_DataSetReaderConfig dataSetreaderConfig;
  378. UA_NodeId localreaderGroup;
  379. UA_NodeId localDataSetreader;
  380. UA_ReaderGroupConfig readerGroupConfig;
  381. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  382. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  383. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  384. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  385. memset(&dataSetreaderConfig, 0, sizeof(dataSetreaderConfig));
  386. retVal |= UA_Server_addDataSetReader(server, localreaderGroup, &dataSetreaderConfig, &localDataSetreader);
  387. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  388. retVal |= UA_Server_DataSetReader_getConfig(server, UA_NODEID_NUMERIC(0, UA_UINT32_MAX), &dataSetreaderConfig);
  389. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  390. } END_TEST
  391. START_TEST(CreateTargetVariableWithInvalidConfiguration) {
  392. /* Check status to create target variable with invalid configuration */
  393. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  394. UA_DataSetReaderConfig dataSetreaderConfig;
  395. UA_NodeId localreaderGroup;
  396. UA_NodeId localDataSetreader;
  397. UA_TargetVariablesDataType localTargetVariable;
  398. UA_ReaderGroupConfig readerGroupConfig;
  399. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  400. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  401. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  402. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  403. memset(&dataSetreaderConfig, 0, sizeof(dataSetreaderConfig));
  404. retVal |= UA_Server_addDataSetReader(server, localreaderGroup, &dataSetreaderConfig, &localDataSetreader);
  405. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  406. retVal |= UA_Server_DataSetReader_createTargetVariables(server, UA_NODEID_NUMERIC(0, UA_UINT32_MAX), &localTargetVariable);
  407. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  408. } END_TEST
  409. START_TEST(AddTargetVariableWithInvalidConfiguration) {
  410. /* Check status to create target variable with invalid configuration */
  411. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  412. UA_DataSetReaderConfig dataSetreaderConfig;
  413. UA_NodeId localreaderGroup;
  414. UA_NodeId localDataSetreader;
  415. UA_ReaderGroupConfig readerGroupConfig;
  416. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  417. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  418. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  419. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  420. memset(&dataSetreaderConfig, 0, sizeof(dataSetreaderConfig));
  421. retVal |= UA_Server_addDataSetReader(server, localreaderGroup, &dataSetreaderConfig, &localDataSetreader);
  422. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  423. retVal |= UA_Server_DataSetReader_addTargetVariables(NULL, &localreaderGroup, localDataSetreader, UA_PUBSUB_SDS_TARGET);
  424. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  425. } END_TEST
  426. START_TEST(AddTargetVariableWithValidConfiguration) {
  427. /* Check status after creating target variables with Valid configuration */
  428. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  429. UA_DataSetReaderConfig dataSetReaderConfig;
  430. UA_NodeId folderId;
  431. UA_QualifiedName folderBrowseName;
  432. UA_NodeId localreaderGroupIdentifier;
  433. UA_NodeId localDataSetreaderIdentifier;
  434. UA_ObjectAttributes oAttr = UA_ObjectAttributes_default;
  435. UA_ReaderGroupConfig readerGroupConfig;
  436. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  437. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  438. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroupIdentifier);
  439. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  440. memset(&dataSetReaderConfig, 0, sizeof(UA_DataSetReaderConfig));
  441. UA_DataSetMetaDataType *pMetaData = &dataSetReaderConfig.dataSetMetaData;
  442. UA_DataSetMetaDataType_init (pMetaData);
  443. pMetaData->name = UA_STRING ("DataSet Test");
  444. /* Static definition of number of fields size to 2 to create targetVariables
  445. * with DateTime and ByteString datatype */
  446. pMetaData->fieldsSize = 2;
  447. pMetaData->fields = (UA_FieldMetaData*)UA_Array_new (pMetaData->fieldsSize,
  448. &UA_TYPES[UA_TYPES_FIELDMETADATA]);
  449. /* DateTime DataType */
  450. UA_FieldMetaData_init (&pMetaData->fields[0]);
  451. UA_NodeId_copy (&UA_TYPES[UA_TYPES_DATETIME].typeId,
  452. &pMetaData->fields[0].dataType);
  453. pMetaData->fields[0].builtInType = UA_NS0ID_DATETIME;
  454. pMetaData->fields[0].valueRank = -1; /* scalar */
  455. /* ByteString DataType */
  456. UA_FieldMetaData_init (&pMetaData->fields[1]);
  457. UA_NodeId_copy (&UA_TYPES[UA_TYPES_BYTESTRING].typeId,
  458. &pMetaData->fields[1].dataType);
  459. pMetaData->fields[1].builtInType = UA_NS0ID_BYTESTRING;
  460. pMetaData->fields[1].valueRank = -1; /* scalar */
  461. retVal |= UA_Server_addDataSetReader(server, localreaderGroupIdentifier, &dataSetReaderConfig, &localDataSetreaderIdentifier);
  462. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  463. folderBrowseName = UA_QUALIFIEDNAME (1, "Subscribed Variables");
  464. UA_Server_addObjectNode (server, UA_NODEID_NULL,
  465. UA_NODEID_NUMERIC (0, UA_NS0ID_OBJECTSFOLDER),
  466. UA_NODEID_NUMERIC (0, UA_NS0ID_ORGANIZES),
  467. folderBrowseName, UA_NODEID_NUMERIC (0,
  468. UA_NS0ID_BASEOBJECTTYPE), oAttr, NULL, &folderId);
  469. retVal |= UA_Server_DataSetReader_addTargetVariables(server, &folderId, localDataSetreaderIdentifier, UA_PUBSUB_SDS_TARGET);
  470. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  471. UA_free(pMetaData->fields);
  472. } END_TEST
  473. START_TEST(SinglePublishSubscribeDateTime) {
  474. /* To check status after running both publisher and subscriber */
  475. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  476. UA_PublishedDataSetConfig pdsConfig;
  477. UA_NodeId dataSetWriter;
  478. UA_NodeId readerIdentifier;
  479. UA_NodeId writerGroup;
  480. UA_DataSetReaderConfig readerConfig;
  481. memset(&pdsConfig, 0, sizeof(UA_PublishedDataSetConfig));
  482. pdsConfig.publishedDataSetType = UA_PUBSUB_DATASET_PUBLISHEDITEMS;
  483. pdsConfig.name = UA_STRING("PublishedDataSet Test");
  484. UA_Server_addPublishedDataSet(server, &pdsConfig, &publishedDataSetTest);
  485. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  486. /* Data Set Field */
  487. UA_NodeId dataSetFieldId;
  488. UA_DataSetFieldConfig dataSetFieldConfig;
  489. memset(&dataSetFieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  490. dataSetFieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  491. dataSetFieldConfig.field.variable.fieldNameAlias = UA_STRING("Server localtime");
  492. dataSetFieldConfig.field.variable.promotedField = UA_FALSE;
  493. dataSetFieldConfig.field.variable.publishParameters.publishedVariable = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_LOCALTIME);
  494. dataSetFieldConfig.field.variable.publishParameters.attributeId = UA_ATTRIBUTEID_VALUE;
  495. UA_Server_addDataSetField(server, publishedDataSetTest, &dataSetFieldConfig, &dataSetFieldId);
  496. /* Writer group */
  497. UA_WriterGroupConfig writerGroupConfig;
  498. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  499. writerGroupConfig.name = UA_STRING("WriterGroup Test");
  500. writerGroupConfig.publishingInterval = PUBLISH_INTERVAL;
  501. writerGroupConfig.enabled = UA_FALSE;
  502. writerGroupConfig.writerGroupId = WRITER_GROUP_ID;
  503. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  504. retVal |= UA_Server_addWriterGroup(server, connection_test, &writerGroupConfig, &writerGroup);
  505. UA_Server_setWriterGroupOperational(server, writerGroup);
  506. /* DataSetWriter */
  507. UA_DataSetWriterConfig dataSetWriterConfig;
  508. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  509. dataSetWriterConfig.name = UA_STRING("DataSetWriter Test");
  510. dataSetWriterConfig.dataSetWriterId = DATASET_WRITER_ID;
  511. dataSetWriterConfig.keyFrameCount = 10;
  512. retVal |= UA_Server_addDataSetWriter(server, writerGroup, publishedDataSetTest, &dataSetWriterConfig, &dataSetWriter);
  513. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  514. /* Reader Group */
  515. UA_ReaderGroupConfig readerGroupConfig;
  516. memset (&readerGroupConfig, 0, sizeof (UA_ReaderGroupConfig));
  517. readerGroupConfig.name = UA_STRING ("ReaderGroup Test");
  518. retVal |= UA_Server_addReaderGroup (server, connection_test, &readerGroupConfig,
  519. &readerGroupTest);
  520. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  521. /* Data Set Reader */
  522. memset (&readerConfig, 0, sizeof (UA_DataSetReaderConfig));
  523. readerConfig.name = UA_STRING ("DataSetReader Test");
  524. readerConfig.dataSetWriterId = DATASET_WRITER_ID;
  525. /* Setting up Meta data configuration in DataSetReader for DateTime DataType */
  526. UA_DataSetMetaDataType *pMetaData = &readerConfig.dataSetMetaData;
  527. /* FilltestMetadata function in subscriber implementation */
  528. UA_DataSetMetaDataType_init (pMetaData);
  529. pMetaData->name = UA_STRING ("DataSet Test");
  530. /* Static definition of number of fields size to 1 to create one
  531. targetVariable */
  532. pMetaData->fieldsSize = 1;
  533. pMetaData->fields = (UA_FieldMetaData*)UA_Array_new (pMetaData->fieldsSize,
  534. &UA_TYPES[UA_TYPES_FIELDMETADATA]);
  535. /* DateTime DataType */
  536. UA_FieldMetaData_init (&pMetaData->fields[0]);
  537. UA_NodeId_copy (&UA_TYPES[UA_TYPES_DATETIME].typeId,
  538. &pMetaData->fields[0].dataType);
  539. pMetaData->fields[0].builtInType = UA_NS0ID_DATETIME;
  540. pMetaData->fields[0].valueRank = -1; /* scalar */
  541. retVal |= UA_Server_addDataSetReader (server, readerGroupTest, &readerConfig,
  542. &readerIdentifier);
  543. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  544. /* Add Subscribed Variables */
  545. UA_NodeId folderId;
  546. UA_String folderName = readerConfig.dataSetMetaData.name;
  547. UA_ObjectAttributes oAttr = UA_ObjectAttributes_default;
  548. UA_QualifiedName folderBrowseName;
  549. if (folderName.length > 0) {
  550. oAttr.displayName.locale = UA_STRING ("en-US");
  551. oAttr.displayName.text = folderName;
  552. folderBrowseName.namespaceIndex = 1;
  553. folderBrowseName.name = folderName;
  554. }
  555. else {
  556. oAttr.displayName = UA_LOCALIZEDTEXT ("en-US", "Subscribed Variables");
  557. folderBrowseName = UA_QUALIFIEDNAME (1, "Subscribed Variables");
  558. }
  559. UA_Server_addObjectNode (server, UA_NODEID_NULL,
  560. UA_NODEID_NUMERIC (0, UA_NS0ID_OBJECTSFOLDER),
  561. UA_NODEID_NUMERIC (0, UA_NS0ID_ORGANIZES),
  562. folderBrowseName, UA_NODEID_NUMERIC (0,
  563. UA_NS0ID_BASEOBJECTTYPE), oAttr, NULL, &folderId);
  564. retVal |= UA_Server_DataSetReader_addTargetVariables (server, &folderId,
  565. readerIdentifier, UA_PUBSUB_SDS_TARGET);
  566. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  567. /* run server - publisher and subscriber */
  568. UA_Server_run_iterate(server,true);
  569. UA_Server_run_iterate(server,true);
  570. UA_free(pMetaData->fields);
  571. }END_TEST
  572. START_TEST(SinglePublishSubscribeInt32) {
  573. /* To check status after running both publisher and subscriber */
  574. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  575. UA_PublishedDataSetConfig pdsConfig;
  576. UA_NodeId dataSetWriter;
  577. UA_NodeId readerIdentifier;
  578. UA_NodeId writerGroup;
  579. UA_DataSetReaderConfig readerConfig;
  580. /* Published DataSet */
  581. memset(&pdsConfig, 0, sizeof(UA_PublishedDataSetConfig));
  582. pdsConfig.publishedDataSetType = UA_PUBSUB_DATASET_PUBLISHEDITEMS;
  583. pdsConfig.name = UA_STRING("PublishedDataSet Test");
  584. UA_Server_addPublishedDataSet(server, &pdsConfig, &publishedDataSetTest);
  585. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  586. /* Create variable to publish integer data */
  587. UA_NodeId publisherNode;
  588. UA_VariableAttributes attr = UA_VariableAttributes_default;
  589. attr.description = UA_LOCALIZEDTEXT("en-US","Published Int32");
  590. attr.displayName = UA_LOCALIZEDTEXT("en-US","Published Int32");
  591. attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  592. UA_Int32 publisherData = 42;
  593. UA_Variant_setScalar(&attr.value, &publisherData, &UA_TYPES[UA_TYPES_INT32]);
  594. retVal = UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, PUBLISHVARIABLE_NODEID),
  595. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  596. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  597. UA_QUALIFIEDNAME(1, "Published Int32"),
  598. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE),
  599. attr, NULL, &publisherNode);
  600. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  601. /* Data Set Field */
  602. UA_NodeId dataSetFieldIdent;
  603. UA_DataSetFieldConfig dataSetFieldConfig;
  604. memset(&dataSetFieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  605. dataSetFieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  606. dataSetFieldConfig.field.variable.fieldNameAlias = UA_STRING("Published Int32");
  607. dataSetFieldConfig.field.variable.promotedField = UA_FALSE;
  608. dataSetFieldConfig.field.variable.publishParameters.publishedVariable = publisherNode;
  609. dataSetFieldConfig.field.variable.publishParameters.attributeId = UA_ATTRIBUTEID_VALUE;
  610. UA_Server_addDataSetField (server, publishedDataSetTest, &dataSetFieldConfig, &dataSetFieldIdent);
  611. /* Writer group */
  612. UA_WriterGroupConfig writerGroupConfig;
  613. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  614. writerGroupConfig.name = UA_STRING("WriterGroup Test");
  615. writerGroupConfig.publishingInterval = PUBLISH_INTERVAL;
  616. writerGroupConfig.enabled = UA_FALSE;
  617. writerGroupConfig.writerGroupId = WRITER_GROUP_ID;
  618. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  619. /* Message settings in WriterGroup to include necessary headers */
  620. writerGroupConfig.messageSettings.encoding = UA_EXTENSIONOBJECT_DECODED;
  621. writerGroupConfig.messageSettings.content.decoded.type = &UA_TYPES[UA_TYPES_UADPWRITERGROUPMESSAGEDATATYPE];
  622. UA_UadpWriterGroupMessageDataType *writerGroupMessage = UA_UadpWriterGroupMessageDataType_new();
  623. writerGroupMessage->networkMessageContentMask = (UA_UadpNetworkMessageContentMask)(UA_UADPNETWORKMESSAGECONTENTMASK_PUBLISHERID |
  624. (UA_UadpNetworkMessageContentMask)UA_UADPNETWORKMESSAGECONTENTMASK_GROUPHEADER |
  625. (UA_UadpNetworkMessageContentMask)UA_UADPNETWORKMESSAGECONTENTMASK_WRITERGROUPID |
  626. (UA_UadpNetworkMessageContentMask)UA_UADPNETWORKMESSAGECONTENTMASK_PAYLOADHEADER);
  627. writerGroupConfig.messageSettings.content.decoded.data = writerGroupMessage;
  628. retVal |= UA_Server_addWriterGroup(server, connection_test, &writerGroupConfig, &writerGroup);
  629. UA_Server_setWriterGroupOperational(server, writerGroup);
  630. UA_UadpWriterGroupMessageDataType_delete(writerGroupMessage);
  631. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  632. /* DataSetWriter */
  633. UA_DataSetWriterConfig dataSetWriterConfig;
  634. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  635. dataSetWriterConfig.name = UA_STRING("DataSetWriter Test");
  636. dataSetWriterConfig.dataSetWriterId = DATASET_WRITER_ID;
  637. dataSetWriterConfig.keyFrameCount = 10;
  638. retVal |= UA_Server_addDataSetWriter(server, writerGroup, publishedDataSetTest, &dataSetWriterConfig, &dataSetWriter);
  639. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  640. /* Reader Group */
  641. UA_ReaderGroupConfig readerGroupConfig;
  642. memset (&readerGroupConfig, 0, sizeof (UA_ReaderGroupConfig));
  643. readerGroupConfig.name = UA_STRING ("ReaderGroup Test");
  644. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &readerGroupTest);
  645. /* Data Set Reader */
  646. /* Parameters to filter received NetworkMessage */
  647. memset (&readerConfig, 0, sizeof (UA_DataSetReaderConfig));
  648. readerConfig.name = UA_STRING ("DataSetReader Test");
  649. UA_UInt16 publisherIdentifier = PUBLISHER_ID;
  650. readerConfig.publisherId.type = &UA_TYPES[UA_TYPES_UINT16];
  651. readerConfig.publisherId.data = &publisherIdentifier;
  652. readerConfig.writerGroupId = WRITER_GROUP_ID;
  653. readerConfig.dataSetWriterId = DATASET_WRITER_ID;
  654. /* Setting up Meta data configuration in DataSetReader */
  655. UA_DataSetMetaDataType *pMetaData = &readerConfig.dataSetMetaData;
  656. /* FilltestMetadata function in subscriber implementation */
  657. UA_DataSetMetaDataType_init (pMetaData);
  658. pMetaData->name = UA_STRING ("DataSet Test");
  659. /* Static definition of number of fields size to 1 to create one
  660. targetVariable */
  661. pMetaData->fieldsSize = 1;
  662. pMetaData->fields = (UA_FieldMetaData*)UA_Array_new (pMetaData->fieldsSize,
  663. &UA_TYPES[UA_TYPES_FIELDMETADATA]);
  664. /* Unsigned Integer DataType */
  665. UA_FieldMetaData_init (&pMetaData->fields[0]);
  666. UA_NodeId_copy (&UA_TYPES[UA_TYPES_INT32].typeId,
  667. &pMetaData->fields[0].dataType);
  668. pMetaData->fields[0].builtInType = UA_NS0ID_INT32;
  669. pMetaData->fields[0].valueRank = -1; /* scalar */
  670. retVal |= UA_Server_addDataSetReader(server, readerGroupTest, &readerConfig,
  671. &readerIdentifier);
  672. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  673. /* Add Subscribed Variables */
  674. UA_NodeId folderId;
  675. UA_NodeId newnodeId;
  676. UA_String folderName = readerConfig.dataSetMetaData.name;
  677. UA_ObjectAttributes oAttr = UA_ObjectAttributes_default;
  678. UA_QualifiedName folderBrowseName;
  679. if (folderName.length > 0) {
  680. oAttr.displayName.locale = UA_STRING ("en-US");
  681. oAttr.displayName.text = folderName;
  682. folderBrowseName.namespaceIndex = 1;
  683. folderBrowseName.name = folderName;
  684. }
  685. else {
  686. oAttr.displayName = UA_LOCALIZEDTEXT ("en-US", "Subscribed Variables");
  687. folderBrowseName = UA_QUALIFIEDNAME (1, "Subscribed Variables");
  688. }
  689. retVal = UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, SUBSCRIBEOBJECT_NODEID),
  690. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  691. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  692. folderBrowseName, UA_NODEID_NUMERIC(0,
  693. UA_NS0ID_BASEOBJECTTYPE), oAttr, NULL, &folderId);
  694. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  695. /* Variable to subscribe data */
  696. UA_VariableAttributes vAttr = UA_VariableAttributes_default;
  697. vAttr.description = UA_LOCALIZEDTEXT ("en-US", "Subscribed Int32");
  698. vAttr.displayName = UA_LOCALIZEDTEXT ("en-US", "Subscribed Int32");
  699. vAttr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  700. retVal = UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, SUBSCRIBEVARIABLE_NODEID),
  701. UA_NODEID_NUMERIC(1, SUBSCRIBEOBJECT_NODEID),
  702. UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT), UA_QUALIFIEDNAME(1, "Subscribed Int32"),
  703. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE), vAttr, NULL, &newnodeId);
  704. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  705. UA_TargetVariablesDataType targetVars;
  706. targetVars.targetVariablesSize = 1;
  707. targetVars.targetVariables = (UA_FieldTargetDataType *)
  708. UA_calloc(targetVars.targetVariablesSize,
  709. sizeof(UA_FieldTargetDataType));
  710. /* For creating Targetvariable */
  711. UA_FieldTargetDataType_init(&targetVars.targetVariables[0]);
  712. targetVars.targetVariables[0].attributeId = UA_ATTRIBUTEID_VALUE;
  713. targetVars.targetVariables[0].targetNodeId = newnodeId;
  714. retVal |= UA_Server_DataSetReader_createTargetVariables(server, readerIdentifier,
  715. &targetVars);
  716. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  717. UA_TargetVariablesDataType_deleteMembers(&targetVars);
  718. UA_free(pMetaData->fields);
  719. /* run server - publisher and subscriber */
  720. UA_Server_run_iterate(server,true);
  721. /* Read data sent by the Publisher */
  722. UA_Variant *publishedNodeData = UA_Variant_new();
  723. retVal = UA_Server_readValue(server, UA_NODEID_NUMERIC(1, PUBLISHVARIABLE_NODEID), publishedNodeData);
  724. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  725. /* Read data received by the Subscriber */
  726. UA_Variant *subscribedNodeData = UA_Variant_new();
  727. retVal = UA_Server_readValue(server, UA_NODEID_NUMERIC(1, SUBSCRIBEVARIABLE_NODEID), subscribedNodeData);
  728. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  729. /* Check if data sent from Publisher is being received by Subscriber */
  730. ck_assert_int_eq(*(UA_Int32 *)publishedNodeData->data, *(UA_Int32 *)subscribedNodeData->data);
  731. UA_Variant_delete(subscribedNodeData);
  732. UA_Variant_delete(publishedNodeData);
  733. } END_TEST
  734. START_TEST(SinglePublishSubscribeInt64) {
  735. /* To check status after running both publisher and subscriber */
  736. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  737. UA_PublishedDataSetConfig pdsConfig;
  738. UA_NodeId dataSetWriter;
  739. UA_NodeId readerIdentifier;
  740. UA_NodeId writerGroup;
  741. UA_DataSetReaderConfig readerConfig;
  742. /* Published DataSet */
  743. memset(&pdsConfig, 0, sizeof(UA_PublishedDataSetConfig));
  744. pdsConfig.publishedDataSetType = UA_PUBSUB_DATASET_PUBLISHEDITEMS;
  745. pdsConfig.name = UA_STRING("PublishedDataSet Test");
  746. UA_Server_addPublishedDataSet(server, &pdsConfig, &publishedDataSetTest);
  747. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  748. /* Create variable to publish integer data */
  749. UA_NodeId publisherNode;
  750. UA_VariableAttributes attr = UA_VariableAttributes_default;
  751. attr.description = UA_LOCALIZEDTEXT("en-US","Published Int64");
  752. attr.displayName = UA_LOCALIZEDTEXT("en-US","Published Int64");
  753. attr.dataType = UA_TYPES[UA_TYPES_INT64].typeId;
  754. UA_Int64 publisherData = 64;
  755. UA_Variant_setScalar(&attr.value, &publisherData, &UA_TYPES[UA_TYPES_INT64]);
  756. retVal = UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, PUBLISHVARIABLE_NODEID),
  757. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  758. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  759. UA_QUALIFIEDNAME(1, "Published Int64"),
  760. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE),
  761. attr, NULL, &publisherNode);
  762. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  763. /* Data Set Field */
  764. UA_NodeId dataSetFieldIdent;
  765. UA_DataSetFieldConfig dataSetFieldConfig;
  766. memset(&dataSetFieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  767. dataSetFieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  768. dataSetFieldConfig.field.variable.fieldNameAlias = UA_STRING("Published Int64");
  769. dataSetFieldConfig.field.variable.promotedField = UA_FALSE;
  770. dataSetFieldConfig.field.variable.publishParameters.publishedVariable = publisherNode;
  771. dataSetFieldConfig.field.variable.publishParameters.attributeId = UA_ATTRIBUTEID_VALUE;
  772. UA_Server_addDataSetField (server, publishedDataSetTest, &dataSetFieldConfig, &dataSetFieldIdent);
  773. /* Writer group */
  774. UA_WriterGroupConfig writerGroupConfig;
  775. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  776. writerGroupConfig.name = UA_STRING("WriterGroup Test");
  777. writerGroupConfig.publishingInterval = PUBLISH_INTERVAL;
  778. writerGroupConfig.enabled = UA_FALSE;
  779. writerGroupConfig.writerGroupId = WRITER_GROUP_ID;
  780. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  781. /* Message settings in WriterGroup to include necessary headers */
  782. writerGroupConfig.messageSettings.encoding = UA_EXTENSIONOBJECT_DECODED;
  783. writerGroupConfig.messageSettings.content.decoded.type = &UA_TYPES[UA_TYPES_UADPWRITERGROUPMESSAGEDATATYPE];
  784. UA_UadpWriterGroupMessageDataType *writerGroupMessage = UA_UadpWriterGroupMessageDataType_new();
  785. writerGroupMessage->networkMessageContentMask = (UA_UadpNetworkMessageContentMask)(UA_UADPNETWORKMESSAGECONTENTMASK_PUBLISHERID |
  786. (UA_UadpNetworkMessageContentMask)UA_UADPNETWORKMESSAGECONTENTMASK_GROUPHEADER |
  787. (UA_UadpNetworkMessageContentMask)UA_UADPNETWORKMESSAGECONTENTMASK_WRITERGROUPID |
  788. (UA_UadpNetworkMessageContentMask)UA_UADPNETWORKMESSAGECONTENTMASK_PAYLOADHEADER);
  789. writerGroupConfig.messageSettings.content.decoded.data = writerGroupMessage;
  790. retVal |= UA_Server_addWriterGroup(server, connection_test, &writerGroupConfig, &writerGroup);
  791. UA_Server_setWriterGroupOperational(server, writerGroup);
  792. UA_UadpWriterGroupMessageDataType_delete(writerGroupMessage);
  793. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  794. /* DataSetWriter */
  795. UA_DataSetWriterConfig dataSetWriterConfig;
  796. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  797. dataSetWriterConfig.name = UA_STRING("DataSetWriter Test");
  798. dataSetWriterConfig.dataSetWriterId = DATASET_WRITER_ID;
  799. dataSetWriterConfig.keyFrameCount = 10;
  800. retVal |= UA_Server_addDataSetWriter(server, writerGroup, publishedDataSetTest, &dataSetWriterConfig, &dataSetWriter);
  801. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  802. /* Reader Group */
  803. UA_ReaderGroupConfig readerGroupConfig;
  804. memset (&readerGroupConfig, 0, sizeof (UA_ReaderGroupConfig));
  805. readerGroupConfig.name = UA_STRING ("ReaderGroup Test");
  806. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &readerGroupTest);
  807. /* Data Set Reader */
  808. /* Parameters to filter received NetworkMessage */
  809. memset (&readerConfig, 0, sizeof (UA_DataSetReaderConfig));
  810. readerConfig.name = UA_STRING ("DataSetReader Test");
  811. UA_UInt16 publisherIdentifier = PUBLISHER_ID;
  812. readerConfig.publisherId.type = &UA_TYPES[UA_TYPES_UINT16];
  813. readerConfig.publisherId.data = &publisherIdentifier;
  814. readerConfig.writerGroupId = WRITER_GROUP_ID;
  815. readerConfig.dataSetWriterId = DATASET_WRITER_ID;
  816. /* Setting up Meta data configuration in DataSetReader */
  817. UA_DataSetMetaDataType *pMetaData = &readerConfig.dataSetMetaData;
  818. /* FilltestMetadata function in subscriber implementation */
  819. UA_DataSetMetaDataType_init (pMetaData);
  820. pMetaData->name = UA_STRING ("DataSet Test");
  821. /* Static definition of number of fields size to 1 to create one
  822. targetVariable */
  823. pMetaData->fieldsSize = 1;
  824. pMetaData->fields = (UA_FieldMetaData*)UA_Array_new (pMetaData->fieldsSize,
  825. &UA_TYPES[UA_TYPES_FIELDMETADATA]);
  826. /* Unsigned Integer DataType */
  827. UA_FieldMetaData_init (&pMetaData->fields[0]);
  828. UA_NodeId_copy (&UA_TYPES[UA_TYPES_INT64].typeId,
  829. &pMetaData->fields[0].dataType);
  830. pMetaData->fields[0].builtInType = UA_NS0ID_INT64;
  831. pMetaData->fields[0].valueRank = -1; /* scalar */
  832. retVal |= UA_Server_addDataSetReader(server, readerGroupTest, &readerConfig,
  833. &readerIdentifier);
  834. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  835. /* Add Subscribed Variables */
  836. UA_NodeId folderId;
  837. UA_NodeId newnodeId;
  838. UA_String folderName = readerConfig.dataSetMetaData.name;
  839. UA_ObjectAttributes oAttr = UA_ObjectAttributes_default;
  840. UA_QualifiedName folderBrowseName;
  841. if (folderName.length > 0) {
  842. oAttr.displayName.locale = UA_STRING ("en-US");
  843. oAttr.displayName.text = folderName;
  844. folderBrowseName.namespaceIndex = 1;
  845. folderBrowseName.name = folderName;
  846. }
  847. else {
  848. oAttr.displayName = UA_LOCALIZEDTEXT ("en-US", "Subscribed Variables");
  849. folderBrowseName = UA_QUALIFIEDNAME (1, "Subscribed Variables");
  850. }
  851. retVal = UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, SUBSCRIBEOBJECT_NODEID),
  852. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  853. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  854. folderBrowseName, UA_NODEID_NUMERIC(0,
  855. UA_NS0ID_BASEOBJECTTYPE), oAttr, NULL, &folderId);
  856. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  857. /* Variable to subscribe data */
  858. UA_VariableAttributes vAttr = UA_VariableAttributes_default;
  859. vAttr.description = UA_LOCALIZEDTEXT ("en-US", "Subscribed Int64");
  860. vAttr.displayName = UA_LOCALIZEDTEXT ("en-US", "Subscribed Int64");
  861. vAttr.dataType = UA_TYPES[UA_TYPES_INT64].typeId;
  862. retVal = UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, SUBSCRIBEVARIABLE_NODEID),
  863. UA_NODEID_NUMERIC(1, SUBSCRIBEOBJECT_NODEID),
  864. UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT), UA_QUALIFIEDNAME(1, "Subscribed Int64"),
  865. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE), vAttr, NULL, &newnodeId);
  866. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  867. UA_TargetVariablesDataType targetVars;
  868. targetVars.targetVariablesSize = 1;
  869. targetVars.targetVariables = (UA_FieldTargetDataType *)
  870. UA_calloc(targetVars.targetVariablesSize,
  871. sizeof(UA_FieldTargetDataType));
  872. /* For creating Targetvariable */
  873. UA_FieldTargetDataType_init(&targetVars.targetVariables[0]);
  874. targetVars.targetVariables[0].attributeId = UA_ATTRIBUTEID_VALUE;
  875. targetVars.targetVariables[0].targetNodeId = newnodeId;
  876. retVal |= UA_Server_DataSetReader_createTargetVariables(server, readerIdentifier,
  877. &targetVars);
  878. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  879. UA_TargetVariablesDataType_deleteMembers(&targetVars);
  880. UA_free(pMetaData->fields);
  881. /* run server - publisher and subscriber */
  882. UA_Server_run_iterate(server,true);
  883. /* Read data sent by the Publisher */
  884. UA_Variant *publishedNodeData = UA_Variant_new();
  885. retVal = UA_Server_readValue(server, UA_NODEID_NUMERIC(1, PUBLISHVARIABLE_NODEID), publishedNodeData);
  886. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  887. /* Read data received by the Subscriber */
  888. UA_Variant *subscribedNodeData = UA_Variant_new();
  889. retVal = UA_Server_readValue(server, UA_NODEID_NUMERIC(1, SUBSCRIBEVARIABLE_NODEID), subscribedNodeData);
  890. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  891. /* Check if data sent from Publisher is being received by Subscriber */
  892. ck_assert_int_eq(*(UA_Int64 *)publishedNodeData->data, *(UA_Int64 *)subscribedNodeData->data);
  893. UA_Variant_delete(subscribedNodeData);
  894. UA_Variant_delete(publishedNodeData);
  895. } END_TEST
  896. START_TEST(SinglePublishSubscribeBool) {
  897. /* To check status after running both publisher and subscriber */
  898. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  899. UA_PublishedDataSetConfig pdsConfig;
  900. UA_NodeId dataSetWriter;
  901. UA_NodeId readerIdentifier;
  902. UA_NodeId writerGroup;
  903. UA_DataSetReaderConfig readerConfig;
  904. /* Published DataSet */
  905. memset(&pdsConfig, 0, sizeof(UA_PublishedDataSetConfig));
  906. pdsConfig.publishedDataSetType = UA_PUBSUB_DATASET_PUBLISHEDITEMS;
  907. pdsConfig.name = UA_STRING("PublishedDataSet Test");
  908. UA_Server_addPublishedDataSet(server, &pdsConfig, &publishedDataSetTest);
  909. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  910. /* Create variable to publish boolean data */
  911. UA_NodeId publisherNode;
  912. UA_VariableAttributes attr = UA_VariableAttributes_default;
  913. attr.description = UA_LOCALIZEDTEXT("en-US","Published Bool");
  914. attr.displayName = UA_LOCALIZEDTEXT("en-US","Published Bool");
  915. attr.dataType = UA_TYPES[UA_TYPES_BOOLEAN].typeId;
  916. UA_Boolean publisherData = UA_FALSE;
  917. UA_Variant_setScalar(&attr.value, &publisherData, &UA_TYPES[UA_TYPES_BOOLEAN]);
  918. retVal = UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, PUBLISHVARIABLE_NODEID),
  919. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  920. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  921. UA_QUALIFIEDNAME(1, "Published Bool"),
  922. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE),
  923. attr, NULL, &publisherNode);
  924. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  925. /* Data Set Field */
  926. UA_NodeId dataSetFieldIdent;
  927. UA_DataSetFieldConfig dataSetFieldConfig;
  928. memset(&dataSetFieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  929. dataSetFieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  930. dataSetFieldConfig.field.variable.fieldNameAlias = UA_STRING("Published Bool");
  931. dataSetFieldConfig.field.variable.promotedField = UA_FALSE;
  932. dataSetFieldConfig.field.variable.publishParameters.publishedVariable = publisherNode;
  933. dataSetFieldConfig.field.variable.publishParameters.attributeId = UA_ATTRIBUTEID_VALUE;
  934. UA_Server_addDataSetField (server, publishedDataSetTest, &dataSetFieldConfig, &dataSetFieldIdent);
  935. /* Writer group */
  936. UA_WriterGroupConfig writerGroupConfig;
  937. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  938. writerGroupConfig.name = UA_STRING("WriterGroup Test");
  939. writerGroupConfig.publishingInterval = PUBLISH_INTERVAL;
  940. writerGroupConfig.enabled = UA_FALSE;
  941. writerGroupConfig.writerGroupId = WRITER_GROUP_ID;
  942. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  943. /* Message settings in WriterGroup to include necessary headers */
  944. writerGroupConfig.messageSettings.encoding = UA_EXTENSIONOBJECT_DECODED;
  945. writerGroupConfig.messageSettings.content.decoded.type = &UA_TYPES[UA_TYPES_UADPWRITERGROUPMESSAGEDATATYPE];
  946. UA_UadpWriterGroupMessageDataType *writerGroupMessage = UA_UadpWriterGroupMessageDataType_new();
  947. writerGroupMessage->networkMessageContentMask = (UA_UadpNetworkMessageContentMask)(UA_UADPNETWORKMESSAGECONTENTMASK_PUBLISHERID |
  948. (UA_UadpNetworkMessageContentMask)UA_UADPNETWORKMESSAGECONTENTMASK_GROUPHEADER |
  949. (UA_UadpNetworkMessageContentMask)UA_UADPNETWORKMESSAGECONTENTMASK_WRITERGROUPID |
  950. (UA_UadpNetworkMessageContentMask)UA_UADPNETWORKMESSAGECONTENTMASK_PAYLOADHEADER);
  951. writerGroupConfig.messageSettings.content.decoded.data = writerGroupMessage;
  952. retVal |= UA_Server_addWriterGroup(server, connection_test, &writerGroupConfig, &writerGroup);
  953. UA_UadpWriterGroupMessageDataType_delete(writerGroupMessage);
  954. UA_Server_setWriterGroupOperational(server, writerGroup);
  955. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  956. /* DataSetWriter */
  957. UA_DataSetWriterConfig dataSetWriterConfig;
  958. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  959. dataSetWriterConfig.name = UA_STRING("DataSetWriter Test");
  960. dataSetWriterConfig.dataSetWriterId = DATASET_WRITER_ID;
  961. dataSetWriterConfig.keyFrameCount = 10;
  962. retVal |= UA_Server_addDataSetWriter(server, writerGroup, publishedDataSetTest, &dataSetWriterConfig, &dataSetWriter);
  963. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  964. /* Reader Group */
  965. UA_ReaderGroupConfig readerGroupConfig;
  966. memset (&readerGroupConfig, 0, sizeof (UA_ReaderGroupConfig));
  967. readerGroupConfig.name = UA_STRING ("ReaderGroup Test");
  968. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &readerGroupTest);
  969. /* Data Set Reader */
  970. /* Parameters to filter received NetworkMessage */
  971. memset (&readerConfig, 0, sizeof (UA_DataSetReaderConfig));
  972. readerConfig.name = UA_STRING ("DataSetReader Test");
  973. UA_UInt16 publisherIdentifier = PUBLISHER_ID;
  974. readerConfig.publisherId.type = &UA_TYPES[UA_TYPES_UINT16];
  975. readerConfig.publisherId.data = &publisherIdentifier;
  976. readerConfig.writerGroupId = WRITER_GROUP_ID;
  977. readerConfig.dataSetWriterId = DATASET_WRITER_ID;
  978. /* Setting up Meta data configuration in DataSetReader */
  979. UA_DataSetMetaDataType *pMetaData = &readerConfig.dataSetMetaData;
  980. /* FilltestMetadata function in subscriber implementation */
  981. UA_DataSetMetaDataType_init (pMetaData);
  982. pMetaData->name = UA_STRING ("DataSet Test");
  983. /* Static definition of number of fields size to 1 to create one
  984. targetVariable */
  985. pMetaData->fieldsSize = 1;
  986. pMetaData->fields = (UA_FieldMetaData*)UA_Array_new (pMetaData->fieldsSize,
  987. &UA_TYPES[UA_TYPES_FIELDMETADATA]);
  988. /* Boolean DataType */
  989. UA_FieldMetaData_init (&pMetaData->fields[0]);
  990. UA_NodeId_copy (&UA_TYPES[UA_TYPES_BOOLEAN].typeId,
  991. &pMetaData->fields[0].dataType);
  992. pMetaData->fields[0].builtInType = UA_NS0ID_BOOLEAN;
  993. pMetaData->fields[0].valueRank = -1; /* scalar */
  994. retVal |= UA_Server_addDataSetReader(server, readerGroupTest, &readerConfig,
  995. &readerIdentifier);
  996. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  997. /* Add Subscribed Variables */
  998. UA_NodeId folderId;
  999. UA_NodeId newnodeId;
  1000. UA_String folderName = readerConfig.dataSetMetaData.name;
  1001. UA_ObjectAttributes oAttr = UA_ObjectAttributes_default;
  1002. UA_QualifiedName folderBrowseName;
  1003. if (folderName.length > 0) {
  1004. oAttr.displayName.locale = UA_STRING ("en-US");
  1005. oAttr.displayName.text = folderName;
  1006. folderBrowseName.namespaceIndex = 1;
  1007. folderBrowseName.name = folderName;
  1008. }
  1009. else {
  1010. oAttr.displayName = UA_LOCALIZEDTEXT ("en-US", "Subscribed Variables");
  1011. folderBrowseName = UA_QUALIFIEDNAME (1, "Subscribed Variables");
  1012. }
  1013. retVal = UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, SUBSCRIBEOBJECT_NODEID),
  1014. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  1015. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  1016. folderBrowseName, UA_NODEID_NUMERIC(0,
  1017. UA_NS0ID_BASEOBJECTTYPE), oAttr, NULL, &folderId);
  1018. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  1019. /* Variable to subscribe data */
  1020. UA_VariableAttributes vAttr = UA_VariableAttributes_default;
  1021. vAttr.description = UA_LOCALIZEDTEXT ("en-US", "Subscribed Bool");
  1022. vAttr.displayName = UA_LOCALIZEDTEXT ("en-US", "Subscribed Bool");
  1023. vAttr.dataType = UA_TYPES[UA_TYPES_BOOLEAN].typeId;
  1024. retVal = UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, SUBSCRIBEVARIABLE_NODEID),
  1025. UA_NODEID_NUMERIC(1, SUBSCRIBEOBJECT_NODEID),
  1026. UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT), UA_QUALIFIEDNAME(1, "Subscribed Bool"),
  1027. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE), vAttr, NULL, &newnodeId);
  1028. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  1029. UA_TargetVariablesDataType targetVars;
  1030. targetVars.targetVariablesSize = 1;
  1031. targetVars.targetVariables = (UA_FieldTargetDataType *)
  1032. UA_calloc(targetVars.targetVariablesSize,
  1033. sizeof(UA_FieldTargetDataType));
  1034. /* For creating Targetvariable */
  1035. UA_FieldTargetDataType_init(&targetVars.targetVariables[0]);
  1036. targetVars.targetVariables[0].attributeId = UA_ATTRIBUTEID_VALUE;
  1037. targetVars.targetVariables[0].targetNodeId = newnodeId;
  1038. retVal |= UA_Server_DataSetReader_createTargetVariables(server, readerIdentifier,
  1039. &targetVars);
  1040. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  1041. UA_TargetVariablesDataType_deleteMembers(&targetVars);
  1042. UA_free(pMetaData->fields);
  1043. /* run server - publisher and subscriber */
  1044. UA_Server_run_iterate(server,true);
  1045. /* Read data sent by the Publisher */
  1046. UA_Variant *publishedNodeData = UA_Variant_new();
  1047. retVal = UA_Server_readValue(server, UA_NODEID_NUMERIC(1, PUBLISHVARIABLE_NODEID), publishedNodeData);
  1048. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  1049. /* Read data received by the Subscriber */
  1050. UA_Variant *subscribedNodeData = UA_Variant_new();
  1051. retVal = UA_Server_readValue(server, UA_NODEID_NUMERIC(1, SUBSCRIBEVARIABLE_NODEID), subscribedNodeData);
  1052. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  1053. /* Check if data sent from Publisher is being received by Subscriber */
  1054. ck_assert_int_eq(*(UA_Boolean *)publishedNodeData->data, *(UA_Boolean *)subscribedNodeData->data);
  1055. UA_Variant_delete(subscribedNodeData);
  1056. UA_Variant_delete(publishedNodeData);
  1057. } END_TEST
  1058. START_TEST(SinglePublishSubscribewithValidIdentifiers) {
  1059. /* To check status after running both publisher and subscriber */
  1060. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  1061. UA_PublishedDataSetConfig pdsConfig;
  1062. UA_NodeId dataSetWriter;
  1063. UA_NodeId readerIdentifier;
  1064. UA_NodeId writerGroup;
  1065. UA_DataSetReaderConfig readerConfig;
  1066. /* Published DataSet */
  1067. memset(&pdsConfig, 0, sizeof(UA_PublishedDataSetConfig));
  1068. pdsConfig.publishedDataSetType = UA_PUBSUB_DATASET_PUBLISHEDITEMS;
  1069. pdsConfig.name = UA_STRING("PublishedDataSet Test");
  1070. UA_Server_addPublishedDataSet(server, &pdsConfig, &publishedDataSetTest);
  1071. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  1072. /* Create variable to publish integer data */
  1073. UA_NodeId publisherNode;
  1074. UA_VariableAttributes attr = UA_VariableAttributes_default;
  1075. attr.description = UA_LOCALIZEDTEXT("en-US","Published Integer");
  1076. attr.displayName = UA_LOCALIZEDTEXT("en-US","Published Integer");
  1077. attr.dataType = UA_TYPES[UA_TYPES_UINT32].typeId;
  1078. attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
  1079. UA_UInt32 publisherData = PUBLISHER_DATA;
  1080. UA_Variant_setScalar(&attr.value, &publisherData, &UA_TYPES[UA_TYPES_UINT32]);
  1081. retVal = UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, PUBLISHVARIABLE_NODEID),
  1082. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  1083. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  1084. UA_QUALIFIEDNAME(1, "Published Integer"),
  1085. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE),
  1086. attr, NULL, &publisherNode);
  1087. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  1088. /* Data Set Field */
  1089. UA_NodeId dataSetFieldIdent;
  1090. UA_DataSetFieldConfig dataSetFieldConfig;
  1091. memset(&dataSetFieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  1092. dataSetFieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  1093. dataSetFieldConfig.field.variable.fieldNameAlias = UA_STRING("Published Integer");
  1094. dataSetFieldConfig.field.variable.promotedField = UA_FALSE;
  1095. dataSetFieldConfig.field.variable.publishParameters.publishedVariable = publisherNode;
  1096. dataSetFieldConfig.field.variable.publishParameters.attributeId = UA_ATTRIBUTEID_VALUE;
  1097. UA_Server_addDataSetField (server, publishedDataSetTest, &dataSetFieldConfig, &dataSetFieldIdent);
  1098. /* Writer group */
  1099. UA_WriterGroupConfig writerGroupConfig;
  1100. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  1101. writerGroupConfig.name = UA_STRING("WriterGroup Test");
  1102. writerGroupConfig.publishingInterval = PUBLISH_INTERVAL;
  1103. writerGroupConfig.enabled = UA_FALSE;
  1104. writerGroupConfig.writerGroupId = WRITER_GROUP_ID;
  1105. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  1106. /* Message settings in WriterGroup to include necessary headers */
  1107. writerGroupConfig.messageSettings.encoding = UA_EXTENSIONOBJECT_DECODED;
  1108. writerGroupConfig.messageSettings.content.decoded.type = &UA_TYPES[UA_TYPES_UADPWRITERGROUPMESSAGEDATATYPE];
  1109. UA_UadpWriterGroupMessageDataType *writerGroupMessage = UA_UadpWriterGroupMessageDataType_new();
  1110. writerGroupMessage->networkMessageContentMask = (UA_UadpNetworkMessageContentMask)(UA_UADPNETWORKMESSAGECONTENTMASK_PUBLISHERID |
  1111. (UA_UadpNetworkMessageContentMask)UA_UADPNETWORKMESSAGECONTENTMASK_GROUPHEADER |
  1112. (UA_UadpNetworkMessageContentMask)UA_UADPNETWORKMESSAGECONTENTMASK_WRITERGROUPID |
  1113. (UA_UadpNetworkMessageContentMask)UA_UADPNETWORKMESSAGECONTENTMASK_PAYLOADHEADER);
  1114. writerGroupConfig.messageSettings.content.decoded.data = writerGroupMessage;
  1115. retVal |= UA_Server_addWriterGroup(server, connection_test, &writerGroupConfig, &writerGroup);
  1116. UA_Server_setWriterGroupOperational(server, writerGroup);
  1117. UA_UadpWriterGroupMessageDataType_delete(writerGroupMessage);
  1118. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  1119. /* DataSetWriter */
  1120. UA_DataSetWriterConfig dataSetWriterConfig;
  1121. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  1122. dataSetWriterConfig.name = UA_STRING("DataSetWriter Test");
  1123. dataSetWriterConfig.dataSetWriterId = DATASET_WRITER_ID;
  1124. dataSetWriterConfig.keyFrameCount = 10;
  1125. retVal |= UA_Server_addDataSetWriter(server, writerGroup, publishedDataSetTest, &dataSetWriterConfig, &dataSetWriter);
  1126. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  1127. /* Reader Group */
  1128. UA_ReaderGroupConfig readerGroupConfig;
  1129. memset (&readerGroupConfig, 0, sizeof (UA_ReaderGroupConfig));
  1130. readerGroupConfig.name = UA_STRING ("ReaderGroup Test");
  1131. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &readerGroupTest);
  1132. /* Data Set Reader */
  1133. /* Parameters to filter received NetworkMessage */
  1134. memset (&readerConfig, 0, sizeof (UA_DataSetReaderConfig));
  1135. readerConfig.name = UA_STRING ("DataSetReader Test");
  1136. UA_UInt16 publisherIdentifier = PUBLISHER_ID;
  1137. readerConfig.publisherId.type = &UA_TYPES[UA_TYPES_UINT16];
  1138. readerConfig.publisherId.data = &publisherIdentifier;
  1139. readerConfig.writerGroupId = WRITER_GROUP_ID;
  1140. readerConfig.dataSetWriterId = DATASET_WRITER_ID;
  1141. /* Setting up Meta data configuration in DataSetReader */
  1142. UA_DataSetMetaDataType *pMetaData = &readerConfig.dataSetMetaData;
  1143. /* FilltestMetadata function in subscriber implementation */
  1144. UA_DataSetMetaDataType_init (pMetaData);
  1145. pMetaData->name = UA_STRING ("DataSet Test");
  1146. /* Static definition of number of fields size to 1 to create one
  1147. targetVariable */
  1148. pMetaData->fieldsSize = 1;
  1149. pMetaData->fields = (UA_FieldMetaData*)UA_Array_new (pMetaData->fieldsSize,
  1150. &UA_TYPES[UA_TYPES_FIELDMETADATA]);
  1151. /* Unsigned Integer DataType */
  1152. UA_FieldMetaData_init (&pMetaData->fields[0]);
  1153. UA_NodeId_copy (&UA_TYPES[UA_TYPES_UINT32].typeId,
  1154. &pMetaData->fields[0].dataType);
  1155. pMetaData->fields[0].builtInType = UA_NS0ID_UINT32;
  1156. pMetaData->fields[0].valueRank = -1; /* scalar */
  1157. retVal |= UA_Server_addDataSetReader(server, readerGroupTest, &readerConfig,
  1158. &readerIdentifier);
  1159. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  1160. /* Add Subscribed Variables */
  1161. UA_NodeId folderId;
  1162. UA_NodeId newnodeId;
  1163. UA_String folderName = readerConfig.dataSetMetaData.name;
  1164. UA_ObjectAttributes oAttr = UA_ObjectAttributes_default;
  1165. UA_QualifiedName folderBrowseName;
  1166. if (folderName.length > 0) {
  1167. oAttr.displayName.locale = UA_STRING ("en-US");
  1168. oAttr.displayName.text = folderName;
  1169. folderBrowseName.namespaceIndex = 1;
  1170. folderBrowseName.name = folderName;
  1171. }
  1172. else {
  1173. oAttr.displayName = UA_LOCALIZEDTEXT ("en-US", "Subscribed Variables");
  1174. folderBrowseName = UA_QUALIFIEDNAME (1, "Subscribed Variables");
  1175. }
  1176. retVal = UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, SUBSCRIBEOBJECT_NODEID),
  1177. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  1178. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  1179. folderBrowseName, UA_NODEID_NUMERIC(0,
  1180. UA_NS0ID_BASEOBJECTTYPE), oAttr, NULL, &folderId);
  1181. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  1182. /* Variable to subscribe data */
  1183. UA_VariableAttributes vAttr = UA_VariableAttributes_default;
  1184. vAttr.displayName.locale = UA_STRING ("en-US");
  1185. vAttr.displayName.text = UA_STRING ("Subscribed Integer");
  1186. vAttr.valueRank = -1;
  1187. retVal = UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, SUBSCRIBEVARIABLE_NODEID),
  1188. UA_NODEID_NUMERIC(1, SUBSCRIBEOBJECT_NODEID),
  1189. UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT), UA_QUALIFIEDNAME(1, "Subscribed Integer"),
  1190. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE), vAttr, NULL, &newnodeId);
  1191. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  1192. UA_TargetVariablesDataType targetVars;
  1193. targetVars.targetVariablesSize = 1;
  1194. targetVars.targetVariables = (UA_FieldTargetDataType *)
  1195. UA_calloc(targetVars.targetVariablesSize,
  1196. sizeof(UA_FieldTargetDataType));
  1197. /* For creating Targetvariable */
  1198. UA_FieldTargetDataType_init(&targetVars.targetVariables[0]);
  1199. targetVars.targetVariables[0].attributeId = UA_ATTRIBUTEID_VALUE;
  1200. targetVars.targetVariables[0].targetNodeId = newnodeId;
  1201. retVal |= UA_Server_DataSetReader_createTargetVariables(server, readerIdentifier,
  1202. &targetVars);
  1203. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  1204. UA_TargetVariablesDataType_deleteMembers(&targetVars);
  1205. UA_free(pMetaData->fields);
  1206. /* run server - publisher and subscriber */
  1207. UA_Server_run_iterate(server,true);
  1208. /* Read data sent by the Publisher */
  1209. UA_Variant *publishedNodeData = UA_Variant_new();
  1210. retVal = UA_Server_readValue(server, UA_NODEID_NUMERIC(1, PUBLISHVARIABLE_NODEID), publishedNodeData);
  1211. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  1212. /* Read data received by the Subscriber */
  1213. UA_Variant *subscribedNodeData = UA_Variant_new();
  1214. retVal = UA_Server_readValue(server, UA_NODEID_NUMERIC(1, SUBSCRIBEVARIABLE_NODEID), subscribedNodeData);
  1215. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  1216. /* Check if data sent from Publisher is being received by Subscriber */
  1217. ck_assert_int_eq(*(UA_UInt32 *)publishedNodeData->data, *(UA_UInt32 *)subscribedNodeData->data);
  1218. UA_Variant_delete(subscribedNodeData);
  1219. UA_Variant_delete(publishedNodeData);
  1220. } END_TEST
  1221. int main(void) {
  1222. TCase *tc_add_pubsub_readergroup = tcase_create("PubSub readerGroup items handling");
  1223. tcase_add_checked_fixture(tc_add_pubsub_readergroup, setup, teardown);
  1224. /* Test cases for ReaderGroup functionality */
  1225. tcase_add_test(tc_add_pubsub_readergroup, AddReaderGroupWithValidConfiguration);
  1226. tcase_add_test(tc_add_pubsub_readergroup, AddReaderGroupWithNullConfig);
  1227. tcase_add_test(tc_add_pubsub_readergroup, AddReaderGroupWithInvalidConnectionId);
  1228. tcase_add_test(tc_add_pubsub_readergroup, RemoveReaderGroupWithInvalidIdentifier);
  1229. tcase_add_test(tc_add_pubsub_readergroup, AddRemoveMultipleAddReaderGroupWithValidConfiguration);
  1230. /* tcase_add_test(tc_add_pubsub_readergroup, UpdateReaderGroupWithInvalidIdentifier); */
  1231. tcase_add_test(tc_add_pubsub_readergroup, GetReaderGroupConfigWithInvalidConfig);
  1232. tcase_add_test(tc_add_pubsub_readergroup, GetReaderGroupConfigWithInvalidIdentifier);
  1233. tcase_add_test(tc_add_pubsub_readergroup, GetReaderGroupConfigWithValidConfig);
  1234. /* Test cases for DataSetReader functionality */
  1235. tcase_add_test(tc_add_pubsub_readergroup, AddDataSetReaderWithValidConfiguration);
  1236. tcase_add_test(tc_add_pubsub_readergroup, AddDataSetReaderWithNullConfig);
  1237. tcase_add_test(tc_add_pubsub_readergroup, RemoveDataSetReaderWithValidConfiguration);
  1238. tcase_add_test(tc_add_pubsub_readergroup, RemoveDataSetReaderWithInvalidIdentifier);
  1239. tcase_add_test(tc_add_pubsub_readergroup, AddMultipleDataSetReaderWithValidConfiguration);
  1240. tcase_add_test(tc_add_pubsub_readergroup, UpdateDataSetReaderConfigWithInvalidId);
  1241. tcase_add_test(tc_add_pubsub_readergroup, GetDataSetReaderConfigWithValidConfiguration);
  1242. tcase_add_test(tc_add_pubsub_readergroup, GetDataSetReaderConfigWithInvalidConfiguration);
  1243. tcase_add_test(tc_add_pubsub_readergroup, GetDataSetReaderConfigWithInvalidIdentifier);
  1244. tcase_add_test(tc_add_pubsub_readergroup, CreateTargetVariableWithInvalidConfiguration);
  1245. tcase_add_test(tc_add_pubsub_readergroup, AddTargetVariableWithInvalidConfiguration);
  1246. tcase_add_test(tc_add_pubsub_readergroup, AddTargetVariableWithValidConfiguration);
  1247. /*Test case to run both publisher and subscriber */
  1248. TCase *tc_pubsub_publish_subscribe = tcase_create("Publisher publishing and Subscriber subscribing");
  1249. tcase_add_checked_fixture(tc_pubsub_publish_subscribe, setup, teardown);
  1250. tcase_add_test(tc_pubsub_publish_subscribe, SinglePublishSubscribeDateTime);
  1251. tcase_add_test(tc_pubsub_publish_subscribe, SinglePublishSubscribeInt32);
  1252. tcase_add_test(tc_pubsub_publish_subscribe, SinglePublishSubscribeInt64);
  1253. tcase_add_test(tc_pubsub_publish_subscribe, SinglePublishSubscribeBool);
  1254. tcase_add_test(tc_pubsub_publish_subscribe, SinglePublishSubscribewithValidIdentifiers);
  1255. Suite *suite = suite_create("PubSub readerGroups/reader/Fields handling and publishing");
  1256. suite_add_tcase(suite, tc_add_pubsub_readergroup);
  1257. suite_add_tcase(suite, tc_pubsub_publish_subscribe);
  1258. SRunner *suiteRunner = srunner_create(suite);
  1259. srunner_set_fork_status(suiteRunner, CK_NOFORK);
  1260. srunner_run_all(suiteRunner,CK_NORMAL);
  1261. int number_failed = srunner_ntests_failed(suiteRunner);
  1262. srunner_free(suiteRunner);
  1263. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  1264. }