check_services_attributes.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include "check.h"
  5. #include "server/ua_nodestore.h"
  6. #include "server/ua_services.h"
  7. #include "ua_client.h"
  8. #include "ua_nodeids.h"
  9. #include "ua_types.h"
  10. #include "ua_config_standard.h"
  11. #include "server/ua_server_internal.h"
  12. #ifdef UA_ENABLE_MULTITHREADING
  13. #include <pthread.h>
  14. #include <urcu.h>
  15. #endif
  16. static UA_StatusCode
  17. readCPUTemperature_broken(void *handle, const UA_NodeId nodeid, UA_Boolean sourceTimeStamp,
  18. const UA_NumericRange *range, UA_DataValue *dataValue) {
  19. dataValue->hasValue = true;
  20. return UA_STATUSCODE_GOOD;
  21. }
  22. static UA_Server* makeTestSequence(void) {
  23. UA_Server *server = UA_Server_new(UA_ServerConfig_standard);
  24. /* VariableNode */
  25. UA_VariableAttributes vattr;
  26. UA_VariableAttributes_init(&vattr);
  27. UA_Int32 myInteger = 42;
  28. UA_Variant_setScalar(&vattr.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
  29. vattr.description = UA_LOCALIZEDTEXT("locale","the answer");
  30. vattr.displayName = UA_LOCALIZEDTEXT("locale","the answer");
  31. vattr.valueRank = -2;
  32. UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, "the answer");
  33. UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "the.answer");
  34. UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
  35. UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
  36. UA_Server_addVariableNode(server, myIntegerNodeId, parentNodeId,
  37. parentReferenceNodeId, myIntegerName,
  38. UA_NODEID_NULL, vattr, NULL, NULL);
  39. /* DataSource VariableNode */
  40. UA_VariableAttributes_init(&vattr);
  41. UA_DataSource temperatureDataSource = (UA_DataSource) {
  42. .handle = NULL, .read = NULL, .write = NULL};
  43. vattr.description = UA_LOCALIZEDTEXT("en_US","temperature");
  44. vattr.displayName = UA_LOCALIZEDTEXT("en_US","temperature");
  45. UA_Server_addDataSourceVariableNode(server, UA_NODEID_STRING(1, "cpu.temperature"),
  46. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  47. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  48. UA_QUALIFIEDNAME(1, "cpu temperature"),
  49. UA_NODEID_NULL, vattr, temperatureDataSource, NULL);
  50. /* DataSource Variable returning no value */
  51. UA_DataSource temperatureDataSource1 = (UA_DataSource) {
  52. .handle = NULL, .read = readCPUTemperature_broken, .write = NULL};
  53. vattr.description = UA_LOCALIZEDTEXT("en_US","temperature1");
  54. vattr.displayName = UA_LOCALIZEDTEXT("en_US","temperature1");
  55. UA_Server_addDataSourceVariableNode(server, UA_NODEID_STRING(1, "cpu.temperature1"),
  56. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  57. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  58. UA_QUALIFIEDNAME(1, "cpu temperature bogus"),
  59. UA_NODEID_NULL, vattr, temperatureDataSource1, NULL);
  60. /* VariableNode with array */
  61. UA_VariableAttributes_init(&vattr);
  62. UA_Int32 myIntegerArray[9] = {1,2,3,4,5,6,7,8,9};
  63. UA_Variant_setArray(&vattr.value, &myIntegerArray, 9, &UA_TYPES[UA_TYPES_INT32]);
  64. UA_Int32 myIntegerDimensions[2] = {3,3};
  65. vattr.value.arrayDimensions = myIntegerDimensions;
  66. vattr.value.arrayDimensionsSize = 2;
  67. vattr.displayName = UA_LOCALIZEDTEXT("locale","myarray");
  68. myIntegerName = UA_QUALIFIEDNAME(1, "myarray");
  69. myIntegerNodeId = UA_NODEID_STRING(1, "myarray");
  70. parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
  71. parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
  72. UA_Server_addVariableNode(server, myIntegerNodeId, parentNodeId,
  73. parentReferenceNodeId, myIntegerName,
  74. UA_NODEID_NULL, vattr, NULL, NULL);
  75. /* ObjectNode */
  76. UA_ObjectAttributes obj_attr;
  77. UA_ObjectAttributes_init(&obj_attr);
  78. obj_attr.description = UA_LOCALIZEDTEXT("en_US","Demo");
  79. obj_attr.displayName = UA_LOCALIZEDTEXT("en_US","Demo");
  80. UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, 50),
  81. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  82. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  83. UA_QUALIFIEDNAME(1, "Demo"),
  84. UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE),
  85. obj_attr, NULL, NULL);
  86. /* ViewNode */
  87. UA_ViewAttributes view_attr;
  88. UA_ViewAttributes_init(&view_attr);
  89. view_attr.description = UA_LOCALIZEDTEXT("en_US", "Viewtest");
  90. view_attr.displayName = UA_LOCALIZEDTEXT("en_US", "Viewtest");
  91. UA_Server_addViewNode(server, UA_NODEID_NUMERIC(0, UA_NS0ID_VIEWNODE),
  92. UA_NODEID_NUMERIC(0, UA_NS0ID_VIEWSFOLDER),
  93. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  94. UA_QUALIFIEDNAME(0, "Viewtest"), view_attr, NULL, NULL);
  95. #ifdef UA_ENABLE_METHODCALLS
  96. /* MethodNode */
  97. UA_MethodAttributes ma;
  98. UA_MethodAttributes_init(&ma);
  99. ma.description = UA_LOCALIZEDTEXT("en_US", "Methodtest");
  100. ma.displayName = UA_LOCALIZEDTEXT("en_US", "Methodtest");
  101. UA_Server_addMethodNode(server, UA_NODEID_NUMERIC(0, UA_NS0ID_METHODNODE),
  102. UA_NODEID_NUMERIC(0, 3),
  103. UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
  104. UA_QUALIFIEDNAME_ALLOC(0, "Methodtest"), ma,
  105. NULL, NULL, 0, NULL, 0, NULL, NULL);
  106. #endif
  107. return server;
  108. }
  109. static UA_VariableNode* makeCompareSequence(void) {
  110. UA_VariableNode *node = UA_NodeStore_newVariableNode();
  111. UA_Int32 myInteger = 42;
  112. UA_Variant_setScalarCopy(&node->value.variant.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
  113. const UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, "the answer");
  114. UA_QualifiedName_copy(&myIntegerName,&node->browseName);
  115. const UA_LocalizedText myIntegerDisplName = UA_LOCALIZEDTEXT("locale", "the answer");
  116. UA_LocalizedText_copy(&myIntegerDisplName, &node->displayName);
  117. UA_LocalizedText_copy(&myIntegerDisplName, &node->description);
  118. const UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "the.answer");
  119. UA_NodeId_copy(&myIntegerNodeId,&node->nodeId);
  120. return node;
  121. }
  122. START_TEST(ReadSingleAttributeValueWithoutTimestamp) {
  123. UA_Server *server = makeTestSequence();
  124. UA_DataValue resp;
  125. UA_DataValue_init(&resp);
  126. UA_ReadRequest rReq;
  127. UA_ReadRequest_init(&rReq);
  128. rReq.nodesToRead = UA_ReadValueId_new();
  129. rReq.nodesToReadSize = 1;
  130. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  131. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_VALUE;
  132. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  133. ck_assert_int_eq(0, resp.value.arrayLength);
  134. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_INT32], resp.value.type);
  135. ck_assert_int_eq(42, *(UA_Int32* )resp.value.data);
  136. UA_Server_delete(server);
  137. UA_ReadRequest_deleteMembers(&rReq);
  138. UA_DataValue_deleteMembers(&resp);
  139. } END_TEST
  140. START_TEST(ReadSingleAttributeValueRangeWithoutTimestamp) {
  141. UA_Server *server = makeTestSequence();
  142. UA_DataValue resp;
  143. UA_DataValue_init(&resp);
  144. UA_ReadRequest rReq;
  145. UA_ReadRequest_init(&rReq);
  146. rReq.nodesToRead = UA_ReadValueId_new();
  147. rReq.nodesToReadSize = 1;
  148. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "myarray");
  149. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_VALUE;
  150. rReq.nodesToRead[0].indexRange = UA_STRING_ALLOC("1:2,0:1");
  151. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  152. ck_assert_int_eq(4, resp.value.arrayLength);
  153. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_INT32], resp.value.type);
  154. UA_Server_delete(server);
  155. UA_ReadRequest_deleteMembers(&rReq);
  156. UA_DataValue_deleteMembers(&resp);
  157. } END_TEST
  158. START_TEST(ReadSingleAttributeNodeIdWithoutTimestamp) {
  159. UA_Server *server = makeTestSequence();
  160. UA_DataValue resp;
  161. UA_DataValue_init(&resp);
  162. UA_ReadRequest rReq;
  163. UA_ReadRequest_init(&rReq);
  164. rReq.nodesToRead = UA_ReadValueId_new();
  165. rReq.nodesToReadSize = 1;
  166. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  167. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_NODEID;
  168. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  169. const UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "the.answer");
  170. ck_assert_int_eq(0, resp.value.arrayLength);
  171. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_NODEID], resp.value.type);
  172. UA_NodeId* respval = (UA_NodeId*) resp.value.data;
  173. ck_assert_int_eq(1, respval->namespaceIndex);
  174. ck_assert(UA_String_equal(&myIntegerNodeId.identifier.string, &respval->identifier.string));
  175. UA_ReadRequest_deleteMembers(&rReq);
  176. UA_DataValue_deleteMembers(&resp);
  177. UA_Server_delete(server);
  178. } END_TEST
  179. START_TEST(ReadSingleAttributeNodeClassWithoutTimestamp) {
  180. UA_Server *server = makeTestSequence();
  181. UA_DataValue resp;
  182. UA_DataValue_init(&resp);
  183. UA_ReadRequest rReq;
  184. UA_ReadRequest_init(&rReq);
  185. rReq.nodesToRead = UA_ReadValueId_new();
  186. rReq.nodesToReadSize = 1;
  187. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  188. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_NODECLASS;
  189. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  190. ck_assert_int_eq(0, resp.value.arrayLength);
  191. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_NODECLASS],resp.value.type);
  192. ck_assert_int_eq(*(UA_Int32*)resp.value.data,UA_NODECLASS_VARIABLE);
  193. UA_ReadRequest_deleteMembers(&rReq);
  194. UA_DataValue_deleteMembers(&resp);
  195. UA_Server_delete(server);
  196. } END_TEST
  197. START_TEST(ReadSingleAttributeBrowseNameWithoutTimestamp) {
  198. UA_Server *server = makeTestSequence();
  199. UA_DataValue resp;
  200. UA_DataValue_init(&resp);
  201. UA_ReadRequest rReq;
  202. UA_ReadRequest_init(&rReq);
  203. rReq.nodesToRead = UA_ReadValueId_new();
  204. rReq.nodesToReadSize = 1;
  205. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  206. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_BROWSENAME;
  207. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  208. UA_QualifiedName* respval = (UA_QualifiedName*) resp.value.data;
  209. const UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, "the answer");
  210. ck_assert_int_eq(0, resp.value.arrayLength);
  211. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_QUALIFIEDNAME], resp.value.type);
  212. ck_assert_int_eq(1, respval->namespaceIndex);
  213. ck_assert(UA_String_equal(&myIntegerName.name, &respval->name));
  214. UA_ReadRequest_deleteMembers(&rReq);
  215. UA_DataValue_deleteMembers(&resp);
  216. UA_Server_delete(server);
  217. } END_TEST
  218. START_TEST(ReadSingleAttributeDisplayNameWithoutTimestamp) {
  219. UA_Server *server = makeTestSequence();
  220. UA_DataValue resp;
  221. UA_DataValue_init(&resp);
  222. UA_ReadRequest rReq;
  223. UA_ReadRequest_init(&rReq);
  224. rReq.nodesToRead = UA_ReadValueId_new();
  225. rReq.nodesToReadSize = 1;
  226. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  227. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_DISPLAYNAME;
  228. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  229. UA_LocalizedText* respval = (UA_LocalizedText*) resp.value.data;
  230. const UA_LocalizedText comp = UA_LOCALIZEDTEXT("locale", "the answer");
  231. UA_VariableNode* compNode = makeCompareSequence();
  232. ck_assert_int_eq(0, resp.value.arrayLength);
  233. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_LOCALIZEDTEXT], resp.value.type);
  234. ck_assert(UA_String_equal(&comp.text, &respval->text));
  235. ck_assert(UA_String_equal(&compNode->displayName.locale, &respval->locale));
  236. UA_Server_delete(server);
  237. UA_ReadRequest_deleteMembers(&rReq);
  238. UA_DataValue_deleteMembers(&resp);
  239. UA_NodeStore_deleteNode((UA_Node*)compNode);
  240. } END_TEST
  241. START_TEST(ReadSingleAttributeDescriptionWithoutTimestamp) {
  242. UA_Server *server = makeTestSequence();
  243. UA_DataValue resp;
  244. UA_DataValue_init(&resp);
  245. UA_ReadRequest rReq;
  246. UA_ReadRequest_init(&rReq);
  247. rReq.nodesToRead = UA_ReadValueId_new();
  248. rReq.nodesToReadSize = 1;
  249. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  250. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_DESCRIPTION;
  251. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  252. UA_LocalizedText* respval = (UA_LocalizedText*) resp.value.data;
  253. UA_VariableNode* compNode = makeCompareSequence();
  254. ck_assert_int_eq(0, resp.value.arrayLength);
  255. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_LOCALIZEDTEXT], resp.value.type);
  256. ck_assert(UA_String_equal(&compNode->description.locale, &respval->locale));
  257. ck_assert(UA_String_equal(&compNode->description.text, &respval->text));
  258. UA_ReadRequest_deleteMembers(&rReq);
  259. UA_DataValue_deleteMembers(&resp);
  260. UA_NodeStore_deleteNode((UA_Node*)compNode);
  261. UA_Server_delete(server);
  262. } END_TEST
  263. START_TEST(ReadSingleAttributeWriteMaskWithoutTimestamp) {
  264. UA_Server *server = makeTestSequence();
  265. UA_DataValue resp;
  266. UA_DataValue_init(&resp);
  267. UA_ReadRequest rReq;
  268. UA_ReadRequest_init(&rReq);
  269. rReq.nodesToRead = UA_ReadValueId_new();
  270. rReq.nodesToReadSize = 1;
  271. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  272. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_WRITEMASK;
  273. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  274. UA_UInt32* respval = (UA_UInt32*) resp.value.data;
  275. ck_assert_int_eq(0, resp.value.arrayLength);
  276. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_UINT32], resp.value.type);
  277. ck_assert_int_eq(0,*respval);
  278. UA_ReadRequest_deleteMembers(&rReq);
  279. UA_DataValue_deleteMembers(&resp);
  280. UA_Server_delete(server);
  281. } END_TEST
  282. START_TEST(ReadSingleAttributeUserWriteMaskWithoutTimestamp) {
  283. UA_Server *server = makeTestSequence();
  284. UA_DataValue resp;
  285. UA_DataValue_init(&resp);
  286. UA_ReadRequest rReq;
  287. UA_ReadRequest_init(&rReq);
  288. rReq.nodesToRead = UA_ReadValueId_new();
  289. rReq.nodesToReadSize = 1;
  290. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  291. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_USERWRITEMASK;
  292. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  293. UA_UInt32* respval = (UA_UInt32*) resp.value.data;
  294. ck_assert_int_eq(0, resp.value.arrayLength);
  295. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_UINT32], resp.value.type);
  296. ck_assert_int_eq(0,*respval);
  297. UA_ReadRequest_deleteMembers(&rReq);
  298. UA_DataValue_deleteMembers(&resp);
  299. UA_Server_delete(server);
  300. } END_TEST
  301. START_TEST(ReadSingleAttributeIsAbstractWithoutTimestamp) {
  302. UA_Server *server = makeTestSequence();
  303. UA_DataValue resp;
  304. UA_DataValue_init(&resp);
  305. UA_ReadRequest rReq;
  306. UA_ReadRequest_init(&rReq);
  307. rReq.nodesToRead = UA_ReadValueId_new();
  308. rReq.nodesToReadSize = 1;
  309. rReq.nodesToRead[0].nodeId.identifier.numeric = UA_NS0ID_ORGANIZES;
  310. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_ISABSTRACT;
  311. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  312. ck_assert_int_eq(0, resp.value.arrayLength);
  313. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BOOLEAN], resp.value.type);
  314. ck_assert(*(UA_Boolean* )resp.value.data==false);
  315. UA_ReadRequest_deleteMembers(&rReq);
  316. UA_DataValue_deleteMembers(&resp);
  317. UA_Server_delete(server);
  318. } END_TEST
  319. START_TEST(ReadSingleAttributeSymmetricWithoutTimestamp) {
  320. UA_Server *server = makeTestSequence();
  321. UA_DataValue resp;
  322. UA_DataValue_init(&resp);
  323. UA_ReadRequest rReq;
  324. UA_ReadRequest_init(&rReq);
  325. rReq.nodesToRead = UA_ReadValueId_new();
  326. rReq.nodesToReadSize = 1;
  327. rReq.nodesToRead[0].nodeId.identifier.numeric = UA_NS0ID_ORGANIZES;
  328. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_SYMMETRIC;
  329. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  330. ck_assert_int_eq(0, resp.value.arrayLength);
  331. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BOOLEAN], resp.value.type);
  332. ck_assert(*(UA_Boolean* )resp.value.data==false);
  333. UA_ReadRequest_deleteMembers(&rReq);
  334. UA_DataValue_deleteMembers(&resp);
  335. UA_Server_delete(server);
  336. } END_TEST
  337. START_TEST(ReadSingleAttributeInverseNameWithoutTimestamp) {
  338. UA_Server *server = makeTestSequence();
  339. UA_DataValue resp;
  340. UA_DataValue_init(&resp);
  341. UA_ReadRequest rReq;
  342. UA_ReadRequest_init(&rReq);
  343. rReq.nodesToRead = UA_ReadValueId_new();
  344. rReq.nodesToReadSize = 1;
  345. rReq.nodesToRead[0].nodeId.identifier.numeric = UA_NS0ID_ORGANIZES;
  346. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_INVERSENAME;
  347. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  348. UA_LocalizedText* respval = (UA_LocalizedText*) resp.value.data;
  349. const UA_LocalizedText comp = UA_LOCALIZEDTEXT("en_US", "OrganizedBy");
  350. ck_assert_int_eq(0, resp.value.arrayLength);
  351. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_LOCALIZEDTEXT],resp.value.type);
  352. ck_assert(UA_String_equal(&comp.text, &respval->text));
  353. ck_assert(UA_String_equal(&comp.locale, &respval->locale));
  354. UA_ReadRequest_deleteMembers(&rReq);
  355. UA_DataValue_deleteMembers(&resp);
  356. UA_Server_delete(server);
  357. } END_TEST
  358. START_TEST(ReadSingleAttributeContainsNoLoopsWithoutTimestamp) {
  359. UA_Server *server = makeTestSequence();
  360. UA_DataValue resp;
  361. UA_DataValue_init(&resp);
  362. UA_ReadRequest rReq;
  363. UA_ReadRequest_init(&rReq);
  364. rReq.nodesToRead = UA_ReadValueId_new();
  365. rReq.nodesToReadSize = 1;
  366. rReq.nodesToRead[0].nodeId.identifier.numeric = UA_NS0ID_VIEWNODE;
  367. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_CONTAINSNOLOOPS;
  368. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  369. ck_assert_int_eq(0, resp.value.arrayLength);
  370. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BOOLEAN], resp.value.type);
  371. ck_assert(*(UA_Boolean* )resp.value.data==false);
  372. UA_ReadRequest_deleteMembers(&rReq);
  373. UA_DataValue_deleteMembers(&resp);
  374. UA_Server_delete(server);
  375. } END_TEST
  376. START_TEST(ReadSingleAttributeEventNotifierWithoutTimestamp) {
  377. UA_Server *server = makeTestSequence();
  378. UA_DataValue resp;
  379. UA_DataValue_init(&resp);
  380. UA_ReadRequest rReq;
  381. UA_ReadRequest_init(&rReq);
  382. rReq.nodesToRead = UA_ReadValueId_new();
  383. rReq.nodesToReadSize = 1;
  384. rReq.nodesToRead[0].nodeId = UA_NODEID_NUMERIC(1, 50);
  385. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_EVENTNOTIFIER;
  386. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  387. ck_assert_int_eq(UA_STATUSCODE_GOOD, resp.status);
  388. ck_assert_int_eq(0, resp.value.arrayLength);
  389. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BYTE],resp.value.type);
  390. ck_assert_int_eq(*(UA_Byte*)resp.value.data, 0);
  391. UA_ReadRequest_deleteMembers(&rReq);
  392. UA_DataValue_deleteMembers(&resp);
  393. UA_Server_delete(server);
  394. } END_TEST
  395. START_TEST(ReadSingleAttributeDataTypeWithoutTimestamp) {
  396. UA_Server *server = makeTestSequence();
  397. UA_DataValue resp;
  398. UA_DataValue_init(&resp);
  399. UA_ReadRequest rReq;
  400. UA_ReadRequest_init(&rReq);
  401. rReq.nodesToRead = UA_ReadValueId_new();
  402. rReq.nodesToReadSize = 1;
  403. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  404. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_DATATYPE;
  405. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  406. UA_NodeId* respval = (UA_NodeId*) resp.value.data;
  407. ck_assert_int_eq(0, resp.value.arrayLength);
  408. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_NODEID], resp.value.type);
  409. ck_assert_int_eq(respval->namespaceIndex,0);
  410. ck_assert_int_eq(respval->identifier.numeric,UA_NS0ID_INT32);
  411. UA_ReadRequest_deleteMembers(&rReq);
  412. UA_DataValue_deleteMembers(&resp);
  413. UA_Server_delete(server);
  414. } END_TEST
  415. START_TEST(ReadSingleAttributeValueRankWithoutTimestamp) {
  416. UA_Server *server = makeTestSequence();
  417. UA_DataValue resp;
  418. UA_DataValue_init(&resp);
  419. UA_ReadRequest rReq;
  420. UA_ReadRequest_init(&rReq);
  421. rReq.nodesToRead = UA_ReadValueId_new();
  422. rReq.nodesToReadSize = 1;
  423. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  424. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_VALUERANK;
  425. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  426. ck_assert_int_eq(0, resp.value.arrayLength);
  427. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_INT32], resp.value.type);
  428. ck_assert_int_eq(-2, *(UA_Int32* )resp.value.data);
  429. UA_ReadRequest_deleteMembers(&rReq);
  430. UA_DataValue_deleteMembers(&resp);
  431. UA_Server_delete(server);
  432. } END_TEST
  433. START_TEST(ReadSingleAttributeArrayDimensionsWithoutTimestamp) {
  434. UA_Server *server = makeTestSequence();
  435. UA_DataValue resp;
  436. UA_DataValue_init(&resp);
  437. UA_ReadRequest rReq;
  438. UA_ReadRequest_init(&rReq);
  439. rReq.nodesToRead = UA_ReadValueId_new();
  440. rReq.nodesToReadSize = 1;
  441. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  442. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_ARRAYDIMENSIONS;
  443. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  444. ck_assert_int_eq(0, resp.value.arrayLength);
  445. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_INT32], resp.value.type);
  446. ck_assert_ptr_eq((UA_Int32*)resp.value.data,0);
  447. UA_DataValue_deleteMembers(&resp);
  448. UA_ReadRequest_deleteMembers(&rReq);
  449. UA_Server_delete(server);
  450. } END_TEST
  451. START_TEST(ReadSingleAttributeAccessLevelWithoutTimestamp) {
  452. UA_Server *server = makeTestSequence();
  453. UA_DataValue resp;
  454. UA_DataValue_init(&resp);
  455. UA_ReadRequest rReq;
  456. UA_ReadRequest_init(&rReq);
  457. rReq.nodesToRead = UA_ReadValueId_new();
  458. rReq.nodesToReadSize = 1;
  459. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  460. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_ACCESSLEVEL;
  461. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  462. ck_assert_int_eq(0, resp.value.arrayLength);
  463. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BYTE], resp.value.type);
  464. ck_assert_int_eq(*(UA_Byte*)resp.value.data, 0);
  465. UA_DataValue_deleteMembers(&resp);
  466. UA_ReadRequest_deleteMembers(&rReq);
  467. UA_Server_delete(server);
  468. } END_TEST
  469. START_TEST(ReadSingleAttributeUserAccessLevelWithoutTimestamp) {
  470. UA_Server *server = makeTestSequence();
  471. UA_DataValue resp;
  472. UA_DataValue_init(&resp);
  473. UA_ReadRequest rReq;
  474. UA_ReadRequest_init(&rReq);
  475. rReq.nodesToRead = UA_ReadValueId_new();
  476. rReq.nodesToReadSize = 1;
  477. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  478. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_USERACCESSLEVEL;
  479. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  480. const UA_VariableNode* compNode =
  481. (const UA_VariableNode*)UA_NodeStore_get(server->nodestore, &rReq.nodesToRead[0].nodeId);
  482. ck_assert_int_eq(0, resp.value.arrayLength);
  483. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BYTE], resp.value.type);
  484. ck_assert_int_eq(*(UA_Byte*)resp.value.data, compNode->userAccessLevel);
  485. UA_Server_delete(server);
  486. UA_DataValue_deleteMembers(&resp);
  487. UA_ReadRequest_deleteMembers(&rReq);
  488. } END_TEST
  489. START_TEST(ReadSingleAttributeMinimumSamplingIntervalWithoutTimestamp) {
  490. UA_Server *server = makeTestSequence();
  491. UA_DataValue resp;
  492. UA_DataValue_init(&resp);
  493. UA_ReadRequest rReq;
  494. UA_ReadRequest_init(&rReq);
  495. rReq.nodesToRead = UA_ReadValueId_new();
  496. rReq.nodesToReadSize = 1;
  497. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  498. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL;
  499. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  500. UA_Double* respval = (UA_Double*) resp.value.data;
  501. UA_VariableNode *compNode = makeCompareSequence();
  502. UA_Double comp = (UA_Double) compNode->minimumSamplingInterval;
  503. ck_assert_int_eq(0, resp.value.arrayLength);
  504. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_DOUBLE], resp.value.type);
  505. ck_assert(*respval == comp);
  506. UA_DataValue_deleteMembers(&resp);
  507. UA_ReadRequest_deleteMembers(&rReq);
  508. UA_NodeStore_deleteNode((UA_Node*)compNode);
  509. UA_Server_delete(server);
  510. } END_TEST
  511. START_TEST(ReadSingleAttributeHistorizingWithoutTimestamp) {
  512. UA_Server *server = makeTestSequence();
  513. UA_DataValue resp;
  514. UA_DataValue_init(&resp);
  515. UA_ReadRequest rReq;
  516. UA_ReadRequest_init(&rReq);
  517. rReq.nodesToRead = UA_ReadValueId_new();
  518. rReq.nodesToReadSize = 1;
  519. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.answer");
  520. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_HISTORIZING;
  521. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  522. ck_assert_int_eq(0, resp.value.arrayLength);
  523. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BOOLEAN], resp.value.type);
  524. ck_assert(*(UA_Boolean*)resp.value.data==false);
  525. UA_ReadRequest_deleteMembers(&rReq);
  526. UA_DataValue_deleteMembers(&resp);
  527. UA_Server_delete(server);
  528. } END_TEST
  529. START_TEST(ReadSingleAttributeExecutableWithoutTimestamp) {
  530. #ifdef UA_ENABLE_METHODCALLS
  531. UA_Server *server = makeTestSequence();
  532. UA_DataValue resp;
  533. UA_DataValue_init(&resp);
  534. UA_ReadRequest rReq;
  535. UA_ReadRequest_init(&rReq);
  536. rReq.nodesToRead = UA_ReadValueId_new();
  537. rReq.nodesToReadSize = 1;
  538. rReq.nodesToRead[0].nodeId.identifier.numeric = UA_NS0ID_METHODNODE;
  539. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_EXECUTABLE;
  540. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  541. ck_assert_int_eq(0, resp.value.arrayLength);
  542. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BOOLEAN], resp.value.type);
  543. ck_assert(*(UA_Boolean*)resp.value.data==false);
  544. UA_DataValue_deleteMembers(&resp);
  545. UA_ReadRequest_deleteMembers(&rReq);
  546. UA_Server_delete(server);
  547. #endif
  548. } END_TEST
  549. START_TEST(ReadSingleAttributeUserExecutableWithoutTimestamp) {
  550. #ifdef UA_ENABLE_METHODCALLS
  551. UA_Server *server = makeTestSequence();
  552. UA_DataValue resp;
  553. UA_DataValue_init(&resp);
  554. UA_ReadRequest rReq;
  555. UA_ReadRequest_init(&rReq);
  556. rReq.nodesToRead = UA_ReadValueId_new();
  557. rReq.nodesToReadSize = 1;
  558. rReq.nodesToRead[0].nodeId.identifier.numeric = UA_NS0ID_METHODNODE;
  559. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_USEREXECUTABLE;
  560. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  561. ck_assert_int_eq(0, resp.value.arrayLength);
  562. ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BOOLEAN], resp.value.type);
  563. ck_assert(*(UA_Boolean*)resp.value.data==false);
  564. UA_DataValue_deleteMembers(&resp);
  565. UA_ReadRequest_deleteMembers(&rReq);
  566. UA_Server_delete(server);
  567. #endif
  568. } END_TEST
  569. START_TEST(ReadSingleDataSourceAttributeDataTypeWithoutTimestampFromBrokenSource) {
  570. UA_Server *server = makeTestSequence();
  571. UA_DataValue resp;
  572. UA_DataValue_init(&resp);
  573. UA_ReadRequest rReq;
  574. UA_ReadRequest_init(&rReq);
  575. rReq.nodesToRead = UA_ReadValueId_new();
  576. rReq.nodesToReadSize = 1;
  577. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "cpu.temperature1");
  578. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_DATATYPE;
  579. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  580. ck_assert_int_eq(UA_STATUSCODE_GOOD, resp.status);
  581. UA_Server_delete(server);
  582. UA_ReadRequest_deleteMembers(&rReq);
  583. UA_DataValue_deleteMembers(&resp);
  584. } END_TEST
  585. START_TEST(ReadSingleDataSourceAttributeValueWithoutTimestamp) {
  586. UA_Server *server = makeTestSequence();
  587. UA_DataValue resp;
  588. UA_DataValue_init(&resp);
  589. UA_ReadRequest rReq;
  590. UA_ReadRequest_init(&rReq);
  591. rReq.nodesToRead = UA_ReadValueId_new();
  592. rReq.nodesToReadSize = 1;
  593. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "cpu.temperature");
  594. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_VALUE;
  595. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  596. ck_assert_int_eq(UA_STATUSCODE_BADINTERNALERROR, resp.status);
  597. UA_Server_delete(server);
  598. UA_ReadRequest_deleteMembers(&rReq);
  599. UA_DataValue_deleteMembers(&resp);
  600. } END_TEST
  601. START_TEST(ReadSingleDataSourceAttributeDataTypeWithoutTimestamp) {
  602. UA_Server *server = makeTestSequence();
  603. UA_DataValue resp;
  604. UA_DataValue_init(&resp);
  605. UA_ReadRequest rReq;
  606. UA_ReadRequest_init(&rReq);
  607. rReq.nodesToRead = UA_ReadValueId_new();
  608. rReq.nodesToReadSize = 1;
  609. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "cpu.temperature");
  610. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_DATATYPE;
  611. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  612. ck_assert_int_eq(UA_STATUSCODE_BADINTERNALERROR, resp.status);
  613. UA_Server_delete(server);
  614. UA_ReadRequest_deleteMembers(&rReq);
  615. UA_DataValue_deleteMembers(&resp);
  616. } END_TEST
  617. START_TEST (ReadSingleDataSourceAttributeArrayDimensionsWithoutTimestamp) {
  618. UA_Server *server = makeTestSequence();
  619. UA_DataValue resp;
  620. UA_DataValue_init(&resp);
  621. UA_ReadRequest rReq;
  622. UA_ReadRequest_init(&rReq);
  623. rReq.nodesToRead = UA_ReadValueId_new();
  624. rReq.nodesToReadSize = 1;
  625. rReq.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "cpu.temperature");
  626. rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_ARRAYDIMENSIONS;
  627. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0], &resp);
  628. ck_assert_int_eq(UA_STATUSCODE_BADINTERNALERROR, resp.status);
  629. UA_Server_delete(server);
  630. UA_ReadRequest_deleteMembers(&rReq);
  631. UA_DataValue_deleteMembers(&resp);
  632. } END_TEST
  633. /* Tests for writeValue method */
  634. START_TEST(WriteSingleAttributeNodeId) {
  635. UA_Server *server = makeTestSequence();
  636. UA_WriteValue wValue;
  637. UA_WriteValue_init(&wValue);
  638. UA_NodeId id;
  639. UA_NodeId_init(&id);
  640. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  641. wValue.attributeId = UA_ATTRIBUTEID_NODEID;
  642. wValue.value.hasValue = true;
  643. UA_Variant_setScalar(&wValue.value.value, &id, &UA_TYPES[UA_TYPES_NODEID]);
  644. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  645. ck_assert_int_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  646. UA_Server_delete(server);
  647. } END_TEST
  648. START_TEST(WriteSingleAttributeNodeclass) {
  649. UA_Server *server = makeTestSequence();
  650. UA_WriteValue wValue;
  651. UA_WriteValue_init(&wValue);
  652. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  653. UA_NodeClass class;
  654. UA_NodeClass_init(&class);
  655. wValue.attributeId = UA_ATTRIBUTEID_NODECLASS;
  656. wValue.value.hasValue = true;
  657. UA_Variant_setScalar(&wValue.value.value, &class, &UA_TYPES[UA_TYPES_NODECLASS]);
  658. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  659. ck_assert_int_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  660. UA_Server_delete(server);
  661. } END_TEST
  662. START_TEST(WriteSingleAttributeBrowseName) {
  663. UA_Server *server = makeTestSequence();
  664. UA_WriteValue wValue;
  665. UA_WriteValue_init(&wValue);
  666. UA_QualifiedName testValue = UA_QUALIFIEDNAME(1, "the.answer");
  667. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_QUALIFIEDNAME]);
  668. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  669. wValue.attributeId = UA_ATTRIBUTEID_BROWSENAME;
  670. wValue.value.hasValue = true;
  671. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  672. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  673. UA_Server_delete(server);
  674. } END_TEST
  675. START_TEST(WriteSingleAttributeDisplayName) {
  676. UA_Server *server = makeTestSequence();
  677. UA_WriteValue wValue;
  678. UA_WriteValue_init(&wValue);
  679. UA_LocalizedText testValue = UA_LOCALIZEDTEXT("en_EN", "the.answer");
  680. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_LOCALIZEDTEXT]);
  681. wValue.value.hasValue = true;
  682. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  683. wValue.attributeId = UA_ATTRIBUTEID_DISPLAYNAME;
  684. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  685. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  686. UA_Server_delete(server);
  687. } END_TEST
  688. START_TEST(WriteSingleAttributeDescription) {
  689. UA_Server *server = makeTestSequence();
  690. UA_WriteValue wValue;
  691. UA_WriteValue_init(&wValue);
  692. UA_LocalizedText testValue = UA_LOCALIZEDTEXT("en_EN", "the.answer");
  693. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_LOCALIZEDTEXT]);
  694. wValue.value.hasValue = true;
  695. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  696. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  697. wValue.attributeId = UA_ATTRIBUTEID_DESCRIPTION;
  698. wValue.value.hasValue = true;
  699. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  700. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  701. UA_Server_delete(server);
  702. } END_TEST
  703. START_TEST(WriteSingleAttributeWriteMask) {
  704. UA_Server *server = makeTestSequence();
  705. UA_WriteValue wValue;
  706. UA_WriteValue_init(&wValue);
  707. UA_Int32 testValue = 0;
  708. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_UINT32]);
  709. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  710. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  711. wValue.attributeId = UA_ATTRIBUTEID_WRITEMASK;
  712. wValue.value.hasValue = true;
  713. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  714. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  715. UA_Server_delete(server);
  716. } END_TEST
  717. START_TEST(WriteSingleAttributeUserWriteMask) {
  718. UA_Server *server = makeTestSequence();
  719. UA_WriteValue wValue;
  720. UA_WriteValue_init(&wValue);
  721. UA_Int32 testValue = 0;
  722. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_UINT32]);
  723. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  724. wValue.attributeId = UA_ATTRIBUTEID_USERWRITEMASK;
  725. wValue.value.hasValue = true;
  726. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  727. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  728. UA_Server_delete(server);
  729. } END_TEST
  730. START_TEST(WriteSingleAttributeIsAbstract) {
  731. UA_Server *server = makeTestSequence();
  732. UA_WriteValue wValue;
  733. UA_WriteValue_init(&wValue);
  734. UA_Boolean testValue = true;
  735. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BOOLEAN]);
  736. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  737. wValue.attributeId = UA_ATTRIBUTEID_ISABSTRACT;
  738. wValue.value.hasValue = true;
  739. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  740. ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
  741. UA_Server_delete(server);
  742. } END_TEST
  743. START_TEST(WriteSingleAttributeSymmetric) {
  744. UA_Server *server = makeTestSequence();
  745. UA_WriteValue wValue;
  746. UA_WriteValue_init(&wValue);
  747. UA_Boolean testValue = true;
  748. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BOOLEAN]);
  749. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  750. wValue.attributeId = UA_ATTRIBUTEID_SYMMETRIC;
  751. wValue.value.hasValue = true;
  752. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  753. ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
  754. UA_Server_delete(server);
  755. } END_TEST
  756. START_TEST(WriteSingleAttributeInverseName) {
  757. UA_Server *server = makeTestSequence();
  758. UA_WriteValue wValue;
  759. UA_WriteValue_init(&wValue);
  760. UA_LocalizedText testValue = UA_LOCALIZEDTEXT("en_US", "not.the.answer");
  761. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_LOCALIZEDTEXT]);
  762. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  763. wValue.attributeId = UA_ATTRIBUTEID_INVERSENAME;
  764. wValue.value.hasValue = true;
  765. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  766. ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
  767. UA_Server_delete(server);
  768. } END_TEST
  769. START_TEST(WriteSingleAttributeContainsNoLoops) {
  770. UA_Server *server = makeTestSequence();
  771. UA_WriteValue wValue;
  772. UA_WriteValue_init(&wValue);
  773. UA_Boolean testValue = true;
  774. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BOOLEAN]);
  775. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  776. wValue.attributeId = UA_ATTRIBUTEID_CONTAINSNOLOOPS;
  777. wValue.value.hasValue = true;
  778. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  779. ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
  780. UA_Server_delete(server);
  781. } END_TEST
  782. START_TEST(WriteSingleAttributeEventNotifier) {
  783. UA_Server *server = makeTestSequence();
  784. UA_WriteValue wValue;
  785. UA_WriteValue_init(&wValue);
  786. UA_Byte testValue = 0;
  787. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BYTE]);
  788. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  789. wValue.attributeId = UA_ATTRIBUTEID_EVENTNOTIFIER;
  790. wValue.value.hasValue = true;
  791. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  792. ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
  793. UA_Server_delete(server);
  794. } END_TEST
  795. START_TEST(WriteSingleAttributeValue) {
  796. UA_Server *server = makeTestSequence();
  797. UA_WriteValue wValue;
  798. UA_WriteValue_init(&wValue);
  799. UA_Int32 myInteger = 20;
  800. UA_Variant_setScalar(&wValue.value.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
  801. wValue.value.hasValue = true;
  802. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  803. wValue.attributeId = UA_ATTRIBUTEID_VALUE;
  804. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  805. UA_DataValue resp;
  806. UA_DataValue_init(&resp);
  807. UA_ReadValueId id;
  808. UA_ReadValueId_init(&id);
  809. id.nodeId = UA_NODEID_STRING(1, "the.answer");
  810. id.attributeId = UA_ATTRIBUTEID_VALUE;
  811. Service_Read_single(server, &adminSession, UA_TIMESTAMPSTORETURN_NEITHER, &id, &resp);
  812. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  813. ck_assert(wValue.value.hasValue);
  814. ck_assert_int_eq(20, *(UA_Int32*)resp.value.data);
  815. UA_DataValue_deleteMembers(&resp);
  816. UA_Server_delete(server);
  817. } END_TEST
  818. START_TEST(WriteSingleAttributeDataType) {
  819. UA_Server *server = makeTestSequence();
  820. UA_WriteValue wValue;
  821. UA_WriteValue_init(&wValue);
  822. UA_NodeId typeId;
  823. UA_NodeId_init(&typeId);
  824. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  825. wValue.attributeId = UA_ATTRIBUTEID_DATATYPE;
  826. wValue.value.hasValue = true;
  827. UA_Variant_setScalar(&wValue.value.value, &typeId, &UA_TYPES[UA_TYPES_NODEID]);
  828. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  829. ck_assert_int_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  830. UA_Server_delete(server);
  831. } END_TEST
  832. START_TEST(WriteSingleAttributeValueRank) {
  833. UA_Server *server = makeTestSequence();
  834. UA_WriteValue wValue;
  835. UA_WriteValue_init(&wValue);
  836. UA_Int32 testValue = -1;
  837. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_INT32]);
  838. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  839. wValue.attributeId = UA_ATTRIBUTEID_VALUERANK;
  840. wValue.value.hasValue = true;
  841. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  842. // Returns attributeInvalid, since variant/value may be writable
  843. ck_assert_int_eq(retval, UA_STATUSCODE_BADATTRIBUTEIDINVALID);
  844. UA_Server_delete(server);
  845. } END_TEST
  846. START_TEST(WriteSingleAttributeArrayDimensions) {
  847. UA_Server *server = makeTestSequence();
  848. UA_WriteValue wValue;
  849. UA_WriteValue_init(&wValue);
  850. UA_Int32 testValue[] = {-1,-1,-1};
  851. UA_Variant_setArray(&wValue.value.value, &testValue, 3, &UA_TYPES[UA_TYPES_INT32]);
  852. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  853. wValue.attributeId = UA_ATTRIBUTEID_ARRAYDIMENSIONS;
  854. wValue.value.hasValue = true;
  855. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  856. // Returns attributeInvalid, since variant/value may be writable
  857. ck_assert_int_eq(retval, UA_STATUSCODE_BADATTRIBUTEIDINVALID);
  858. UA_Server_delete(server);
  859. } END_TEST
  860. START_TEST(WriteSingleAttributeAccessLevel) {
  861. UA_Server *server = makeTestSequence();
  862. UA_WriteValue wValue;
  863. UA_WriteValue_init(&wValue);
  864. UA_Byte testValue = 0;
  865. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BYTE]);
  866. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  867. wValue.attributeId = UA_ATTRIBUTEID_ACCESSLEVEL;
  868. wValue.value.hasValue = true;
  869. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  870. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  871. UA_Server_delete(server);
  872. } END_TEST
  873. START_TEST(WriteSingleAttributeUserAccessLevel) {
  874. UA_Server *server = makeTestSequence();
  875. UA_WriteValue wValue;
  876. UA_WriteValue_init(&wValue);
  877. UA_Byte testValue = 0;
  878. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BYTE]);
  879. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  880. wValue.attributeId = UA_ATTRIBUTEID_USERACCESSLEVEL;
  881. wValue.value.hasValue = true;
  882. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  883. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  884. UA_Server_delete(server);
  885. } END_TEST
  886. START_TEST(WriteSingleAttributeMinimumSamplingInterval) {
  887. UA_Server *server = makeTestSequence();
  888. UA_WriteValue wValue;
  889. UA_WriteValue_init(&wValue);
  890. UA_Double testValue = 0.0;
  891. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_DOUBLE]);
  892. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  893. wValue.attributeId = UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL;
  894. wValue.value.hasValue = true;
  895. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  896. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  897. UA_Server_delete(server);
  898. } END_TEST
  899. START_TEST(WriteSingleAttributeHistorizing) {
  900. UA_Server *server = makeTestSequence();
  901. UA_WriteValue wValue;
  902. UA_WriteValue_init(&wValue);
  903. UA_Boolean testValue = true;
  904. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BOOLEAN]);
  905. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  906. wValue.attributeId = UA_ATTRIBUTEID_HISTORIZING;
  907. wValue.value.hasValue = true;
  908. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  909. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  910. UA_Server_delete(server);
  911. } END_TEST
  912. START_TEST(WriteSingleAttributeExecutable) {
  913. UA_Server *server = makeTestSequence();
  914. UA_WriteValue wValue;
  915. UA_WriteValue_init(&wValue);
  916. UA_Boolean testValue = true;
  917. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BOOLEAN]);
  918. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  919. wValue.attributeId = UA_ATTRIBUTEID_EXECUTABLE;
  920. wValue.value.hasValue = true;
  921. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  922. ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
  923. UA_Server_delete(server);
  924. } END_TEST
  925. START_TEST(WriteSingleAttributeUserExecutable) {
  926. UA_Server *server = makeTestSequence();
  927. UA_WriteValue wValue;
  928. UA_WriteValue_init(&wValue);
  929. UA_Boolean testValue = true;
  930. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BOOLEAN]);
  931. wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
  932. wValue.attributeId = UA_ATTRIBUTEID_USEREXECUTABLE;
  933. wValue.value.hasValue = true;
  934. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  935. ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
  936. UA_Server_delete(server);
  937. } END_TEST
  938. START_TEST(WriteSingleDataSourceAttributeValue) {
  939. UA_Server *server = makeTestSequence();
  940. UA_WriteValue wValue;
  941. UA_WriteValue_init(&wValue);
  942. UA_Int32 testValue = 0;
  943. UA_Variant_setScalar(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_INT32]);
  944. wValue.nodeId = UA_NODEID_STRING(1, "cpu.temperature");
  945. wValue.attributeId = UA_ATTRIBUTEID_VALUE;
  946. wValue.value.hasValue = true;
  947. UA_StatusCode retval = Service_Write_single(server, &adminSession, &wValue);
  948. ck_assert_int_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  949. UA_Server_delete(server);
  950. } END_TEST
  951. static Suite * testSuite_services_attributes(void) {
  952. Suite *s = suite_create("services_attributes_read");
  953. TCase *tc_readSingleAttributes = tcase_create("readSingleAttributes");
  954. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeValueWithoutTimestamp);
  955. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeValueRangeWithoutTimestamp);
  956. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeNodeIdWithoutTimestamp);
  957. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeNodeClassWithoutTimestamp);
  958. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeBrowseNameWithoutTimestamp);
  959. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeDisplayNameWithoutTimestamp);
  960. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeDescriptionWithoutTimestamp);
  961. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeWriteMaskWithoutTimestamp);
  962. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeUserWriteMaskWithoutTimestamp);
  963. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeIsAbstractWithoutTimestamp);
  964. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeSymmetricWithoutTimestamp);
  965. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeInverseNameWithoutTimestamp);
  966. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeContainsNoLoopsWithoutTimestamp);
  967. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeEventNotifierWithoutTimestamp);
  968. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeDataTypeWithoutTimestamp);
  969. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeValueRankWithoutTimestamp);
  970. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeArrayDimensionsWithoutTimestamp);
  971. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeAccessLevelWithoutTimestamp);
  972. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeUserAccessLevelWithoutTimestamp);
  973. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeMinimumSamplingIntervalWithoutTimestamp);
  974. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeHistorizingWithoutTimestamp);
  975. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeExecutableWithoutTimestamp);
  976. tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeUserExecutableWithoutTimestamp);
  977. tcase_add_test(tc_readSingleAttributes, ReadSingleDataSourceAttributeDataTypeWithoutTimestampFromBrokenSource);
  978. tcase_add_test(tc_readSingleAttributes, ReadSingleDataSourceAttributeValueWithoutTimestamp);
  979. tcase_add_test(tc_readSingleAttributes, ReadSingleDataSourceAttributeDataTypeWithoutTimestamp);
  980. tcase_add_test(tc_readSingleAttributes, ReadSingleDataSourceAttributeArrayDimensionsWithoutTimestamp);
  981. suite_add_tcase(s, tc_readSingleAttributes);
  982. TCase *tc_writeSingleAttributes = tcase_create("writeSingleAttributes");
  983. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeNodeId);
  984. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeNodeclass);
  985. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeBrowseName);
  986. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeDisplayName);
  987. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeDescription);
  988. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeWriteMask);
  989. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeUserWriteMask);
  990. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeIsAbstract);
  991. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeSymmetric);
  992. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeInverseName);
  993. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeContainsNoLoops);
  994. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeEventNotifier);
  995. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeValue);
  996. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeDataType);
  997. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeValueRank);
  998. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeArrayDimensions);
  999. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeAccessLevel);
  1000. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeUserAccessLevel);
  1001. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeMinimumSamplingInterval);
  1002. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeHistorizing);
  1003. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeExecutable);
  1004. tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeUserExecutable);
  1005. tcase_add_test(tc_writeSingleAttributes, WriteSingleDataSourceAttributeValue);
  1006. suite_add_tcase(s, tc_writeSingleAttributes);
  1007. return s;
  1008. }
  1009. int main(void) {
  1010. int number_failed = 0;
  1011. Suite *s;
  1012. s = testSuite_services_attributes();
  1013. SRunner *sr = srunner_create(s);
  1014. srunner_set_fork_status(sr, CK_NOFORK);
  1015. srunner_run_all(sr, CK_NORMAL);
  1016. number_failed += srunner_ntests_failed(sr);
  1017. srunner_free(sr);
  1018. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  1019. }