about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-01-19 17:20:31 +0000
committerJames Booth <boothj5@gmail.com>2014-01-19 17:20:31 +0000
commit69f2f4a16f44ae7f6ab94f39623f2f44dfa0a754 (patch)
treef7650f4730df674f7c335c2950114a89dd67aea4
parent5f25d99357bd126bbae99c585cc9d84c265b62fc (diff)
downloadprofani-tty-69f2f4a16f44ae7f6ab94f39623f2f44dfa0a754.tar.gz
Use defaults for /statuses commands
-rw-r--r--Makefile.am1
-rw-r--r--src/config/preferences.c4
-rw-r--r--tests/test_cmd_statuses.h3
-rw-r--r--tests/test_preferences.c41
-rw-r--r--tests/test_preferences.h3
-rw-r--r--tests/testsuite.c14
6 files changed, 63 insertions, 3 deletions
diff --git a/Makefile.am b/Makefile.am
index 9c8a46f3..99a9db8f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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
diff --git a/src/config/preferences.c b/src/config/preferences.c
index 7f7e8b2d..3a7e489a 100644
--- a/src/config/preferences.c
+++ b/src/config/preferences.c
@@ -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;
     }
diff --git a/tests/test_cmd_statuses.h b/tests/test_cmd_statuses.h
index 2ad74c44..69f935f0 100644
--- a/tests/test_cmd_statuses.h
+++ b/tests/test_cmd_statuses.h
@@ -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);
diff --git a/tests/test_preferences.c b/tests/test_preferences.c
new file mode 100644
index 00000000..77aabc6f
--- /dev/null
+++ b/tests/test_preferences.c
@@ -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();
+}
diff --git a/tests/test_preferences.h b/tests/test_preferences.h
new file mode 100644
index 00000000..577226b7
--- /dev/null
+++ b/tests/test_preferences.h
@@ -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);
diff --git a/tests/testsuite.c b/tests/testsuite.c
index 694d8cf3..6f229bcf 100644
--- a/tests/testsuite.c
+++ b/tests/testsuite.c
@@ -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);