check_services_attributes.c 42 KB

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