2018-01-04 08:29:57 -05:00
|
|
|
/*
|
|
|
|
test-796.c : irssi
|
|
|
|
|
|
|
|
Copyright (C) 2017 The Irssi project.
|
|
|
|
|
|
|
|
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 "common.h"
|
2018-01-04 10:18:07 -05:00
|
|
|
#include "args.h"
|
|
|
|
#include "core.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "servers-setup.h"
|
|
|
|
|
|
|
|
#include "formats.h"
|
|
|
|
#include "fe-common-core.h"
|
|
|
|
|
|
|
|
#include "irc.h"
|
|
|
|
#include "irc-servers.h"
|
|
|
|
#include "irc-channels.h"
|
|
|
|
|
|
|
|
/* irc.c */
|
|
|
|
void irc_init(void);
|
2018-01-04 15:11:00 -05:00
|
|
|
void irc_deinit(void);
|
2018-01-04 10:18:07 -05:00
|
|
|
|
|
|
|
/* irc-session.c */
|
|
|
|
void irc_session_init(void);
|
|
|
|
void irc_session_deinit(void);
|
|
|
|
|
|
|
|
/* fe-common-irc.c */
|
|
|
|
void fe_common_irc_init(void);
|
|
|
|
void fe_common_irc_deinit(void);
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
} ServerDestroyFloodData;
|
|
|
|
|
|
|
|
#define MODULE_NAME "tests"
|
|
|
|
|
|
|
|
static void cmd_echo(const char *data, void *server, WI_ITEM_REC *item)
|
|
|
|
{
|
|
|
|
g_test_message("echo: [server=%p,item=%p] %s", server, item, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_public(SERVER_REC *server, const char *msg, const char *nick, const char *address, const char *target)
|
|
|
|
{
|
|
|
|
signal_emit("send command", 3, "/eval echo $tag", server, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_disconnect(SERVER_REC *server)
|
|
|
|
{
|
|
|
|
g_test_message("server %p was disconnected", server);
|
|
|
|
}
|
|
|
|
|
2018-01-04 17:01:28 -05:00
|
|
|
static void print_destroyed(SERVER_REC *server)
|
|
|
|
{
|
|
|
|
g_test_message("server %p was destroyed", server);
|
|
|
|
}
|
|
|
|
|
2018-01-04 10:18:07 -05:00
|
|
|
static void server_destroy_flood_set_up(ServerDestroyFloodData *fixture, const void *data)
|
|
|
|
{
|
|
|
|
args_execute(0, NULL);
|
|
|
|
core_init();
|
|
|
|
irc_init();
|
|
|
|
fe_common_core_init();
|
|
|
|
fe_common_irc_init();
|
|
|
|
signal_emit("irssi init finished", 0);
|
|
|
|
command_bind("echo", NULL, (SIGNAL_FUNC) cmd_echo);
|
|
|
|
signal_add("message public", (SIGNAL_FUNC) sig_public);
|
2018-01-04 17:01:28 -05:00
|
|
|
signal_add("server destroyed", (SIGNAL_FUNC) print_destroyed);
|
2018-01-04 10:18:07 -05:00
|
|
|
signal_add_first("server disconnected", (SIGNAL_FUNC) print_disconnect);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void server_destroy_flood_tear_down(ServerDestroyFloodData *fixture, const void *data)
|
|
|
|
{
|
|
|
|
signal_remove("server disconnected", (SIGNAL_FUNC) print_disconnect);
|
2018-01-04 17:01:28 -05:00
|
|
|
signal_remove("server destroyed", (SIGNAL_FUNC) print_destroyed);
|
2018-01-04 10:18:07 -05:00
|
|
|
signal_remove("message public", (SIGNAL_FUNC) sig_public);
|
|
|
|
command_unbind("echo", (SIGNAL_FUNC) cmd_echo);
|
|
|
|
fe_common_irc_deinit();
|
|
|
|
fe_common_core_deinit();
|
|
|
|
irc_deinit();
|
|
|
|
core_deinit();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void irc_server_init_bare_minimum(IRC_SERVER_REC *server)
|
|
|
|
{
|
|
|
|
server->isupport = g_hash_table_new((GHashFunc) g_istr_hash,
|
2018-01-04 17:01:28 -05:00
|
|
|
(GCompareFunc) g_istr_equal);
|
2018-01-04 10:18:07 -05:00
|
|
|
|
2018-01-04 17:01:28 -05:00
|
|
|
/* set the standards */
|
|
|
|
g_hash_table_insert(server->isupport, g_strdup("CHANMODES"), g_strdup("beI,k,l,imnpst"));
|
|
|
|
g_hash_table_insert(server->isupport, g_strdup("PREFIX"), g_strdup("(ohv)@%+"));
|
2018-01-04 10:18:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_server_destroy_flood(ServerDestroyFloodData *fixture, const void *data)
|
|
|
|
{
|
|
|
|
SERVER_REC *server; /* = g_new0(IRC_SERVER_REC, 1); */
|
2018-01-04 17:01:28 -05:00
|
|
|
CHAT_PROTOCOL_REC *proto;
|
2018-01-04 10:18:07 -05:00
|
|
|
SERVER_CONNECT_REC *conn;
|
2018-01-04 17:01:28 -05:00
|
|
|
GLogLevelFlags loglev;
|
2018-01-04 10:18:07 -05:00
|
|
|
|
|
|
|
g_test_bug("796");
|
|
|
|
|
2018-01-04 17:01:28 -05:00
|
|
|
/* for the purpose of this exercise, we are ignoring the
|
|
|
|
errors of g_hash_table_lookup failure */
|
|
|
|
loglev = g_log_set_always_fatal(G_LOG_FATAL_MASK);
|
|
|
|
|
2018-01-04 10:18:07 -05:00
|
|
|
proto = chat_protocol_find("IRC");
|
|
|
|
conn = server_create_conn(proto->id, "localhost", 0, "", "", "user");
|
|
|
|
server = proto->server_init_connect(conn);
|
|
|
|
server->session_reconnect = TRUE;
|
|
|
|
server->tag = g_strdup("testserver");
|
|
|
|
|
|
|
|
g_test_message("created server: %p", server);
|
|
|
|
|
|
|
|
/* we skip some initialisations that would try to send data */
|
|
|
|
/* irc_servers_deinit(); */
|
|
|
|
irc_session_deinit();
|
|
|
|
irc_irc_deinit();
|
|
|
|
|
2018-01-04 10:43:58 -05:00
|
|
|
|
|
|
|
server_connect_finished(server);
|
2018-01-04 10:18:07 -05:00
|
|
|
|
|
|
|
/* make up for the skipped session init */
|
|
|
|
irc_server_init_bare_minimum(IRC_SERVER(server));
|
|
|
|
|
|
|
|
irc_irc_init();
|
|
|
|
irc_session_init();
|
|
|
|
/* irc_servers_init(); */
|
|
|
|
|
|
|
|
/* simulate failing irc_server_send_data() */
|
|
|
|
server->connection_lost = TRUE;
|
|
|
|
|
2018-01-04 10:43:58 -05:00
|
|
|
/*
|
|
|
|
chat_completion_deinit();
|
|
|
|
fe_messages_deinit();
|
|
|
|
irc_notifylist_deinit();
|
|
|
|
*/
|
|
|
|
|
2018-01-04 17:01:28 -05:00
|
|
|
server_ref(server);
|
2018-01-04 10:18:07 -05:00
|
|
|
signal_emit("event privmsg", 4, server, "#someroom :test message", "nick", "user@host");
|
2018-01-04 17:01:28 -05:00
|
|
|
server_unref(server);
|
|
|
|
|
|
|
|
g_log_set_always_fatal(loglev);
|
2018-01-04 10:18:07 -05:00
|
|
|
}
|
2018-01-04 08:29:57 -05:00
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
2018-01-04 10:18:07 -05:00
|
|
|
g_test_bug_base("https://github.com/irssi/irssi/issues/");
|
|
|
|
|
|
|
|
g_test_add("/test/server_destroy_flood", ServerDestroyFloodData, NULL,
|
|
|
|
server_destroy_flood_set_up, test_server_destroy_flood,
|
|
|
|
server_destroy_flood_tear_down);
|
2018-01-04 08:29:57 -05:00
|
|
|
|
2018-04-24 08:00:30 -04:00
|
|
|
#if GLIB_CHECK_VERSION(2,38,0)
|
2018-01-04 08:29:57 -05:00
|
|
|
g_test_set_nonfatal_assertions();
|
2018-04-24 08:00:30 -04:00
|
|
|
#endif
|
2018-01-04 10:18:07 -05:00
|
|
|
|
|
|
|
core_preinit(*argv);
|
|
|
|
irssi_gui = IRSSI_GUI_NONE;
|
|
|
|
|
2018-01-04 08:29:57 -05:00
|
|
|
return g_test_run();
|
|
|
|
}
|