check_services_attributes.c 40 KB

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