check_server_interaction_fileinput.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include <stdlib.h>
  2. #include "check.h"
  3. #ifdef NOT_AMALGATED
  4. #include "ua_server.h"
  5. #else
  6. #include "open62541.h"
  7. #endif
  8. #include "testing_networklayers.h"
  9. #include "logger_stdout.h"
  10. #include <stdio.h>
  11. UA_Boolean running = 1;
  12. UA_UInt32 read_count = 0;
  13. UA_UInt32 max_reads;
  14. char **filenames;
  15. static UA_StatusCode writeCallback(void *handle, UA_ByteString *buf) {
  16. return UA_STATUSCODE_GOOD;
  17. }
  18. static void readCallback(void) {
  19. read_count++;
  20. if(read_count > max_reads)
  21. running = UA_FALSE;
  22. }
  23. START_TEST(readVariable) {
  24. UA_Server *server = UA_Server_new(UA_ServerConfig_standard);
  25. UA_Server_setLogger(server, Logger_Stdout_new());
  26. UA_Server_addNetworkLayer(server, ServerNetworkLayerFileInput_new(max_reads, filenames, readCallback,
  27. writeCallback, NULL));
  28. UA_StatusCode retval = UA_Server_run(server, 1, &running);
  29. UA_Server_delete(server);
  30. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  31. }
  32. END_TEST
  33. static Suite *testSuite_builtin(void) {
  34. Suite *s = suite_create("Test server with client messages stored in text files");
  35. TCase *tc_nano = tcase_create("nano profile");
  36. tcase_add_test(tc_nano, readVariable);
  37. suite_add_tcase(s, tc_nano);
  38. return s;
  39. }
  40. int main(int argc, char **argv) {
  41. if(argc < 2)
  42. return EXIT_FAILURE;
  43. filenames = &argv[1];
  44. max_reads = argc - 1;
  45. int number_failed = 0;
  46. Suite *s;
  47. SRunner *sr;
  48. s = testSuite_builtin();
  49. sr = srunner_create(s);
  50. srunner_set_fork_status(sr, CK_NOFORK);
  51. srunner_run_all(sr, CK_NORMAL);
  52. number_failed += srunner_ntests_failed(sr);
  53. srunner_free(sr);
  54. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  55. }