check_client.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 <pthread.h>
  7. #include "ua_types.h"
  8. #include "ua_server.h"
  9. #include "ua_client.h"
  10. #include "ua_config_standard.h"
  11. #include "ua_network_tcp.h"
  12. #include "check.h"
  13. UA_Server *server;
  14. UA_Boolean *running;
  15. UA_ServerNetworkLayer nl;
  16. pthread_t server_thread;
  17. static void * serverloop(void *_) {
  18. while(*running)
  19. UA_Server_run_iterate(server, true);
  20. return NULL;
  21. }
  22. static void setup(void) {
  23. running = UA_Boolean_new();
  24. *running = true;
  25. UA_ServerConfig config = UA_ServerConfig_standard;
  26. nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
  27. config.networkLayers = &nl;
  28. config.networkLayersSize = 1;
  29. server = UA_Server_new(config);
  30. UA_Server_run_startup(server);
  31. pthread_create(&server_thread, NULL, serverloop, NULL);
  32. }
  33. static void teardown(void) {
  34. *running = false;
  35. pthread_join(server_thread, NULL);
  36. UA_Server_run_shutdown(server);
  37. UA_Boolean_delete(running);
  38. UA_Server_delete(server);
  39. nl.deleteMembers(&nl);
  40. }
  41. START_TEST(Client_connect) {
  42. UA_Client *client = UA_Client_new(UA_ClientConfig_standard);
  43. UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:16664");
  44. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  45. UA_Client_disconnect(client);
  46. UA_Client_delete(client);
  47. }
  48. END_TEST
  49. static Suite* testSuite_Client(void) {
  50. Suite *s = suite_create("Client");
  51. TCase *tc_client = tcase_create("Client Basic");
  52. tcase_add_checked_fixture(tc_client, setup, teardown);
  53. tcase_add_test(tc_client, Client_connect);
  54. suite_add_tcase(s,tc_client);
  55. return s;
  56. }
  57. int main(void) {
  58. Suite *s = testSuite_Client();
  59. SRunner *sr = srunner_create(s);
  60. srunner_set_fork_status(sr, CK_NOFORK);
  61. srunner_run_all(sr,CK_NORMAL);
  62. int number_failed = srunner_ntests_failed(sr);
  63. srunner_free(sr);
  64. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  65. }