Fri, 10 Jun 2022 20:42:36 -0500
fix memory leak when using purple accounts
Testing Done:
ran test_account_manager and test_notification (from /r/1502 where I first encountered that leak) in valgrind -> no more leak and no new invalid read/write
Reviewed at https://reviews.imfreedom.org/r/1503/
|
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 | #include "test_ui.h" |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
24 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
25 | #define PURPLE_GLOBAL_HEADER_INSIDE |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
26 | #include "../purpleprivate.h" |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
27 | #undef PURPLE_GLOBAL_HEADER_INSIDE |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
28 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
29 | /****************************************************************************** |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
30 | * Tests |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
31 | *****************************************************************************/ |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
32 | static void |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
33 | test_purple_account_manager_get_default(void) { |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
34 | PurpleAccountManager *manager1 = NULL, *manager2 = NULL; |
|
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 | manager1 = purple_account_manager_get_default(); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
37 | g_assert_true(PURPLE_IS_ACCOUNT_MANAGER(manager1)); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
38 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
39 | manager2 = purple_account_manager_get_default(); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
40 | g_assert_true(PURPLE_IS_ACCOUNT_MANAGER(manager2)); |
|
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 | g_assert_true(manager1 == manager2); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
43 | } |
|
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 | /****************************************************************************** |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
46 | * Add/Remove Test |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
47 | *****************************************************************************/ |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
48 | static void |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
49 | test_purple_account_manager_signal_called(G_GNUC_UNUSED PurpleAccountManager *manager, |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
50 | G_GNUC_UNUSED PurpleAccount *account, |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
51 | gpointer data) |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
52 | { |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
53 | gboolean *called = (data); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
54 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
55 | *called = TRUE; |
|
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 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
58 | static void |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
59 | test_purple_account_manager_add_remove(void) { |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
60 | PurpleAccount *account = NULL; |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
61 | PurpleAccountManager *manager = NULL; |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
62 | GList *accounts = NULL; |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
63 | gboolean signal_called = FALSE; |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
64 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
65 | account = purple_account_new("test", "test"); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
66 | manager = g_object_new(PURPLE_TYPE_ACCOUNT_MANAGER, NULL); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
67 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
68 | g_signal_connect(manager, "added", |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
69 | G_CALLBACK(test_purple_account_manager_signal_called), |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
70 | &signal_called); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
71 | g_signal_connect(manager, "removed", |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
72 | G_CALLBACK(test_purple_account_manager_signal_called), |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
73 | &signal_called); |
|
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 | accounts = purple_account_manager_get_all(manager); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
76 | g_assert_true(g_list_length(accounts) == 0); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
77 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
78 | /* 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
|
79 | * emitted. |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
80 | */ |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
81 | purple_account_manager_add(manager, account); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
82 | accounts = purple_account_manager_get_all(manager); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
83 | g_assert_true(g_list_length(accounts) == 1); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
84 | g_assert_true(signal_called); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
85 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
86 | signal_called = FALSE; |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
87 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
88 | /* 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
|
89 | * was emitted. |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
90 | */ |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
91 | purple_account_manager_remove(manager, account); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
92 | accounts = purple_account_manager_get_all(manager); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
93 | g_assert_true(g_list_length(accounts) == 0); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
94 | g_assert_true(signal_called); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
95 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
96 | /* Cleanup */ |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
97 | g_clear_object(&account); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
98 | g_clear_object(&manager); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
99 | } |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
100 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
101 | /****************************************************************************** |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
102 | * Find Tests |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
103 | *****************************************************************************/ |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
104 | static void |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
105 | test_purple_account_manager_find(void) { |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
106 | PurpleAccount *account = NULL, *found = NULL; |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
107 | PurpleAccountManager *manager = NULL; |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
108 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
109 | manager = g_object_new(PURPLE_TYPE_ACCOUNT_MANAGER, NULL); |
|
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 | /* Try to find an account that doesn't exist. */ |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
112 | found = purple_account_manager_find(manager, "test", "test"); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
113 | g_assert_null(found); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
114 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
115 | /* 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
|
116 | account = purple_account_new("test", "test"); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
117 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
118 | /* Now add an account and verify that we can find it. */ |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
119 | purple_account_manager_add(manager, account); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
120 | found = purple_account_manager_find(manager, "test", "test"); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
121 | g_assert_nonnull(found); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
122 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
123 | /* Finally remove the account and verify it can't be found. */ |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
124 | purple_account_manager_remove(manager, account); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
125 | found = purple_account_manager_find(manager, "test", "test"); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
126 | g_assert_null(found); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
127 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
128 | /* Cleanup */ |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
129 | g_clear_object(&account); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
130 | g_clear_object(&manager); |
|
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 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
133 | /****************************************************************************** |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
134 | * Foreach Tests |
|
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 | static void |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
137 | test_purple_account_manager_foreach_func(G_GNUC_UNUSED PurpleAccount *account, |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
138 | gpointer data) |
|
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 | guint *count = (guint *)data; |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
141 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
142 | /* 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
|
143 | * happens after the statement which is no longer the dereferenced pointer. |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
144 | */ |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
145 | (*count)++; |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
146 | } |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
147 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
148 | static void |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
149 | test_purple_account_manager_foreach(void) { |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
150 | PurpleAccount *accounts[3]; |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
151 | PurpleAccountManager *manager = NULL; |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
152 | guint count = 0; |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
153 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
154 | manager = g_object_new(PURPLE_TYPE_ACCOUNT_MANAGER, NULL); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
155 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
156 | accounts[0] = purple_account_new("test0", "test"); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
157 | accounts[1] = purple_account_new("test1", "test"); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
158 | accounts[2] = purple_account_new("test2", "test"); |
|
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 | purple_account_manager_add(manager, accounts[0]); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
161 | purple_account_manager_add(manager, accounts[1]); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
162 | purple_account_manager_add(manager, accounts[2]); |
|
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_foreach(manager, |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
165 | test_purple_account_manager_foreach_func, |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
166 | &count); |
|
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 | g_assert_cmpuint(count, ==, 3); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
169 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
170 | /* Now remove everything and verify that the foreach callback wasn't |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
171 | * called. |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
172 | */ |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
173 | purple_account_manager_remove(manager, accounts[0]); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
174 | purple_account_manager_remove(manager, accounts[1]); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
175 | purple_account_manager_remove(manager, accounts[2]); |
|
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 | count = 0; |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
178 | purple_account_manager_foreach(manager, |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
179 | test_purple_account_manager_foreach_func, |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
180 | &count); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
181 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
182 | g_assert_cmpuint(count, ==, 0); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
183 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
184 | /* Cleanup */ |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
185 | g_clear_object(&accounts[0]); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
186 | g_clear_object(&accounts[1]); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
187 | g_clear_object(&accounts[2]); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
188 | g_clear_object(&manager); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
189 | } |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
190 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
191 | /****************************************************************************** |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
192 | * Main |
|
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 | gint |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
195 | main(gint argc, gchar *argv[]) { |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
196 | g_test_init(&argc, &argv, NULL); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
197 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
198 | test_ui_purple_init(); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
199 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
200 | g_test_add_func("/account-manager/get-default", |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
201 | test_purple_account_manager_get_default); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
202 | g_test_add_func("/account-manager/add-remove", |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
203 | test_purple_account_manager_add_remove); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
204 | g_test_add_func("/account-manager/find", |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
205 | test_purple_account_manager_find); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
206 | g_test_add_func("/account-manager/foreach", |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
207 | test_purple_account_manager_foreach); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
208 | |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
209 | return g_test_run(); |
|
e859c41d8996
Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
210 | } |