check_services_attributes.c 44 KB

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