check_pubsub_subscribe.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  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 DATASET_WRITER_ID 62541 /* DataSet Writer Id*/
  18. #define WRITER_GROUP_ID 100 /* Writer group Id */
  19. #define PUBLISHVARIABLE_NODEID 1000 /* Published data nodeId */
  20. #define SUBSCRIBEOBJECT_NODEID 1001 /* Object nodeId */
  21. #define SUBSCRIBEVARIABLE_NODEID 1002 /* Subscribed data nodeId */
  22. /* Global declaration for test cases */
  23. UA_Server *server = NULL;
  24. UA_ServerConfig *config = NULL;
  25. UA_NodeId connection_test;
  26. UA_NodeId readerGroupTest;
  27. UA_NodeId publishedDataSetTest;
  28. /* setup() is to create an environment for test cases */
  29. static void setup(void) {
  30. /*Add setup by creating new server with valid configuration */
  31. server = UA_Server_new();
  32. config = UA_Server_getConfig(server);
  33. UA_ServerConfig_setMinimal(config, UA_SUBSCRIBER_PORT, NULL);
  34. UA_Server_run_startup(server);
  35. config->pubsubTransportLayers = (UA_PubSubTransportLayer *) UA_malloc(sizeof(UA_PubSubTransportLayer));
  36. if(!config->pubsubTransportLayers) {
  37. UA_ServerConfig_clean(config);
  38. }
  39. config->pubsubTransportLayers[0] = UA_PubSubTransportLayerUDPMP();
  40. config->pubsubTransportLayersSize++;
  41. /* Add connection to the server */
  42. UA_PubSubConnectionConfig connectionConfig;
  43. memset(&connectionConfig, 0, sizeof(UA_PubSubConnectionConfig));
  44. connectionConfig.name = UA_STRING("UADP Test Connection");
  45. UA_NetworkAddressUrlDataType networkAddressUrl = {UA_STRING_NULL, UA_STRING("opc.udp://224.0.0.22:4801/")};
  46. UA_Variant_setScalar(&connectionConfig.address, &networkAddressUrl,
  47. &UA_TYPES[UA_TYPES_NETWORKADDRESSURLDATATYPE]);
  48. connectionConfig.transportProfileUri = UA_STRING("http://opcfoundation.org/UA-Profile/Transport/pubsub-udp-uadp");
  49. UA_Server_addPubSubConnection(server, &connectionConfig, &connection_test);
  50. }
  51. /* teardown() is to delete the environment set for test cases */
  52. static void teardown(void) {
  53. /*Call server delete functions */
  54. UA_Server_run_shutdown(server);
  55. UA_Server_delete(server);
  56. }
  57. START_TEST(AddReaderGroupWithValidConfiguration) {
  58. /* To test if ReaderGroup has been added to the connection with valid configuration */
  59. UA_StatusCode retVal;
  60. UA_ReaderGroupConfig readerGroupConfig;
  61. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  62. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  63. UA_NodeId localreaderGroup;
  64. retVal = UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  65. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  66. size_t readerGroupCount = 0;
  67. UA_ReaderGroup *readerGroup;
  68. LIST_FOREACH(readerGroup, &UA_PubSubConnection_findConnectionbyId(server, connection_test)->readerGroups, listEntry){
  69. readerGroupCount++;
  70. }
  71. /* Check readerGroup count */
  72. ck_assert_int_eq(readerGroupCount, 1);
  73. /* To Do: RemoveReaderGroup operation should be carried out when UA_Server_delete has been called */
  74. UA_Server_removeReaderGroup(server, localreaderGroup);
  75. } END_TEST
  76. START_TEST(AddReaderGroupWithNullConfig) {
  77. /* Check the status of adding ReaderGroup when NULL configuration is given */
  78. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  79. retVal |= UA_Server_addReaderGroup(server, connection_test, NULL, NULL);
  80. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  81. size_t readerGroupCount = 0;
  82. UA_ReaderGroup *readerGroup;
  83. LIST_FOREACH(readerGroup, &UA_PubSubConnection_findConnectionbyId(server, connection_test)->readerGroups, listEntry){
  84. readerGroupCount++;
  85. }
  86. /* Check readerGroup count */
  87. ck_assert_int_eq(readerGroupCount, 0);
  88. } END_TEST
  89. START_TEST(AddReaderGroupWithInvalidConnectionId) {
  90. /* Check status of adding ReaderGroup with invalid connection identifier */
  91. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  92. UA_ReaderGroupConfig readerGroupConfig;
  93. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  94. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  95. retVal |= UA_Server_addReaderGroup(server, UA_NODEID_NUMERIC(0, UA_UINT32_MAX), &readerGroupConfig, NULL);
  96. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  97. size_t readerGroupCount = 0;
  98. UA_ReaderGroup *readerGroup;
  99. LIST_FOREACH(readerGroup, &UA_PubSubConnection_findConnectionbyId(server, connection_test)->readerGroups, listEntry){
  100. readerGroupCount++;
  101. }
  102. /* Check readerGroup count */
  103. ck_assert_int_eq(readerGroupCount, 0);
  104. } END_TEST
  105. START_TEST(RemoveReaderGroupWithInvalidIdentifier) {
  106. /* Check status of removing ReaderGroup when giving invalid ReaderGroup identifier */
  107. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  108. UA_ReaderGroupConfig readerGroupConfig;
  109. UA_NodeId localreaderGroup;
  110. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  111. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  112. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  113. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  114. /* Delete the added readerGroup */
  115. retVal |= UA_Server_removeReaderGroup(server, UA_NODEID_NUMERIC(0, UA_UINT32_MAX));
  116. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  117. size_t readerGroupCount = 0;
  118. UA_ReaderGroup *readerGroup;
  119. LIST_FOREACH(readerGroup, &UA_PubSubConnection_findConnectionbyId(server, connection_test)->readerGroups, listEntry){
  120. readerGroupCount++;
  121. }
  122. /* Check readerGroup count */
  123. ck_assert_int_eq(readerGroupCount, 1);
  124. UA_Server_removeReaderGroup(server, localreaderGroup);
  125. } END_TEST
  126. START_TEST(UpdateReaderGroupWithInvalidIdentifier) {
  127. /* Check status of updating ReaderGroup with invalid identifier */
  128. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  129. UA_ReaderGroupConfig readerGroupConfig;
  130. UA_NodeId localreaderGroup;
  131. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  132. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  133. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  134. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  135. retVal |= UA_Server_ReaderGroup_updateConfig(server, UA_NODEID_NUMERIC(0, UA_UINT32_MAX), NULL);
  136. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  137. UA_Server_removeReaderGroup(server, localreaderGroup);
  138. } END_TEST
  139. START_TEST(GetReaderGroupConfigWithInvalidConfig) {
  140. /* Check status of getting ReaderGroup configuration with invalid configuration */
  141. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  142. UA_ReaderGroupConfig readerGroupConfig;
  143. UA_NodeId localreaderGroup;
  144. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  145. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  146. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  147. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  148. retVal |= UA_Server_ReaderGroup_getConfig(server, UA_NODEID_NUMERIC(0, UA_UINT32_MAX), NULL);
  149. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  150. UA_Server_removeReaderGroup(server, localreaderGroup);
  151. } END_TEST
  152. START_TEST(GetReaderGroupConfigWithInvalidIdentifier) {
  153. /* Check status of getting ReaderGroup configuration with invlaid identifier */
  154. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  155. UA_ReaderGroupConfig readerGroupConfig;
  156. UA_NodeId localreaderGroup;
  157. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  158. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  159. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  160. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  161. retVal |= UA_Server_ReaderGroup_getConfig(server, UA_NODEID_NUMERIC(0, UA_UINT32_MAX), &readerGroupConfig);
  162. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  163. UA_Server_removeReaderGroup(server, localreaderGroup);
  164. } END_TEST
  165. START_TEST(GetReaderGroupConfigWithValidConfig) {
  166. /* Check status of getting ReaderGroup configuration with valid parameters */
  167. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  168. UA_NodeId localreaderGroup;
  169. UA_ReaderGroupConfig readerGroupConfig;
  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_getConfig(server, localreaderGroup, &readerGroupConfig);
  175. /* To Do: DeleteMembers of readergroup config has to be a separate function */
  176. UA_String_deleteMembers (&readerGroupConfig.name);
  177. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  178. } END_TEST
  179. START_TEST(AddDataSetReaderWithValidConfiguration) {
  180. /* Check status of adding DataSetReader to ReaderGroup with valid parameters*/
  181. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  182. UA_DataSetReaderConfig dataSetreaderConfig;
  183. UA_NodeId localreaderGroup;
  184. UA_ReaderGroupConfig readerGroupConfig;
  185. UA_NodeId localDataSetreader;
  186. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  187. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  188. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  189. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  190. memset(&dataSetreaderConfig, 0, sizeof(dataSetreaderConfig));
  191. dataSetreaderConfig.name = UA_STRING("DataSetreader Test");
  192. retVal |= UA_Server_addDataSetReader(server, localreaderGroup, &dataSetreaderConfig, &localDataSetreader);
  193. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  194. } END_TEST
  195. START_TEST(AddDataSetReaderWithNullConfig) {
  196. /* Check status of adding DataSetReader to ReaderGroup with invalid parameters */
  197. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  198. UA_DataSetReaderConfig dataSetreaderConfig;
  199. UA_NodeId localreaderGroup;
  200. UA_ReaderGroupConfig readerGroupConfig;
  201. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  202. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  203. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  204. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  205. memset(&dataSetreaderConfig, 0, sizeof(dataSetreaderConfig));
  206. dataSetreaderConfig.name = UA_STRING("DataSetreader Test ");
  207. /* Remove the added DataSetReader */
  208. retVal |= UA_Server_addDataSetReader(server, localreaderGroup, NULL, NULL);
  209. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  210. } END_TEST
  211. START_TEST(RemoveDataSetReaderWithValidConfiguration) {
  212. /* Check status of adding DataSetReader to ReaderGroup with valid parameters */
  213. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  214. UA_DataSetReaderConfig dataSetreaderConfig;
  215. UA_NodeId localreaderGroup;
  216. UA_ReaderGroupConfig readerGroupConfig;
  217. UA_NodeId localDataSetreader;
  218. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  219. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  220. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  221. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  222. memset(&dataSetreaderConfig, 0, sizeof(dataSetreaderConfig));
  223. dataSetreaderConfig.name = UA_STRING("DataSetReader Test ");
  224. retVal |= UA_Server_addDataSetReader(server, localreaderGroup, &dataSetreaderConfig, &localDataSetreader);
  225. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  226. retVal |= UA_Server_removeDataSetReader(server, localDataSetreader);
  227. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  228. } END_TEST
  229. START_TEST(RemoveDataSetReaderWithInvalidIdentifier) {
  230. /* Check status of removing DataSetReader from ReaderGroup with invalid parameters */
  231. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  232. UA_DataSetReaderConfig dataSetreaderConfig;
  233. UA_NodeId localreaderGroup;
  234. UA_ReaderGroupConfig readerGroupConfig;
  235. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  236. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  237. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  238. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  239. memset(&dataSetreaderConfig, 0, sizeof(dataSetreaderConfig));
  240. dataSetreaderConfig.name = UA_STRING("DataSetReader Test ");
  241. retVal |= UA_Server_addDataSetReader(server, localreaderGroup, NULL, NULL);
  242. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  243. /* Remove the added DataSetReader */
  244. retVal |= UA_Server_removeDataSetReader(server, UA_NODEID_NUMERIC(0, UA_UINT32_MAX));
  245. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  246. } END_TEST
  247. START_TEST(UpdateDataSetReaderConfigWithInvalidId) {
  248. /* Check status of updatting DataSetReader with invalid configuration */
  249. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  250. UA_DataSetReaderConfig dataSetreaderConfig;
  251. UA_NodeId localreaderGroup;
  252. UA_NodeId localDataSetreader;
  253. UA_ReaderGroupConfig readerGroupConfig;
  254. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  255. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  256. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  257. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  258. memset(&dataSetreaderConfig, 0, sizeof(dataSetreaderConfig));
  259. retVal |= UA_Server_addDataSetReader(server, localreaderGroup,
  260. &dataSetreaderConfig, &localDataSetreader);
  261. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  262. retVal |= UA_Server_DataSetReader_updateConfig(server, UA_NODEID_NUMERIC(0, UA_UINT32_MAX),
  263. localreaderGroup, &dataSetreaderConfig );
  264. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  265. } END_TEST
  266. START_TEST(GetDataSetReaderConfigWithValidConfiguration) {
  267. /* Check status of getting DataSetReader with Valid configuration */
  268. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  269. UA_DataSetReaderConfig dataSetreaderConfig;
  270. UA_NodeId localreaderGroup;
  271. UA_NodeId localDataSetreader;
  272. UA_ReaderGroupConfig readerGroupConfig;
  273. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  274. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  275. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  276. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  277. memset(&dataSetreaderConfig, 0, sizeof(dataSetreaderConfig));
  278. retVal |= UA_Server_addDataSetReader(server, localreaderGroup, &dataSetreaderConfig, &localDataSetreader);
  279. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  280. retVal |= UA_Server_DataSetReader_getConfig(server, localDataSetreader, &dataSetreaderConfig);
  281. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  282. } END_TEST
  283. START_TEST(GetDataSetReaderConfigWithInvalidConfiguration) {
  284. /* Check status of getting DataSetReader with Invalid configuration */
  285. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  286. UA_DataSetReaderConfig dataSetreaderConfig;
  287. UA_NodeId localreaderGroup;
  288. UA_NodeId localDataSetreader;
  289. UA_ReaderGroupConfig readerGroupConfig;
  290. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  291. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  292. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  293. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  294. memset(&dataSetreaderConfig, 0, sizeof(dataSetreaderConfig));
  295. retVal |= UA_Server_addDataSetReader(server, localreaderGroup, &dataSetreaderConfig, &localDataSetreader);
  296. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  297. retVal |= UA_Server_DataSetReader_getConfig(server, localDataSetreader, NULL);
  298. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  299. } END_TEST
  300. START_TEST(GetDataSetReaderConfigWithInvalidIdentifier) {
  301. /* Check status of getting DataSetReader with Invalid Identifier */
  302. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  303. UA_DataSetReaderConfig dataSetreaderConfig;
  304. UA_NodeId localreaderGroup;
  305. UA_NodeId localDataSetreader;
  306. UA_ReaderGroupConfig readerGroupConfig;
  307. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  308. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  309. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  310. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  311. memset(&dataSetreaderConfig, 0, sizeof(dataSetreaderConfig));
  312. retVal |= UA_Server_addDataSetReader(server, localreaderGroup, &dataSetreaderConfig, &localDataSetreader);
  313. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  314. retVal |= UA_Server_DataSetReader_getConfig(server, UA_NODEID_NUMERIC(0, UA_UINT32_MAX), &dataSetreaderConfig);
  315. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  316. } END_TEST
  317. START_TEST(CreateTargetVariableWithInvalidConfiguration) {
  318. /* Check status to create target variable with invalid configuration */
  319. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  320. UA_DataSetReaderConfig dataSetreaderConfig;
  321. UA_NodeId localreaderGroup;
  322. UA_NodeId localDataSetreader;
  323. UA_TargetVariablesDataType localTargetVariable;
  324. UA_ReaderGroupConfig readerGroupConfig;
  325. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  326. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  327. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  328. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  329. memset(&dataSetreaderConfig, 0, sizeof(dataSetreaderConfig));
  330. retVal |= UA_Server_addDataSetReader(server, localreaderGroup, &dataSetreaderConfig, &localDataSetreader);
  331. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  332. retVal |= UA_Server_DataSetReader_createTargetVariables(server, UA_NODEID_NUMERIC(0, UA_UINT32_MAX), &localTargetVariable);
  333. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  334. } END_TEST
  335. START_TEST(AddTargetVariableWithInvalidConfiguration) {
  336. /* Check status to create target variable with invalid configuration */
  337. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  338. UA_DataSetReaderConfig dataSetreaderConfig;
  339. UA_NodeId localreaderGroup;
  340. UA_NodeId localDataSetreader;
  341. UA_ReaderGroupConfig readerGroupConfig;
  342. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  343. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  344. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroup);
  345. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  346. memset(&dataSetreaderConfig, 0, sizeof(dataSetreaderConfig));
  347. retVal |= UA_Server_addDataSetReader(server, localreaderGroup, &dataSetreaderConfig, &localDataSetreader);
  348. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  349. retVal |= UA_Server_DataSetReader_addTargetVariables(NULL, &localreaderGroup, localDataSetreader, UA_PUBSUB_SDS_TARGET);
  350. ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD);
  351. } END_TEST
  352. START_TEST(AddTargetVariableWithValidConfiguration) {
  353. /* Check status after creating target variables with Valid configuration */
  354. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  355. UA_DataSetReaderConfig dataSetReaderConfig;
  356. UA_NodeId folderId;
  357. UA_QualifiedName folderBrowseName;
  358. UA_NodeId localreaderGroupIdentifier;
  359. UA_NodeId localDataSetreaderIdentifier;
  360. UA_ObjectAttributes oAttr = UA_ObjectAttributes_default;
  361. UA_ReaderGroupConfig readerGroupConfig;
  362. memset(&readerGroupConfig, 0, sizeof(readerGroupConfig));
  363. readerGroupConfig.name = UA_STRING("ReaderGroup Test");
  364. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localreaderGroupIdentifier);
  365. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  366. memset(&dataSetReaderConfig, 0, sizeof(UA_DataSetReaderConfig));
  367. UA_DataSetMetaDataType *pMetaData = &dataSetReaderConfig.dataSetMetaData;
  368. UA_DataSetMetaDataType_init (pMetaData);
  369. pMetaData->name = UA_STRING ("DataSet Test");
  370. /* Static definition of number of fields size to 2 to create targetVariables
  371. * with DateTime and ByteString datatype */
  372. pMetaData->fieldsSize = 2;
  373. pMetaData->fields = (UA_FieldMetaData*)UA_Array_new (pMetaData->fieldsSize,
  374. &UA_TYPES[UA_TYPES_FIELDMETADATA]);
  375. /* DateTime DataType */
  376. UA_FieldMetaData_init (&pMetaData->fields[0]);
  377. UA_NodeId_copy (&UA_TYPES[UA_TYPES_DATETIME].typeId,
  378. &pMetaData->fields[0].dataType);
  379. pMetaData->fields[0].builtInType = UA_NS0ID_DATETIME;
  380. pMetaData->fields[0].valueRank = -1; /* scalar */
  381. /* ByteString DataType */
  382. UA_FieldMetaData_init (&pMetaData->fields[1]);
  383. UA_NodeId_copy (&UA_TYPES[UA_TYPES_BYTESTRING].typeId,
  384. &pMetaData->fields[1].dataType);
  385. pMetaData->fields[1].builtInType = UA_NS0ID_BYTESTRING;
  386. pMetaData->fields[1].valueRank = -1; /* scalar */
  387. retVal |= UA_Server_addDataSetReader(server, localreaderGroupIdentifier, &dataSetReaderConfig, &localDataSetreaderIdentifier);
  388. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  389. folderBrowseName = UA_QUALIFIEDNAME (1, "Subscribed Variables");
  390. UA_Server_addObjectNode (server, UA_NODEID_NULL,
  391. UA_NODEID_NUMERIC (0, UA_NS0ID_OBJECTSFOLDER),
  392. UA_NODEID_NUMERIC (0, UA_NS0ID_ORGANIZES),
  393. folderBrowseName, UA_NODEID_NUMERIC (0,
  394. UA_NS0ID_BASEOBJECTTYPE), oAttr, NULL, &folderId);
  395. retVal |= UA_Server_DataSetReader_addTargetVariables(server, &folderId, localDataSetreaderIdentifier, UA_PUBSUB_SDS_TARGET);
  396. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  397. UA_free(pMetaData->fields);
  398. } END_TEST
  399. START_TEST(SinglePublishSubscribeDateTime) {
  400. /* To check status after running both publisher and subscriber */
  401. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  402. UA_PublishedDataSetConfig pdsConfig;
  403. UA_NodeId dataSetWriter;
  404. UA_NodeId readerIdentifier;
  405. UA_NodeId writerGroup;
  406. UA_DataSetReaderConfig readerConfig;
  407. memset(&pdsConfig, 0, sizeof(UA_PublishedDataSetConfig));
  408. pdsConfig.publishedDataSetType = UA_PUBSUB_DATASET_PUBLISHEDITEMS;
  409. pdsConfig.name = UA_STRING("PublishedDataSet Test");
  410. UA_Server_addPublishedDataSet(server, &pdsConfig, &publishedDataSetTest);
  411. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  412. /* Data Set Field */
  413. UA_NodeId dataSetFieldId;
  414. UA_DataSetFieldConfig dataSetFieldConfig;
  415. memset(&dataSetFieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  416. dataSetFieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  417. dataSetFieldConfig.field.variable.fieldNameAlias = UA_STRING("Server localtime");
  418. dataSetFieldConfig.field.variable.promotedField = UA_FALSE;
  419. dataSetFieldConfig.field.variable.publishParameters.publishedVariable = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_LOCALTIME);
  420. dataSetFieldConfig.field.variable.publishParameters.attributeId = UA_ATTRIBUTEID_VALUE;
  421. UA_Server_addDataSetField(server, publishedDataSetTest, &dataSetFieldConfig, &dataSetFieldId);
  422. /* Writer group */
  423. UA_WriterGroupConfig writerGroupConfig;
  424. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  425. writerGroupConfig.name = UA_STRING("WriterGroup Test");
  426. writerGroupConfig.publishingInterval = PUBLISH_INTERVAL;
  427. writerGroupConfig.enabled = UA_FALSE;
  428. writerGroupConfig.writerGroupId = WRITER_GROUP_ID;
  429. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  430. retVal |= UA_Server_addWriterGroup(server, connection_test, &writerGroupConfig, &writerGroup);
  431. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  432. /* DataSetWriter */
  433. UA_DataSetWriterConfig dataSetWriterConfig;
  434. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  435. dataSetWriterConfig.name = UA_STRING("DataSetWriter Test");
  436. dataSetWriterConfig.dataSetWriterId = DATASET_WRITER_ID;
  437. dataSetWriterConfig.keyFrameCount = 10;
  438. retVal |= UA_Server_addDataSetWriter(server, writerGroup, publishedDataSetTest, &dataSetWriterConfig, &dataSetWriter);
  439. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  440. /* Reader Group */
  441. UA_ReaderGroupConfig readerGroupConfig;
  442. memset (&readerGroupConfig, 0, sizeof (UA_ReaderGroupConfig));
  443. readerGroupConfig.name = UA_STRING ("ReaderGroup Test");
  444. retVal |= UA_Server_addReaderGroup (server, connection_test, &readerGroupConfig,
  445. &readerGroupTest);
  446. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  447. /* Data Set Reader */
  448. memset (&readerConfig, 0, sizeof (UA_DataSetReaderConfig));
  449. readerConfig.name = UA_STRING ("DataSetReader Test");
  450. readerConfig.dataSetWriterId = DATASET_WRITER_ID;
  451. /* Setting up Meta data configuration in DataSetReader for DateTime DataType */
  452. UA_DataSetMetaDataType *pMetaData = &readerConfig.dataSetMetaData;
  453. /* FilltestMetadata function in subscriber implementation */
  454. UA_DataSetMetaDataType_init (pMetaData);
  455. pMetaData->name = UA_STRING ("DataSet Test");
  456. /* Static definition of number of fields size to 1 to create one
  457. targetVariable */
  458. pMetaData->fieldsSize = 1;
  459. pMetaData->fields = (UA_FieldMetaData*)UA_Array_new (pMetaData->fieldsSize,
  460. &UA_TYPES[UA_TYPES_FIELDMETADATA]);
  461. /* DateTime DataType */
  462. UA_FieldMetaData_init (&pMetaData->fields[0]);
  463. UA_NodeId_copy (&UA_TYPES[UA_TYPES_DATETIME].typeId,
  464. &pMetaData->fields[0].dataType);
  465. pMetaData->fields[0].builtInType = UA_NS0ID_DATETIME;
  466. pMetaData->fields[0].valueRank = -1; /* scalar */
  467. retVal |= UA_Server_addDataSetReader (server, readerGroupTest, &readerConfig,
  468. &readerIdentifier);
  469. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  470. /* Add Subscribed Variables */
  471. UA_NodeId folderId;
  472. UA_String folderName = readerConfig.dataSetMetaData.name;
  473. UA_ObjectAttributes oAttr = UA_ObjectAttributes_default;
  474. UA_QualifiedName folderBrowseName;
  475. if (folderName.length > 0) {
  476. oAttr.displayName.locale = UA_STRING ("en-US");
  477. oAttr.displayName.text = folderName;
  478. folderBrowseName.namespaceIndex = 1;
  479. folderBrowseName.name = folderName;
  480. }
  481. else {
  482. oAttr.displayName = UA_LOCALIZEDTEXT ("en-US", "Subscribed Variables");
  483. folderBrowseName = UA_QUALIFIEDNAME (1, "Subscribed Variables");
  484. }
  485. UA_Server_addObjectNode (server, UA_NODEID_NULL,
  486. UA_NODEID_NUMERIC (0, UA_NS0ID_OBJECTSFOLDER),
  487. UA_NODEID_NUMERIC (0, UA_NS0ID_ORGANIZES),
  488. folderBrowseName, UA_NODEID_NUMERIC (0,
  489. UA_NS0ID_BASEOBJECTTYPE), oAttr, NULL, &folderId);
  490. retVal |= UA_Server_DataSetReader_addTargetVariables (server, &folderId,
  491. readerIdentifier, UA_PUBSUB_SDS_TARGET);
  492. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  493. /* run server - publisher and subscriber */
  494. UA_Server_run_iterate(server,true);
  495. UA_Server_run_iterate(server,true);
  496. UA_free(pMetaData->fields);
  497. }END_TEST
  498. START_TEST(SinglePublishSubscribeInt32) {
  499. /* To check status after running both publisher and subscriber */
  500. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  501. UA_PublishedDataSetConfig pdsConfig;
  502. UA_NodeId dataSetWriter;
  503. UA_NodeId readerIdentifier;
  504. UA_NodeId writerGroup;
  505. UA_DataSetReaderConfig readerConfig;
  506. /* Published DataSet */
  507. memset(&pdsConfig, 0, sizeof(UA_PublishedDataSetConfig));
  508. pdsConfig.publishedDataSetType = UA_PUBSUB_DATASET_PUBLISHEDITEMS;
  509. pdsConfig.name = UA_STRING("PublishedDataSet Test");
  510. UA_Server_addPublishedDataSet(server, &pdsConfig, &publishedDataSetTest);
  511. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  512. /* Create variable to publish integer data */
  513. UA_NodeId publisherNode;
  514. UA_VariableAttributes attr = UA_VariableAttributes_default;
  515. attr.description = UA_LOCALIZEDTEXT("en-US","Published Int32");
  516. attr.displayName = UA_LOCALIZEDTEXT("en-US","Published Int32");
  517. attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  518. UA_Int32 publisherData = 42;
  519. UA_Variant_setScalar(&attr.value, &publisherData, &UA_TYPES[UA_TYPES_INT32]);
  520. retVal = UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, PUBLISHVARIABLE_NODEID),
  521. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  522. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  523. UA_QUALIFIEDNAME(1, "Published Int32"),
  524. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE),
  525. attr, NULL, &publisherNode);
  526. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  527. /* Data Set Field */
  528. UA_NodeId dataSetFieldIdent;
  529. UA_DataSetFieldConfig dataSetFieldConfig;
  530. memset(&dataSetFieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  531. dataSetFieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  532. dataSetFieldConfig.field.variable.fieldNameAlias = UA_STRING("Published Int32");
  533. dataSetFieldConfig.field.variable.promotedField = UA_FALSE;
  534. dataSetFieldConfig.field.variable.publishParameters.publishedVariable = publisherNode;
  535. dataSetFieldConfig.field.variable.publishParameters.attributeId = UA_ATTRIBUTEID_VALUE;
  536. UA_Server_addDataSetField (server, publishedDataSetTest, &dataSetFieldConfig, &dataSetFieldIdent);
  537. /* Writer group */
  538. UA_WriterGroupConfig writerGroupConfig;
  539. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  540. writerGroupConfig.name = UA_STRING("WriterGroup Test");
  541. writerGroupConfig.publishingInterval = PUBLISH_INTERVAL;
  542. writerGroupConfig.enabled = UA_FALSE;
  543. writerGroupConfig.writerGroupId = WRITER_GROUP_ID;
  544. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  545. retVal |= UA_Server_addWriterGroup(server, connection_test, &writerGroupConfig, &writerGroup);
  546. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  547. /* DataSetWriter */
  548. UA_DataSetWriterConfig dataSetWriterConfig;
  549. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  550. dataSetWriterConfig.name = UA_STRING("DataSetWriter Test");
  551. dataSetWriterConfig.dataSetWriterId = DATASET_WRITER_ID;
  552. dataSetWriterConfig.keyFrameCount = 10;
  553. retVal |= UA_Server_addDataSetWriter(server, writerGroup, publishedDataSetTest, &dataSetWriterConfig, &dataSetWriter);
  554. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  555. /* Reader Group */
  556. UA_ReaderGroupConfig readerGroupConfig;
  557. memset (&readerGroupConfig, 0, sizeof (UA_ReaderGroupConfig));
  558. readerGroupConfig.name = UA_STRING ("ReaderGroup Test");
  559. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &readerGroupTest);
  560. /* Data Set Reader */
  561. /* Parameters to filter received NetworkMessage */
  562. memset (&readerConfig, 0, sizeof (UA_DataSetReaderConfig));
  563. readerConfig.name = UA_STRING ("DataSetReader Test");
  564. readerConfig.dataSetWriterId = DATASET_WRITER_ID;
  565. /* Setting up Meta data configuration in DataSetReader */
  566. UA_DataSetMetaDataType *pMetaData = &readerConfig.dataSetMetaData;
  567. /* FilltestMetadata function in subscriber implementation */
  568. UA_DataSetMetaDataType_init (pMetaData);
  569. pMetaData->name = UA_STRING ("DataSet Test");
  570. /* Static definition of number of fields size to 1 to create one
  571. targetVariable */
  572. pMetaData->fieldsSize = 1;
  573. pMetaData->fields = (UA_FieldMetaData*)UA_Array_new (pMetaData->fieldsSize,
  574. &UA_TYPES[UA_TYPES_FIELDMETADATA]);
  575. /* Unsigned Integer DataType */
  576. UA_FieldMetaData_init (&pMetaData->fields[0]);
  577. UA_NodeId_copy (&UA_TYPES[UA_TYPES_INT32].typeId,
  578. &pMetaData->fields[0].dataType);
  579. pMetaData->fields[0].builtInType = UA_NS0ID_INT32;
  580. pMetaData->fields[0].valueRank = -1; /* scalar */
  581. retVal |= UA_Server_addDataSetReader(server, readerGroupTest, &readerConfig,
  582. &readerIdentifier);
  583. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  584. /* Add Subscribed Variables */
  585. UA_NodeId folderId;
  586. UA_NodeId newnodeId;
  587. UA_String folderName = readerConfig.dataSetMetaData.name;
  588. UA_ObjectAttributes oAttr = UA_ObjectAttributes_default;
  589. UA_QualifiedName folderBrowseName;
  590. if (folderName.length > 0) {
  591. oAttr.displayName.locale = UA_STRING ("en-US");
  592. oAttr.displayName.text = folderName;
  593. folderBrowseName.namespaceIndex = 1;
  594. folderBrowseName.name = folderName;
  595. }
  596. else {
  597. oAttr.displayName = UA_LOCALIZEDTEXT ("en-US", "Subscribed Variables");
  598. folderBrowseName = UA_QUALIFIEDNAME (1, "Subscribed Variables");
  599. }
  600. retVal = UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, SUBSCRIBEOBJECT_NODEID),
  601. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  602. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  603. folderBrowseName, UA_NODEID_NUMERIC(0,
  604. UA_NS0ID_BASEOBJECTTYPE), oAttr, NULL, &folderId);
  605. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  606. /* Variable to subscribe data */
  607. UA_VariableAttributes vAttr = UA_VariableAttributes_default;
  608. vAttr.description = UA_LOCALIZEDTEXT ("en-US", "Subscribed Int32");
  609. vAttr.displayName = UA_LOCALIZEDTEXT ("en-US", "Subscribed Int32");
  610. vAttr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  611. retVal = UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, SUBSCRIBEVARIABLE_NODEID),
  612. UA_NODEID_NUMERIC(1, SUBSCRIBEOBJECT_NODEID),
  613. UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT), UA_QUALIFIEDNAME(1, "Subscribed Int32"),
  614. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE), vAttr, NULL, &newnodeId);
  615. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  616. UA_TargetVariablesDataType targetVars;
  617. targetVars.targetVariablesSize = 1;
  618. targetVars.targetVariables = (UA_FieldTargetDataType *)
  619. UA_calloc(targetVars.targetVariablesSize,
  620. sizeof(UA_FieldTargetDataType));
  621. /* For creating Targetvariable */
  622. UA_FieldTargetDataType_init(&targetVars.targetVariables[0]);
  623. targetVars.targetVariables[0].attributeId = UA_ATTRIBUTEID_VALUE;
  624. targetVars.targetVariables[0].targetNodeId = newnodeId;
  625. retVal |= UA_Server_DataSetReader_createTargetVariables(server, readerIdentifier,
  626. &targetVars);
  627. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  628. UA_TargetVariablesDataType_deleteMembers(&targetVars);
  629. UA_free(pMetaData->fields);
  630. /* run server - publisher and subscriber */
  631. UA_Server_run_iterate(server,true);
  632. /* Read data sent by the Publisher */
  633. UA_Variant *publishedNodeData = UA_Variant_new();
  634. retVal = UA_Server_readValue(server, UA_NODEID_NUMERIC(1, PUBLISHVARIABLE_NODEID), publishedNodeData);
  635. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  636. /* Read data received by the Subscriber */
  637. UA_Variant *subscribedNodeData = UA_Variant_new();
  638. retVal = UA_Server_readValue(server, UA_NODEID_NUMERIC(1, SUBSCRIBEVARIABLE_NODEID), subscribedNodeData);
  639. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  640. /* Check if data sent from Publisher is being received by Subscriber */
  641. ck_assert_int_eq(*(UA_Int32 *)publishedNodeData->data, *(UA_Int32 *)subscribedNodeData->data);
  642. UA_Variant_delete(subscribedNodeData);
  643. UA_Variant_delete(publishedNodeData);
  644. } END_TEST
  645. START_TEST(SinglePublishSubscribeInt64) {
  646. /* To check status after running both publisher and subscriber */
  647. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  648. UA_PublishedDataSetConfig pdsConfig;
  649. UA_NodeId dataSetWriter;
  650. UA_NodeId readerIdentifier;
  651. UA_NodeId writerGroup;
  652. UA_DataSetReaderConfig readerConfig;
  653. /* Published DataSet */
  654. memset(&pdsConfig, 0, sizeof(UA_PublishedDataSetConfig));
  655. pdsConfig.publishedDataSetType = UA_PUBSUB_DATASET_PUBLISHEDITEMS;
  656. pdsConfig.name = UA_STRING("PublishedDataSet Test");
  657. UA_Server_addPublishedDataSet(server, &pdsConfig, &publishedDataSetTest);
  658. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  659. /* Create variable to publish integer data */
  660. UA_NodeId publisherNode;
  661. UA_VariableAttributes attr = UA_VariableAttributes_default;
  662. attr.description = UA_LOCALIZEDTEXT("en-US","Published Int64");
  663. attr.displayName = UA_LOCALIZEDTEXT("en-US","Published Int64");
  664. attr.dataType = UA_TYPES[UA_TYPES_INT64].typeId;
  665. UA_Int64 publisherData = 64;
  666. UA_Variant_setScalar(&attr.value, &publisherData, &UA_TYPES[UA_TYPES_INT64]);
  667. retVal = UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, PUBLISHVARIABLE_NODEID),
  668. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  669. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  670. UA_QUALIFIEDNAME(1, "Published Int64"),
  671. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE),
  672. attr, NULL, &publisherNode);
  673. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  674. /* Data Set Field */
  675. UA_NodeId dataSetFieldIdent;
  676. UA_DataSetFieldConfig dataSetFieldConfig;
  677. memset(&dataSetFieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  678. dataSetFieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  679. dataSetFieldConfig.field.variable.fieldNameAlias = UA_STRING("Published Int64");
  680. dataSetFieldConfig.field.variable.promotedField = UA_FALSE;
  681. dataSetFieldConfig.field.variable.publishParameters.publishedVariable = publisherNode;
  682. dataSetFieldConfig.field.variable.publishParameters.attributeId = UA_ATTRIBUTEID_VALUE;
  683. UA_Server_addDataSetField (server, publishedDataSetTest, &dataSetFieldConfig, &dataSetFieldIdent);
  684. /* Writer group */
  685. UA_WriterGroupConfig writerGroupConfig;
  686. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  687. writerGroupConfig.name = UA_STRING("WriterGroup Test");
  688. writerGroupConfig.publishingInterval = PUBLISH_INTERVAL;
  689. writerGroupConfig.enabled = UA_FALSE;
  690. writerGroupConfig.writerGroupId = WRITER_GROUP_ID;
  691. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  692. retVal |= UA_Server_addWriterGroup(server, connection_test, &writerGroupConfig, &writerGroup);
  693. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  694. /* DataSetWriter */
  695. UA_DataSetWriterConfig dataSetWriterConfig;
  696. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  697. dataSetWriterConfig.name = UA_STRING("DataSetWriter Test");
  698. dataSetWriterConfig.dataSetWriterId = DATASET_WRITER_ID;
  699. dataSetWriterConfig.keyFrameCount = 10;
  700. retVal |= UA_Server_addDataSetWriter(server, writerGroup, publishedDataSetTest, &dataSetWriterConfig, &dataSetWriter);
  701. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  702. /* Reader Group */
  703. UA_ReaderGroupConfig readerGroupConfig;
  704. memset (&readerGroupConfig, 0, sizeof (UA_ReaderGroupConfig));
  705. readerGroupConfig.name = UA_STRING ("ReaderGroup Test");
  706. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &readerGroupTest);
  707. /* Data Set Reader */
  708. /* Parameters to filter received NetworkMessage */
  709. memset (&readerConfig, 0, sizeof (UA_DataSetReaderConfig));
  710. readerConfig.name = UA_STRING ("DataSetReader Test");
  711. readerConfig.dataSetWriterId = DATASET_WRITER_ID;
  712. /* Setting up Meta data configuration in DataSetReader */
  713. UA_DataSetMetaDataType *pMetaData = &readerConfig.dataSetMetaData;
  714. /* FilltestMetadata function in subscriber implementation */
  715. UA_DataSetMetaDataType_init (pMetaData);
  716. pMetaData->name = UA_STRING ("DataSet Test");
  717. /* Static definition of number of fields size to 1 to create one
  718. targetVariable */
  719. pMetaData->fieldsSize = 1;
  720. pMetaData->fields = (UA_FieldMetaData*)UA_Array_new (pMetaData->fieldsSize,
  721. &UA_TYPES[UA_TYPES_FIELDMETADATA]);
  722. /* Unsigned Integer DataType */
  723. UA_FieldMetaData_init (&pMetaData->fields[0]);
  724. UA_NodeId_copy (&UA_TYPES[UA_TYPES_INT64].typeId,
  725. &pMetaData->fields[0].dataType);
  726. pMetaData->fields[0].builtInType = UA_NS0ID_INT64;
  727. pMetaData->fields[0].valueRank = -1; /* scalar */
  728. retVal |= UA_Server_addDataSetReader(server, readerGroupTest, &readerConfig,
  729. &readerIdentifier);
  730. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  731. /* Add Subscribed Variables */
  732. UA_NodeId folderId;
  733. UA_NodeId newnodeId;
  734. UA_String folderName = readerConfig.dataSetMetaData.name;
  735. UA_ObjectAttributes oAttr = UA_ObjectAttributes_default;
  736. UA_QualifiedName folderBrowseName;
  737. if (folderName.length > 0) {
  738. oAttr.displayName.locale = UA_STRING ("en-US");
  739. oAttr.displayName.text = folderName;
  740. folderBrowseName.namespaceIndex = 1;
  741. folderBrowseName.name = folderName;
  742. }
  743. else {
  744. oAttr.displayName = UA_LOCALIZEDTEXT ("en-US", "Subscribed Variables");
  745. folderBrowseName = UA_QUALIFIEDNAME (1, "Subscribed Variables");
  746. }
  747. retVal = UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, SUBSCRIBEOBJECT_NODEID),
  748. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  749. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  750. folderBrowseName, UA_NODEID_NUMERIC(0,
  751. UA_NS0ID_BASEOBJECTTYPE), oAttr, NULL, &folderId);
  752. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  753. /* Variable to subscribe data */
  754. UA_VariableAttributes vAttr = UA_VariableAttributes_default;
  755. vAttr.description = UA_LOCALIZEDTEXT ("en-US", "Subscribed Int64");
  756. vAttr.displayName = UA_LOCALIZEDTEXT ("en-US", "Subscribed Int64");
  757. vAttr.dataType = UA_TYPES[UA_TYPES_INT64].typeId;
  758. retVal = UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, SUBSCRIBEVARIABLE_NODEID),
  759. UA_NODEID_NUMERIC(1, SUBSCRIBEOBJECT_NODEID),
  760. UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT), UA_QUALIFIEDNAME(1, "Subscribed Int64"),
  761. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE), vAttr, NULL, &newnodeId);
  762. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  763. UA_TargetVariablesDataType targetVars;
  764. targetVars.targetVariablesSize = 1;
  765. targetVars.targetVariables = (UA_FieldTargetDataType *)
  766. UA_calloc(targetVars.targetVariablesSize,
  767. sizeof(UA_FieldTargetDataType));
  768. /* For creating Targetvariable */
  769. UA_FieldTargetDataType_init(&targetVars.targetVariables[0]);
  770. targetVars.targetVariables[0].attributeId = UA_ATTRIBUTEID_VALUE;
  771. targetVars.targetVariables[0].targetNodeId = newnodeId;
  772. retVal |= UA_Server_DataSetReader_createTargetVariables(server, readerIdentifier,
  773. &targetVars);
  774. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  775. UA_TargetVariablesDataType_deleteMembers(&targetVars);
  776. UA_free(pMetaData->fields);
  777. /* run server - publisher and subscriber */
  778. UA_Server_run_iterate(server,true);
  779. /* Read data sent by the Publisher */
  780. UA_Variant *publishedNodeData = UA_Variant_new();
  781. retVal = UA_Server_readValue(server, UA_NODEID_NUMERIC(1, PUBLISHVARIABLE_NODEID), publishedNodeData);
  782. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  783. /* Read data received by the Subscriber */
  784. UA_Variant *subscribedNodeData = UA_Variant_new();
  785. retVal = UA_Server_readValue(server, UA_NODEID_NUMERIC(1, SUBSCRIBEVARIABLE_NODEID), subscribedNodeData);
  786. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  787. /* Check if data sent from Publisher is being received by Subscriber */
  788. ck_assert_int_eq(*(UA_Int64 *)publishedNodeData->data, *(UA_Int64 *)subscribedNodeData->data);
  789. UA_Variant_delete(subscribedNodeData);
  790. UA_Variant_delete(publishedNodeData);
  791. } END_TEST
  792. START_TEST(SinglePublishSubscribeBool) {
  793. /* To check status after running both publisher and subscriber */
  794. UA_StatusCode retVal = UA_STATUSCODE_GOOD;
  795. UA_PublishedDataSetConfig pdsConfig;
  796. UA_NodeId dataSetWriter;
  797. UA_NodeId readerIdentifier;
  798. UA_NodeId writerGroup;
  799. UA_DataSetReaderConfig readerConfig;
  800. /* Published DataSet */
  801. memset(&pdsConfig, 0, sizeof(UA_PublishedDataSetConfig));
  802. pdsConfig.publishedDataSetType = UA_PUBSUB_DATASET_PUBLISHEDITEMS;
  803. pdsConfig.name = UA_STRING("PublishedDataSet Test");
  804. UA_Server_addPublishedDataSet(server, &pdsConfig, &publishedDataSetTest);
  805. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  806. /* Create variable to publish boolean data */
  807. UA_NodeId publisherNode;
  808. UA_VariableAttributes attr = UA_VariableAttributes_default;
  809. attr.description = UA_LOCALIZEDTEXT("en-US","Published Bool");
  810. attr.displayName = UA_LOCALIZEDTEXT("en-US","Published Bool");
  811. attr.dataType = UA_TYPES[UA_TYPES_BOOLEAN].typeId;
  812. UA_Boolean publisherData = UA_FALSE;
  813. UA_Variant_setScalar(&attr.value, &publisherData, &UA_TYPES[UA_TYPES_BOOLEAN]);
  814. retVal = UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, PUBLISHVARIABLE_NODEID),
  815. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  816. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  817. UA_QUALIFIEDNAME(1, "Published Bool"),
  818. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE),
  819. attr, NULL, &publisherNode);
  820. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  821. /* Data Set Field */
  822. UA_NodeId dataSetFieldIdent;
  823. UA_DataSetFieldConfig dataSetFieldConfig;
  824. memset(&dataSetFieldConfig, 0, sizeof(UA_DataSetFieldConfig));
  825. dataSetFieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
  826. dataSetFieldConfig.field.variable.fieldNameAlias = UA_STRING("Published Bool");
  827. dataSetFieldConfig.field.variable.promotedField = UA_FALSE;
  828. dataSetFieldConfig.field.variable.publishParameters.publishedVariable = publisherNode;
  829. dataSetFieldConfig.field.variable.publishParameters.attributeId = UA_ATTRIBUTEID_VALUE;
  830. UA_Server_addDataSetField (server, publishedDataSetTest, &dataSetFieldConfig, &dataSetFieldIdent);
  831. /* Writer group */
  832. UA_WriterGroupConfig writerGroupConfig;
  833. memset(&writerGroupConfig, 0, sizeof(writerGroupConfig));
  834. writerGroupConfig.name = UA_STRING("WriterGroup Test");
  835. writerGroupConfig.publishingInterval = PUBLISH_INTERVAL;
  836. writerGroupConfig.enabled = UA_FALSE;
  837. writerGroupConfig.writerGroupId = WRITER_GROUP_ID;
  838. writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
  839. retVal |= UA_Server_addWriterGroup(server, connection_test, &writerGroupConfig, &writerGroup);
  840. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  841. /* DataSetWriter */
  842. UA_DataSetWriterConfig dataSetWriterConfig;
  843. memset(&dataSetWriterConfig, 0, sizeof(dataSetWriterConfig));
  844. dataSetWriterConfig.name = UA_STRING("DataSetWriter Test");
  845. dataSetWriterConfig.dataSetWriterId = DATASET_WRITER_ID;
  846. dataSetWriterConfig.keyFrameCount = 10;
  847. retVal |= UA_Server_addDataSetWriter(server, writerGroup, publishedDataSetTest, &dataSetWriterConfig, &dataSetWriter);
  848. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  849. /* Reader Group */
  850. UA_ReaderGroupConfig readerGroupConfig;
  851. memset (&readerGroupConfig, 0, sizeof (UA_ReaderGroupConfig));
  852. readerGroupConfig.name = UA_STRING ("ReaderGroup Test");
  853. retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &readerGroupTest);
  854. /* Data Set Reader */
  855. /* Parameters to filter received NetworkMessage */
  856. memset (&readerConfig, 0, sizeof (UA_DataSetReaderConfig));
  857. readerConfig.name = UA_STRING ("DataSetReader Test");
  858. readerConfig.dataSetWriterId = DATASET_WRITER_ID;
  859. /* Setting up Meta data configuration in DataSetReader */
  860. UA_DataSetMetaDataType *pMetaData = &readerConfig.dataSetMetaData;
  861. /* FilltestMetadata function in subscriber implementation */
  862. UA_DataSetMetaDataType_init (pMetaData);
  863. pMetaData->name = UA_STRING ("DataSet Test");
  864. /* Static definition of number of fields size to 1 to create one
  865. targetVariable */
  866. pMetaData->fieldsSize = 1;
  867. pMetaData->fields = (UA_FieldMetaData*)UA_Array_new (pMetaData->fieldsSize,
  868. &UA_TYPES[UA_TYPES_FIELDMETADATA]);
  869. /* Boolean DataType */
  870. UA_FieldMetaData_init (&pMetaData->fields[0]);
  871. UA_NodeId_copy (&UA_TYPES[UA_TYPES_BOOLEAN].typeId,
  872. &pMetaData->fields[0].dataType);
  873. pMetaData->fields[0].builtInType = UA_NS0ID_BOOLEAN;
  874. pMetaData->fields[0].valueRank = -1; /* scalar */
  875. retVal |= UA_Server_addDataSetReader(server, readerGroupTest, &readerConfig,
  876. &readerIdentifier);
  877. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  878. /* Add Subscribed Variables */
  879. UA_NodeId folderId;
  880. UA_NodeId newnodeId;
  881. UA_String folderName = readerConfig.dataSetMetaData.name;
  882. UA_ObjectAttributes oAttr = UA_ObjectAttributes_default;
  883. UA_QualifiedName folderBrowseName;
  884. if (folderName.length > 0) {
  885. oAttr.displayName.locale = UA_STRING ("en-US");
  886. oAttr.displayName.text = folderName;
  887. folderBrowseName.namespaceIndex = 1;
  888. folderBrowseName.name = folderName;
  889. }
  890. else {
  891. oAttr.displayName = UA_LOCALIZEDTEXT ("en-US", "Subscribed Variables");
  892. folderBrowseName = UA_QUALIFIEDNAME (1, "Subscribed Variables");
  893. }
  894. retVal = UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, SUBSCRIBEOBJECT_NODEID),
  895. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  896. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  897. folderBrowseName, UA_NODEID_NUMERIC(0,
  898. UA_NS0ID_BASEOBJECTTYPE), oAttr, NULL, &folderId);
  899. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  900. /* Variable to subscribe data */
  901. UA_VariableAttributes vAttr = UA_VariableAttributes_default;
  902. vAttr.description = UA_LOCALIZEDTEXT ("en-US", "Subscribed Bool");
  903. vAttr.displayName = UA_LOCALIZEDTEXT ("en-US", "Subscribed Bool");
  904. vAttr.dataType = UA_TYPES[UA_TYPES_BOOLEAN].typeId;
  905. retVal = UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, SUBSCRIBEVARIABLE_NODEID),
  906. UA_NODEID_NUMERIC(1, SUBSCRIBEOBJECT_NODEID),
  907. UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT), UA_QUALIFIEDNAME(1, "Subscribed Bool"),
  908. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE), vAttr, NULL, &newnodeId);
  909. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  910. UA_TargetVariablesDataType targetVars;
  911. targetVars.targetVariablesSize = 1;
  912. targetVars.targetVariables = (UA_FieldTargetDataType *)
  913. UA_calloc(targetVars.targetVariablesSize,
  914. sizeof(UA_FieldTargetDataType));
  915. /* For creating Targetvariable */
  916. UA_FieldTargetDataType_init(&targetVars.targetVariables[0]);
  917. targetVars.targetVariables[0].attributeId = UA_ATTRIBUTEID_VALUE;
  918. targetVars.targetVariables[0].targetNodeId = newnodeId;
  919. retVal |= UA_Server_DataSetReader_createTargetVariables(server, readerIdentifier,
  920. &targetVars);
  921. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  922. UA_TargetVariablesDataType_deleteMembers(&targetVars);
  923. UA_free(pMetaData->fields);
  924. /* run server - publisher and subscriber */
  925. UA_Server_run_iterate(server,true);
  926. /* Read data sent by the Publisher */
  927. UA_Variant *publishedNodeData = UA_Variant_new();
  928. retVal = UA_Server_readValue(server, UA_NODEID_NUMERIC(1, PUBLISHVARIABLE_NODEID), publishedNodeData);
  929. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  930. /* Read data received by the Subscriber */
  931. UA_Variant *subscribedNodeData = UA_Variant_new();
  932. retVal = UA_Server_readValue(server, UA_NODEID_NUMERIC(1, SUBSCRIBEVARIABLE_NODEID), subscribedNodeData);
  933. ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD);
  934. /* Check if data sent from Publisher is being received by Subscriber */
  935. ck_assert_int_eq(*(UA_Boolean *)publishedNodeData->data, *(UA_Boolean *)subscribedNodeData->data);
  936. UA_Variant_delete(subscribedNodeData);
  937. UA_Variant_delete(publishedNodeData);
  938. } END_TEST
  939. int main(void) {
  940. TCase *tc_add_pubsub_readergroup = tcase_create("PubSub readerGroup items handling");
  941. tcase_add_checked_fixture(tc_add_pubsub_readergroup, setup, teardown);
  942. /* Test cases for ReaderGroup functionality */
  943. tcase_add_test(tc_add_pubsub_readergroup, AddReaderGroupWithValidConfiguration);
  944. tcase_add_test(tc_add_pubsub_readergroup, AddReaderGroupWithNullConfig);
  945. tcase_add_test(tc_add_pubsub_readergroup, AddReaderGroupWithInvalidConnectionId);
  946. tcase_add_test(tc_add_pubsub_readergroup, RemoveReaderGroupWithInvalidIdentifier);
  947. tcase_add_test(tc_add_pubsub_readergroup, UpdateReaderGroupWithInvalidIdentifier);
  948. tcase_add_test(tc_add_pubsub_readergroup, GetReaderGroupConfigWithInvalidConfig);
  949. tcase_add_test(tc_add_pubsub_readergroup, GetReaderGroupConfigWithInvalidIdentifier);
  950. tcase_add_test(tc_add_pubsub_readergroup, GetReaderGroupConfigWithValidConfig);
  951. /* Test cases for DataSetReader functionality */
  952. tcase_add_test(tc_add_pubsub_readergroup, AddDataSetReaderWithValidConfiguration);
  953. tcase_add_test(tc_add_pubsub_readergroup, AddDataSetReaderWithNullConfig);
  954. tcase_add_test(tc_add_pubsub_readergroup, RemoveDataSetReaderWithValidConfiguration);
  955. tcase_add_test(tc_add_pubsub_readergroup, RemoveDataSetReaderWithInvalidIdentifier);
  956. tcase_add_test(tc_add_pubsub_readergroup, UpdateDataSetReaderConfigWithInvalidId);
  957. tcase_add_test(tc_add_pubsub_readergroup, GetDataSetReaderConfigWithValidConfiguration);
  958. tcase_add_test(tc_add_pubsub_readergroup, GetDataSetReaderConfigWithInvalidConfiguration);
  959. tcase_add_test(tc_add_pubsub_readergroup, GetDataSetReaderConfigWithInvalidIdentifier);
  960. tcase_add_test(tc_add_pubsub_readergroup, CreateTargetVariableWithInvalidConfiguration);
  961. tcase_add_test(tc_add_pubsub_readergroup, AddTargetVariableWithInvalidConfiguration);
  962. tcase_add_test(tc_add_pubsub_readergroup, AddTargetVariableWithValidConfiguration);
  963. /*Test case to run both publisher and subscriber */
  964. TCase *tc_pubsub_publish_subscribe = tcase_create("Publisher publishing and Subscriber subscribing");
  965. tcase_add_checked_fixture(tc_pubsub_publish_subscribe, setup, teardown);
  966. tcase_add_test(tc_pubsub_publish_subscribe, SinglePublishSubscribeDateTime);
  967. tcase_add_test(tc_pubsub_publish_subscribe, SinglePublishSubscribeInt32);
  968. tcase_add_test(tc_pubsub_publish_subscribe, SinglePublishSubscribeInt64);
  969. tcase_add_test(tc_pubsub_publish_subscribe, SinglePublishSubscribeBool);
  970. Suite *suite = suite_create("PubSub readerGroups/reader/Fields handling and publishing");
  971. suite_add_tcase(suite, tc_add_pubsub_readergroup);
  972. suite_add_tcase(suite, tc_pubsub_publish_subscribe);
  973. SRunner *suiteRunner = srunner_create(suite);
  974. srunner_set_fork_status(suiteRunner, CK_NOFORK);
  975. srunner_run_all(suiteRunner,CK_NORMAL);
  976. int number_failed = srunner_ntests_failed(suiteRunner);
  977. srunner_free(suiteRunner);
  978. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  979. }