libpurple/tests/test_contact.c

Sat, 01 Oct 2022 01:50:52 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Sat, 01 Oct 2022 01:50:52 -0500
changeset 41771
c5877e2c93f2
parent 41759
1ecc0512e714
child 41918
106ae46b290b
permissions
-rw-r--r--

Create and add PurpleContacts to the manager when purple_buddy_new is called

This required some additional changes to PurpleContact. Namely that the contact always has a presence and it is no longer writeable.

Testing Done:
Ran the unit tests and verified nothing funky happens when running.

We can't test that all of the properties are properly bound because we would have to start up a lot more of libpurple than I'm willing to do for something that's temporary.

Bugs closed: PIDGIN-17685

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

41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 *
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 * Lesser General Public License for more details.
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 *
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 */
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 #include <glib.h>
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 #include <purple.h>
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include "test_ui.h"
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 /******************************************************************************
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26 * Tests
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 *****************************************************************************/
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28 static void
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 test_purple_contact_new(void) {
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 PurpleAccount *account = NULL;
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 PurpleContact *contact = NULL;
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 account = purple_account_new("test", "test");
41759
1ecc0512e714 Make purple_contact_new take the id instead of the username.
Gary Kramlich <grim@reaperworld.com>
parents: 41755
diff changeset
34 contact = purple_contact_new(account, "id");
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 g_assert_true(purple_contact_get_account(contact) == account);
41759
1ecc0512e714 Make purple_contact_new take the id instead of the username.
Gary Kramlich <grim@reaperworld.com>
parents: 41755
diff changeset
37 g_assert_cmpstr(purple_contact_get_id(contact), ==, "id");
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 g_clear_object(&contact);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 g_clear_object(&account);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 static void
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 test_purple_contact_properties(void) {
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 PurpleAccount *account = NULL;
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 PurpleAccount *account1 = NULL;
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 PurpleContact *contact = NULL;
41755
b7e6166e5300 Add a person property to PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41739
diff changeset
48 PurplePerson *person = NULL;
b7e6166e5300 Add a person property to PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41739
diff changeset
49 PurplePerson *person1 = NULL;
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 PurplePresence *presence1 = NULL;
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 PurpleTags *tags = NULL;
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 GdkPixbuf *avatar = NULL;
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 GdkPixbuf *avatar1 = NULL;
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 gchar *id = NULL;
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 gchar *username = NULL;
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 gchar *display_name = NULL;
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 gchar *alias = NULL;
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 account = purple_account_new("test", "test");
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 avatar = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 1, 1);
41755
b7e6166e5300 Add a person property to PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41739
diff changeset
61 person = purple_person_new();
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 /* Use g_object_new so we can test setting properties by name. All of them
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 * call the setter methods, so by doing it this way we exercise more of the
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 * code.
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 */
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67 contact = g_object_new(
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 PURPLE_TYPE_CONTACT,
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69 "account", account,
41759
1ecc0512e714 Make purple_contact_new take the id instead of the username.
Gary Kramlich <grim@reaperworld.com>
parents: 41755
diff changeset
70 "id", "id1",
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 "username", "username",
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 "display-name", "display-name",
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 "alias", "alias",
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 "avatar", avatar,
41755
b7e6166e5300 Add a person property to PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41739
diff changeset
75 "person", person,
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 NULL);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78 /* Now use g_object_get to read all of the properties. */
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79 g_object_get(contact,
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80 "id", &id,
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81 "account", &account1,
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 "username", &username,
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83 "display-name", &display_name,
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84 "alias", &alias,
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85 "avatar", &avatar1,
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86 "presence", &presence1,
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87 "tags", &tags,
41755
b7e6166e5300 Add a person property to PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41739
diff changeset
88 "person", &person1,
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
89 NULL);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91 /* Compare all the things. */
41759
1ecc0512e714 Make purple_contact_new take the id instead of the username.
Gary Kramlich <grim@reaperworld.com>
parents: 41755
diff changeset
92 g_assert_cmpstr(id, ==, "id1");
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93 g_assert_true(account1 == account);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94 g_assert_cmpstr(username, ==, "username");
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95 g_assert_cmpstr(display_name, ==, "display-name");
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
96 g_assert_cmpstr(alias, ==, "alias");
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
97 g_assert_true(avatar1 == avatar);
41771
c5877e2c93f2 Create and add PurpleContacts to the manager when purple_buddy_new is called
Gary Kramlich <grim@reaperworld.com>
parents: 41759
diff changeset
98 g_assert_nonnull(presence1);
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
99 g_assert_nonnull(tags);
41755
b7e6166e5300 Add a person property to PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41739
diff changeset
100 g_assert_true(person1 == person);
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102 /* Free/unref all the things. */
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
103 g_clear_pointer(&id, g_free);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104 g_clear_object(&account1);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105 g_clear_pointer(&username, g_free);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106 g_clear_pointer(&display_name, g_free);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107 g_clear_pointer(&alias, g_free);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108 g_clear_object(&avatar1);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109 g_clear_object(&presence1);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110 g_clear_object(&tags);
41755
b7e6166e5300 Add a person property to PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41739
diff changeset
111 g_clear_object(&person);
b7e6166e5300 Add a person property to PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41739
diff changeset
112 g_clear_object(&person1);
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114 g_clear_object(&avatar);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115 g_clear_object(&contact);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116 g_clear_object(&account);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
118
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119 /******************************************************************************
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120 * Main
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
121 *****************************************************************************/
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122 gint
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123 main(gint argc, gchar *argv[]) {
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124 g_test_init(&argc, &argv, NULL);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
126 test_ui_purple_init();
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
127
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
128 g_test_add_func("/contact/new",
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
129 test_purple_contact_new);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
130 g_test_add_func("/contact/properties",
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
131 test_purple_contact_properties);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
132
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
133 return g_test_run();
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
134 }

mercurial