about summary refs log blame commit diff stats
path: root/subx.dte
blob: cab7b72db0341dac99c139040aa8eeb7d965e15d (plain) (tree)
1
2
3
4
5
6
7
8
9
10




                                                            




                                                                               



                                 
                                                         



























                             
# Syntax highlighting for https://gitlab.com/craigbarnes/dte
#
# To install this file, symlink it to ~/.dte/syntax/subx
# Then add this line to ~/.dte/rc:
#   ft subx subx

syntax subx

# For improved colorization, add lines like these in your ~/.dte/rc (the
# precise colors here assume the default color scheme in a 256-color terminal):
#   hi subx.comment0 25 underline
#   hi comment 25
#   hi subx.comment2 19
#   hi subx.comment3 245
default comment subx.comment0 subx.comment2 subx.comment3

state start code
    str "# . ." subx.comment3
    str "# ." subx.comment2
    str "# -" subx.comment0
    char # comment
    char '"' string
    eat this

state comment
    char "\n" start
    eat this

state subx.comment0
    char "\n" start
    eat this

state subx.comment2
    char "\n" start
    eat this

state subx.comment3
    char "\n" start
    eat this

state string
    char "\"" start string
    eat this
-tty/blame/tests/functionaltests/proftest.c?id=82ff85c329dca6105bfa9add9cb1424ecc2ae334'>^
6d6bb645 ^




97c5072f ^

05be6082 ^
2241473e ^






97c5072f ^


80665ea0 ^

97c5072f ^



db9376d8 ^

e50461a8 ^
fee6fea0 ^
e50461a8 ^
fee6fea0 ^
e50461a8 ^
fee6fea0 ^
e50461a8 ^
9f3497bf ^
e50461a8 ^





97c5072f ^




0e5dc6d8 ^

97c5072f ^
2241473e ^



046da191 ^
97c5072f ^
db9376d8 ^

db9376d8 ^








a522d022 ^
db9376d8 ^


f17afcf5 ^
a522d022 ^





f17afcf5 ^
f9a7e350 ^
f17afcf5 ^
f9a7e350 ^

a48b9fce ^









6255420b ^

a48b9fce ^
6255420b ^
f3326bf1 ^
f17afcf5 ^
f9a7e350 ^












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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245









                     
                  
                   
 
                    
                   
 
                     
 


                  

           


























                                                           
                                           
































































                                                           
                                                             


                           


    

                






                                                                     

                                
                            




                          

                            
                                                    






                                            


                                                  

                    



                           

                 
                                                
 
                                                                        
                                      
                                                                           
                                        
                                                                      
                                      





                                                                     




                             

                              
                    



                                              
                 
 

    








                                           
                             


                                                               
 





                                                                
    
                                      
 

                                                









                                                                                                                                                 

                                          
                                                                                                               
                     
                                      
 












                                                                                        
#include <sys/stat.h>
#include <glib.h>

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

#include <stabber.h>
#include <expect.h>

#include "proftest.h"

char *config_orig;
char *data_orig;

int fd = 0;

gboolean
_create_dir(char *name)
{
    struct stat sb;

    if (stat(name, &sb) != 0) {
        if (errno != ENOENT || mkdir(name, S_IRWXU) != 0) {
            return FALSE;
        }
    } else {
        if ((sb.st_mode & S_IFDIR) != S_IFDIR) {
            return FALSE;
        }
    }

    return TRUE;
}

gboolean
_mkdir_recursive(const char *dir)
{
    int i;
    gboolean result = TRUE;

    for (i = 1; i <= strlen(dir); i++) {
        if (dir[i] == '/' || dir[i] == '\0') {
            gchar *next_dir = g_strndup(dir, i);
            result = _create_dir(next_dir);
            g_free(next_dir);
            if (!result) {
                break;
            }
        }
    }

    return result;
}

void
_create_config_dir(void)
{
    GString *profanity_dir = g_string_new(XDG_CONFIG_HOME);
    g_string_append(profanity_dir, "/profanity");

    if (!_mkdir_recursive(profanity_dir->str)) {
        assert_true(FALSE);
    }

    g_string_free(profanity_dir, TRUE);
}

void
_create_data_dir(void)
{
    GString *profanity_dir = g_string_new(XDG_DATA_HOME);
    g_string_append(profanity_dir, "/profanity");

    if (!_mkdir_recursive(profanity_dir->str)) {
        assert_true(FALSE);
    }

    g_string_free(profanity_dir, TRUE);
}

void
_create_chatlogs_dir(void)
{
    GString *chatlogs_dir = g_string_new(XDG_DATA_HOME);
    g_string_append(chatlogs_dir, "/profanity/chatlogs");

    if (!_mkdir_recursive(chatlogs_dir->str)) {
        assert_true(FALSE);
    }

    g_string_free(chatlogs_dir, TRUE);
}

void
_create_logs_dir(void)
{
    GString *logs_dir = g_string_new(XDG_DATA_HOME);
    g_string_append(logs_dir, "/profanity/logs");

    if (!_mkdir_recursive(logs_dir->str)) {
        assert_true(FALSE);
    }

    g_string_free(logs_dir, TRUE);
}

void
_cleanup_dirs(void)
{
    int res = system("rm -rf ./tests/functionaltests/files");
    if (res == -1) {
        assert_true(FALSE);
    }
}

void
prof_start(void)
{
    // helper script sets terminal columns, avoids assertions failing
    // based on the test runner terminal size
    fd = exp_spawnl("sh",
        "sh",
        "-c",
        "./tests/functionaltests/start_profanity.sh",
        NULL);
    FILE *fp = fdopen(fd, "r+");

    assert_true(fp != NULL);

    setbuf(fp, (char *)0);
}

void
init_prof_test(void **state)
{
    if (stbbr_start(STBBR_LOGDEBUG ,5230, 0) != 0) {
        assert_true(FALSE);
        return;
    }

    config_orig = getenv("XDG_CONFIG_HOME");
    data_orig = getenv("XDG_DATA_HOME");

    setenv("XDG_CONFIG_HOME", XDG_CONFIG_HOME, 1);
    setenv("XDG_DATA_HOME", XDG_DATA_HOME, 1);

    _cleanup_dirs();

    _create_config_dir();
    _create_data_dir();
    _create_chatlogs_dir();
    _create_logs_dir();

    prof_start();
    assert_true(prof_output_exact("Profanity"));

    // set UI options to make expect assertions faster and more reliable
    prof_input("/inpblock timeout 5");
    assert_true(prof_output_exact("Input blocking set to 5 milliseconds"));
    prof_input("/inpblock dynamic off");
    assert_true(prof_output_exact("Dynamic input blocking disabled"));
    prof_input("/notify message off");
    assert_true(prof_output_exact("Message notifications disabled"));
    prof_input("/wrap off");
    assert_true(prof_output_exact("Word wrap disabled"));
    prof_input("/roster hide");
    assert_true(prof_output_exact("Roster disabled"));
    prof_input("/time off");
}

void
close_prof_test(void **state)
{
    prof_input("/quit");
    waitpid(exp_pid, NULL, 0);
    _cleanup_dirs();

    setenv("XDG_CONFIG_HOME", config_orig, 1);
    setenv("XDG_DATA_HOME", data_orig, 1);

    stbbr_stop();
}

void
prof_input(char *input)
{
    GString *inp_str = g_string_new(input);
    g_string_append(inp_str, "\r");
    write(fd, inp_str->str, inp_str->len);
    g_string_free(inp_str, TRUE);
}

int
prof_output_exact(char *text)
{
    return (1 == exp_expectl(fd, exp_exact, text, 1, exp_end));
}

int
prof_output_regex(char *text)
{
    return (1 == exp_expectl(fd, exp_regexp, text, 1, exp_end));
}

void
prof_connect_with_roster(char *roster)
{
    stbbr_for_query("jabber:iq:roster", roster);

    stbbr_for_id("prof_presence_1",
        "<presence id=\"prof_presence_1\" lang=\"en\" to=\"stabber@localhost/profanity\" from=\"stabber@localhost/profanity\">"
            "<priority>0</priority>"
            "<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" node=\"http://www.profanity.im\" ver=\"f8mrtdyAmhnj8Ca+630bThSL718=\"/>"
        "</presence>"
    );

    prof_input("/connect stabber@localhost port 5230");
    prof_input("password");

    // Allow time for profanity to connect
    exp_timeout = 30;
    assert_true(prof_output_regex("stabber@localhost logged in successfully, .+online.+ \\(priority 0\\)\\."));
    exp_timeout = 10;
    stbbr_wait_for("prof_presence_*");
}

void
prof_connect(void)
{
    prof_connect_with_roster(
        "<iq type=\"result\" to=\"stabber@localhost/profanity\">"
            "<query xmlns=\"jabber:iq:roster\" ver=\"362\">"
                "<item jid=\"buddy1@localhost\" subscription=\"both\" name=\"Buddy1\"/>"
                "<item jid=\"buddy2@localhost\" subscription=\"both\" name=\"Buddy2\"/>"
            "</query>"
        "</iq>"
    );
}