libpurple/tests/test_contact.c

Mon, 28 Nov 2022 23:48:33 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Mon, 28 Nov 2022 23:48:33 -0600
changeset 41948
6d844d2faff1
parent 41930
0472e404b129
child 42184
4e1bf25f5575
permissions
-rw-r--r--

Split PurpleContactInfo out of PurpleContact

This change separates all of the data away from the runtime information which
makes it easier to store contacts with everything.

Testing Done:
Ran the unit tests and sent a few messages with ircv3 and demo protocols.

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

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;
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41930
diff changeset
32 PurpleContactInfo *info = NULL;
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 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
35 contact = purple_contact_new(account, "id");
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41930
diff changeset
36 info = PURPLE_CONTACT_INFO(contact);
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 g_assert_true(purple_contact_get_account(contact) == account);
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41930
diff changeset
39 g_assert_cmpstr(purple_contact_info_get_id(info), ==, "id");
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 g_clear_object(&contact);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 g_clear_object(&account);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 static void
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 test_purple_contact_properties(void) {
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 PurpleAccount *account = NULL;
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48 PurpleAccount *account1 = NULL;
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 PurpleContact *contact = NULL;
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41930
diff changeset
50 char *id = NULL;
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 account = purple_account_new("test", "test");
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 /* 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
55 * 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
56 * code.
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 */
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 contact = g_object_new(
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 PURPLE_TYPE_CONTACT,
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 "account", account,
41759
1ecc0512e714 Make purple_contact_new take the id instead of the username.
Gary Kramlich <grim@reaperworld.com>
parents: 41755
diff changeset
61 "id", "id1",
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 NULL);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 /* Now use g_object_get to read all of the properties. */
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 g_object_get(contact,
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 "id", &id,
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67 "account", &account1,
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 NULL);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70 /* 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
71 g_assert_cmpstr(id, ==, "id1");
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 g_assert_true(account1 == account);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 /* Free/unref all the things. */
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 g_clear_pointer(&id, g_free);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 g_clear_object(&account1);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 g_clear_object(&contact);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78 g_clear_object(&account);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81 /******************************************************************************
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 * Main
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83 *****************************************************************************/
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84 gint
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85 main(gint argc, gchar *argv[]) {
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86 g_test_init(&argc, &argv, NULL);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
88 test_ui_purple_init();
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
89
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90 g_test_add_func("/contact/new",
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91 test_purple_contact_new);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92 g_test_add_func("/contact/properties",
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93 test_purple_contact_properties);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95 return g_test_run();
41918
106ae46b290b Add a permission property to PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
96 }

mercurial