libuv/test/test-callback-stack.c

43 lines
711 B
C
Raw Normal View History

2011-04-07 09:02:54 +00:00
#include "../oio.h"
#include "test.h"
2011-04-15 17:27:09 +00:00
/* TODO: Add explanation of why we want on_close to be called from fresh
* stack.
*/
int nested = 0;
int close_cb_called = 0;
void close_cb(oio_handle *handle, oio_err err) {
ASSERT(!err)
ASSERT(nested == 0 && "oio_close_cb must be called from a fresh stack")
close_cb_called++;
}
TEST_IMPL(close_cb_stack) {
2011-04-07 09:02:54 +00:00
oio_handle handle;
2011-04-07 09:02:54 +00:00
oio_init();
2011-04-07 02:51:59 +00:00
2011-04-15 17:27:09 +00:00
if (oio_tcp_handle_init(&handle, &close_cb, NULL)) {
FATAL(oio_tcp_handle_init failed)
2011-04-15 17:27:09 +00:00
}
nested++;
2011-04-15 17:27:09 +00:00
if (oio_close(&handle)) {
FATAL(oio_close failed)
2011-04-15 17:27:09 +00:00
}
nested--;
2011-04-07 09:02:54 +00:00
oio_run();
2011-04-15 17:27:09 +00:00
ASSERT(nested == 0)
ASSERT(close_cb_called == 1 && "oio_close_cb must be called exactly once")
return 0;
2011-04-15 17:27:09 +00:00
}