Fri, 17 Feb 2023 19:32:38 -0600
Add search support to the contact list
This searches everything in `PurplePerson` and all of it's contacts, but does not yet cover tags. I am planning on covering that in another review request.
Right now the matching is just using `strstr`, but will will update this as part of [PIDGIN-17737](https://issues.imfreedom.org/issue/PIDGIN-17737/).
I also tried to figure out how to get focus back to the list view, but didn't come up with any viable solutions.
Testing Done:
Ran the unit tests and did a bunch of searches in the contact list with the demo protocol plugin.
Bugs closed: PIDGIN-17717
Reviewed at https://reviews.imfreedom.org/r/2211/
| 41749 | 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 "test_ui.h" | |
| 24 | ||
| 25 | /****************************************************************************** | |
| 26 | * Callbacks | |
| 27 | *****************************************************************************/ | |
| 28 | static void | |
| 29 | test_purple_person_items_changed_cb(G_GNUC_UNUSED GListModel *model, | |
| 30 | G_GNUC_UNUSED guint position, | |
| 31 | G_GNUC_UNUSED guint removed, | |
| 32 | G_GNUC_UNUSED guint added, | |
| 33 | gpointer data) | |
| 34 | { | |
| 35 | gboolean *called = data; | |
| 36 | ||
| 37 | *called = TRUE; | |
| 38 | } | |
| 39 | ||
| 40 | static void | |
| 41 | test_purple_person_notify_cb(G_GNUC_UNUSED GObject *obj, | |
| 42 | G_GNUC_UNUSED GParamSpec *pspec, | |
| 43 | gpointer data) | |
| 44 | { | |
| 45 | gboolean *called = data; | |
| 46 | ||
| 47 | *called = TRUE; | |
| 48 | } | |
| 49 | ||
| 50 | /****************************************************************************** | |
| 51 | * Tests | |
| 52 | *****************************************************************************/ | |
| 53 | static void | |
| 54 | test_purple_person_new(void) { | |
| 55 | PurplePerson *person = NULL; | |
| 56 | ||
| 57 | person = purple_person_new(); | |
| 58 | ||
| 59 | g_assert_true(PURPLE_IS_PERSON(person)); | |
| 60 | ||
| 61 | g_clear_object(&person); | |
| 62 | } | |
| 63 | ||
| 64 | static void | |
| 65 | test_purple_person_properties(void) { | |
| 66 | PurpleContact *person = NULL; | |
| 67 | PurpleTags *tags = NULL; | |
| 68 | GdkPixbuf *avatar = NULL; | |
| 69 | GdkPixbuf *avatar1 = NULL; | |
|
42054
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
70 | GdkPixbuf *avatar_for_display = NULL; |
|
42053
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
71 | char *id = NULL; |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
72 | char *alias = NULL; |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
73 | char *name_for_display = NULL; |
| 41749 | 74 | |
| 75 | /* Create our avatar for testing. */ | |
| 76 | avatar = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 1, 1); | |
| 77 | ||
| 78 | /* Use g_object_new so we can test setting properties by name. All of them | |
| 79 | * call the setter methods, so by doing it this way we exercise more of the | |
| 80 | * code. | |
| 81 | */ | |
| 82 | person = g_object_new( | |
| 83 | PURPLE_TYPE_PERSON, | |
| 84 | "alias", "alias", | |
| 85 | "avatar", avatar, | |
| 86 | NULL); | |
| 87 | ||
| 88 | /* Now use g_object_get to read all of the properties. */ | |
| 89 | g_object_get(person, | |
| 90 | "id", &id, | |
| 91 | "alias", &alias, | |
| 92 | "avatar", &avatar1, | |
|
42054
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
93 | "avatar-for-display", &avatar_for_display, |
|
42053
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
94 | "name-for-display", &name_for_display, |
| 41749 | 95 | "tags", &tags, |
| 96 | NULL); | |
| 97 | ||
| 98 | /* Compare all the things. */ | |
| 99 | g_assert_nonnull(id); | |
| 100 | g_assert_cmpstr(alias, ==, "alias"); | |
| 101 | g_assert_true(avatar1 == avatar); | |
|
42054
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
102 | g_assert_true(avatar1 == avatar_for_display); |
|
42053
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
103 | g_assert_cmpstr(name_for_display, ==, "alias"); |
| 41749 | 104 | g_assert_nonnull(tags); |
| 105 | ||
| 106 | /* Free/unref all the things. */ | |
| 107 | g_clear_pointer(&id, g_free); | |
| 108 | g_clear_pointer(&alias, g_free); | |
| 109 | g_clear_object(&avatar1); | |
|
42054
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
110 | g_clear_object(&avatar_for_display); |
|
42053
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
111 | g_clear_pointer(&name_for_display, g_free); |
| 41749 | 112 | g_clear_object(&tags); |
| 113 | ||
| 114 | g_clear_object(&avatar); | |
| 115 | g_clear_object(&person); | |
| 116 | } | |
| 117 | ||
| 118 | static void | |
|
42054
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
119 | test_purple_person_avatar_for_display_person(void) { |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
120 | PurpleContactInfo *info = NULL; |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
121 | PurplePerson *person = NULL; |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
122 | GdkPixbuf *avatar = NULL; |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
123 | |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
124 | person = purple_person_new(); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
125 | avatar = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 1, 1); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
126 | purple_person_set_avatar(person, avatar); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
127 | |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
128 | info = purple_contact_info_new("id"); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
129 | purple_person_add_contact_info(person, info); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
130 | |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
131 | /* Make sure the person's alias is overriding the contact info. */ |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
132 | g_assert_true(purple_person_get_avatar_for_display(person) == avatar); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
133 | |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
134 | g_clear_object(&info); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
135 | g_clear_object(&person); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
136 | g_clear_object(&avatar); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
137 | } |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
138 | |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
139 | static void |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
140 | test_purple_person_avatar_for_display_contact(void) { |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
141 | PurpleContactInfo *info = NULL; |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
142 | PurplePerson *person = NULL; |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
143 | GdkPixbuf *avatar = NULL; |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
144 | |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
145 | person = purple_person_new(); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
146 | |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
147 | info = purple_contact_info_new("id"); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
148 | avatar = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 1, 1); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
149 | purple_contact_info_set_avatar(info, avatar); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
150 | purple_person_add_contact_info(person, info); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
151 | |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
152 | /* Make sure the person's alias is overriding the contact info. */ |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
153 | g_assert_true(purple_person_get_avatar_for_display(person) == avatar); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
154 | |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
155 | g_clear_object(&info); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
156 | g_clear_object(&person); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
157 | g_clear_object(&avatar); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
158 | } |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
159 | |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
160 | static void |
|
42053
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
161 | test_purple_person_name_for_display_person(void) { |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
162 | PurpleContactInfo *info = NULL; |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
163 | PurplePerson *person = NULL; |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
164 | |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
165 | person = purple_person_new(); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
166 | purple_person_set_alias(person, "person-alias"); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
167 | |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
168 | info = purple_contact_info_new("id"); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
169 | purple_person_add_contact_info(person, info); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
170 | |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
171 | /* Make sure the person's alias is overriding the contact info. */ |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
172 | g_assert_cmpstr(purple_person_get_name_for_display(person), ==, |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
173 | "person-alias"); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
174 | |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
175 | g_clear_object(&info); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
176 | g_clear_object(&person); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
177 | } |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
178 | |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
179 | static void |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
180 | test_purple_person_name_for_display_contact(void) { |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
181 | PurpleContactInfo *info = NULL; |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
182 | PurplePerson *person = NULL; |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
183 | |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
184 | person = purple_person_new(); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
185 | |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
186 | info = purple_contact_info_new("id"); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
187 | purple_person_add_contact_info(person, info); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
188 | |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
189 | /* Make sure the contact info's name for display is called when the |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
190 | * person's alias is unset. |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
191 | */ |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
192 | g_assert_cmpstr(purple_person_get_name_for_display(person), ==, "id"); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
193 | |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
194 | g_clear_object(&info); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
195 | g_clear_object(&person); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
196 | } |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
197 | |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
198 | static void |
| 41749 | 199 | test_purple_person_contacts_single(void) { |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
200 | PurpleContactInfo *info = NULL; |
| 41749 | 201 | PurplePerson *person = NULL; |
|
41761
9dc5d28fca99
When a Contact is added to a Person set the Contact's Person to that Person.
Gary Kramlich <grim@reaperworld.com>
parents:
41749
diff
changeset
|
202 | PurplePerson *person1 = NULL; |
| 41749 | 203 | guint n_items = 0; |
| 204 | gboolean removed = FALSE; | |
| 205 | gboolean changed = FALSE; | |
| 206 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
207 | info = purple_contact_info_new("id"); |
| 41749 | 208 | person = purple_person_new(); |
| 209 | g_signal_connect(person, "items-changed", | |
| 210 | G_CALLBACK(test_purple_person_items_changed_cb), &changed); | |
| 211 | ||
| 212 | n_items = g_list_model_get_n_items(G_LIST_MODEL(person)); | |
| 213 | g_assert_cmpuint(n_items, ==, 0); | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
214 | purple_person_add_contact_info(person, info); |
| 41749 | 215 | n_items = g_list_model_get_n_items(G_LIST_MODEL(person)); |
| 216 | g_assert_cmpuint(n_items, ==, 1); | |
| 217 | g_assert_true(changed); | |
| 218 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
219 | person1 = purple_contact_info_get_person(info); |
|
41761
9dc5d28fca99
When a Contact is added to a Person set the Contact's Person to that Person.
Gary Kramlich <grim@reaperworld.com>
parents:
41749
diff
changeset
|
220 | g_assert_true(person1 == person); |
|
9dc5d28fca99
When a Contact is added to a Person set the Contact's Person to that Person.
Gary Kramlich <grim@reaperworld.com>
parents:
41749
diff
changeset
|
221 | |
| 41749 | 222 | changed = FALSE; |
| 223 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
224 | removed = purple_person_remove_contact_info(person, info); |
| 41749 | 225 | g_assert_true(removed); |
| 226 | n_items = g_list_model_get_n_items(G_LIST_MODEL(person)); | |
| 227 | g_assert_cmpuint(n_items, ==, 0); | |
| 228 | g_assert_true(changed); | |
| 229 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
230 | person1 = purple_contact_info_get_person(info); |
|
41761
9dc5d28fca99
When a Contact is added to a Person set the Contact's Person to that Person.
Gary Kramlich <grim@reaperworld.com>
parents:
41749
diff
changeset
|
231 | g_assert_null(person1); |
|
9dc5d28fca99
When a Contact is added to a Person set the Contact's Person to that Person.
Gary Kramlich <grim@reaperworld.com>
parents:
41749
diff
changeset
|
232 | |
| 41749 | 233 | g_clear_object(&person); |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
234 | g_clear_object(&info); |
| 41749 | 235 | } |
| 236 | ||
| 237 | static void | |
| 238 | test_purple_person_contacts_multiple(void) { | |
| 239 | PurplePerson *person = NULL; | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
240 | GPtrArray *infos = NULL; |
| 41749 | 241 | guint n_items = 0; |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
242 | const gint n_infos = 5; |
| 41749 | 243 | gboolean changed = FALSE; |
| 244 | ||
| 245 | person = purple_person_new(); | |
| 246 | g_signal_connect(person, "items-changed", | |
| 247 | G_CALLBACK(test_purple_person_items_changed_cb), &changed); | |
| 248 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
249 | infos = g_ptr_array_new_full(n_infos, g_object_unref); |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
250 | for(gint i = 0; i < n_infos; i++) { |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
251 | PurpleContactInfo *info = NULL; |
| 41749 | 252 | gchar *username = NULL; |
| 253 | ||
| 254 | changed = FALSE; | |
| 255 | ||
| 256 | n_items = g_list_model_get_n_items(G_LIST_MODEL(person)); | |
| 257 | g_assert_cmpuint(n_items, ==, i); | |
| 258 | ||
| 259 | username = g_strdup_printf("username%d", i); | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
260 | info = purple_contact_info_new(NULL); |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
261 | purple_contact_info_set_username(info, username); |
| 41749 | 262 | g_free(username); |
| 263 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
264 | /* Add the contact info to the ptr array so we can remove it below. */ |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
265 | g_ptr_array_add(infos, info); |
| 41749 | 266 | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
267 | /* Add the contact info to the person and make sure that all the magic |
| 41749 | 268 | * happened. |
| 269 | */ | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
270 | purple_person_add_contact_info(person, info); |
| 41749 | 271 | n_items = g_list_model_get_n_items(G_LIST_MODEL(person)); |
| 272 | g_assert_cmpuint(n_items, ==, i + 1); | |
| 273 | g_assert_true(changed); | |
| 274 | } | |
| 275 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
276 | for(gint i = 0; i < n_infos; i++) { |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
277 | PurpleContactInfo *info = g_ptr_array_index(infos, i); |
| 41749 | 278 | gboolean removed = FALSE; |
| 279 | ||
| 280 | changed = FALSE; | |
| 281 | ||
| 282 | n_items = g_list_model_get_n_items(G_LIST_MODEL(person)); | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
283 | g_assert_cmpuint(n_items, ==, n_infos - i); |
| 41749 | 284 | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
285 | removed = purple_person_remove_contact_info(person, info); |
| 41749 | 286 | g_assert_true(removed); |
| 287 | ||
| 288 | n_items = g_list_model_get_n_items(G_LIST_MODEL(person)); | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
289 | g_assert_cmpuint(n_items, ==, n_infos - (i + 1)); |
| 41749 | 290 | |
| 291 | g_assert_true(changed); | |
| 292 | } | |
| 293 | ||
| 294 | /* Final sanity check that the person has no more contacts. */ | |
| 295 | n_items = g_list_model_get_n_items(G_LIST_MODEL(person)); | |
| 296 | g_assert_cmpuint(n_items, ==, 0); | |
| 297 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
298 | g_ptr_array_free(infos, TRUE); |
| 41749 | 299 | |
| 300 | g_clear_object(&person); | |
| 301 | } | |
| 302 | ||
| 303 | static void | |
| 304 | test_purple_person_priority_single(void) { | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
305 | PurpleContactInfo *info = NULL; |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
306 | PurpleContactInfo *priority = NULL; |
| 41749 | 307 | PurplePerson *person = NULL; |
| 308 | PurplePresence *presence = NULL; | |
| 309 | PurpleStatus *status = NULL; | |
| 310 | PurpleStatusType *status_type = NULL; | |
| 311 | gboolean called = FALSE; | |
| 312 | ||
| 313 | person = purple_person_new(); | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
314 | g_signal_connect(person, "notify::priority-contact-info", |
| 41749 | 315 | G_CALLBACK(test_purple_person_notify_cb), &called); |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
316 | priority = purple_person_get_priority_contact_info(person); |
| 41749 | 317 | g_assert_null(priority); |
| 318 | ||
|
41771
c5877e2c93f2
Create and add PurpleContacts to the manager when purple_buddy_new is called
Gary Kramlich <grim@reaperworld.com>
parents:
41761
diff
changeset
|
319 | /* Now create a real contact. */ |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
320 | info = purple_contact_info_new(NULL); |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
321 | purple_person_add_contact_info(person, info); |
|
41771
c5877e2c93f2
Create and add PurpleContacts to the manager when purple_buddy_new is called
Gary Kramlich <grim@reaperworld.com>
parents:
41761
diff
changeset
|
322 | |
|
c5877e2c93f2
Create and add PurpleContacts to the manager when purple_buddy_new is called
Gary Kramlich <grim@reaperworld.com>
parents:
41761
diff
changeset
|
323 | /* Set the status of the contact. */ |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
324 | presence = purple_contact_info_get_presence(info); |
| 41749 | 325 | status_type = purple_status_type_new(PURPLE_STATUS_AVAILABLE, "available", |
| 326 | "Available", FALSE); | |
| 327 | status = purple_status_new(status_type, presence); | |
| 328 | g_object_set(G_OBJECT(presence), "active-status", status, NULL); | |
| 329 | g_clear_object(&status); | |
| 330 | ||
| 331 | g_assert_true(called); | |
| 332 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
333 | priority = purple_person_get_priority_contact_info(person); |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
334 | g_assert_true(priority == info); |
| 41749 | 335 | |
| 336 | purple_status_type_destroy(status_type); | |
| 337 | g_clear_object(&person); | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
338 | g_clear_object(&info); |
| 41749 | 339 | g_clear_object(&presence); |
| 340 | } | |
| 341 | ||
| 342 | static void | |
| 343 | test_purple_person_priority_multiple_with_change(void) { | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
344 | PurpleContactInfo *priority = NULL; |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
345 | PurpleContactInfo *first = NULL; |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
346 | PurpleContactInfo *sorted_contact = NULL; |
| 41749 | 347 | PurplePerson *person = NULL; |
| 348 | PurplePresence *sorted_presence = NULL; | |
| 349 | PurpleStatus *status = NULL; | |
| 350 | PurpleStatusType *available = NULL; | |
| 351 | PurpleStatusType *offline = NULL; | |
| 352 | gboolean changed = FALSE; | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
353 | gint n_infos = 5; |
| 41749 | 354 | guint n_items = 0; |
| 355 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
356 | /* This unit test is a bit complicated, but it adds 5 contact infos to a |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
357 | * person all whose presences are set to offline. After adding all the |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
358 | * contact infos, we verify that the first contact info we added is the |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
359 | * priority contact info. Then we flip the active status of the n_infos - 2 |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
360 | * infos to available. This should make it the priority contact info which |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
361 | * we then assert. |
| 41749 | 362 | */ |
| 363 | ||
| 364 | /* Create our status types. */ | |
| 365 | available = purple_status_type_new(PURPLE_STATUS_AVAILABLE, "available", | |
| 366 | "Available", FALSE); | |
| 367 | offline = purple_status_type_new(PURPLE_STATUS_OFFLINE, "offline", | |
| 368 | "Offline", FALSE); | |
| 369 | ||
| 370 | /* Create the person and connected to the notify signal for the | |
| 371 | * priority-contact property. | |
| 372 | */ | |
| 373 | person = purple_person_new(); | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
374 | g_signal_connect(person, "notify::priority-contact-info", |
| 41749 | 375 | G_CALLBACK(test_purple_person_notify_cb), &changed); |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
376 | priority = purple_person_get_priority_contact_info(person); |
| 41749 | 377 | g_assert_null(priority); |
| 378 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
379 | /* Create and add all contact infos. */ |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
380 | for(gint i = 0; i < n_infos; i++) { |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
381 | PurpleContactInfo *info = NULL; |
| 41749 | 382 | PurplePresence *presence = NULL; |
| 383 | gchar *username = NULL; | |
| 384 | ||
| 385 | /* Set changed to false as it shouldn't be changed. */ | |
| 386 | changed = FALSE; | |
| 387 | ||
| 388 | /* Now create a real contact. */ | |
| 389 | username = g_strdup_printf("username%d", i + 1); | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
390 | info = purple_contact_info_new(NULL); |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
391 | purple_contact_info_set_username(info, username); |
| 41749 | 392 | g_free(username); |
|
41771
c5877e2c93f2
Create and add PurpleContacts to the manager when purple_buddy_new is called
Gary Kramlich <grim@reaperworld.com>
parents:
41761
diff
changeset
|
393 | |
|
c5877e2c93f2
Create and add PurpleContacts to the manager when purple_buddy_new is called
Gary Kramlich <grim@reaperworld.com>
parents:
41761
diff
changeset
|
394 | /* Set the status for the contact. */ |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
395 | presence = purple_contact_info_get_presence(info); |
|
41771
c5877e2c93f2
Create and add PurpleContacts to the manager when purple_buddy_new is called
Gary Kramlich <grim@reaperworld.com>
parents:
41761
diff
changeset
|
396 | status = purple_status_new(offline, presence); |
|
c5877e2c93f2
Create and add PurpleContacts to the manager when purple_buddy_new is called
Gary Kramlich <grim@reaperworld.com>
parents:
41761
diff
changeset
|
397 | g_object_set(G_OBJECT(presence), "active-status", status, NULL); |
|
c5877e2c93f2
Create and add PurpleContacts to the manager when purple_buddy_new is called
Gary Kramlich <grim@reaperworld.com>
parents:
41761
diff
changeset
|
398 | g_clear_object(&status); |
| 41749 | 399 | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
400 | purple_person_add_contact_info(person, info); |
| 41749 | 401 | |
| 402 | if(i == 0) { | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
403 | first = g_object_ref(info); |
| 41749 | 404 | g_assert_true(changed); |
| 405 | } else { | |
| 406 | g_assert_false(changed); | |
| 407 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
408 | if(i == n_infos - 2) { |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
409 | sorted_contact = g_object_ref(info); |
| 41749 | 410 | sorted_presence = g_object_ref(presence); |
| 411 | } | |
| 412 | } | |
| 413 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
414 | g_clear_object(&info); |
| 41749 | 415 | } |
| 416 | ||
| 417 | n_items = g_list_model_get_n_items(G_LIST_MODEL(person)); | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
418 | g_assert_cmpuint(n_items, ==, n_infos); |
| 41749 | 419 | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
420 | priority = purple_person_get_priority_contact_info(person); |
| 41749 | 421 | g_assert_true(priority == first); |
| 422 | g_clear_object(&first); | |
| 423 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
424 | /* Now set the second from the last contact info's status to available, and |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
425 | * verify that that contact info is now the priority contact info. |
| 41749 | 426 | */ |
| 427 | changed = FALSE; | |
| 428 | status = purple_status_new(available, sorted_presence); | |
| 429 | g_object_set(G_OBJECT(sorted_presence), "active-status", status, NULL); | |
| 430 | g_clear_object(&status); | |
| 431 | g_assert_true(changed); | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
432 | priority = purple_person_get_priority_contact_info(person); |
| 41749 | 433 | g_assert_true(priority == sorted_contact); |
| 434 | ||
| 435 | /* Cleanup. */ | |
| 436 | purple_status_type_destroy(offline); | |
| 437 | purple_status_type_destroy(available); | |
| 438 | ||
| 439 | g_clear_object(&sorted_contact); | |
| 440 | g_clear_object(&sorted_presence); | |
| 441 | ||
| 442 | g_clear_object(&person); | |
| 443 | } | |
| 444 | ||
| 445 | /****************************************************************************** | |
|
42059
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
446 | * Matches tests |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
447 | *****************************************************************************/ |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
448 | static void |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
449 | test_purple_person_matches_accepts_null(void) { |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
450 | PurplePerson *person = purple_person_new(); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
451 | |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
452 | g_assert_true(purple_person_matches(person, NULL)); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
453 | |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
454 | g_clear_object(&person); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
455 | } |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
456 | |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
457 | static void |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
458 | test_purple_person_matches_empty_string(void) { |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
459 | PurplePerson *person = purple_person_new(); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
460 | |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
461 | g_assert_true(purple_person_matches(person, "")); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
462 | |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
463 | g_clear_object(&person); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
464 | } |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
465 | |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
466 | static void |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
467 | test_purple_person_matches_alias(void) { |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
468 | PurplePerson *person = purple_person_new(); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
469 | |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
470 | purple_person_set_alias(person, "this is the alias"); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
471 | |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
472 | g_assert_true(purple_person_matches(person, "the")); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
473 | g_assert_false(purple_person_matches(person, "what")); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
474 | |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
475 | g_clear_object(&person); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
476 | } |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
477 | |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
478 | static void |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
479 | test_purple_person_matches_contact_info(void) { |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
480 | PurplePerson *person = purple_person_new(); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
481 | PurpleContactInfo *info = purple_contact_info_new(NULL); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
482 | |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
483 | purple_contact_info_set_username(info, "user1"); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
484 | purple_person_add_contact_info(person, info); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
485 | g_clear_object(&info); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
486 | |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
487 | g_assert_true(purple_person_matches(person, "user1")); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
488 | |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
489 | g_clear_object(&person); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
490 | } |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
491 | |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
492 | /****************************************************************************** |
| 41749 | 493 | * Main |
| 494 | *****************************************************************************/ | |
| 495 | gint | |
| 496 | main(gint argc, gchar *argv[]) { | |
| 497 | g_test_init(&argc, &argv, NULL); | |
| 498 | ||
| 499 | test_ui_purple_init(); | |
| 500 | ||
| 501 | g_test_add_func("/person/new", | |
| 502 | test_purple_person_new); | |
| 503 | g_test_add_func("/person/properties", | |
| 504 | test_purple_person_properties); | |
|
42053
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
505 | |
|
42054
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
506 | g_test_add_func("/person/avatar-for-display/person", |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
507 | test_purple_person_avatar_for_display_person); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
508 | g_test_add_func("/person/avatar-for-display/contact", |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
509 | test_purple_person_avatar_for_display_contact); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
510 | |
|
42053
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
511 | g_test_add_func("/person/name-for-display/person", |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
512 | test_purple_person_name_for_display_person); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
513 | g_test_add_func("/person/name-for-display/contact", |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
514 | test_purple_person_name_for_display_contact); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
515 | |
| 41749 | 516 | g_test_add_func("/person/contacts/single", |
| 517 | test_purple_person_contacts_single); | |
| 518 | g_test_add_func("/person/contacts/multiple", | |
| 519 | test_purple_person_contacts_multiple); | |
| 520 | ||
| 521 | g_test_add_func("/person/priority/single", | |
| 522 | test_purple_person_priority_single); | |
| 523 | g_test_add_func("/person/priority/multiple-with-change", | |
| 524 | test_purple_person_priority_multiple_with_change); | |
| 525 | ||
|
42059
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
526 | g_test_add_func("/person/matches/accepts_null", |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
527 | test_purple_person_matches_accepts_null); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
528 | g_test_add_func("/person/matches/empty_string", |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
529 | test_purple_person_matches_empty_string); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
530 | g_test_add_func("/person/matches/alias", |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
531 | test_purple_person_matches_alias); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
532 | g_test_add_func("/person/matches/contact_info", |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
533 | test_purple_person_matches_contact_info); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
534 | |
| 41749 | 535 | return g_test_run(); |
|
42059
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
536 | } |