Test chmode parsing

This commit is contained in:
Ed Kellett 2020-11-06 14:16:23 +00:00
parent 047b56e70e
commit 7393690255
5 changed files with 125 additions and 0 deletions

1
.gitignore vendored
View File

@ -57,6 +57,7 @@ ircd/version.c.last
ssld/ssld
wsockd/wsockd
tests/core
tests/chmode1
tests/hostmask1
tests/match1
tests/msgbuf_parse1

View 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

View File

@ -1,3 +1,4 @@
chmode1
match1
msgbuf_parse1
msgbuf_unparse1

92
tests/chmode1.c Normal file
View File

@ -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;
}

29
tests/chmode1.conf Normal file
View File

@ -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;
};