check_services_attributes.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include "check.h"
  5. #include "server/ua_nodestore.h"
  6. #include "server/ua_services.h"
  7. #include "ua_client.h"
  8. #include "ua_nodeids.h"
  9. #include "ua_statuscodes.h"
  10. #include "ua_types.h"
  11. #include "ua_util.h"
  12. #include "server/ua_server_internal.h"
  13. #ifdef UA_MULTITHREADING
  14. #include <pthread.h>
  15. #include <urcu.h>
  16. #endif
  17. static UA_Server* makeTestSequence(void) {
  18. UA_Server *server = UA_Server_new(UA_ServerConfig_standard);
  19. /* VariableNode */
  20. UA_VariableAttributes vattr;
  21. UA_VariableAttributes_init(&vattr);
  22. UA_Int32 myInteger = 42;
  23. UA_Variant_setScalarCopy(&vattr.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
  24. vattr.description = UA_LOCALIZEDTEXT("locale","the answer");
  25. vattr.displayName = UA_LOCALIZEDTEXT("locale","the answer");
  26. vattr.valueRank = -2;
  27. const UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, "the answer");
  28. const UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "the.answer");
  29. UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
  30. UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
  31. UA_Server_addVariableNode(server, myIntegerNodeId, parentNodeId,
  32. parentReferenceNodeId, myIntegerName,
  33. UA_NODEID_NULL, vattr, NULL);
  34. /* ObjectNode */
  35. UA_ObjectAttributes obj_attr;
  36. UA_ObjectAttributes_init(&obj_attr);
  37. obj_attr.description = UA_LOCALIZEDTEXT("en_US","Demo");
  38. obj_attr.displayName = UA_LOCALIZEDTEXT("en_US","Demo");
  39. UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, 50),
  40. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  41. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  42. UA_QUALIFIEDNAME(1, "Demo"),
  43. UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE),
  44. obj_attr, NULL);
  45. /* ViewNode */
  46. UA_ViewAttributes view_attr;
  47. UA_ViewAttributes_init(&view_attr);
  48. view_attr.description = UA_LOCALIZEDTEXT("en_US", "Viewtest");
  49. view_attr.displayName = UA_LOCALIZEDTEXT("en_US", "Viewtest");
  50. UA_Server_addViewNode(server, UA_NODEID_NUMERIC(0, UA_NS0ID_VIEWNODE),
  51. UA_NODEID_NUMERIC(0, UA_NS0ID_VIEWSFOLDER),
  52. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  53. UA_QUALIFIEDNAME_ALLOC(0, "Viewtest"), view_attr, NULL);
  54. #ifdef ENABLE_METHODCALLS
  55. /* MethodNode */
  56. UA_MethodAttributes ma;
  57. UA_MethodAttributes_init(&ma);
  58. ma.description = UA_LOCALIZEDTEXT("en_US", "Methodtest");
  59. ma.displayName = UA_LOCALIZEDTEXT("en_US", "Methodtest");
  60. UA_Server_addMethodNode(server, UA_NODEID_NUMERIC(0, UA_NS0ID_METHODNODE),
  61. UA_NODEID_NUMERIC(0, 3),
  62. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  63. UA_QUALIFIEDNAME_ALLOC(0, "Methodtest"), ma,
  64. NULL, NULL, -1, NULL, -1, NULL, NULL);
  65. #endif
  66. return server;
  67. }
  68. static UA_VariableNode* makeCompareSequence(void) {
  69. UA_VariableNode *node = UA_VariableNode_new();
  70. UA_Variant *myIntegerVariant = UA_Variant_new();
  71. UA_Int32 myInteger = 42;
  72. UA_Variant_setScalarCopy(myIntegerVariant, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
  73. const UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, "the answer");
  74. const UA_LocalizedText myIntegerDisplName = UA_LOCALIZEDTEXT("locale", "the answer");
  75. const UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "the.answer");
  76. UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
  77. //UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
  78. node->value.variant.value = *myIntegerVariant;
  79. UA_NodeId_copy(&myIntegerNodeId,&node->nodeId);
  80. UA_QualifiedName_copy(&myIntegerName,&node->browseName);
  81. UA_LocalizedText_copy(&myIntegerDisplName, &node->displayName);
  82. UA_LocalizedText_copy(&myIntegerDisplName, &node->description);
  83. UA_ExpandedNodeId parentId;
  84. UA_ExpandedNodeId_init(&parentId);
  85. UA_NodeId_copy(&parentNodeId,&parentId.nodeId);
  86. return node;
  87. }
  88. START_TEST(ReadSingleAttributeValueWithoutTimestamp) {
  89. UA_Server *server = makeTestSequence();
  90. UA_DataValue resp;
  91. UA_DataValue_init(&resp);
  92. UA_ReadRequest rReq;
  93. UA_ReadRequest_init(&rReq);
  94. rReq.nodesToRead = UA_ReadValueId_new();
  95. rReq.nodesToReadSize = 1;
  96. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  97. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_VALUE;
  98. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  99. ck_assert_int_eq(-1, resp.value.arrayLength);
  100. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_INT32], resp.value.type);
  101. ck_assert_int_eq(42, *(UA_Int32* )resp.value.data);
  102. UA_Server_delete(server);
  103. UA_ReadRequest_deleteMembers(&rReq);
  104. UA_DataValue_deleteMembers(&resp);
  105. } END_TEST
  106. START_TEST(ReadSingleAttributeNodeIdWithoutTimestamp) {
  107. UA_Server *server = makeTestSequence();
  108. UA_DataValue resp;
  109. UA_DataValue_init(&resp);
  110. UA_ReadRequest rReq;
  111. UA_ReadRequest_init(&rReq);
  112. rReq.nodesToRead = UA_ReadValueId_new();
  113. rReq.nodesToReadSize = 1;
  114. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  115. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_NODEID;
  116. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  117. const UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "the.answer");
  118. ck_assert_int_eq(-1, resp.value.arrayLength);
  119. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_NODEID], resp.value.type);
  120. UA_NodeId* respval = (UA_NodeId*) resp.value.data;
  121. ck_assert_int_eq(1, respval->namespaceIndex);
  122. ck_assert(UA_String_equal(&myIntegerNodeId.identifier.string, &respval->identifier.string));
  123. UA_ReadRequest_deleteMembers(&rReq);
  124. UA_DataValue_deleteMembers(&resp);
  125. UA_Server_delete(server);
  126. } END_TEST
  127. START_TEST(ReadSingleAttributeNodeClassWithoutTimestamp) {
  128. UA_Server *server = makeTestSequence();
  129. UA_DataValue resp;
  130. UA_DataValue_init(&resp);
  131. UA_ReadRequest rReq;
  132. UA_ReadRequest_init(&rReq);
  133. rReq.nodesToRead = UA_ReadValueId_new();
  134. rReq.nodesToReadSize = 1;
  135. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  136. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_NODECLASS;
  137. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  138. ck_assert_int_eq(-1, resp.value.arrayLength);
  139. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_INT32],resp.value.type);
  140. ck_assert_int_eq(*(UA_Int32*)resp.value.data,UA_NODECLASS_VARIABLE);
  141. UA_ReadRequest_deleteMembers(&rReq);
  142. UA_DataValue_deleteMembers(&resp);
  143. UA_Server_delete(server);
  144. } END_TEST
  145. START_TEST(ReadSingleAttributeBrowseNameWithoutTimestamp) {
  146. UA_Server *server = makeTestSequence();
  147. UA_DataValue resp;
  148. UA_DataValue_init(&resp);
  149. UA_ReadRequest rReq;
  150. UA_ReadRequest_init(&rReq);
  151. rReq.nodesToRead = UA_ReadValueId_new();
  152. rReq.nodesToReadSize = 1;
  153. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  154. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_BROWSENAME;
  155. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  156. UA_QualifiedName* respval = (UA_QualifiedName*) resp.value.data;
  157. const UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, "the answer");
  158. ck_assert_int_eq(-1, resp.value.arrayLength);
  159. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_QUALIFIEDNAME], resp.value.type);
  160. ck_assert_int_eq(1, respval->namespaceIndex);
  161. ck_assert(UA_String_equal(&myIntegerName.name, &respval->name));
  162. UA_ReadRequest_deleteMembers(&rReq);
  163. UA_DataValue_deleteMembers(&resp);
  164. UA_Server_delete(server);
  165. } END_TEST
  166. START_TEST(ReadSingleAttributeDisplayNameWithoutTimestamp) {
  167. UA_Server *server = makeTestSequence();
  168. UA_DataValue resp;
  169. UA_DataValue_init(&resp);
  170. UA_ReadRequest rReq;
  171. UA_ReadRequest_init(&rReq);
  172. rReq.nodesToRead = UA_ReadValueId_new();
  173. rReq.nodesToReadSize = 1;
  174. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  175. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_DISPLAYNAME;
  176. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  177. UA_LocalizedText* respval = (UA_LocalizedText*) resp.value.data;
  178. const UA_LocalizedText comp = UA_LOCALIZEDTEXT("locale", "the answer");
  179. UA_VariableNode* compNode = makeCompareSequence();
  180. ck_assert_int_eq(-1, resp.value.arrayLength);
  181. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_LOCALIZEDTEXT], resp.value.type);
  182. ck_assert(UA_String_equal(&comp.text, &respval->text));
  183. ck_assert(UA_String_equal(&compNode->displayName.locale, &respval->locale));
  184. UA_Server_delete(server);
  185. UA_ReadRequest_deleteMembers(&rReq);
  186. UA_DataValue_deleteMembers(&resp);
  187. UA_VariableNode_delete(compNode);
  188. } END_TEST
  189. START_TEST(ReadSingleAttributeDescriptionWithoutTimestamp) {
  190. UA_Server *server = makeTestSequence();
  191. UA_DataValue resp;
  192. UA_DataValue_init(&resp);
  193. UA_ReadRequest rReq;
  194. UA_ReadRequest_init(&rReq);
  195. rReq.nodesToRead = UA_ReadValueId_new();
  196. rReq.nodesToReadSize = 1;
  197. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  198. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_DESCRIPTION;
  199. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  200. UA_LocalizedText* respval = (UA_LocalizedText*) resp.value.data;
  201. UA_VariableNode* compNode = makeCompareSequence();
  202. ck_assert_int_eq(-1, resp.value.arrayLength);
  203. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_LOCALIZEDTEXT], resp.value.type);
  204. ck_assert(UA_String_equal(&compNode->description.locale, &respval->locale));
  205. ck_assert(UA_String_equal(&compNode->description.text, &respval->text));
  206. UA_ReadRequest_deleteMembers(&rReq);
  207. UA_DataValue_deleteMembers(&resp);
  208. UA_VariableNode_delete(compNode);
  209. UA_Server_delete(server);
  210. } END_TEST
  211. START_TEST(ReadSingleAttributeWriteMaskWithoutTimestamp) {
  212. UA_Server *server = makeTestSequence();
  213. UA_DataValue resp;
  214. UA_DataValue_init(&resp);
  215. UA_ReadRequest rReq;
  216. UA_ReadRequest_init(&rReq);
  217. rReq.nodesToRead = UA_ReadValueId_new();
  218. rReq.nodesToReadSize = 1;
  219. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  220. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_WRITEMASK;
  221. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  222. UA_UInt32* respval = (UA_UInt32*) resp.value.data;
  223. ck_assert_int_eq(-1, resp.value.arrayLength);
  224. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_UINT32], resp.value.type);
  225. ck_assert_int_eq(0,*respval);
  226. UA_ReadRequest_deleteMembers(&rReq);
  227. UA_DataValue_deleteMembers(&resp);
  228. UA_Server_delete(server);
  229. } END_TEST
  230. START_TEST(ReadSingleAttributeUserWriteMaskWithoutTimestamp) {
  231. UA_Server *server = makeTestSequence();
  232. UA_DataValue resp;
  233. UA_DataValue_init(&resp);
  234. UA_ReadRequest rReq;
  235. UA_ReadRequest_init(&rReq);
  236. rReq.nodesToRead = UA_ReadValueId_new();
  237. rReq.nodesToReadSize = 1;
  238. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  239. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_USERWRITEMASK;
  240. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  241. UA_UInt32* respval = (UA_UInt32*) resp.value.data;
  242. ck_assert_int_eq(-1, resp.value.arrayLength);
  243. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_UINT32], resp.value.type);
  244. ck_assert_int_eq(0,*respval);
  245. UA_ReadRequest_deleteMembers(&rReq);
  246. UA_DataValue_deleteMembers(&resp);
  247. UA_Server_delete(server);
  248. } END_TEST
  249. START_TEST(ReadSingleAttributeIsAbstractWithoutTimestamp) {
  250. UA_Server *server = makeTestSequence();
  251. UA_DataValue resp;
  252. UA_DataValue_init(&resp);
  253. UA_ReadRequest rReq;
  254. UA_ReadRequest_init(&rReq);
  255. rReq.nodesToRead = UA_ReadValueId_new();
  256. rReq.nodesToReadSize = 1;
  257. rReq.nodesToRead[0].nodeId.identifier.numeric = UA_NS0ID_ORGANIZES;
  258. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_ISABSTRACT;
  259. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  260. ck_assert_int_eq(-1, resp.value.arrayLength);
  261. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BOOLEAN], resp.value.type);
  262. ck_assert(*(UA_Boolean* )resp.value.data==UA_FALSE);
  263. UA_ReadRequest_deleteMembers(&rReq);
  264. UA_DataValue_deleteMembers(&resp);
  265. UA_Server_delete(server);
  266. } END_TEST
  267. START_TEST(ReadSingleAttributeSymmetricWithoutTimestamp) {
  268. UA_Server *server = makeTestSequence();
  269. UA_DataValue resp;
  270. UA_DataValue_init(&resp);
  271. UA_ReadRequest rReq;
  272. UA_ReadRequest_init(&rReq);
  273. rReq.nodesToRead = UA_ReadValueId_new();
  274. rReq.nodesToReadSize = 1;
  275. rReq.nodesToRead[0].nodeId.identifier.numeric = UA_NS0ID_ORGANIZES;
  276. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_SYMMETRIC;
  277. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  278. ck_assert_int_eq(-1, resp.value.arrayLength);
  279. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BOOLEAN], resp.value.type);
  280. ck_assert(*(UA_Boolean* )resp.value.data==UA_FALSE);
  281. UA_ReadRequest_deleteMembers(&rReq);
  282. UA_DataValue_deleteMembers(&resp);
  283. UA_Server_delete(server);
  284. } END_TEST
  285. START_TEST(ReadSingleAttributeInverseNameWithoutTimestamp) {
  286. UA_Server *server = makeTestSequence();
  287. UA_DataValue resp;
  288. UA_DataValue_init(&resp);
  289. UA_ReadRequest rReq;
  290. UA_ReadRequest_init(&rReq);
  291. rReq.nodesToRead = UA_ReadValueId_new();
  292. rReq.nodesToReadSize = 1;
  293. rReq.nodesToRead[0].nodeId.identifier.numeric = UA_NS0ID_ORGANIZES;
  294. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_INVERSENAME;
  295. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  296. UA_LocalizedText* respval = (UA_LocalizedText*) resp.value.data;
  297. const UA_LocalizedText comp = UA_LOCALIZEDTEXT("en_US", "OrganizedBy");
  298. ck_assert_int_eq(-1, resp.value.arrayLength);
  299. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_LOCALIZEDTEXT],resp.value.type);
  300. ck_assert(UA_String_equal(&comp.text, &respval->text));
  301. ck_assert(UA_String_equal(&comp.locale, &respval->locale));
  302. UA_ReadRequest_deleteMembers(&rReq);
  303. UA_DataValue_deleteMembers(&resp);
  304. UA_Server_delete(server);
  305. } END_TEST
  306. START_TEST(ReadSingleAttributeContainsNoLoopsWithoutTimestamp) {
  307. UA_Server *server = makeTestSequence();
  308. UA_DataValue resp;
  309. UA_DataValue_init(&resp);
  310. UA_ReadRequest rReq;
  311. UA_ReadRequest_init(&rReq);
  312. rReq.nodesToRead = UA_ReadValueId_new();
  313. rReq.nodesToReadSize = 1;
  314. rReq.nodesToRead[0].nodeId.identifier.numeric = UA_NS0ID_VIEWNODE;
  315. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_CONTAINSNOLOOPS;
  316. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  317. ck_assert_int_eq(-1, resp.value.arrayLength);
  318. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BOOLEAN], resp.value.type);
  319. ck_assert(*(UA_Boolean* )resp.value.data==UA_FALSE);
  320. UA_ReadRequest_deleteMembers(&rReq);
  321. UA_DataValue_deleteMembers(&resp);
  322. UA_Server_delete(server);
  323. } END_TEST
  324. START_TEST(ReadSingleAttributeEventNotifierWithoutTimestamp) {
  325. UA_Server *server = makeTestSequence();
  326. UA_DataValue resp;
  327. UA_DataValue_init(&resp);
  328. UA_ReadRequest rReq;
  329. UA_ReadRequest_init(&rReq);
  330. rReq.nodesToRead = UA_ReadValueId_new();
  331. rReq.nodesToReadSize = 1;
  332. rReq.nodesToRead[0].nodeId = UA_NODEID_NUMERIC(1, 50);
  333. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_EVENTNOTIFIER;
  334. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  335. ck_assert_int_eq(UA_STATUSCODE_GOOD, resp.status);
  336. ck_assert_int_eq(-1, resp.value.arrayLength);
  337. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BYTE],resp.value.type);
  338. ck_assert_int_eq(*(UA_Byte*)resp.value.data, 0);
  339. UA_ReadRequest_deleteMembers(&rReq);
  340. UA_DataValue_deleteMembers(&resp);
  341. UA_Server_delete(server);
  342. } END_TEST
  343. START_TEST(ReadSingleAttributeDataTypeWithoutTimestamp) {
  344. UA_Server *server = makeTestSequence();
  345. UA_DataValue resp;
  346. UA_DataValue_init(&resp);
  347. UA_ReadRequest rReq;
  348. UA_ReadRequest_init(&rReq);
  349. rReq.nodesToRead = UA_ReadValueId_new();
  350. rReq.nodesToReadSize = 1;
  351. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  352. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_DATATYPE;
  353. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  354. UA_NodeId* respval = (UA_NodeId*) resp.value.data;
  355. ck_assert_int_eq(-1, resp.value.arrayLength);
  356. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_NODEID], resp.value.type);
  357. ck_assert_int_eq(respval->namespaceIndex,0);
  358. ck_assert_int_eq(respval->identifier.numeric,UA_NS0ID_INT32);
  359. UA_ReadRequest_deleteMembers(&rReq);
  360. UA_DataValue_deleteMembers(&resp);
  361. UA_Server_delete(server);
  362. } END_TEST
  363. START_TEST(ReadSingleAttributeValueRankWithoutTimestamp) {
  364. UA_Server *server = makeTestSequence();
  365. UA_DataValue resp;
  366. UA_DataValue_init(&resp);
  367. UA_ReadRequest rReq;
  368. UA_ReadRequest_init(&rReq);
  369. rReq.nodesToRead = UA_ReadValueId_new();
  370. rReq.nodesToReadSize = 1;
  371. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  372. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_VALUERANK;
  373. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  374. ck_assert_int_eq(-1, resp.value.arrayLength);
  375. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_INT32], resp.value.type);
  376. ck_assert_int_eq(-2, *(UA_Int32* )resp.value.data);
  377. UA_ReadRequest_deleteMembers(&rReq);
  378. UA_DataValue_deleteMembers(&resp);
  379. UA_Server_delete(server);
  380. } END_TEST
  381. START_TEST(ReadSingleAttributeArrayDimensionsWithoutTimestamp) {
  382. UA_Server *server = makeTestSequence();
  383. UA_DataValue resp;
  384. UA_DataValue_init(&resp);
  385. UA_ReadRequest rReq;
  386. UA_ReadRequest_init(&rReq);
  387. rReq.nodesToRead = UA_ReadValueId_new();
  388. rReq.nodesToReadSize = 1;
  389. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  390. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_ARRAYDIMENSIONS;
  391. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  392. ck_assert_int_eq(-1, resp.value.arrayLength);
  393. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_INT32], resp.value.type);
  394. ck_assert_ptr_eq((UA_Int32*)resp.value.data,0);
  395. UA_DataValue_deleteMembers(&resp);
  396. UA_ReadRequest_deleteMembers(&rReq);
  397. UA_Server_delete(server);
  398. } END_TEST
  399. START_TEST(ReadSingleAttributeAccessLevelWithoutTimestamp) {
  400. UA_Server *server = makeTestSequence();
  401. UA_DataValue resp;
  402. UA_DataValue_init(&resp);
  403. UA_ReadRequest rReq;
  404. UA_ReadRequest_init(&rReq);
  405. rReq.nodesToRead = UA_ReadValueId_new();
  406. rReq.nodesToReadSize = 1;
  407. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  408. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_ACCESSLEVEL;
  409. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  410. ck_assert_int_eq(-1, resp.value.arrayLength);
  411. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BYTE], resp.value.type);
  412. ck_assert_int_eq(*(UA_Byte*)resp.value.data, 0);
  413. UA_DataValue_deleteMembers(&resp);
  414. UA_ReadRequest_deleteMembers(&rReq);
  415. UA_Server_delete(server);
  416. } END_TEST
  417. START_TEST(ReadSingleAttributeUserAccessLevelWithoutTimestamp) {
  418. UA_Server *server = makeTestSequence();
  419. UA_DataValue resp;
  420. UA_DataValue_init(&resp);
  421. UA_ReadRequest rReq;
  422. UA_ReadRequest_init(&rReq);
  423. rReq.nodesToRead = UA_ReadValueId_new();
  424. rReq.nodesToReadSize = 1;
  425. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  426. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_USERACCESSLEVEL;
  427. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  428. UA_VariableNode* compNode = makeCompareSequence();
  429. ck_assert_int_eq(-1, resp.value.arrayLength);
  430. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BYTE], resp.value.type);
  431. ck_assert_int_eq(*(UA_Byte*)resp.value.data, compNode->userAccessLevel);
  432. UA_Server_delete(server);
  433. UA_DataValue_deleteMembers(&resp);
  434. UA_ReadRequest_deleteMembers(&rReq);
  435. UA_VariableNode_delete(compNode);
  436. } END_TEST
  437. START_TEST(ReadSingleAttributeMinimumSamplingIntervalWithoutTimestamp) {
  438. UA_Server *server = makeTestSequence();
  439. UA_DataValue resp;
  440. UA_DataValue_init(&resp);
  441. UA_ReadRequest rReq;
  442. UA_ReadRequest_init(&rReq);
  443. rReq.nodesToRead = UA_ReadValueId_new();
  444. rReq.nodesToReadSize = 1;
  445. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  446. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL;
  447. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  448. UA_Double* respval = (UA_Double*) resp.value.data;
  449. UA_VariableNode *compNode = makeCompareSequence();
  450. UA_Double comp = (UA_Double) compNode->minimumSamplingInterval;
  451. ck_assert_int_eq(-1, resp.value.arrayLength);
  452. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_DOUBLE], resp.value.type);
  453. ck_assert(*respval == comp);
  454. UA_DataValue_deleteMembers(&resp);
  455. UA_ReadRequest_deleteMembers(&rReq);
  456. UA_VariableNode_delete(compNode);
  457. UA_Server_delete(server);
  458. } END_TEST
  459. START_TEST(ReadSingleAttributeHistorizingWithoutTimestamp) {
  460. UA_Server *server = makeTestSequence();
  461. UA_DataValue resp;
  462. UA_DataValue_init(&resp);
  463. UA_ReadRequest rReq;
  464. UA_ReadRequest_init(&rReq);
  465. rReq.nodesToRead = UA_ReadValueId_new();
  466. rReq.nodesToReadSize = 1;
  467. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  468. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_HISTORIZING;
  469. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  470. ck_assert_int_eq(-1, resp.value.arrayLength);
  471. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BOOLEAN], resp.value.type);
  472. ck_assert(*(UA_Boolean*)resp.value.data==UA_FALSE);
  473. UA_ReadRequest_deleteMembers(&rReq);
  474. UA_DataValue_deleteMembers(&resp);
  475. UA_Server_delete(server);
  476. } END_TEST
  477. START_TEST(ReadSingleAttributeExecutableWithoutTimestamp) {
  478. #ifdef ENABLE_METHODCALLS
  479. UA_Server *server = makeTestSequence();
  480. UA_DataValue resp;
  481. UA_DataValue_init(&resp);
  482. UA_ReadRequest rReq;
  483. UA_ReadRequest_init(&rReq);
  484. rReq.nodesToRead = UA_ReadValueId_new();
  485. rReq.nodesToReadSize = 1;
  486. rReq.nodesToRead[0].nodeId.identifier.numeric = UA_NS0ID_METHODNODE;
  487. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_EXECUTABLE;
  488. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  489. ck_assert_int_eq(-1, resp.value.arrayLength);
  490. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BOOLEAN], resp.value.type);
  491. ck_assert(*(UA_Boolean*)resp.value.data==UA_FALSE);
  492. UA_DataValue_deleteMembers(&resp);
  493. UA_ReadRequest_deleteMembers(&rReq);
  494. UA_Server_delete(server);
  495. #endif
  496. } END_TEST
  497. START_TEST(ReadSingleAttributeUserExecutableWithoutTimestamp) {
  498. #ifdef ENABLE_METHODCALLS
  499. UA_Server *server = makeTestSequence();
  500. UA_DataValue resp;
  501. UA_DataValue_init(&resp);
  502. UA_ReadRequest rReq;
  503. UA_ReadRequest_init(&rReq);
  504. rReq.nodesToRead = UA_ReadValueId_new();
  505. rReq.nodesToReadSize = 1;
  506. rReq.nodesToRead[0].nodeId.identifier.numeric = UA_NS0ID_METHODNODE;
  507. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_USEREXECUTABLE;
  508. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  509. ck_assert_int_eq(-1, resp.value.arrayLength);
  510. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BOOLEAN], resp.value.type);
  511. ck_assert(*(UA_Boolean*)resp.value.data==UA_FALSE);
  512. UA_DataValue_deleteMembers(&resp);
  513. UA_ReadRequest_deleteMembers(&rReq);
  514. UA_Server_delete(server);
  515. #endif
  516. } END_TEST
  517. /* Tests for writeValue method */
  518. START_TEST(WriteSingleAttributeNodeId) {
  519. UA_Server *server = makeTestSequence();
  520. UA_WriteValue wValue;
  521. UA_WriteValue_init(&wValue);
  522. UA_NodeId *id = UA_NodeId_new();
  523. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  524. wValue.attributeId = UA_ATTRIBUTEID_NODEID;
  525. wValue.value.hasValue = UA_TRUE;
  526. UA_Variant_setScalar(&wValue.value.value, id, &UA_TYPES[UA_TYPES_NODEID]);
  527. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  528. ck_assert_int_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  529. UA_Server_delete(server);
  530. } END_TEST
  531. START_TEST(WriteSingleAttributeNodeclass) {
  532. UA_Server *server = makeTestSequence();
  533. UA_WriteValue wValue;
  534. UA_WriteValue_init(&wValue);
  535. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  536. UA_NodeClass *class = UA_NodeClass_new();
  537. wValue.attributeId = UA_ATTRIBUTEID_NODECLASS;
  538. wValue.value.hasValue = UA_TRUE;
  539. UA_Variant_setScalar(&wValue.value.value, class, &UA_TYPES[UA_TYPES_NODECLASS]);
  540. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  541. ck_assert_int_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  542. UA_Server_delete(server);
  543. } END_TEST
  544. START_TEST(WriteSingleAttributeBrowseName) {
  545. UA_Server *server = makeTestSequence();
  546. UA_WriteValue wValue;
  547. UA_WriteValue_init(&wValue);
  548. UA_QualifiedName testValue = UA_QUALIFIEDNAME(1, "the.answer");
  549. UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_QUALIFIEDNAME]);
  550. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  551. wValue.attributeId = UA_ATTRIBUTEID_BROWSENAME;
  552. wValue.value.hasValue = UA_TRUE;
  553. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  554. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  555. UA_Server_delete(server);
  556. } END_TEST
  557. START_TEST(WriteSingleAttributeDisplayName) {
  558. UA_Server *server = makeTestSequence();
  559. UA_WriteValue wValue;
  560. UA_WriteValue_init(&wValue);
  561. UA_LocalizedText testValue = UA_LOCALIZEDTEXT("en_EN", "the.answer");
  562. UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_LOCALIZEDTEXT]);
  563. wValue.value.hasValue = UA_TRUE;
  564. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  565. wValue.attributeId = UA_ATTRIBUTEID_DISPLAYNAME;
  566. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  567. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  568. UA_Server_delete(server);
  569. } END_TEST
  570. START_TEST(WriteSingleAttributeDescription) {
  571. UA_Server *server = makeTestSequence();
  572. UA_WriteValue wValue;
  573. UA_WriteValue_init(&wValue);
  574. UA_LocalizedText testValue = UA_LOCALIZEDTEXT("en_EN", "the.answer");
  575. UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_LOCALIZEDTEXT]);
  576. wValue.value.hasValue = UA_TRUE;
  577. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  578. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  579. wValue.attributeId = UA_ATTRIBUTEID_DESCRIPTION;
  580. wValue.value.hasValue = UA_TRUE;
  581. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  582. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  583. UA_Server_delete(server);
  584. } END_TEST
  585. START_TEST(WriteSingleAttributeWriteMask) {
  586. UA_Server *server = makeTestSequence();
  587. UA_WriteValue wValue;
  588. UA_WriteValue_init(&wValue);
  589. UA_Int32 testValue = 0;
  590. UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_UINT32]);
  591. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  592. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  593. wValue.attributeId = UA_ATTRIBUTEID_WRITEMASK;
  594. wValue.value.hasValue = UA_TRUE;
  595. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  596. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  597. UA_Server_delete(server);
  598. } END_TEST
  599. START_TEST(WriteSingleAttributeUserWriteMask) {
  600. UA_Server *server = makeTestSequence();
  601. UA_WriteValue wValue;
  602. UA_WriteValue_init(&wValue);
  603. UA_Int32 testValue = 0;
  604. UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_UINT32]);
  605. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  606. wValue.attributeId = UA_ATTRIBUTEID_USERWRITEMASK;
  607. wValue.value.hasValue = UA_TRUE;
  608. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  609. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  610. UA_Server_delete(server);
  611. } END_TEST
  612. START_TEST(WriteSingleAttributeIsAbstract) {
  613. UA_Server *server = makeTestSequence();
  614. UA_WriteValue wValue;
  615. UA_WriteValue_init(&wValue);
  616. UA_Boolean testValue = UA_TRUE;
  617. UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BOOLEAN]);
  618. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  619. wValue.attributeId = UA_ATTRIBUTEID_ISABSTRACT;
  620. wValue.value.hasValue = UA_TRUE;
  621. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  622. ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
  623. UA_Server_delete(server);
  624. } END_TEST
  625. START_TEST(WriteSingleAttributeSymmetric) {
  626. UA_Server *server = makeTestSequence();
  627. UA_WriteValue wValue;
  628. UA_WriteValue_init(&wValue);
  629. UA_Boolean testValue = UA_TRUE;
  630. UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BOOLEAN]);
  631. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  632. wValue.attributeId = UA_ATTRIBUTEID_SYMMETRIC;
  633. wValue.value.hasValue = UA_TRUE;
  634. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  635. ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
  636. UA_Server_delete(server);
  637. } END_TEST
  638. START_TEST(WriteSingleAttributeInverseName) {
  639. UA_Server *server = makeTestSequence();
  640. UA_WriteValue wValue;
  641. UA_WriteValue_init(&wValue);
  642. UA_LocalizedText testValue = UA_LOCALIZEDTEXT("en_US", "not.the.answer");
  643. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_LOCALIZEDTEXT]);
  644. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  645. wValue.attributeId = UA_ATTRIBUTEID_INVERSENAME;
  646. wValue.value.hasValue = UA_TRUE;
  647. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  648. ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
  649. UA_Server_delete(server);
  650. } END_TEST
  651. START_TEST(WriteSingleAttributeContainsNoLoops) {
  652. UA_Server *server = makeTestSequence();
  653. UA_WriteValue wValue;
  654. UA_WriteValue_init(&wValue);
  655. UA_Boolean testValue = UA_TRUE;
  656. UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BOOLEAN]);
  657. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  658. wValue.attributeId = UA_ATTRIBUTEID_CONTAINSNOLOOPS;
  659. wValue.value.hasValue = UA_TRUE;
  660. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  661. ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
  662. UA_Server_delete(server);
  663. } END_TEST
  664. START_TEST(WriteSingleAttributeEventNotifier) {
  665. UA_Server *server = makeTestSequence();
  666. UA_WriteValue wValue;
  667. UA_WriteValue_init(&wValue);
  668. UA_Byte testValue = 0;
  669. UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BYTE]);
  670. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  671. wValue.attributeId = UA_ATTRIBUTEID_EVENTNOTIFIER;
  672. wValue.value.hasValue = UA_TRUE;
  673. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  674. ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
  675. UA_Server_delete(server);
  676. } END_TEST
  677. START_TEST(WriteSingleAttributeValue) {
  678. UA_Server *server = makeTestSequence();
  679. UA_WriteValue wValue;
  680. UA_WriteValue_init(&wValue);
  681. UA_Variant *myIntegerVariant = UA_Variant_new();
  682. UA_Int32 myInteger = 20;
  683. UA_Variant_setScalarCopy(myIntegerVariant, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
  684. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  685. wValue.attributeId = UA_ATTRIBUTEID_VALUE;
  686. wValue.value.hasValue = UA_TRUE;
  687. wValue.value.value = *myIntegerVariant;
  688. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  689. UA_DataValue resp;
  690. UA_DataValue_init(&resp);
  691. UA_ReadRequest rReq;
  692. UA_ReadRequest_init(&rReq);
  693. rReq.nodesToRead = UA_ReadValueId_new();
  694. rReq.nodesToReadSize = 1;
  695. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING(1, "the.answer");
  696. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_VALUE;
  697. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  698. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  699. ck_assert(wValue.value.hasValue);
  700. ck_assert_int_eq(20, *(UA_Int32*)resp.value.data);
  701. UA_DataValue_deleteMembers(&resp);
  702. UA_Server_delete(server);
  703. } END_TEST
  704. START_TEST(WriteSingleAttributeDataType) {
  705. UA_Server *server = makeTestSequence();
  706. UA_WriteValue wValue;
  707. UA_WriteValue_init(&wValue);
  708. UA_NodeId *typeId = UA_NodeId_new();
  709. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  710. wValue.attributeId = UA_ATTRIBUTEID_DATATYPE;
  711. wValue.value.hasValue = UA_TRUE;
  712. UA_Variant_setScalar(&wValue.value.value, typeId, &UA_TYPES[UA_TYPES_NODEID]);
  713. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  714. ck_assert_int_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  715. UA_Server_delete(server);
  716. } END_TEST
  717. START_TEST(WriteSingleAttributeValueRank) {
  718. UA_Server *server = makeTestSequence();
  719. UA_WriteValue wValue;
  720. UA_WriteValue_init(&wValue);
  721. UA_Int32 testValue = -1;
  722. UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_INT32]);
  723. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  724. wValue.attributeId = UA_ATTRIBUTEID_VALUERANK;
  725. wValue.value.hasValue = UA_TRUE;
  726. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  727. // Returns attributeInvalid, since variant/value may be writable
  728. ck_assert_int_eq(retval, UA_STATUSCODE_BADATTRIBUTEIDINVALID);
  729. UA_Server_delete(server);
  730. } END_TEST
  731. START_TEST(WriteSingleAttributeArrayDimensions) {
  732. UA_Server *server = makeTestSequence();
  733. UA_WriteValue wValue;
  734. UA_WriteValue_init(&wValue);
  735. UA_Int32 testValue[] = {-1,-1,-1};
  736. UA_Variant_setArrayCopy(&wValue.value.value, &testValue, 3, &UA_TYPES[UA_TYPES_INT32]);
  737. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  738. wValue.attributeId = UA_ATTRIBUTEID_ARRAYDIMENSIONS;
  739. wValue.value.hasValue = UA_TRUE;
  740. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  741. // Returns attributeInvalid, since variant/value may be writable
  742. ck_assert_int_eq(retval, UA_STATUSCODE_BADATTRIBUTEIDINVALID);
  743. UA_Server_delete(server);
  744. } END_TEST
  745. START_TEST(WriteSingleAttributeAccessLevel) {
  746. UA_Server *server = makeTestSequence();
  747. UA_WriteValue wValue;
  748. UA_WriteValue_init(&wValue);
  749. UA_Byte testValue = 0;
  750. UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BYTE]);
  751. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  752. wValue.attributeId = UA_ATTRIBUTEID_ACCESSLEVEL;
  753. wValue.value.hasValue = UA_TRUE;
  754. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  755. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  756. UA_Server_delete(server);
  757. } END_TEST
  758. START_TEST(WriteSingleAttributeUserAccessLevel) {
  759. UA_Server *server = makeTestSequence();
  760. UA_WriteValue wValue;
  761. UA_WriteValue_init(&wValue);
  762. UA_Byte testValue = 0;
  763. UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BYTE]);
  764. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  765. wValue.attributeId = UA_ATTRIBUTEID_USERACCESSLEVEL;
  766. wValue.value.hasValue = UA_TRUE;
  767. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  768. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  769. UA_Server_delete(server);
  770. } END_TEST
  771. START_TEST(WriteSingleAttributeMinimumSamplingInterval) {
  772. UA_Server *server = makeTestSequence();
  773. UA_WriteValue wValue;
  774. UA_WriteValue_init(&wValue);
  775. UA_Double testValue = 0.0;
  776. UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_DOUBLE]);
  777. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  778. wValue.attributeId = UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL;
  779. wValue.value.hasValue = UA_TRUE;
  780. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  781. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  782. UA_Server_delete(server);
  783. } END_TEST
  784. START_TEST(WriteSingleAttributeHistorizing) {
  785. UA_Server *server = makeTestSequence();
  786. UA_WriteValue wValue;
  787. UA_WriteValue_init(&wValue);
  788. UA_Boolean testValue = UA_TRUE;
  789. UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BOOLEAN]);
  790. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  791. wValue.attributeId = UA_ATTRIBUTEID_HISTORIZING;
  792. wValue.value.hasValue = UA_TRUE;
  793. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  794. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  795. UA_Server_delete(server);
  796. } END_TEST
  797. START_TEST(WriteSingleAttributeExecutable) {
  798. UA_Server *server = makeTestSequence();
  799. UA_WriteValue wValue;
  800. UA_WriteValue_init(&wValue);
  801. UA_Boolean testValue = UA_TRUE;
  802. UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BOOLEAN]);
  803. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  804. wValue.attributeId = UA_ATTRIBUTEID_EXECUTABLE;
  805. wValue.value.hasValue = UA_TRUE;
  806. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  807. ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
  808. UA_Server_delete(server);
  809. } END_TEST
  810. START_TEST(WriteSingleAttributeUserExecutable) {
  811. UA_Server *server = makeTestSequence();
  812. UA_WriteValue wValue;
  813. UA_WriteValue_init(&wValue);
  814. UA_Boolean testValue = UA_TRUE;
  815. UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BOOLEAN]);
  816. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  817. wValue.attributeId = UA_ATTRIBUTEID_USEREXECUTABLE;
  818. wValue.value.hasValue = UA_TRUE;
  819. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  820. ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
  821. UA_Server_delete(server);
  822. } END_TEST
  823. START_TEST(numericRange) {
  824. UA_NumericRange range;
  825. const UA_String str = (UA_String){9, (UA_Byte*)"1:2,0:3,5"};
  826. UA_StatusCode retval = parse_numericrange(str, &range);
  827. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  828. ck_assert_int_eq(range.dimensionsSize,3);
  829. ck_assert_int_eq(range.dimensions[0].min,1);
  830. ck_assert_int_eq(range.dimensions[0].max,2);
  831. ck_assert_int_eq(range.dimensions[1].min,0);
  832. ck_assert_int_eq(range.dimensions[1].max,3);
  833. ck_assert_int_eq(range.dimensions[2].min,5);
  834. ck_assert_int_eq(range.dimensions[2].max,5);
  835. } END_TEST
  836. static Suite * testSuite_services_attributes(void) {
  837. Suite *s = suite_create("services_attributes_read");
  838. TCase *tc_readSingleAttributes = tcase_create("readSingleAttributes");
  839. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeValueWithoutTimestamp);
  840. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeNodeIdWithoutTimestamp);
  841. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeNodeClassWithoutTimestamp);
  842. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeBrowseNameWithoutTimestamp);
  843. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeDisplayNameWithoutTimestamp);
  844. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeDescriptionWithoutTimestamp);
  845. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeWriteMaskWithoutTimestamp);
  846. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeUserWriteMaskWithoutTimestamp);
  847. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeIsAbstractWithoutTimestamp);
  848. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeSymmetricWithoutTimestamp);
  849. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeInverseNameWithoutTimestamp);
  850. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeContainsNoLoopsWithoutTimestamp);
  851. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeEventNotifierWithoutTimestamp);
  852. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeDataTypeWithoutTimestamp);
  853. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeValueRankWithoutTimestamp);
  854. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeArrayDimensionsWithoutTimestamp);
  855. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeAccessLevelWithoutTimestamp);
  856. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeUserAccessLevelWithoutTimestamp);
  857. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeMinimumSamplingIntervalWithoutTimestamp);
  858. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeHistorizingWithoutTimestamp);
  859. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeExecutableWithoutTimestamp);
  860. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeUserExecutableWithoutTimestamp);
  861. suite_add_tcase(s, tc_readSingleAttributes);
  862. TCase *tc_writeSingleAttributes = tcase_create("writeSingleAttributes");
  863. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeNodeId);
  864. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeNodeclass);
  865. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeBrowseName);
  866. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeDisplayName);
  867. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeDescription);
  868. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeWriteMask);
  869. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeUserWriteMask);
  870. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeIsAbstract);
  871. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeSymmetric);
  872. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeInverseName);
  873. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeContainsNoLoops);
  874. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeEventNotifier);
  875. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeValue);
  876. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeDataType);
  877. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeValueRank);
  878. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeArrayDimensions);
  879. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeAccessLevel);
  880. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeUserAccessLevel);
  881. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeMinimumSamplingInterval);
  882. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeHistorizing);
  883. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeExecutable);
  884. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeUserExecutable);
  885. suite_add_tcase(s, tc_writeSingleAttributes);
  886. TCase *tc_parseNumericRange = tcase_create("parseNumericRange");
  887. tcase_add_test(tc_parseNumericRange, numericRange);
  888. suite_add_tcase(s, tc_parseNumericRange);
  889. return s;
  890. }
  891. int main(void) {
  892. int number_failed = 0;
  893. Suite *s;
  894. s = testSuite_services_attributes();
  895. SRunner *sr = srunner_create(s);
  896. // srunner_set_fork_status(sr, CK_NOFORK);
  897. srunner_run_all(sr, CK_NORMAL);
  898. number_failed += srunner_ntests_failed(sr);
  899. srunner_free(sr);
  900. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  901. }