···11+/*
22+ * client_util.c: Utility functions for making test clients
33+ * Copyright 2017 Simon Arlott
44+ *
55+ * This program is free software; you can redistribute it and/or modify
66+ * it under the terms of the GNU General Public License as published by
77+ * the Free Software Foundation; either version 2 of the License, or
88+ * (at your option) any later version.
99+ *
1010+ * This program is distributed in the hope that it will be useful,
1111+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1212+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313+ * GNU General Public License for more details.
1414+ *
1515+ * You should have received a copy of the GNU General Public License
1616+ * along with this program; if not, write to the Free Software
1717+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
1818+ * USA
1919+ */
2020+#include <stdio.h>
2121+#include <string.h>
2222+#include <stdlib.h>
2323+#include <unistd.h>
2424+#include "tap/basic.h"
2525+2626+#include "stdinc.h"
2727+#include "ircd_defs.h"
2828+#include "client_util.h"
2929+3030+#define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__
3131+3232+struct Client *make_local_person(void)
3333+{
3434+ return make_local_person_nick(TEST_NICK);
3535+}
3636+3737+struct Client *make_local_person_nick(const char *nick)
3838+{
3939+ return make_local_person_full(nick, TEST_USERNAME, TEST_HOSTNAME, TEST_IP, TEST_REALNAME);
4040+}
4141+4242+struct Client *make_local_person_full(const char *nick, const char *username, const char *hostname, const char *ip, const char *realname)
4343+{
4444+ struct Client *client;
4545+4646+ client = make_client(NULL);
4747+ rb_dlinkMoveNode(&client->localClient->tnode, &unknown_list, &lclient_list);
4848+ client->servptr = &me;
4949+ rb_dlinkAdd(client, &client->lnode, &client->servptr->serv->users);
5050+ SetClient(client);
5151+ make_user(client);
5252+5353+ rb_inet_pton_sock(ip, (struct sockaddr *)&client->localClient->ip);
5454+ rb_strlcpy(client->name, nick, sizeof(client->name));
5555+ rb_strlcpy(client->username, username, sizeof(client->username));
5656+ rb_strlcpy(client->host, hostname, sizeof(client->host));
5757+ rb_inet_ntop_sock((struct sockaddr *)&client->localClient->ip, client->sockhost, sizeof(client->sockhost));
5858+ rb_strlcpy(client->info, realname, sizeof(client->info));
5959+6060+ return client;
6161+}
6262+6363+void remove_local_person(struct Client *client)
6464+{
6565+ exit_client(NULL, client, &me, "Test client removed");
6666+}
6767+6868+char *get_client_sendq(const struct Client *client)
6969+{
7070+ static char buf[EXT_BUFSIZE + sizeof(CRLF)];
7171+7272+ if (rb_linebuf_len(&client->localClient->buf_sendq)) {
7373+ int ret;
7474+7575+ memset(buf, 0, sizeof(buf));
7676+ ret = rb_linebuf_get(&client->localClient->buf_sendq, buf, sizeof(buf), 0, 1);
7777+7878+ if (is_bool(ret > 0, true, MSG)) {
7979+ return buf;
8080+ } else {
8181+ return "<get_client_sendq error>";
8282+ }
8383+ }
8484+8585+ return "";
8686+}
8787+8888+void client_util_init(void)
8989+{
9090+}
9191+9292+void client_util_free(void)
9393+{
9494+}
+55
tests/client_util.h
···11+/*
22+ * client_util.c: Utility functions for making test clients
33+ * Copyright 2017 Simon Arlott
44+ *
55+ * This program is free software; you can redistribute it and/or modify
66+ * it under the terms of the GNU General Public License as published by
77+ * the Free Software Foundation; either version 2 of the License, or
88+ * (at your option) any later version.
99+ *
1010+ * This program is distributed in the hope that it will be useful,
1111+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1212+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313+ * GNU General Public License for more details.
1414+ *
1515+ * You should have received a copy of the GNU General Public License
1616+ * along with this program; if not, write to the Free Software
1717+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
1818+ * USA
1919+ */
2020+#include <stdio.h>
2121+#include <string.h>
2222+#include <stdlib.h>
2323+#include <unistd.h>
2424+2525+#include "stdinc.h"
2626+#include "ircd_defs.h"
2727+#include "msg.h"
2828+#include "client.h"
2929+3030+#define TEST_NICK "test"
3131+#define TEST_USERNAME "username"
3232+#define TEST_HOSTNAME "example.test"
3333+#define TEST_IP "2001:db8::1:5ee:bad:c0de"
3434+#define TEST_REALNAME "Test user"
3535+3636+#define CRLF "\r\n"
3737+3838+void client_util_init(void);
3939+void client_util_free(void);
4040+4141+struct Client *make_local_person(void);
4242+struct Client *make_local_person_nick(const char *nick);
4343+struct Client *make_local_person_full(const char *nick, const char *username, const char *hostname, const char *ip, const char *realname);
4444+void remove_local_person(struct Client *client);
4545+4646+char *get_client_sendq(const struct Client *client);
4747+4848+#define is_client_sendq_empty(client, message, ...) do { \
4949+ is_string("", get_client_sendq(client), message, ##__VA_ARGS__); \
5050+ } while (0)
5151+5252+#define is_client_sendq(queue, client, message, ...) do { \
5353+ is_string(queue, get_client_sendq(client), message, ##__VA_ARGS__); \
5454+ is_client_sendq_empty(client, message, ##__VA_ARGS__); \
5555+ } while (0)
+102
tests/ircd_util.c
···11+/*
22+ * ircd_util.c: Utility functions for making test ircds
33+ * Copyright 2017 Simon Arlott
44+ *
55+ * This program is free software; you can redistribute it and/or modify
66+ * it under the terms of the GNU General Public License as published by
77+ * the Free Software Foundation; either version 2 of the License, or
88+ * (at your option) any later version.
99+ *
1010+ * This program is distributed in the hope that it will be useful,
1111+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1212+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313+ * GNU General Public License for more details.
1414+ *
1515+ * You should have received a copy of the GNU General Public License
1616+ * along with this program; if not, write to the Free Software
1717+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
1818+ * USA
1919+ */
2020+#include <stdio.h>
2121+#include <string.h>
2222+#include <stdlib.h>
2323+#include <unistd.h>
2424+#include "tap/basic.h"
2525+2626+#include "stdinc.h"
2727+#include "ircd_defs.h"
2828+#include "defaults.h"
2929+#include "client.h"
3030+#include "ircd_util.h"
3131+3232+#define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__
3333+3434+extern int charybdis_main(int argc, const char *argv[]);
3535+3636+static char argv0[BUFSIZE];
3737+static char configfile[BUFSIZE];
3838+static char logfile[BUFSIZE];
3939+static char pidfile[BUFSIZE];
4040+4141+static const char *argv[] = {
4242+ argv0,
4343+ "-configfile", configfile,
4444+ "-logfile", logfile,
4545+ "-pidfile", pidfile,
4646+ "-conftest",
4747+ NULL,
4848+};
4949+5050+void ircd_util_init(const char *name)
5151+{
5252+ rb_strlcpy(argv0, name, sizeof(argv0));
5353+ snprintf(configfile, sizeof(configfile), "%sonf", name);
5454+ snprintf(logfile, sizeof(logfile), "%s.log", name);
5555+ snprintf(pidfile, sizeof(pidfile), "%s.pid", name);
5656+ unlink(logfile);
5757+ unlink(pidfile);
5858+5959+ rb_lib_init(NULL, NULL, NULL, 0, 1024, DNODE_HEAP_SIZE, FD_HEAP_SIZE);
6060+ rb_linebuf_init(LINEBUF_HEAP_SIZE);
6161+6262+ char buf[BUFSIZE];
6363+ ircd_paths[IRCD_PATH_IRCD_EXEC] = argv0;
6464+ ircd_paths[IRCD_PATH_PREFIX] = ".";
6565+6666+ snprintf(buf, sizeof(buf), "runtime%cmodules", RB_PATH_SEPARATOR);
6767+ ircd_paths[IRCD_PATH_MODULES] = rb_strdup(buf);
6868+6969+ snprintf(buf, sizeof(buf), "runtime%1$cmodules%1$cautoload", RB_PATH_SEPARATOR);
7070+ ircd_paths[IRCD_PATH_AUTOLOAD_MODULES] = rb_strdup(buf);
7171+7272+ ircd_paths[IRCD_PATH_ETC] = "runtime";
7373+ ircd_paths[IRCD_PATH_LOG] = "runtime";
7474+7575+ snprintf(buf, sizeof(buf), "runtime%1$chelp%1$cusers", RB_PATH_SEPARATOR);
7676+ ircd_paths[IRCD_PATH_USERHELP] = rb_strdup(buf);
7777+7878+ snprintf(buf, sizeof(buf), "runtime%1$chelp%1$copers", RB_PATH_SEPARATOR);
7979+ ircd_paths[IRCD_PATH_OPERHELP] = rb_strdup(buf);
8080+8181+ snprintf(buf, sizeof(buf), "runtime%cmotd", RB_PATH_SEPARATOR);
8282+ ircd_paths[IRCD_PATH_IRCD_MOTD] = rb_strdup(buf);
8383+ ircd_paths[IRCD_PATH_IRCD_OMOTD] = rb_strdup(buf);
8484+8585+ snprintf(buf, sizeof(buf), "%s.ban.db", name);
8686+ ircd_paths[IRCD_PATH_BANDB] = rb_strdup(buf);
8787+ snprintf(buf, sizeof(buf), "%s.ban.db-journal", name);
8888+ unlink(buf);
8989+9090+ ircd_paths[IRCD_PATH_IRCD_PID] = rb_strdup(pidfile);
9191+ ircd_paths[IRCD_PATH_IRCD_LOG] = rb_strdup(logfile);
9292+9393+ snprintf(buf, sizeof(buf), "runtime%cbin", RB_PATH_SEPARATOR);
9494+ ircd_paths[IRCD_PATH_BIN] = rb_strdup(buf);
9595+ ircd_paths[IRCD_PATH_LIBEXEC] = rb_strdup(buf);
9696+9797+ is_int(0, charybdis_main(ARRAY_SIZE(argv) - 1, argv), MSG);
9898+}
9999+100100+void ircd_util_free(void)
101101+{
102102+}
+31
tests/ircd_util.h
···11+/*
22+ * ircd_util.c: Utility functions for making test ircds
33+ * Copyright 2017 Simon Arlott
44+ *
55+ * This program is free software; you can redistribute it and/or modify
66+ * it under the terms of the GNU General Public License as published by
77+ * the Free Software Foundation; either version 2 of the License, or
88+ * (at your option) any later version.
99+ *
1010+ * This program is distributed in the hope that it will be useful,
1111+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1212+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313+ * GNU General Public License for more details.
1414+ *
1515+ * You should have received a copy of the GNU General Public License
1616+ * along with this program; if not, write to the Free Software
1717+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
1818+ * USA
1919+ */
2020+#include <stdio.h>
2121+#include <string.h>
2222+#include <stdlib.h>
2323+#include <unistd.h>
2424+2525+#include "stdinc.h"
2626+#include "ircd_defs.h"
2727+2828+#define TEST_ME_NAME "me.test"
2929+3030+void ircd_util_init(const char *name);
3131+void ircd_util_free(void);