diff --git a/.gitignore b/.gitignore index 9cd2a514..6aaa21e7 100644 --- a/.gitignore +++ b/.gitignore @@ -57,6 +57,7 @@ ircd/version.c.last ssld/ssld wsockd/wsockd tests/core +tests/chmode1 tests/hostmask1 tests/match1 tests/msgbuf_parse1 diff --git a/tests/Makefile.am b/tests/Makefile.am index 5c6c67d1..f1279114 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,5 @@ check_PROGRAMS = runtests \ + chmode1 \ match1 \ msgbuf_parse1 \ msgbuf_unparse1 \ @@ -24,6 +25,7 @@ check_LIBRARIES = tap/libtap.a tap_libtap_a_SOURCES = tap/basic.c tap/basic.h \ tap/float.c tap/float.h tap/macros.h +chmode1_SOURCES = chmode1.c ircd_util.c client_util.c match1_SOURCES = match1.c msgbuf_parse1_SOURCES = msgbuf_parse1.c msgbuf_unparse1_SOURCES = msgbuf_unparse1.c diff --git a/tests/TESTS b/tests/TESTS index a7627c17..5c8314a9 100644 --- a/tests/TESTS +++ b/tests/TESTS @@ -1,3 +1,4 @@ +chmode1 match1 msgbuf_parse1 msgbuf_unparse1 diff --git a/tests/chmode1.c b/tests/chmode1.c new file mode 100644 index 00000000..4c83ed5b --- /dev/null +++ b/tests/chmode1.c @@ -0,0 +1,92 @@ +/* + * Copyright 2020 Ed Kellett + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +#include +#include +#include + +#include "client_util.h" +#include "ircd_util.h" +#include "tap/basic.h" + +#define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__ + +static struct Channel *channel; +static struct Client *client; + +static hook_data_channel_approval chmode_hdata; + +static void +chmode_access_hook(void *data_) +{ + hook_data_channel_approval *data = data_; + chmode_hdata = *data; +} + +void +test_chmode_parse(void) +{ + add_hook_prio("get_channel_access", chmode_access_hook, HOOK_MONITOR); + + set_channel_mode(client, client, channel, NULL, 2, (const char *[]){"o", "foo"}); + is_string("+o foo", chmode_hdata.modestr, MSG); + + set_channel_mode(client, client, channel, NULL, 3, (const char *[]){"o", "foo", "bar"}); + is_string("+o foo", chmode_hdata.modestr, MSG); + + chmode_hdata.modestr = NULL; + set_channel_mode(client, client, channel, NULL, 3, (const char *[]){"+-=+++--+", "foo", "bar"}); + is_bool(true, chmode_hdata.modestr == NULL, MSG); + + set_channel_mode(client, client, channel, NULL, 1, (const char *[]){"b"}); + is_string("=b", chmode_hdata.modestr, MSG); + + set_channel_mode(client, client, channel, NULL, 2, (const char *[]){"bb", "foo"}); + is_string("+b=b foo", chmode_hdata.modestr, MSG); + + set_channel_mode(client, client, channel, NULL, 1, (const char *[]){"iqiqiqiq"}); + is_string("+i=q+i=q+i=q+i=q", chmode_hdata.modestr, MSG); + + remove_hook("get_channel_access", chmode_access_hook); +} + +static void +chmode_init(void) +{ + channel = make_channel(); + client = make_local_person(); +} + +int +main(int argc, char *argv[]) +{ + plan_lazy(); + + ircd_util_init(__FILE__); + client_util_init(); + + chmode_init(); + + test_chmode_parse(); + + client_util_free(); + ircd_util_free(); + + return 0; +} diff --git a/tests/chmode1.conf b/tests/chmode1.conf new file mode 100644 index 00000000..5490917f --- /dev/null +++ b/tests/chmode1.conf @@ -0,0 +1,29 @@ +serverinfo { + sid = "0AA"; + name = "me.test"; + description = "Test server"; + network_name = "Test network"; +}; + +connect "remote.test" { + host = "::1"; + fingerprint = "test"; + class = "default"; +}; + +connect "remote2.test" { + host = "::1"; + fingerprint = "test"; + class = "default"; +}; + +connect "remote3.test" { + host = "::1"; + fingerprint = "test"; + class = "default"; +}; + +privset "admin" { + privs = oper:admin; +}; +