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