0
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-07-26 12:14:28 -04:00

Rage-cleanup.

While trying to get the unit tests working again I stumbled over all those
things that I thought could be better^TM.

Now we also know "TODO: why does this make the test fail?" - because
the unit tests are brittle AF ... and we have to init the subsystems
we use in the test, otherwise the cleanup will fail...

BTW. you can now also only run a single test ... or a pattern or so ...
you'd have to read how `cmocka_set_test_filter()` works exactly.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
Steffen Jaeckel 2025-03-07 19:03:10 +01:00
parent 72b99ceb6d
commit c0da36c48d
26 changed files with 139 additions and 110 deletions

View File

@ -357,6 +357,9 @@ check-unit: tests/unittests/unittests
format: $(all_c_sources) format: $(all_c_sources)
clang-format -i $(all_c_sources) clang-format -i $(all_c_sources)
format-sources: $(core_sources) $(main_source)
clang-format -i $^
spell: spell:
codespell codespell

View File

@ -1648,6 +1648,7 @@ cmd_ac_uninit(void)
autocomplete_free(plugins_reload_ac); autocomplete_free(plugins_reload_ac);
autocomplete_free(script_show_ac); autocomplete_free(script_show_ac);
g_hash_table_destroy(ac_funcs); g_hash_table_destroy(ac_funcs);
ac_funcs = NULL;
} }
static void static void

View File

@ -2845,7 +2845,9 @@ _cmd_uninit(void)
{ {
cmd_ac_uninit(); cmd_ac_uninit();
g_hash_table_destroy(commands); g_hash_table_destroy(commands);
commands = NULL;
g_hash_table_destroy(search_index); g_hash_table_destroy(search_index);
search_index = NULL;
} }
/* /*

View File

@ -54,6 +54,8 @@
#define PROF "prof" #define PROF "prof"
static void _log_msg(log_level_t level, const char* const area, const char* const msg);
static FILE* logp; static FILE* logp;
static gchar* mainlogfile = NULL; static gchar* mainlogfile = NULL;
static gboolean user_provided_log = FALSE; static gboolean user_provided_log = FALSE;
@ -121,14 +123,22 @@ _log_abbreviation_string_from_level(log_level_t level)
} }
} }
static gboolean
_should_log(log_level_t level)
{
return level >= level_filter && logp;
}
void void
log_debug(const char* const msg, ...) log_debug(const char* const msg, ...)
{ {
if (!_should_log(PROF_LEVEL_DEBUG))
return;
va_list arg; va_list arg;
va_start(arg, msg); va_start(arg, msg);
GString* fmt_msg = g_string_new(NULL); GString* fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, msg, arg); g_string_vprintf(fmt_msg, msg, arg);
log_msg(PROF_LEVEL_DEBUG, PROF, fmt_msg->str); _log_msg(PROF_LEVEL_DEBUG, PROF, fmt_msg->str);
g_string_free(fmt_msg, TRUE); g_string_free(fmt_msg, TRUE);
va_end(arg); va_end(arg);
} }
@ -136,11 +146,13 @@ log_debug(const char* const msg, ...)
void void
log_info(const char* const msg, ...) log_info(const char* const msg, ...)
{ {
if (!_should_log(PROF_LEVEL_INFO))
return;
va_list arg; va_list arg;
va_start(arg, msg); va_start(arg, msg);
GString* fmt_msg = g_string_new(NULL); GString* fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, msg, arg); g_string_vprintf(fmt_msg, msg, arg);
log_msg(PROF_LEVEL_INFO, PROF, fmt_msg->str); _log_msg(PROF_LEVEL_INFO, PROF, fmt_msg->str);
g_string_free(fmt_msg, TRUE); g_string_free(fmt_msg, TRUE);
va_end(arg); va_end(arg);
} }
@ -148,11 +160,13 @@ log_info(const char* const msg, ...)
void void
log_warning(const char* const msg, ...) log_warning(const char* const msg, ...)
{ {
if (!_should_log(PROF_LEVEL_WARN))
return;
va_list arg; va_list arg;
va_start(arg, msg); va_start(arg, msg);
GString* fmt_msg = g_string_new(NULL); GString* fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, msg, arg); g_string_vprintf(fmt_msg, msg, arg);
log_msg(PROF_LEVEL_WARN, PROF, fmt_msg->str); _log_msg(PROF_LEVEL_WARN, PROF, fmt_msg->str);
g_string_free(fmt_msg, TRUE); g_string_free(fmt_msg, TRUE);
va_end(arg); va_end(arg);
} }
@ -160,11 +174,13 @@ log_warning(const char* const msg, ...)
void void
log_error(const char* const msg, ...) log_error(const char* const msg, ...)
{ {
if (!_should_log(PROF_LEVEL_ERROR))
return;
va_list arg; va_list arg;
va_start(arg, msg); va_start(arg, msg);
GString* fmt_msg = g_string_new(NULL); GString* fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, msg, arg); g_string_vprintf(fmt_msg, msg, arg);
log_msg(PROF_LEVEL_ERROR, PROF, fmt_msg->str); _log_msg(PROF_LEVEL_ERROR, PROF, fmt_msg->str);
g_string_free(fmt_msg, TRUE); g_string_free(fmt_msg, TRUE);
va_end(arg); va_end(arg);
} }
@ -206,28 +222,34 @@ log_close(void)
} }
} }
static void
_log_msg(log_level_t level, const char* const area, const char* const msg)
{
GDateTime* dt = g_date_time_new_now_local();
char* level_str = _log_abbreviation_string_from_level(level);
auto_gchar gchar* date_fmt = g_date_time_format_iso8601(dt);
fprintf(logp, "%s: %s: %s: %s\n", date_fmt, area, level_str, msg);
g_date_time_unref(dt);
fflush(logp);
if (prefs_get_boolean(PREF_LOG_ROTATE) && !user_provided_log) {
long result = ftell(logp);
if (result != -1 && result >= prefs_get_max_log_size()) {
_rotate_log_file();
}
}
}
void void
log_msg(log_level_t level, const char* const area, const char* const msg) log_msg(log_level_t level, const char* const area, const char* const msg)
{ {
if (level >= level_filter && logp) { if (!_should_log(level))
GDateTime* dt = g_date_time_new_now_local(); return;
_log_msg(level, area, msg);
char* level_str = _log_abbreviation_string_from_level(level);
auto_gchar gchar* date_fmt = g_date_time_format_iso8601(dt);
fprintf(logp, "%s: %s: %s: %s\n", date_fmt, area, level_str, msg);
g_date_time_unref(dt);
fflush(logp);
if (prefs_get_boolean(PREF_LOG_ROTATE) && !user_provided_log) {
long result = ftell(logp);
if (result != -1 && result >= prefs_get_max_log_size()) {
_rotate_log_file();
}
}
}
} }
int int

View File

@ -111,7 +111,7 @@ api_register_command(const char* const plugin_name, const char* command_name, in
char** synopsis, const char* description, char* arguments[][2], char** examples, char** synopsis, const char* description, char* arguments[][2], char** examples,
void* callback, void (*callback_exec)(PluginCommand* command, gchar** args), void (*callback_destroy)(void* callback)) void* callback, void (*callback_exec)(PluginCommand* command, gchar** args), void (*callback_destroy)(void* callback))
{ {
PluginCommand* command = malloc(sizeof(PluginCommand)); PluginCommand* command = calloc(1, sizeof(PluginCommand));
command->command_name = strdup(command_name); command->command_name = strdup(command_name);
command->min_args = min_args; command->min_args = min_args;
command->max_args = max_args; command->max_args = max_args;
@ -119,28 +119,22 @@ api_register_command(const char* const plugin_name, const char* command_name, in
command->callback_exec = callback_exec; command->callback_exec = callback_exec;
command->callback_destroy = callback_destroy; command->callback_destroy = callback_destroy;
CommandHelp* help = malloc(sizeof(CommandHelp)); CommandHelp* help = calloc(1, sizeof(CommandHelp));
help->tags[0] = NULL;
int i; int i;
for (i = 0; synopsis[i] != NULL; i++) { for (i = 0; synopsis[i] != NULL; i++) {
help->synopsis[i] = strdup(synopsis[i]); help->synopsis[i] = strdup(synopsis[i]);
} }
help->synopsis[i] = NULL;
help->desc = strdup(description); help->desc = strdup(description);
for (i = 0; arguments[i][0] != NULL; i++) { for (i = 0; arguments[i][0] != NULL; i++) {
help->args[i][0] = strdup(arguments[i][0]); help->args[i][0] = strdup(arguments[i][0]);
help->args[i][1] = strdup(arguments[i][1]); help->args[i][1] = strdup(arguments[i][1]);
} }
help->args[i][0] = NULL;
help->args[i][1] = NULL;
for (i = 0; examples[i] != NULL; i++) { for (i = 0; examples[i] != NULL; i++) {
help->examples[i] = strdup(examples[i]); help->examples[i] = strdup(examples[i]);
} }
help->examples[i] = NULL;
command->help = help; command->help = help;

View File

@ -104,7 +104,8 @@ _free_command(PluginCommand* command)
} }
free(command->command_name); free(command->command_name);
_free_command_help(command->help); if (command->help)
_free_command_help(command->help);
free(command); free(command);
} }
@ -118,6 +119,8 @@ _free_command_hash(GHashTable* command_hash)
static void static void
_free_timed_function(PluginTimedFunction* timed_function) _free_timed_function(PluginTimedFunction* timed_function)
{ {
if (!timed_function)
return;
if (timed_function->callback_destroy) { if (timed_function->callback_destroy) {
timed_function->callback_destroy(timed_function->callback); timed_function->callback_destroy(timed_function->callback);
} }
@ -178,8 +181,11 @@ void
callbacks_close(void) callbacks_close(void)
{ {
g_hash_table_destroy(p_window_callbacks); g_hash_table_destroy(p_window_callbacks);
p_window_callbacks = NULL;
g_hash_table_destroy(p_timed_functions); g_hash_table_destroy(p_timed_functions);
p_timed_functions = NULL;
g_hash_table_destroy(p_commands); g_hash_table_destroy(p_commands);
p_commands = NULL;
} }
void void

View File

@ -69,12 +69,6 @@ disable_python_threads()
PyEval_RestoreThread(thread_state); PyEval_RestoreThread(thread_state);
} }
static void
_unref_module(PyObject* module)
{
Py_XDECREF(module);
}
const char* const char*
python_get_version_string(void) python_get_version_string(void)
{ {
@ -95,14 +89,15 @@ python_get_version_number(void)
void void
python_env_init(void) python_env_init(void)
{ {
loaded_modules = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_unref_module); loaded_modules = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)Py_XDECREF);
python_init_prof(); python_init_prof();
auto_gchar gchar* plugins_dir = files_get_data_path(DIR_PLUGINS); auto_gchar gchar* plugins_dir = files_get_data_path(DIR_PLUGINS);
auto_gchar gchar* path = g_strdup_printf( auto_gchar gchar* path = g_strdup_printf(
"import sys\n" "import sys\n"
"sys.path.append(\"%s/\")\n", plugins_dir); "sys.path.append(\"%s/\")\n",
plugins_dir);
PyRun_SimpleString(path); PyRun_SimpleString(path);
python_check_error(); python_check_error();

View File

@ -298,7 +298,10 @@ _call_and_free_shutdown_routine(struct shutdown_routine* r)
void void
prof_shutdown(void) prof_shutdown(void)
{ {
g_list_free_full(shutdown_routines, (GDestroyNotify)_call_and_free_shutdown_routine); if (shutdown_routines) {
g_list_free_full(shutdown_routines, (GDestroyNotify)_call_and_free_shutdown_routine);
shutdown_routines = NULL;
}
} }
static void static void

View File

@ -62,12 +62,7 @@ static gchar* _search(Autocomplete ac, GList* curr, gboolean quote, search_direc
Autocomplete Autocomplete
autocomplete_new(void) autocomplete_new(void)
{ {
Autocomplete new = malloc(sizeof(struct autocomplete_t)); return calloc(1, sizeof(struct autocomplete_t));
new->items = NULL;
new->last_found = NULL;
new->search_str = NULL;
return new;
} }
void void

View File

@ -99,9 +99,10 @@ _ui_close(void)
inp_close(); inp_close();
status_bar_close(); status_bar_close();
free_title_bar(); free_title_bar();
delwin(main_scr);
delscreen(set_term(NULL));
endwin(); endwin();
delwin(main_scr);
main_scr = NULL;
delscreen(set_term(NULL));
} }
void void

View File

@ -164,7 +164,6 @@ create_input_window(void)
inp_win = newpad(1, INP_WIN_MAX); inp_win = newpad(1, INP_WIN_MAX);
wbkgd(inp_win, theme_attrs(THEME_INPUT_TEXT)); wbkgd(inp_win, theme_attrs(THEME_INPUT_TEXT));
;
keypad(inp_win, TRUE); keypad(inp_win, TRUE);
wmove(inp_win, 0, 0); wmove(inp_win, 0, 0);
@ -274,7 +273,9 @@ inp_close(void)
{ {
rl_callback_handler_remove(); rl_callback_handler_remove();
delwin(inp_win); delwin(inp_win);
inp_win = NULL;
fclose(discard); fclose(discard);
discard = NULL;
} }
char* char*

View File

@ -120,6 +120,7 @@ void
status_bar_close(void) status_bar_close(void)
{ {
delwin(statusbar_win); delwin(statusbar_win);
statusbar_win = NULL;
if (statusbar) { if (statusbar) {
if (statusbar->time) { if (statusbar->time) {
g_free(statusbar->time); g_free(statusbar->time);
@ -133,10 +134,11 @@ status_bar_close(void)
if (statusbar->tabs) { if (statusbar->tabs) {
g_hash_table_destroy(statusbar->tabs); g_hash_table_destroy(statusbar->tabs);
} }
free(statusbar); FREE_SET_NULL(statusbar);
} }
if (tz) { if (tz) {
g_time_zone_unref(tz); g_time_zone_unref(tz);
tz = NULL;
} }
} }

View File

@ -89,6 +89,7 @@ void
free_title_bar(void) free_title_bar(void)
{ {
delwin(win); delwin(win);
win = NULL;
} }
void void

View File

@ -1226,8 +1226,11 @@ void
wins_destroy(void) wins_destroy(void)
{ {
g_hash_table_destroy(windows); g_hash_table_destroy(windows);
windows = NULL;
autocomplete_free(wins_ac); autocomplete_free(wins_ac);
wins_ac = NULL;
autocomplete_free(wins_close_ac); autocomplete_free(wins_close_ac);
wins_close_ac = NULL;
} }
ProfWin* ProfWin*

View File

@ -77,22 +77,30 @@ _free_avatar_data(avatar_metadata* data)
} }
} }
static void
_avatar_cleanup(void)
{
if (looking_for) {
g_hash_table_destroy(looking_for);
}
if (shall_open) {
g_hash_table_destroy(shall_open);
}
looking_for = NULL;
shall_open = NULL;
}
void void
avatar_pep_subscribe(void) avatar_pep_subscribe(void)
{ {
prof_add_shutdown_routine(_avatar_cleanup);
message_pubsub_event_handler_add(STANZA_NS_USER_AVATAR_METADATA, _avatar_metadata_handler, NULL, NULL); message_pubsub_event_handler_add(STANZA_NS_USER_AVATAR_METADATA, _avatar_metadata_handler, NULL, NULL);
message_pubsub_event_handler_add(STANZA_NS_USER_AVATAR_DATA, _avatar_metadata_handler, NULL, NULL); message_pubsub_event_handler_add(STANZA_NS_USER_AVATAR_DATA, _avatar_metadata_handler, NULL, NULL);
// caps_add_feature(XMPP_FEATURE_USER_AVATAR_METADATA_NOTIFY); // caps_add_feature(XMPP_FEATURE_USER_AVATAR_METADATA_NOTIFY);
if (looking_for) { _avatar_cleanup();
g_hash_table_destroy(looking_for);
}
looking_for = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); looking_for = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
if (shall_open) {
g_hash_table_destroy(shall_open);
}
shall_open = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); shall_open = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
} }

View File

@ -56,7 +56,7 @@ _chat_session_new(const char* const barejid, const char* const resource, gboolea
assert(barejid != NULL); assert(barejid != NULL);
assert(resource != NULL); assert(resource != NULL);
ChatSession* new_session = malloc(sizeof(struct chat_session_t)); ChatSession* new_session = calloc(1, sizeof(*new_session));
new_session->barejid = strdup(barejid); new_session->barejid = strdup(barejid);
new_session->resource = strdup(resource); new_session->resource = strdup(resource);
new_session->resource_override = resource_override; new_session->resource_override = resource_override;
@ -88,8 +88,10 @@ chat_sessions_init(void)
void void
chat_sessions_clear(void) chat_sessions_clear(void)
{ {
if (sessions) if (sessions) {
g_hash_table_remove_all(sessions); g_hash_table_remove_all(sessions);
sessions = NULL;
}
} }
void void
@ -101,7 +103,7 @@ chat_session_resource_override(const char* const barejid, const char* const reso
ChatSession* ChatSession*
chat_session_get(const char* const barejid) chat_session_get(const char* const barejid)
{ {
return g_hash_table_lookup(sessions, barejid); return sessions ? g_hash_table_lookup(sessions, barejid) : NULL;
} }
char* char*

View File

@ -320,7 +320,6 @@ void
iq_handlers_clear(void) iq_handlers_clear(void)
{ {
if (id_handlers) { if (id_handlers) {
g_hash_table_remove_all(id_handlers);
g_hash_table_destroy(id_handlers); g_hash_table_destroy(id_handlers);
id_handlers = NULL; id_handlers = NULL;
} }
@ -410,7 +409,6 @@ void
iq_rooms_cache_clear(void) iq_rooms_cache_clear(void)
{ {
if (rooms_cache) { if (rooms_cache) {
g_hash_table_remove_all(rooms_cache);
g_hash_table_destroy(rooms_cache); g_hash_table_destroy(rooms_cache);
rooms_cache = NULL; rooms_cache = NULL;
} }

View File

@ -320,13 +320,9 @@ _handle_form(xmpp_stanza_t* const stanza)
return TRUE; return TRUE;
} }
void static void
message_handlers_init(void) _message_handlers_cleanup(void)
{ {
xmpp_conn_t* const conn = connection_get_conn();
xmpp_ctx_t* const ctx = connection_get_ctx();
xmpp_handler_add(conn, _message_handler, NULL, STANZA_NAME_MESSAGE, NULL, ctx);
if (pubsub_event_handlers) { if (pubsub_event_handlers) {
GList* keys = g_hash_table_get_keys(pubsub_event_handlers); GList* keys = g_hash_table_get_keys(pubsub_event_handlers);
GList* curr = keys; GList* curr = keys;
@ -340,7 +336,17 @@ message_handlers_init(void)
g_list_free(keys); g_list_free(keys);
g_hash_table_destroy(pubsub_event_handlers); g_hash_table_destroy(pubsub_event_handlers);
} }
pubsub_event_handlers = NULL;
}
void
message_handlers_init(void)
{
prof_add_shutdown_routine(_message_handlers_cleanup);
xmpp_conn_t* const conn = connection_get_conn();
xmpp_ctx_t* const ctx = connection_get_ctx();
xmpp_handler_add(conn, _message_handler, NULL, STANZA_NAME_MESSAGE, NULL, ctx);
_message_handlers_cleanup();
pubsub_event_handlers = g_hash_table_new_full(g_str_hash, g_str_equal, free, free); pubsub_event_handlers = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
} }

View File

@ -11,6 +11,9 @@
#include "helpers.h" #include "helpers.h"
#include "config/preferences.h" #include "config/preferences.h"
#include "xmpp/chat_session.h" #include "xmpp/chat_session.h"
#include "command/cmd_defs.h"
void prof_shutdown(void);
void void
create_config_dir(void** state) create_config_dir(void** state)
@ -51,18 +54,24 @@ load_preferences(void** state)
FILE* f = fopen("./tests/files/xdg_config_home/profanity/profrc", "ab+"); FILE* f = fopen("./tests/files/xdg_config_home/profanity/profrc", "ab+");
if (f) { if (f) {
prefs_load(NULL); prefs_load(NULL);
} else {
return 1;
} }
fclose(f); fclose(f);
cmd_init();
chat_sessions_init();
return 0; return 0;
} }
int int
close_preferences(void** state) close_preferences(void** state)
{ {
chat_sessions_clear();
prefs_close(); prefs_close();
remove("./tests/files/xdg_config_home/profanity/profrc"); remove("./tests/files/xdg_config_home/profanity/profrc");
remove_config_dir(state); remove_config_dir(state);
rmdir("./tests/files"); rmdir("./tests/files");
prof_shutdown();
return 0; return 0;
} }
@ -79,6 +88,7 @@ close_chat_sessions(void** state)
{ {
chat_sessions_clear(); chat_sessions_clear();
close_preferences(NULL); close_preferences(NULL);
prof_shutdown();
return 0; return 0;
} }

View File

@ -16,9 +16,6 @@ returns_no_commands(void** state)
GList* commands = plugins_get_command_names(); GList* commands = plugins_get_command_names();
assert_true(commands == NULL); assert_true(commands == NULL);
callbacks_close();
g_list_free(commands);
} }
void void
@ -26,15 +23,15 @@ returns_commands(void** state)
{ {
callbacks_init(); callbacks_init();
PluginCommand* command1 = malloc(sizeof(PluginCommand)); PluginCommand* command1 = calloc(1, sizeof(PluginCommand));
command1->command_name = strdup("command1"); command1->command_name = strdup("command1");
callbacks_add_command("plugin1", command1); callbacks_add_command("plugin1", command1);
PluginCommand* command2 = malloc(sizeof(PluginCommand)); PluginCommand* command2 = calloc(1, sizeof(PluginCommand));
command2->command_name = strdup("command2"); command2->command_name = strdup("command2");
callbacks_add_command("plugin1", command2); callbacks_add_command("plugin1", command2);
PluginCommand* command3 = malloc(sizeof(PluginCommand)); PluginCommand* command3 = calloc(1, sizeof(PluginCommand));
command3->command_name = strdup("command3"); command3->command_name = strdup("command3");
callbacks_add_command("plugin2", command3); callbacks_add_command("plugin2", command3);
@ -61,6 +58,4 @@ returns_commands(void** state)
assert_true(foundCommand1 && foundCommand2 && foundCommand3); assert_true(foundCommand1 && foundCommand2 && foundCommand3);
g_list_free(names); g_list_free(names);
// TODO: why does this make the test fail?
// callbacks_close();
} }

View File

@ -84,7 +84,6 @@ cmd_alias_add_shows_message_when_exists(void** state)
{ {
gchar* args[] = { "add", "hc", "/help commands", NULL }; gchar* args[] = { "add", "hc", "/help commands", NULL };
cmd_init();
prefs_add_alias("hc", "/help commands"); prefs_add_alias("hc", "/help commands");
cmd_ac_add("/hc"); cmd_ac_add("/hc");

View File

@ -216,8 +216,6 @@ cmd_bookmark_uses_roomjid_in_room(void** state)
gboolean result = cmd_bookmark(&muc_win.window, CMD_BOOKMARK, args); gboolean result = cmd_bookmark(&muc_win.window, CMD_BOOKMARK, args);
assert_true(result); assert_true(result);
muc_close();
} }
void void
@ -243,8 +241,6 @@ cmd_bookmark_add_uses_roomjid_in_room(void** state)
gboolean result = cmd_bookmark(&muc_win.window, CMD_BOOKMARK, args); gboolean result = cmd_bookmark(&muc_win.window, CMD_BOOKMARK, args);
assert_true(result); assert_true(result);
muc_close();
} }
void void
@ -271,8 +267,6 @@ cmd_bookmark_add_uses_supplied_jid_in_room(void** state)
gboolean result = cmd_bookmark(&muc_win.window, CMD_BOOKMARK, args); gboolean result = cmd_bookmark(&muc_win.window, CMD_BOOKMARK, args);
assert_true(result); assert_true(result);
muc_close();
} }
void void
@ -401,8 +395,6 @@ cmd_bookmark_remove_uses_roomjid_in_room(void** state)
gboolean result = cmd_bookmark(&muc_win.window, CMD_BOOKMARK, args); gboolean result = cmd_bookmark(&muc_win.window, CMD_BOOKMARK, args);
assert_true(result); assert_true(result);
muc_close();
} }
void void
@ -426,6 +418,4 @@ cmd_bookmark_remove_uses_supplied_jid_in_room(void** state)
gboolean result = cmd_bookmark(&muc_win.window, CMD_BOOKMARK, args); gboolean result = cmd_bookmark(&muc_win.window, CMD_BOOKMARK, args);
assert_true(result); assert_true(result);
muc_close();
} }

View File

@ -87,8 +87,6 @@ cmd_join_uses_account_mucservice_when_no_service_specified(void** state)
gboolean result = cmd_join(NULL, CMD_JOIN, args); gboolean result = cmd_join(NULL, CMD_JOIN, args);
assert_true(result); assert_true(result);
muc_close();
} }
void void
@ -115,8 +113,6 @@ cmd_join_uses_supplied_nick(void** state)
gboolean result = cmd_join(NULL, CMD_JOIN, args); gboolean result = cmd_join(NULL, CMD_JOIN, args);
assert_true(result); assert_true(result);
muc_close();
} }
void void
@ -143,8 +139,6 @@ cmd_join_uses_account_nick_when_not_supplied(void** state)
gboolean result = cmd_join(NULL, CMD_JOIN, args); gboolean result = cmd_join(NULL, CMD_JOIN, args);
assert_true(result); assert_true(result);
muc_close();
} }
void void
@ -174,6 +168,4 @@ cmd_join_uses_password_when_supplied(void** state)
gboolean result = cmd_join(NULL, CMD_JOIN, args); gboolean result = cmd_join(NULL, CMD_JOIN, args);
assert_true(result); assert_true(result);
muc_close();
} }

View File

@ -16,7 +16,6 @@ muc_before_test(void** state)
int int
muc_after_test(void** state) muc_after_test(void** state)
{ {
muc_close();
return 0; return 0;
} }

View File

@ -17,9 +17,6 @@
#include "plugins/plugins.h" #include "plugins/plugins.h"
#include "ui/window_list.h" #include "ui/window_list.h"
void prof_shutdown(void);
void void
console_shows_online_presence_when_set_online(void** state) console_shows_online_presence_when_set_online(void** state)
{ {
@ -38,7 +35,6 @@ console_shows_online_presence_when_set_online(void** state)
sv_ev_contact_online(barejid, resource, NULL, NULL); sv_ev_contact_online(barejid, resource, NULL, NULL);
roster_destroy(); roster_destroy();
prof_shutdown();
} }
void void
@ -59,7 +55,6 @@ console_shows_online_presence_when_set_all(void** state)
sv_ev_contact_online(barejid, resource, NULL, NULL); sv_ev_contact_online(barejid, resource, NULL, NULL);
roster_destroy(); roster_destroy();
prof_shutdown();
} }
void void
@ -80,7 +75,6 @@ console_shows_dnd_presence_when_set_all(void** state)
sv_ev_contact_online(barejid, resource, NULL, NULL); sv_ev_contact_online(barejid, resource, NULL, NULL);
roster_destroy(); roster_destroy();
prof_shutdown();
} }
void void
@ -96,7 +90,7 @@ handle_offline_removes_chat_session(void** state)
Resource* resourcep = resource_new(resource, RESOURCE_ONLINE, NULL, 10); Resource* resourcep = resource_new(resource, RESOURCE_ONLINE, NULL, 10);
roster_update_presence(barejid, resourcep, NULL); roster_update_presence(barejid, resourcep, NULL);
chat_session_recipient_active(barejid, resource, FALSE); chat_session_recipient_active(barejid, resource, FALSE);
ProfConsoleWin* console = malloc(sizeof(ProfConsoleWin)); ProfConsoleWin* console = calloc(1, sizeof(ProfConsoleWin));
will_return(win_create_console, &console->window); will_return(win_create_console, &console->window);
wins_init(); wins_init();
sv_ev_contact_offline(barejid, resource, NULL); sv_ev_contact_offline(barejid, resource, NULL);
@ -106,7 +100,6 @@ handle_offline_removes_chat_session(void** state)
roster_destroy(); roster_destroy();
chat_sessions_clear(); chat_sessions_clear();
prof_shutdown();
} }
void void

View File

@ -57,6 +57,9 @@ main(int argc, char* argv[])
printf(" MB_CUR_MAX: %d\n", (int)MB_CUR_MAX); printf(" MB_CUR_MAX: %d\n", (int)MB_CUR_MAX);
printf(" MB_LEN_MAX: %d\n", (int)MB_LEN_MAX); printf(" MB_LEN_MAX: %d\n", (int)MB_LEN_MAX);
if (argc > 1)
cmocka_set_test_filter(argv[1]);
const struct CMUnitTest all_tests[] = { const struct CMUnitTest all_tests[] = {
cmocka_unit_test(replace_one_substr), cmocka_unit_test(replace_one_substr),
@ -460,7 +463,9 @@ main(int argc, char* argv[])
cmocka_unit_test_setup_teardown(handle_offline_removes_chat_session, cmocka_unit_test_setup_teardown(handle_offline_removes_chat_session,
load_preferences, load_preferences,
close_preferences), close_preferences),
cmocka_unit_test(lost_connection_clears_chat_sessions), cmocka_unit_test_setup_teardown(lost_connection_clears_chat_sessions,
load_preferences,
close_preferences),
cmocka_unit_test(cmd_alias_add_shows_usage_when_no_args), cmocka_unit_test(cmd_alias_add_shows_usage_when_no_args),
cmocka_unit_test(cmd_alias_add_shows_usage_when_no_value), cmocka_unit_test(cmd_alias_add_shows_usage_when_no_value),
@ -623,8 +628,12 @@ main(int argc, char* argv[])
cmocka_unit_test(prof_whole_occurrences_tests), cmocka_unit_test(prof_whole_occurrences_tests),
cmocka_unit_test(prof_occurrences_of_large_message_tests), cmocka_unit_test(prof_occurrences_of_large_message_tests),
cmocka_unit_test(returns_no_commands), cmocka_unit_test_setup_teardown(returns_no_commands,
cmocka_unit_test(returns_commands), load_preferences,
close_preferences),
cmocka_unit_test_setup_teardown(returns_commands,
load_preferences,
close_preferences),
cmocka_unit_test(returns_empty_list_when_none), cmocka_unit_test(returns_empty_list_when_none),
cmocka_unit_test(returns_added_feature), cmocka_unit_test(returns_added_feature),
@ -634,6 +643,5 @@ main(int argc, char* argv[])
cmocka_unit_test(removes_plugin_features), cmocka_unit_test(removes_plugin_features),
cmocka_unit_test(does_not_remove_feature_when_more_than_one_reference), cmocka_unit_test(does_not_remove_feature_when_more_than_one_reference),
}; };
return cmocka_run_group_tests(all_tests, NULL, NULL); return cmocka_run_group_tests(all_tests, NULL, NULL);
} }