about summary refs log tree commit diff stats
path: root/tests/unittests/test_cmd_pgp.c
blob: 55130dac068ff03ae7ac1a154a2898f36df5bd72 (plain) (blame)
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
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>

#include "config.h"

#include "command/cmd_funcs.h"
#include "xmpp/xmpp.h"

#include "ui/stub_ui.h"

#define CMD_PGP "/pgp"

#ifdef HAVE_LIBGPGME
void
cmd_pgp_shows_usage_when_no_args(void** state)
{
    gchar* args[] = { NULL };

    expect_string(cons_bad_cmd_usage, cmd, CMD_PGP);

    gboolean result = cmd_pgp(NULL, CMD_PGP, args);
    assert_true(result);
}

void
cmd_pgp_start_shows_message_when_connection(jabber_conn_status_t conn_status)
{
    gchar* args[] = { "start", NULL };
    ProfWin window;
    window.type = WIN_CHAT;

    will_return(connection_get_status, conn_status);

    expect_cons_show("You must be connected to start PGP encrpytion.");

    gboolean result = cmd_pgp(&window, CMD_PGP, args);
    assert_true(result);
}

void
cmd_pgp_start_shows_message_when_disconnected(void** state)
{
    cmd_pgp_start_shows_message_when_connection(JABBER_DISCONNECTED);
}

void
cmd_pgp_start_shows_message_when_disconnecting(void** state)
{
    cmd_pgp_start_shows_message_when_connection(JABBER_DISCONNECTING);
}

void
cmd_pgp_start_shows_message_when_connecting(void** state)
{
    cmd_pgp_start_shows_message_when_connection(JABBER_CONNECTING);
}

void
cmd_pgp_start_shows_message_when_no_arg_in_wintype(win_type_t wintype)
{
    gchar* args[] = { "start", NULL };
    ProfWin window;
    window.type = wintype;

    will_return(connection_get_status, JABBER_CONNECTED);

    expect_cons_show("You must be in a regular chat window to start PGP encrpytion.");

    gboolean result = cmd_pgp(&window, CMD_PGP, args);
    assert_true(result);
}

void
cmd_pgp_start_shows_message_when_no_arg_in_console(void** state)
{
    cmd_pgp_start_shows_message_when_no_arg_in_wintype(WIN_CONSOLE);
}

void
cmd_pgp_start_shows_message_when_no_arg_in_muc(void** state)
{
    cmd_pgp_start_shows_message_when_no_arg_in_wintype(WIN_MUC);
}

void
cmd_pgp_start_shows_message_when_no_arg_in_conf(void** state)
{
    cmd_pgp_start_shows_message_when_no_arg_in_wintype(WIN_CONFIG);
}

void
cmd_pgp_start_shows_message_when_no_arg_in_private(void** state)
{
    cmd_pgp_start_shows_message_when_no_arg_in_wintype(WIN_PRIVATE);
}

void
cmd_pgp_start_shows_message_when_no_arg_in_xmlconsole(void** state)
{
    cmd_pgp_start_shows_message_when_no_arg_in_wintype(WIN_XML);
}

#else
void
cmd_pgp_shows_message_when_pgp_unsupported(void** state)
{
    gchar* args[] = { "gen", NULL };

    expect_cons_show("This version of Profanity has not been built with PGP support enabled");

    gboolean result = cmd_pgp(NULL, CMD_PGP, args);
    assert_true(result);
}
#endif
k for too many clients in stacked mode' href='/acidbong/suckless/dwm/commit/tag.c?id=79cd408844c62963aa0eec45bb0414ed66f06f6f'>79cd408 ^
58f2fe3 ^



dba2306 ^
79cd408 ^





c53980c ^
dba2306 ^





4f8b08d ^
dba2306 ^






adaa28a ^
4f8b08d ^
dba2306 ^
4f8b08d ^
adaa28a ^
dba2306 ^


4f8b08d ^













0aaa9a2 ^
4f8b08d ^



dba2306 ^










adaa28a ^


bcaf6a7 ^
adaa28a ^

bcaf6a7 ^

adaa28a ^
bcaf6a7 ^
adaa28a ^






bcaf6a7 ^








adaa28a ^
bcaf6a7 ^
901b3ed ^
adaa28a ^
bcaf6a7 ^

adaa28a ^





adaa28a ^










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



                                                              
                
 

                  
                   
                      

                      
            
 





                            
                
                      


                                                                                      

  
            
 






                               
                                

    
                   
 
                
                       
 
                                         
                      








                                          

                                   
                                                 
                 



                                     
                                                    















                                               
                                                







                                                 
                           
                                   
                                        
                                          
                                                         


                                         



                                                                

                                         



                                                                
                         
                                         



                                                              
                         





                                                                
                                                  





                                               
                                                    






                                    
        
                                  
 
                                             
                 


    













                                           
               



                 










                                    


                  
                            

                                                                            

                       
                             
                      






                                             








                                                                             
                                                                             
                                         
                                                                     
                                 

                                                





                                            










                                           
/*
 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
 * See LICENSE file for license details.
 */
#include "dwm.h"

#include <regex.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <X11/Xutil.h>

/* static */

typedef struct {
	const char *pattern;
	char *tags[TLast];
	Bool isfloat;
} Rule;

/* CUSTOMIZE */ 
static Rule rule[] = {
	/* class			instance	tags		isfloat */
	{ "Firefox.*",	{ [Twww] = "www" },			False },
	{ "Gimp.*",		{ 0 },						True},
};

/* extern */

/* CUSTOMIZE */
char *tags[TLast] = {
	[Tscratch] = "scratch",
	[Tdev] = "dev",
	[Twww] = "www",
	[Twork] = "work",
};
void (*arrange)(Arg *) = dotile;

void
appendtag(Arg *arg)
{
	if(!sel)
		return;

	sel->tags[arg->i] = tags[arg->i];
	arrange(NULL);
}

void
dofloat(Arg *arg)
{
	Client *c;

	arrange = dofloat;
	for(c = clients; c; c = c->next) {
		setgeom(c);
		if(c->tags[tsel]) {
			resize(c, True, TopLeft);
		}
		else
			ban(c);
	}
	if(sel && !sel->tags[tsel]) {
		if((sel = getnext(clients, tsel))) {
			higher(sel);
			focus(sel);
		}
	}
	drawall();
}

void
dotile(Arg *arg)
{
	Client *c;
	int n, i, w, h;

	w = sw - mw;
	arrange = dotile;
	for(n = 0, c = clients; c; c = c->next)
		if(c->tags[tsel] && !c->isfloat)
			n++;

	if(n > 1)
		h = (sh - bh) / (n - 1);
	else
		h = sh - bh;

	for(i = 0, c = clients; c; c = c->next) {
		setgeom(c);
		if(c->tags[tsel]) {
			if(c->isfloat) {
				higher(c);
				resize(c, True, TopLeft);
				continue;
			}
			if(n == 1) {
				*c->x = sx;
				*c->y = sy + bh;
				*c->w = sw - 2 * c->border;
				*c->h = sh - 2 * c->border - bh;
			}
			else if(i == 0) {
				*c->x = sx;
				*c->y = sy + bh;
				*c->w = mw - 2 * c->border;
				*c->h = sh - 2 * c->border - bh;
			}
			else if(h > bh) {
				*c->x = sx + mw;
				*c->y = sy + (i - 1) * h + bh;
				*c->w = w - 2 * c->border;
				*c->h = h - 2 * c->border;
			}
			else { /* fallback if h < bh */
				*c->x = sx + mw;
				*c->y = sy + bh;
				*c->w = w - 2 * c->border;
				*c->h = sh - 2 * c->border - bh;
			}
			resize(c, False, TopLeft);
			i++;
		}
		else
			ban(c);
	}
	if(!sel || (sel && !sel->tags[tsel])) {
		if((sel = getnext(clients, tsel))) {
			higher(sel);
			focus(sel);
		}
	}
	drawall();
}

Client *
getnext(Client *c, unsigned int t)
{
	for(; c && !c->tags[t]; c = c->next);
	return c;
}

void
heretag(Arg *arg)
{
	int i;
	Client *c;

	if(arg->i == tsel)
		return;

	if(!(c = getnext(clients, arg->i)))
		return;

	for(i = 0; i < TLast; i++)
		c->tags[i] = NULL;
	c->tags[tsel] = tags[tsel];
	pop(c);
	focus(c);
}

void
replacetag(Arg *arg)
{
	int i;
	if(!sel)
		return;

	for(i = 0; i < TLast; i++)
		sel->tags[i] = NULL;
	appendtag(arg);
}

void
settags(Client *c)
{
	char classinst[256];
	static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
	unsigned int i, j;
	regex_t regex;
	regmatch_t tmp;
	Bool matched = False;
	XClassHint ch;

	if(!len) {
		c->tags[tsel] = tags[tsel];
		return;
	}

	if(XGetClassHint(dpy, c->win, &ch)) {
		snprintf(classinst, sizeof(classinst), "%s:%s",
				ch.res_class ? ch.res_class : "",
				ch.res_name ? ch.res_name : "");
		for(i = 0; !matched && i < len; i++) {
			if(!regcomp(&regex, rule[i].pattern, 0)) {
				if(!regexec(&regex, classinst, 1, &tmp, 0)) {
					for(j = 0; j < TLast; j++) {
						if(rule[i].tags[j])
							matched = True;
						c->tags[j] = rule[i].tags[j];
					}
					c->isfloat = rule[i].isfloat;
				}
				regfree(&regex);
			}
		}
		if(ch.res_class)
			XFree(ch.res_class);
		if(ch.res_name)
			XFree(ch.res_name);
	}
	if(!matched)
		c->tags[tsel] = tags[tsel];
}

void
view(Arg *arg)
{
	tsel = arg->i;
	arrange(NULL);
	drawall();
}