odyssey/tests/test_getaddrinfo1.c

71 lines
1.2 KiB
C
Raw Normal View History

2017-05-16 09:54:03 +00:00
/*
* machinarium.
*
* Cooperative multitasking engine.
*/
#include <machinarium.h>
#include <machinarium_test.h>
static void
test_gai0(void *arg)
{
machine_io_t io = machine_create_io();
2017-05-16 09:54:03 +00:00
test(io != NULL);
struct addrinfo *res = NULL;
int rc = machine_getaddrinfo(io, "localhost", "http", NULL, &res, INT_MAX);
if (rc < 0) {
printf("failed to resolve address\n");
} else {
test(res != NULL);
if (res)
freeaddrinfo(res);
}
machine_free_io(io);
}
static void
test_gai1(void *arg)
{
machine_io_t io = machine_create_io();
2017-05-16 09:54:03 +00:00
test(io != NULL);
struct addrinfo *res = NULL;
int rc = machine_getaddrinfo(io, "localhost", "http", NULL, &res, INT_MAX);
if (rc < 0) {
printf("failed to resolve address\n");
} else {
test(res != NULL);
if (res)
freeaddrinfo(res);
}
machine_free_io(io);
}
static void
test_gai(void *arg)
2017-05-16 09:54:03 +00:00
{
int rc;
rc = machine_create_fiber(test_gai0, NULL);
2017-05-16 09:54:03 +00:00
test(rc != -1);
rc = machine_create_fiber(test_gai1, NULL);
2017-05-16 09:54:03 +00:00
test(rc != -1);
}
2017-05-16 09:54:03 +00:00
void
test_getaddrinfo1(void)
{
machinarium_init();
int id;
id = machine_create("test", test_gai, NULL);
test(id != -1);
2017-05-16 09:54:03 +00:00
int rc;
rc = machine_join(id);
2017-05-16 09:54:03 +00:00
test(rc != -1);
machinarium_free();
2017-05-16 09:54:03 +00:00
}