check_services_attributes.c 42 KB

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