author | Tero Marttila <terom@fixme.fi> |
Fri, 13 Mar 2009 15:09:53 +0200 | |
changeset 51 | cc61eaa841ef |
parent 50 | 46c3983638d3 |
child 52 | 97604efda1ce |
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> |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
14 |
#include <ctype.h> |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
15 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
16 |
#define DUMP_STR_BUF 1024 |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
17 |
#define DUMP_STR_COUNT 8 |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
18 |
#define DUMP_STR_TAIL 10 |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
19 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
20 |
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
|
21 |
{ |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
22 |
while (*str) |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
23 |
*buf++ = *str++; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
24 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
25 |
return buf; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
26 |
} |
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 |
* 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
|
30 |
* |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
31 |
* If len is given as >= 0, only the given number of chars will be dumped from str |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
32 |
* |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
33 |
* The buffer cycles a bit, so you 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
|
34 |
* |
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
35 |
* The resulting strings are truncated to (DUMP_STR_BUF - DUMP_STR_TAIL) bytes, not including the ending "...'\0" |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
36 |
*/ |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
37 |
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
|
38 |
{ |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
39 |
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
|
40 |
static size_t dump_idx = 0; |
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 |
// pick a buffer to use |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
43 |
const char *str_ptr = str; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
44 |
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
|
45 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
46 |
// cycle |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
47 |
if (dump_idx >= DUMP_STR_COUNT) |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
48 |
dump_idx = 0; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
49 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
50 |
// NULL? |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
51 |
if (str == NULL) { |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
52 |
buf = dump_str_append(buf, "NULL"); |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
53 |
*buf = '\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 |
return buf_ptr; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
56 |
} |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
57 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
58 |
// quote |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
59 |
*buf++ = '\''; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
60 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
61 |
// dump each char |
51
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
62 |
for (; ( |
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
63 |
// ...stop on NUL |
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
64 |
*str |
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
65 |
|
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
66 |
// ...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
|
67 |
&& (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
|
68 |
|
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
69 |
// ...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
|
70 |
&& (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
|
71 |
); str++ |
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
72 |
) { |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
73 |
if (*str == '\'') { |
51
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
74 |
// escape quotes |
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
75 |
buf = dump_str_append(buf, "\\'"); |
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
76 |
|
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
77 |
} else if (*str == '\\') { |
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
78 |
// escape escapes |
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
79 |
buf = dump_str_append(buf, "\\\\"); |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
80 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
81 |
} else if (isprint(*str)) { |
51
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
82 |
// normal char |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
83 |
*buf++ = *str; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
84 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
85 |
} else { |
51
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
86 |
// something more special |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
87 |
switch (*str) { |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
88 |
case '\r': |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
89 |
buf = dump_str_append(buf, "\\r"); break; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
90 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
91 |
case '\n': |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
92 |
buf = dump_str_append(buf, "\\n"); break; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
93 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
94 |
default: |
51
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
95 |
// format as "\xFF" |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
96 |
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
|
97 |
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 |
} |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
100 |
} |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
101 |
|
51
cc61eaa841ef
add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
102 |
// end quote |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
103 |
*buf++ = '\''; |
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 |
// overflow? |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
106 |
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
|
107 |
buf = dump_str_append(buf, "..."); |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
108 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
109 |
// terminate |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
110 |
*buf = '\0'; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
111 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
112 |
// ok |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
113 |
return buf_ptr; |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
114 |
} |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
115 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
116 |
const char *dump_str (const char *str) |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
117 |
{ |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
118 |
return dump_strn(str, -1); |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
119 |
} |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
120 |
|
42 | 121 |
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
|
122 |
{ |
42 | 123 |
if (strcmp(is, should_be)) |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
124 |
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
|
125 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
126 |
|
42 | 127 |
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
|
128 |
{ |
42 | 129 |
if (strncmp(is, should_be, n)) |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
130 |
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
|
131 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
132 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
133 |
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
|
134 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
135 |
if (strlen(str) != n) |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
136 |
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
|
137 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
138 |
|
42 | 139 |
void assert_strnull (const char *str) |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
140 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
141 |
if (str != NULL) |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
142 |
FATAL("%s != NULL", dump_str(str)); |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
143 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
144 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
145 |
void assert_success (err_t err) |
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 |
if (err != SUCCESS) |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
148 |
FATAL("error: %s", error_name(err)); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
149 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
150 |
} |
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 |
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
|
153 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
154 |
if (err != target) |
42 | 155 |
FATAL("error: <%s> != <%s>", error_name(err), error_name(target)); |
156 |
} |
|
157 |
||
158 |
void assert_error_info (struct error_info *is, struct error_info *should_be) |
|
159 |
{ |
|
160 |
if (ERROR_CODE(is) != ERROR_CODE(should_be) || ERROR_EXTRA(is) != ERROR_EXTRA(should_be)) |
|
161 |
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
|
162 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
163 |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
164 |
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
|
165 |
{ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
166 |
char buf[strlen(str)]; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
167 |
|
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
168 |
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
|
169 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
170 |
// read it |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
171 |
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
|
172 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
173 |
// cmp |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
174 |
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
|
175 |
} |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
176 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
177 |
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
|
178 |
{ |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
179 |
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
|
180 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
181 |
// write it |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
182 |
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
|
183 |
} |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
184 |
|
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
185 |
void assert_sock_eof (struct sock_stream *sock) |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
186 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
187 |
char buf; |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
188 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
189 |
log_debug("eof: %p", sock); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
190 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
191 |
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
|
192 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
193 |
|
44 | 194 |
void assert_sock_data (struct sock_test *sock, const char *data) |
43 | 195 |
{ |
196 |
// get the data out |
|
197 |
char *buf; |
|
198 |
size_t len; |
|
199 |
||
200 |
sock_test_get_send_data(sock, &buf, &len); |
|
201 |
||
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
202 |
log_debug("get_send_data: %s", dump_strn(buf, len)); |
43 | 203 |
|
204 |
// should be the same |
|
205 |
assert_strncmp(buf, data, len); |
|
206 |
assert_strlen(data, len); |
|
207 |
||
208 |
// cleanup |
|
209 |
free(buf); |
|
210 |
} |
|
211 |
||
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
212 |
void test_dump_str (void) |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
213 |
{ |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
214 |
log_info("dumping example strings on stdout:"); |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
215 |
|
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
216 |
log_debug("normal: %s", dump_str("Hello World")); |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
217 |
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
|
218 |
log_debug("length: %s", dump_strn("<-->**", 4)); |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
219 |
log_debug("overflow: %s", dump_str( "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")); |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
220 |
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
|
221 |
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
|
222 |
} |
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
223 |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
224 |
void test_sock_test (void) |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
225 |
{ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
226 |
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
|
227 |
struct io_vec _read_data[] = { |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
228 |
{ "foo", 3 }, |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
229 |
{ "barx", 4 } |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
230 |
}; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
231 |
const char *_write_data = "test data"; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
232 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
233 |
// put the read data |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
234 |
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
|
235 |
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
|
236 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
237 |
// read it out |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
238 |
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
|
239 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
240 |
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
|
241 |
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
|
242 |
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
|
243 |
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
|
244 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
245 |
// write the data in |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
246 |
log_info("test sock_test_write"); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
247 |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
248 |
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
|
249 |
assert_sock_write(SOCK_TEST_BASE(sock), "data"); |
43 | 250 |
|
251 |
// check output |
|
44 | 252 |
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
|
253 |
|
43 | 254 |
// check output |
44 | 255 |
assert_sock_data(sock, ""); |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
256 |
|
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
257 |
// cleanup |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
258 |
sock_test_destroy(sock); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
259 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
260 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
261 |
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
|
262 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
263 |
char *line_buf; |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
264 |
|
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
265 |
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
|
266 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
267 |
assert_success(line_proto_recv(lp, &line_buf)); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
268 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
269 |
if (line_str) { |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
270 |
assert(line_buf != NULL); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
271 |
assert_strcmp(line_buf, line_str); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
272 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
273 |
} else { |
42 | 274 |
assert_strnull(line_buf); |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
275 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
276 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
277 |
} |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
278 |
|
42 | 279 |
/** |
280 |
* Context info for test_line_proto callbacks |
|
281 |
*/ |
|
282 |
struct _lp_test_ctx { |
|
283 |
/** Expected line */ |
|
284 |
const char *line; |
|
285 |
||
286 |
/** Expected error */ |
|
287 |
struct error_info err; |
|
288 |
}; |
|
289 |
||
290 |
static void _lp_on_line (char *line, void *arg) |
|
291 |
{ |
|
292 |
struct _lp_test_ctx *ctx = arg; |
|
293 |
||
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
294 |
log_debug("%s", dump_str(line)); |
42 | 295 |
|
296 |
assert_strcmp(line, ctx->line); |
|
297 |
||
298 |
ctx->line = NULL; |
|
299 |
} |
|
300 |
||
301 |
static void _lp_on_error (struct error_info *err, void *arg) |
|
302 |
{ |
|
303 |
struct _lp_test_ctx *ctx = arg; |
|
304 |
||
305 |
assert_error_info(err, &ctx->err); |
|
306 |
} |
|
307 |
||
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
308 |
static struct line_proto_callbacks _lp_callbacks = { |
42 | 309 |
.on_line = &_lp_on_line, |
310 |
.on_error = &_lp_on_error, |
|
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
311 |
}; |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
312 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
313 |
void test_line_proto (void) |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
314 |
{ |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
315 |
struct sock_test *sock = sock_test_create(); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
316 |
struct io_vec _read_data[] = { |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
317 |
{ "hello\r\n", 7 }, |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
318 |
{ "world\n", 6 }, |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
319 |
{ "this ", 5 }, |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
320 |
{ "is a line\r", 10 }, |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
321 |
{ "\nfragment", 9 }, |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
322 |
}, _trailing_data = { "\r\n", 2 }; |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
323 |
struct line_proto *lp; |
42 | 324 |
struct _lp_test_ctx ctx; |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
325 |
struct error_info err; |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
326 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
327 |
// put the read data |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
328 |
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
|
329 |
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
|
330 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
331 |
// create the lp |
42 | 332 |
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
|
333 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
334 |
log_info("test line_proto_recv"); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
335 |
|
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
336 |
// then read some lines from it |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
337 |
assert_read_line(lp, "hello"); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
338 |
assert_read_line(lp, "world"); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
339 |
assert_read_line(lp, "this is a line"); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
340 |
assert_read_line(lp, NULL); |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
341 |
|
42 | 342 |
// then add a final bit to trigger on_line |
343 |
log_info("test on_line"); |
|
344 |
||
345 |
ctx.line = "fragment"; |
|
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
346 |
sock_test_add_recv_vec(sock, _trailing_data); |
42 | 347 |
assert_strnull(ctx.line); |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
348 |
|
43 | 349 |
// test writing |
350 |
log_info("test line_proto_send"); |
|
351 |
assert_success(-line_proto_send(lp, "foobar\r\n")); |
|
352 |
assert_success(-line_proto_send(lp, "quux\r\n")); |
|
44 | 353 |
assert_sock_data(sock, "foobar\r\nquux\r\n"); |
43 | 354 |
|
355 |
// XXX: test partial writes |
|
356 |
||
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
357 |
// cleanup |
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
358 |
line_proto_release(lp); |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
359 |
} |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
360 |
|
43 | 361 |
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
|
362 |
bool on_registered, on_TEST, on_error, on_quit; |
43 | 363 |
}; |
364 |
||
365 |
static void _conn_on_registered (struct irc_conn *conn, void *arg) |
|
366 |
{ |
|
367 |
struct _test_irc_conn_ctx *ctx = arg; |
|
368 |
||
369 |
(void) conn; |
|
370 |
||
44 | 371 |
if (ctx) ctx->on_registered = true; |
43 | 372 |
|
373 |
log_debug("registered"); |
|
374 |
} |
|
375 |
||
49
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
376 |
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
|
377 |
{ |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
378 |
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
|
379 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
380 |
(void) conn; |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
381 |
(void) err; |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
382 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
383 |
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
|
384 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
385 |
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
|
386 |
} |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
387 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
388 |
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
|
389 |
{ |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
390 |
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
|
391 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
392 |
(void) conn; |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
393 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
394 |
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
|
395 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
396 |
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
|
397 |
} |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
398 |
|
43 | 399 |
static void _conn_on_TEST (const struct irc_line *line, void *arg) |
400 |
{ |
|
401 |
struct _test_irc_conn_ctx *ctx = arg; |
|
402 |
||
403 |
assert_strcmp(line->prefix, "foobar-prefix"); |
|
404 |
assert_strcmp(line->command, "TEST"); |
|
405 |
assert_strcmp(line->args[0], "arg0"); |
|
406 |
assert_strnull(line->args[1]); |
|
407 |
||
44 | 408 |
if (ctx) ctx->on_TEST = true; |
43 | 409 |
|
410 |
log_debug("on_TEST"); |
|
411 |
} |
|
412 |
||
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
413 |
static struct irc_conn_callbacks _conn_callbacks = { |
43 | 414 |
.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
|
415 |
.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
|
416 |
.on_quit = &_conn_on_quit, |
43 | 417 |
}; |
418 |
||
419 |
static struct irc_cmd_handler _conn_handlers[] = { |
|
420 |
{ "TEST", &_conn_on_TEST }, |
|
421 |
{ NULL, NULL } |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
422 |
}; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
423 |
|
44 | 424 |
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
|
425 |
{ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
426 |
struct irc_conn *conn; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
427 |
struct error_info err; |
43 | 428 |
struct irc_conn_register_info register_info = { |
429 |
"nick", "user", "realname" |
|
430 |
}; |
|
44 | 431 |
|
432 |
// create the irc_conn |
|
433 |
assert_success(irc_conn_create(&conn, SOCK_TEST_BASE(sock), &_conn_callbacks, ctx, &err)); |
|
434 |
||
435 |
// test register |
|
436 |
if (noisy) log_info("test irc_conn_register"); |
|
437 |
assert_success(irc_conn_register(conn, ®ister_info)); |
|
438 |
assert_sock_data(sock, "NICK nick\r\nUSER user 0 * realname\r\n"); |
|
439 |
||
440 |
// test on_register callback |
|
441 |
if (noisy) log_info("test irc_conn_callbacks.on_register"); |
|
442 |
sock_test_add_recv_str(sock, "001 mynick :Blaa blaa blaa\r\n"); |
|
443 |
if (ctx) assert(ctx->on_registered); |
|
444 |
assert_strcmp(conn->nickname, "mynick"); |
|
445 |
||
446 |
// ok |
|
447 |
return conn; |
|
448 |
} |
|
449 |
||
450 |
void test_irc_conn (void) |
|
451 |
{ |
|
452 |
struct sock_test *sock; |
|
453 |
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
|
454 |
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
|
455 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
456 |
// create the test socket |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
457 |
assert((sock = sock_test_create())); |
43 | 458 |
|
44 | 459 |
// setup the basic irc_conn |
460 |
conn = setup_irc_conn(sock, true, &ctx); |
|
43 | 461 |
|
44 | 462 |
// add our test handlers |
463 |
assert_success(irc_conn_add_cmd_handlers(conn, _conn_handlers, &ctx)); |
|
43 | 464 |
|
465 |
// test on_TEST handler |
|
466 |
log_info("test irc_conn.handlers"); |
|
467 |
sock_test_add_recv_str(sock, ":foobar-prefix TEST arg0\r\n"); |
|
468 |
assert(ctx.on_TEST); |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
469 |
|
44 | 470 |
// test PING/PONG |
471 |
log_info("test PING/PONG"); |
|
472 |
sock_test_add_recv_str(sock, "PING foo\r\n"); |
|
473 |
assert_sock_data(sock, "PONG foo\r\n"); |
|
474 |
||
49
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
475 |
// quit nicely |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
476 |
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
|
477 |
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
|
478 |
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
|
479 |
assert(conn->quitting); |
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
480 |
|
96e0f703a58c
update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
481 |
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
|
482 |
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
|
483 |
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
|
484 |
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
|
485 |
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
|
486 |
|
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
487 |
// destroy it |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
488 |
irc_conn_destroy(conn); |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
489 |
} |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
490 |
|
44 | 491 |
struct _test_net_ctx { |
492 |
struct irc_chan *chan; |
|
493 |
||
494 |
bool on_chan_self_join; |
|
495 |
}; |
|
496 |
||
497 |
void _on_chan_self_join (struct irc_chan *chan, void *arg) |
|
498 |
{ |
|
499 |
struct _test_net_ctx *ctx = arg; |
|
500 |
||
501 |
assert(chan == ctx->chan); |
|
502 |
||
503 |
ctx->on_chan_self_join = true; |
|
504 |
||
505 |
log_debug("on_self_join"); |
|
506 |
} |
|
507 |
||
508 |
struct irc_chan_callbacks _chan_callbacks = { |
|
509 |
.on_self_join = &_on_chan_self_join, |
|
510 |
}; |
|
511 |
||
512 |
void test_irc_net (void) |
|
513 |
{ |
|
514 |
struct sock_test *sock; |
|
515 |
struct irc_net *net; |
|
516 |
struct irc_net_info net_info = { |
|
517 |
.register_info = { |
|
518 |
"nick", "user", "realname" |
|
519 |
}, |
|
520 |
}; |
|
521 |
struct irc_chan *chan; |
|
522 |
struct irc_chan_info chan_info = { |
|
523 |
.channel = "#test", |
|
524 |
}; |
|
525 |
struct error_info err; |
|
526 |
struct _test_net_ctx ctx = { NULL, false }; |
|
527 |
||
528 |
// create the test socket |
|
529 |
assert((sock = sock_test_create())); |
|
530 |
||
531 |
// create the irc_net |
|
532 |
net_info.raw_sock = SOCK_TEST_BASE(sock); |
|
533 |
assert_success(irc_net_create(&net, &net_info, &err)); |
|
534 |
||
535 |
// 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
|
536 |
log_info("test offline irc_net_add_chan"); |
44 | 537 |
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
|
538 |
assert(!chan->joining && !chan->joined); |
44 | 539 |
assert_success(irc_chan_add_callbacks(chan, &_chan_callbacks, &ctx)); |
540 |
ctx.chan = chan; |
|
541 |
||
542 |
// test register output |
|
543 |
assert_sock_data(sock, "NICK nick\r\nUSER user 0 * realname\r\n"); |
|
544 |
||
545 |
// 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
|
546 |
log_info("test irc_conn_on_RPL_WELCOME"); |
44 | 547 |
sock_test_add_recv_str(sock, "001 mynick :Blaa blaa blaa\r\n"); |
548 |
assert(net->conn->registered); |
|
549 |
assert_strcmp(net->conn->nickname, "mynick"); |
|
550 |
||
551 |
// 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
|
552 |
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
|
553 |
assert(chan->joining); |
44 | 554 |
assert_sock_data(sock, "JOIN #test\r\n"); |
555 |
||
556 |
// 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
|
557 |
log_info("test irc_chan_on_JOIN"); |
44 | 558 |
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
|
559 |
assert(!chan->joining && chan->joined); |
44 | 560 |
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
|
561 |
|
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
562 |
// 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
|
563 |
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
|
564 |
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
|
565 |
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
|
566 |
|
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
567 |
// 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
|
568 |
irc_net_destroy(net); |
44 | 569 |
} |
570 |
||
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
571 |
/** |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
572 |
* Test definition |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
573 |
*/ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
574 |
static struct test { |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
575 |
/** Test name */ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
576 |
const char *name; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
577 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
578 |
/** Test func */ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
579 |
void (*func) (void); |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
580 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
581 |
} _tests[] = { |
50
46c3983638d3
add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
582 |
{ "dump_str", &test_dump_str }, |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
583 |
{ "sock_test", &test_sock_test }, |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
584 |
{ "line_proto", &test_line_proto }, |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
585 |
{ "irc_conn", &test_irc_conn }, |
44 | 586 |
{ "irc_net", &test_irc_net }, |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
587 |
{ NULL, NULL } |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
588 |
}; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
589 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
590 |
int main (int argc, char **argv) |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
591 |
{ |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
592 |
struct test *test; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
593 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
594 |
(void) argv; |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
595 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
596 |
// no arguments |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
597 |
assert(argc == 1); |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
598 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
599 |
// run tests |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
600 |
for (test = _tests; test->name; test++) { |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
601 |
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
|
602 |
|
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
603 |
test->func(); |
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
604 |
} |
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
|
605 |
|
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
606 |
log_info("done"); |
40
51678c7eae03
add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
607 |
} |