check_services_attributes.c 39 KB

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