check_server_interaction_fileinput.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 void writeCallback(void *handle, UA_ByteStringArray buf) {
  16. }
  17. static void readCallback(void) {
  18. read_count++;
  19. if(read_count > max_reads)
  20. running = UA_FALSE;
  21. }
  22. START_TEST(readVariable) {
  23. UA_Server *server = UA_Server_new();
  24. UA_Server_setLogger(server, Logger_Stdout_new());
  25. UA_Server_addNetworkLayer(server, ServerNetworkLayerFileInput_new(max_reads, filenames, readCallback,
  26. writeCallback, NULL));
  27. UA_StatusCode retval = UA_Server_run(server, 1, &running);
  28. UA_Server_delete(server);
  29. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  30. }
  31. END_TEST
  32. static Suite *testSuite_builtin(void) {
  33. Suite *s = suite_create("Test server with client messages stored in text files");
  34. TCase *tc_nano = tcase_create("nano profile");
  35. tcase_add_test(tc_nano, readVariable);
  36. suite_add_tcase(s, tc_nano);
  37. return s;
  38. }
  39. int main(int argc, char **argv) {
  40. if(argc < 2)
  41. return EXIT_FAILURE;
  42. filenames = &argv[1];
  43. max_reads = argc - 1;
  44. int number_failed = 0;
  45. Suite *s;
  46. SRunner *sr;
  47. s = testSuite_builtin();
  48. sr = srunner_create(s);
  49. srunner_set_fork_status(sr, CK_NOFORK);
  50. srunner_run_all(sr, CK_NORMAL);
  51. number_failed += srunner_ntests_failed(sr);
  52. srunner_free(sr);
  53. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  54. }