From 5bddfe7b7336f6b48408c72955dbcb664cc4dc97 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Thu, 4 Jan 2018 14:29:57 +0100 Subject: add new test skeleton --- configure.ac | 1 + tests/irc/Makefile.am | 4 +++- tests/irc/flood/Makefile.am | 32 ++++++++++++++++++++++++++++++++ tests/irc/flood/test-796.c | 29 +++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 tests/irc/flood/Makefile.am create mode 100644 tests/irc/flood/test-796.c diff --git a/configure.ac b/configure.ac index 76ada09f..61e96149 100644 --- a/configure.ac +++ b/configure.ac @@ -665,6 +665,7 @@ tests/fe-common/Makefile tests/fe-common/core/Makefile tests/irc/Makefile tests/irc/core/Makefile +tests/irc/flood/Makefile docs/Makefile docs/help/Makefile docs/help/in/Makefile diff --git a/tests/irc/Makefile.am b/tests/irc/Makefile.am index 52770885..d42cfc87 100644 --- a/tests/irc/Makefile.am +++ b/tests/irc/Makefile.am @@ -1 +1,3 @@ -SUBDIRS = core +SUBDIRS = \ + core \ + flood diff --git a/tests/irc/flood/Makefile.am b/tests/irc/flood/Makefile.am new file mode 100644 index 00000000..4bc4a93c --- /dev/null +++ b/tests/irc/flood/Makefile.am @@ -0,0 +1,32 @@ +include $(top_srcdir)/utils/glib-tap.mk + +PACKAGE_STRING=irc/flood + +AM_CPPFLAGS = \ + -I$(top_srcdir)/src \ + -I$(top_srcdir)/src/core \ + -DSYSCONFDIR=\""$(sysconfdir)"\" \ + $(GLIB_CFLAGS) + +test_programs = \ + test-796 + +test_796_CPPFLAGS = \ + -I$(top_srcdir)/src/irc/core \ + -I$(top_srcdir)/src/irc/flood \ + $(AM_CPPFLAGS) + +test_796_DEPENDENCIES = \ + ../../../src/core/libcore.a \ + ../../../src/lib-config/libirssi_config.a + +test_796_LDADD = \ + ../../../src/irc/flood/libirc_flood.a \ + ../../../src/irc/core/libirc_core.a \ + ../../../src/core/libcore.a \ + ../../../src/lib-config/libirssi_config.a \ + @GLIB_LIBS@ \ + @OPENSSL_LIBS@ + +test_796_SOURCES = \ + test-796.c diff --git a/tests/irc/flood/test-796.c b/tests/irc/flood/test-796.c new file mode 100644 index 00000000..9ca29489 --- /dev/null +++ b/tests/irc/flood/test-796.c @@ -0,0 +1,29 @@ +/* + 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" + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + + g_test_set_nonfatal_assertions(); + return g_test_run(); +} -- cgit v1.2.3 From c7cd49f8d7e83302c0f21f4449cddac528d28eea Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Thu, 4 Jan 2018 16:18:07 +0100 Subject: first bug case, exposes broken server object in chat-completion --- tests/irc/flood/Makefile.am | 8 +++ tests/irc/flood/test-796.c | 122 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) diff --git a/tests/irc/flood/Makefile.am b/tests/irc/flood/Makefile.am index 4bc4a93c..85b52eab 100644 --- a/tests/irc/flood/Makefile.am +++ b/tests/irc/flood/Makefile.am @@ -12,6 +12,7 @@ test_programs = \ test-796 test_796_CPPFLAGS = \ + -I$(top_srcdir)/src/fe-common/core \ -I$(top_srcdir)/src/irc/core \ -I$(top_srcdir)/src/irc/flood \ $(AM_CPPFLAGS) @@ -21,8 +22,15 @@ test_796_DEPENDENCIES = \ ../../../src/lib-config/libirssi_config.a test_796_LDADD = \ + ../../../src/irc/libirc.a \ + ../../../src/fe-common/irc/libfe_common_irc.a \ + ../../../src/fe-common/irc/dcc/libfe_irc_dcc.a \ + ../../../src/fe-common/irc/notifylist/libfe_irc_notifylist.a \ + ../../../src/irc/dcc/libirc_dcc.a \ + ../../../src/irc/notifylist/libirc_notifylist.a \ ../../../src/irc/flood/libirc_flood.a \ ../../../src/irc/core/libirc_core.a \ + ../../../src/fe-common/core/libfe_common_core.a \ ../../../src/core/libcore.a \ ../../../src/lib-config/libirssi_config.a \ @GLIB_LIBS@ \ diff --git a/tests/irc/flood/test-796.c b/tests/irc/flood/test-796.c index 9ca29489..293e87d7 100644 --- a/tests/irc/flood/test-796.c +++ b/tests/irc/flood/test-796.c @@ -19,11 +19,133 @@ */ #include "common.h" +#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); +void irc_deinit(void) ; + +/* 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); +} + +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); + 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); + 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, + (GCompareFunc) g_istr_equal); + + /* 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)@%+")); +} + +static void test_server_destroy_flood(ServerDestroyFloodData *fixture, const void *data) +{ + SERVER_REC *server; /* = g_new0(IRC_SERVER_REC, 1); */ + CHAT_PROTOCOL_REC *proto; + SERVER_CONNECT_REC *conn; + + g_test_bug("796"); + + 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(); + + signal_emit("server connected", 1, server); + + /* 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; + + signal_emit("event privmsg", 4, server, "#someroom :test message", "nick", "user@host"); +} int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); + 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); g_test_set_nonfatal_assertions(); + + core_preinit(*argv); + irssi_gui = IRSSI_GUI_NONE; + return g_test_run(); } -- cgit v1.2.3 From 3b7b868bb11faf74c872ecf606c4eef189e31725 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Thu, 4 Jan 2018 16:43:58 +0100 Subject: finish test case --- tests/irc/flood/test-796.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/irc/flood/test-796.c b/tests/irc/flood/test-796.c index 293e87d7..24a5d4be 100644 --- a/tests/irc/flood/test-796.c +++ b/tests/irc/flood/test-796.c @@ -110,6 +110,7 @@ static void test_server_destroy_flood(ServerDestroyFloodData *fixture, const voi server = proto->server_init_connect(conn); server->session_reconnect = TRUE; server->tag = g_strdup("testserver"); + server_ref(server); g_test_message("created server: %p", server); @@ -118,7 +119,8 @@ static void test_server_destroy_flood(ServerDestroyFloodData *fixture, const voi irc_session_deinit(); irc_irc_deinit(); - signal_emit("server connected", 1, server); + + server_connect_finished(server); /* make up for the skipped session init */ irc_server_init_bare_minimum(IRC_SERVER(server)); @@ -130,6 +132,16 @@ static void test_server_destroy_flood(ServerDestroyFloodData *fixture, const voi /* simulate failing irc_server_send_data() */ server->connection_lost = TRUE; + /* + chat_completion_deinit(); + fe_messages_deinit(); + irc_notifylist_deinit(); + */ + + /* for the purpose of this exercise, we are ignoring the + errors of g_hash_table_lookup failure */ + g_log_set_always_fatal(G_LOG_FATAL_MASK); + signal_emit("event privmsg", 4, server, "#someroom :test message", "nick", "user@host"); } -- cgit v1.2.3 From bffced54981c191f5bac4f9611e4691fe442e58c Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Thu, 4 Jan 2018 21:11:00 +0100 Subject: Update test-796.c odd space --- tests/irc/flood/test-796.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/irc/flood/test-796.c b/tests/irc/flood/test-796.c index 24a5d4be..ae94c5ab 100644 --- a/tests/irc/flood/test-796.c +++ b/tests/irc/flood/test-796.c @@ -33,7 +33,7 @@ /* irc.c */ void irc_init(void); -void irc_deinit(void) ; +void irc_deinit(void); /* irc-session.c */ void irc_session_init(void); -- cgit v1.2.3 From 6b0e14099655bf4d94a19dff252cce89b2858c93 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Thu, 4 Jan 2018 23:01:28 +0100 Subject: show destroyed event --- tests/irc/flood/test-796.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/tests/irc/flood/test-796.c b/tests/irc/flood/test-796.c index ae94c5ab..2e4affa0 100644 --- a/tests/irc/flood/test-796.c +++ b/tests/irc/flood/test-796.c @@ -63,6 +63,11 @@ static void print_disconnect(SERVER_REC *server) g_test_message("server %p was disconnected", server); } +static void print_destroyed(SERVER_REC *server) +{ + g_test_message("server %p was destroyed", server); +} + static void server_destroy_flood_set_up(ServerDestroyFloodData *fixture, const void *data) { args_execute(0, NULL); @@ -73,12 +78,14 @@ static void server_destroy_flood_set_up(ServerDestroyFloodData *fixture, const v signal_emit("irssi init finished", 0); command_bind("echo", NULL, (SIGNAL_FUNC) cmd_echo); signal_add("message public", (SIGNAL_FUNC) sig_public); + signal_add("server destroyed", (SIGNAL_FUNC) print_destroyed); 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); + signal_remove("server destroyed", (SIGNAL_FUNC) print_destroyed); signal_remove("message public", (SIGNAL_FUNC) sig_public); command_unbind("echo", (SIGNAL_FUNC) cmd_echo); fe_common_irc_deinit(); @@ -90,27 +97,31 @@ static void server_destroy_flood_tear_down(ServerDestroyFloodData *fixture, cons static void irc_server_init_bare_minimum(IRC_SERVER_REC *server) { server->isupport = g_hash_table_new((GHashFunc) g_istr_hash, - (GCompareFunc) g_istr_equal); + (GCompareFunc) g_istr_equal); - /* 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)@%+")); + /* 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)@%+")); } static void test_server_destroy_flood(ServerDestroyFloodData *fixture, const void *data) { SERVER_REC *server; /* = g_new0(IRC_SERVER_REC, 1); */ - CHAT_PROTOCOL_REC *proto; + CHAT_PROTOCOL_REC *proto; SERVER_CONNECT_REC *conn; + GLogLevelFlags loglev; g_test_bug("796"); + /* 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); + 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"); - server_ref(server); g_test_message("created server: %p", server); @@ -138,11 +149,11 @@ static void test_server_destroy_flood(ServerDestroyFloodData *fixture, const voi irc_notifylist_deinit(); */ - /* for the purpose of this exercise, we are ignoring the - errors of g_hash_table_lookup failure */ - g_log_set_always_fatal(G_LOG_FATAL_MASK); - + server_ref(server); signal_emit("event privmsg", 4, server, "#someroom :test message", "nick", "user@host"); + server_unref(server); + + g_log_set_always_fatal(loglev); } int main(int argc, char **argv) -- cgit v1.2.3