168
|
1 |
/**
|
|
2 |
* @file
|
|
3 |
*
|
|
4 |
* Test functions for the irc_queue module
|
|
5 |
*/
|
|
6 |
#include "test.h"
|
|
7 |
#include "transport.h"
|
|
8 |
|
|
9 |
#include "../irc_queue.h"
|
|
10 |
|
|
11 |
static struct line_proto_callbacks _lp_callbacks = {
|
|
12 |
.on_line = NULL,
|
|
13 |
.on_error = NULL
|
|
14 |
};
|
|
15 |
|
|
16 |
void test_irc_queue (void)
|
|
17 |
{
|
|
18 |
struct transport_test *tp = transport_test_create(NULL);
|
|
19 |
transport_t *transport = transport_test_cast(tp);
|
|
20 |
struct line_proto *lp;
|
|
21 |
struct irc_queue *queue;
|
|
22 |
struct irc_queue_entry *queue_entry;
|
|
23 |
struct error_info err;
|
|
24 |
|
|
25 |
// create the lp
|
|
26 |
assert_success(line_proto_create(&lp, transport, 128, &_lp_callbacks, NULL, &err));
|
|
27 |
|
|
28 |
// create the queue
|
|
29 |
assert_success(irc_queue_create(&queue, _test_ctx.ev_base, lp, &err));
|
|
30 |
|
|
31 |
struct irc_line line = {
|
|
32 |
NULL, "TEST", { "fooX" }
|
|
33 |
};
|
|
34 |
|
|
35 |
// then test simple writes, we should be able to push five lines directly
|
|
36 |
log_info("test irc_queue_process (irc_queue_send_direct)");
|
|
37 |
line.args[0] = "foo0"; assert_success(irc_queue_process(queue, &line));
|
|
38 |
line.args[0] = "foo1"; assert_success(irc_queue_process(queue, &line));
|
|
39 |
line.args[0] = "foo2"; assert_success(irc_queue_process(queue, &line));
|
|
40 |
line.args[0] = "foo3"; assert_success(irc_queue_process(queue, &line));
|
|
41 |
line.args[0] = "foo4"; assert_success(irc_queue_process(queue, &line));
|
|
42 |
|
|
43 |
// they should all be output
|
|
44 |
assert_transport_data(tp,
|
|
45 |
"TEST foo0\r\n"
|
|
46 |
"TEST foo1\r\n"
|
|
47 |
"TEST foo2\r\n"
|
|
48 |
"TEST foo3\r\n"
|
|
49 |
"TEST foo4\r\n"
|
|
50 |
);
|
|
51 |
|
|
52 |
// then enqueue
|
|
53 |
log_info("test irc_queue_process (irc_queue_put)");
|
|
54 |
line.args[0] = "foo5"; assert_success(irc_queue_process(queue, &line));
|
|
55 |
|
|
56 |
// ensure it was enqueued
|
|
57 |
assert((queue_entry = TAILQ_FIRST(&queue->list)) != NULL);
|
|
58 |
assert_strcmp(queue_entry->line_buf, "TEST foo5\r\n");
|
|
59 |
|
|
60 |
// ensure timer is set
|
|
61 |
assert(event_pending(queue->ev, EV_TIMEOUT, NULL));
|
|
62 |
|
|
63 |
// run the event loop to let the timer run
|
|
64 |
log_info("running the event loop once...");
|
|
65 |
assert(event_base_loop(_test_ctx.ev_base, EVLOOP_ONCE) == 0);
|
|
66 |
|
|
67 |
// test to check that the line was now sent
|
|
68 |
log_info("checking that the delayed line was sent...");
|
|
69 |
assert_transport_data(tp, "TEST foo5\r\n");
|
|
70 |
assert(TAILQ_EMPTY(&queue->list));
|
|
71 |
assert(!event_pending(queue->ev, EV_TIMEOUT, NULL));
|
|
72 |
|
|
73 |
// cleanup
|
|
74 |
irc_queue_destroy(queue);
|
|
75 |
}
|
|
76 |
|