| |
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 "../purpleircv3source.h" |
| |
24 |
| |
25 /****************************************************************************** |
| |
26 * Tests |
| |
27 *****************************************************************************/ |
| |
28 static void |
| |
29 test_ircv3_source_parse_return_address_required(void) { |
| |
30 if(g_test_subprocess()) { |
| |
31 purple_ircv3_source_parse("pidgy", NULL, NULL, NULL); |
| |
32 } |
| |
33 |
| |
34 g_test_trap_subprocess(NULL, 0, G_TEST_SUBPROCESS_DEFAULT); |
| |
35 g_test_trap_assert_stderr("*nick != NULL || user != NULL || host != NULL' failed*"); |
| |
36 } |
| |
37 |
| |
38 static void |
| |
39 test_ircv3_source_parse_nick(void) { |
| |
40 char *nick = NULL; |
| |
41 char *user = NULL; |
| |
42 char *host = NULL; |
| |
43 |
| |
44 /* Once to make sure that user and host are null. */ |
| |
45 purple_ircv3_source_parse("pidgy", &nick, &user, &host); |
| |
46 g_assert_cmpstr(nick, ==, "pidgy"); |
| |
47 g_clear_pointer(&nick, g_free); |
| |
48 |
| |
49 g_assert_null(user); |
| |
50 g_assert_null(host); |
| |
51 |
| |
52 /* Again to make sure it works without user and host. */ |
| |
53 purple_ircv3_source_parse("pidgy", &nick, NULL, NULL); |
| |
54 g_assert_cmpstr(nick, ==, "pidgy"); |
| |
55 g_clear_pointer(&nick, g_free); |
| |
56 } |
| |
57 |
| |
58 static void |
| |
59 test_ircv3_source_parse_user(void) { |
| |
60 char *nick = NULL; |
| |
61 char *user = NULL; |
| |
62 char *host = NULL; |
| |
63 |
| |
64 /* Once to make sure host is null. */ |
| |
65 purple_ircv3_source_parse("pidgy!~u", &nick, &user, &host); |
| |
66 g_assert_cmpstr(nick, ==, "pidgy"); |
| |
67 g_clear_pointer(&nick, g_free); |
| |
68 |
| |
69 g_assert_cmpstr(user, ==, "~u"); |
| |
70 g_clear_pointer(&user, g_free); |
| |
71 |
| |
72 g_assert_null(host); |
| |
73 |
| |
74 /* Again to make sure nick and host aren't required. */ |
| |
75 purple_ircv3_source_parse("pidgy!~u", NULL, &user, NULL); |
| |
76 g_assert_cmpstr(user, ==, "~u"); |
| |
77 g_clear_pointer(&user, g_free); |
| |
78 } |
| |
79 |
| |
80 static void |
| |
81 test_ircv3_source_parse_host(void) { |
| |
82 char *nick = NULL; |
| |
83 char *user = NULL; |
| |
84 char *host = NULL; |
| |
85 |
| |
86 /* Once to make sure everything works. */ |
| |
87 purple_ircv3_source_parse("pidgy!~u@53unc8n42i868.irc", &nick, &user, |
| |
88 &host); |
| |
89 g_assert_cmpstr(nick, ==, "pidgy"); |
| |
90 g_clear_pointer(&nick, g_free); |
| |
91 |
| |
92 g_assert_cmpstr(user, ==, "~u"); |
| |
93 g_clear_pointer(&user, g_free); |
| |
94 |
| |
95 g_assert_cmpstr(host, ==, "53unc8n42i868.irc"); |
| |
96 g_clear_pointer(&host, g_free); |
| |
97 |
| |
98 /* Again to make sure nick and host aren't required. */ |
| |
99 purple_ircv3_source_parse("pidgy!~u@53unc8n42i868.irc", NULL, NULL, &host); |
| |
100 g_assert_cmpstr(host, ==, "53unc8n42i868.irc"); |
| |
101 g_clear_pointer(&host, g_free); |
| |
102 } |
| |
103 |
| |
104 static void |
| |
105 test_ircv3_source_parse_baddies(void) { |
| |
106 char *nick = NULL; |
| |
107 char *user = NULL; |
| |
108 char *server = NULL; |
| |
109 |
| |
110 purple_ircv3_source_parse("\n", &nick, NULL, NULL); |
| |
111 g_assert_null(nick); |
| |
112 |
| |
113 purple_ircv3_source_parse("a\nb", &nick, NULL, NULL); |
| |
114 g_assert_null(nick); |
| |
115 |
| |
116 purple_ircv3_source_parse("\r", &nick, NULL, NULL); |
| |
117 g_assert_null(nick); |
| |
118 |
| |
119 purple_ircv3_source_parse("c\rd", &nick, NULL, NULL); |
| |
120 g_assert_null(nick); |
| |
121 |
| |
122 purple_ircv3_source_parse(" ", &nick, NULL, NULL); |
| |
123 g_assert_null(nick); |
| |
124 |
| |
125 purple_ircv3_source_parse("e f", &nick, NULL, NULL); |
| |
126 g_assert_null(nick); |
| |
127 |
| |
128 purple_ircv3_source_parse("nick@foo!user@server", &nick, &user, &server); |
| |
129 g_assert_cmpstr(nick, ==, "nick@foo"); |
| |
130 g_clear_pointer(&nick, g_free); |
| |
131 g_assert_cmpstr(user, ==, "user"); |
| |
132 g_clear_pointer(&user, g_free); |
| |
133 g_assert_cmpstr(server, ==, "server"); |
| |
134 g_clear_pointer(&server, g_free); |
| |
135 |
| |
136 purple_ircv3_source_parse("nick!user@server!foo", &nick, &user, &server); |
| |
137 g_assert_cmpstr(nick, ==, "nick!user@server!foo"); |
| |
138 g_assert_null(user); |
| |
139 g_assert_null(server); |
| |
140 } |
| |
141 |
| |
142 /****************************************************************************** |
| |
143 * Main |
| |
144 *****************************************************************************/ |
| |
145 int |
| |
146 main(int argc, char *argv[]) { |
| |
147 g_test_init(&argc, &argv, NULL); |
| |
148 |
| |
149 g_test_add_func("/ircv3/source/parse/return-address-required", |
| |
150 test_ircv3_source_parse_return_address_required); |
| |
151 g_test_add_func("/ircv3/source/parse/nick", test_ircv3_source_parse_nick); |
| |
152 g_test_add_func("/ircv3/source/parse/user", test_ircv3_source_parse_user); |
| |
153 g_test_add_func("/ircv3/source/parse/host", test_ircv3_source_parse_host); |
| |
154 g_test_add_func("/ircv3/source/parse/baddies", |
| |
155 test_ircv3_source_parse_baddies); |
| |
156 |
| |
157 return g_test_run(); |
| |
158 } |