check_client.c 1.9 KB

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