check_server_userspace.c 2.7 KB

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