[READ-ONLY] Mirror of https://github.com/VibeDevelopers/Comet.
0

Configure Feed

Select the types of activity you want to include in your feed.

tests: add sendto_* test framework

Simon Arlott (Aug 5, 2017, 2:09 PM +0100) d2b5f411 84a3275b

+439 -8
+6
.gitignore
··· 56 56 ircd/version.c.last 57 57 ssld/ssld 58 58 wsockd/wsockd 59 + tests/core 59 60 tests/msgbuf_parse1 60 61 tests/msgbuf_unparse1 61 62 tests/rb_linebuf_put1 62 63 tests/rb_snprintf_append1 63 64 tests/rb_snprintf_try_append1 65 + tests/send1 64 66 tests/substitution1 65 67 tests/runtests 68 + tests/*.c.ban.db 69 + tests/*.c.ban.db-journal 70 + tests/*.c.log 71 + tests/*.c.pid 66 72 testsuite/ircd.pid.* 67 73 tools/charybdis-mkpasswd 68 74 tools/charybdis-mkfingerprint
+7 -7
ircd/ircd.c
··· 823 823 ircd_ssl_ok = true; 824 824 } 825 825 826 - if (testing_conf) 827 - { 828 - fprintf(stderr, "\nConfig testing complete.\n"); 829 - fflush(stderr); 830 - return 0; /* Why? We want the launcher to exit out. */ 831 - } 832 - 833 826 me.from = &me; 834 827 me.servptr = &me; 835 828 SetMe(&me); ··· 842 835 rb_dlinkAddAlloc(&me, &global_serv_list); 843 836 844 837 construct_umodebuf(); 838 + 839 + if (testing_conf) 840 + { 841 + fprintf(stderr, "\nConfig testing complete.\n"); 842 + fflush(stderr); 843 + return 0; /* Why? We want the launcher to exit out. */ 844 + } 845 845 846 846 check_class(); 847 847 write_pidfile(pidFileName);
+11 -1
tests/Makefile.am
··· 4 4 rb_linebuf_put1 \ 5 5 rb_snprintf_append1 \ 6 6 rb_snprintf_try_append1 \ 7 + send1 \ 7 8 substitution1 8 9 AM_CFLAGS=$(WARNFLAGS) 9 10 AM_CPPFLAGS = $(DEFAULT_INCLUDES) -I../librb/include -I.. ··· 24 25 rb_linebuf_put1_SOURCES = rb_linebuf_put1.c 25 26 rb_snprintf_append1_SOURCES = rb_snprintf_append1.c 26 27 rb_snprintf_try_append1_SOURCES = rb_snprintf_try_append1.c 28 + send1_SOURCES = send1.c ircd_util.c client_util.c 27 29 substitution1_SOURCES = substitution1.c 28 30 29 - check-local: $(check_PROGRAMS) 31 + check-local: $(check_PROGRAMS) \ 32 + ../authd/authd \ 33 + ../bandb/bandb \ 34 + ../ssld/ssld \ 35 + ../wsockd/wsockd \ 36 + $(patsubst ../modules/%.c,../modules/.libs/%.so,$(wildcard ../modules/*.c)) \ 37 + $(patsubst ../modules/core/%.c,../modules/core/.libs/%.so,$(wildcard ../modules/core/*.c)) \ 38 + $(patsubst ../extensions/%.c,../extensions/.libs/%.so,$(wildcard ../extensions/*.c)) 39 + 30 40 ./runtests -l $(abs_top_srcdir)/tests/TESTS
+1
tests/TESTS
··· 3 3 rb_linebuf_put1 4 4 rb_snprintf_append1 5 5 rb_snprintf_try_append1 6 + send1 6 7 substitution1
+94
tests/client_util.c
··· 1 + /* 2 + * client_util.c: Utility functions for making test clients 3 + * Copyright 2017 Simon Arlott 4 + * 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. 9 + * 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. 14 + * 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 18 + * USA 19 + */ 20 + #include <stdio.h> 21 + #include <string.h> 22 + #include <stdlib.h> 23 + #include <unistd.h> 24 + #include "tap/basic.h" 25 + 26 + #include "stdinc.h" 27 + #include "ircd_defs.h" 28 + #include "client_util.h" 29 + 30 + #define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__ 31 + 32 + struct Client *make_local_person(void) 33 + { 34 + return make_local_person_nick(TEST_NICK); 35 + } 36 + 37 + struct Client *make_local_person_nick(const char *nick) 38 + { 39 + return make_local_person_full(nick, TEST_USERNAME, TEST_HOSTNAME, TEST_IP, TEST_REALNAME); 40 + } 41 + 42 + struct Client *make_local_person_full(const char *nick, const char *username, const char *hostname, const char *ip, const char *realname) 43 + { 44 + struct Client *client; 45 + 46 + client = make_client(NULL); 47 + rb_dlinkMoveNode(&client->localClient->tnode, &unknown_list, &lclient_list); 48 + client->servptr = &me; 49 + rb_dlinkAdd(client, &client->lnode, &client->servptr->serv->users); 50 + SetClient(client); 51 + make_user(client); 52 + 53 + rb_inet_pton_sock(ip, (struct sockaddr *)&client->localClient->ip); 54 + rb_strlcpy(client->name, nick, sizeof(client->name)); 55 + rb_strlcpy(client->username, username, sizeof(client->username)); 56 + rb_strlcpy(client->host, hostname, sizeof(client->host)); 57 + rb_inet_ntop_sock((struct sockaddr *)&client->localClient->ip, client->sockhost, sizeof(client->sockhost)); 58 + rb_strlcpy(client->info, realname, sizeof(client->info)); 59 + 60 + return client; 61 + } 62 + 63 + void remove_local_person(struct Client *client) 64 + { 65 + exit_client(NULL, client, &me, "Test client removed"); 66 + } 67 + 68 + char *get_client_sendq(const struct Client *client) 69 + { 70 + static char buf[EXT_BUFSIZE + sizeof(CRLF)]; 71 + 72 + if (rb_linebuf_len(&client->localClient->buf_sendq)) { 73 + int ret; 74 + 75 + memset(buf, 0, sizeof(buf)); 76 + ret = rb_linebuf_get(&client->localClient->buf_sendq, buf, sizeof(buf), 0, 1); 77 + 78 + if (is_bool(ret > 0, true, MSG)) { 79 + return buf; 80 + } else { 81 + return "<get_client_sendq error>"; 82 + } 83 + } 84 + 85 + return ""; 86 + } 87 + 88 + void client_util_init(void) 89 + { 90 + } 91 + 92 + void client_util_free(void) 93 + { 94 + }
+55
tests/client_util.h
··· 1 + /* 2 + * client_util.c: Utility functions for making test clients 3 + * Copyright 2017 Simon Arlott 4 + * 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. 9 + * 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. 14 + * 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 18 + * USA 19 + */ 20 + #include <stdio.h> 21 + #include <string.h> 22 + #include <stdlib.h> 23 + #include <unistd.h> 24 + 25 + #include "stdinc.h" 26 + #include "ircd_defs.h" 27 + #include "msg.h" 28 + #include "client.h" 29 + 30 + #define TEST_NICK "test" 31 + #define TEST_USERNAME "username" 32 + #define TEST_HOSTNAME "example.test" 33 + #define TEST_IP "2001:db8::1:5ee:bad:c0de" 34 + #define TEST_REALNAME "Test user" 35 + 36 + #define CRLF "\r\n" 37 + 38 + void client_util_init(void); 39 + void client_util_free(void); 40 + 41 + struct Client *make_local_person(void); 42 + struct Client *make_local_person_nick(const char *nick); 43 + struct Client *make_local_person_full(const char *nick, const char *username, const char *hostname, const char *ip, const char *realname); 44 + void remove_local_person(struct Client *client); 45 + 46 + char *get_client_sendq(const struct Client *client); 47 + 48 + #define is_client_sendq_empty(client, message, ...) do { \ 49 + is_string("", get_client_sendq(client), message, ##__VA_ARGS__); \ 50 + } while (0) 51 + 52 + #define is_client_sendq(queue, client, message, ...) do { \ 53 + is_string(queue, get_client_sendq(client), message, ##__VA_ARGS__); \ 54 + is_client_sendq_empty(client, message, ##__VA_ARGS__); \ 55 + } while (0)
+102
tests/ircd_util.c
··· 1 + /* 2 + * ircd_util.c: Utility functions for making test ircds 3 + * Copyright 2017 Simon Arlott 4 + * 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. 9 + * 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. 14 + * 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 18 + * USA 19 + */ 20 + #include <stdio.h> 21 + #include <string.h> 22 + #include <stdlib.h> 23 + #include <unistd.h> 24 + #include "tap/basic.h" 25 + 26 + #include "stdinc.h" 27 + #include "ircd_defs.h" 28 + #include "defaults.h" 29 + #include "client.h" 30 + #include "ircd_util.h" 31 + 32 + #define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__ 33 + 34 + extern int charybdis_main(int argc, const char *argv[]); 35 + 36 + static char argv0[BUFSIZE]; 37 + static char configfile[BUFSIZE]; 38 + static char logfile[BUFSIZE]; 39 + static char pidfile[BUFSIZE]; 40 + 41 + static const char *argv[] = { 42 + argv0, 43 + "-configfile", configfile, 44 + "-logfile", logfile, 45 + "-pidfile", pidfile, 46 + "-conftest", 47 + NULL, 48 + }; 49 + 50 + void ircd_util_init(const char *name) 51 + { 52 + rb_strlcpy(argv0, name, sizeof(argv0)); 53 + snprintf(configfile, sizeof(configfile), "%sonf", name); 54 + snprintf(logfile, sizeof(logfile), "%s.log", name); 55 + snprintf(pidfile, sizeof(pidfile), "%s.pid", name); 56 + unlink(logfile); 57 + unlink(pidfile); 58 + 59 + rb_lib_init(NULL, NULL, NULL, 0, 1024, DNODE_HEAP_SIZE, FD_HEAP_SIZE); 60 + rb_linebuf_init(LINEBUF_HEAP_SIZE); 61 + 62 + char buf[BUFSIZE]; 63 + ircd_paths[IRCD_PATH_IRCD_EXEC] = argv0; 64 + ircd_paths[IRCD_PATH_PREFIX] = "."; 65 + 66 + snprintf(buf, sizeof(buf), "runtime%cmodules", RB_PATH_SEPARATOR); 67 + ircd_paths[IRCD_PATH_MODULES] = rb_strdup(buf); 68 + 69 + snprintf(buf, sizeof(buf), "runtime%1$cmodules%1$cautoload", RB_PATH_SEPARATOR); 70 + ircd_paths[IRCD_PATH_AUTOLOAD_MODULES] = rb_strdup(buf); 71 + 72 + ircd_paths[IRCD_PATH_ETC] = "runtime"; 73 + ircd_paths[IRCD_PATH_LOG] = "runtime"; 74 + 75 + snprintf(buf, sizeof(buf), "runtime%1$chelp%1$cusers", RB_PATH_SEPARATOR); 76 + ircd_paths[IRCD_PATH_USERHELP] = rb_strdup(buf); 77 + 78 + snprintf(buf, sizeof(buf), "runtime%1$chelp%1$copers", RB_PATH_SEPARATOR); 79 + ircd_paths[IRCD_PATH_OPERHELP] = rb_strdup(buf); 80 + 81 + snprintf(buf, sizeof(buf), "runtime%cmotd", RB_PATH_SEPARATOR); 82 + ircd_paths[IRCD_PATH_IRCD_MOTD] = rb_strdup(buf); 83 + ircd_paths[IRCD_PATH_IRCD_OMOTD] = rb_strdup(buf); 84 + 85 + snprintf(buf, sizeof(buf), "%s.ban.db", name); 86 + ircd_paths[IRCD_PATH_BANDB] = rb_strdup(buf); 87 + snprintf(buf, sizeof(buf), "%s.ban.db-journal", name); 88 + unlink(buf); 89 + 90 + ircd_paths[IRCD_PATH_IRCD_PID] = rb_strdup(pidfile); 91 + ircd_paths[IRCD_PATH_IRCD_LOG] = rb_strdup(logfile); 92 + 93 + snprintf(buf, sizeof(buf), "runtime%cbin", RB_PATH_SEPARATOR); 94 + ircd_paths[IRCD_PATH_BIN] = rb_strdup(buf); 95 + ircd_paths[IRCD_PATH_LIBEXEC] = rb_strdup(buf); 96 + 97 + is_int(0, charybdis_main(ARRAY_SIZE(argv) - 1, argv), MSG); 98 + } 99 + 100 + void ircd_util_free(void) 101 + { 102 + }
+31
tests/ircd_util.h
··· 1 + /* 2 + * ircd_util.c: Utility functions for making test ircds 3 + * Copyright 2017 Simon Arlott 4 + * 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. 9 + * 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. 14 + * 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 18 + * USA 19 + */ 20 + #include <stdio.h> 21 + #include <string.h> 22 + #include <stdlib.h> 23 + #include <unistd.h> 24 + 25 + #include "stdinc.h" 26 + #include "ircd_defs.h" 27 + 28 + #define TEST_ME_NAME "me.test" 29 + 30 + void ircd_util_init(const char *name); 31 + void ircd_util_free(void);
+1
tests/runtime/bin/authd
··· 1 + ../../../authd/authd
+1
tests/runtime/bin/bandb
··· 1 + ../../../bandb/bandb
+1
tests/runtime/bin/ssld
··· 1 + ../../../ssld/ssld
+1
tests/runtime/bin/wsockd
··· 1 + ../../../wsockd/wsockd
+1
tests/runtime/help
··· 1 + ../../help
+1
tests/runtime/motd
··· 1 + Hello World!
+119
tests/send1.c
··· 1 + /* 2 + * send1.c: Test sendto_* under various conditions 3 + * Copyright 2017 Simon Arlott 4 + * 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. 9 + * 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. 14 + * 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 18 + * USA 19 + */ 20 + #include <stdio.h> 21 + #include <string.h> 22 + #include <stdlib.h> 23 + #include <unistd.h> 24 + #include "tap/basic.h" 25 + 26 + #include "ircd_util.h" 27 + #include "client_util.h" 28 + 29 + #include "send.h" 30 + 31 + #define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__ 32 + 33 + static void sendto_one_numeric1(void) 34 + { 35 + struct Client *user = make_local_person(); 36 + 37 + sendto_one_numeric(user, 1, "Hello %s!", "World"); 38 + is_client_sendq(":" TEST_ME_NAME " 001 " TEST_NICK " Hello World!" CRLF, user, MSG); 39 + 40 + remove_local_person(user); 41 + } 42 + 43 + static void sendto_wallops_flags1(void) 44 + { 45 + struct Client *user1 = make_local_person_nick("user1"); 46 + struct Client *user2 = make_local_person_nick("user2"); 47 + struct Client *oper1 = make_local_person_nick("oper1"); 48 + struct Client *oper2 = make_local_person_nick("oper2"); 49 + struct Client *oper3 = make_local_person_nick("oper3"); 50 + struct Client *oper4 = make_local_person_nick("oper4"); 51 + 52 + rb_dlinkAddAlloc(oper1, &local_oper_list); 53 + rb_dlinkAddAlloc(oper1, &oper_list); 54 + SetOper(oper1); 55 + 56 + rb_dlinkAddAlloc(oper2, &local_oper_list); 57 + rb_dlinkAddAlloc(oper2, &oper_list); 58 + SetOper(oper2); 59 + 60 + rb_dlinkAddAlloc(oper3, &local_oper_list); 61 + rb_dlinkAddAlloc(oper3, &oper_list); 62 + SetOper(oper3); 63 + 64 + rb_dlinkAddAlloc(oper4, &local_oper_list); 65 + rb_dlinkAddAlloc(oper4, &oper_list); 66 + SetOper(oper4); 67 + 68 + user1->umodes |= UMODE_WALLOP; 69 + oper1->umodes |= UMODE_WALLOP | UMODE_OPERWALL; 70 + oper2->umodes |= UMODE_WALLOP | UMODE_OPERWALL | UMODE_ADMIN; 71 + oper3->umodes |= UMODE_WALLOP; 72 + oper4->umodes |= UMODE_OPERWALL; 73 + 74 + sendto_wallops_flags(UMODE_WALLOP, oper1, "Test to users"); 75 + is_client_sendq(":oper1!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to users" CRLF, user1, "User is +w; " MSG); 76 + is_client_sendq_empty(user2, "User is -w; " MSG); 77 + is_client_sendq(":oper1!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to users" CRLF, oper1, "User is +w; " MSG); 78 + is_client_sendq(":oper1!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to users" CRLF, oper2, "User is +w; " MSG); 79 + is_client_sendq(":oper1!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to users" CRLF, oper3, "User is +w; " MSG); 80 + is_client_sendq_empty(oper4, "User is -w; " MSG); 81 + 82 + sendto_wallops_flags(UMODE_OPERWALL, oper2, "Test to opers"); 83 + is_client_sendq_empty(user1, "Not an oper; " MSG); 84 + is_client_sendq_empty(user2, "Not an oper; " MSG); 85 + is_client_sendq(":oper2!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to opers" CRLF, oper1, "Oper is +z; " MSG); 86 + is_client_sendq(":oper2!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to opers" CRLF, oper2, "Oper is +z; " MSG); 87 + is_client_sendq_empty(oper3, "Oper is -z; " MSG); 88 + is_client_sendq(":oper2!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to opers" CRLF, oper4, "Oper is +z; " MSG); 89 + 90 + sendto_wallops_flags(UMODE_ADMIN, &me, "Test to admins"); 91 + is_client_sendq_empty(user1, "Not an admin; " MSG); 92 + is_client_sendq_empty(user2, "Not an admin; " MSG); 93 + is_client_sendq_empty(oper1, "Not an admin; " MSG); 94 + is_client_sendq(":" TEST_ME_NAME " WALLOPS :Test to admins" CRLF, oper2, MSG); 95 + is_client_sendq_empty(oper3, "Not an admin; " MSG); 96 + is_client_sendq_empty(oper4, "Not an admin; " MSG); 97 + 98 + remove_local_person(user1); 99 + remove_local_person(user2); 100 + remove_local_person(oper1); 101 + remove_local_person(oper2); 102 + remove_local_person(oper3); 103 + remove_local_person(oper4); 104 + } 105 + 106 + int main(int argc, char *argv[]) 107 + { 108 + plan_lazy(); 109 + 110 + ircd_util_init(__FILE__); 111 + client_util_init(); 112 + 113 + sendto_one_numeric1(); 114 + sendto_wallops_flags1(); 115 + 116 + client_util_free(); 117 + ircd_util_free(); 118 + return 0; 119 + }
+7
tests/send1.conf
··· 1 + serverinfo { 2 + sid = "0AA"; 3 + name = "me.test"; 4 + description = "Test server"; 5 + network_name = "Test network"; 6 + }; 7 +