about summary refs log tree commit diff stats
path: root/linux/translate_subx
Commit message (Expand)AuthorAgeFilesLines
* 7842 - new directory organizationKartik K. Agaram2021-03-031-0/+38
file to .gitignore' href='/danisanti/profani-tty/commit/.gitignore?id=362c1d81ae9a975355e16133eb99ed2bee320858'>362c1d81 ^
d944e825 ^

b1375328 ^


30ca6cac ^

b1375328 ^
30ca6cac ^

b1375328 ^

30ca6cac ^
376804be ^
d95ceeb3 ^

1814dcdd ^
b1375328 ^



c182f3ec ^
b1375328 ^


41fe8c22 ^
b1375328 ^





68ed20f1 ^





b1375328 ^


e94b604b ^
e0dfe483 ^
b1375328 ^


e0dfe483 ^

d944e825 ^


9d782fa6 ^


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67





                                                                 





                   
                     

             


           

           
            

               

          
             
         

               
   



               
                


                   
                      





             





                                         


               
             
           


               

                  


                


               
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~

# IDE
.codelite/
profanity.mk
profanity.project
profanity.workspace
compile_commands.json
.tern-port
.tern-project

# autotools
.libs/
Makefile
Makefile.in
_configs.sed
aclocal.m4
autom4te.cache/
build-aux/
config.log
config.status
configure
libprofanity.la
libtool
m4/
**/.deps/
**.dirstamp
src/config.h
src/config.h.in
src/config.h.in~
src/gitversion.h
src/gitversion.h.in
src/stamp-h1
src/plugins/profapi.lo

# binaries
profanity
**/*.o

# test output
tests/functionaltests/functionaltests
tests/functionaltests/functionaltests.log
tests/functionaltests/functionaltests.trs
tests/unittests/unittests
tests/unittests/unittests.log
tests/unittests/unittests.trs
test-suite.log

# local scripts
clean-test.sh
gen_docs.sh
gitpushall.sh

# website files
main_fragment.html
toc_fragment.html

# valgrind files
valgrind.out

.DS_Store
apidocs/c/html/
                           
 
 

                                     
                           





                                      
                            

 

















                                                     










































                                                                      
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <cmocka.h>
#include <glib.h>
#include <stdio.h>
#include <unistd.h>

#include "common.h"
#include "helpers.h"
#include "config/preferences.h"
#include "chat_session.h"

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_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);
    g_string_free(profanity_dir, TRUE);
}

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);
    FILE *f = fopen("./tests/files/xdg_config_home/profanity/profrc", "ab+");
    if (f) {
        prefs_load();
    }
}

void close_preferences(void **state)
{
    prefs_close();
    remove("./tests/files/xdg_config_home/profanity/profrc");
    remove_config_dir(state);
    rmdir("./tests/files");
}

void init_chat_sessions(void **state)
{
    load_preferences(NULL);
    chat_sessions_init();
}

void close_chat_sessions(void **state)
{
    chat_sessions_clear();
    close_preferences(NULL);
}

int
utf8_pos_to_col(char *str, int utf8_pos)
{
    int col = 0;

    int i = 0;
    for (i = 0; i<utf8_pos; i++) {
        col++;
        gchar *ch = g_utf8_offset_to_pointer(str, i);
        gunichar uni = g_utf8_get_char(ch);
        if (g_unichar_iswide(uni)) {
            col++;
        }
    }

    return col;
}

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;
}