author | Tero Marttila <terom@fixme.fi> |
Thu, 23 Apr 2009 17:17:33 +0300 | |
changeset 147 | fd97eb3c183a |
parent 129 | 361740b82fe5 |
child 167 | 0d2d8ca879d8 |
permissions | -rw-r--r-- |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1 |
/** |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
2 |
* The main test code entry point |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
3 |
*/ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
4 |
#include "sock_test.h" |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
5 |
#include "line_proto.h" |
90
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
6 |
#include "irc_queue.h" |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
7 |
#include "irc_conn.h" |
44 | 8 |
#include "irc_net.h" |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
9 |
#include "log.h" |
125
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
10 |
#include "str.h" |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
11 |
#include "error.h" |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
12 |
|
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
13 |
#include <stdlib.h> |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
14 |
#include <string.h> |
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
15 |
#include <getopt.h> |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
16 |
#include <assert.h> |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
17 |
#include <ctype.h> |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
18 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
19 |
#define DUMP_STR_BUF 1024 |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
20 |
#define DUMP_STR_COUNT 8 |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
21 |
#define DUMP_STR_TAIL 10 |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
22 |
|
90
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
23 |
/** |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
24 |
* Global test-running state |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
25 |
*/ |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
26 |
struct test_ctx { |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
27 |
/** The event_base that we have setup */ |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
28 |
struct event_base *ev_base; |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
29 |
|
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
30 |
} _test_ctx; |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
31 |
|
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
32 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
33 |
/** |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
34 |
* This re-formats the given string to escape values, and returns a pointer to an internal static buffer. |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
35 |
* |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
36 |
* If len is given as >= 0, only the given number of chars will be dumped from str. |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
37 |
* |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
38 |
* The buffer cycles a bit, so the returned pointers remain valid across DUMP_STR_COUNT calls. |
51
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
39 |
* |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
40 |
* The resulting string is truncated to (DUMP_STR_BUF - DUMP_STR_TAIL) bytes, not including the ending "...'\0". |
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
41 |
* |
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
42 |
* @param str the string to dump, should be NUL-terminated unless len is given |
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
43 |
* @param len if negative, ignored, otherwise, only this many bytes are dumped from str |
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
44 |
* @param return a pointer to a static buffer that remains valid across DUMP_STR_COUNT calls to this function |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
45 |
*/ |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
46 |
const char *dump_strn (const char *str, ssize_t len) |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
47 |
{ |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
48 |
static char dump_buf[DUMP_STR_COUNT][DUMP_STR_BUF]; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
49 |
static size_t dump_idx = 0; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
50 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
51 |
// pick a buffer to use |
125
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
52 |
char *buf = dump_buf[dump_idx++]; |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
53 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
54 |
// cycle |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
55 |
if (dump_idx >= DUMP_STR_COUNT) |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
56 |
dump_idx = 0; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
57 |
|
125
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
58 |
str_quote(buf, DUMP_STR_BUF, str, len); |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
59 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
60 |
// ok |
125
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
61 |
return buf; |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
62 |
} |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
63 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
64 |
const char *dump_str (const char *str) |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
65 |
{ |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
66 |
return dump_strn(str, -1); |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
67 |
} |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
68 |
|
75
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
69 |
void assert_null (const void *ptr) |
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
70 |
{ |
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
71 |
if (ptr) |
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
72 |
FATAL("%p != NULL", ptr); |
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
73 |
} |
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
74 |
|
42 | 75 |
void assert_strcmp (const char *is, const char *should_be) |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
76 |
{ |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
77 |
if (!is || strcmp(is, should_be)) |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
78 |
FATAL("%s != %s", dump_str(is), dump_str(should_be)); |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
79 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
80 |
|
42 | 81 |
void assert_strncmp (const char *is, const char *should_be, size_t n) |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
82 |
{ |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
83 |
if (!is || strncmp(is, should_be, n)) |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
84 |
FATAL("%s:%u != %s", dump_strn(is, n), (unsigned) n, dump_strn(should_be, n)); |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
85 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
86 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
87 |
void assert_strlen (const char *str, size_t n) |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
88 |
{ |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
89 |
if (!str || strlen(str) != n) |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
90 |
FATAL("strlen(%s) != %u", dump_str(str), (unsigned) n); |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
91 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
92 |
|
42 | 93 |
void assert_strnull (const char *str) |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
94 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
95 |
if (str != NULL) |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
96 |
FATAL("%s != NULL", dump_str(str)); |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
97 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
98 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
99 |
void assert_success (err_t err) |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
100 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
101 |
if (err != SUCCESS) |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
102 |
FATAL("error: %s", error_name(err)); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
103 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
104 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
105 |
void assert_err (err_t err, err_t target) |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
106 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
107 |
if (err != target) |
42 | 108 |
FATAL("error: <%s> != <%s>", error_name(err), error_name(target)); |
109 |
} |
|
110 |
||
111 |
void assert_error_info (struct error_info *is, struct error_info *should_be) |
|
112 |
{ |
|
113 |
if (ERROR_CODE(is) != ERROR_CODE(should_be) || ERROR_EXTRA(is) != ERROR_EXTRA(should_be)) |
|
114 |
FATAL("error: <%s> != <%s>", error_msg(is), error_msg(should_be)); |
|
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
115 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
116 |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
117 |
void assert_sock_read (struct sock_stream *sock, const char *str) |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
118 |
{ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
119 |
char buf[strlen(str)]; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
120 |
|
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
121 |
log_debug("read: %p: %s", sock, dump_str(str)); |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
122 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
123 |
// read it |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
124 |
assert(sock_stream_read(sock, buf, strlen(str)) == (int) strlen(str)); |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
125 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
126 |
// cmp |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
127 |
assert_strncmp(buf, str, strlen(str)); |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
128 |
} |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
129 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
130 |
void assert_sock_write (struct sock_stream *sock, const char *str) |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
131 |
{ |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
132 |
log_debug("write: %p: %s", sock, dump_str(str)); |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
133 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
134 |
// write it |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
135 |
assert(sock_stream_write(sock, str, strlen(str)) == (int) strlen(str)); |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
136 |
} |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
137 |
|
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
138 |
void assert_sock_eof (struct sock_stream *sock) |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
139 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
140 |
char buf; |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
141 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
142 |
log_debug("eof: %p", sock); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
143 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
144 |
assert_err(-sock_stream_read(sock, &buf, 1), ERR_READ_EOF); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
145 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
146 |
|
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
147 |
/** |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
148 |
* Maximum amount that can be pushed using test_sock_push |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
149 |
*/ |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
150 |
#define TEST_SOCK_FMT_MAX 1024 |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
151 |
|
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
152 |
void assert_sock_data (struct sock_test *sock, const char *fmt, ...) |
43 | 153 |
{ |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
154 |
char buf[TEST_SOCK_FMT_MAX]; |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
155 |
va_list vargs; |
43 | 156 |
size_t len; |
157 |
||
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
158 |
va_start(vargs, fmt); |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
159 |
|
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
160 |
if ((len = vsnprintf(buf, TEST_SOCK_FMT_MAX, fmt, vargs)) >= TEST_SOCK_FMT_MAX) |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
161 |
FATAL("input too long: %zu bytes", len); |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
162 |
|
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
163 |
va_end(vargs); |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
164 |
|
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
165 |
// get the data out |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
166 |
char *out; |
43 | 167 |
|
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
168 |
sock_test_get_send_data(sock, &out, &len); |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
169 |
|
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
170 |
log_debug("get_send_data: %s", dump_strn(out, len)); |
43 | 171 |
|
172 |
// should be the same |
|
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
173 |
assert_strncmp(out, buf, len); |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
174 |
assert_strlen(buf, len); |
43 | 175 |
|
176 |
// cleanup |
|
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
177 |
free(out); |
43 | 178 |
} |
179 |
||
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
180 |
/** |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
181 |
* Nicer name for test_sock_add_recv_str, also supports formatted data. |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
182 |
* |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
183 |
* The formatted result is limited to TEST_SOCK_PUSH_MAX bytes |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
184 |
*/ |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
185 |
void test_sock_push (struct sock_test *sock, const char *fmt, ...) |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
186 |
{ |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
187 |
char buf[TEST_SOCK_FMT_MAX]; |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
188 |
va_list vargs; |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
189 |
size_t len; |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
190 |
|
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
191 |
va_start(vargs, fmt); |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
192 |
|
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
193 |
if ((len = vsnprintf(buf, TEST_SOCK_FMT_MAX, fmt, vargs)) >= TEST_SOCK_FMT_MAX) |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
194 |
FATAL("output too long: %zu bytes", len); |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
195 |
|
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
196 |
va_end(vargs); |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
197 |
|
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
198 |
return sock_test_add_recv_str(sock, buf); |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
199 |
} |
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
200 |
|
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
201 |
/** |
90
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
202 |
* Setup the global sock_stream state |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
203 |
*/ |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
204 |
struct event_base* setup_sock (void) |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
205 |
{ |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
206 |
struct event_base *ev_base; |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
207 |
struct error_info err; |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
208 |
|
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
209 |
assert((ev_base = event_base_new())); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
210 |
assert_success(sock_init(ev_base, &err)); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
211 |
|
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
212 |
return ev_base; |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
213 |
} |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
214 |
|
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
215 |
/** |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
216 |
* Create an empty sock_test |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
217 |
*/ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
218 |
struct sock_test* setup_sock_test (void) |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
219 |
{ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
220 |
struct sock_test *sock; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
221 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
222 |
assert ((sock = sock_test_create()) != NULL); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
223 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
224 |
return sock; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
225 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
226 |
|
125
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
227 |
void assert_str_quote (size_t buf_size, const char *data, ssize_t len, const char *target, size_t out) |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
228 |
{ |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
229 |
char buf[buf_size]; |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
230 |
|
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
231 |
size_t ret = str_quote(buf, buf_size, data, len); |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
232 |
|
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
233 |
log_debug("str_quote(%zu, %zd) -> %s:%zu / %s:%zu", buf_size, len, buf, ret, target, out); |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
234 |
|
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
235 |
assert_strcmp(buf, target); |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
236 |
assert(ret == out); |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
237 |
} |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
238 |
|
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
239 |
void test_str_quote (void) |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
240 |
{ |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
241 |
log_info("testing str_quote()"); |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
242 |
|
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
243 |
assert_str_quote(5, NULL, -1, "NULL", 4 ); |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
244 |
assert_str_quote(16, "foo", -1, "'foo'", 5 ); |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
245 |
assert_str_quote(16, "foobar", 3, "'foo'", 5 ); |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
246 |
assert_str_quote(16, "\r\n", -1, "'\\r\\n'", 6 ); |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
247 |
assert_str_quote(16, "\x13", -1, "'\\x13'", 6 ); |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
248 |
assert_str_quote(16, "x'y", -1, "'x\\'y'", 6 ); |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
249 |
assert_str_quote(7, "1234567890", -1, "'1'...", 12 ); |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
250 |
assert_str_quote(9, "1234567890", -1, "'123'...", 12 ); |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
251 |
} |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
252 |
|
129
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
253 |
struct str_format_ctx { |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
254 |
const char *name; |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
255 |
|
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
256 |
const char *value; |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
257 |
}; |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
258 |
|
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
259 |
err_t test_str_format_cb (const char *name, const char **value, ssize_t *value_len, void *arg) |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
260 |
{ |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
261 |
struct str_format_ctx *ctx = arg; |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
262 |
|
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
263 |
assert_strcmp(name, ctx->name); |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
264 |
|
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
265 |
*value = ctx->value; |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
266 |
*value_len = -1; |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
267 |
|
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
268 |
return SUCCESS; |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
269 |
} |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
270 |
|
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
271 |
void assert_str_format (const char *format, const char *name, const char *value, const char *out) |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
272 |
{ |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
273 |
struct str_format_ctx ctx = { name, value }; |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
274 |
char buf[512]; |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
275 |
|
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
276 |
assert_success(str_format(buf, sizeof(buf), format, test_str_format_cb, &ctx)); |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
277 |
|
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
278 |
log_debug("str_format(%s), { %s:%s } -> %s / %s", format, name, value, buf, out); |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
279 |
|
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
280 |
assert_strcmp(buf, out); |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
281 |
} |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
282 |
|
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
283 |
void test_str_format (void) |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
284 |
{ |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
285 |
log_info("test str_format()"); |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
286 |
|
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
287 |
assert_str_format("foo", NULL, NULL, "foo"); |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
288 |
assert_str_format("foo {bar} quux", "bar", "XXX", "foo XXX quux"); |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
289 |
} |
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
290 |
|
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
291 |
void test_dump_str (void) |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
292 |
{ |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
293 |
log_info("dumping example strings on stdout:"); |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
294 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
295 |
log_debug("normal: %s", dump_str("Hello World")); |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
296 |
log_debug("escapes: %s", dump_str("foo\r\nbar\a\001")); |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
297 |
log_debug("length: %s", dump_strn("<-->**", 4)); |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
298 |
log_debug("overflow: %s", dump_str( "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")); |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
299 |
log_debug("null: %s", dump_str(NULL)); |
51
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
300 |
log_debug("quote: %s", dump_str("foo\\bar'quux")); |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
301 |
} |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
302 |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
303 |
void test_sock_test (void) |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
304 |
{ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
305 |
struct sock_test *sock = sock_test_create(); |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
306 |
struct io_vec _read_data[] = { |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
307 |
{ "foo", 3 }, |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
308 |
{ "barx", 4 } |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
309 |
}; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
310 |
const char *_write_data = "test data"; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
311 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
312 |
// put the read data |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
313 |
log_debug("set_recv_buffer: %p, %d", _read_data, 2); |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
314 |
sock_test_set_recv_buffer(sock, _read_data, 2, true); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
315 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
316 |
// read it out |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
317 |
log_info("test sock_test_read"); |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
318 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
319 |
assert_sock_read(SOCK_TEST_BASE(sock), "foo"); |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
320 |
assert_sock_read(SOCK_TEST_BASE(sock), "ba"); |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
321 |
assert_sock_read(SOCK_TEST_BASE(sock), "rx"); |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
322 |
assert_sock_eof(SOCK_TEST_BASE(sock)); |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
323 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
324 |
// write the data in |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
325 |
log_info("test sock_test_write"); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
326 |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
327 |
assert_sock_write(SOCK_TEST_BASE(sock), "test "); |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
328 |
assert_sock_write(SOCK_TEST_BASE(sock), "data"); |
43 | 329 |
|
330 |
// check output |
|
44 | 331 |
assert_sock_data(sock, _write_data); |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
332 |
|
43 | 333 |
// check output |
44 | 334 |
assert_sock_data(sock, ""); |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
335 |
|
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
336 |
// cleanup |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
337 |
sock_test_destroy(sock); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
338 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
339 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
340 |
void assert_read_line (struct line_proto *lp, const char *line_str) |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
341 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
342 |
char *line_buf; |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
343 |
|
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
344 |
log_debug("expect: %s", dump_str(line_str)); |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
345 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
346 |
assert_success(line_proto_recv(lp, &line_buf)); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
347 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
348 |
if (line_str) { |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
349 |
assert_strcmp(line_buf, line_str); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
350 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
351 |
} else { |
42 | 352 |
assert_strnull(line_buf); |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
353 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
354 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
355 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
356 |
|
42 | 357 |
/** |
358 |
* Context info for test_line_proto callbacks |
|
359 |
*/ |
|
360 |
struct _lp_test_ctx { |
|
361 |
/** Expected line */ |
|
362 |
const char *line; |
|
363 |
||
364 |
/** Expected error */ |
|
365 |
struct error_info err; |
|
366 |
}; |
|
367 |
||
368 |
static void _lp_on_line (char *line, void *arg) |
|
369 |
{ |
|
370 |
struct _lp_test_ctx *ctx = arg; |
|
371 |
||
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
372 |
log_debug("%s", dump_str(line)); |
42 | 373 |
|
374 |
assert_strcmp(line, ctx->line); |
|
375 |
||
376 |
ctx->line = NULL; |
|
377 |
} |
|
378 |
||
379 |
static void _lp_on_error (struct error_info *err, void *arg) |
|
380 |
{ |
|
381 |
struct _lp_test_ctx *ctx = arg; |
|
382 |
||
383 |
assert_error_info(err, &ctx->err); |
|
384 |
} |
|
385 |
||
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
386 |
static struct line_proto_callbacks _lp_callbacks = { |
42 | 387 |
.on_line = &_lp_on_line, |
388 |
.on_error = &_lp_on_error, |
|
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
389 |
}; |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
390 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
391 |
void test_line_proto (void) |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
392 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
393 |
struct sock_test *sock = sock_test_create(); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
394 |
struct io_vec _read_data[] = { |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
395 |
{ "hello\r\n", 7 }, |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
396 |
{ "world\n", 6 }, |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
397 |
{ "this ", 5 }, |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
398 |
{ "is a line\r", 10 }, |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
399 |
{ "\nfragment", 9 }, |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
400 |
}, _trailing_data = { "\r\n", 2 }; |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
401 |
struct line_proto *lp; |
42 | 402 |
struct _lp_test_ctx ctx; |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
403 |
struct error_info err; |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
404 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
405 |
// put the read data |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
406 |
log_debug("set_recv_buffer: %p, %d", _read_data, 5); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
407 |
sock_test_set_recv_buffer(sock, _read_data, 5, false); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
408 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
409 |
// create the lp |
42 | 410 |
assert_success(line_proto_create(&lp, SOCK_TEST_BASE(sock), 128, &_lp_callbacks, &ctx, &err)); |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
411 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
412 |
log_info("test line_proto_recv"); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
413 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
414 |
// then read some lines from it |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
415 |
assert_read_line(lp, "hello"); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
416 |
assert_read_line(lp, "world"); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
417 |
assert_read_line(lp, "this is a line"); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
418 |
assert_read_line(lp, NULL); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
419 |
|
42 | 420 |
// then add a final bit to trigger on_line |
421 |
log_info("test on_line"); |
|
422 |
||
423 |
ctx.line = "fragment"; |
|
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
424 |
sock_test_add_recv_vec(sock, _trailing_data); |
42 | 425 |
assert_strnull(ctx.line); |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
426 |
|
43 | 427 |
// test writing |
428 |
log_info("test line_proto_send"); |
|
429 |
assert_success(-line_proto_send(lp, "foobar\r\n")); |
|
430 |
assert_success(-line_proto_send(lp, "quux\r\n")); |
|
44 | 431 |
assert_sock_data(sock, "foobar\r\nquux\r\n"); |
43 | 432 |
|
433 |
// XXX: test partial writes |
|
434 |
||
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
435 |
// cleanup |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
436 |
line_proto_release(lp); |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
437 |
} |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
438 |
|
90
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
439 |
void test_irc_queue (void) |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
440 |
{ |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
441 |
struct sock_test *sock = sock_test_create(); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
442 |
struct line_proto *lp; |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
443 |
struct irc_queue *queue; |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
444 |
struct irc_queue_entry *queue_entry; |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
445 |
struct error_info err; |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
446 |
|
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
447 |
// create the lp |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
448 |
assert_success(line_proto_create(&lp, SOCK_TEST_BASE(sock), 128, &_lp_callbacks, NULL, &err)); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
449 |
|
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
450 |
// create the queue |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
451 |
assert_success(irc_queue_create(&queue, lp, &err)); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
452 |
|
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
453 |
struct irc_line line = { |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
454 |
NULL, "TEST", { "fooX" } |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
455 |
}; |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
456 |
|
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
457 |
// then test simple writes, we should be able to push five lines directly |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
458 |
log_info("test irc_queue_process (irc_queue_send_direct)"); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
459 |
line.args[0] = "foo0"; assert_success(irc_queue_process(queue, &line)); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
460 |
line.args[0] = "foo1"; assert_success(irc_queue_process(queue, &line)); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
461 |
line.args[0] = "foo2"; assert_success(irc_queue_process(queue, &line)); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
462 |
line.args[0] = "foo3"; assert_success(irc_queue_process(queue, &line)); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
463 |
line.args[0] = "foo4"; assert_success(irc_queue_process(queue, &line)); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
464 |
|
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
465 |
// they should all be output |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
466 |
assert_sock_data(sock, |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
467 |
"TEST foo0\r\n" |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
468 |
"TEST foo1\r\n" |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
469 |
"TEST foo2\r\n" |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
470 |
"TEST foo3\r\n" |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
471 |
"TEST foo4\r\n" |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
472 |
); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
473 |
|
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
474 |
// then enqueue |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
475 |
log_info("test irc_queue_process (irc_queue_put)"); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
476 |
line.args[0] = "foo5"; assert_success(irc_queue_process(queue, &line)); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
477 |
|
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
478 |
// ensure it was enqueued |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
479 |
assert((queue_entry = TAILQ_FIRST(&queue->list)) != NULL); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
480 |
assert_strcmp(queue_entry->line_buf, "TEST foo5\r\n"); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
481 |
|
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
482 |
// ensure timer is set |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
483 |
assert(event_pending(queue->ev, EV_TIMEOUT, NULL)); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
484 |
|
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
485 |
// run the event loop to let the timer run |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
486 |
log_info("running the event loop once..."); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
487 |
assert(event_base_loop(_test_ctx.ev_base, EVLOOP_ONCE) == 0); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
488 |
|
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
489 |
// test to check that the line was now sent |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
490 |
log_info("checking that the delayed line was sent..."); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
491 |
assert_sock_data(sock, "TEST foo5\r\n"); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
492 |
assert(TAILQ_EMPTY(&queue->list)); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
493 |
assert(!event_pending(queue->ev, EV_TIMEOUT, NULL)); |
91
bca23cbe1dce
implement irc_queue for irc_conn, and add missing irc_queue_destroy, fix irc_conn_destroy
Tero Marttila <terom@fixme.fi>
parents:
90
diff
changeset
|
494 |
|
bca23cbe1dce
implement irc_queue for irc_conn, and add missing irc_queue_destroy, fix irc_conn_destroy
Tero Marttila <terom@fixme.fi>
parents:
90
diff
changeset
|
495 |
// cleanup |
bca23cbe1dce
implement irc_queue for irc_conn, and add missing irc_queue_destroy, fix irc_conn_destroy
Tero Marttila <terom@fixme.fi>
parents:
90
diff
changeset
|
496 |
irc_queue_destroy(queue); |
90
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
497 |
} |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
498 |
|
76 | 499 |
struct test_conn_ctx { |
500 |
/** Callback flags */ |
|
49
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
501 |
bool on_registered, on_TEST, on_error, on_quit; |
43 | 502 |
}; |
503 |
||
504 |
static void _conn_on_registered (struct irc_conn *conn, void *arg) |
|
505 |
{ |
|
76 | 506 |
struct test_conn_ctx *ctx = arg; |
43 | 507 |
|
508 |
(void) conn; |
|
509 |
||
44 | 510 |
if (ctx) ctx->on_registered = true; |
43 | 511 |
|
512 |
log_debug("registered"); |
|
513 |
} |
|
514 |
||
49
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
515 |
static void _conn_on_error (struct irc_conn *conn, struct error_info *err, void *arg) |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
516 |
{ |
76 | 517 |
struct test_conn_ctx *ctx = arg; |
49
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
518 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
519 |
(void) conn; |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
520 |
(void) err; |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
521 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
522 |
if (ctx) ctx->on_error = true; |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
523 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
524 |
log_debug("on_error"); |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
525 |
} |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
526 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
527 |
static void _conn_on_quit (struct irc_conn *conn, void *arg) |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
528 |
{ |
76 | 529 |
struct test_conn_ctx *ctx = arg; |
49
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
530 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
531 |
(void) conn; |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
532 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
533 |
if (ctx) ctx->on_quit = true; |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
534 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
535 |
log_debug("on_quit"); |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
536 |
} |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
537 |
|
43 | 538 |
static void _conn_on_TEST (const struct irc_line *line, void *arg) |
539 |
{ |
|
76 | 540 |
struct test_conn_ctx *ctx = arg; |
43 | 541 |
|
75
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
542 |
assert_null(line->source); |
43 | 543 |
assert_strcmp(line->command, "TEST"); |
544 |
assert_strcmp(line->args[0], "arg0"); |
|
545 |
assert_strnull(line->args[1]); |
|
546 |
||
44 | 547 |
if (ctx) ctx->on_TEST = true; |
43 | 548 |
|
549 |
log_debug("on_TEST"); |
|
550 |
} |
|
551 |
||
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
552 |
static struct irc_conn_callbacks _conn_callbacks = { |
43 | 553 |
.on_registered = &_conn_on_registered, |
49
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
554 |
.on_error = &_conn_on_error, |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
555 |
.on_quit = &_conn_on_quit, |
43 | 556 |
}; |
557 |
||
558 |
static struct irc_cmd_handler _conn_handlers[] = { |
|
559 |
{ "TEST", &_conn_on_TEST }, |
|
560 |
{ NULL, NULL } |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
561 |
}; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
562 |
|
76 | 563 |
/** |
564 |
* Create and return a new irc_conn with the given ctx (will be initialized to zero). |
|
565 |
*/ |
|
566 |
struct irc_conn* setup_irc_conn (struct sock_test *sock, bool noisy, struct test_conn_ctx *ctx) |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
567 |
{ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
568 |
struct irc_conn *conn; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
569 |
struct error_info err; |
43 | 570 |
struct irc_conn_register_info register_info = { |
571 |
"nick", "user", "realname" |
|
572 |
}; |
|
44 | 573 |
|
76 | 574 |
// init the ctx |
575 |
memset(ctx, 0, sizeof(*ctx)); |
|
576 |
||
44 | 577 |
// create the irc_conn |
578 |
assert_success(irc_conn_create(&conn, SOCK_TEST_BASE(sock), &_conn_callbacks, ctx, &err)); |
|
579 |
||
580 |
// test register |
|
581 |
if (noisy) log_info("test irc_conn_register"); |
|
582 |
assert_success(irc_conn_register(conn, ®ister_info)); |
|
583 |
assert_sock_data(sock, "NICK nick\r\nUSER user 0 * realname\r\n"); |
|
584 |
||
585 |
// test on_register callback |
|
586 |
if (noisy) log_info("test irc_conn_callbacks.on_register"); |
|
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
587 |
test_sock_push(sock, "001 mynick :Blaa blaa blaa\r\n"); |
44 | 588 |
if (ctx) assert(ctx->on_registered); |
589 |
assert_strcmp(conn->nickname, "mynick"); |
|
590 |
||
591 |
// ok |
|
592 |
return conn; |
|
593 |
} |
|
594 |
||
595 |
void test_irc_conn (void) |
|
596 |
{ |
|
76 | 597 |
struct test_conn_ctx ctx; |
598 |
struct sock_test *sock = setup_sock_test(); |
|
599 |
struct irc_conn *conn = setup_irc_conn(sock, true, &ctx); |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
600 |
|
44 | 601 |
// add our test handlers |
602 |
assert_success(irc_conn_add_cmd_handlers(conn, _conn_handlers, &ctx)); |
|
43 | 603 |
|
604 |
// test on_TEST handler |
|
75
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
605 |
// XXX: come up with a better prefix |
43 | 606 |
log_info("test irc_conn.handlers"); |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
607 |
test_sock_push(sock, ":foobar-prefix TEST arg0\r\n"); |
43 | 608 |
assert(ctx.on_TEST); |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
609 |
|
44 | 610 |
// test PING/PONG |
611 |
log_info("test PING/PONG"); |
|
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
612 |
test_sock_push(sock, "PING foo\r\n"); |
44 | 613 |
assert_sock_data(sock, "PONG foo\r\n"); |
614 |
||
49
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
615 |
// quit nicely |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
616 |
log_info("test QUIT"); |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
617 |
assert_success(irc_conn_QUIT(conn, "bye now")); |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
618 |
assert_sock_data(sock, "QUIT :bye now\r\n"); |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
619 |
assert(conn->quitting); |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
620 |
|
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
621 |
test_sock_push(sock, "ERROR :Closing Link: Quit\r\n"); |
49
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
622 |
sock_test_set_recv_eof(sock); |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
623 |
assert(conn->quit && !conn->quitting && !conn->registered); |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
624 |
assert(ctx.on_quit); |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
625 |
assert(!ctx.on_error); |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
626 |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
627 |
// destroy it |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
628 |
irc_conn_destroy(conn); |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
629 |
} |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
630 |
|
76 | 631 |
void test_irc_conn_self_nick (void) |
632 |
{ |
|
633 |
struct test_conn_ctx ctx; |
|
634 |
struct sock_test *sock = setup_sock_test(); |
|
635 |
struct irc_conn *conn = setup_irc_conn(sock, false, &ctx); |
|
636 |
||
637 |
log_info("test irc_conn_on_NICK"); |
|
638 |
test_sock_push(sock, ":mynick!user@somehost NICK mynick2\r\n"); |
|
639 |
assert_strcmp(conn->nickname, "mynick2"); |
|
640 |
||
641 |
// cleanup |
|
642 |
irc_conn_destroy(conn); |
|
643 |
} |
|
644 |
||
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
645 |
struct test_chan_ctx { |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
646 |
/** The channel name */ |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
647 |
const char *channel; |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
648 |
|
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
649 |
/** The channel we're supposed to be testing */ |
44 | 650 |
struct irc_chan *chan; |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
651 |
|
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
652 |
/** Flags for callbacks called*/ |
74
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
653 |
bool on_chan_self_join, on_chan_self_part, on_chan_join, on_chan_part; |
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
654 |
|
44 | 655 |
}; |
656 |
||
657 |
void _on_chan_self_join (struct irc_chan *chan, void *arg) |
|
658 |
{ |
|
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
659 |
struct test_chan_ctx *ctx = arg; |
44 | 660 |
|
661 |
assert(chan == ctx->chan); |
|
662 |
||
663 |
ctx->on_chan_self_join = true; |
|
664 |
||
665 |
log_debug("on_self_join"); |
|
666 |
} |
|
667 |
||
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
668 |
void _on_chan_join (struct irc_chan *chan, const struct irc_nm *source, void *arg) |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
669 |
{ |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
670 |
struct test_chan_ctx *ctx = arg; |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
671 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
672 |
assert(chan == ctx->chan); |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
673 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
674 |
// XXX: verify source |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
675 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
676 |
ctx->on_chan_join = true; |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
677 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
678 |
log_debug("on_join"); |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
679 |
} |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
680 |
|
74
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
681 |
void _on_chan_part (struct irc_chan *chan, const struct irc_nm *source, const char *msg, void *arg) |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
682 |
{ |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
683 |
struct test_chan_ctx *ctx = arg; |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
684 |
|
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
685 |
assert(chan == ctx->chan); |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
686 |
|
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
687 |
// XXX: verify source |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
688 |
// XXX: verify msg |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
689 |
|
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
690 |
ctx->on_chan_part = true; |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
691 |
|
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
692 |
log_debug("on_part"); |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
693 |
} |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
694 |
|
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
695 |
|
44 | 696 |
struct irc_chan_callbacks _chan_callbacks = { |
697 |
.on_self_join = &_on_chan_self_join, |
|
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
698 |
.on_join = &_on_chan_join, |
74
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
699 |
.on_part = &_on_chan_part, |
44 | 700 |
}; |
701 |
||
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
702 |
/** |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
703 |
* Setup an irc_net using the given socket, and consume the register request output, but do not push the RPL_WELCOME |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
704 |
*/ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
705 |
struct irc_net* setup_irc_net_unregistered (struct sock_test *sock) |
44 | 706 |
{ |
707 |
struct irc_net *net; |
|
708 |
struct irc_net_info net_info = { |
|
709 |
.register_info = { |
|
710 |
"nick", "user", "realname" |
|
711 |
}, |
|
712 |
}; |
|
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
713 |
struct error_info err; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
714 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
715 |
// create the irc_net |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
716 |
net_info.raw_sock = SOCK_TEST_BASE(sock); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
717 |
assert_success(irc_net_create(&net, &net_info, &err)); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
718 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
719 |
// test register output |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
720 |
assert_sock_data(sock, "NICK nick\r\nUSER user 0 * realname\r\n"); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
721 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
722 |
// ok |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
723 |
return net; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
724 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
725 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
726 |
/** |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
727 |
* Push to RPL_WELCOME reply, and test state |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
728 |
*/ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
729 |
void do_irc_net_welcome (struct sock_test *sock, struct irc_net *net) |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
730 |
{ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
731 |
// registration reply |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
732 |
test_sock_push(sock, "001 mynick :Blaa blaa blaa\r\n"); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
733 |
assert(net->conn->registered); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
734 |
assert_strcmp(net->conn->nickname, "mynick"); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
735 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
736 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
737 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
738 |
/** |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
739 |
* Creates an irc_net and puts it into the registered state |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
740 |
*/ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
741 |
struct irc_net* setup_irc_net (struct sock_test *sock) |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
742 |
{ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
743 |
struct irc_net *net; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
744 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
745 |
net = setup_irc_net_unregistered(sock); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
746 |
do_irc_net_welcome(sock, net); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
747 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
748 |
// ok |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
749 |
return net; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
750 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
751 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
752 |
/** |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
753 |
* General test for irc_net to handle startup |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
754 |
*/ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
755 |
void test_irc_net (void) |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
756 |
{ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
757 |
struct sock_test *sock = setup_sock_test(); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
758 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
759 |
// create the network |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
760 |
log_info("test irc_net_create"); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
761 |
struct irc_net *net = setup_irc_net_unregistered(sock); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
762 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
763 |
// send the registration reply |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
764 |
log_info("test irc_conn_on_RPL_WELCOME"); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
765 |
do_irc_net_welcome(sock, net); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
766 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
767 |
// test errors by setting EOF |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
768 |
log_info("test irc_net_error"); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
769 |
sock_test_set_recv_eof(sock); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
770 |
assert(net->conn == NULL); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
771 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
772 |
// cleanup |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
773 |
irc_net_destroy(net); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
774 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
775 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
776 |
/** |
74
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
777 |
* Ensure that an irc_chan_user exists/doesn't exist for the given channel/nickname, and return it |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
778 |
*/ |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
779 |
struct irc_chan_user* check_chan_user (struct irc_chan *chan, const char *nickname, bool exists) |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
780 |
{ |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
781 |
struct irc_chan_user *chan_user = irc_chan_get_user(chan, nickname); |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
782 |
|
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
783 |
if (exists && chan_user == NULL) |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
784 |
FATAL("user %s not found in channel %s", dump_str(nickname), dump_str(irc_chan_name(chan))); |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
785 |
|
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
786 |
if (!exists && chan_user) |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
787 |
FATAL("user %s should not be on channel %s anymore", dump_str(nickname), dump_str(irc_chan_name(chan))); |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
788 |
|
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
789 |
log_debug("%s, exists=%d -> %p: user=%p, nickname=%s", |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
790 |
nickname, exists, chan_user, chan_user ? chan_user->user : NULL, chan_user ? chan_user->user->nickname : NULL); |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
791 |
|
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
792 |
if (chan_user) |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
793 |
assert_strcmp(chan_user->user->nickname, nickname); |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
794 |
|
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
795 |
return chan_user; |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
796 |
} |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
797 |
|
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
798 |
/** |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
799 |
* Creates an irc_chan on the given irc_net, but does not check any output (useful for testing offline add). |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
800 |
* |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
801 |
* You must pass a test_chan_ctx for use with later operations, this will be initialized for you. |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
802 |
*/ |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
803 |
struct irc_chan* setup_irc_chan_raw (struct irc_net *net, const char *channel, struct test_chan_ctx *ctx) |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
804 |
{ |
44 | 805 |
struct irc_chan *chan; |
806 |
struct irc_chan_info chan_info = { |
|
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
807 |
.channel = channel, |
44 | 808 |
}; |
809 |
struct error_info err; |
|
810 |
||
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
811 |
// initialize the given ctx |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
812 |
memset(ctx, 0, sizeof(*ctx)); |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
813 |
ctx->channel = channel; |
44 | 814 |
|
815 |
// add a channel |
|
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
816 |
assert_success(irc_net_add_chan(net, &chan, &chan_info, &err)); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
817 |
assert(!chan->joined); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
818 |
assert_success(irc_chan_add_callbacks(chan, &_chan_callbacks, ctx)); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
819 |
ctx->chan = chan; |
44 | 820 |
|
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
821 |
// ok |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
822 |
return chan; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
823 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
824 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
825 |
/** |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
826 |
* Checks that the JOIN request for a channel was sent, and sends the basic JOIN reply |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
827 |
*/ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
828 |
void do_irc_chan_join (struct sock_test *sock, struct test_chan_ctx *ctx) |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
829 |
{ |
44 | 830 |
// JOIN request |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
831 |
assert(ctx->chan->joining); |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
832 |
assert_sock_data(sock, "JOIN %s\r\n", ctx->channel); |
44 | 833 |
|
834 |
// JOIN reply |
|
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
835 |
test_sock_push(sock, ":mynick!user@host JOIN %s\r\n", ctx->channel); |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
836 |
assert(!ctx->chan->joining && ctx->chan->joined); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
837 |
assert(ctx->on_chan_self_join); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
838 |
} |
46
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
839 |
|
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
840 |
/** |
74
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
841 |
* Sends a short RPL_NAMREPLY/RPL_ENDOFNAMES reply and checks that the users list matches |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
842 |
*/ |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
843 |
void do_irc_chan_namreply (struct sock_test *sock, struct test_chan_ctx *ctx) |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
844 |
{ |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
845 |
// RPL_NAMREPLY |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
846 |
test_sock_push(sock, "353 mynick = %s :mynick userA +userB @userC\r\n", ctx->channel); |
82
bc767e01648d
fix a valgrind'd bug with irc_nick_chanflags being given an empty string
Tero Marttila <terom@fixme.fi>
parents:
81
diff
changeset
|
847 |
test_sock_push(sock, "353 mynick = %s :trailingspace \r\n", ctx->channel); |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
848 |
test_sock_push(sock, "366 mynick %s :End of NAMES\r\n", ctx->channel); |
74
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
849 |
|
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
850 |
// XXX: this should be an exclusive test, i.e. these should be the only ones... |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
851 |
check_chan_user(ctx->chan, "mynick", true); |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
852 |
check_chan_user(ctx->chan, "userA", true); |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
853 |
check_chan_user(ctx->chan, "userB", true); |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
854 |
check_chan_user(ctx->chan, "userC", true); |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
855 |
} |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
856 |
|
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
857 |
/** |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
858 |
* Creates an irc_chan on the given irc_net, and checks up to the JOIN reply |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
859 |
*/ |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
860 |
struct irc_chan* setup_irc_chan_join (struct sock_test *sock, struct irc_net *net, const char *channel, struct test_chan_ctx *ctx) |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
861 |
{ |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
862 |
setup_irc_chan_raw(net, channel, ctx); |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
863 |
do_irc_chan_join(sock, ctx); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
864 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
865 |
// ok |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
866 |
return ctx->chan; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
867 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
868 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
869 |
/** |
74
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
870 |
* Creates an irc_chan on the given irc_net, sends the JOIN stuff plus RPL_NAMREPLY |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
871 |
*/ |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
872 |
struct irc_chan* setup_irc_chan (struct sock_test *sock, struct irc_net *net, const char *channel, struct test_chan_ctx *ctx) |
74
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
873 |
{ |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
874 |
setup_irc_chan_raw(net, channel, ctx); |
74
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
875 |
do_irc_chan_join(sock, ctx); |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
876 |
do_irc_chan_namreply(sock, ctx); |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
877 |
|
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
878 |
// ok |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
879 |
return ctx->chan; |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
880 |
} |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
881 |
|
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
882 |
|
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
883 |
/** |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
884 |
* Call irc_net_add_chan while offline, and ensure that we send the JOIN request after RPL_WELCOME, and handle the join |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
885 |
* reply OK. |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
886 |
*/ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
887 |
void test_irc_chan_add_offline (void) |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
888 |
{ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
889 |
struct test_chan_ctx ctx; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
890 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
891 |
struct sock_test *sock = setup_sock_test(); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
892 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
893 |
log_info("test irc_net_create"); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
894 |
struct irc_net *net = setup_irc_net_unregistered(sock); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
895 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
896 |
// add an offline channel |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
897 |
log_info("test offline irc_net_add_chan"); |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
898 |
struct irc_chan *chan = setup_irc_chan_raw(net, "#test", &ctx); |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
899 |
assert(!chan->joining && !chan->joined); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
900 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
901 |
// send the registration reply |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
902 |
log_info("test irc_conn_on_RPL_WELCOME"); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
903 |
do_irc_net_welcome(sock, net); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
904 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
905 |
// test the join sequence |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
906 |
log_info("test irc_chan_join/irc_chan_on_JOIN"); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
907 |
do_irc_chan_join(sock, &ctx); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
908 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
909 |
// cleanup |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
910 |
irc_net_destroy(net); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
911 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
912 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
913 |
void test_irc_chan_namreply (void) |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
914 |
{ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
915 |
struct test_chan_ctx ctx; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
916 |
struct sock_test *sock = setup_sock_test(); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
917 |
struct irc_net *net = setup_irc_net(sock); |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
918 |
setup_irc_chan_join(sock, net, "#test", &ctx); |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
919 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
920 |
log_info("test irc_chan_on_RPL_NAMREPLY"); |
74
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
921 |
do_irc_chan_namreply(sock, &ctx); |
47
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
922 |
|
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
923 |
// cleanup |
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
924 |
irc_net_destroy(net); |
44 | 925 |
} |
926 |
||
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
927 |
void test_irc_chan_user_join (void) |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
928 |
{ |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
929 |
struct test_chan_ctx ctx; |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
930 |
struct sock_test *sock = setup_sock_test(); |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
931 |
struct irc_net *net = setup_irc_net(sock); |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
932 |
struct irc_chan *chan = setup_irc_chan(sock, net, "#test", &ctx); |
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
933 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
934 |
// have a user join |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
935 |
log_info("test irc_chan_on_JOIN"); |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
936 |
test_sock_push(sock, ":newuser!someone@somewhere JOIN %s\r\n", "#test"); |
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
937 |
assert(ctx.on_chan_join); |
74
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
938 |
check_chan_user(chan, "newuser", true); |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
939 |
|
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
940 |
// cleanup |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
941 |
irc_net_destroy(net); |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
942 |
} |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
943 |
|
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
944 |
void test_irc_chan_user_part (void) |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
945 |
{ |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
946 |
struct test_chan_ctx ctx; |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
947 |
struct sock_test *sock = setup_sock_test(); |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
948 |
struct irc_net *net = setup_irc_net(sock); |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
949 |
struct irc_chan *chan = setup_irc_chan(sock, net, "#test", &ctx); |
74
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
950 |
|
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
951 |
// have a user join |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
952 |
log_info("test irc_chan_on_PART"); |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
953 |
test_sock_push(sock, ":userA!someone@somewhere PART %s\r\n", "#test"); |
74
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
954 |
assert(ctx.on_chan_part); ctx.on_chan_part = NULL; |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
955 |
check_chan_user(chan, "userA", false); |
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
956 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
957 |
// cleanup |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
958 |
irc_net_destroy(net); |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
959 |
} |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
960 |
|
89 | 961 |
void test_irc_chan_user_kick (void) |
962 |
{ |
|
963 |
struct test_chan_ctx ctx; |
|
964 |
struct sock_test *sock = setup_sock_test(); |
|
965 |
struct irc_net *net = setup_irc_net(sock); |
|
966 |
struct irc_chan *chan = setup_irc_chan(sock, net, "#test", &ctx); |
|
967 |
||
968 |
// kick a user |
|
969 |
log_info("test irc_chan_on_KICK (other)"); |
|
970 |
test_sock_push(sock, ":userA!someone@somewhere KICK %s userB\r\n", "#test"); |
|
971 |
check_chan_user(chan, "userA", true); |
|
972 |
check_chan_user(chan, "userB", false); |
|
973 |
||
974 |
// cleanup |
|
975 |
irc_net_destroy(net); |
|
976 |
} |
|
977 |
||
978 |
void test_irc_chan_self_kick (void) |
|
979 |
{ |
|
980 |
struct test_chan_ctx ctx; |
|
981 |
struct sock_test *sock = setup_sock_test(); |
|
982 |
struct irc_net *net = setup_irc_net(sock); |
|
983 |
struct irc_chan *chan = setup_irc_chan(sock, net, "#test", &ctx); |
|
984 |
||
985 |
// kick a user |
|
986 |
log_info("test irc_chan_on_KICK (self)"); |
|
987 |
test_sock_push(sock, ":userA!someone@somewhere KICK %s mynick foobar\r\n", "#test"); |
|
988 |
assert(!chan->joined); |
|
989 |
assert(chan->kicked); |
|
990 |
||
991 |
// cleanup |
|
992 |
irc_net_destroy(net); |
|
993 |
} |
|
994 |
||
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
995 |
void test_irc_chan_user_nick (void) |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
996 |
{ |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
997 |
struct test_chan_ctx ctx; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
998 |
struct sock_test *sock = setup_sock_test(); |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
999 |
struct irc_net *net = setup_irc_net(sock); |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
1000 |
struct irc_chan *chan = setup_irc_chan(sock, net, "#test", &ctx); |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
1001 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
1002 |
// rename one of the users |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
1003 |
log_info("test irc_net_on_chanuser"); |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
1004 |
test_sock_push(sock, ":userA!someone@somewhere NICK userA2\r\n"); |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
1005 |
check_chan_user(chan, "userA", false); |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
1006 |
check_chan_user(chan, "userB", true); |
81
d90edc052352
update TODO and fix some valgrind errors in test
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
1007 |
|
d90edc052352
update TODO and fix some valgrind errors in test
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
1008 |
// cleanup |
d90edc052352
update TODO and fix some valgrind errors in test
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
1009 |
irc_net_destroy(net); |
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
1010 |
} |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
1011 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
1012 |
void test_irc_chan_user_quit (void) |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
1013 |
{ |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
1014 |
struct test_chan_ctx ctx; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
1015 |
struct sock_test *sock = setup_sock_test(); |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
1016 |
struct irc_net *net = setup_irc_net(sock); |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
1017 |
struct irc_chan *chan = setup_irc_chan(sock, net, "#test", &ctx); |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
1018 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
1019 |
// rename one of the users |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
1020 |
log_info("test irc_net_on_chanuser"); |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
1021 |
test_sock_push(sock, ":userA!someone@somewhere QUIT foo\r\n"); |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
1022 |
check_chan_user(chan, "userA", false); |
81
d90edc052352
update TODO and fix some valgrind errors in test
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
1023 |
|
d90edc052352
update TODO and fix some valgrind errors in test
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
1024 |
// cleanup |
d90edc052352
update TODO and fix some valgrind errors in test
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
1025 |
irc_net_destroy(net); |
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
1026 |
} |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
1027 |
|
88
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1028 |
void _test_irc_chan_on_CTCP_ACTION (const struct irc_line *line, void *arg) |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1029 |
{ |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1030 |
bool *flag = arg; |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1031 |
|
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1032 |
log_debug("CTCP ACTION"); |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1033 |
|
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1034 |
*flag = true; |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1035 |
} |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1036 |
|
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1037 |
static struct irc_cmd_handler _test_irc_chan_handlers[] = { |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1038 |
{ "CTCP ACTION", &_test_irc_chan_on_CTCP_ACTION }, |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1039 |
{ NULL, NULL } |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1040 |
}; |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1041 |
|
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1042 |
void test_irc_chan_CTCP_ACTION (void) |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1043 |
{ |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1044 |
struct test_chan_ctx ctx; |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1045 |
struct sock_test *sock = setup_sock_test(); |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1046 |
struct irc_net *net = setup_irc_net(sock); |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1047 |
struct irc_chan *chan = setup_irc_chan(sock, net, "#test", &ctx); |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1048 |
bool cb_ok = false; |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1049 |
|
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1050 |
// add our handler |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1051 |
assert_success(irc_cmd_add(&chan->handlers, _test_irc_chan_handlers, &cb_ok)); |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1052 |
|
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1053 |
// rename one of the users |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1054 |
log_info("test irc_conn_on_CTCP_ACTION"); |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1055 |
test_sock_push(sock, ":userA!someone@somewhere PRIVMSG #test \001ACTION hello world\001\r\n"); |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1056 |
assert(cb_ok); |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1057 |
|
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1058 |
// cleanup |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1059 |
irc_net_destroy(net); |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1060 |
} |
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1061 |
|
97
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
91
diff
changeset
|
1062 |
void test_irc_chan_privmsg (void) |
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
91
diff
changeset
|
1063 |
{ |
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
91
diff
changeset
|
1064 |
struct test_chan_ctx ctx; |
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
91
diff
changeset
|
1065 |
struct sock_test *sock = setup_sock_test(); |
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
91
diff
changeset
|
1066 |
struct irc_net *net = setup_irc_net(sock); |
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
91
diff
changeset
|
1067 |
struct irc_chan *chan = setup_irc_chan(sock, net, "#test", &ctx); |
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
91
diff
changeset
|
1068 |
|
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
91
diff
changeset
|
1069 |
// rename one of the users |
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
91
diff
changeset
|
1070 |
log_info("test irc_chan_PRIVMSG"); |
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
91
diff
changeset
|
1071 |
assert_success(irc_chan_PRIVMSG(chan, "foobar quux")); |
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
91
diff
changeset
|
1072 |
assert_sock_data(sock, "PRIVMSG #test :foobar quux\r\n"); |
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
91
diff
changeset
|
1073 |
|
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
91
diff
changeset
|
1074 |
// cleanup |
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
91
diff
changeset
|
1075 |
irc_net_destroy(net); |
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
91
diff
changeset
|
1076 |
} |
88
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
1077 |
|
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1078 |
// XXX: needs to be split off into its own test_fifo.c |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1079 |
#include <sys/types.h> |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1080 |
#include <sys/stat.h> |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1081 |
#include <fcntl.h> |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1082 |
#include <unistd.h> |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1083 |
struct test_fifo_ctx { |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1084 |
/** Path to the fifo */ |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1085 |
const char *path; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1086 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1087 |
/** The write end */ |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1088 |
int fd; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1089 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1090 |
/** callback invoked? */ |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1091 |
bool on_read; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1092 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1093 |
/** Still running? */ |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1094 |
bool run; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1095 |
}; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1096 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1097 |
/** |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1098 |
* Open the FIFO and write the test string to it |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1099 |
*/ |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1100 |
static void test_fifo_open_write (struct test_fifo_ctx *ctx) |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1101 |
{ |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1102 |
// ...raw, for writing |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1103 |
if ((ctx->fd = open(ctx->path, O_WRONLY)) < 0) |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1104 |
FATAL_PERROR("open"); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1105 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1106 |
// write something into it |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1107 |
if (write(ctx->fd, "test", 4) != 4) |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1108 |
FATAL_PERROR("write"); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1109 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1110 |
} |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1111 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1112 |
static void test_fifo_close (struct test_fifo_ctx *ctx) |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1113 |
{ |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1114 |
close(ctx->fd); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1115 |
ctx->fd = -1; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1116 |
} |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1117 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1118 |
static void test_fifo_on_read (struct sock_stream *fifo, void *arg) |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1119 |
{ |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1120 |
int ret; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1121 |
char buf[16]; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1122 |
struct test_fifo_ctx *ctx = arg; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1123 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1124 |
// read it back out |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1125 |
log_info("test fifo_read"); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1126 |
if ((ret = sock_stream_read(fifo, buf, 16)) < 0) |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1127 |
assert_success(-ret); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1128 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1129 |
assert(ret == 4); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1130 |
assert_strncmp(buf, "test", 4); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1131 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1132 |
if (ctx->on_read) { |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1133 |
test_fifo_close(ctx); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1134 |
ctx->run = false; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1135 |
return; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1136 |
} |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1137 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1138 |
// re-open the fifo |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1139 |
log_info("test fifo-re-open"); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1140 |
test_fifo_close(ctx); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1141 |
test_fifo_open_write(ctx); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1142 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1143 |
assert_success(sock_stream_event_enable(fifo, EV_READ)); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1144 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1145 |
ctx->on_read = true; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1146 |
} |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1147 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1148 |
static struct sock_stream_callbacks test_fifo_callbacks = { |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1149 |
.on_read = test_fifo_on_read, |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1150 |
}; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1151 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1152 |
void test_fifo (void) |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1153 |
{ |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1154 |
struct sock_stream *fifo; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1155 |
struct error_info err; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1156 |
struct test_fifo_ctx _ctx, *ctx = &_ctx; memset(ctx, 0, sizeof(*ctx)); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1157 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1158 |
// XXX: requires that this be run in a suitable CWD |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1159 |
ctx->path = "test.fifo"; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1160 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1161 |
// create the fifo |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1162 |
if ((mkfifo(ctx->path, 0600) < 0) && (errno != EEXIST)) |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1163 |
FATAL_PERROR("mkfifo"); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1164 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1165 |
// open it |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1166 |
log_info("test fifo_open_read"); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1167 |
assert_success(fifo_open_read(&fifo, ctx->path, &err)); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1168 |
assert_success(sock_stream_event_init(fifo, &test_fifo_callbacks, ctx)); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1169 |
assert_success(sock_stream_event_enable(fifo, EV_READ)); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1170 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1171 |
// put some data into it |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1172 |
test_fifo_open_write(ctx); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1173 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1174 |
// run the event loop |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1175 |
log_debug("running the event loop..."); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1176 |
ctx->run = true; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1177 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1178 |
while (ctx->run) |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1179 |
assert(event_base_loop(_test_ctx.ev_base, EVLOOP_ONCE) == 0); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1180 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1181 |
// check |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1182 |
assert(ctx->fd < 0); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1183 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1184 |
// cleanup |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1185 |
sock_stream_release(fifo); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1186 |
} |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1187 |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1188 |
/** |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1189 |
* Test definition |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1190 |
*/ |
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1191 |
struct test { |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1192 |
/** Test name */ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1193 |
const char *name; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1194 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1195 |
/** Test func */ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1196 |
void (*func) (void); |
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1197 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1198 |
bool optional; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1199 |
}; |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1200 |
|
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1201 |
#define DEF_TEST(name) { #name, &test_ ## name, false } |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1202 |
#define DEF_TEST_OPTIONAL(name) { #name, &test_ ## name, true } |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1203 |
#define DEF_TEST_END { NULL, NULL, false } |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1204 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1205 |
static struct test _tests[] = { |
125
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
1206 |
DEF_TEST( str_quote ), |
129
361740b82fe5
implement str_format with tests
Tero Marttila <terom@fixme.fi>
parents:
125
diff
changeset
|
1207 |
DEF_TEST( str_format ), |
125
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
1208 |
DEF_TEST( dump_str ), |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
1209 |
DEF_TEST( sock_test ), |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
1210 |
DEF_TEST( line_proto ), |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
1211 |
DEF_TEST( irc_queue ), |
75
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
1212 |
// XXX: irc_line_parse_invalid_prefix |
125
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
1213 |
DEF_TEST( irc_conn ), |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
1214 |
DEF_TEST( irc_conn_self_nick ), |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
1215 |
DEF_TEST( irc_net ), |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
1216 |
DEF_TEST( irc_chan_add_offline ), |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
1217 |
DEF_TEST( irc_chan_namreply ), |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
1218 |
DEF_TEST( irc_chan_user_join ), |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
1219 |
DEF_TEST( irc_chan_user_part ), |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
1220 |
DEF_TEST( irc_chan_user_kick ), |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
1221 |
DEF_TEST( irc_chan_self_kick ), |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
1222 |
DEF_TEST( irc_chan_user_nick ), |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
1223 |
DEF_TEST( irc_chan_user_quit ), |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
1224 |
DEF_TEST( irc_chan_CTCP_ACTION ), |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
1225 |
DEF_TEST( irc_chan_privmsg ), |
5c70fb2d6793
move test.c dump_str implemention into str.h str_quote, and improve it
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
1226 |
DEF_TEST_OPTIONAL( fifo ), |
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1227 |
DEF_TEST_END |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1228 |
}; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1229 |
|
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1230 |
/** |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1231 |
* Command-line option codes |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1232 |
*/ |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1233 |
enum option_code { |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1234 |
OPT_HELP = 'h', |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1235 |
OPT_DEBUG = 'd', |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1236 |
OPT_QUIET = 'q', |
90
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
1237 |
OPT_LIST = 'l', |
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1238 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1239 |
/** Options without short names */ |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1240 |
_OPT_EXT_BEGIN = 0x00ff, |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1241 |
}; |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1242 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1243 |
/** |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1244 |
* Command-line option definitions |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1245 |
*/ |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1246 |
static struct option options[] = { |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1247 |
{"help", 0, NULL, OPT_HELP }, |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1248 |
{"debug", 0, NULL, OPT_DEBUG }, |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1249 |
{"quiet", 0, NULL, OPT_QUIET }, |
90
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
1250 |
{"list", 0, NULL, OPT_LIST }, |
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1251 |
{0, 0, 0, 0 }, |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1252 |
}; |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1253 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1254 |
/** |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1255 |
* Display --help output on stdout |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1256 |
*/ |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1257 |
static void usage (const char *exe) |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1258 |
{ |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1259 |
printf("Usage: %s [OPTIONS]\n", exe); |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1260 |
printf("\n"); |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1261 |
printf(" --help / -h display this message\n"); |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1262 |
printf(" --debug / -d display DEBUG log messages\n"); |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1263 |
printf(" --quiet / -q supress INFO log messages\n"); |
90
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
1264 |
printf(" --list / -l list all tests\n"); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
1265 |
} |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
1266 |
|
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
1267 |
static void list_tests (struct test *tests) |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
1268 |
{ |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
1269 |
struct test *test; |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
1270 |
|
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
1271 |
printf("Available tests:\n"); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
1272 |
|
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
1273 |
for (test = tests; test->name; test++) { |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
1274 |
printf("\t%s\n", test->name); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
1275 |
} |
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1276 |
} |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1277 |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1278 |
int main (int argc, char **argv) |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1279 |
{ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1280 |
struct test *test; |
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1281 |
size_t test_count = 0; |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
1282 |
|
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1283 |
int opt, option_index; |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1284 |
const char *filter = NULL; |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1285 |
|
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1286 |
// parse options |
90
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
1287 |
while ((opt = getopt_long(argc, argv, "hdql", options, &option_index)) != -1) { |
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1288 |
switch (opt) { |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1289 |
case OPT_HELP: |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1290 |
usage(argv[0]); |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1291 |
exit(EXIT_SUCCESS); |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1292 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1293 |
case OPT_DEBUG: |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1294 |
set_log_level(LOG_DEBUG); |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1295 |
break; |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
1296 |
|
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1297 |
case OPT_QUIET: |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1298 |
set_log_level(LOG_WARN); |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1299 |
break; |
90
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
1300 |
|
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
1301 |
case OPT_LIST: |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
1302 |
list_tests(_tests); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
1303 |
exit(EXIT_SUCCESS); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
1304 |
|
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1305 |
case '?': |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1306 |
usage(argv[0]); |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1307 |
exit(EXIT_FAILURE); |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1308 |
} |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1309 |
} |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1310 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1311 |
if (optind < argc) { |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1312 |
if (optind == argc - 1) { |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1313 |
// filter |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1314 |
filter = argv[optind]; |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1315 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1316 |
log_info("only running tests: %s", filter); |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1317 |
} else { |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1318 |
FATAL("too many arguments"); |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1319 |
} |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
1320 |
} |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1321 |
|
90
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
1322 |
// setup the sockets stuff |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
1323 |
_test_ctx.ev_base = setup_sock(); |
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
1324 |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1325 |
// run tests |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1326 |
for (test = _tests; test->name; test++) { |
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
1327 |
if ((filter && strcmp(test->name, filter)) || (!filter && test->optional)) |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
1328 |
continue; |
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
1329 |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1330 |
log_info("Running test: %s", test->name); |
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1331 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1332 |
test_count++; |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1333 |
test->func(); |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1334 |
} |
46
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
1335 |
|
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1336 |
// no tests run? |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1337 |
if (test_count == 0) |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1338 |
FATAL("no tests run"); |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1339 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1340 |
log_info("done, ran %zu tests", test_count); |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1341 |
} |