libpurple/protocols/ircv3/tests/test_ircv3_formatting.c

changeset 42505
cc095f9ce1f3
equal deleted inserted replaced
42504:02c38caf387b 42505:cc095f9ce1f3
1 /*
2 * Purple - Internet Messaging Library
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library 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 GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
17 */
18
19 #include <glib.h>
20
21 #include <purple.h>
22
23 #include "../purpleircv3formatting.h"
24
25 /******************************************************************************
26 * Strip Tests
27 *****************************************************************************/
28 static void
29 test_ircv3_formatting_strip(const char *input, const char *expected) {
30 char *actual = NULL;
31
32 actual = purple_ircv3_formatting_strip(input);
33 g_assert_cmpstr(actual, ==, expected);
34 g_clear_pointer(&actual, g_free);
35 }
36
37 static void
38 test_ircv3_formatting_strip_null(void) {
39 test_ircv3_formatting_strip(NULL, NULL);
40 }
41
42 static void
43 test_ircv3_formatting_strip_empty(void) {
44 test_ircv3_formatting_strip("", "");
45 }
46
47 static void
48 test_ircv3_formatting_strip_color_comma(void) {
49 test_ircv3_formatting_strip("\003,", ",");
50 }
51
52 static void
53 test_ircv3_formatting_strip_color_foreground_comma(void) {
54 test_ircv3_formatting_strip("\0033,", ",");
55 }
56
57 static void
58 test_ircv3_formatting_strip_color_full(void) {
59 test_ircv3_formatting_strip("\0033,9wee", "wee");
60 }
61
62 static void
63 test_ircv3_formatting_strip_color_foreground_3_digit(void) {
64 test_ircv3_formatting_strip("\003314", "4");
65 }
66
67 static void
68 test_ircv3_formatting_strip_color_background_3_digit(void) {
69 test_ircv3_formatting_strip("\0031,234", "4");
70 }
71
72 static void
73 test_ircv3_formatting_strip_hex_color(void) {
74 test_ircv3_formatting_strip("\004FF00FFwoo!", "woo!");
75 }
76
77 static void
78 test_ircv3_formatting_strip_hex_color_full(void) {
79 test_ircv3_formatting_strip("\004FF00FF,00FF00woo!", "woo!");
80 }
81
82 static void
83 test_ircv3_formatting_strip_hex_color_comma(void) {
84 test_ircv3_formatting_strip("\004,", ",");
85 }
86
87 static void
88 test_ircv3_formatting_strip_hex_color_foreground_comma(void) {
89 test_ircv3_formatting_strip("\004FEFEFE,", ",");
90 }
91
92 static void
93 test_ircv3_formatting_strip_hex_color_foreground_7_characters(void) {
94 test_ircv3_formatting_strip("\004FEFEFEF", "F");
95 }
96
97 static void
98 test_ircv3_formatting_strip_hex_color_background_7_characters(void) {
99 test_ircv3_formatting_strip("\004FEFEFE,2222223", "3");
100 }
101
102 static void
103 test_ircv3_formatting_strip_bold(void) {
104 test_ircv3_formatting_strip("this is \002bold\002!", "this is bold!");
105 }
106
107 static void
108 test_ircv3_formatting_strip_italic(void) {
109 test_ircv3_formatting_strip("what do you \035mean\035?!",
110 "what do you mean?!");
111 }
112
113 static void
114 test_ircv3_formatting_strip_monospace(void) {
115 test_ircv3_formatting_strip("\021i++;\021", "i++;");
116 }
117
118 static void
119 test_ircv3_formatting_strip_reset(void) {
120 test_ircv3_formatting_strip("end of formatting\017", "end of formatting");
121 }
122
123 static void
124 test_ircv3_formatting_strip_reverse(void) {
125 test_ircv3_formatting_strip("re\026ver\026se", "reverse");
126 }
127
128 static void
129 test_ircv3_formatting_strip_strikethrough(void) {
130 test_ircv3_formatting_strip("\036I could be wrong\036",
131 "I could be wrong");
132 }
133
134 static void
135 test_ircv3_formatting_strip_underline(void) {
136 test_ircv3_formatting_strip("You can't handle the \037truth\037!",
137 "You can't handle the truth!");
138 }
139
140 static void
141 test_ircv3_formatting_strip_spec_example1(void) {
142 test_ircv3_formatting_strip(
143 "I love \0033IRC! \003It is the \0037best protocol ever!",
144 "I love IRC! It is the best protocol ever!");
145 }
146
147 static void
148 test_ircv3_formatting_strip_spec_example2(void) {
149 test_ircv3_formatting_strip(
150 "This is a \035\00313,9cool \003message",
151 "This is a cool message");
152 }
153
154 static void
155 test_ircv3_formatting_strip_spec_example3(void) {
156 test_ircv3_formatting_strip(
157 "IRC \002is \0034,12so \003great\017!",
158 "IRC is so great!");
159 }
160
161 static void
162 test_ircv3_formatting_strip_spec_example4(void) {
163 test_ircv3_formatting_strip(
164 "Rules: Don't spam 5\00313,8,6\003,7,8, and especially not \0029\002\035!",
165 "Rules: Don't spam 5,6,7,8, and especially not 9!");
166 }
167
168 /******************************************************************************
169 * Main
170 *****************************************************************************/
171 int
172 main(int argc, char *argv[]) {
173 g_test_init(&argc, &argv, NULL);
174
175 g_test_add_func("/ircv3/formatting/strip/null",
176 test_ircv3_formatting_strip_null);
177 g_test_add_func("/ircv3/formatting/strip/empty",
178 test_ircv3_formatting_strip_empty);
179
180 g_test_add_func("/ircv3/formatting/strip/color-comma",
181 test_ircv3_formatting_strip_color_comma);
182 g_test_add_func("/ircv3/formatting/strip/color-full",
183 test_ircv3_formatting_strip_color_full);
184 g_test_add_func("/ircv3/formatting/strip/color-foreground-comma",
185 test_ircv3_formatting_strip_color_foreground_comma);
186 g_test_add_func("/ircv3/formatting/strip/color-foreground-3-digit",
187 test_ircv3_formatting_strip_color_foreground_3_digit);
188 g_test_add_func("/ircv3/formatting/strip/color-background-3-digit",
189 test_ircv3_formatting_strip_color_background_3_digit);
190
191 g_test_add_func("/ircv3/formatting/strip/hex-color",
192 test_ircv3_formatting_strip_hex_color);
193 g_test_add_func("/ircv3/formatting/strip/hex-color-full",
194 test_ircv3_formatting_strip_hex_color_full);
195 g_test_add_func("/ircv3/formatting/strip/hex-color-comma",
196 test_ircv3_formatting_strip_hex_color_comma);
197 g_test_add_func("/ircv3/formatting/strip/hex-color-foreground-comma",
198 test_ircv3_formatting_strip_hex_color_foreground_comma);
199 g_test_add_func("/ircv3/formatting/strip/hex-color-foreground-7-characters",
200 test_ircv3_formatting_strip_hex_color_foreground_7_characters);
201 g_test_add_func("/ircv3/formatting/strip/hex-color-background-7-characters",
202 test_ircv3_formatting_strip_hex_color_background_7_characters);
203
204 g_test_add_func("/ircv3/formatting/strip/bold",
205 test_ircv3_formatting_strip_bold);
206 g_test_add_func("/ircv3/formatting/strip/italic",
207 test_ircv3_formatting_strip_italic);
208 g_test_add_func("/ircv3/formatting/strip/monospace",
209 test_ircv3_formatting_strip_monospace);
210 g_test_add_func("/ircv3/formatting/strip/reset",
211 test_ircv3_formatting_strip_reset);
212 g_test_add_func("/ircv3/formatting/strip/reverse",
213 test_ircv3_formatting_strip_reverse);
214 g_test_add_func("/ircv3/formatting/strip/strikethrough",
215 test_ircv3_formatting_strip_strikethrough);
216 g_test_add_func("/ircv3/formatting/strip/underline",
217 test_ircv3_formatting_strip_underline);
218
219 /* These tests are based on the examples here
220 * https://modern.ircdocs.horse/formatting.html#examples
221 */
222 g_test_add_func("/ircv3/formatting/strip/spec-example1",
223 test_ircv3_formatting_strip_spec_example1);
224 g_test_add_func("/ircv3/formatting/strip/spec-example2",
225 test_ircv3_formatting_strip_spec_example2);
226 g_test_add_func("/ircv3/formatting/strip/spec-example3",
227 test_ircv3_formatting_strip_spec_example3);
228 g_test_add_func("/ircv3/formatting/strip/spec-example4",
229 test_ircv3_formatting_strip_spec_example4);
230
231 return g_test_run();
232 }

mercurial