about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-01-19 16:32:31 +0000
committerJames Booth <boothj5@gmail.com>2014-01-19 16:32:31 +0000
commit5f25d99357bd126bbae99c585cc9d84c265b62fc (patch)
tree38d911a9dfe6e10d903f03289a8538d2dec07a2c
parent79e9ab83b02ca8bd1c4ad77b59eb536fa7f081a8 (diff)
downloadprofani-tty-5f25d99357bd126bbae99c585cc9d84c265b62fc.tar.gz
Added tests/config/helpers
-rw-r--r--Makefile.am1
-rw-r--r--tests/config/helpers.c46
-rw-r--r--tests/config/helpers.h2
-rw-r--r--tests/test_cmd_statuses.c40
-rw-r--r--tests/testsuite.c1
5 files changed, 50 insertions, 40 deletions
diff --git a/Makefile.am b/Makefile.am
index bb662711..9c8a46f3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -65,6 +65,7 @@ test_sources = \
     tests/xmpp/mock_xmpp.h tests/xmpp/mock_xmpp.c \
     tests/ui/mock_ui.h tests/ui/mock_ui.c \
     tests/config/mock_accounts.h tests/config/mock_accounts.c \
+    tests/config/helpers.c tests/config/helpers.h \
     tests/log/mock_log.c \
     tests/test_autocomplete.c \
     tests/test_common.c \
diff --git a/tests/config/helpers.c b/tests/config/helpers.c
new file mode 100644
index 00000000..f7e7fdb9
--- /dev/null
+++ b/tests/config/helpers.c
@@ -0,0 +1,46 @@
+#define _XOPEN_SOURCE 600
+#include <glib.h>
+#include <setjmp.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <ftw.h>
+#include <stdlib.h>
+#include <cmocka.h>
+
+#include "common.h"
+
+static int unlink_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
+{
+    int rv = remove(fpath);
+
+    if (rv)
+        perror(fpath);
+
+    return rv;
+}
+
+static int rmrf(char *path)
+{
+    return nftw(path, unlink_cb, 64, FTW_DEPTH | FTW_PHYS);
+}
+
+void create_config_dir(void **state)
+{
+    setenv("XDG_CONFIG_HOME", "./tests/files/xdg_config_home", 1);
+    gchar *xdg_config = xdg_get_config_home();
+
+    GString *profanity_dir = g_string_new(xdg_config);
+    g_string_append(profanity_dir, "/profanity");
+
+    if (!mkdir_recursive(profanity_dir->str)) {
+        assert_true(FALSE);
+    }
+    g_string_free(profanity_dir, TRUE);
+
+    g_free(xdg_config);
+}
+
+void delete_config_dir(void **state)
+{
+   rmrf("./tests/files");
+}
diff --git a/tests/config/helpers.h b/tests/config/helpers.h
new file mode 100644
index 00000000..cd4d5f9d
--- /dev/null
+++ b/tests/config/helpers.h
@@ -0,0 +1,2 @@
+void create_config_dir(void **state);
+void delete_config_dir(void **state);
diff --git a/tests/test_cmd_statuses.c b/tests/test_cmd_statuses.c
index d3797d9c..44f5ea1e 100644
--- a/tests/test_cmd_statuses.c
+++ b/tests/test_cmd_statuses.c
@@ -1,7 +1,3 @@
-#define _XOPEN_SOURCE 600
-#include <stdio.h>
-#include <ftw.h>
-#include <unistd.h>
 #include <stdarg.h>
 #include <stddef.h>
 #include <setjmp.h>
@@ -17,42 +13,6 @@
 
 #include "command/commands.h"
 
-static int unlink_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
-{
-    int rv = remove(fpath);
-
-    if (rv)
-        perror(fpath);
-
-    return rv;
-}
-
-static int rmrf(char *path)
-{
-    return nftw(path, unlink_cb, 64, FTW_DEPTH | FTW_PHYS);
-}
-
-void create_config_dir(void **state)
-{
-    setenv("XDG_CONFIG_HOME", "./tests/files/xdg_config_home", 1);
-    gchar *xdg_config = xdg_get_config_home();
-
-    GString *profanity_dir = g_string_new(xdg_config);
-    g_string_append(profanity_dir, "/profanity");
-
-    if (!mkdir_recursive(profanity_dir->str)) {
-        assert_true(FALSE);
-    }
-    g_string_free(profanity_dir, TRUE);
-
-    g_free(xdg_config);
-}
-
-void delete_config_dir(void **state)
-{
-   rmrf("./tests/files");
-}
-
 void cmd_statuses_shows_usage_when_bad_subcmd(void **state)
 {
     mock_cons_show();
diff --git a/tests/testsuite.c b/tests/testsuite.c
index 642f3e80..694d8cf3 100644
--- a/tests/testsuite.c
+++ b/tests/testsuite.c
@@ -6,6 +6,7 @@
 #include <setjmp.h>
 #include <cmocka.h>
 
+#include "config/helpers.h"
 #include "test_autocomplete.h"
 #include "test_common.h"
 #include "test_contact.h"