check_services_attributes.c 42 KB

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