check_services_attributes.c 42 KB

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