1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Use defaults for /statuses commands

This commit is contained in:
James Booth 2014-01-19 17:20:31 +00:00
parent 5f25d99357
commit 69f2f4a16f
6 changed files with 63 additions and 3 deletions

View File

@ -79,6 +79,7 @@ test_sources = \
tests/test_jid.c \
tests/test_parser.c \
tests/test_roster_list.c \
tests/test_preferences.c \
tests/testsuite.c
main_source = src/main.c

View File

@ -393,6 +393,7 @@ _get_default_boolean(preference_t pref)
case PREF_STATUSES:
case PREF_AUTOAWAY_CHECK:
case PREF_OTR_WARN:
case PREF_STATUSES_MUC:
return TRUE;
default:
return FALSE;
@ -408,6 +409,9 @@ _get_default_string(preference_t pref)
return "off";
case PREF_OTR_LOG:
return "redact";
case PREF_STATUSES_CONSOLE:
case PREF_STATUSES_CHAT:
return "all";
default:
return NULL;
}

View File

@ -1,6 +1,3 @@
void create_config_dir(void **state);
void delete_config_dir(void **state);
void cmd_statuses_shows_usage_when_bad_subcmd(void **state);
void cmd_statuses_shows_usage_when_bad_console_setting(void **state);
void cmd_statuses_shows_usage_when_bad_chat_setting(void **state);

41
tests/test_preferences.c Normal file
View File

@ -0,0 +1,41 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "config/preferences.h"
void statuses_console_defaults_to_all(void **state)
{
prefs_load();
char *setting = prefs_get_string(PREF_STATUSES_CONSOLE);
assert_non_null(setting);
assert_string_equal("all", setting);
prefs_close();
}
void statuses_chat_defaults_to_all(void **state)
{
prefs_load();
char *setting = prefs_get_string(PREF_STATUSES_CHAT);
assert_non_null(setting);
assert_string_equal("all", setting);
prefs_close();
}
void statuses_muc_defaults_to_on(void **state)
{
prefs_load();
gboolean setting = prefs_get_boolean(PREF_STATUSES_MUC);
assert_true(setting);
prefs_close();
}

3
tests/test_preferences.h Normal file
View File

@ -0,0 +1,3 @@
void statuses_console_defaults_to_all(void **state);
void statuses_chat_defaults_to_all(void **state);
void statuses_muc_defaults_to_on(void **state);

View File

@ -19,6 +19,7 @@
#include "test_jid.h"
#include "test_parser.h"
#include "test_roster_list.h"
#include "test_preferences.h"
#define PROF_RUN_TESTS(name) fprintf(stderr, "\n-> Running %s\n", #name); \
fflush(stderr); \
@ -356,6 +357,18 @@ int main(int argc, char* argv[]) {
delete_config_dir),
};
const UnitTest preferences_tests[] = {
unit_test_setup_teardown(statuses_console_defaults_to_all,
create_config_dir,
delete_config_dir),
unit_test_setup_teardown(statuses_chat_defaults_to_all,
create_config_dir,
delete_config_dir),
unit_test_setup_teardown(statuses_muc_defaults_to_on,
create_config_dir,
delete_config_dir),
};
int bak, new;
fflush(stdout);
bak = dup(1);
@ -377,6 +390,7 @@ int main(int argc, char* argv[]) {
PROF_RUN_TESTS(cmd_sub_tests);
PROF_RUN_TESTS(contact_tests);
PROF_RUN_TESTS(cmd_statuses_tests);
PROF_RUN_TESTS(preferences_tests);
fflush(stdout);
dup2(bak, 1);