check_services_attributes.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  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. UA_UInt32* respval = (UA_UInt32*) resp.value.data;
  252. ck_assert_int_eq(0, resp.value.arrayLength);
  253. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_UINT32], resp.value.type);
  254. ck_assert_int_eq(0,*respval);
  255. UA_DataValue_deleteMembers(&resp);
  256. UA_Server_delete(server);
  257. } END_TEST
  258. START_TEST(ReadSingleAttributeIsAbstractWithoutTimestamp) {
  259. UA_Server *server = makeTestSequence();
  260. UA_ReadValueId rvi;
  261. UA_ReadValueId_init(&rvi);
  262. rvi.nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
  263. rvi.attributeId = UA_ATTRIBUTEID_ISABSTRACT;
  264. UA_DataValue resp = UA_Server_read(server, &rvi, UA_TIMESTAMPSTORETURN_NEITHER);
  265. ck_assert_int_eq(0, resp.value.arrayLength);
  266. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BOOLEAN], resp.value.type);
  267. ck_assert(*(UA_Boolean* )resp.value.data==false);
  268. UA_DataValue_deleteMembers(&resp);
  269. UA_Server_delete(server);
  270. } END_TEST
  271. START_TEST(ReadSingleAttributeSymmetricWithoutTimestamp) {
  272. UA_Server *server = makeTestSequence();
  273. UA_ReadValueId rvi;
  274. UA_ReadValueId_init(&rvi);
  275. rvi.nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
  276. rvi.attributeId = UA_ATTRIBUTEID_SYMMETRIC;
  277. UA_DataValue resp = UA_Server_read(server, &rvi, UA_TIMESTAMPSTORETURN_NEITHER);
  278. ck_assert_int_eq(0, resp.value.arrayLength);
  279. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BOOLEAN], resp.value.type);
  280. ck_assert(*(UA_Boolean* )resp.value.data==false);
  281. UA_DataValue_deleteMembers(&resp);
  282. UA_Server_delete(server);
  283. } END_TEST
  284. START_TEST(ReadSingleAttributeInverseNameWithoutTimestamp) {
  285. UA_Server *server = makeTestSequence();
  286. UA_ReadValueId rvi;
  287. UA_ReadValueId_init(&rvi);
  288. rvi.nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
  289. rvi.attributeId = UA_ATTRIBUTEID_INVERSENAME;
  290. UA_DataValue resp = UA_Server_read(server, &rvi, UA_TIMESTAMPSTORETURN_NEITHER);
  291. UA_LocalizedText* respval = (UA_LocalizedText*) resp.value.data;
  292. const UA_LocalizedText comp = UA_LOCALIZEDTEXT("en_US", "OrganizedBy");
  293. ck_assert_int_eq(0, resp.value.arrayLength);
  294. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_LOCALIZEDTEXT],resp.value.type);
  295. ck_assert(UA_String_equal(&comp.text, &respval->text));
  296. ck_assert(UA_String_equal(&comp.locale, &respval->locale));
  297. UA_DataValue_deleteMembers(&resp);
  298. UA_Server_delete(server);
  299. } END_TEST
  300. START_TEST(ReadSingleAttributeContainsNoLoopsWithoutTimestamp) {
  301. UA_Server *server = makeTestSequence();
  302. UA_ReadValueId rvi;
  303. UA_ReadValueId_init(&rvi);
  304. rvi.nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_VIEWNODE);
  305. rvi.attributeId = UA_ATTRIBUTEID_CONTAINSNOLOOPS;
  306. UA_DataValue resp = UA_Server_read(server, &rvi, UA_TIMESTAMPSTORETURN_NEITHER);
  307. ck_assert_int_eq(0, resp.value.arrayLength);
  308. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BOOLEAN], resp.value.type);
  309. ck_assert(*(UA_Boolean* )resp.value.data==false);
  310. UA_DataValue_deleteMembers(&resp);
  311. UA_Server_delete(server);
  312. } END_TEST
  313. START_TEST(ReadSingleAttributeEventNotifierWithoutTimestamp) {
  314. UA_Server *server = makeTestSequence();
  315. UA_ReadValueId rvi;
  316. UA_ReadValueId_init(&rvi);
  317. rvi.nodeId = UA_NODEID_NUMERIC(1, 50);
  318. rvi.attributeId = UA_ATTRIBUTEID_EVENTNOTIFIER;
  319. UA_DataValue resp = UA_Server_read(server, &rvi, UA_TIMESTAMPSTORETURN_NEITHER);
  320. ck_assert_int_eq(UA_STATUSCODE_GOOD, resp.status);
  321. ck_assert_int_eq(0, resp.value.arrayLength);
  322. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BYTE],resp.value.type);
  323. ck_assert_int_eq(*(UA_Byte*)resp.value.data, 0);
  324. UA_DataValue_deleteMembers(&resp);
  325. UA_Server_delete(server);
  326. } END_TEST
  327. START_TEST(ReadSingleAttributeDataTypeWithoutTimestamp) {
  328. UA_Server *server = makeTestSequence();
  329. UA_ReadValueId rvi;
  330. UA_ReadValueId_init(&rvi);
  331. rvi.nodeId = UA_NODEID_STRING(1, "the.answer");
  332. rvi.attributeId = UA_ATTRIBUTEID_DATATYPE;
  333. UA_DataValue resp = UA_Server_read(server, &rvi, UA_TIMESTAMPSTORETURN_NEITHER);
  334. ck_assert_int_eq(0, resp.value.arrayLength);
  335. ck_assert_int_eq(UA_STATUSCODE_GOOD, resp.status);
  336. ck_assert_int_eq(true, resp.hasValue);
  337. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_NODEID], resp.value.type);
  338. UA_NodeId* respval = (UA_NodeId*)resp.value.data;
  339. ck_assert_int_eq(respval->namespaceIndex,0);
  340. ck_assert_int_eq(respval->identifier.numeric, UA_NS0ID_BASEDATATYPE);
  341. UA_DataValue_deleteMembers(&resp);
  342. UA_Server_delete(server);
  343. } END_TEST
  344. START_TEST(ReadSingleAttributeValueRankWithoutTimestamp) {
  345. UA_Server *server = makeTestSequence();
  346. UA_ReadValueId rvi;
  347. UA_ReadValueId_init(&rvi);
  348. rvi.nodeId = UA_NODEID_STRING(1, "the.answer");
  349. rvi.attributeId = UA_ATTRIBUTEID_VALUERANK;
  350. UA_DataValue resp = UA_Server_read(server, &rvi, UA_TIMESTAMPSTORETURN_NEITHER);
  351. ck_assert_int_eq(0, resp.value.arrayLength);
  352. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_INT32], resp.value.type);
  353. ck_assert_int_eq(-2, *(UA_Int32* )resp.value.data);
  354. UA_DataValue_deleteMembers(&resp);
  355. UA_Server_delete(server);
  356. } END_TEST
  357. START_TEST(ReadSingleAttributeArrayDimensionsWithoutTimestamp) {
  358. UA_Server *server = makeTestSequence();
  359. UA_ReadValueId rvi;
  360. UA_ReadValueId_init(&rvi);
  361. rvi.nodeId = UA_NODEID_STRING(1, "the.answer");
  362. rvi.attributeId = UA_ATTRIBUTEID_ARRAYDIMENSIONS;
  363. UA_DataValue resp = UA_Server_read(server, &rvi, UA_TIMESTAMPSTORETURN_NEITHER);
  364. ck_assert_int_eq(0, resp.value.arrayLength);
  365. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_UINT32], resp.value.type);
  366. ck_assert_ptr_eq((UA_Int32*)resp.value.data,0);
  367. UA_DataValue_deleteMembers(&resp);
  368. UA_Server_delete(server);
  369. } END_TEST
  370. START_TEST(ReadSingleAttributeAccessLevelWithoutTimestamp) {
  371. UA_Server *server = makeTestSequence();
  372. UA_ReadValueId rvi;
  373. UA_ReadValueId_init(&rvi);
  374. rvi.nodeId = UA_NODEID_STRING(1, "the.answer");
  375. rvi.attributeId = UA_ATTRIBUTEID_ACCESSLEVEL;
  376. UA_DataValue resp = UA_Server_read(server, &rvi, UA_TIMESTAMPSTORETURN_NEITHER);
  377. ck_assert_int_eq(0, resp.value.arrayLength);
  378. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BYTE], resp.value.type);
  379. ck_assert_int_eq(*(UA_Byte*)resp.value.data, 0);
  380. UA_DataValue_deleteMembers(&resp);
  381. UA_Server_delete(server);
  382. } END_TEST
  383. START_TEST(ReadSingleAttributeUserAccessLevelWithoutTimestamp) {
  384. UA_Server *server = makeTestSequence();
  385. UA_ReadValueId rvi;
  386. UA_ReadValueId_init(&rvi);
  387. rvi.nodeId = UA_NODEID_STRING(1, "the.answer");
  388. rvi.attributeId = UA_ATTRIBUTEID_USERACCESSLEVEL;
  389. UA_DataValue resp = UA_Server_read(server, &rvi, UA_TIMESTAMPSTORETURN_NEITHER);
  390. UA_RCU_LOCK();
  391. const UA_VariableNode* compNode =
  392. (const UA_VariableNode*)UA_NodeStore_get(server->nodestore, &rvi.nodeId);
  393. ck_assert_int_eq(0, resp.value.arrayLength);
  394. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BYTE], resp.value.type);
  395. ck_assert_int_eq(*(UA_Byte*)resp.value.data, compNode->userAccessLevel);
  396. UA_RCU_UNLOCK();
  397. UA_Server_delete(server);
  398. UA_DataValue_deleteMembers(&resp);
  399. } END_TEST
  400. START_TEST(ReadSingleAttributeMinimumSamplingIntervalWithoutTimestamp) {
  401. UA_Server *server = makeTestSequence();
  402. UA_ReadValueId rvi;
  403. UA_ReadValueId_init(&rvi);
  404. rvi.nodeId = UA_NODEID_STRING(1, "the.answer");
  405. rvi.attributeId = UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL;
  406. UA_DataValue resp = UA_Server_read(server, &rvi, UA_TIMESTAMPSTORETURN_NEITHER);
  407. UA_Double* respval = (UA_Double*) resp.value.data;
  408. UA_VariableNode *compNode = makeCompareSequence();
  409. UA_Double comp = (UA_Double) compNode->minimumSamplingInterval;
  410. ck_assert_int_eq(0, resp.value.arrayLength);
  411. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_DOUBLE], resp.value.type);
  412. ck_assert(*respval == comp);
  413. UA_DataValue_deleteMembers(&resp);
  414. UA_NodeStore_deleteNode((UA_Node*)compNode);
  415. UA_Server_delete(server);
  416. } END_TEST
  417. START_TEST(ReadSingleAttributeHistorizingWithoutTimestamp) {
  418. UA_Server *server = makeTestSequence();
  419. UA_ReadValueId rvi;
  420. UA_ReadValueId_init(&rvi);
  421. rvi.nodeId = UA_NODEID_STRING(1, "the.answer");
  422. rvi.attributeId = UA_ATTRIBUTEID_HISTORIZING;
  423. UA_DataValue resp = UA_Server_read(server, &rvi, UA_TIMESTAMPSTORETURN_NEITHER);
  424. ck_assert_int_eq(0, resp.value.arrayLength);
  425. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BOOLEAN], resp.value.type);
  426. ck_assert(*(UA_Boolean*)resp.value.data==false);
  427. UA_DataValue_deleteMembers(&resp);
  428. UA_Server_delete(server);
  429. } END_TEST
  430. START_TEST(ReadSingleAttributeExecutableWithoutTimestamp) {
  431. UA_Server *server = makeTestSequence();
  432. #ifdef UA_ENABLE_METHODCALLS
  433. UA_ReadValueId rvi;
  434. UA_ReadValueId_init(&rvi);
  435. rvi.nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_METHODNODE);
  436. rvi.attributeId = UA_ATTRIBUTEID_EXECUTABLE;
  437. UA_DataValue resp = UA_Server_read(server, &rvi, UA_TIMESTAMPSTORETURN_NEITHER);
  438. ck_assert_int_eq(true, resp.hasValue);
  439. ck_assert_int_eq(0, resp.value.arrayLength);
  440. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BOOLEAN], resp.value.type);
  441. ck_assert(*(UA_Boolean*)resp.value.data==false);
  442. UA_DataValue_deleteMembers(&resp);
  443. #endif
  444. UA_Server_delete(server);
  445. } END_TEST
  446. START_TEST(ReadSingleAttributeUserExecutableWithoutTimestamp) {
  447. #ifdef UA_ENABLE_METHODCALLS
  448. UA_Server *server = makeTestSequence();
  449. UA_ReadValueId rvi;
  450. UA_ReadValueId_init(&rvi);
  451. rvi.nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_METHODNODE);
  452. rvi.attributeId = UA_ATTRIBUTEID_USEREXECUTABLE;
  453. UA_DataValue resp = UA_Server_read(server, &rvi, UA_TIMESTAMPSTORETURN_NEITHER);
  454. ck_assert_int_eq(0, resp.value.arrayLength);
  455. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BOOLEAN], resp.value.type);
  456. ck_assert(*(UA_Boolean*)resp.value.data==false);
  457. UA_DataValue_deleteMembers(&resp);
  458. UA_Server_delete(server);
  459. #endif
  460. } END_TEST
  461. START_TEST(ReadSingleDataSourceAttributeValueWithoutTimestamp) {
  462. UA_Server *server = makeTestSequence();
  463. UA_ReadValueId rvi;
  464. UA_ReadValueId_init(&rvi);
  465. rvi.nodeId = UA_NODEID_STRING(1, "cpu.temperature");
  466. rvi.attributeId = UA_ATTRIBUTEID_VALUE;
  467. UA_DataValue resp = UA_Server_read(server, &rvi, UA_TIMESTAMPSTORETURN_NEITHER);
  468. ck_assert_int_eq(UA_STATUSCODE_GOOD, resp.status);
  469. UA_Server_delete(server);
  470. UA_DataValue_deleteMembers(&resp);
  471. } END_TEST
  472. START_TEST(ReadSingleDataSourceAttributeDataTypeWithoutTimestamp) {
  473. UA_Server *server = makeTestSequence();
  474. UA_ReadValueId rvi;
  475. UA_ReadValueId_init(&rvi);
  476. rvi.nodeId = UA_NODEID_STRING(1, "cpu.temperature");
  477. rvi.attributeId = UA_ATTRIBUTEID_DATATYPE;
  478. UA_DataValue resp = UA_Server_read(server, &rvi, UA_TIMESTAMPSTORETURN_NEITHER);
  479. ck_assert_int_eq(UA_STATUSCODE_GOOD, resp.status);
  480. ck_assert_int_eq(resp.hasServerTimestamp, false);
  481. UA_Server_delete(server);
  482. UA_DataValue_deleteMembers(&resp);
  483. } END_TEST
  484. START_TEST (ReadSingleDataSourceAttributeArrayDimensionsWithoutTimestamp) {
  485. UA_Server *server = makeTestSequence();
  486. UA_ReadValueId rvi;
  487. UA_ReadValueId_init(&rvi);
  488. rvi.nodeId = UA_NODEID_STRING(1, "cpu.temperature");
  489. rvi.attributeId = UA_ATTRIBUTEID_ARRAYDIMENSIONS;
  490. UA_DataValue resp = UA_Server_read(server, &rvi, UA_TIMESTAMPSTORETURN_NEITHER);
  491. ck_assert_int_eq(UA_STATUSCODE_GOOD, resp.status);
  492. UA_Server_delete(server);
  493. UA_DataValue_deleteMembers(&resp);
  494. } END_TEST
  495. /* Tests for writeValue method */
  496. START_TEST(WriteSingleAttributeNodeId) {
  497. UA_Server *server = makeTestSequence();
  498. UA_WriteValue wValue;
  499. UA_WriteValue_init(&wValue);
  500. UA_NodeId id;
  501. UA_NodeId_init(&id);
  502. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  503. wValue.attributeId = UA_ATTRIBUTEID_NODEID;
  504. wValue.value.hasValue = true;
  505. UA_Variant_setScalar(&wValue.value.value, &id, &UA_TYPES[UA_TYPES_NODEID]);
  506. UA_StatusCode retval = UA_Server_write(server, &wValue);
  507. ck_assert_int_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  508. UA_Server_delete(server);
  509. } END_TEST
  510. START_TEST(WriteSingleAttributeNodeclass) {
  511. UA_Server *server = makeTestSequence();
  512. UA_WriteValue wValue;
  513. UA_WriteValue_init(&wValue);
  514. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  515. UA_NodeClass class;
  516. UA_NodeClass_init(&class);
  517. wValue.attributeId = UA_ATTRIBUTEID_NODECLASS;
  518. wValue.value.hasValue = true;
  519. UA_Variant_setScalar(&wValue.value.value, &class, &UA_TYPES[UA_TYPES_NODECLASS]);
  520. UA_StatusCode retval = UA_Server_write(server, &wValue);
  521. ck_assert_int_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  522. UA_Server_delete(server);
  523. } END_TEST
  524. START_TEST(WriteSingleAttributeBrowseName) {
  525. UA_Server *server = makeTestSequence();
  526. UA_WriteValue wValue;
  527. UA_WriteValue_init(&wValue);
  528. UA_QualifiedName testValue = UA_QUALIFIEDNAME(1, "the.answer");
  529. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_QUALIFIEDNAME]);
  530. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  531. wValue.attributeId = UA_ATTRIBUTEID_BROWSENAME;
  532. wValue.value.hasValue = true;
  533. UA_StatusCode retval = UA_Server_write(server, &wValue);
  534. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  535. UA_Server_delete(server);
  536. } END_TEST
  537. START_TEST(WriteSingleAttributeDisplayName) {
  538. UA_Server *server = makeTestSequence();
  539. UA_WriteValue wValue;
  540. UA_WriteValue_init(&wValue);
  541. UA_LocalizedText testValue = UA_LOCALIZEDTEXT("en_EN", "the.answer");
  542. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_LOCALIZEDTEXT]);
  543. wValue.value.hasValue = true;
  544. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  545. wValue.attributeId = UA_ATTRIBUTEID_DISPLAYNAME;
  546. UA_StatusCode retval = UA_Server_write(server, &wValue);
  547. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  548. UA_Server_delete(server);
  549. } END_TEST
  550. START_TEST(WriteSingleAttributeDescription) {
  551. UA_Server *server = makeTestSequence();
  552. UA_WriteValue wValue;
  553. UA_WriteValue_init(&wValue);
  554. UA_LocalizedText testValue = UA_LOCALIZEDTEXT("en_EN", "the.answer");
  555. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_LOCALIZEDTEXT]);
  556. wValue.value.hasValue = true;
  557. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  558. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  559. wValue.attributeId = UA_ATTRIBUTEID_DESCRIPTION;
  560. wValue.value.hasValue = true;
  561. UA_StatusCode retval = UA_Server_write(server, &wValue);
  562. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  563. UA_Server_delete(server);
  564. } END_TEST
  565. START_TEST(WriteSingleAttributeWriteMask) {
  566. UA_Server *server = makeTestSequence();
  567. UA_WriteValue wValue;
  568. UA_WriteValue_init(&wValue);
  569. UA_Int32 testValue = 0;
  570. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_UINT32]);
  571. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  572. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  573. wValue.attributeId = UA_ATTRIBUTEID_WRITEMASK;
  574. wValue.value.hasValue = true;
  575. UA_StatusCode retval = UA_Server_write(server, &wValue);
  576. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  577. UA_Server_delete(server);
  578. } END_TEST
  579. START_TEST(WriteSingleAttributeUserWriteMask) {
  580. UA_Server *server = makeTestSequence();
  581. UA_WriteValue wValue;
  582. UA_WriteValue_init(&wValue);
  583. UA_Int32 testValue = 0;
  584. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_UINT32]);
  585. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  586. wValue.attributeId = UA_ATTRIBUTEID_USERWRITEMASK;
  587. wValue.value.hasValue = true;
  588. UA_StatusCode retval = UA_Server_write(server, &wValue);
  589. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  590. UA_Server_delete(server);
  591. } END_TEST
  592. START_TEST(WriteSingleAttributeIsAbstract) {
  593. UA_Server *server = makeTestSequence();
  594. UA_WriteValue wValue;
  595. UA_WriteValue_init(&wValue);
  596. UA_Boolean testValue = true;
  597. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BOOLEAN]);
  598. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  599. wValue.attributeId = UA_ATTRIBUTEID_ISABSTRACT;
  600. wValue.value.hasValue = true;
  601. UA_StatusCode retval = UA_Server_write(server, &wValue);
  602. ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
  603. UA_Server_delete(server);
  604. } END_TEST
  605. START_TEST(WriteSingleAttributeSymmetric) {
  606. UA_Server *server = makeTestSequence();
  607. UA_WriteValue wValue;
  608. UA_WriteValue_init(&wValue);
  609. UA_Boolean testValue = true;
  610. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BOOLEAN]);
  611. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  612. wValue.attributeId = UA_ATTRIBUTEID_SYMMETRIC;
  613. wValue.value.hasValue = true;
  614. UA_StatusCode retval = UA_Server_write(server, &wValue);
  615. ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
  616. UA_Server_delete(server);
  617. } END_TEST
  618. START_TEST(WriteSingleAttributeInverseName) {
  619. UA_Server *server = makeTestSequence();
  620. UA_WriteValue wValue;
  621. UA_WriteValue_init(&wValue);
  622. UA_LocalizedText testValue = UA_LOCALIZEDTEXT("en_US", "not.the.answer");
  623. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_LOCALIZEDTEXT]);
  624. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  625. wValue.attributeId = UA_ATTRIBUTEID_INVERSENAME;
  626. wValue.value.hasValue = true;
  627. UA_StatusCode retval = UA_Server_write(server, &wValue);
  628. ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
  629. UA_Server_delete(server);
  630. } END_TEST
  631. START_TEST(WriteSingleAttributeContainsNoLoops) {
  632. UA_Server *server = makeTestSequence();
  633. UA_WriteValue wValue;
  634. UA_WriteValue_init(&wValue);
  635. UA_Boolean testValue = true;
  636. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BOOLEAN]);
  637. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  638. wValue.attributeId = UA_ATTRIBUTEID_CONTAINSNOLOOPS;
  639. wValue.value.hasValue = true;
  640. UA_StatusCode retval = UA_Server_write(server, &wValue);
  641. ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
  642. UA_Server_delete(server);
  643. } END_TEST
  644. START_TEST(WriteSingleAttributeEventNotifier) {
  645. UA_Server *server = makeTestSequence();
  646. UA_WriteValue wValue;
  647. UA_WriteValue_init(&wValue);
  648. UA_Byte testValue = 0;
  649. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BYTE]);
  650. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  651. wValue.attributeId = UA_ATTRIBUTEID_EVENTNOTIFIER;
  652. wValue.value.hasValue = true;
  653. UA_StatusCode retval = UA_Server_write(server, &wValue);
  654. ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
  655. UA_Server_delete(server);
  656. } END_TEST
  657. START_TEST(WriteSingleAttributeValue) {
  658. UA_Server *server = makeTestSequence();
  659. UA_WriteValue wValue;
  660. UA_WriteValue_init(&wValue);
  661. UA_Int32 myInteger = 20;
  662. UA_Variant_setScalar(&wValue.value.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
  663. wValue.value.hasValue = true;
  664. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  665. wValue.attributeId = UA_ATTRIBUTEID_VALUE;
  666. UA_StatusCode retval = UA_Server_write(server, &wValue);
  667. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  668. UA_ReadValueId rvi;
  669. UA_ReadValueId_init(&rvi);
  670. rvi.nodeId = UA_NODEID_STRING(1, "the.answer");
  671. rvi.attributeId = UA_ATTRIBUTEID_VALUE;
  672. UA_DataValue resp = UA_Server_read(server, &rvi, UA_TIMESTAMPSTORETURN_NEITHER);
  673. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  674. ck_assert(resp.hasValue);
  675. ck_assert_int_eq(20, *(UA_Int32*)resp.value.data);
  676. UA_DataValue_deleteMembers(&resp);
  677. UA_Server_delete(server);
  678. } END_TEST
  679. START_TEST(WriteSingleAttributeValueRangeFromScalar) {
  680. UA_Server *server = makeTestSequence();
  681. UA_WriteValue wValue;
  682. UA_WriteValue_init(&wValue);
  683. UA_Int32 myInteger = 20;
  684. UA_Variant_setScalar(&wValue.value.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
  685. wValue.value.hasValue = true;
  686. wValue.nodeId = UA_NODEID_STRING(1, "myarray");
  687. wValue.indexRange = UA_STRING("0,0");
  688. wValue.attributeId = UA_ATTRIBUTEID_VALUE;
  689. UA_StatusCode retval = UA_Server_write(server, &wValue);
  690. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  691. UA_Server_delete(server);
  692. } END_TEST
  693. START_TEST(WriteSingleAttributeValueRangeFromArray) {
  694. UA_Server *server = makeTestSequence();
  695. UA_WriteValue wValue;
  696. UA_WriteValue_init(&wValue);
  697. UA_Int32 myInteger = 20;
  698. UA_Variant_setArray(&wValue.value.value, &myInteger, 1, &UA_TYPES[UA_TYPES_INT32]);
  699. wValue.value.hasValue = true;
  700. wValue.nodeId = UA_NODEID_STRING(1, "myarray");
  701. wValue.indexRange = UA_STRING("0,0");
  702. wValue.attributeId = UA_ATTRIBUTEID_VALUE;
  703. UA_StatusCode retval = UA_Server_write(server, &wValue);
  704. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  705. UA_Server_delete(server);
  706. } END_TEST
  707. START_TEST(WriteSingleAttributeDataType) {
  708. UA_Server *server = makeTestSequence();
  709. UA_WriteValue wValue;
  710. UA_WriteValue_init(&wValue);
  711. UA_NodeId typeId;
  712. UA_NodeId_init(&typeId);
  713. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  714. wValue.attributeId = UA_ATTRIBUTEID_DATATYPE;
  715. wValue.value.hasValue = true;
  716. UA_Variant_setScalar(&wValue.value.value, &typeId, &UA_TYPES[UA_TYPES_NODEID]);
  717. UA_StatusCode retval = UA_Server_write(server, &wValue);
  718. ck_assert_int_eq(retval, UA_STATUSCODE_BADTYPEMISMATCH);
  719. UA_Server_delete(server);
  720. } END_TEST
  721. START_TEST(WriteSingleAttributeValueRank) {
  722. UA_Server *server = makeTestSequence();
  723. UA_WriteValue wValue;
  724. UA_WriteValue_init(&wValue);
  725. UA_Int32 testValue = -1;
  726. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_INT32]);
  727. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  728. wValue.attributeId = UA_ATTRIBUTEID_VALUERANK;
  729. wValue.value.hasValue = true;
  730. UA_StatusCode retval = UA_Server_write(server, &wValue);
  731. // Returns attributeInvalid, since variant/value may be writable
  732. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  733. UA_Server_delete(server);
  734. } END_TEST
  735. START_TEST(WriteSingleAttributeArrayDimensions) {
  736. UA_Server *server = makeTestSequence();
  737. UA_WriteValue wValue;
  738. UA_WriteValue_init(&wValue);
  739. UA_UInt32 testValue[] = {1,1,1};
  740. UA_Variant_setArray(&wValue.value.value, &testValue, 3, &UA_TYPES[UA_TYPES_UINT32]);
  741. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  742. wValue.attributeId = UA_ATTRIBUTEID_ARRAYDIMENSIONS;
  743. wValue.value.hasValue = true;
  744. UA_StatusCode retval = UA_Server_write(server, &wValue);
  745. // Returns attributeInvalid, since variant/value may be writable
  746. ck_assert_int_eq(retval, UA_STATUSCODE_BADTYPEMISMATCH);
  747. UA_Server_delete(server);
  748. } END_TEST
  749. START_TEST(WriteSingleAttributeAccessLevel) {
  750. UA_Server *server = makeTestSequence();
  751. UA_WriteValue wValue;
  752. UA_WriteValue_init(&wValue);
  753. UA_Byte testValue = 0;
  754. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BYTE]);
  755. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  756. wValue.attributeId = UA_ATTRIBUTEID_ACCESSLEVEL;
  757. wValue.value.hasValue = true;
  758. UA_StatusCode retval = UA_Server_write(server, &wValue);
  759. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  760. UA_Server_delete(server);
  761. } END_TEST
  762. START_TEST(WriteSingleAttributeUserAccessLevel) {
  763. UA_Server *server = makeTestSequence();
  764. UA_WriteValue wValue;
  765. UA_WriteValue_init(&wValue);
  766. UA_Byte testValue = 0;
  767. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BYTE]);
  768. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  769. wValue.attributeId = UA_ATTRIBUTEID_USERACCESSLEVEL;
  770. wValue.value.hasValue = true;
  771. UA_StatusCode retval = UA_Server_write(server, &wValue);
  772. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  773. UA_Server_delete(server);
  774. } END_TEST
  775. START_TEST(WriteSingleAttributeMinimumSamplingInterval) {
  776. UA_Server *server = makeTestSequence();
  777. UA_WriteValue wValue;
  778. UA_WriteValue_init(&wValue);
  779. UA_Double testValue = 0.0;
  780. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_DOUBLE]);
  781. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  782. wValue.attributeId = UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL;
  783. wValue.value.hasValue = true;
  784. UA_StatusCode retval = UA_Server_write(server, &wValue);
  785. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  786. UA_Server_delete(server);
  787. } END_TEST
  788. START_TEST(WriteSingleAttributeHistorizing) {
  789. UA_Server *server = makeTestSequence();
  790. UA_WriteValue wValue;
  791. UA_WriteValue_init(&wValue);
  792. UA_Boolean testValue = true;
  793. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BOOLEAN]);
  794. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  795. wValue.attributeId = UA_ATTRIBUTEID_HISTORIZING;
  796. wValue.value.hasValue = true;
  797. UA_StatusCode retval = UA_Server_write(server, &wValue);
  798. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  799. UA_Server_delete(server);
  800. } END_TEST
  801. START_TEST(WriteSingleAttributeExecutable) {
  802. UA_Server *server = makeTestSequence();
  803. UA_WriteValue wValue;
  804. UA_WriteValue_init(&wValue);
  805. UA_Boolean testValue = true;
  806. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BOOLEAN]);
  807. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  808. wValue.attributeId = UA_ATTRIBUTEID_EXECUTABLE;
  809. wValue.value.hasValue = true;
  810. UA_StatusCode retval = UA_Server_write(server, &wValue);
  811. ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
  812. UA_Server_delete(server);
  813. } END_TEST
  814. START_TEST(WriteSingleAttributeUserExecutable) {
  815. UA_Server *server = makeTestSequence();
  816. UA_WriteValue wValue;
  817. UA_WriteValue_init(&wValue);
  818. UA_Boolean testValue = true;
  819. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BOOLEAN]);
  820. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  821. wValue.attributeId = UA_ATTRIBUTEID_USEREXECUTABLE;
  822. wValue.value.hasValue = true;
  823. UA_StatusCode retval = UA_Server_write(server, &wValue);
  824. ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
  825. UA_Server_delete(server);
  826. } END_TEST
  827. START_TEST(WriteSingleDataSourceAttributeValue) {
  828. UA_Server *server = makeTestSequence();
  829. UA_WriteValue wValue;
  830. UA_WriteValue_init(&wValue);
  831. UA_Int32 testValue = 0;
  832. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_INT32]);
  833. wValue.nodeId = UA_NODEID_STRING(1, "cpu.temperature");
  834. wValue.attributeId = UA_ATTRIBUTEID_VALUE;
  835. wValue.value.hasValue = true;
  836. UA_StatusCode retval = UA_Server_write(server, &wValue);
  837. ck_assert_int_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  838. UA_Server_delete(server);
  839. } END_TEST
  840. static Suite * testSuite_services_attributes(void) {
  841. Suite *s = suite_create("services_attributes_read");
  842. TCase *tc_readSingleAttributes = tcase_create("readSingleAttributes");
  843. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeValueWithoutTimestamp);
  844. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeValueRangeWithoutTimestamp);
  845. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeNodeIdWithoutTimestamp);
  846. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeNodeClassWithoutTimestamp);
  847. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeBrowseNameWithoutTimestamp);
  848. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeDisplayNameWithoutTimestamp);
  849. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeDescriptionWithoutTimestamp);
  850. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeWriteMaskWithoutTimestamp);
  851. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeUserWriteMaskWithoutTimestamp);
  852. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeIsAbstractWithoutTimestamp);
  853. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeSymmetricWithoutTimestamp);
  854. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeInverseNameWithoutTimestamp);
  855. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeContainsNoLoopsWithoutTimestamp);
  856. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeEventNotifierWithoutTimestamp);
  857. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeDataTypeWithoutTimestamp);
  858. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeValueRankWithoutTimestamp);
  859. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeArrayDimensionsWithoutTimestamp);
  860. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeAccessLevelWithoutTimestamp);
  861. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeUserAccessLevelWithoutTimestamp);
  862. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeMinimumSamplingIntervalWithoutTimestamp);
  863. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeHistorizingWithoutTimestamp);
  864. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeExecutableWithoutTimestamp);
  865. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeUserExecutableWithoutTimestamp);
  866. tcase_add_test(tc_readSingleAttributes, ReadSingleDataSourceAttributeValueWithoutTimestamp);
  867. tcase_add_test(tc_readSingleAttributes, ReadSingleDataSourceAttributeDataTypeWithoutTimestamp);
  868. tcase_add_test(tc_readSingleAttributes, ReadSingleDataSourceAttributeArrayDimensionsWithoutTimestamp);
  869. suite_add_tcase(s, tc_readSingleAttributes);
  870. TCase *tc_writeSingleAttributes = tcase_create("writeSingleAttributes");
  871. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeNodeId);
  872. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeNodeclass);
  873. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeBrowseName);
  874. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeDisplayName);
  875. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeDescription);
  876. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeWriteMask);
  877. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeUserWriteMask);
  878. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeIsAbstract);
  879. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeSymmetric);
  880. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeInverseName);
  881. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeContainsNoLoops);
  882. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeEventNotifier);
  883. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeValue);
  884. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeDataType);
  885. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeValueRangeFromScalar);
  886. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeValueRangeFromArray);
  887. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeValueRank);
  888. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeArrayDimensions);
  889. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeAccessLevel);
  890. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeUserAccessLevel);
  891. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeMinimumSamplingInterval);
  892. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeHistorizing);
  893. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeExecutable);
  894. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeUserExecutable);
  895. tcase_add_test(tc_writeSingleAttributes, WriteSingleDataSourceAttributeValue);
  896. suite_add_tcase(s, tc_writeSingleAttributes);
  897. return s;
  898. }
  899. int main(void) {
  900. int number_failed = 0;
  901. Suite *s;
  902. s = testSuite_services_attributes();
  903. SRunner *sr = srunner_create(s);
  904. srunner_set_fork_status(sr, CK_NOFORK);
  905. srunner_run_all(sr, CK_NORMAL);
  906. number_failed += srunner_ntests_failed(sr);
  907. srunner_free(sr);
  908. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  909. }