check_services_attributes.c 43 KB

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