mirror of
https://github.com/irssi/irssi.git
synced 2025-02-02 15:08:01 -05:00
Merge pull request #905 from horgh/horgh/topic-regression
Add tests for topic events
This commit is contained in:
commit
6ca13dd5cd
20
.gitignore
vendored
20
.gitignore
vendored
@ -51,14 +51,30 @@ src/perl/*/Makefile.old
|
||||
src/fe-fuzz/crash-*
|
||||
src/fe-fuzz/oom-*
|
||||
|
||||
tests/irc/core/test-irc
|
||||
tests/irc/core/test-irc.trs
|
||||
/core
|
||||
/tests/fe-common/core/test-formats
|
||||
/tests/fe-common/core/test-formats.log
|
||||
/tests/fe-common/core/test-formats.trs
|
||||
/tests/fe-common/core/test-suite.log
|
||||
/tests/irc/core/core
|
||||
/tests/irc/core/test-channel-events
|
||||
/tests/irc/core/test-channel-events.log
|
||||
/tests/irc/core/test-channel-events.trs
|
||||
/tests/irc/core/test-irc
|
||||
/tests/irc/core/test-irc.log
|
||||
/tests/irc/core/test-irc.trs
|
||||
/tests/irc/core/test-suite.log
|
||||
/tests/irc/flood/test-796
|
||||
/tests/irc/flood/test-796.log
|
||||
/tests/irc/flood/test-796.trs
|
||||
/tests/irc/flood/test-suite.log
|
||||
|
||||
*.a
|
||||
*.bs
|
||||
*.la
|
||||
*.lo
|
||||
*.o
|
||||
*.swp
|
||||
*~
|
||||
|
||||
*.tar.bz2
|
||||
|
@ -40,6 +40,7 @@ pkginc_irc_coredir=$(pkgincludedir)/src/irc/core
|
||||
pkginc_irc_core_HEADERS = \
|
||||
bans.h \
|
||||
ctcp.h \
|
||||
channel-events.h \
|
||||
channel-rejoin.h \
|
||||
irc.h \
|
||||
irc-channels.h \
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "module.h"
|
||||
#include "signals.h"
|
||||
#include "misc.h"
|
||||
#include "channel-events.h"
|
||||
#include "channels-setup.h"
|
||||
#include "settings.h"
|
||||
#include "recode.h"
|
||||
|
9
src/irc/core/channel-events.h
Normal file
9
src/irc/core/channel-events.h
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef __CHANNEL_EVENTS_H
|
||||
#define __CHANNEL_EVENTS_H
|
||||
|
||||
#include "irc.h"
|
||||
|
||||
void channel_events_init(void);
|
||||
void channel_events_deinit(void);
|
||||
|
||||
#endif
|
@ -8,21 +8,24 @@ AM_CPPFLAGS = \
|
||||
-DSYSCONFDIR=\""$(sysconfdir)"\" \
|
||||
$(GLIB_CFLAGS)
|
||||
|
||||
test_programs = test-irc
|
||||
test_programs = test-channel-events test-irc
|
||||
|
||||
test_irc_CPPFLAGS = \
|
||||
CPPFLAGS = \
|
||||
-I$(top_srcdir)/src/irc/core \
|
||||
$(AM_CPPFLAGS)
|
||||
|
||||
test_irc_DEPENDENCIES = \
|
||||
DEPENDENCIES = \
|
||||
../../../src/core/libcore.a \
|
||||
../../../src/lib-config/libirssi_config.a
|
||||
|
||||
test_irc_LDADD = \
|
||||
LDADD = \
|
||||
../../../src/irc/core/libirc_core.a \
|
||||
../../../src/core/libcore.a \
|
||||
../../../src/lib-config/libirssi_config.a \
|
||||
@PROG_LIBS@
|
||||
|
||||
test_channel_events_SOURCES = \
|
||||
test-channel-events.c
|
||||
|
||||
test_irc_SOURCES = \
|
||||
test-irc.c
|
||||
|
207
tests/irc/core/test-channel-events.c
Normal file
207
tests/irc/core/test-channel-events.c
Normal file
@ -0,0 +1,207 @@
|
||||
/*
|
||||
test-irc.c : irssi
|
||||
|
||||
Copyright (C) 2018 Will Storey
|
||||
|
||||
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 <glib.h>
|
||||
|
||||
#include <channel-events.h>
|
||||
#include <common.h>
|
||||
#include <core.h>
|
||||
#include <irc.h>
|
||||
#include <irc-channels.h>
|
||||
#include <irc-servers.h>
|
||||
#include <modules.h>
|
||||
#include <recode.h>
|
||||
#include <settings.h>
|
||||
#include <signals.h>
|
||||
#include <time.h>
|
||||
#include <args.h>
|
||||
|
||||
#define MODULE_NAME "test-channel-events"
|
||||
|
||||
typedef struct {
|
||||
char const *const description;
|
||||
char const *const input;
|
||||
char const *const topic;
|
||||
char const *const topic_by;
|
||||
time_t const topic_time;
|
||||
} topic_test_case;
|
||||
|
||||
static void test_event_topic_get(topic_test_case const *const);
|
||||
static void test_event_topic(topic_test_case const *const);
|
||||
static void test_event_topic_info(topic_test_case const *const);
|
||||
static void setup(void);
|
||||
static void teardown(void);
|
||||
|
||||
static IRC_SERVER_REC *server;
|
||||
static CHANNEL_REC *channel;
|
||||
|
||||
topic_test_case const event_topic_get_test_cases[] = {
|
||||
{
|
||||
.description = "Normal 332 message with a topic with multiple words",
|
||||
.input = "testnick #test :new topic",
|
||||
.topic = "new topic",
|
||||
.topic_by = NULL,
|
||||
.topic_time = 0,
|
||||
},
|
||||
};
|
||||
|
||||
topic_test_case const event_topic_info_test_cases[] = {
|
||||
{
|
||||
.description = "Normal 333 message",
|
||||
.input = "testnick #test newnick!user@example.com 1533866229",
|
||||
.topic = "initial topic",
|
||||
.topic_by = "newnick!user@example.com",
|
||||
.topic_time = 1533866229,
|
||||
},
|
||||
};
|
||||
|
||||
topic_test_case const event_topic_test_cases[] = {
|
||||
{
|
||||
.description = "Normal TOPIC message",
|
||||
.input = "#test :new topic",
|
||||
.topic = "new topic",
|
||||
.topic_by = "newnick!user@example.com",
|
||||
.topic_time = 0, /* Dynamic */
|
||||
},
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i, res;
|
||||
|
||||
g_test_init(&argc, &argv, NULL);
|
||||
|
||||
core_preinit(*argv);
|
||||
irssi_gui = IRSSI_GUI_NONE;
|
||||
|
||||
modules_init();
|
||||
signals_init();
|
||||
settings_init();
|
||||
recode_init();
|
||||
channel_events_init();
|
||||
|
||||
settings_add_str("lookandfeel", "term_charset", "UTF-8");
|
||||
recode_update_charset();
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS(event_topic_get_test_cases); i++) {
|
||||
char *const name = g_strdup_printf("/test/event_topic_get/%d", i);
|
||||
g_test_add_data_func(name, &event_topic_get_test_cases[i],
|
||||
(GTestDataFunc)test_event_topic_get);
|
||||
g_free(name);
|
||||
}
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS(event_topic_test_cases); i++) {
|
||||
char *const name = g_strdup_printf("/test/event_topic/%d", i);
|
||||
g_test_add_data_func(name, &event_topic_test_cases[i],
|
||||
(GTestDataFunc)test_event_topic);
|
||||
g_free(name);
|
||||
}
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS(event_topic_info_test_cases); i++) {
|
||||
char *const name = g_strdup_printf("/test/event_topic_info/%d", i);
|
||||
g_test_add_data_func(name, &event_topic_info_test_cases[i],
|
||||
(GTestDataFunc)test_event_topic_info);
|
||||
g_free(name);
|
||||
}
|
||||
|
||||
#if GLIB_CHECK_VERSION(2,38,0)
|
||||
g_test_set_nonfatal_assertions();
|
||||
#endif
|
||||
res = g_test_run();
|
||||
|
||||
channel_events_deinit();
|
||||
recode_deinit();
|
||||
settings_deinit();
|
||||
signals_deinit();
|
||||
modules_deinit();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static void test_event_topic_get(topic_test_case const *const test)
|
||||
{
|
||||
setup();
|
||||
|
||||
signal_emit("event 332", 2, server, test->input);
|
||||
|
||||
g_assert_cmpstr(channel->topic, ==, test->topic);
|
||||
g_assert_cmpstr(channel->topic_by, ==, test->topic_by);
|
||||
g_assert_cmpint(channel->topic_time, ==, test->topic_time);
|
||||
|
||||
teardown();
|
||||
}
|
||||
|
||||
static void test_event_topic(topic_test_case const *const test)
|
||||
{
|
||||
time_t now;
|
||||
|
||||
setup();
|
||||
|
||||
now = time(NULL);
|
||||
signal_emit("event topic", 4, server, test->input, "newnick",
|
||||
"user@example.com");
|
||||
|
||||
g_assert_cmpstr(channel->topic, ==, test->topic);
|
||||
g_assert_cmpstr(channel->topic_by, ==, test->topic_by);
|
||||
g_assert_cmpint(channel->topic_time, >=, now);
|
||||
|
||||
teardown();
|
||||
}
|
||||
|
||||
static void test_event_topic_info(topic_test_case const *const test)
|
||||
{
|
||||
setup();
|
||||
|
||||
signal_emit("event 333", 2, server, test->input);
|
||||
|
||||
g_assert_cmpstr(channel->topic, ==, test->topic);
|
||||
g_assert_cmpstr(channel->topic_by, ==, test->topic_by);
|
||||
g_assert_cmpint(channel->topic_time, ==, test->topic_time);
|
||||
|
||||
teardown();
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
server = g_new0(IRC_SERVER_REC, 1);
|
||||
MODULE_DATA_INIT(server);
|
||||
server->type = module_get_uniq_id("SERVER", 0);
|
||||
|
||||
channel = g_new0(CHANNEL_REC, 1);
|
||||
channel->name = "#test";
|
||||
server->channels = g_slist_append(server->channels, channel);
|
||||
|
||||
g_assert_nonnull(channel_find(SERVER(server), "#test"));
|
||||
|
||||
channel->topic = g_strdup("initial topic");
|
||||
channel->topic_by = g_strdup("initialnick!user@example.com");
|
||||
channel->topic_time = 123;
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
g_slist_free(server->channels);
|
||||
MODULE_DATA_DEINIT(server);
|
||||
g_free(server);
|
||||
|
||||
g_free(channel->topic);
|
||||
g_free(channel->topic_by);
|
||||
g_free(channel);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user