about summary refs log tree commit diff stats
Commit message (Expand)AuthorAgeFilesLines
* Improve error reportingDrew DeVault2019-03-101-3/+2
* Flesh out command parsing & handlingDrew DeVault2019-03-106-23/+48
* Start building out command subsystemDrew DeVault2019-03-107-8/+119
* Add missing go.sum entriesElias Naur2019-02-101-0/+6
* Fix buildElias Naur2019-02-102-2/+3
* Implement Container interface in widgets/Drew DeVault2019-01-202-0/+8
* Implement the Container interface in lib/ui/Drew DeVault2019-01-205-7/+26
* Merge lib/ui/interfaces.go and add anotherDrew DeVault2019-01-203-30/+42
* Make repeated invalidations more efficientDrew DeVault2019-01-141-0/+10
* Send commands up to the top-level aerc widgetDrew DeVault2019-01-142-12/+24
* Add cursor handling in ex lineDrew DeVault2019-01-142-11/+18
* Add README.md, update license (MIT -2019)Drew DeVault2019-01-132-1/+21
* Handle errors from worker initializationDrew DeVault2019-01-131-1/+1
* Swap message list placeholder for spinnerDrew DeVault2019-01-131-1/+3
* Add loading spinnerDrew DeVault2019-01-133-1/+190
* Handle connection errors properlyDrew DeVault2019-01-131-3/+4
* Add name to DirectoryInfo messagesDrew DeVault2019-01-132-2/+4
* Issue IMAP SELECT commandDrew DeVault2019-01-134-1/+53
* Simplify approach to directory listDrew DeVault2019-01-132-8/+35
* Revert "Add abstract list, update dirlist accordingly"Drew DeVault2019-01-133-156/+26
* Revert "Render selected list item differently"Drew DeVault2019-01-132-8/+3
* Render selected list item differentlyDrew DeVault2019-01-132-3/+8
* Add abstract list, update dirlist accordinglyDrew DeVault2019-01-133-26/+156
* Filter dirlist according to user configDrew DeVault2019-01-132-6/+19
* Add directory list widgetDrew DeVault2019-01-132-23/+84
* Move ex line into accountDrew DeVault2019-01-132-66/+58
* Move status line into account, update behaviorDrew DeVault2019-01-132-15/+44
* Remove old account widgetDrew DeVault2019-01-131-97/+0
* Initialize worker in account widgetDrew DeVault2019-01-135-3/+66
* Add basic account widget, populate real acct viewsDrew DeVault2019-01-134-30/+61
* refactor lib/ui/tab to ensure staying in boundsMarkus Ongyerth2018-06-131-8/+21
* Apply gofmtDrew DeVault2018-06-122-9/+10
* fallthrough in worker selectionMarkus Ongyerth2018-06-121-1/+1
* Fix tab invalidation bugsDrew DeVault2018-06-111-1/+5
* Apply gofmtDrew DeVault2018-06-116-17/+17
* Clean up some old codeDrew DeVault2018-06-112-10/+6
* Move sidebar into account tabsDrew DeVault2018-06-112-20/+33
* Use default color for selected tabDrew DeVault2018-06-071-3/+9
* Update go.modDrew DeVault2018-06-011-7/+10
* switch to tcell from termboxMarkus Ongyerth2018-06-0112-159/+151
* Switch to vgoDrew DeVault2018-03-024-25/+10
* Summon exline on demandDrew DeVault2018-02-271-11/+24
* Push commands to the status stackDrew DeVault2018-02-271-4/+3
* Pull main aerc UI into widgetDrew DeVault2018-02-275-83/+130
* Add statusline widgetDrew DeVault2018-02-273-7/+119
* Add stack UI containerDrew DeVault2018-02-273-8/+84
* Make ex line fully unicode awareDrew DeVault2018-02-271-20/+19
* Split UI library and widgetsDrew DeVault2018-02-2611-25/+34
* Implement basic ex line inputDrew DeVault2018-02-265-4/+162
* Add fake status lineDrew DeVault2018-02-171-1/+2
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148


                   

                   


                   

                   
                    
                               
                         
 
                                    









                                                                  























                                                              
                                       
 
 








                                                   

                                                                             

                     

 
                                    
 

                                                             
                             
                           
 
 

                                     
                           





                                      
                            

 

















                                                     










































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