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