check_server_userspace.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "ua_types.h"
  4. #include "ua_config_standard.h"
  5. #include "check.h"
  6. START_TEST(Server_addNamespace_ShallWork)
  7. {
  8. UA_ServerConfig config = UA_ServerConfig_standard;
  9. UA_Server *server = UA_Server_new(config);
  10. UA_UInt16 a = UA_Server_addNamespace(server, "http://nameOfNamespace");
  11. UA_UInt16 b = UA_Server_addNamespace(server, "http://nameOfNamespace");
  12. UA_UInt16 c = UA_Server_addNamespace(server, "http://nameOfNamespace2");
  13. ck_assert_uint_gt(a, 0);
  14. ck_assert_uint_eq(a,b);
  15. ck_assert_uint_ne(a,c);
  16. UA_Server_delete(server);
  17. }
  18. END_TEST
  19. START_TEST(Server_addNamespace_writeService)
  20. {
  21. UA_ServerConfig config = UA_ServerConfig_standard;
  22. UA_Server *server = UA_Server_new(config);
  23. UA_Variant namespaces;
  24. UA_StatusCode retval = UA_STATUSCODE_GOOD;
  25. UA_Server_readValue(server, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_NAMESPACEARRAY),
  26. &namespaces);
  27. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  28. ck_assert_ptr_eq(namespaces.type, &UA_TYPES[UA_TYPES_STRING]);
  29. namespaces.data = realloc(namespaces.data, (namespaces.arrayLength + 1) * sizeof(UA_String));
  30. ++namespaces.arrayLength;
  31. UA_String *ns = namespaces.data;
  32. ns[namespaces.arrayLength-1] = UA_STRING_ALLOC("test");
  33. size_t nsSize = namespaces.arrayLength;
  34. retval = UA_Server_writeValue(server, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_NAMESPACEARRAY),
  35. namespaces);
  36. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  37. UA_Variant_deleteMembers(&namespaces);
  38. /* Now read again */
  39. UA_Server_readValue(server, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_NAMESPACEARRAY),
  40. &namespaces);
  41. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  42. ck_assert_uint_eq(namespaces.arrayLength, nsSize);
  43. UA_Variant_deleteMembers(&namespaces);
  44. UA_Server_delete(server);
  45. }
  46. END_TEST
  47. static Suite* testSuite_ServerUserspace(void) {
  48. Suite *s = suite_create("ServerUserspace");
  49. TCase *tc_core = tcase_create("Core");
  50. tcase_add_test(tc_core, Server_addNamespace_ShallWork);
  51. tcase_add_test(tc_core, Server_addNamespace_writeService);
  52. suite_add_tcase(s,tc_core);
  53. return s;
  54. }
  55. int main(void) {
  56. int number_failed = 0;
  57. Suite *s;
  58. SRunner *sr;
  59. s = testSuite_ServerUserspace();
  60. sr = srunner_create(s);
  61. srunner_set_fork_status(sr, CK_NOFORK);
  62. srunner_run_all(sr,CK_NORMAL);
  63. number_failed += srunner_ntests_failed(sr);
  64. srunner_free(sr);
  65. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  66. }