check_services_nodemanagement.c 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. START_TEST(AddVariableNode) {
  18. UA_Server *server = UA_Server_new(UA_ServerConfig_standard);
  19. /* add a variable node to the address space */
  20. UA_VariableAttributes attr;
  21. UA_VariableAttributes_init(&attr);
  22. UA_Int32 myInteger = 42;
  23. UA_Variant_setScalar(&attr.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
  24. attr.description = UA_LOCALIZEDTEXT("en_US","the answer");
  25. attr.displayName = UA_LOCALIZEDTEXT("en_US","the answer");
  26. UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "the.answer");
  27. UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, "the answer");
  28. UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
  29. UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
  30. UA_StatusCode res = UA_Server_addVariableNode(server, myIntegerNodeId, parentNodeId, parentReferenceNodeId,
  31. myIntegerName, UA_NODEID_NULL, attr, NULL);
  32. ck_assert_int_eq(UA_STATUSCODE_GOOD, res);
  33. UA_Server_delete(server);
  34. } END_TEST
  35. START_TEST(AddNodeTwiceGivesError) {
  36. UA_Server *server = UA_Server_new(UA_ServerConfig_standard);
  37. /* add a variable node to the address space */
  38. UA_VariableAttributes attr;
  39. UA_VariableAttributes_init(&attr);
  40. UA_Int32 myInteger = 42;
  41. UA_Variant_setScalar(&attr.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
  42. attr.description = UA_LOCALIZEDTEXT("en_US","the answer");
  43. attr.displayName = UA_LOCALIZEDTEXT("en_US","the answer");
  44. UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "the.answer");
  45. UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, "the answer");
  46. UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
  47. UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
  48. UA_StatusCode res = UA_Server_addVariableNode(server, myIntegerNodeId, parentNodeId, parentReferenceNodeId,
  49. myIntegerName, UA_NODEID_NULL, attr, NULL);
  50. ck_assert_int_eq(UA_STATUSCODE_GOOD, res);
  51. res = UA_Server_addVariableNode(server, myIntegerNodeId, parentNodeId, parentReferenceNodeId,
  52. myIntegerName, UA_NODEID_NULL, attr, NULL);
  53. ck_assert_int_eq(res, UA_STATUSCODE_BADNODEIDEXISTS);
  54. UA_Server_delete(server);
  55. } END_TEST
  56. static Suite * testSuite_services_nodemanagement(void) {
  57. Suite *s = suite_create("services_nodemanagement");
  58. TCase *tc_addnodes = tcase_create("addnodes");
  59. tcase_add_test(tc_addnodes, AddVariableNode);
  60. tcase_add_test(tc_addnodes, AddNodeTwiceGivesError);
  61. suite_add_tcase(s, tc_addnodes);
  62. return s;
  63. }
  64. int main(void) {
  65. int number_failed = 0;
  66. Suite *s;
  67. s = testSuite_services_nodemanagement();
  68. SRunner *sr = srunner_create(s);
  69. srunner_set_fork_status(sr, CK_NOFORK);
  70. srunner_run_all(sr, CK_NORMAL);
  71. number_failed += srunner_ntests_failed(sr);
  72. srunner_free(sr);
  73. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  74. }