author | Tero Marttila <terom@fixme.fi> |
Fri, 27 Mar 2009 00:48:12 +0200 | |
changeset 81 | d90edc052352 |
parent 78 | 941bb8379d3d |
child 82 | bc767e01648d |
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" |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
6 |
#include "irc_conn.h" |
44 | 7 |
#include "irc_net.h" |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
8 |
#include "log.h" |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
9 |
#include "error.h" |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
10 |
|
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
11 |
#include <stdlib.h> |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
12 |
#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
|
13 |
#include <getopt.h> |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
14 |
#include <assert.h> |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
15 |
#include <ctype.h> |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
16 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
17 |
#define DUMP_STR_BUF 1024 |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
18 |
#define DUMP_STR_COUNT 8 |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
19 |
#define DUMP_STR_TAIL 10 |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
20 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
21 |
char *dump_str_append (char *buf, const char *str) |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
22 |
{ |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
23 |
while (*str) |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
24 |
*buf++ = *str++; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
25 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
26 |
return buf; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
27 |
} |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
28 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
29 |
/** |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
30 |
* 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
|
31 |
* |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
32 |
* 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
|
33 |
* |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
34 |
* 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
|
35 |
* |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
36 |
* 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
|
37 |
* |
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
38 |
* @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
|
39 |
* @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
|
40 |
* @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
|
41 |
*/ |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
42 |
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
|
43 |
{ |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
44 |
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
|
45 |
static size_t dump_idx = 0; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
46 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
47 |
// pick a buffer to use |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
48 |
const char *str_ptr = str; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
49 |
char *buf_ptr = dump_buf[dump_idx++], *buf = buf_ptr; |
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 |
// cycle |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
52 |
if (dump_idx >= DUMP_STR_COUNT) |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
53 |
dump_idx = 0; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
54 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
55 |
// NULL? |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
56 |
if (str == NULL) { |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
57 |
buf = dump_str_append(buf, "NULL"); |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
58 |
*buf = '\0'; |
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 |
return buf_ptr; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
61 |
} |
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 |
// quote |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
64 |
*buf++ = '\''; |
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 |
// dump each char |
51
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
67 |
for (; ( |
81
d90edc052352
update TODO and fix some valgrind errors in test
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
68 |
// ...don't consume more than len bytes of str, unless len < 0 |
d90edc052352
update TODO and fix some valgrind errors in test
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
69 |
(len < 0 || (size_t) (str - str_ptr) < (size_t) len) |
d90edc052352
update TODO and fix some valgrind errors in test
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
70 |
|
51
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
71 |
// ...stop on NUL |
81
d90edc052352
update TODO and fix some valgrind errors in test
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
72 |
&& *str |
51
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
73 |
|
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
74 |
// ...leave DUMP_STR_TAIL bytes room at the end of buf |
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
75 |
&& (size_t) (buf - buf_ptr) < DUMP_STR_BUF - DUMP_STR_TAIL |
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
76 |
|
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
77 |
); str++ |
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
78 |
) { |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
79 |
if (*str == '\'') { |
51
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
80 |
// escape quotes |
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
81 |
buf = dump_str_append(buf, "\\'"); |
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
82 |
|
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
83 |
} else if (*str == '\\') { |
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
84 |
// escape escapes |
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
85 |
buf = dump_str_append(buf, "\\\\"); |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
86 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
87 |
} else if (isprint(*str)) { |
51
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
88 |
// normal char |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
89 |
*buf++ = *str; |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
90 |
|
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
91 |
} else { |
51
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
92 |
// something more special |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
93 |
switch (*str) { |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
94 |
case '\r': |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
95 |
buf = dump_str_append(buf, "\\r"); break; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
96 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
97 |
case '\n': |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
98 |
buf = dump_str_append(buf, "\\n"); break; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
99 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
100 |
default: |
51
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
101 |
// format as "\xFF" |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
102 |
buf += snprintf(buf, (DUMP_STR_BUF - (buf - buf_ptr)), "\\x%02x", *str); |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
103 |
break; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
104 |
} |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
105 |
} |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
106 |
} |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
107 |
|
51
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
108 |
// end quote |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
109 |
*buf++ = '\''; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
110 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
111 |
// overflow? |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
112 |
if ((size_t)(buf - buf_ptr) == DUMP_STR_BUF - DUMP_STR_TAIL) |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
113 |
buf = dump_str_append(buf, "..."); |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
114 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
115 |
// terminate |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
116 |
*buf = '\0'; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
117 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
118 |
// ok |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
119 |
return buf_ptr; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
120 |
} |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
121 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
122 |
const char *dump_str (const char *str) |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
123 |
{ |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
124 |
return dump_strn(str, -1); |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
125 |
} |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
126 |
|
75
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
127 |
void assert_null (const void *ptr) |
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
128 |
{ |
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
129 |
if (ptr) |
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
130 |
FATAL("%p != NULL", ptr); |
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
131 |
} |
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
132 |
|
42 | 133 |
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
|
134 |
{ |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
135 |
if (!is || strcmp(is, should_be)) |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
136 |
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
|
137 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
138 |
|
42 | 139 |
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
|
140 |
{ |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
141 |
if (!is || strncmp(is, should_be, n)) |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
142 |
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
|
143 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
144 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
145 |
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
|
146 |
{ |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
147 |
if (!str || strlen(str) != n) |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
148 |
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
|
149 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
150 |
|
42 | 151 |
void assert_strnull (const char *str) |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
152 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
153 |
if (str != NULL) |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
154 |
FATAL("%s != NULL", dump_str(str)); |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
155 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
156 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
157 |
void assert_success (err_t err) |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
158 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
159 |
if (err != SUCCESS) |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
160 |
FATAL("error: %s", error_name(err)); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
161 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
162 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
163 |
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
|
164 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
165 |
if (err != target) |
42 | 166 |
FATAL("error: <%s> != <%s>", error_name(err), error_name(target)); |
167 |
} |
|
168 |
||
169 |
void assert_error_info (struct error_info *is, struct error_info *should_be) |
|
170 |
{ |
|
171 |
if (ERROR_CODE(is) != ERROR_CODE(should_be) || ERROR_EXTRA(is) != ERROR_EXTRA(should_be)) |
|
172 |
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
|
173 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
174 |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
175 |
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
|
176 |
{ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
177 |
char buf[strlen(str)]; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
178 |
|
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
179 |
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
|
180 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
181 |
// read it |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
182 |
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
|
183 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
184 |
// cmp |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
185 |
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
|
186 |
} |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
187 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
188 |
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
|
189 |
{ |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
190 |
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
|
191 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
192 |
// write it |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
193 |
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
|
194 |
} |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
195 |
|
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
196 |
void assert_sock_eof (struct sock_stream *sock) |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
197 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
198 |
char buf; |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
199 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
200 |
log_debug("eof: %p", sock); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
201 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
202 |
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
|
203 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
204 |
|
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
205 |
/** |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
206 |
* 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
|
207 |
*/ |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
208 |
#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
|
209 |
|
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
210 |
void assert_sock_data (struct sock_test *sock, const char *fmt, ...) |
43 | 211 |
{ |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
212 |
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
|
213 |
va_list vargs; |
43 | 214 |
size_t len; |
215 |
||
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
216 |
va_start(vargs, fmt); |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
217 |
|
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
218 |
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
|
219 |
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
|
220 |
|
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
221 |
va_end(vargs); |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
222 |
|
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
223 |
// get the data out |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
224 |
char *out; |
43 | 225 |
|
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
226 |
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
|
227 |
|
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
228 |
log_debug("get_send_data: %s", dump_strn(out, len)); |
43 | 229 |
|
230 |
// should be the same |
|
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
231 |
assert_strncmp(out, buf, len); |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
232 |
assert_strlen(buf, len); |
43 | 233 |
|
234 |
// cleanup |
|
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
235 |
free(out); |
43 | 236 |
} |
237 |
||
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
238 |
/** |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
239 |
* 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
|
240 |
* |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
241 |
* 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
|
242 |
*/ |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
243 |
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
|
244 |
{ |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
245 |
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
|
246 |
va_list vargs; |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
247 |
size_t len; |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
248 |
|
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
249 |
va_start(vargs, fmt); |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
250 |
|
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
251 |
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
|
252 |
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
|
253 |
|
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
254 |
va_end(vargs); |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
255 |
|
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
256 |
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
|
257 |
} |
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
258 |
|
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
259 |
/** |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
260 |
* 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
|
261 |
*/ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
262 |
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
|
263 |
{ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
264 |
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
|
265 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
266 |
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
|
267 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
268 |
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
|
269 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
270 |
|
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
271 |
void test_dump_str (void) |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
272 |
{ |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
273 |
log_info("dumping example strings on stdout:"); |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
274 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
275 |
log_debug("normal: %s", dump_str("Hello World")); |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
276 |
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
|
277 |
log_debug("length: %s", dump_strn("<-->**", 4)); |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
278 |
log_debug("overflow: %s", dump_str( "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")); |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
279 |
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
|
280 |
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
|
281 |
} |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
282 |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
283 |
void test_sock_test (void) |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
284 |
{ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
285 |
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
|
286 |
struct io_vec _read_data[] = { |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
287 |
{ "foo", 3 }, |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
288 |
{ "barx", 4 } |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
289 |
}; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
290 |
const char *_write_data = "test data"; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
291 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
292 |
// put the read data |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
293 |
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
|
294 |
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
|
295 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
296 |
// read it out |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
297 |
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
|
298 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
299 |
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
|
300 |
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
|
301 |
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
|
302 |
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
|
303 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
304 |
// write the data in |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
305 |
log_info("test sock_test_write"); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
306 |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
307 |
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
|
308 |
assert_sock_write(SOCK_TEST_BASE(sock), "data"); |
43 | 309 |
|
310 |
// check output |
|
44 | 311 |
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
|
312 |
|
43 | 313 |
// check output |
44 | 314 |
assert_sock_data(sock, ""); |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
315 |
|
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
316 |
// cleanup |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
317 |
sock_test_destroy(sock); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
318 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
319 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
320 |
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
|
321 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
322 |
char *line_buf; |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
323 |
|
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
324 |
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
|
325 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
326 |
assert_success(line_proto_recv(lp, &line_buf)); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
327 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
328 |
if (line_str) { |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
329 |
assert_strcmp(line_buf, line_str); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
330 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
331 |
} else { |
42 | 332 |
assert_strnull(line_buf); |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
333 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
334 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
335 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
336 |
|
42 | 337 |
/** |
338 |
* Context info for test_line_proto callbacks |
|
339 |
*/ |
|
340 |
struct _lp_test_ctx { |
|
341 |
/** Expected line */ |
|
342 |
const char *line; |
|
343 |
||
344 |
/** Expected error */ |
|
345 |
struct error_info err; |
|
346 |
}; |
|
347 |
||
348 |
static void _lp_on_line (char *line, void *arg) |
|
349 |
{ |
|
350 |
struct _lp_test_ctx *ctx = arg; |
|
351 |
||
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
352 |
log_debug("%s", dump_str(line)); |
42 | 353 |
|
354 |
assert_strcmp(line, ctx->line); |
|
355 |
||
356 |
ctx->line = NULL; |
|
357 |
} |
|
358 |
||
359 |
static void _lp_on_error (struct error_info *err, void *arg) |
|
360 |
{ |
|
361 |
struct _lp_test_ctx *ctx = arg; |
|
362 |
||
363 |
assert_error_info(err, &ctx->err); |
|
364 |
} |
|
365 |
||
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
366 |
static struct line_proto_callbacks _lp_callbacks = { |
42 | 367 |
.on_line = &_lp_on_line, |
368 |
.on_error = &_lp_on_error, |
|
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
369 |
}; |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
370 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
371 |
void test_line_proto (void) |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
372 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
373 |
struct sock_test *sock = sock_test_create(); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
374 |
struct io_vec _read_data[] = { |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
375 |
{ "hello\r\n", 7 }, |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
376 |
{ "world\n", 6 }, |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
377 |
{ "this ", 5 }, |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
378 |
{ "is a line\r", 10 }, |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
379 |
{ "\nfragment", 9 }, |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
380 |
}, _trailing_data = { "\r\n", 2 }; |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
381 |
struct line_proto *lp; |
42 | 382 |
struct _lp_test_ctx ctx; |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
383 |
struct error_info err; |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
384 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
385 |
// put the read data |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
386 |
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
|
387 |
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
|
388 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
389 |
// create the lp |
42 | 390 |
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
|
391 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
392 |
log_info("test line_proto_recv"); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
393 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
394 |
// then read some lines from it |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
395 |
assert_read_line(lp, "hello"); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
396 |
assert_read_line(lp, "world"); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
397 |
assert_read_line(lp, "this is a line"); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
398 |
assert_read_line(lp, NULL); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
399 |
|
42 | 400 |
// then add a final bit to trigger on_line |
401 |
log_info("test on_line"); |
|
402 |
||
403 |
ctx.line = "fragment"; |
|
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
404 |
sock_test_add_recv_vec(sock, _trailing_data); |
42 | 405 |
assert_strnull(ctx.line); |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
406 |
|
43 | 407 |
// test writing |
408 |
log_info("test line_proto_send"); |
|
409 |
assert_success(-line_proto_send(lp, "foobar\r\n")); |
|
410 |
assert_success(-line_proto_send(lp, "quux\r\n")); |
|
44 | 411 |
assert_sock_data(sock, "foobar\r\nquux\r\n"); |
43 | 412 |
|
413 |
// XXX: test partial writes |
|
414 |
||
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
415 |
// cleanup |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
416 |
line_proto_release(lp); |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
417 |
} |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
418 |
|
76 | 419 |
struct test_conn_ctx { |
420 |
/** Callback flags */ |
|
49
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
421 |
bool on_registered, on_TEST, on_error, on_quit; |
43 | 422 |
}; |
423 |
||
424 |
static void _conn_on_registered (struct irc_conn *conn, void *arg) |
|
425 |
{ |
|
76 | 426 |
struct test_conn_ctx *ctx = arg; |
43 | 427 |
|
428 |
(void) conn; |
|
429 |
||
44 | 430 |
if (ctx) ctx->on_registered = true; |
43 | 431 |
|
432 |
log_debug("registered"); |
|
433 |
} |
|
434 |
||
49
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
435 |
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
|
436 |
{ |
76 | 437 |
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
|
438 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
439 |
(void) conn; |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
440 |
(void) err; |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
441 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
442 |
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
|
443 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
444 |
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
|
445 |
} |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
446 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
447 |
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
|
448 |
{ |
76 | 449 |
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
|
450 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
451 |
(void) conn; |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
452 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
453 |
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
|
454 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
455 |
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
|
456 |
} |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
457 |
|
43 | 458 |
static void _conn_on_TEST (const struct irc_line *line, void *arg) |
459 |
{ |
|
76 | 460 |
struct test_conn_ctx *ctx = arg; |
43 | 461 |
|
75
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
462 |
assert_null(line->source); |
43 | 463 |
assert_strcmp(line->command, "TEST"); |
464 |
assert_strcmp(line->args[0], "arg0"); |
|
465 |
assert_strnull(line->args[1]); |
|
466 |
||
44 | 467 |
if (ctx) ctx->on_TEST = true; |
43 | 468 |
|
469 |
log_debug("on_TEST"); |
|
470 |
} |
|
471 |
||
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
472 |
static struct irc_conn_callbacks _conn_callbacks = { |
43 | 473 |
.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
|
474 |
.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
|
475 |
.on_quit = &_conn_on_quit, |
43 | 476 |
}; |
477 |
||
478 |
static struct irc_cmd_handler _conn_handlers[] = { |
|
479 |
{ "TEST", &_conn_on_TEST }, |
|
480 |
{ NULL, NULL } |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
481 |
}; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
482 |
|
76 | 483 |
/** |
484 |
* Create and return a new irc_conn with the given ctx (will be initialized to zero). |
|
485 |
*/ |
|
486 |
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
|
487 |
{ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
488 |
struct irc_conn *conn; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
489 |
struct error_info err; |
43 | 490 |
struct irc_conn_register_info register_info = { |
491 |
"nick", "user", "realname" |
|
492 |
}; |
|
44 | 493 |
|
76 | 494 |
// init the ctx |
495 |
memset(ctx, 0, sizeof(*ctx)); |
|
496 |
||
44 | 497 |
// create the irc_conn |
498 |
assert_success(irc_conn_create(&conn, SOCK_TEST_BASE(sock), &_conn_callbacks, ctx, &err)); |
|
499 |
||
500 |
// test register |
|
501 |
if (noisy) log_info("test irc_conn_register"); |
|
502 |
assert_success(irc_conn_register(conn, ®ister_info)); |
|
503 |
assert_sock_data(sock, "NICK nick\r\nUSER user 0 * realname\r\n"); |
|
504 |
||
505 |
// test on_register callback |
|
506 |
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
|
507 |
test_sock_push(sock, "001 mynick :Blaa blaa blaa\r\n"); |
44 | 508 |
if (ctx) assert(ctx->on_registered); |
509 |
assert_strcmp(conn->nickname, "mynick"); |
|
510 |
||
511 |
// ok |
|
512 |
return conn; |
|
513 |
} |
|
514 |
||
515 |
void test_irc_conn (void) |
|
516 |
{ |
|
76 | 517 |
struct test_conn_ctx ctx; |
518 |
struct sock_test *sock = setup_sock_test(); |
|
519 |
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
|
520 |
|
44 | 521 |
// add our test handlers |
522 |
assert_success(irc_conn_add_cmd_handlers(conn, _conn_handlers, &ctx)); |
|
43 | 523 |
|
524 |
// test on_TEST handler |
|
75
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
525 |
// XXX: come up with a better prefix |
43 | 526 |
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
|
527 |
test_sock_push(sock, ":foobar-prefix TEST arg0\r\n"); |
43 | 528 |
assert(ctx.on_TEST); |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
529 |
|
44 | 530 |
// test PING/PONG |
531 |
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
|
532 |
test_sock_push(sock, "PING foo\r\n"); |
44 | 533 |
assert_sock_data(sock, "PONG foo\r\n"); |
534 |
||
49
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
535 |
// quit nicely |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
536 |
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
|
537 |
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
|
538 |
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
|
539 |
assert(conn->quitting); |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
540 |
|
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
541 |
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
|
542 |
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
|
543 |
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
|
544 |
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
|
545 |
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
|
546 |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
547 |
// destroy it |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
548 |
irc_conn_destroy(conn); |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
549 |
} |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
550 |
|
76 | 551 |
void test_irc_conn_self_nick (void) |
552 |
{ |
|
553 |
struct test_conn_ctx ctx; |
|
554 |
struct sock_test *sock = setup_sock_test(); |
|
555 |
struct irc_conn *conn = setup_irc_conn(sock, false, &ctx); |
|
556 |
||
557 |
log_info("test irc_conn_on_NICK"); |
|
558 |
test_sock_push(sock, ":mynick!user@somehost NICK mynick2\r\n"); |
|
559 |
assert_strcmp(conn->nickname, "mynick2"); |
|
560 |
||
561 |
// cleanup |
|
562 |
irc_conn_destroy(conn); |
|
563 |
} |
|
564 |
||
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
565 |
struct test_chan_ctx { |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
566 |
/** The channel name */ |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
567 |
const char *channel; |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
568 |
|
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
569 |
/** The channel we're supposed to be testing */ |
44 | 570 |
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
|
571 |
|
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
572 |
/** 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
|
573 |
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
|
574 |
|
44 | 575 |
}; |
576 |
||
577 |
void _on_chan_self_join (struct irc_chan *chan, void *arg) |
|
578 |
{ |
|
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
579 |
struct test_chan_ctx *ctx = arg; |
44 | 580 |
|
581 |
assert(chan == ctx->chan); |
|
582 |
||
583 |
ctx->on_chan_self_join = true; |
|
584 |
||
585 |
log_debug("on_self_join"); |
|
586 |
} |
|
587 |
||
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
588 |
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
|
589 |
{ |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
590 |
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
|
591 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
592 |
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
|
593 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
594 |
// 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
|
595 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
596 |
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
|
597 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
598 |
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
|
599 |
} |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
600 |
|
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
|
601 |
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
|
602 |
{ |
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
|
603 |
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
|
604 |
|
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
|
605 |
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
|
606 |
|
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
|
607 |
// 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
|
608 |
// 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
|
609 |
|
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
|
610 |
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
|
611 |
|
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
|
612 |
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
|
613 |
} |
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
|
614 |
|
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
|
615 |
|
44 | 616 |
struct irc_chan_callbacks _chan_callbacks = { |
617 |
.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
|
618 |
.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
|
619 |
.on_part = &_on_chan_part, |
44 | 620 |
}; |
621 |
||
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
622 |
/** |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
623 |
* 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
|
624 |
*/ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
625 |
struct irc_net* setup_irc_net_unregistered (struct sock_test *sock) |
44 | 626 |
{ |
627 |
struct irc_net *net; |
|
628 |
struct irc_net_info net_info = { |
|
629 |
.register_info = { |
|
630 |
"nick", "user", "realname" |
|
631 |
}, |
|
632 |
}; |
|
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
633 |
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
|
634 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
635 |
// 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
|
636 |
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
|
637 |
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
|
638 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
639 |
// 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
|
640 |
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
|
641 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
642 |
// ok |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
643 |
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
|
644 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
645 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
646 |
/** |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
647 |
* 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
|
648 |
*/ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
649 |
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
|
650 |
{ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
651 |
// 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
|
652 |
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
|
653 |
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
|
654 |
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
|
655 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
656 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
657 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
658 |
/** |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
659 |
* 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
|
660 |
*/ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
661 |
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
|
662 |
{ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
663 |
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
|
664 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
665 |
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
|
666 |
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
|
667 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
668 |
// ok |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
669 |
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
|
670 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
671 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
672 |
/** |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
673 |
* 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
|
674 |
*/ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
675 |
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
|
676 |
{ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
677 |
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
|
678 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
679 |
// 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
|
680 |
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
|
681 |
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
|
682 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
683 |
// 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
|
684 |
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
|
685 |
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
|
686 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
687 |
// 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
|
688 |
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
|
689 |
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
|
690 |
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
|
691 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
692 |
// cleanup |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
693 |
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
|
694 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
695 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
696 |
/** |
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
|
697 |
* 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
|
698 |
*/ |
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 |
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
|
700 |
{ |
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
|
701 |
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
|
702 |
|
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
|
703 |
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
|
704 |
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
|
705 |
|
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
|
706 |
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
|
707 |
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
|
708 |
|
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
|
709 |
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
|
710 |
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
|
711 |
|
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
|
712 |
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
|
713 |
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
|
714 |
|
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
|
715 |
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
|
716 |
} |
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
|
717 |
|
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
|
718 |
/** |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
719 |
* 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
|
720 |
* |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
721 |
* 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
|
722 |
*/ |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
723 |
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
|
724 |
{ |
44 | 725 |
struct irc_chan *chan; |
726 |
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
|
727 |
.channel = channel, |
44 | 728 |
}; |
729 |
struct error_info err; |
|
730 |
||
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
731 |
// 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
|
732 |
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
|
733 |
ctx->channel = channel; |
44 | 734 |
|
735 |
// 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
|
736 |
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
|
737 |
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
|
738 |
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
|
739 |
ctx->chan = chan; |
44 | 740 |
|
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
741 |
// ok |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
742 |
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
|
743 |
} |
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 |
/** |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
746 |
* 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
|
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 |
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
|
749 |
{ |
44 | 750 |
// 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
|
751 |
assert(ctx->chan->joining); |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
752 |
assert_sock_data(sock, "JOIN %s\r\n", ctx->channel); |
44 | 753 |
|
754 |
// JOIN reply |
|
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
755 |
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
|
756 |
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
|
757 |
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
|
758 |
} |
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
|
759 |
|
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
760 |
/** |
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
|
761 |
* 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
|
762 |
*/ |
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
|
763 |
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
|
764 |
{ |
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
|
765 |
// RPL_NAMREPLY |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
766 |
test_sock_push(sock, "353 mynick = %s :mynick userA +userB @userC\r\n", ctx->channel); |
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
767 |
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
|
768 |
|
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
|
769 |
// 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
|
770 |
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
|
771 |
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
|
772 |
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
|
773 |
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
|
774 |
} |
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
|
775 |
|
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
|
776 |
/** |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
777 |
* 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
|
778 |
*/ |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
779 |
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
|
780 |
{ |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
781 |
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
|
782 |
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
|
783 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
784 |
// ok |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
785 |
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
|
786 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
787 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
788 |
/** |
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
|
789 |
* 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
|
790 |
*/ |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
791 |
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
|
792 |
{ |
77
5478ade62546
use vsnprintf in assert_sock_data/test_sock_push
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
793 |
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
|
794 |
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
|
795 |
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
|
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 |
// 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
|
798 |
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
|
799 |
} |
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
|
800 |
|
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
|
801 |
|
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
|
802 |
/** |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
803 |
* 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
|
804 |
* 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
|
805 |
*/ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
806 |
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
|
807 |
{ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
808 |
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
|
809 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
810 |
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
|
811 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
812 |
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
|
813 |
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
|
814 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
815 |
// 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
|
816 |
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
|
817 |
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
|
818 |
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
|
819 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
820 |
// 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
|
821 |
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
|
822 |
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
|
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 |
// 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
|
825 |
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
|
826 |
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
|
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 |
// cleanup |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
829 |
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
|
830 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
831 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
832 |
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
|
833 |
{ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
834 |
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
|
835 |
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
|
836 |
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
|
837 |
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
|
838 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
839 |
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
|
840 |
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
|
841 |
|
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
842 |
// 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
|
843 |
irc_net_destroy(net); |
44 | 844 |
} |
845 |
||
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
846 |
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
|
847 |
{ |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
848 |
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
|
849 |
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
|
850 |
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
|
851 |
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
|
852 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
853 |
// 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
|
854 |
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
|
855 |
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
|
856 |
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
|
857 |
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
|
858 |
|
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
|
859 |
// 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
|
860 |
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
|
861 |
} |
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
|
862 |
|
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
|
863 |
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
|
864 |
{ |
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
|
865 |
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
|
866 |
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
|
867 |
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
|
868 |
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
|
869 |
|
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 |
// 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
|
871 |
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
|
872 |
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
|
873 |
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
|
874 |
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
|
875 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
876 |
// cleanup |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
877 |
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
|
878 |
} |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
879 |
|
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
880 |
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
|
881 |
{ |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
882 |
struct test_chan_ctx ctx; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
883 |
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
|
884 |
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
|
885 |
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
|
886 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
887 |
// rename one of the users |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
888 |
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
|
889 |
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
|
890 |
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
|
891 |
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
|
892 |
|
d90edc052352
update TODO and fix some valgrind errors in test
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
893 |
// cleanup |
d90edc052352
update TODO and fix some valgrind errors in test
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
894 |
irc_net_destroy(net); |
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
895 |
} |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
896 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
897 |
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
|
898 |
{ |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
899 |
struct test_chan_ctx ctx; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
900 |
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
|
901 |
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
|
902 |
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
|
903 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
904 |
// rename one of the users |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
905 |
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
|
906 |
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
|
907 |
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
|
908 |
|
d90edc052352
update TODO and fix some valgrind errors in test
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
909 |
// cleanup |
d90edc052352
update TODO and fix some valgrind errors in test
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
910 |
irc_net_destroy(net); |
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
911 |
} |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
912 |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
913 |
/** |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
914 |
* Test definition |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
915 |
*/ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
916 |
static struct test { |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
917 |
/** Test name */ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
918 |
const char *name; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
919 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
920 |
/** Test func */ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
921 |
void (*func) (void); |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
922 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
923 |
} _tests[] = { |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
924 |
{ "dump_str", &test_dump_str }, |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
925 |
{ "sock_test", &test_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
|
926 |
{ "line_proto", &test_line_proto }, |
75
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
927 |
// XXX: irc_line_parse_invalid_prefix |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
928 |
{ "irc_conn", &test_irc_conn }, |
76 | 929 |
{ "irc_conn_self_nick", &test_irc_conn_self_nick }, |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
930 |
{ "irc_net", &test_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
|
931 |
{ "irc_chan_add_offline", &test_irc_chan_add_offline }, |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
932 |
{ "irc_chan_namreply", &test_irc_chan_namreply }, |
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
933 |
{ "irc_chan_user_join", &test_irc_chan_user_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
|
934 |
{ "irc_chan_user_part", &test_irc_chan_user_part }, |
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
935 |
{ "irc_chan_user_nick", &test_irc_chan_user_nick }, |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
77
diff
changeset
|
936 |
{ "irc_chan_user_quit", &test_irc_chan_user_quit }, |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
937 |
{ NULL, NULL } |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
938 |
}; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
939 |
|
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
940 |
/** |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
941 |
* 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
|
942 |
*/ |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
943 |
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
|
944 |
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
|
945 |
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
|
946 |
OPT_QUIET = 'q', |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
947 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
948 |
/** 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
|
949 |
_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
|
950 |
}; |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
951 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
952 |
/** |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
953 |
* 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
|
954 |
*/ |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
955 |
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
|
956 |
{"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
|
957 |
{"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
|
958 |
{"quiet", 0, NULL, OPT_QUIET }, |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
959 |
{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
|
960 |
}; |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
961 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
962 |
/** |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
963 |
* 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
|
964 |
*/ |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
965 |
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
|
966 |
{ |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
967 |
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
|
968 |
printf("\n"); |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
969 |
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
|
970 |
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
|
971 |
printf(" --quiet / -q supress INFO 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
|
972 |
} |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
973 |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
974 |
int main (int argc, char **argv) |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
975 |
{ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
976 |
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
|
977 |
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
|
978 |
|
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
979 |
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
|
980 |
const char *filter = NULL; |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
981 |
|
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
982 |
// parse options |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
983 |
while ((opt = getopt_long(argc, argv, "hdq", options, &option_index)) != -1) { |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
984 |
switch (opt) { |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
985 |
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
|
986 |
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
|
987 |
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
|
988 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
989 |
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
|
990 |
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
|
991 |
break; |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
992 |
|
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
993 |
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
|
994 |
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
|
995 |
break; |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
996 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
997 |
case '?': |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
998 |
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
|
999 |
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
|
1000 |
} |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1001 |
} |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1002 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1003 |
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
|
1004 |
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
|
1005 |
// filter |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1006 |
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
|
1007 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1008 |
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
|
1009 |
} else { |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1010 |
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
|
1011 |
} |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
1012 |
} |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1013 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1014 |
// run tests |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1015 |
for (test = _tests; test->name; test++) { |
52
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
1016 |
if (filter && strcmp(test->name, filter)) |
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
1017 |
continue; |
97604efda1ce
add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents:
51
diff
changeset
|
1018 |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1019 |
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
|
1020 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1021 |
test_count++; |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1022 |
test->func(); |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1023 |
} |
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
|
1024 |
|
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1025 |
// 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
|
1026 |
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
|
1027 |
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
|
1028 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
1029 |
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
|
1030 |
} |