check_services_attributes.c 42 KB

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