]>
jfr.im git - solanum.git/blob - tests/serv_connect1.c
2 * serv_connect_exit_unknown_client1.c: Test serv_connect followed by exit_unknown_client
3 * Copyright 2017 Simon Arlott
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
27 #include "tap/basic.h"
29 #include "ircd_util.h"
30 #include "client_util.h"
34 #include "s_newconf.h"
37 #define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__
39 static rb_fde_t
*last_F
= NULL
;
40 static CNCB
*last_connect_callback
= NULL
;
41 static void *last_connect_data
= NULL
;
43 int connect(int sockfd
, const struct sockaddr
*addr
, socklen_t addrlen
)
45 printf("# connect(%d, ...)\n", sockfd
);
50 void rb_connect_tcp(rb_fde_t
*F
, struct sockaddr
*dest
, struct sockaddr
*clocal
, CNCB
*callback
, void *data
, int timeout
)
52 printf("# rb_connect_tcp(%p, ...)\n", F
);
55 last_connect_callback
= callback
;
56 last_connect_data
= data
;
58 void *(*func
)() = dlsym(RTLD_NEXT
, "rb_connect_tcp");
59 func(F
, dest
, clocal
, callback
, data
, timeout
);
62 static void basic_test(void)
64 struct server_conf
*server
= NULL
;
67 RB_DLINK_FOREACH(ptr
, server_conf_list
.head
)
72 /* The server doesn't exist before */
73 ok(find_server(NULL
, server
->name
) == NULL
, MSG
);
75 /* The server doesn't exist during the connection attempt */
76 is_int(1, serv_connect(server
, NULL
), MSG
);
77 ok(find_server(NULL
, server
->name
) == NULL
, MSG
);
79 if (ok(last_connect_callback
!= NULL
, MSG
)) {
80 last_connect_callback(last_F
, RB_ERR_CONNECT
, last_connect_data
);
83 /* The server doesn't exist after the connection attempt fails */
84 ok(find_server(NULL
, server
->name
) == NULL
, MSG
);
87 static void incoming_during_outgoing(void)
89 struct server_conf
*server
= NULL
;
90 struct Client
*incoming
= NULL
;
93 RB_DLINK_FOREACH(ptr
, server_conf_list
.head
)
98 printf("# Test server = %s\n", server
->name
);
100 /* The server doesn't exist before */
101 ok(find_server(NULL
, server
->name
) == NULL
, MSG
);
103 /* The server doesn't exist during the connection attempt */
104 is_int(1, serv_connect(server
, NULL
), MSG
);
105 ok(find_server(NULL
, server
->name
) == NULL
, MSG
);
107 /* The server makes its own incoming connection */
108 incoming
= make_remote_server_full(&me
, server
->name
, TEST_SERVER_ID
);
109 ok(find_server(NULL
, server
->name
) == incoming
, MSG
);
110 ok(find_id(TEST_SERVER_ID
) == incoming
, MSG
);
112 if (ok(last_connect_callback
!= NULL
, MSG
)) {
113 /* This will call exit_unknown_client on our outgoing connection */
114 last_connect_callback(last_F
, RB_ERR_CONNECT
, last_connect_data
);
117 /* The incoming server should still be here */
118 ok(find_server(NULL
, server
->name
) == incoming
, MSG
);
119 ok(find_id(TEST_SERVER_ID
) == incoming
, MSG
);
121 remove_remote_server(incoming
);
123 ok(find_server(NULL
, server
->name
) == NULL
, MSG
);
124 ok(find_id(TEST_SERVER_ID
) == NULL
, MSG
);
127 int main(int argc
, char *argv
[])
131 ircd_util_init(__FILE__
);
135 incoming_during_outgoing();