terom@168: /** terom@168: * @file terom@168: * terom@168: * Test functions for the irc_queue module terom@168: */ terom@168: #include "test.h" terom@168: #include "transport.h" terom@168: terom@168: #include "../irc_queue.h" terom@168: terom@168: static struct line_proto_callbacks _lp_callbacks = { terom@168: .on_line = NULL, terom@168: .on_error = NULL terom@168: }; terom@168: terom@168: void test_irc_queue (void) terom@168: { terom@168: struct transport_test *tp = transport_test_create(NULL); terom@168: transport_t *transport = transport_test_cast(tp); terom@168: struct line_proto *lp; terom@168: struct irc_queue *queue; terom@168: struct irc_queue_entry *queue_entry; terom@168: struct error_info err; terom@168: terom@168: // create the lp terom@168: assert_success(line_proto_create(&lp, transport, 128, &_lp_callbacks, NULL, &err)); terom@168: terom@168: // create the queue terom@168: assert_success(irc_queue_create(&queue, _test_ctx.ev_base, lp, &err)); terom@168: terom@168: struct irc_line line = { terom@168: NULL, "TEST", { "fooX" } terom@168: }; terom@168: terom@168: // then test simple writes, we should be able to push five lines directly terom@168: log_info("test irc_queue_process (irc_queue_send_direct)"); terom@168: line.args[0] = "foo0"; assert_success(irc_queue_process(queue, &line)); terom@168: line.args[0] = "foo1"; assert_success(irc_queue_process(queue, &line)); terom@168: line.args[0] = "foo2"; assert_success(irc_queue_process(queue, &line)); terom@168: line.args[0] = "foo3"; assert_success(irc_queue_process(queue, &line)); terom@168: line.args[0] = "foo4"; assert_success(irc_queue_process(queue, &line)); terom@168: terom@168: // they should all be output terom@168: assert_transport_data(tp, terom@168: "TEST foo0\r\n" terom@168: "TEST foo1\r\n" terom@168: "TEST foo2\r\n" terom@168: "TEST foo3\r\n" terom@168: "TEST foo4\r\n" terom@168: ); terom@168: terom@168: // then enqueue terom@168: log_info("test irc_queue_process (irc_queue_put)"); terom@168: line.args[0] = "foo5"; assert_success(irc_queue_process(queue, &line)); terom@168: terom@168: // ensure it was enqueued terom@168: assert((queue_entry = TAILQ_FIRST(&queue->list)) != NULL); terom@168: assert_strcmp(queue_entry->line_buf, "TEST foo5\r\n"); terom@168: terom@168: // ensure timer is set terom@168: assert(event_pending(queue->ev, EV_TIMEOUT, NULL)); terom@168: terom@168: // run the event loop to let the timer run terom@168: log_info("running the event loop once..."); terom@168: assert(event_base_loop(_test_ctx.ev_base, EVLOOP_ONCE) == 0); terom@168: terom@168: // test to check that the line was now sent terom@168: log_info("checking that the delayed line was sent..."); terom@168: assert_transport_data(tp, "TEST foo5\r\n"); terom@168: assert(TAILQ_EMPTY(&queue->list)); terom@168: assert(!event_pending(queue->ev, EV_TIMEOUT, NULL)); terom@168: terom@168: // cleanup terom@168: irc_queue_destroy(queue); terom@171: line_proto_destroy(lp); terom@168: } terom@168: