libpurple/tests/test_person.c

Mon, 03 Feb 2025 21:07:27 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Mon, 03 Feb 2025 21:07:27 -0600
changeset 43171
914049a55a72
parent 42866
4b201e18638f
child 43265
7960b5f85729
permissions
-rw-r--r--

Update the tests for Purple.Person

I also added Purple.Person.remove_all_contact_infos as we need it for the
tests and it could be useful for others maybe.

Testing Done:
Ran the tests under valgrind and called in the turtles.

Reviewed at https://reviews.imfreedom.org/r/3795/

41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 *
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 * Lesser General Public License for more details.
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 *
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 */
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 #include <glib.h>
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 #include <purple.h>
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 /******************************************************************************
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24 * Callbacks
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 *****************************************************************************/
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26 static void
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 test_purple_person_items_changed_cb(G_GNUC_UNUSED GListModel *model,
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28 G_GNUC_UNUSED guint position,
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 G_GNUC_UNUSED guint removed,
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 G_GNUC_UNUSED guint added,
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 gpointer data)
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 {
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
33 guint *counter = data;
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
35 *counter = *counter + 1;
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 }
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 static void
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 test_purple_person_notify_cb(G_GNUC_UNUSED GObject *obj,
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 G_GNUC_UNUSED GParamSpec *pspec,
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 gpointer data)
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 {
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
43 guint *called = data;
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
45 *called = *called + 1;
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 }
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48 /******************************************************************************
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 * Tests
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 *****************************************************************************/
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 static void
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 test_purple_person_new(void) {
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 PurplePerson *person = NULL;
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 person = purple_person_new();
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 g_assert_true(PURPLE_IS_PERSON(person));
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
59 g_assert_finalize_object(person);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 }
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 static void
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 test_purple_person_properties(void) {
42312
7d6f0b8b6e77 Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents: 42309
diff changeset
64 PurpleAvatar *avatar = NULL;
7d6f0b8b6e77 Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents: 42309
diff changeset
65 PurpleAvatar *avatar1 = NULL;
7d6f0b8b6e77 Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents: 42309
diff changeset
66 PurpleAvatar *avatar_for_display = NULL;
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67 PurpleContact *person = NULL;
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 PurpleTags *tags = NULL;
42053
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
69 char *id = NULL;
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
70 char *alias = NULL;
42309
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
71 char *color = NULL;
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
72 char *color_for_display = NULL;
42053
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
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 /* Create our avatar for testing. */
42312
7d6f0b8b6e77 Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents: 42309
diff changeset
76 avatar = g_object_new(PURPLE_TYPE_AVATAR, NULL);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78 /* Use g_object_new so we can test setting properties by name. All of them
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79 * call the setter methods, so by doing it this way we exercise more of the
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80 * code.
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81 */
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 person = g_object_new(
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83 PURPLE_TYPE_PERSON,
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84 "alias", "alias",
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85 "avatar", avatar,
42309
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
86 "color", "#794a85",
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87 NULL);
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
88
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
89 /* Now use g_object_get to read all of the properties. */
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90 g_object_get(person,
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91 "id", &id,
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92 "alias", &alias,
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93 "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
94 "avatar-for-display", &avatar_for_display,
42309
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
95 "color", &color,
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
96 "color-for-display", &color_for_display,
42053
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
97 "name-for-display", &name_for_display,
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
98 "tags", &tags,
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
99 NULL);
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100
42309
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
101 /* Test all the things. */
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102 g_assert_nonnull(id);
42309
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
103 g_clear_pointer(&id, g_free);
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
104
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105 g_assert_cmpstr(alias, ==, "alias");
42309
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
106 g_clear_pointer(&alias, g_free);
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
107
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108 g_assert_true(avatar1 == avatar);
42309
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
109 g_clear_object(&avatar1);
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
110
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
111 g_assert_true(avatar_for_display == avatar);
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
112 g_clear_object(&avatar_for_display);
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
113
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
114 g_assert_cmpstr(color, ==, "#794a85");
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
115 g_clear_pointer(&color, g_free);
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
116
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
117 g_assert_cmpstr(color_for_display, ==, "#794a85");
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
118 g_clear_pointer(&color_for_display, g_free);
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
119
42053
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
120 g_assert_cmpstr(name_for_display, ==, "alias");
42309
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
121 g_clear_pointer(&name_for_display, g_free);
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
122
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123 g_assert_nonnull(tags);
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124 g_clear_object(&tags);
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125
42309
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
126 /* Additional cleanup. */
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
127 g_assert_finalize_object(person);
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
128 g_assert_finalize_object(avatar);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
129 }
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
130
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
131 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
132 test_purple_person_avatar_for_display_person(void) {
42312
7d6f0b8b6e77 Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents: 42309
diff changeset
133 PurpleAvatar *avatar = 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
134 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
135 PurplePerson *person = NULL;
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
136 guint called = 0;
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
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 person = purple_person_new();
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
139 g_signal_connect(person, "notify::avatar",
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
140 G_CALLBACK(test_purple_person_notify_cb), &called);
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
141 g_signal_connect(person, "notify::avatar-for-display",
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
142 G_CALLBACK(test_purple_person_notify_cb), &called);
42312
7d6f0b8b6e77 Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents: 42309
diff changeset
143 avatar = g_object_new(PURPLE_TYPE_AVATAR, 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
144 purple_person_set_avatar(person, avatar);
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
145 g_assert_cmpuint(called, ==, 2);
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
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 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
149
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
150 /* Make sure the person's avatar is overriding the contact info. */
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
151 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
152
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
153 /* Contact info's have a reference on the person, so the easiest way to
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
154 * remove that is to remove them from the person.
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
155 */
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
156 purple_person_remove_contact_info(person, info);
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
157
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
158 g_assert_finalize_object(person);
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
159 g_assert_finalize_object(info);
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
160 g_assert_finalize_object(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
161 }
7aa77854392d Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42053
diff changeset
162
7aa77854392d Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42053
diff changeset
163 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
164 test_purple_person_avatar_for_display_contact(void) {
42312
7d6f0b8b6e77 Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents: 42309
diff changeset
165 PurpleAvatar *avatar = 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
166 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
167 PurplePerson *person = NULL;
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
168 guint called = 0;
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
169
7aa77854392d Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42053
diff changeset
170 person = purple_person_new();
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
171 g_signal_connect(person, "notify::avatar-for-display",
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
172 G_CALLBACK(test_purple_person_notify_cb), &called);
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
173
7aa77854392d Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42053
diff changeset
174 info = purple_contact_info_new("id");
42312
7d6f0b8b6e77 Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents: 42309
diff changeset
175 avatar = g_object_new(PURPLE_TYPE_AVATAR, 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
176 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
177 purple_person_add_contact_info(person, info);
42309
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
178
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
179 g_assert_cmpuint(called, ==, 1);
42309
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
180 called = 0;
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
181
7aa77854392d Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42053
diff changeset
182 /* 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
183 g_assert_true(purple_person_get_avatar_for_display(person) == avatar);
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
184 g_clear_object(&avatar);
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
185
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
186 /* Now change the avatar on the contact info an verify that we not notified
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
187 * of the property changing.
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
188 */
42312
7d6f0b8b6e77 Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents: 42309
diff changeset
189 called = 0;
7d6f0b8b6e77 Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents: 42309
diff changeset
190 avatar = g_object_new(PURPLE_TYPE_AVATAR, NULL);
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
191 purple_contact_info_set_avatar(info, avatar);
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
192 g_assert_cmpuint(called, ==, 1);
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
193
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
194 /* Contact info's have a reference on the person, so the easiest way to
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
195 * remove that is to remove them from the person.
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
196 */
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
197 purple_person_remove_contact_info(person, info);
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
198
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
199 g_assert_finalize_object(person);
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
200 g_assert_finalize_object(info);
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
201 g_assert_finalize_object(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
202 }
7aa77854392d Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42053
diff changeset
203
7aa77854392d Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42053
diff changeset
204 static void
42309
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
205 test_purple_person_color_for_display_person(void) {
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
206 PurpleContactInfo *info = NULL;
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
207 PurplePerson *person = NULL;
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
208 const char *color = NULL;
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
209 guint color_called = 0;
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
210 guint color_for_display_called = 0;
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
211
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
212 person = purple_person_new();
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
213 g_signal_connect(person, "notify::color",
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
214 G_CALLBACK(test_purple_person_notify_cb), &color_called);
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
215 g_signal_connect(person, "notify::color-for-display",
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
216 G_CALLBACK(test_purple_person_notify_cb),
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
217 &color_for_display_called);
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
218 purple_person_set_color(person, "#abcdef");
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
219
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
220 g_assert_cmpuint(color_called, ==, 1);
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
221 color_called = 0;
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
222
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
223 g_assert_cmpuint(color_for_display_called, ==, 1);
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
224 color_for_display_called = 0;
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
225
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
226 /* Make sure the person's color is overriding the contact info. */
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
227 info = purple_contact_info_new("id");
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
228 purple_person_add_contact_info(person, info);
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
229
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
230 color = purple_person_get_color_for_display(person);
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
231 g_assert_cmpstr(color, ==, "#abcdef");
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
232
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
233 g_assert_cmpuint(color_called, ==, 0);
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
234 g_assert_cmpuint(color_for_display_called, ==, 0);
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
235
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
236 /* Contact info's have a reference on the person, so the easiest way to
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
237 * remove that is to remove them from the person.
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
238 */
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
239 purple_person_remove_contact_info(person, info);
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
240
42309
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
241 /* Cleanup. */
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
242 g_assert_finalize_object(person);
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
243 g_assert_finalize_object(info);
42309
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
244 }
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
245
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
246 static void
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
247 test_purple_person_color_for_display_contact(void) {
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
248 PurpleContactInfo *info = NULL;
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
249 PurplePerson *person = NULL;
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
250 const char *color = NULL;
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
251 guint called = 0;
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
252
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
253 person = purple_person_new();
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
254 g_signal_connect(person, "notify::color-for-display",
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
255 G_CALLBACK(test_purple_person_notify_cb), &called);
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
256
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
257 info = purple_contact_info_new("id");
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
258 purple_contact_info_set_color(info, "#012345");
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
259 purple_person_add_contact_info(person, info);
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
260
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
261 g_assert_cmpuint(called, ==, 1);
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
262 called = 0;
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
263
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
264 /* Make sure the person's alias is overriding the contact info. */
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
265 color = purple_person_get_color_for_display(person);
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
266 g_assert_cmpstr(color, ==, "#012345");
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
267
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
268 /* Now change the avatar on the contact info and verify that we are
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
269 * notified of the property changing.
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
270 */
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
271 purple_contact_info_set_color(info, "#6789ab");
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
272 g_assert_cmpuint(called, ==, 1);
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
273
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
274 /* Contact info's have a reference on the person, so the easiest way to
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
275 * remove that is to remove them from the person.
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
276 */
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
277 purple_person_remove_contact_info(person, info);
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
278
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
279 g_assert_finalize_object(person);
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
280 g_assert_finalize_object(info);
42309
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
281 }
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
282
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
283 static void
42053
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
284 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
285 PurpleContactInfo *info = NULL;
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
286 PurplePerson *person = NULL;
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
287
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
288 person = purple_person_new();
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
289 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
290
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
291 info = purple_contact_info_new("id");
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
292 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
293
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
294 /* 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
295 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
296 "person-alias");
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
297
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
298 /* Contact info's have a reference on the person, so the easiest way to
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
299 * remove that is to remove them from the person.
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
300 */
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
301 purple_person_remove_contact_info(person, info);
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
302
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
303 g_assert_finalize_object(person);
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
304 g_assert_finalize_object(info);
42053
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
305 }
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
306
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
307 static void
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
308 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
309 PurpleContactInfo *info = NULL;
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
310 PurplePerson *person = NULL;
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
311 guint called = 0;
42053
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
312
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
313 person = purple_person_new();
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
314 g_signal_connect(person, "notify::name-for-display",
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
315 G_CALLBACK(test_purple_person_notify_cb), &called);
42053
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
316
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
317 info = purple_contact_info_new("id");
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
318 purple_person_add_contact_info(person, info);
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
319 g_assert_cmpuint(called, ==, 1);
42053
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
320
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
321 /* Make sure the name for display matches the id of the contact. */
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
322 g_assert_cmpstr(purple_person_get_name_for_display(person), ==, "id");
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
323
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
324 /* Now set a username on the contact and verify that the name for display
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
325 * matches and that the notify signal was emitted for the property.
42053
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
326 */
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
327 purple_contact_info_set_username(info, "clu");
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
328 g_assert_cmpstr(purple_person_get_name_for_display(person), ==, "clu");
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
329 g_assert_cmpuint(called, ==, 2);
42053
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
330
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
331 /* Contact info's have a reference on the person, so the easiest way to
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
332 * remove that is to remove them from the person.
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
333 */
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
334 purple_person_remove_contact_info(person, info);
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
335
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
336 g_assert_finalize_object(person);
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
337 g_assert_finalize_object(info);
42053
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
338 }
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
339
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
340 static void
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
341 test_purple_person_contacts_single(void) {
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
342 PurpleContactInfo *info = NULL;
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
343 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
344 PurplePerson *person1 = NULL;
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
345 guint n_items = 0;
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
346 gboolean removed = FALSE;
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
347 guint changed = 0;
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
348
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
349 info = purple_contact_info_new("id");
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
350 person = purple_person_new();
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
351 g_signal_connect(person, "items-changed",
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
352 G_CALLBACK(test_purple_person_items_changed_cb), &changed);
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
353
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
354 n_items = g_list_model_get_n_items(G_LIST_MODEL(person));
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
355 g_assert_cmpuint(n_items, ==, 0);
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
356 purple_person_add_contact_info(person, info);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
357 n_items = g_list_model_get_n_items(G_LIST_MODEL(person));
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
358 g_assert_cmpuint(n_items, ==, 1);
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
359 g_assert_cmpuint(changed, ==, 1);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
360
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
361 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
362 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
363
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
364 changed = 0;
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
365 removed = purple_person_remove_contact_info(person, info);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
366 g_assert_true(removed);
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
367 g_assert_cmpuint(changed, ==, 1);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
368 n_items = g_list_model_get_n_items(G_LIST_MODEL(person));
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
369 g_assert_cmpuint(n_items, ==, 0);
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
370
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
371 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
372 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
373
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
374 g_assert_finalize_object(person);
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
375 g_assert_finalize_object(info);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
376 }
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
377
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
378 static void
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
379 test_purple_person_contacts_multiple(void) {
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
380 PurplePerson *person = NULL;
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
381 GPtrArray *infos = NULL;
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
382 guint n_items = 0;
42866
4b201e18638f Modernize most of the unit tests
Gary Kramlich <grim@reaperworld.com>
parents: 42312
diff changeset
383 const int n_infos = 5;
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
384 guint changed = 0;
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
385
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
386 person = purple_person_new();
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
387 g_signal_connect(person, "items-changed",
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
388 G_CALLBACK(test_purple_person_items_changed_cb), &changed);
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
389
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
390 infos = g_ptr_array_new_full(n_infos, g_object_unref);
42866
4b201e18638f Modernize most of the unit tests
Gary Kramlich <grim@reaperworld.com>
parents: 42312
diff changeset
391 for(int i = 0; i < n_infos; i++) {
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
392 PurpleContactInfo *info = NULL;
42866
4b201e18638f Modernize most of the unit tests
Gary Kramlich <grim@reaperworld.com>
parents: 42312
diff changeset
393 char *username = NULL;
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
394
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
395 changed = 0;
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
396
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
397 n_items = g_list_model_get_n_items(G_LIST_MODEL(person));
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
398 g_assert_cmpuint(n_items, ==, i);
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
399
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
400 username = g_strdup_printf("username%d", i);
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
401 info = purple_contact_info_new(NULL);
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
402 purple_contact_info_set_username(info, username);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
403 g_free(username);
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
404
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
405 /* 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
406 g_ptr_array_add(infos, info);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
407
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
408 /* Add the contact info to the person and make sure that all the magic
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
409 * happened.
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
410 */
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
411 purple_person_add_contact_info(person, info);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
412 n_items = g_list_model_get_n_items(G_LIST_MODEL(person));
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
413 g_assert_cmpuint(n_items, ==, i + 1);
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
414 g_assert_cmpuint(changed, ==, 1);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
415 }
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
416
42866
4b201e18638f Modernize most of the unit tests
Gary Kramlich <grim@reaperworld.com>
parents: 42312
diff changeset
417 for(int i = 0; i < n_infos; i++) {
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
418 PurpleContactInfo *info = g_ptr_array_index(infos, i);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
419 gboolean removed = FALSE;
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
420
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
421 changed = 0;
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
422
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
423 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
424 g_assert_cmpuint(n_items, ==, n_infos - i);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
425
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
426 removed = purple_person_remove_contact_info(person, info);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
427 g_assert_true(removed);
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
428
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
429 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
430 g_assert_cmpuint(n_items, ==, n_infos - (i + 1));
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
431
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
432 g_assert_cmpuint(changed, ==, 1);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
433 }
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
434
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
435 /* Final sanity check that the person has no more contacts. */
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
436 n_items = g_list_model_get_n_items(G_LIST_MODEL(person));
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
437 g_assert_cmpuint(n_items, ==, 0);
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
438
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
439 g_ptr_array_free(infos, TRUE);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
440
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
441 g_assert_finalize_object(person);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
442 }
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
443
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
444 static void
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
445 test_purple_person_priority_single(void) {
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
446 PurpleContactInfo *info = NULL;
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
447 PurpleContactInfo *priority = NULL;
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
448 PurplePerson *person = NULL;
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
449 PurplePresence *presence = NULL;
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
450 guint called = 0;
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
451
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
452 person = purple_person_new();
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
453 g_signal_connect(person, "notify::priority-contact-info",
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
454 G_CALLBACK(test_purple_person_notify_cb), &called);
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
455 priority = purple_person_get_priority_contact_info(person);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
456 g_assert_null(priority);
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
457
41771
c5877e2c93f2 Create and add PurpleContacts to the manager when purple_buddy_new is called
Gary Kramlich <grim@reaperworld.com>
parents: 41761
diff changeset
458 /* Now create a real contact. */
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
459 info = purple_contact_info_new(NULL);
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
460 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
461
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
462 /* Set the presence of the contact. */
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
463 presence = purple_contact_info_get_presence(info);
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
464 purple_presence_set_primitive(presence,
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
465 PURPLE_PRESENCE_PRIMITIVE_AVAILABLE);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
466
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
467 g_assert_cmpuint(called, ==, 1);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
468
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
469 priority = purple_person_get_priority_contact_info(person);
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
470 g_assert_true(priority == info);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
471
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
472 /* Contact info's have a reference on the person, so the easiest way to
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
473 * remove that is to remove them from the person.
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
474 */
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
475 purple_person_remove_contact_info(person, info);
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
476
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
477 g_assert_finalize_object(person);
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
478 g_assert_finalize_object(info);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
479 }
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
480
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
481 static void
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
482 test_purple_person_priority_multiple_with_change(void) {
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
483 PurpleContactInfo *priority = NULL;
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
484 PurpleContactInfo *first = NULL;
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
485 PurpleContactInfo *sorted_contact = NULL;
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
486 PurplePerson *person = NULL;
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
487 PurplePresence *sorted_presence = NULL;
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
488 guint called = 0;
42866
4b201e18638f Modernize most of the unit tests
Gary Kramlich <grim@reaperworld.com>
parents: 42312
diff changeset
489 int n_infos = 5;
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
490 guint n_items = 0;
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
491
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
492 /* 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
493 * 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
494 * 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
495 * 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
496 * 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
497 * we then assert.
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
498 */
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
499
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
500 /* Create the person and connected to the notify signal for the
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
501 * priority-contact property.
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
502 */
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
503 person = purple_person_new();
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
504 g_signal_connect(person, "notify::priority-contact-info",
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
505 G_CALLBACK(test_purple_person_notify_cb), &called);
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
506 priority = purple_person_get_priority_contact_info(person);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
507 g_assert_null(priority);
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
508
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
509 /* Create and add all contact infos. */
42866
4b201e18638f Modernize most of the unit tests
Gary Kramlich <grim@reaperworld.com>
parents: 42312
diff changeset
510 for(int i = 0; i < n_infos; i++) {
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
511 PurpleContactInfo *info = NULL;
42866
4b201e18638f Modernize most of the unit tests
Gary Kramlich <grim@reaperworld.com>
parents: 42312
diff changeset
512 char *username = NULL;
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
513
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
514 /* Set called to 0 as it shouldn't be called as the priority contact
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
515 * info shouldn't change except for the first index.
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
516 */
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
517 called = 0;
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
518
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
519 /* Now create a real contact. */
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
520 username = g_strdup_printf("username%d", i + 1);
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
521 info = purple_contact_info_new(NULL);
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
522 purple_contact_info_set_username(info, username);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
523 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
524
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
525 purple_person_add_contact_info(person, info);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
526
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
527 if(i == 0) {
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
528 first = g_object_ref(info);
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
529 g_assert_cmpuint(called, ==, 1);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
530 } else {
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
531 g_assert_cmpuint(called, ==, 0);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
532
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
533 if(i == n_infos - 2) {
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
534 PurplePresence *presence = NULL;
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
535
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
536 /* Add a reference to the presence of this specific contact
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
537 * info, as we want to tweak it later.
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
538 */
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
539 presence = purple_contact_info_get_presence(info);
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
540 sorted_presence = g_object_ref(presence);
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
541
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
542 sorted_contact = g_object_ref(info);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
543 }
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
544 }
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
545
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
546 g_clear_object(&info);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
547 }
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
548
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
549 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
550 g_assert_cmpuint(n_items, ==, n_infos);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
551
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
552 priority = purple_person_get_priority_contact_info(person);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
553 g_assert_true(priority == first);
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
554 g_clear_object(&first);
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
555
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
556 /* 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
557 * verify that that contact info is now the priority contact info.
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
558 */
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
559 called = 0;
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
560 purple_presence_set_primitive(sorted_presence,
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
561 PURPLE_PRESENCE_PRIMITIVE_AVAILABLE);
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
562 priority = purple_person_get_priority_contact_info(person);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
563 g_assert_true(priority == sorted_contact);
42270
1bdd57a0c0d1 Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
564 g_assert_cmpuint(called, ==, 1);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
565
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
566 /* Cleanup. */
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
567 purple_person_remove_all_contact_infos(person);
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
568
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
569 g_clear_object(&sorted_contact);
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
570 g_clear_object(&sorted_presence);
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
571
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
572 g_assert_finalize_object(person);
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
573 }
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
574
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
575 /******************************************************************************
42059
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
576 * Matches tests
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
577 *****************************************************************************/
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
578 static void
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
579 test_purple_person_matches_accepts_null(void) {
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
580 PurplePerson *person = purple_person_new();
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
581
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
582 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
583
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
584 g_assert_finalize_object(person);
42059
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
585 }
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
586
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
587 static void
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
588 test_purple_person_matches_empty_string(void) {
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
589 PurplePerson *person = purple_person_new();
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
590
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
591 g_assert_true(purple_person_matches(person, ""));
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
592
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
593 g_assert_finalize_object(person);
42059
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
594 }
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
595
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
596 static void
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
597 test_purple_person_matches_alias(void) {
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
598 PurplePerson *person = purple_person_new();
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
599
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
600 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
601
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
602 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
603 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
604
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
605 g_assert_finalize_object(person);
42059
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
606 }
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
607
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
608 static void
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
609 test_purple_person_matches_contact_info(void) {
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
610 PurplePerson *person = purple_person_new();
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
611 PurpleContactInfo *info = purple_contact_info_new(NULL);
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
612
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
613 purple_contact_info_set_username(info, "user1");
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
614 purple_person_add_contact_info(person, info);
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
615
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
616 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
617
43171
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
618 /* Contact info's have a reference on the person, so the easiest way to
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
619 * remove that is to remove them from the person.
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
620 */
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
621 purple_person_remove_contact_info(person, info);
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
622
914049a55a72 Update the tests for Purple.Person
Gary Kramlich <grim@reaperworld.com>
parents: 42866
diff changeset
623 g_assert_finalize_object(person);
42059
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
624 }
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
625
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
626 /******************************************************************************
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
627 * Main
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
628 *****************************************************************************/
42866
4b201e18638f Modernize most of the unit tests
Gary Kramlich <grim@reaperworld.com>
parents: 42312
diff changeset
629 int
4b201e18638f Modernize most of the unit tests
Gary Kramlich <grim@reaperworld.com>
parents: 42312
diff changeset
630 main(int argc, char *argv[]) {
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
631 g_test_init(&argc, &argv, NULL);
42866
4b201e18638f Modernize most of the unit tests
Gary Kramlich <grim@reaperworld.com>
parents: 42312
diff changeset
632 g_test_set_nonfatal_assertions();
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
633
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
634 g_test_add_func("/person/new",
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
635 test_purple_person_new);
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
636 g_test_add_func("/person/properties",
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
637 test_purple_person_properties);
42053
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
638
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
639 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
640 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
641 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
642 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
643
42309
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
644 g_test_add_func("/person/color-for-display/person",
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
645 test_purple_person_color_for_display_person);
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
646 g_test_add_func("/person/color-for-display/contact",
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
647 test_purple_person_color_for_display_contact);
52571584c0ae Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 42270
diff changeset
648
42053
742efe62e610 Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents: 41948
diff changeset
649 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
650 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
651 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
652 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
653
41749
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
654 g_test_add_func("/person/contacts/single",
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
655 test_purple_person_contacts_single);
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
656 g_test_add_func("/person/contacts/multiple",
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
657 test_purple_person_contacts_multiple);
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
658
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
659 g_test_add_func("/person/priority/single",
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
660 test_purple_person_priority_single);
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
661 g_test_add_func("/person/priority/multiple-with-change",
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
662 test_purple_person_priority_multiple_with_change);
c22448f50d5d Create PurplePerson.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
663
42059
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
664 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
665 test_purple_person_matches_accepts_null);
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
666 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
667 test_purple_person_matches_empty_string);
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
668 g_test_add_func("/person/matches/alias",
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
669 test_purple_person_matches_alias);
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
670 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
671 test_purple_person_matches_contact_info);
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
672
42866
4b201e18638f Modernize most of the unit tests
Gary Kramlich <grim@reaperworld.com>
parents: 42312
diff changeset
673 return g_test_run();
42059
e6dcbf0db616 Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents: 42054
diff changeset
674 }

mercurial