mirror of
https://github.com/profanity-im/profanity.git
synced 2024-10-06 20:03:46 -04:00
Refactor test setup and teardown functions
This commit is contained in:
parent
e1fe7783c0
commit
6ef1174bf4
@ -11,7 +11,7 @@
|
||||
#include "helpers.h"
|
||||
#include "config/preferences.h"
|
||||
|
||||
void init_preferences(void **state)
|
||||
void create_config_dir(void **state)
|
||||
{
|
||||
setenv("XDG_CONFIG_HOME", "./tests/files/xdg_config_home", 1);
|
||||
gchar *xdg_config = xdg_get_config_home();
|
||||
@ -22,11 +22,44 @@ void init_preferences(void **state)
|
||||
if (!mkdir_recursive(profanity_dir->str)) {
|
||||
assert_true(FALSE);
|
||||
}
|
||||
g_string_free(profanity_dir, TRUE);
|
||||
|
||||
g_free(xdg_config);
|
||||
g_string_free(profanity_dir, TRUE);
|
||||
}
|
||||
|
||||
void remove_config_dir(void **state)
|
||||
{
|
||||
rmdir("./tests/files/xdg_config_home/profanity");
|
||||
rmdir("./tests/files/xdg_config_home");
|
||||
}
|
||||
|
||||
void create_data_dir(void **state)
|
||||
{
|
||||
setenv("XDG_DATA_HOME", "./tests/files/xdg_data_home", 1);
|
||||
gchar *xdg_data = xdg_get_data_home();
|
||||
|
||||
GString *profanity_dir = g_string_new(xdg_data);
|
||||
g_string_append(profanity_dir, "/profanity");
|
||||
|
||||
if (!mkdir_recursive(profanity_dir->str)) {
|
||||
assert_true(FALSE);
|
||||
}
|
||||
|
||||
g_free(xdg_data);
|
||||
g_string_free(profanity_dir, TRUE);
|
||||
}
|
||||
|
||||
void remove_data_dir(void **state)
|
||||
{
|
||||
rmdir("./tests/files/xdg_data_home/profanity");
|
||||
rmdir("./tests/files/xdg_data_home");
|
||||
}
|
||||
|
||||
void load_preferences(void **state)
|
||||
{
|
||||
create_config_dir(state);
|
||||
FILE *f = fopen("./tests/files/xdg_config_home/profanity/profrc", "ab+");
|
||||
if (f) {
|
||||
g_free(xdg_config);
|
||||
prefs_load();
|
||||
}
|
||||
}
|
||||
@ -35,8 +68,7 @@ void close_preferences(void **state)
|
||||
{
|
||||
prefs_close();
|
||||
remove("./tests/files/xdg_config_home/profanity/profrc");
|
||||
rmdir("./tests/files/xdg_config_home/profanity");
|
||||
rmdir("./tests/files/xdg_config_home");
|
||||
remove_config_dir(state);
|
||||
rmdir("./tests/files");
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "glib.h"
|
||||
|
||||
void init_preferences(void **state);
|
||||
void load_preferences(void **state);
|
||||
void close_preferences(void **state);
|
||||
|
||||
void glist_set_cmp(GCompareFunc func);
|
||||
|
@ -313,64 +313,64 @@ int main(int argc, char* argv[]) {
|
||||
unit_test(cmd_statuses_shows_usage_when_bad_chat_setting),
|
||||
unit_test(cmd_statuses_shows_usage_when_bad_muc_setting),
|
||||
unit_test_setup_teardown(cmd_statuses_console_sets_all,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(cmd_statuses_console_sets_online,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(cmd_statuses_console_sets_none,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(cmd_statuses_chat_sets_all,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(cmd_statuses_chat_sets_online,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(cmd_statuses_chat_sets_none,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(cmd_statuses_muc_sets_on,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(cmd_statuses_muc_sets_off,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
|
||||
unit_test_setup_teardown(statuses_console_defaults_to_all,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(statuses_chat_defaults_to_all,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(statuses_muc_defaults_to_on,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
|
||||
unit_test_setup_teardown(console_doesnt_show_online_presence_when_set_none,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(console_shows_online_presence_when_set_online,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(console_shows_online_presence_when_set_all,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(console_doesnt_show_dnd_presence_when_set_none,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(console_doesnt_show_dnd_presence_when_set_online,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(console_shows_dnd_presence_when_set_all,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test(handle_message_error_when_no_recipient),
|
||||
unit_test_setup_teardown(handle_message_error_when_recipient_cancel,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(handle_message_error_when_recipient_cancel_disables_chat_session,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test(handle_message_error_when_recipient_and_no_type),
|
||||
unit_test(handle_presence_error_when_no_recipient),
|
||||
@ -384,19 +384,19 @@ int main(int argc, char* argv[]) {
|
||||
unit_test(cmd_alias_remove_shows_usage_when_no_args),
|
||||
unit_test(cmd_alias_show_usage_when_invalid_subcmd),
|
||||
unit_test_setup_teardown(cmd_alias_add_adds_alias,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(cmd_alias_add_shows_message_when_exists,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(cmd_alias_remove_removes_alias,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(cmd_alias_remove_shows_message_when_no_alias,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(cmd_alias_list_shows_all_aliases,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
|
||||
unit_test_setup_teardown(test_muc_add_invite, muc_before_test, muc_after_test),
|
||||
@ -433,27 +433,27 @@ int main(int argc, char* argv[]) {
|
||||
unit_test(cmd_otr_log_shows_usage_when_no_args),
|
||||
unit_test(cmd_otr_log_shows_usage_when_invalid_subcommand),
|
||||
unit_test_setup_teardown(cmd_otr_log_on_enables_logging,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(cmd_otr_log_off_disables_logging,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(cmd_otr_redact_redacts_logging,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(cmd_otr_log_on_shows_warning_when_chlog_disabled,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(cmd_otr_log_redact_shows_warning_when_chlog_disabled,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test(cmd_otr_warn_shows_usage_when_no_args),
|
||||
unit_test(cmd_otr_warn_shows_usage_when_invalid_arg),
|
||||
unit_test_setup_teardown(cmd_otr_warn_on_enables_unencrypted_warning,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(cmd_otr_warn_off_disables_unencrypted_warning,
|
||||
init_preferences,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
unit_test(cmd_otr_libver_shows_libotr_version),
|
||||
#else
|
||||
|
Loading…
Reference in New Issue
Block a user