author | Tero Marttila <terom@fixme.fi> |
Fri, 13 Mar 2009 00:01:12 +0200 | |
changeset 49 | 96e0f703a58c |
parent 47 | 7d4094eb3117 |
child 50 | 46c3983638d3 |
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> |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
13 |
#include <assert.h> |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
14 |
|
42 | 15 |
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
|
16 |
{ |
42 | 17 |
if (strcmp(is, should_be)) |
18 |
FATAL("'%s' != '%s'", is, should_be); |
|
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
19 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
20 |
|
42 | 21 |
void assert_strncmp (const char *is, const char *should_be, size_t n) |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
22 |
{ |
42 | 23 |
if (strncmp(is, should_be, n)) |
44 | 24 |
FATAL("'%s':%u != '%s'", is, (unsigned) n, should_be); |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
25 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
26 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
27 |
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
|
28 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
29 |
if (strlen(str) != n) |
44 | 30 |
FATAL("strlen('%s') != %u", str, (unsigned) n); |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
31 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
32 |
|
42 | 33 |
void assert_strnull (const char *str) |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
34 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
35 |
if (str != NULL) |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
36 |
FATAL("'%s' != NULL", str); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
37 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
38 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
39 |
void assert_success (err_t err) |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
40 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
41 |
if (err != SUCCESS) |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
42 |
FATAL("error: %s", error_name(err)); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
43 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
44 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
45 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
46 |
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
|
47 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
48 |
if (err != target) |
42 | 49 |
FATAL("error: <%s> != <%s>", error_name(err), error_name(target)); |
50 |
} |
|
51 |
||
52 |
void assert_error_info (struct error_info *is, struct error_info *should_be) |
|
53 |
{ |
|
54 |
if (ERROR_CODE(is) != ERROR_CODE(should_be) || ERROR_EXTRA(is) != ERROR_EXTRA(should_be)) |
|
55 |
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
|
56 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
57 |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
58 |
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
|
59 |
{ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
60 |
char buf[strlen(str)]; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
61 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
62 |
log_debug("read: %p: '%s'", sock, str); |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
63 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
64 |
// read it |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
65 |
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
|
66 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
67 |
// cmp |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
68 |
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
|
69 |
} |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
70 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
71 |
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
|
72 |
{ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
73 |
log_debug("write: %p: '%s'", sock, str); |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
74 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
75 |
// write it |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
76 |
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
|
77 |
} |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
78 |
|
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
79 |
void assert_sock_eof (struct sock_stream *sock) |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
80 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
81 |
char buf; |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
82 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
83 |
log_debug("eof: %p", sock); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
84 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
85 |
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
|
86 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
87 |
|
44 | 88 |
void assert_sock_data (struct sock_test *sock, const char *data) |
43 | 89 |
{ |
90 |
// get the data out |
|
91 |
char *buf; |
|
92 |
size_t len; |
|
93 |
||
94 |
sock_test_get_send_data(sock, &buf, &len); |
|
95 |
||
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
|
96 |
log_debug("get_send_data: '%.*s'", (int) len, buf); |
43 | 97 |
|
98 |
// should be the same |
|
99 |
assert_strncmp(buf, data, len); |
|
100 |
assert_strlen(data, len); |
|
101 |
||
102 |
// cleanup |
|
103 |
free(buf); |
|
104 |
} |
|
105 |
||
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
106 |
void test_sock_test (void) |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
107 |
{ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
108 |
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
|
109 |
struct io_vec _read_data[] = { |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
110 |
{ "foo", 3 }, |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
111 |
{ "barx", 4 } |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
112 |
}; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
113 |
const char *_write_data = "test data"; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
114 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
115 |
// put the read data |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
116 |
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
|
117 |
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
|
118 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
119 |
// read it out |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
120 |
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
|
121 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
122 |
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
|
123 |
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
|
124 |
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
|
125 |
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
|
126 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
127 |
// write the data in |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
128 |
log_info("test sock_test_write"); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
129 |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
130 |
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
|
131 |
assert_sock_write(SOCK_TEST_BASE(sock), "data"); |
43 | 132 |
|
133 |
// check output |
|
44 | 134 |
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
|
135 |
|
43 | 136 |
// check output |
44 | 137 |
assert_sock_data(sock, ""); |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
138 |
|
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
139 |
// cleanup |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
140 |
sock_test_destroy(sock); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
141 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
142 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
143 |
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
|
144 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
145 |
char *line_buf; |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
146 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
147 |
log_debug("expect: '%s'", line_str); |
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 |
assert_success(line_proto_recv(lp, &line_buf)); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
150 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
151 |
if (line_str) { |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
152 |
assert(line_buf != NULL); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
153 |
assert_strcmp(line_buf, line_str); |
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 |
} else { |
42 | 156 |
assert_strnull(line_buf); |
41
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 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
159 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
160 |
|
42 | 161 |
/** |
162 |
* Context info for test_line_proto callbacks |
|
163 |
*/ |
|
164 |
struct _lp_test_ctx { |
|
165 |
/** Expected line */ |
|
166 |
const char *line; |
|
167 |
||
168 |
/** Expected error */ |
|
169 |
struct error_info err; |
|
170 |
}; |
|
171 |
||
172 |
static void _lp_on_line (char *line, void *arg) |
|
173 |
{ |
|
174 |
struct _lp_test_ctx *ctx = arg; |
|
175 |
||
176 |
log_debug("'%s'", line); |
|
177 |
||
178 |
assert_strcmp(line, ctx->line); |
|
179 |
||
180 |
ctx->line = NULL; |
|
181 |
} |
|
182 |
||
183 |
static void _lp_on_error (struct error_info *err, void *arg) |
|
184 |
{ |
|
185 |
struct _lp_test_ctx *ctx = arg; |
|
186 |
||
187 |
assert_error_info(err, &ctx->err); |
|
188 |
} |
|
189 |
||
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
190 |
static struct line_proto_callbacks _lp_callbacks = { |
42 | 191 |
.on_line = &_lp_on_line, |
192 |
.on_error = &_lp_on_error, |
|
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
193 |
}; |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
194 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
195 |
void test_line_proto (void) |
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 |
struct sock_test *sock = sock_test_create(); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
198 |
struct io_vec _read_data[] = { |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
199 |
{ "hello\r\n", 7 }, |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
200 |
{ "world\n", 6 }, |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
201 |
{ "this ", 5 }, |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
202 |
{ "is a line\r", 10 }, |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
203 |
{ "\nfragment", 9 }, |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
204 |
}, _trailing_data = { "\r\n", 2 }; |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
205 |
struct line_proto *lp; |
42 | 206 |
struct _lp_test_ctx ctx; |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
207 |
struct error_info err; |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
208 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
209 |
// put the read data |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
210 |
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
|
211 |
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
|
212 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
213 |
// create the lp |
42 | 214 |
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
|
215 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
216 |
log_info("test line_proto_recv"); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
217 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
218 |
// then read some lines from it |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
219 |
assert_read_line(lp, "hello"); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
220 |
assert_read_line(lp, "world"); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
221 |
assert_read_line(lp, "this is a line"); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
222 |
assert_read_line(lp, NULL); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
223 |
|
42 | 224 |
// then add a final bit to trigger on_line |
225 |
log_info("test on_line"); |
|
226 |
||
227 |
ctx.line = "fragment"; |
|
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
228 |
sock_test_add_recv_vec(sock, _trailing_data); |
42 | 229 |
assert_strnull(ctx.line); |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
230 |
|
43 | 231 |
// test writing |
232 |
log_info("test line_proto_send"); |
|
233 |
assert_success(-line_proto_send(lp, "foobar\r\n")); |
|
234 |
assert_success(-line_proto_send(lp, "quux\r\n")); |
|
44 | 235 |
assert_sock_data(sock, "foobar\r\nquux\r\n"); |
43 | 236 |
|
237 |
// XXX: test partial writes |
|
238 |
||
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
239 |
// cleanup |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
240 |
line_proto_release(lp); |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
241 |
} |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
242 |
|
43 | 243 |
struct _test_irc_conn_ctx { |
49
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
244 |
bool on_registered, on_TEST, on_error, on_quit; |
43 | 245 |
}; |
246 |
||
247 |
static void _conn_on_registered (struct irc_conn *conn, void *arg) |
|
248 |
{ |
|
249 |
struct _test_irc_conn_ctx *ctx = arg; |
|
250 |
||
251 |
(void) conn; |
|
252 |
||
44 | 253 |
if (ctx) ctx->on_registered = true; |
43 | 254 |
|
255 |
log_debug("registered"); |
|
256 |
} |
|
257 |
||
49
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
258 |
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
|
259 |
{ |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
260 |
struct _test_irc_conn_ctx *ctx = arg; |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
261 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
262 |
(void) conn; |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
263 |
(void) err; |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
264 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
265 |
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
|
266 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
267 |
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
|
268 |
} |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
269 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
270 |
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
|
271 |
{ |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
272 |
struct _test_irc_conn_ctx *ctx = arg; |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
273 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
274 |
(void) conn; |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
275 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
276 |
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
|
277 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
278 |
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
|
279 |
} |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
280 |
|
43 | 281 |
static void _conn_on_TEST (const struct irc_line *line, void *arg) |
282 |
{ |
|
283 |
struct _test_irc_conn_ctx *ctx = arg; |
|
284 |
||
285 |
assert_strcmp(line->prefix, "foobar-prefix"); |
|
286 |
assert_strcmp(line->command, "TEST"); |
|
287 |
assert_strcmp(line->args[0], "arg0"); |
|
288 |
assert_strnull(line->args[1]); |
|
289 |
||
44 | 290 |
if (ctx) ctx->on_TEST = true; |
43 | 291 |
|
292 |
log_debug("on_TEST"); |
|
293 |
} |
|
294 |
||
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
295 |
static struct irc_conn_callbacks _conn_callbacks = { |
43 | 296 |
.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
|
297 |
.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
|
298 |
.on_quit = &_conn_on_quit, |
43 | 299 |
}; |
300 |
||
301 |
static struct irc_cmd_handler _conn_handlers[] = { |
|
302 |
{ "TEST", &_conn_on_TEST }, |
|
303 |
{ NULL, NULL } |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
304 |
}; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
305 |
|
44 | 306 |
struct irc_conn* setup_irc_conn (struct sock_test *sock, bool noisy, struct _test_irc_conn_ctx *ctx) |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
307 |
{ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
308 |
struct irc_conn *conn; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
309 |
struct error_info err; |
43 | 310 |
struct irc_conn_register_info register_info = { |
311 |
"nick", "user", "realname" |
|
312 |
}; |
|
44 | 313 |
|
314 |
// create the irc_conn |
|
315 |
assert_success(irc_conn_create(&conn, SOCK_TEST_BASE(sock), &_conn_callbacks, ctx, &err)); |
|
316 |
||
317 |
// test register |
|
318 |
if (noisy) log_info("test irc_conn_register"); |
|
319 |
assert_success(irc_conn_register(conn, ®ister_info)); |
|
320 |
assert_sock_data(sock, "NICK nick\r\nUSER user 0 * realname\r\n"); |
|
321 |
||
322 |
// test on_register callback |
|
323 |
if (noisy) log_info("test irc_conn_callbacks.on_register"); |
|
324 |
sock_test_add_recv_str(sock, "001 mynick :Blaa blaa blaa\r\n"); |
|
325 |
if (ctx) assert(ctx->on_registered); |
|
326 |
assert_strcmp(conn->nickname, "mynick"); |
|
327 |
||
328 |
// ok |
|
329 |
return conn; |
|
330 |
} |
|
331 |
||
332 |
void test_irc_conn (void) |
|
333 |
{ |
|
334 |
struct sock_test *sock; |
|
335 |
struct irc_conn *conn; |
|
49
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
336 |
struct _test_irc_conn_ctx ctx = { false, false, false, false }; |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
337 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
338 |
// create the test socket |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
339 |
assert((sock = sock_test_create())); |
43 | 340 |
|
44 | 341 |
// setup the basic irc_conn |
342 |
conn = setup_irc_conn(sock, true, &ctx); |
|
43 | 343 |
|
44 | 344 |
// add our test handlers |
345 |
assert_success(irc_conn_add_cmd_handlers(conn, _conn_handlers, &ctx)); |
|
43 | 346 |
|
347 |
// test on_TEST handler |
|
348 |
log_info("test irc_conn.handlers"); |
|
349 |
sock_test_add_recv_str(sock, ":foobar-prefix TEST arg0\r\n"); |
|
350 |
assert(ctx.on_TEST); |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
351 |
|
44 | 352 |
// test PING/PONG |
353 |
log_info("test PING/PONG"); |
|
354 |
sock_test_add_recv_str(sock, "PING foo\r\n"); |
|
355 |
assert_sock_data(sock, "PONG foo\r\n"); |
|
356 |
||
49
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
357 |
// quit nicely |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
358 |
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
|
359 |
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
|
360 |
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
|
361 |
assert(conn->quitting); |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
362 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
363 |
sock_test_add_recv_str(sock, "ERROR :Closing Link: Quit\r\n"); |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
364 |
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
|
365 |
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
|
366 |
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
|
367 |
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
|
368 |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
369 |
// destroy it |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
370 |
irc_conn_destroy(conn); |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
371 |
} |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
372 |
|
44 | 373 |
struct _test_net_ctx { |
374 |
struct irc_chan *chan; |
|
375 |
||
376 |
bool on_chan_self_join; |
|
377 |
}; |
|
378 |
||
379 |
void _on_chan_self_join (struct irc_chan *chan, void *arg) |
|
380 |
{ |
|
381 |
struct _test_net_ctx *ctx = arg; |
|
382 |
||
383 |
assert(chan == ctx->chan); |
|
384 |
||
385 |
ctx->on_chan_self_join = true; |
|
386 |
||
387 |
log_debug("on_self_join"); |
|
388 |
} |
|
389 |
||
390 |
struct irc_chan_callbacks _chan_callbacks = { |
|
391 |
.on_self_join = &_on_chan_self_join, |
|
392 |
}; |
|
393 |
||
394 |
void test_irc_net (void) |
|
395 |
{ |
|
396 |
struct sock_test *sock; |
|
397 |
struct irc_net *net; |
|
398 |
struct irc_net_info net_info = { |
|
399 |
.register_info = { |
|
400 |
"nick", "user", "realname" |
|
401 |
}, |
|
402 |
}; |
|
403 |
struct irc_chan *chan; |
|
404 |
struct irc_chan_info chan_info = { |
|
405 |
.channel = "#test", |
|
406 |
}; |
|
407 |
struct error_info err; |
|
408 |
struct _test_net_ctx ctx = { NULL, false }; |
|
409 |
||
410 |
// create the test socket |
|
411 |
assert((sock = sock_test_create())); |
|
412 |
||
413 |
// create the irc_net |
|
414 |
net_info.raw_sock = SOCK_TEST_BASE(sock); |
|
415 |
assert_success(irc_net_create(&net, &net_info, &err)); |
|
416 |
||
417 |
// add a channel |
|
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
|
418 |
log_info("test offline irc_net_add_chan"); |
44 | 419 |
assert((chan = irc_net_add_chan(net, &chan_info))); |
45
71e65564afd2
remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
420 |
assert(!chan->joining && !chan->joined); |
44 | 421 |
assert_success(irc_chan_add_callbacks(chan, &_chan_callbacks, &ctx)); |
422 |
ctx.chan = chan; |
|
423 |
||
424 |
// test register output |
|
425 |
assert_sock_data(sock, "NICK nick\r\nUSER user 0 * realname\r\n"); |
|
426 |
||
427 |
// registration reply |
|
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
|
428 |
log_info("test irc_conn_on_RPL_WELCOME"); |
44 | 429 |
sock_test_add_recv_str(sock, "001 mynick :Blaa blaa blaa\r\n"); |
430 |
assert(net->conn->registered); |
|
431 |
assert_strcmp(net->conn->nickname, "mynick"); |
|
432 |
||
433 |
// JOIN request |
|
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
|
434 |
log_info("test irc_net_conn_registered -> irc_chan_join"); |
45
71e65564afd2
remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
435 |
assert(chan->joining); |
44 | 436 |
assert_sock_data(sock, "JOIN #test\r\n"); |
437 |
||
438 |
// JOIN reply |
|
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
|
439 |
log_info("test irc_chan_on_JOIN"); |
44 | 440 |
sock_test_add_recv_str(sock, ":mynick!user@host JOIN #test\r\n"); |
45
71e65564afd2
remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
441 |
assert(!chan->joining && chan->joined); |
44 | 442 |
assert(ctx.on_chan_self_join); |
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
|
443 |
|
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
444 |
// test errors by setting EOF |
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
445 |
log_info("test irc_net_error"); |
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
446 |
sock_test_set_recv_eof(sock); |
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
447 |
assert(net->conn == NULL); |
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
|
448 |
|
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
449 |
// 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
|
450 |
irc_net_destroy(net); |
44 | 451 |
} |
452 |
||
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
453 |
/** |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
454 |
* Test definition |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
455 |
*/ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
456 |
static struct test { |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
457 |
/** Test name */ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
458 |
const char *name; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
459 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
460 |
/** Test func */ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
461 |
void (*func) (void); |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
462 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
463 |
} _tests[] = { |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
464 |
{ "sock_test", &test_sock_test }, |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
465 |
{ "line_proto", &test_line_proto }, |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
466 |
{ "irc_conn", &test_irc_conn }, |
44 | 467 |
{ "irc_net", &test_irc_net }, |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
468 |
{ NULL, NULL } |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
469 |
}; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
470 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
471 |
int main (int argc, char **argv) |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
472 |
{ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
473 |
struct test *test; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
474 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
475 |
(void) argv; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
476 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
477 |
// no arguments |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
478 |
assert(argc == 1); |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
479 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
480 |
// run tests |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
481 |
for (test = _tests; test->name; test++) { |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
482 |
log_info("Running test: %s", test->name); |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
483 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
484 |
test->func(); |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
485 |
} |
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
|
486 |
|
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
487 |
log_info("done"); |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
488 |
} |