Mon, 22 Aug 2022 22:05:55 -0500
Create PurpleAuthorizationRequest and use it for notifications.
This replaces the old internal representation of authorization requests as well
as the UI's implementation of their own objects. Everything is now controlled
via PurpleAuthorizationRequest and the UI's display the notification for
interaction.
Testing Done:
Verified the notification and actions work in both finch and pidgin.
Reviewed at https://reviews.imfreedom.org/r/1613/
|
38057
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37601
diff
changeset
|
1 | /* |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37601
diff
changeset
|
2 | * purple |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37601
diff
changeset
|
3 | * |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37601
diff
changeset
|
4 | * Purple is the legal property of its developers, whose names are too numerous |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37601
diff
changeset
|
5 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37601
diff
changeset
|
6 | * source distribution. |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37601
diff
changeset
|
7 | * |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37601
diff
changeset
|
8 | * This program is free software; you can redistribute it and/or modify |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37601
diff
changeset
|
9 | * it under the terms of the GNU General Public License as published by |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37601
diff
changeset
|
10 | * the Free Software Foundation; either version 2 of the License, or |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37601
diff
changeset
|
11 | * (at your option) any later version. |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37601
diff
changeset
|
12 | * |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37601
diff
changeset
|
13 | * This program is distributed in the hope that it will be useful, |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37601
diff
changeset
|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37601
diff
changeset
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37601
diff
changeset
|
16 | * GNU General Public License for more details. |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37601
diff
changeset
|
17 | * |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37601
diff
changeset
|
18 | * You should have received a copy of the GNU General Public License |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37601
diff
changeset
|
19 | * along with this program; if not, write to the Free Software |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37601
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37601
diff
changeset
|
21 | * |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37601
diff
changeset
|
22 | */ |
|
37600
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
23 | #include <glib.h> |
|
15950
0f01bb61c5d3
Fix compiler warnings and errors in tests resulting from using DEBUG_CFLAGS
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
24 | |
|
40358
e6fe6fc1f516
move all protocols, purple plugins, and purple tests to use purple.h instead of including files individually
Gary Kramlich <grim@reaperworld.com>
parents:
39987
diff
changeset
|
25 | #include <purple.h> |
| 15104 | 26 | |
|
37600
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
27 | /****************************************************************************** |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
28 | * filename escape tests |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
29 | *****************************************************************************/ |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
30 | static void |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
31 | test_util_filename_escape(void) { |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
32 | g_assert_cmpstr("foo", ==, purple_escape_filename("foo")); |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
33 | g_assert_cmpstr("@oo", ==, purple_escape_filename("@oo")); |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
34 | g_assert_cmpstr("#oo", ==, purple_escape_filename("#oo")); |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
35 | g_assert_cmpstr("-oo", ==, purple_escape_filename("-oo")); |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
36 | g_assert_cmpstr("_oo", ==, purple_escape_filename("_oo")); |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
37 | g_assert_cmpstr(".oo", ==, purple_escape_filename(".oo")); |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
38 | g_assert_cmpstr("%25oo", ==, purple_escape_filename("%oo")); |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
39 | g_assert_cmpstr("%21oo", ==, purple_escape_filename("!oo")); |
| 15104 | 40 | } |
| 41 | ||
|
37600
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
42 | /****************************************************************************** |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
43 | * text_strip tests |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
44 | *****************************************************************************/ |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
45 | static void |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
46 | test_util_text_strip_mnemonic(void) { |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
47 | g_assert_cmpstr("", ==, purple_text_strip_mnemonic("")); |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
48 | g_assert_cmpstr("foo", ==, purple_text_strip_mnemonic("foo")); |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
49 | g_assert_cmpstr("foo", ==, purple_text_strip_mnemonic("_foo")); |
| 15104 | 50 | |
| 51 | } | |
| 52 | ||
|
37600
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
53 | /****************************************************************************** |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
54 | * email tests |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
55 | *****************************************************************************/ |
|
30440
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
56 | /* |
|
30442
a4f304b33d50
Oh, let's put our original test cases in the two arrays, to make things
Mark Doliner <markdoliner@pidgin.im>
parents:
30440
diff
changeset
|
57 | * Many of the valid and invalid email addresses lised below are from |
|
30440
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
58 | * http://fightingforalostcause.net/misc/2006/compare-email-regex.php |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
59 | */ |
|
37600
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
60 | const gchar *valid_emails[] = { |
|
30442
a4f304b33d50
Oh, let's put our original test cases in the two arrays, to make things
Mark Doliner <markdoliner@pidgin.im>
parents:
30440
diff
changeset
|
61 | "purple-devel@lists.sf.net", |
|
30440
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
62 | "l3tt3rsAndNumb3rs@domain.com", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
63 | "has-dash@domain.com", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
64 | "hasApostrophe.o'leary@domain.org", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
65 | "uncommonTLD@domain.museum", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
66 | "uncommonTLD@domain.travel", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
67 | "uncommonTLD@domain.mobi", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
68 | "countryCodeTLD@domain.uk", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
69 | "countryCodeTLD@domain.rw", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
70 | "lettersInDomain@911.com", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
71 | "underscore_inLocal@domain.net", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
72 | "IPInsteadOfDomain@127.0.0.1", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
73 | /* "IPAndPort@127.0.0.1:25", */ |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
74 | "subdomain@sub.domain.com", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
75 | "local@dash-inDomain.com", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
76 | "dot.inLocal@foo.com", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
77 | "a@singleLetterLocal.org", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
78 | "singleLetterDomain@x.org", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
79 | "&*=?^+{}'~@validCharsInLocal.net", |
|
31484
b7cfae50e10c
Add two valid email addresses to this list
Mark Doliner <markdoliner@pidgin.im>
parents:
31232
diff
changeset
|
80 | "foor@bar.newTLD", |
|
b7cfae50e10c
Add two valid email addresses to this list
Mark Doliner <markdoliner@pidgin.im>
parents:
31232
diff
changeset
|
81 | "HenryTheGreatWhiteCricket@live.ca", |
|
b7cfae50e10c
Add two valid email addresses to this list
Mark Doliner <markdoliner@pidgin.im>
parents:
31232
diff
changeset
|
82 | "HenryThe__WhiteCricket@hotmail.com" |
|
30440
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
83 | }; |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
84 | |
|
37600
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
85 | static void |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
86 | test_util_email_is_valid(void) { |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
87 | size_t i; |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
88 | |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
89 | for (i = 0; i < G_N_ELEMENTS(valid_emails); i++) |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
90 | g_assert_true(purple_email_is_valid(valid_emails[i])); |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
91 | } |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
92 | |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
93 | const gchar *invalid_emails[] = { |
|
30442
a4f304b33d50
Oh, let's put our original test cases in the two arrays, to make things
Mark Doliner <markdoliner@pidgin.im>
parents:
30440
diff
changeset
|
94 | "purple-devel@@lists.sf.net", |
|
a4f304b33d50
Oh, let's put our original test cases in the two arrays, to make things
Mark Doliner <markdoliner@pidgin.im>
parents:
30440
diff
changeset
|
95 | "purple@devel@lists.sf.net", |
|
a4f304b33d50
Oh, let's put our original test cases in the two arrays, to make things
Mark Doliner <markdoliner@pidgin.im>
parents:
30440
diff
changeset
|
96 | "purple-devel@list..sf.net", |
|
a4f304b33d50
Oh, let's put our original test cases in the two arrays, to make things
Mark Doliner <markdoliner@pidgin.im>
parents:
30440
diff
changeset
|
97 | "purple-devel", |
|
a4f304b33d50
Oh, let's put our original test cases in the two arrays, to make things
Mark Doliner <markdoliner@pidgin.im>
parents:
30440
diff
changeset
|
98 | "purple-devel@", |
|
a4f304b33d50
Oh, let's put our original test cases in the two arrays, to make things
Mark Doliner <markdoliner@pidgin.im>
parents:
30440
diff
changeset
|
99 | "@lists.sf.net", |
|
a4f304b33d50
Oh, let's put our original test cases in the two arrays, to make things
Mark Doliner <markdoliner@pidgin.im>
parents:
30440
diff
changeset
|
100 | "totally bogus", |
|
30440
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
101 | "missingDomain@.com", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
102 | "@missingLocal.org", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
103 | "missingatSign.net", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
104 | "missingDot@com", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
105 | "two@@signs.com", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
106 | "colonButNoPort@127.0.0.1:", |
|
36049
bffbd724134d
Fix CWE-252 coverity issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35297
diff
changeset
|
107 | "", |
|
30440
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
108 | /* "someone-else@127.0.0.1.26", */ |
|
30444
d871c3fd6637
Catch some more invalid email addresses, thanks to Mark for additional
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
30442
diff
changeset
|
109 | ".localStartsWithDot@domain.com", |
|
d871c3fd6637
Catch some more invalid email addresses, thanks to Mark for additional
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
30442
diff
changeset
|
110 | /* "localEndsWithDot.@domain.com", */ /* I don't think this is invalid -- Stu */ |
|
d871c3fd6637
Catch some more invalid email addresses, thanks to Mark for additional
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
30442
diff
changeset
|
111 | /* "two..consecutiveDots@domain.com", */ /* I don't think this is invalid -- Stu */ |
|
d871c3fd6637
Catch some more invalid email addresses, thanks to Mark for additional
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
30442
diff
changeset
|
112 | "domainStartsWithDash@-domain.com", |
|
30440
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
113 | "domainEndsWithDash@domain-.com", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
114 | /* "numbersInTLD@domain.c0m", */ |
|
30444
d871c3fd6637
Catch some more invalid email addresses, thanks to Mark for additional
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
30442
diff
changeset
|
115 | /* "missingTLD@domain.", */ /* This certainly isn't invalid -- Stu */ |
|
30440
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
116 | "! \"#$%(),/;<>[]`|@invalidCharsInLocal.org", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
117 | "invalidCharsInDomain@! \"#$%(),/;<>_[]`|.org", |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
118 | /* "local@SecondLevelDomainNamesAreInvalidIfTheyAreLongerThan64Charactersss.org" */ |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
119 | }; |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
120 | |
|
37600
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
121 | static void |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
122 | test_util_email_is_invalid(void) { |
|
30440
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
123 | size_t i; |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
124 | |
|
4ec59d547bff
Expand our test for purple_email_is_valid(). I stumbled across a large list
Mark Doliner <markdoliner@pidgin.im>
parents:
30149
diff
changeset
|
125 | for (i = 0; i < G_N_ELEMENTS(invalid_emails); i++) |
|
37600
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
126 | g_assert_false(purple_email_is_valid(invalid_emails[i])); |
| 15104 | 127 | } |
|
37600
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
128 | |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
129 | /****************************************************************************** |
|
37601
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
130 | * UTF8 tests |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
131 | *****************************************************************************/ |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
132 | typedef struct { |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
133 | gchar *input; |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
134 | gchar *output; |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
135 | } UTF8TestData; |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
136 | |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
137 | static void |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
138 | test_util_utf8_strip_unprintables(void) { |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
139 | gint i; |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
140 | UTF8TestData data[] = { |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
141 | { |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
142 | /* \t, \n, \r, space */ |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
143 | "ab \tcd\nef\r ", |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
144 | "ab \tcd\nef\r ", |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
145 | }, { |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
146 | /* ASCII control characters (stripped) */ |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
147 | "\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x0E\x0F\x10 aaaa " |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
148 | "\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F", |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
149 | " aaaa ", |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
150 | }, { |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
151 | /* Basic ASCII */ |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
152 | "Foobar", |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
153 | "Foobar", |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
154 | }, { |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
155 | /* 0xE000 - 0xFFFD (UTF-8 encoded) */ |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
156 | /* U+F1F7 */ |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
157 | "aaaa\xef\x87\xb7", |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
158 | "aaaa\xef\x87\xb7", |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
159 | }, { |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
160 | /* U+FEFF (should not be stripped) */ |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
161 | "aaaa\xef\xbb\xbf", |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
162 | "aaaa\xef\xbb\xbf", |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
163 | }, { |
|
38813
9506fb3fe6a2
Remove #if 0's from libpurple
Gary Kramlich <grim@reaperworld.com>
parents:
38748
diff
changeset
|
164 | /* U+FFFE (should be stripped) */ |
|
9506fb3fe6a2
Remove #if 0's from libpurple
Gary Kramlich <grim@reaperworld.com>
parents:
38748
diff
changeset
|
165 | "aaaa\xef\xbf\xbe", |
|
9506fb3fe6a2
Remove #if 0's from libpurple
Gary Kramlich <grim@reaperworld.com>
parents:
38748
diff
changeset
|
166 | "aaaa", |
|
9506fb3fe6a2
Remove #if 0's from libpurple
Gary Kramlich <grim@reaperworld.com>
parents:
38748
diff
changeset
|
167 | }, { |
|
37601
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
168 | NULL, |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
169 | NULL, |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
170 | } |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
171 | }; |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
172 | |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
173 | for(i = 0; ; i++) { |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
174 | gchar *result = purple_utf8_strip_unprintables(data[i].input); |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
175 | |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
176 | g_assert_cmpstr(data[i].output, ==, result); |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
177 | |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
178 | g_free(result); |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
179 | |
|
38813
9506fb3fe6a2
Remove #if 0's from libpurple
Gary Kramlich <grim@reaperworld.com>
parents:
38748
diff
changeset
|
180 | /* NULL as input is a valid test, but it's the last test, so we break |
|
9506fb3fe6a2
Remove #if 0's from libpurple
Gary Kramlich <grim@reaperworld.com>
parents:
38748
diff
changeset
|
181 | * after it. |
|
9506fb3fe6a2
Remove #if 0's from libpurple
Gary Kramlich <grim@reaperworld.com>
parents:
38748
diff
changeset
|
182 | */ |
|
37601
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
183 | if(data[i].input == NULL) |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
184 | break; |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
185 | } |
|
30143
468e3b69fd10
util: Better validation of the allowed character values in XML 1.0
Paul Aurich <darkrain42@pidgin.im>
parents:
29227
diff
changeset
|
186 | } |
|
468e3b69fd10
util: Better validation of the allowed character values in XML 1.0
Paul Aurich <darkrain42@pidgin.im>
parents:
29227
diff
changeset
|
187 | |
|
37601
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
188 | /****************************************************************************** |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
189 | * strdup_withhtml tests |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
190 | *****************************************************************************/ |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
191 | static void |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
192 | test_util_strdup_withhtml(void) { |
|
32014
daedb1559529
A unit test check from the EFF
Mark Doliner <markdoliner@pidgin.im>
parents:
31484
diff
changeset
|
193 | gchar *result = purple_strdup_withhtml("hi\r\nthere\n"); |
|
37601
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
194 | |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
195 | g_assert_cmpstr("hi<BR>there<BR>", ==, result); |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
196 | |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
197 | g_free(result); |
|
32014
daedb1559529
A unit test check from the EFF
Mark Doliner <markdoliner@pidgin.im>
parents:
31484
diff
changeset
|
198 | } |
|
daedb1559529
A unit test check from the EFF
Mark Doliner <markdoliner@pidgin.im>
parents:
31484
diff
changeset
|
199 | |
|
37601
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
200 | /****************************************************************************** |
| 38748 | 201 | * URI Escaping |
| 202 | *****************************************************************************/ | |
| 203 | static void | |
| 204 | test_uri_escape_for_open(void) { | |
|
38737
d85c241e3183
Add unit tests for xdg-open URI escaping
Daniel Kamil Kozar <dkk089@gmail.com>
parents:
35181
diff
changeset
|
205 | /* make sure shell stuff is escaped... */ |
|
d85c241e3183
Add unit tests for xdg-open URI escaping
Daniel Kamil Kozar <dkk089@gmail.com>
parents:
35181
diff
changeset
|
206 | gchar *result = purple_uri_escape_for_open("https://$(xterm)"); |
| 38748 | 207 | g_assert_cmpstr("https://%24%28xterm%29", ==, result); |
| 208 | g_free(result); | |
|
38737
d85c241e3183
Add unit tests for xdg-open URI escaping
Daniel Kamil Kozar <dkk089@gmail.com>
parents:
35181
diff
changeset
|
209 | |
|
d85c241e3183
Add unit tests for xdg-open URI escaping
Daniel Kamil Kozar <dkk089@gmail.com>
parents:
35181
diff
changeset
|
210 | result = purple_uri_escape_for_open("https://`xterm`"); |
| 38748 | 211 | g_assert_cmpstr("https://%60xterm%60", ==, result); |
| 212 | g_free(result); | |
|
38737
d85c241e3183
Add unit tests for xdg-open URI escaping
Daniel Kamil Kozar <dkk089@gmail.com>
parents:
35181
diff
changeset
|
213 | |
|
d85c241e3183
Add unit tests for xdg-open URI escaping
Daniel Kamil Kozar <dkk089@gmail.com>
parents:
35181
diff
changeset
|
214 | result = purple_uri_escape_for_open("https://$((25 + 13))"); |
| 38748 | 215 | g_assert_cmpstr("https://%24%28%2825%20+%2013%29%29", ==, result); |
| 216 | g_free(result); | |
|
38737
d85c241e3183
Add unit tests for xdg-open URI escaping
Daniel Kamil Kozar <dkk089@gmail.com>
parents:
35181
diff
changeset
|
217 | |
|
d85c241e3183
Add unit tests for xdg-open URI escaping
Daniel Kamil Kozar <dkk089@gmail.com>
parents:
35181
diff
changeset
|
218 | /* ...but keep brackets so that ipv6 links can be opened. */ |
|
d85c241e3183
Add unit tests for xdg-open URI escaping
Daniel Kamil Kozar <dkk089@gmail.com>
parents:
35181
diff
changeset
|
219 | result = purple_uri_escape_for_open("https://[123:4567:89a::::]"); |
| 38748 | 220 | g_assert_cmpstr("https://[123:4567:89a::::]", ==, result); |
| 221 | g_free(result); | |
|
38737
d85c241e3183
Add unit tests for xdg-open URI escaping
Daniel Kamil Kozar <dkk089@gmail.com>
parents:
35181
diff
changeset
|
222 | } |
|
d85c241e3183
Add unit tests for xdg-open URI escaping
Daniel Kamil Kozar <dkk089@gmail.com>
parents:
35181
diff
changeset
|
223 | |
| 38748 | 224 | /****************************************************************************** |
|
37601
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
225 | * MANE |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
226 | *****************************************************************************/ |
|
37600
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
227 | gint |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
228 | main(gint argc, gchar **argv) { |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
229 | g_test_init(&argc, &argv, NULL); |
| 15104 | 230 | |
|
37600
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
231 | g_test_add_func("/util/filename/escape", |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
232 | test_util_filename_escape); |
| 15104 | 233 | |
|
37600
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
234 | g_test_add_func("/util/mnemonic/strip", |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
235 | test_util_text_strip_mnemonic); |
| 15104 | 236 | |
|
37600
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
237 | g_test_add_func("/util/email/is valid", |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
238 | test_util_email_is_valid); |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
239 | g_test_add_func("/util/email/is invalid", |
|
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
240 | test_util_email_is_invalid); |
| 15104 | 241 | |
|
37601
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
242 | g_test_add_func("/util/utf8/strip unprintables", |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
243 | test_util_utf8_strip_unprintables); |
|
30143
468e3b69fd10
util: Better validation of the allowed character values in XML 1.0
Paul Aurich <darkrain42@pidgin.im>
parents:
29227
diff
changeset
|
244 | |
|
37601
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
245 | g_test_add_func("/util/test_strdup_withhtml", |
|
bf18c71d8508
Finish up the util unit tests
Gary Kramlich <grim@reaperworld.com>
parents:
37600
diff
changeset
|
246 | test_util_strdup_withhtml); |
|
32014
daedb1559529
A unit test check from the EFF
Mark Doliner <markdoliner@pidgin.im>
parents:
31484
diff
changeset
|
247 | |
| 38748 | 248 | g_test_add_func("/util/test_uri_escape_for_open", |
| 249 | test_uri_escape_for_open); | |
|
38737
d85c241e3183
Add unit tests for xdg-open URI escaping
Daniel Kamil Kozar <dkk089@gmail.com>
parents:
35181
diff
changeset
|
250 | |
|
37600
fce4d896285e
Add a bunch of util tests
Gary Kramlich <grim@reaperworld.com>
parents:
36049
diff
changeset
|
251 | return g_test_run(); |
| 15104 | 252 | } |