check_services_attributes.c 42 KB

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