check_services_attributes.c 48 KB

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