check_server_userspace.c 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #ifdef __clang__
  10. //required for ck_assert_ptr_eq and const casting
  11. #pragma clang diagnostic push
  12. #pragma clang diagnostic ignored "-Wincompatible-pointer-types-discards-qualifiers"
  13. #endif
  14. START_TEST(Server_addNamespace_ShallWork)
  15. {
  16. UA_ServerConfig config = UA_ServerConfig_standard;
  17. UA_Server *server = UA_Server_new(config);
  18. UA_UInt16 a = UA_Server_addNamespace(server, "http://nameOfNamespace");
  19. UA_UInt16 b = UA_Server_addNamespace(server, "http://nameOfNamespace");
  20. UA_UInt16 c = UA_Server_addNamespace(server, "http://nameOfNamespace2");
  21. ck_assert_uint_gt(a, 0);
  22. ck_assert_uint_eq(a,b);
  23. ck_assert_uint_ne(a,c);
  24. UA_Server_delete(server);
  25. }
  26. END_TEST
  27. START_TEST(Server_addNamespace_writeService)
  28. {
  29. UA_ServerConfig config = UA_ServerConfig_standard;
  30. UA_Server *server = UA_Server_new(config);
  31. UA_Variant namespaces;
  32. UA_StatusCode retval = UA_STATUSCODE_GOOD;
  33. UA_Server_readValue(server, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_NAMESPACEARRAY),
  34. &namespaces);
  35. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  36. ck_assert_ptr_eq(namespaces.type, &UA_TYPES[UA_TYPES_STRING]);
  37. namespaces.data = UA_realloc(namespaces.data, (namespaces.arrayLength + 1) * sizeof(UA_String));
  38. ++namespaces.arrayLength;
  39. UA_String *ns = (UA_String*)namespaces.data;
  40. ns[namespaces.arrayLength-1] = UA_STRING_ALLOC("test");
  41. size_t nsSize = namespaces.arrayLength;
  42. retval = UA_Server_writeValue(server, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_NAMESPACEARRAY),
  43. namespaces);
  44. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  45. UA_Variant_deleteMembers(&namespaces);
  46. /* Now read again */
  47. UA_Server_readValue(server, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_NAMESPACEARRAY),
  48. &namespaces);
  49. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  50. ck_assert_uint_eq(namespaces.arrayLength, nsSize);
  51. UA_Variant_deleteMembers(&namespaces);
  52. UA_Server_delete(server);
  53. }
  54. END_TEST
  55. static Suite* testSuite_ServerUserspace(void) {
  56. Suite *s = suite_create("ServerUserspace");
  57. TCase *tc_core = tcase_create("Core");
  58. tcase_add_test(tc_core, Server_addNamespace_ShallWork);
  59. tcase_add_test(tc_core, Server_addNamespace_writeService);
  60. suite_add_tcase(s,tc_core);
  61. return s;
  62. }
  63. int main(void) {
  64. int number_failed = 0;
  65. Suite *s;
  66. SRunner *sr;
  67. s = testSuite_ServerUserspace();
  68. 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. }
  75. #ifdef __clang__
  76. #pragma clang diagnostic pop
  77. #endif