libpurple/tests/test_protocol.c

Tue, 28 Jan 2025 10:56:12 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Tue, 28 Jan 2025 10:56:12 -0600
changeset 43161
920605926071
parent 42877
566102577b66
child 43257
934732945514
permissions
-rw-r--r--

Add Purple.Protocol.generate_account_name

This is the first step in allowing users to assign names to their accounts.

I also did a bunch of house keeping in the existing unit tests.

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

Bugs closed: PIDGIN-17997

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

41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 *
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 * Lesser General Public License for more details.
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 *
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 */
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 #include <glib.h>
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20
42877
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
21 #include <birb.h>
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
22
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include <purple.h>
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 #define TEST_PROTOCOL_DOMAIN (g_quark_from_static_string("test-protocol"))
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 /******************************************************************************
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28 * TestPurpleProtocol
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 *****************************************************************************/
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 #define TEST_PURPLE_TYPE_PROTOCOL (test_purple_protocol_get_type())
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 G_DECLARE_FINAL_TYPE(TestPurpleProtocol,
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 test_purple_protocol,
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 TEST_PURPLE, PROTOCOL,
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 PurpleProtocol)
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 struct _TestPurpleProtocol {
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 PurpleProtocol parent;
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 gboolean result;
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 GError *error;
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41
43161
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
42 guint can_connect_async;
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
43 guint can_connect_finish;
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
44
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
45 guint generate_account_name;
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 };
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47
42576
ab1ca778ddb2 Make sure all of the final types in libpurple are defined as such
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
48 G_DEFINE_FINAL_TYPE(TestPurpleProtocol, test_purple_protocol,
ab1ca778ddb2 Make sure all of the final types in libpurple are defined as such
Gary Kramlich <grim@reaperworld.com>
parents: 42184
diff changeset
49 PURPLE_TYPE_PROTOCOL)
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 static void
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 test_purple_protocol_can_connect_async(PurpleProtocol *protocol,
42089
083eae91c9a8 Update the libpurple tests for the warning level 2 update
Gary Kramlich <grim@reaperworld.com>
parents: 41884
diff changeset
53 G_GNUC_UNUSED PurpleAccount *account,
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 GCancellable *cancellable,
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 GAsyncReadyCallback callback,
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 gpointer data)
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 {
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 TestPurpleProtocol *test_protocol = TEST_PURPLE_PROTOCOL(protocol);
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 GTask *task = NULL;
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 task = g_task_new(protocol, cancellable, callback, data);
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 if(test_protocol->error != NULL) {
42182
3fc2d2b7b7a8 Fix leaked errors
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42089
diff changeset
63 g_task_return_error(task, g_error_copy(test_protocol->error));
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 } else {
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 g_task_return_boolean(task, test_protocol->result);
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 }
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67 g_clear_object(&task);
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68
43161
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
69 test_protocol->can_connect_async += 1;
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70 }
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 static gboolean
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 test_purple_protocol_can_connect_finish(PurpleProtocol *protocol,
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 GAsyncResult *result,
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 GError **error)
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 {
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 TestPurpleProtocol *test_protocol = TEST_PURPLE_PROTOCOL(protocol);
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78
43161
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
79 test_protocol->can_connect_finish += 1;
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81 return g_task_propagate_boolean(G_TASK(result), error);
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 }
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83
43161
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
84 static char *
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
85 test_purple_protocol_generate_account_name(PurpleProtocol *protocol,
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
86 PurpleAccount *account,
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
87 guint n_accounts)
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
88 {
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
89 TestPurpleProtocol *test_protocol = NULL;
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
90
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
91 birb_assert_type(protocol, TEST_PURPLE_TYPE_PROTOCOL);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
92 birb_assert_type(account, PURPLE_TYPE_ACCOUNT);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
93
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
94 test_protocol = TEST_PURPLE_PROTOCOL(protocol);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
95 test_protocol->generate_account_name += 1;
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
96
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
97 return g_strdup_printf("override %u", n_accounts + 1);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
98 }
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
99
42877
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
100 static BirbActionMenu *
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
101 test_purple_protocol_get_action_menu(PurpleProtocol *protocol,
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
102 PurpleAccount *account)
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
103 {
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
104 g_assert_true(PURPLE_IS_PROTOCOL(protocol));
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
105 g_assert_true(PURPLE_IS_ACCOUNT(account));
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
106
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
107 return birb_action_menu_new();
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
108 }
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
109
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110 static void
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 test_purple_protocol_finalize(GObject *obj) {
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112 TestPurpleProtocol *protocol = TEST_PURPLE_PROTOCOL(obj);
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114 g_clear_error(&protocol->error);
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116 G_OBJECT_CLASS(test_purple_protocol_parent_class)->finalize(obj);
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117 }
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
118
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119 static void
43161
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
120 test_purple_protocol_init(G_GNUC_UNUSED TestPurpleProtocol *protocol) {
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
121 }
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123 static void
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124 test_purple_protocol_class_init(TestPurpleProtocolClass *klass)
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125 {
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
126 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
127 PurpleProtocolClass *protocol_class = PURPLE_PROTOCOL_CLASS(klass);
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
128
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
129 obj_class->finalize = test_purple_protocol_finalize;
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
130
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
131 protocol_class->can_connect_async = test_purple_protocol_can_connect_async;
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
132 protocol_class->can_connect_finish = test_purple_protocol_can_connect_finish;
43161
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
133 protocol_class->generate_account_name = test_purple_protocol_generate_account_name;
42877
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
134 protocol_class->get_action_menu = test_purple_protocol_get_action_menu;
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
135 }
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
136
43161
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
137 static PurpleProtocol *
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
138 test_purple_protocol_new(void) {
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
139 return g_object_new(
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
140 TEST_PURPLE_TYPE_PROTOCOL,
43161
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
141 "id", "test-protocol",
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
142 "name", "Test Protocol",
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
143 NULL);
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
144 }
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
145
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
146 /******************************************************************************
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
147 * TestPurpleProtocol->can_connect Tests
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
148 *****************************************************************************/
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
149 static void
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
150 test_purple_protocol_can_connect_cb(GObject *obj, GAsyncResult *res,
42862
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
151 G_GNUC_UNUSED gpointer data)
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
152 {
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
153 PurpleProtocol *protocol = PURPLE_PROTOCOL(obj);
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
154 TestPurpleProtocol *test_protocol = TEST_PURPLE_PROTOCOL(protocol);
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
155 GError *error = NULL;
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
156 gboolean result = FALSE;
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
157
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
158 result = purple_protocol_can_connect_finish(protocol, res, &error);
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
159
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
160 if(test_protocol->error != NULL) {
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
161 g_assert_error(error, TEST_PROTOCOL_DOMAIN, 0);
42182
3fc2d2b7b7a8 Fix leaked errors
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42089
diff changeset
162 g_clear_error(&error);
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
163 } else {
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
164 g_assert_no_error(error);
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
165 }
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
166
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
167 g_assert_true(result == test_protocol->result);
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
168 }
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
169
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
170 static void
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
171 test_purple_protocol_can_connect_error(void) {
43161
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
172 TestPurpleProtocol *test_protocol = NULL;
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
173 PurpleProtocol *protocol = NULL;
42862
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
174 PurpleAccount *account = NULL;
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
175 GError *error = NULL;
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
176
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
177 error = g_error_new(TEST_PROTOCOL_DOMAIN, 0, "no network");
43161
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
178 protocol = test_purple_protocol_new();
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
179 test_protocol = TEST_PURPLE_PROTOCOL(protocol);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
180 test_protocol->error = error;
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
181
42862
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
182 account = purple_account_new("test", "test");
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
183
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
184 purple_protocol_can_connect_async(PURPLE_PROTOCOL(protocol), account, NULL,
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
185 test_purple_protocol_can_connect_cb,
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
186 NULL);
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
187
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
188 g_main_context_iteration(NULL, FALSE);
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
189
43161
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
190 g_assert_cmpuint(test_protocol->can_connect_async, ==, 1);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
191 g_assert_cmpuint(test_protocol->can_connect_finish, ==, 1);
42862
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
192
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
193 g_assert_finalize_object(protocol);
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
194 g_clear_object(&account);
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
195 }
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
196
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
197 static void
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
198 test_purple_protocol_can_connect_false(void) {
43161
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
199 TestPurpleProtocol *test_protocol = NULL;
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
200 PurpleProtocol *protocol = NULL;
42862
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
201 PurpleAccount *account = NULL;
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
202
43161
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
203 protocol = test_purple_protocol_new();
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
204 test_protocol = TEST_PURPLE_PROTOCOL(protocol);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
205 account = purple_account_new("test", "test");
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
206
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
207 purple_protocol_can_connect_async(PURPLE_PROTOCOL(protocol), account, NULL,
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
208 test_purple_protocol_can_connect_cb,
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
209 NULL);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
210
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
211 g_main_context_iteration(NULL, FALSE);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
212
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
213 g_assert_cmpuint(test_protocol->can_connect_async, ==, 1);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
214 g_assert_cmpuint(test_protocol->can_connect_finish, ==, 1);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
215
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
216 g_assert_finalize_object(protocol);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
217 g_clear_object(&account);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
218 }
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
219
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
220 static void
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
221 test_purple_protocol_can_connect_true(void) {
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
222 TestPurpleProtocol *test_protocol = NULL;
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
223 PurpleProtocol *protocol = NULL;
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
224 PurpleAccount *account = NULL;
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
225
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
226 protocol = test_purple_protocol_new();
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
227 test_protocol = TEST_PURPLE_PROTOCOL(protocol);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
228 test_protocol->result = TRUE;
42862
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
229 account = purple_account_new("test", "test");
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
230
42862
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
231 purple_protocol_can_connect_async(PURPLE_PROTOCOL(protocol), account, NULL,
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
232 test_purple_protocol_can_connect_cb,
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
233 NULL);
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
234
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
235 g_main_context_iteration(NULL, FALSE);
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
236
43161
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
237 g_assert_cmpuint(test_protocol->can_connect_async, ==, 1);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
238 g_assert_cmpuint(test_protocol->can_connect_finish, ==, 1);
42862
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
239
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
240 g_assert_finalize_object(protocol);
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
241 g_clear_object(&account);
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
242 }
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
243
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
244 static void
43161
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
245 test_purple_protocol_generate_account_name_default(void) {
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
246 TestPurpleProtocol *test_protocol = NULL;
42862
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
247 PurpleAccount *account = NULL;
43161
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
248 PurpleProtocol *protocol = NULL;
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
249 PurpleProtocolClass *klass = NULL;
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
250 char *name = NULL;
42862
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
251
43161
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
252 protocol = test_purple_protocol_new();
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
253 test_protocol = TEST_PURPLE_PROTOCOL(protocol);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
254 klass = PURPLE_PROTOCOL_GET_CLASS(protocol);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
255 klass->generate_account_name = PURPLE_PROTOCOL_CLASS(test_purple_protocol_parent_class)->generate_account_name;
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
256
42862
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
257 account = purple_account_new("test", "test");
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
258
43161
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
259 name = purple_protocol_generate_account_name(protocol, account, 0);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
260 g_assert_cmpstr(name, ==, "Test Protocol 1");
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
261 g_clear_pointer(&name, g_free);
42862
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
262
43161
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
263 name = purple_protocol_generate_account_name(protocol, account, 9);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
264 g_assert_cmpstr(name, ==, "Test Protocol 10");
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
265 g_clear_pointer(&name, g_free);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
266
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
267 g_assert_cmpuint(test_protocol->generate_account_name, ==, 0);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
268
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
269 g_assert_finalize_object(account);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
270 g_assert_finalize_object(protocol);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
271 }
42862
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
272
43161
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
273 static void
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
274 test_purple_protocol_generate_account_name_override(void) {
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
275 TestPurpleProtocol *test_protocol = NULL;
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
276 PurpleAccount *account = NULL;
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
277 PurpleProtocol *protocol = NULL;
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
278 char *name = NULL;
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
279
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
280 protocol = test_purple_protocol_new();
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
281 test_protocol = TEST_PURPLE_PROTOCOL(protocol);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
282
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
283 account = purple_account_new("test", "test");
42862
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
284
43161
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
285 name = purple_protocol_generate_account_name(protocol, account, 0);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
286 g_assert_cmpstr(name, ==, "override 1");
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
287 g_clear_pointer(&name, g_free);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
288
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
289 name = purple_protocol_generate_account_name(protocol, account, 9);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
290 g_assert_cmpstr(name, ==, "override 10");
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
291 g_clear_pointer(&name, g_free);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
292
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
293 g_assert_cmpuint(test_protocol->generate_account_name, ==, 2);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
294
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
295 g_assert_finalize_object(account);
42862
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
296 g_assert_finalize_object(protocol);
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
297 }
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
298
42877
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
299 static void
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
300 test_purple_protocol_get_action_menu_valid(void) {
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
301 PurpleProtocol *protocol = NULL;
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
302 PurpleAccount *account = NULL;
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
303 BirbActionMenu *action_menu = NULL;
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
304
43161
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
305 protocol = test_purple_protocol_new();
42877
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
306 account = purple_account_new("test", "test");
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
307
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
308 action_menu = purple_protocol_get_action_menu(protocol, account);
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
309 g_assert_true(BIRB_IS_ACTION_MENU(action_menu));
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
310 g_clear_object(&action_menu);
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
311
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
312 g_clear_object(&account);
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
313 g_assert_finalize_object(protocol);
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
314 }
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
315
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
316 /******************************************************************************
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
317 * Main
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
318 *****************************************************************************/
42862
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
319 int
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
320 main(int argc, char *argv[]) {
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
321 g_test_init(&argc, &argv, NULL);
42862
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
322 g_test_set_nonfatal_assertions();
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
323
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
324 g_test_add_func("/protocol/can-connect/error",
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
325 test_purple_protocol_can_connect_error);
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
326 g_test_add_func("/protocol/can-connect/false",
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
327 test_purple_protocol_can_connect_false);
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
328 g_test_add_func("/protocol/can-connect/true",
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
329 test_purple_protocol_can_connect_true);
43161
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
330
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
331 g_test_add_func("/protocol/generate-account-name/override",
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
332 test_purple_protocol_generate_account_name_override);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
333 g_test_add_func("/protocol/generate-account-name/default",
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
334 test_purple_protocol_generate_account_name_default);
920605926071 Add Purple.Protocol.generate_account_name
Gary Kramlich <grim@reaperworld.com>
parents: 42877
diff changeset
335
42877
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
336 g_test_add_func("/protocol/get-action-menu/valid",
566102577b66 Add Purple.Protocol.get_action_menu
Gary Kramlich <grim@reaperworld.com>
parents: 42862
diff changeset
337 test_purple_protocol_get_action_menu_valid);
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
338
42862
ffd03c26426a Modernize the protocol tests
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
339 return g_test_run();
41884
36684da1e60d Add async function to PurpleProtocol for testing whether or not connections are possible
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
340 }

mercurial