1 /**
2 * I3cstatus prints a configurable status bar for the i3 window manager
3 * Copyright (C) 2020 Aaron Ball <nullspoon@oper.io>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "test_common.h"
19
20 void test_str_is_empty() {
21 char* spaces=" ";
22 char* tabs="\t\t \t \t";
23 char* empty="";
24 char* alpha=" abc ";
25 char* alphanum=" abc1234 ";
26 char* fread=" \n";
27
28 assert_int("str_is_empty spaces ", str_is_empty(spaces), 1);
29 assert_int("str_is_empty tabs/spaces ", str_is_empty(tabs), 1);
30 assert_int("str_is_empty empty ", str_is_empty(empty), 1);
31 assert_int("str_is_empty letters ", str_is_empty(alpha), 0);
32 assert_int("str_is_empty alphanumeric", str_is_empty(alphanum), 0);
33 assert_int("str_is_empty fread ", str_is_empty(fread), 1);
34 }
35
36 void test_bar() {
37 char buf[64] = {'\0'};
38 char buf2[64] = "foo: ";
39
40 // Fill is 0, so no colons or periods
41 print_bar(10, 0, buf);
42 assert_strncmp(buf, "[ ", 3);
43
44 print_bar(8, 0, buf);
45 assert_strcmp(buf, "[ ]");
46
47 print_bar(8, 1, buf);
48 assert_strcmp(buf, "[::::::::]");
49
50 print_bar(8, .42, buf);
51 assert_strcmp(buf, "[:::. ]");
52
53 // Fill is 0, so no colons or periods
54 print_bar(10, .13, buf);
55 assert_strcmp(buf, "[:. ]");
56
57 // Fill is 0, so no colons or periods
58 print_bar(10, .17, buf);
59 assert_strncmp(buf, "[:: ", 4);
60
61 // Fill is 2, +.5, so three colons
62 print_bar(10, .25, buf);
63 assert_strncmp(buf, "[::: ", 5);
64
65 // Fill is 2, +.3, so two colons and a period
66 print_bar(10, .23, buf);
67 assert_strncmp(buf, "[::. ", 5);
68
69 // Fill is 2, +.3, so two colons and a period
70 print_bar(10, .23, &buf2[5]);
71 assert_strncmp(buf2, "foo: [::. ", 10);
72 }
73
74 void test_trim() {
75 char buf[256];
76 char none[64] = "needs none";
77 char left[64] = " needs left";
78 char right[64] = "needs right ";
79 char both[64] = " needs both ";
80
81 strcpy(buf, trim(none));
82 assert_strcmp(buf, "needs none");
83
84 strcpy(buf, trim(left));
85 assert_strcmp(buf, "needs left");
86
87 strcpy(buf, trim(right));
88 assert_strcmp(buf, "needs right");
89
90 strcpy(buf, trim(both));
91 assert_strcmp(buf, "needs both");
92 }
|