Browse Source

Add ipv6 parse function tests

Yann Weber 5 years ago
parent
commit
5c42fde3a4
2 changed files with 54 additions and 2 deletions
  1. 2
    0
      include/monitor.h
  2. 52
    2
      tests/check_monitor.c

+ 2
- 0
include/monitor.h View File

83
  * @param int[3] socket creation arguments
83
  * @param int[3] socket creation arguments
84
  * @param pyfcgi_monitor_addr_t the addr to bind to
84
  * @param pyfcgi_monitor_addr_t the addr to bind to
85
  * @return 0 if no error else -1
85
  * @return 0 if no error else -1
86
+ * @todo add support for xxx://[IPV6]:port
86
  */
87
  */
87
 int pyfcgi_monitor_parse_sock(const char*, int[3], pyfcgi_monitor_addr_t*);
88
 int pyfcgi_monitor_parse_sock(const char*, int[3], pyfcgi_monitor_addr_t*);
88
 
89
 
92
  * @param pyfcgi_monitor_addr_t* the addr pointer
93
  * @param pyfcgi_monitor_addr_t* the addr pointer
93
  * @param int* if not NULL will be set to choosen domain
94
  * @param int* if not NULL will be set to choosen domain
94
  * @return 0 if no erro else -1
95
  * @return 0 if no erro else -1
96
+ * @todo add support for xxx://[IPV6]:port
95
  */
97
  */
96
 int pyfcgi_monitor_parse_inet_addr(const char*, int, pyfcgi_monitor_addr_t*, int*);
98
 int pyfcgi_monitor_parse_inet_addr(const char*, int, pyfcgi_monitor_addr_t*, int*);
97
 
99
 

+ 52
- 2
tests/check_monitor.c View File

14
 	"unix://foo.sock",
14
 	"unix://foo.sock",
15
 	NULL};
15
 	NULL};
16
 
16
 
17
+static const char *valids6[] = {
18
+	"tcp://localhost:8181",
19
+	"udp://localhost:8000",
20
+	//"tcp://::1:8000",
21
+	"unix:///tmp/test/test.sock",
22
+	"unix://foo.sock",
23
+	NULL};
24
+
17
 static const char *invalids[] = {
25
 static const char *invalids[] = {
18
 	"localhost:8000",
26
 	"localhost:8000",
19
 	"ttt://127.0.0.1:81",
27
 	"ttt://127.0.0.1:81",
55
 }
63
 }
56
 END_TEST
64
 END_TEST
57
 
65
 
58
-START_TEST(test_parse_sock_valid_v4)
66
+START_TEST(test_parse_sock_valid_ipv4)
59
 {
67
 {
60
 	pyfcgi_monitor_addr_t addr;
68
 	pyfcgi_monitor_addr_t addr;
61
 	int domain, type, protocol, args[3], ret, i;
69
 	int domain, type, protocol, args[3], ret, i;
97
 }
105
 }
98
 END_TEST
106
 END_TEST
99
 
107
 
108
+START_TEST(test_parse_sock_valid_ipv6)
109
+{
110
+	pyfcgi_monitor_addr_t addr;
111
+	int domain, type, protocol, args[3], ret, i;
112
+	const char **urls;
113
+	char err_msg[256];
114
+
115
+	const int expt_ret[] = {
116
+		AF_INET6, SOCK_STREAM, 0,
117
+		AF_INET6, SOCK_DGRAM, 0,
118
+		AF_UNIX, SOCK_STREAM, 0,
119
+		AF_UNIX, SOCK_STREAM, 0,};
120
+	const int *expts = expt_ret;
121
+
122
+	PyFCGI_conf.ipv6 = 1;
123
+	i=0;
124
+
125
+	for(urls=valids6; *urls != NULL; urls++)
126
+	{
127
+		ret = pyfcgi_monitor_parse_sock(*urls, args, &addr);
128
+		snprintf(err_msg, 256,
129
+			"returns %d != 0 but '%s' given",
130
+			ret, *urls);
131
+		ck_assert_msg(ret == 0, err_msg);
132
+
133
+		domain = args[0];
134
+		type = args[1];
135
+		protocol = args[2];
136
+
137
+		ck_assert_int_eq(expts[0], domain);
138
+		ck_assert_int_eq(expts[1], type);
139
+		ck_assert_int_eq(expts[2], protocol);
140
+
141
+		/**@todo check returned address */
142
+		expts+=3;
143
+		i+=1;
144
+	}
145
+}
146
+END_TEST
147
+
148
+
100
 Suite * logger_suite(void)
149
 Suite * logger_suite(void)
101
 {
150
 {
102
 	Suite *s;
151
 	Suite *s;
106
 	tc_sockurl = tcase_create("Socket URL handling functions");
155
 	tc_sockurl = tcase_create("Socket URL handling functions");
107
 	tcase_add_test(tc_sockurl, test_check_sock_valid);
156
 	tcase_add_test(tc_sockurl, test_check_sock_valid);
108
 	tcase_add_test(tc_sockurl, test_check_sock_invalid);
157
 	tcase_add_test(tc_sockurl, test_check_sock_invalid);
109
-	tcase_add_test(tc_sockurl, test_parse_sock_valid_v4);
158
+	tcase_add_test(tc_sockurl, test_parse_sock_valid_ipv4);
159
+	tcase_add_test(tc_sockurl, test_parse_sock_valid_ipv6);
110
 
160
 
111
 	suite_add_tcase(s, tc_sockurl);
161
 	suite_add_tcase(s, tc_sockurl);
112
 	return s;
162
 	return s;

Loading…
Cancel
Save