]> jfr.im git - irc/freenode/solanum.git/commitdiff
Test chmode parsing
authorEd Kellett <redacted>
Fri, 6 Nov 2020 14:16:23 +0000 (14:16 +0000)
committerEd Kellett <redacted>
Sun, 8 Nov 2020 00:26:27 +0000 (00:26 +0000)
.gitignore
tests/Makefile.am
tests/TESTS
tests/chmode1.c [new file with mode: 0644]
tests/chmode1.conf [new file with mode: 0644]

index 9cd2a5146f428ef904c16e74872c33633934e428..6aaa21e756e90de8dd9f3ec3e62bcee1eb5ec06d 100644 (file)
@@ -57,6 +57,7 @@ ircd/version.c.last
 ssld/ssld
 wsockd/wsockd
 tests/core
+tests/chmode1
 tests/hostmask1
 tests/match1
 tests/msgbuf_parse1
index 5c6c67d13dd116c9bc0a694bf85fd75fb48b16fc..f1279114b1f87e2199fe77146af20b110585a32f 100644 (file)
@@ -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
index a7627c177a76c59c737173ddbee08470461f2794..5c8314a992e2fed5da2e6a28d5075aac328cb5e6 100644 (file)
@@ -1,3 +1,4 @@
+chmode1
 match1
 msgbuf_parse1
 msgbuf_unparse1
diff --git a/tests/chmode1.c b/tests/chmode1.c
new file mode 100644 (file)
index 0000000..4c83ed5
--- /dev/null
@@ -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 <stdinc.h>
+#include <channel.h>
+#include <hook.h>
+
+#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 (file)
index 0000000..5490917
--- /dev/null
@@ -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;
+};
+