2014-01-19 11:32:31 -05:00
|
|
|
#include <setjmp.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <cmocka.h>
|
2014-01-20 13:40:48 -05:00
|
|
|
#include <glib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
2014-01-19 11:32:31 -05:00
|
|
|
|
|
|
|
#include "common.h"
|
2014-02-01 16:18:15 -05:00
|
|
|
#include "helpers.h"
|
2014-01-20 13:40:48 -05:00
|
|
|
#include "config/preferences.h"
|
2014-01-19 11:32:31 -05:00
|
|
|
|
2014-12-23 14:26:45 -05:00
|
|
|
#include "ui/stub_ui.h"
|
|
|
|
#include "xmpp/stub_xmpp.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
reset_mocks(void **state)
|
|
|
|
{
|
|
|
|
reset_ui_mocks();
|
|
|
|
reset_xmpp_mocks();
|
|
|
|
}
|
|
|
|
|
2014-02-16 13:07:41 -05:00
|
|
|
void create_config_dir(void **state)
|
2014-01-19 11:32:31 -05:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2014-02-16 13:07:41 -05:00
|
|
|
|
|
|
|
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);
|
2014-01-19 11:32:31 -05:00
|
|
|
g_string_free(profanity_dir, TRUE);
|
2014-02-16 13:07:41 -05:00
|
|
|
}
|
2014-01-19 11:32:31 -05:00
|
|
|
|
2014-02-16 13:07:41 -05:00
|
|
|
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);
|
2014-01-24 19:50:07 -05:00
|
|
|
FILE *f = fopen("./tests/files/xdg_config_home/profanity/profrc", "ab+");
|
|
|
|
if (f) {
|
|
|
|
prefs_load();
|
|
|
|
}
|
2014-01-19 11:32:31 -05:00
|
|
|
}
|
|
|
|
|
2014-01-28 17:05:27 -05:00
|
|
|
void close_preferences(void **state)
|
2014-01-19 11:32:31 -05:00
|
|
|
{
|
2014-01-20 13:40:48 -05:00
|
|
|
prefs_close();
|
|
|
|
remove("./tests/files/xdg_config_home/profanity/profrc");
|
2014-02-16 13:07:41 -05:00
|
|
|
remove_config_dir(state);
|
2014-01-20 13:40:48 -05:00
|
|
|
rmdir("./tests/files");
|
2014-01-19 11:32:31 -05:00
|
|
|
}
|
2014-02-01 16:18:15 -05:00
|
|
|
|
|
|
|
static GCompareFunc cmp_func;
|
|
|
|
|
|
|
|
void
|
|
|
|
glist_set_cmp(GCompareFunc func)
|
|
|
|
{
|
|
|
|
cmp_func = func;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
glist_contents_equal(const void *actual, const void *expected)
|
|
|
|
{
|
|
|
|
GList *ac = (GList *)actual;
|
|
|
|
GList *ex = (GList *)expected;
|
|
|
|
|
|
|
|
GList *p = ex;
|
|
|
|
printf("\nExpected\n");
|
|
|
|
while(ex) {
|
|
|
|
printf("\n\n%s\n", (char*)p->data);
|
|
|
|
ex = g_list_next(ex);
|
|
|
|
}
|
|
|
|
printf("\n\n");
|
|
|
|
p = ac;
|
|
|
|
printf("\nActual\n");
|
|
|
|
while(ac) {
|
|
|
|
printf("\n\n%s\n", (char *)p->data);
|
|
|
|
ac = g_list_next(ac);
|
|
|
|
}
|
|
|
|
printf("\n\n");
|
|
|
|
|
|
|
|
if (g_list_length(ex) != g_list_length(ac)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
GList *ex_curr = ex;
|
|
|
|
while (ex_curr != NULL) {
|
|
|
|
if (g_list_find_custom(ac, ex_curr->data, cmp_func) == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ex_curr = g_list_next(ex_curr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|