Skip to content

Commit

Permalink
Tests: print to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesLorenz committed Jan 13, 2024
1 parent 5162777 commit cd3710d
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/test_bidirectional_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ int generic_handler(const char *path, const char *types, lo_arg ** argv,
lo_address a = lo_message_get_source(data);
int prot = lo_address_get_protocol(a);

printf("%p.%s, from %s:%s:%s\n", s, path,
fprintf(stderr, "%p.%s, from %s:%s:%s\n", s, path,
(prot==LO_UDP) ? "UDP"
: (prot==LO_TCP) ? "TCP"
: (prot==LO_UNIX) ? "UNIX" : "?",
lo_address_get_hostname(a),
lo_address_get_port(a));

printf("%p.address fd: %d\n", s, ((int*)a)[1]);
fprintf(stderr, "%p.address fd: %d\n", s, ((int*)a)[1]);

lo_send_from(a, s, LO_TT_IMMEDIATE, "/reply", 0);
printf("%p.reply sent\n", s);
fprintf(stderr, "%p.reply sent\n", s);

return 0;
}
Expand All @@ -47,20 +47,20 @@ void *sendthread(void *arg)
lo_server s = lo_server_new_with_proto("7772", LO_TCP, 0);
if (!s) { printf("no server2\n"); exit(1); }

printf("%p.sending thread\n", s);
fprintf(stderr, "%p.sending thread\n", s);

lo_server_add_method(s, 0, 0, generic_handler, s);

lo_address a = lo_address_new_with_proto(LO_TCP, "localhost", "7771");

lo_send_from(a, s, LO_TT_IMMEDIATE, "/test", 0);

printf("%p.message sent\n", s);
printf("%p.sending thread waiting\n", s);
fprintf(stderr, "%p.message sent\n", s);
fprintf(stderr, "%p.sending thread waiting\n", s);
lo_server_recv(s);
printf("%p.sending thread received\n", s);
fprintf(stderr, "%p.sending thread received\n", s);

printf("%p.freeing address\n", s);
fprintf(stderr, "%p.freeing address\n", s);
/* Do not close the socket immediatelly, wait 1 second for recv */
#if defined(WIN32) || defined(_MSC_VER)
Sleep(1000);
Expand All @@ -70,7 +70,7 @@ void *sendthread(void *arg)

lo_address_free(a);

printf("%p.freeing\n", s);
fprintf(stderr, "%p.freeing\n", s);
lo_server_free(s);

return 0;
Expand All @@ -85,7 +85,7 @@ int main()
/* add method that will match any path and args */
lo_server_add_method(s, 0, 0, generic_handler, s);

printf("%p.server fd: %d\n", s, lo_server_get_socket_fd(s));
fprintf(stderr, "%p.server fd: %d\n", s, lo_server_get_socket_fd(s));

#ifdef HAVE_WIN32_THREADS
HANDLE thr = (HANDLE)_beginthreadex(NULL, 0, &sendthread, s, 0, NULL);
Expand All @@ -94,13 +94,13 @@ int main()
pthread_create(&thr, 0, sendthread, s);
#endif

printf("%p.receiving1..\n", s);
fprintf(stderr, "%p.receiving1..\n", s);
lo_server_recv(s);
printf("%p.done receiving1\n", s);
fprintf(stderr, "%p.done receiving1\n", s);

printf("%p.receiving2..\n", s);
fprintf(stderr, "%p.receiving2..\n", s);
lo_server_recv(s);
printf("%p.done receiving2\n", s);
fprintf(stderr, "%p.done receiving2\n", s);

#ifdef HAVE_WIN32_THREADS
WaitForSingleObject(thr, INFINITE);
Expand All @@ -109,11 +109,11 @@ int main()
pthread_join(thr, 0);
#endif

printf("%p.freeing\n", s);
fprintf(stderr, "%p.freeing\n", s);
lo_server_free(s);

/* If it gets here without hanging we are good. */
printf("TEST SUCCESSFUL\n");
fprintf(stderr, "TEST SUCCESSFUL\n");

return 0;
}

0 comments on commit cd3710d

Please sign in to comment.