check_services_attributes.c 40 KB

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