check_services_attributes.c 40 KB

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