check_server_binary_messages.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "check.h"
  4. #include "ua_server.h"
  5. #include "ua_server_internal.h"
  6. #include "logger_stdout.h"
  7. #include "testing_networklayers.h"
  8. size_t files;
  9. char **filenames;
  10. static UA_ByteString readFile(char *filename) {
  11. UA_ByteString buf = UA_BYTESTRING_NULL;
  12. size_t length;
  13. FILE *f = fopen(filename,"r");
  14. if(f) {
  15. fseek(f, 0, SEEK_END);
  16. length = ftell(f);
  17. rewind(f);
  18. buf.data = malloc(length);
  19. fread(buf.data, sizeof(char), length, f);
  20. buf.length = length;
  21. fclose(f);
  22. }
  23. return buf;
  24. }
  25. START_TEST(processMessage) {
  26. UA_Connection c = createDummyConnection();
  27. UA_ServerConfig config = UA_ServerConfig_standard;
  28. config.logger = Logger_Stdout;
  29. UA_Server *server = UA_Server_new(config);
  30. for(size_t i = 0; i < files; i++) {
  31. UA_ByteString msg = readFile(filenames[i]);
  32. UA_Server_processBinaryMessage(server, &c, &msg);
  33. UA_ByteString_deleteMembers(&msg);
  34. }
  35. UA_Server_delete(server);
  36. UA_Connection_deleteMembers(&c);
  37. }
  38. END_TEST
  39. static Suite *testSuite_binaryMessages(void) {
  40. Suite *s = suite_create("Test server with messages stored in text files");
  41. TCase *tc_messages = tcase_create("binary messages");
  42. tcase_add_test(tc_messages, processMessage);
  43. suite_add_tcase(s, tc_messages);
  44. return s;
  45. }
  46. int main(int argc, char **argv) {
  47. if(argc < 2)
  48. return EXIT_FAILURE;
  49. filenames = &argv[1];
  50. files = argc - 1;
  51. int number_failed = 0;
  52. Suite *s;
  53. SRunner *sr;
  54. s = testSuite_binaryMessages();
  55. sr = srunner_create(s);
  56. srunner_set_fork_status(sr, CK_NOFORK);
  57. srunner_run_all(sr, CK_NORMAL);
  58. number_failed += srunner_ntests_failed(sr);
  59. srunner_free(sr);
  60. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  61. }