2014-01-19 16:32:31 +00:00
|
|
|
#include <setjmp.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
2020-07-07 13:53:30 +02:00
|
|
|
#include <cmocka.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <stdio.h>
|
2014-01-20 18:40:48 +00:00
|
|
|
#include <unistd.h>
|
2014-01-19 16:32:31 +00:00
|
|
|
|
|
|
|
#include "common.h"
|
2014-02-01 21:18:15 +00:00
|
|
|
#include "helpers.h"
|
2020-07-07 13:53:30 +02:00
|
|
|
#include "config/preferences.h"
|
2016-07-24 14:23:55 +01:00
|
|
|
#include "xmpp/chat_session.h"
|
2014-01-19 16:32:31 +00:00
|
|
|
|
2020-07-07 14:18:57 +02:00
|
|
|
void
|
|
|
|
create_config_dir(void** state)
|
2014-01-19 16:32:31 +00:00
|
|
|
{
|
|
|
|
setenv("XDG_CONFIG_HOME", "./tests/files/xdg_config_home", 1);
|
2022-03-13 12:02:59 +01:00
|
|
|
if (!create_dir("./tests/files/xdg_config_home/profanity")) {
|
2014-01-19 16:32:31 +00:00
|
|
|
assert_true(FALSE);
|
|
|
|
}
|
2014-02-16 18:07:41 +00:00
|
|
|
}
|
|
|
|
|
2020-07-07 14:18:57 +02:00
|
|
|
void
|
|
|
|
remove_config_dir(void** state)
|
2014-02-16 18:07:41 +00:00
|
|
|
{
|
|
|
|
rmdir("./tests/files/xdg_config_home/profanity");
|
|
|
|
rmdir("./tests/files/xdg_config_home");
|
|
|
|
}
|
|
|
|
|
2020-07-07 14:18:57 +02:00
|
|
|
void
|
|
|
|
create_data_dir(void** state)
|
2014-02-16 18:07:41 +00:00
|
|
|
{
|
|
|
|
setenv("XDG_DATA_HOME", "./tests/files/xdg_data_home", 1);
|
2022-03-13 12:02:59 +01:00
|
|
|
if (!create_dir("./tests/files/xdg_data_home/profanity")) {
|
2014-02-16 18:07:41 +00:00
|
|
|
assert_true(FALSE);
|
|
|
|
}
|
|
|
|
}
|
2014-01-19 16:32:31 +00:00
|
|
|
|
2020-07-07 14:18:57 +02:00
|
|
|
void
|
|
|
|
remove_data_dir(void** state)
|
2014-02-16 18:07:41 +00:00
|
|
|
{
|
|
|
|
rmdir("./tests/files/xdg_data_home/profanity");
|
|
|
|
rmdir("./tests/files/xdg_data_home");
|
|
|
|
}
|
|
|
|
|
2020-07-07 14:18:57 +02:00
|
|
|
void
|
|
|
|
load_preferences(void** state)
|
2014-02-16 18:07:41 +00:00
|
|
|
{
|
|
|
|
create_config_dir(state);
|
2020-07-07 14:18:57 +02:00
|
|
|
FILE* f = fopen("./tests/files/xdg_config_home/profanity/profrc", "ab+");
|
2014-01-25 00:50:07 +00:00
|
|
|
if (f) {
|
2019-08-02 15:28:28 +02:00
|
|
|
prefs_load(NULL);
|
2014-01-25 00:50:07 +00:00
|
|
|
}
|
2015-10-26 14:30:26 +01:00
|
|
|
fclose(f);
|
2014-01-19 16:32:31 +00:00
|
|
|
}
|
|
|
|
|
2020-07-07 14:18:57 +02:00
|
|
|
void
|
|
|
|
close_preferences(void** state)
|
2014-01-19 16:32:31 +00:00
|
|
|
{
|
2014-01-20 18:40:48 +00:00
|
|
|
prefs_close();
|
|
|
|
remove("./tests/files/xdg_config_home/profanity/profrc");
|
2014-02-16 18:07:41 +00:00
|
|
|
remove_config_dir(state);
|
2014-01-20 18:40:48 +00:00
|
|
|
rmdir("./tests/files");
|
2014-01-19 16:32:31 +00:00
|
|
|
}
|
2014-02-01 21:18:15 +00:00
|
|
|
|
2020-07-07 14:18:57 +02:00
|
|
|
void
|
|
|
|
init_chat_sessions(void** state)
|
2015-01-06 21:22:09 +00:00
|
|
|
{
|
2015-01-06 21:56:14 +00:00
|
|
|
load_preferences(NULL);
|
2015-01-06 21:22:09 +00:00
|
|
|
chat_sessions_init();
|
|
|
|
}
|
|
|
|
|
2020-07-07 14:18:57 +02:00
|
|
|
void
|
|
|
|
close_chat_sessions(void** state)
|
2015-01-06 21:22:09 +00:00
|
|
|
{
|
|
|
|
chat_sessions_clear();
|
2015-01-06 21:56:14 +00:00
|
|
|
close_preferences(NULL);
|
2015-01-06 21:22:09 +00:00
|
|
|
}
|
|
|
|
|
2015-01-27 22:13:09 +00:00
|
|
|
int
|
2020-07-07 14:18:57 +02:00
|
|
|
utf8_pos_to_col(char* str, int utf8_pos)
|
2015-01-27 22:13:09 +00:00
|
|
|
{
|
|
|
|
int col = 0;
|
|
|
|
|
|
|
|
int i = 0;
|
2020-07-07 14:18:57 +02:00
|
|
|
for (i = 0; i < utf8_pos; i++) {
|
2015-01-27 22:13:09 +00:00
|
|
|
col++;
|
2020-07-07 14:18:57 +02:00
|
|
|
gchar* ch = g_utf8_offset_to_pointer(str, i);
|
2015-01-27 22:13:09 +00:00
|
|
|
gunichar uni = g_utf8_get_char(ch);
|
|
|
|
if (g_unichar_iswide(uni)) {
|
|
|
|
col++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return col;
|
|
|
|
}
|
|
|
|
|
2014-02-01 21:18:15 +00:00
|
|
|
static GCompareFunc cmp_func;
|
|
|
|
|
|
|
|
void
|
|
|
|
glist_set_cmp(GCompareFunc func)
|
|
|
|
{
|
|
|
|
cmp_func = func;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-07-07 14:18:57 +02:00
|
|
|
glist_contents_equal(const void* actual, const void* expected)
|
2014-02-01 21:18:15 +00:00
|
|
|
{
|
2020-07-07 14:18:57 +02:00
|
|
|
GList* ac = (GList*)actual;
|
|
|
|
GList* ex = (GList*)expected;
|
2014-02-01 21:18:15 +00:00
|
|
|
|
2020-07-07 14:18:57 +02:00
|
|
|
GList* p = ex;
|
2014-02-01 21:18:15 +00:00
|
|
|
printf("\nExpected\n");
|
2020-07-07 14:18:57 +02:00
|
|
|
while (ex) {
|
2014-02-01 21:18:15 +00:00
|
|
|
printf("\n\n%s\n", (char*)p->data);
|
|
|
|
ex = g_list_next(ex);
|
|
|
|
}
|
|
|
|
printf("\n\n");
|
|
|
|
p = ac;
|
|
|
|
printf("\nActual\n");
|
2020-07-07 14:18:57 +02:00
|
|
|
while (ac) {
|
|
|
|
printf("\n\n%s\n", (char*)p->data);
|
2014-02-01 21:18:15 +00:00
|
|
|
ac = g_list_next(ac);
|
|
|
|
}
|
|
|
|
printf("\n\n");
|
|
|
|
|
|
|
|
if (g_list_length(ex) != g_list_length(ac)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 14:18:57 +02:00
|
|
|
GList* ex_curr = ex;
|
2014-02-01 21:18:15 +00:00
|
|
|
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;
|
|
|
|
}
|