libpurple/tests/test_account_manager.c

Sat, 09 Aug 2025 17:37:27 +0800

author
Gong Zhile <gongzl@stu.hebust.edu.cn>
date
Sat, 09 Aug 2025 17:37:27 +0800
branch
bird-header-fix
changeset 43304
2599d35e9750
parent 42853
051b8f911409
permissions
-rw-r--r--

Fix the birb header path

The birb header referred would only work with birb provided by wrap casuing
build to fail because of system-installed birb dependency. The commit points
it to the correct path <birb.h>.

See: https://keep.imfreedom.org/birb/birb/file/5bf00c7d7f80/birb/meson.build#l77

41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 *
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 * Lesser General Public License for more details.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 *
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 #include <glib.h>
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 #include <purple.h>
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 /******************************************************************************
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24 * Add/Remove Test
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 *****************************************************************************/
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26 static void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 test_purple_account_manager_signal_called(G_GNUC_UNUSED PurpleAccountManager *manager,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28 G_GNUC_UNUSED PurpleAccount *account,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 gpointer data)
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 gboolean *called = (data);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 *called = TRUE;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 static void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 test_purple_account_manager_add_remove(void) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 PurpleAccount *account = NULL;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 PurpleAccountManager *manager = NULL;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 gboolean signal_called = FALSE;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 account = purple_account_new("test", "test");
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 manager = g_object_new(PURPLE_TYPE_ACCOUNT_MANAGER, NULL);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 g_signal_connect(manager, "added",
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 G_CALLBACK(test_purple_account_manager_signal_called),
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 &signal_called);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48 g_signal_connect(manager, "removed",
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 G_CALLBACK(test_purple_account_manager_signal_called),
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 &signal_called);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41641
diff changeset
52 g_assert_cmpuint(g_list_model_get_n_items(G_LIST_MODEL(manager)), ==, 0);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 /* Add the account and verify that it was added and that the signal was
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 * emitted.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 purple_account_manager_add(manager, account);
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41641
diff changeset
58 g_assert_cmpuint(g_list_model_get_n_items(G_LIST_MODEL(manager)), ==, 1);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 g_assert_true(signal_called);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 signal_called = FALSE;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 /* Remove the account and verify that it was removed and that the signal
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 * was emitted.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 purple_account_manager_remove(manager, account);
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41641
diff changeset
67 g_assert_cmpuint(g_list_model_get_n_items(G_LIST_MODEL(manager)), ==, 0);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 g_assert_true(signal_called);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70 /* Cleanup */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 g_clear_object(&account);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 g_clear_object(&manager);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 /******************************************************************************
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 * Find Tests
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 *****************************************************************************/
41641
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41181
diff changeset
78 static gboolean
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41181
diff changeset
79 test_purple_account_manager_find_func(gconstpointer a, gconstpointer b) {
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41181
diff changeset
80 PurpleAccount *account = PURPLE_ACCOUNT((gpointer)a);
42853
051b8f911409 Remove the test ui from the account manager tests
Gary Kramlich <grim@reaperworld.com>
parents: 42805
diff changeset
81 const char *desired_username = b;
051b8f911409 Remove the test ui from the account manager tests
Gary Kramlich <grim@reaperworld.com>
parents: 42805
diff changeset
82 const char *protocol_id = NULL;
051b8f911409 Remove the test ui from the account manager tests
Gary Kramlich <grim@reaperworld.com>
parents: 42805
diff changeset
83 const char *username = NULL;
41641
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41181
diff changeset
84
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41181
diff changeset
85 /* Check if the protocol id matches expected. */
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41181
diff changeset
86 protocol_id = purple_account_get_protocol_id(account);
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41181
diff changeset
87 if(!purple_strequal(protocol_id, "test")) {
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41181
diff changeset
88 return FALSE;
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41181
diff changeset
89 }
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41181
diff changeset
90
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41181
diff changeset
91 /* Finally verify the username. */
42805
3e77e81168a5 Update libpurple to use get id and username directly on PurpleAccount
Gary Kramlich <grim@reaperworld.com>
parents: 42291
diff changeset
92 username = purple_account_get_username(account);
41641
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41181
diff changeset
93 if(!purple_strequal(username, desired_username)) {
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41181
diff changeset
94 return FALSE;
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41181
diff changeset
95 }
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41181
diff changeset
96
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41181
diff changeset
97 return TRUE;
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41181
diff changeset
98 }
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41181
diff changeset
99
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100 static void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101 test_purple_account_manager_find(void) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102 PurpleAccount *account = NULL, *found = NULL;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
103 PurpleAccountManager *manager = NULL;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105 manager = g_object_new(PURPLE_TYPE_ACCOUNT_MANAGER, NULL);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107 /* Try to find an account that doesn't exist. */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108 found = purple_account_manager_find(manager, "test", "test");
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109 g_assert_null(found);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 /* Create the account that will be used in the rest of the test. */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112 account = purple_account_new("test", "test");
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114 /* Now add an account and verify that we can find it. */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115 purple_account_manager_add(manager, account);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116 found = purple_account_manager_find(manager, "test", "test");
42291
a86b7bcbb471 Make the purple_account_manager_find functions return transfer full.
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
117 g_assert_true(PURPLE_IS_ACCOUNT(found));
a86b7bcbb471 Make the purple_account_manager_find functions return transfer full.
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
118 g_clear_object(&found);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119
41641
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41181
diff changeset
120 /* Verify account can be found using a custom function. */
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41181
diff changeset
121 found = purple_account_manager_find_custom(manager,
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41181
diff changeset
122 test_purple_account_manager_find_func,
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41181
diff changeset
123 "test");
42291
a86b7bcbb471 Make the purple_account_manager_find functions return transfer full.
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
124 g_assert_true(PURPLE_IS_ACCOUNT(found));
a86b7bcbb471 Make the purple_account_manager_find functions return transfer full.
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
125 g_clear_object(&found);
41641
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41181
diff changeset
126
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
127 /* Finally remove the account and verify it can't be found. */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
128 purple_account_manager_remove(manager, account);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
129 found = purple_account_manager_find(manager, "test", "test");
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
130 g_assert_null(found);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
131
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
132 /* Cleanup */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
133 g_clear_object(&account);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
134 g_clear_object(&manager);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
135 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
136
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
137 /******************************************************************************
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
138 * Foreach Tests
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
139 *****************************************************************************/
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
140 static void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
141 test_purple_account_manager_foreach_func(G_GNUC_UNUSED PurpleAccount *account,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
142 gpointer data)
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
143 {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
144 guint *count = (guint *)data;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
145
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
146 /* We have to use (*count)++ because *count++ doesn't work as the ++
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
147 * happens after the statement which is no longer the dereferenced pointer.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
148 */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
149 (*count)++;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
150 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
151
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
152 static void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
153 test_purple_account_manager_foreach(void) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
154 PurpleAccount *accounts[3];
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
155 PurpleAccountManager *manager = NULL;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
156 guint count = 0;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
157
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
158 manager = g_object_new(PURPLE_TYPE_ACCOUNT_MANAGER, NULL);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
159
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
160 accounts[0] = purple_account_new("test0", "test");
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
161 accounts[1] = purple_account_new("test1", "test");
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
162 accounts[2] = purple_account_new("test2", "test");
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
163
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
164 purple_account_manager_add(manager, accounts[0]);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
165 purple_account_manager_add(manager, accounts[1]);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
166 purple_account_manager_add(manager, accounts[2]);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
167
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
168 purple_account_manager_foreach(manager,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
169 test_purple_account_manager_foreach_func,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
170 &count);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
171
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
172 g_assert_cmpuint(count, ==, 3);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
173
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
174 /* Now remove everything and verify that the foreach callback wasn't
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
175 * called.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
176 */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
177 purple_account_manager_remove(manager, accounts[0]);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
178 purple_account_manager_remove(manager, accounts[1]);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
179 purple_account_manager_remove(manager, accounts[2]);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
180
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
181 count = 0;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
182 purple_account_manager_foreach(manager,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
183 test_purple_account_manager_foreach_func,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
184 &count);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
185
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
186 g_assert_cmpuint(count, ==, 0);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
187
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
188 /* Cleanup */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
189 g_clear_object(&accounts[0]);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
190 g_clear_object(&accounts[1]);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
191 g_clear_object(&accounts[2]);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
192 g_clear_object(&manager);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
193 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
194
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
195 /******************************************************************************
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
196 * Main
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
197 *****************************************************************************/
42853
051b8f911409 Remove the test ui from the account manager tests
Gary Kramlich <grim@reaperworld.com>
parents: 42805
diff changeset
198 int
051b8f911409 Remove the test ui from the account manager tests
Gary Kramlich <grim@reaperworld.com>
parents: 42805
diff changeset
199 main(int argc, char *argv[]) {
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
200 g_test_init(&argc, &argv, NULL);
42853
051b8f911409 Remove the test ui from the account manager tests
Gary Kramlich <grim@reaperworld.com>
parents: 42805
diff changeset
201 g_test_set_nonfatal_assertions();
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
202
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
203 g_test_add_func("/account-manager/add-remove",
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
204 test_purple_account_manager_add_remove);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
205 g_test_add_func("/account-manager/find",
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
206 test_purple_account_manager_find);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
207 g_test_add_func("/account-manager/foreach",
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
208 test_purple_account_manager_foreach);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
209
42853
051b8f911409 Remove the test ui from the account manager tests
Gary Kramlich <grim@reaperworld.com>
parents: 42805
diff changeset
210 return g_test_run();
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
211 }

mercurial