check_services_attributes.c 39 KB

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