libpurple/tests/test_protocol_file_transfer.c

Wed, 14 Aug 2024 19:26:26 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Wed, 14 Aug 2024 19:26:26 -0500
changeset 42874
c53e5e1ff6b1
parent 42868
213d7b930ba5
permissions
-rw-r--r--

Remove uri handling from libpurple

Testing Done:
Called in the turtles.

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

42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * Purple is the legal property of its developers, whose names are too numerous
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * to list here. Please refer to the COPYRIGHT file distributed with this
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * source distribution.
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 *
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * (at your option) any later version.
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 *
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 * GNU General Public License for more details.
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18 *
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20 * along with this program; if not, see <https://www.gnu.org/licenses/>.
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 */
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include <glib.h>
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 #include <purple.h>
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
27 #define TEST_PURPLE_PROTOCOL_FILE_TRANSFER_DOMAIN \
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
28 (g_quark_from_static_string("test-protocol-file-transfer"))
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 /******************************************************************************
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 * TestProtocolFileTransferEmpty implementation
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 *****************************************************************************/
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 G_DECLARE_FINAL_TYPE(TestPurpleProtocolFileTransferEmpty,
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 test_purple_protocol_file_transfer_empty,
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 TEST_PURPLE, PROTOCOL_FILE_TRANSFER_EMPTY, PurpleProtocol)
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 struct _TestPurpleProtocolFileTransferEmpty {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 PurpleProtocol parent;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 };
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 static void
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 test_purple_protocol_file_transfer_empty_iface_init(G_GNUC_UNUSED PurpleProtocolFileTransferInterface *iface)
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45
42576
ab1ca778ddb2 Make sure all of the final types in libpurple are defined as such
Gary Kramlich <grim@reaperworld.com>
parents: 42375
diff changeset
46 G_DEFINE_FINAL_TYPE_WITH_CODE(TestPurpleProtocolFileTransferEmpty,
ab1ca778ddb2 Make sure all of the final types in libpurple are defined as such
Gary Kramlich <grim@reaperworld.com>
parents: 42375
diff changeset
47 test_purple_protocol_file_transfer_empty,
ab1ca778ddb2 Make sure all of the final types in libpurple are defined as such
Gary Kramlich <grim@reaperworld.com>
parents: 42375
diff changeset
48 PURPLE_TYPE_PROTOCOL,
ab1ca778ddb2 Make sure all of the final types in libpurple are defined as such
Gary Kramlich <grim@reaperworld.com>
parents: 42375
diff changeset
49 G_IMPLEMENT_INTERFACE(PURPLE_TYPE_PROTOCOL_FILE_TRANSFER,
ab1ca778ddb2 Make sure all of the final types in libpurple are defined as such
Gary Kramlich <grim@reaperworld.com>
parents: 42375
diff changeset
50 test_purple_protocol_file_transfer_empty_iface_init))
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 static void
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 test_purple_protocol_file_transfer_empty_init(G_GNUC_UNUSED TestPurpleProtocolFileTransferEmpty *empty)
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 static void
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 test_purple_protocol_file_transfer_empty_class_init(G_GNUC_UNUSED TestPurpleProtocolFileTransferEmptyClass *klass)
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 /******************************************************************************
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 * TestProtocolFileTransferEmpty Tests
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 *****************************************************************************/
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 static void
42821
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
66 test_purple_protocol_file_transfer_empty_send_cb(GObject *source,
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
67 GAsyncResult *result,
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
68 G_GNUC_UNUSED gpointer data)
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
69 {
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
70 PurpleProtocolFileTransfer *protocol = NULL;
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
71 GError *error = NULL;
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
72 gboolean success = FALSE;
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73
42821
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
74 g_assert_true(PURPLE_IS_PROTOCOL_FILE_TRANSFER(source));
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
75 protocol = PURPLE_PROTOCOL_FILE_TRANSFER(source);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76
42821
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
77 success = purple_protocol_file_transfer_send_finish(protocol, result,
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
78 &error);
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
79 g_assert_error(error, PURPLE_PROTOCOL_FILE_TRANSFER_ERROR, 0);
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
80 g_clear_error(&error);
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
81 g_assert_false(success);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84 static void
42821
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
85 test_purple_protocol_file_transfer_empty_send(gconstpointer data) {
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
86 PurpleAccount *account = NULL;
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
87 PurpleContactInfo *remote = NULL;
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
88 PurpleFileTransfer *transfer = NULL;
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
89 PurpleProtocolFileTransfer *protocol_file_transfer = NULL;
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
90 GFile *local_file = NULL;
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91
42821
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
92 account = purple_account_new("test", "test");
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
93 remote = purple_contact_info_new(NULL);
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
94 local_file = g_file_new_for_path(data);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95
42821
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
96 transfer = purple_file_transfer_new_send(account, remote, local_file);
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
97 g_clear_object(&account);
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
98 g_clear_object(&remote);
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
99 g_clear_object(&local_file);
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
100
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
101 protocol_file_transfer = g_object_new(test_purple_protocol_file_transfer_empty_get_type(),
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
102 NULL);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
103
42821
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
104 purple_protocol_file_transfer_send_async(protocol_file_transfer,
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
105 transfer,
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
106 test_purple_protocol_file_transfer_empty_send_cb,
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
107 NULL);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108
42821
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
109 g_main_context_iteration(NULL, FALSE);
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
110
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
111 g_assert_finalize_object(transfer);
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
112 g_assert_finalize_object(protocol_file_transfer);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115 static void
42821
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
116 test_purple_protocol_file_transfer_empty_receive_cb(GObject *source,
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
117 GAsyncResult *result,
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
118 G_GNUC_UNUSED gpointer data)
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
119 {
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
120 PurpleProtocolFileTransfer *protocol = NULL;
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
121 GError *error = NULL;
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
122 gboolean success = FALSE;
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123
42821
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
124 g_assert_true(PURPLE_IS_PROTOCOL_FILE_TRANSFER(source));
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
125 protocol = PURPLE_PROTOCOL_FILE_TRANSFER(source);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
126
42821
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
127 success = purple_protocol_file_transfer_receive_finish(protocol, result,
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
128 &error);
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
129 g_assert_error(error, PURPLE_PROTOCOL_FILE_TRANSFER_ERROR, 0);
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
130 g_clear_error(&error);
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
131 g_assert_false(success);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
132 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
133
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
134 static void
42821
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
135 test_purple_protocol_file_transfer_empty_receive(void) {
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
136 PurpleAccount *account = NULL;
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
137 PurpleContactInfo *remote = NULL;
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
138 PurpleFileTransfer *transfer = NULL;
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
139 PurpleProtocolFileTransfer *protocol_file_transfer = NULL;
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
140
42821
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
141 account = purple_account_new("test", "test");
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
142 remote = purple_contact_info_new(NULL);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
143
42821
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
144 transfer = purple_file_transfer_new_receive(account, remote,
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
145 "file.png", 0);
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
146 g_clear_object(&account);
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
147 g_clear_object(&remote);
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
148
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
149 protocol_file_transfer = g_object_new(test_purple_protocol_file_transfer_empty_get_type(),
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
150 NULL);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
151
42821
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
152 purple_protocol_file_transfer_receive_async(protocol_file_transfer,
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
153 transfer,
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
154 test_purple_protocol_file_transfer_empty_receive_cb,
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
155 NULL);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
156
42821
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
157 g_main_context_iteration(NULL, FALSE);
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
158
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
159 g_assert_finalize_object(transfer);
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
160 g_assert_finalize_object(protocol_file_transfer);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
161 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
162
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
163 /******************************************************************************
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
164 * TestProtocolFileTransfer implementation
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
165 *****************************************************************************/
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
166 G_DECLARE_FINAL_TYPE(TestPurpleProtocolFileTransfer,
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
167 test_purple_protocol_file_transfer, TEST_PURPLE,
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
168 PROTOCOL_FILE_TRANSFER, PurpleProtocol)
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
169
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
170 struct _TestPurpleProtocolFileTransfer {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
171 PurpleProtocol parent;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
172
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
173 gboolean should_error;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
174
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
175 guint send_async;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
176 guint send_finish;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
177 guint receive_async;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
178 guint receive_finish;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
179 };
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
180
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
181 static void
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
182 test_purple_protocol_file_transfer_send_async(PurpleProtocolFileTransfer *r,
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
183 PurpleFileTransfer *transfer,
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
184 GAsyncReadyCallback callback,
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
185 gpointer data)
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
186 {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
187 TestPurpleProtocolFileTransfer *protocol_file_transfer = NULL;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
188 GCancellable *cancellable = NULL;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
189 GTask *task = NULL;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
190
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
191 protocol_file_transfer = TEST_PURPLE_PROTOCOL_FILE_TRANSFER(r);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
192 protocol_file_transfer->send_async += 1;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
193
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
194 cancellable = purple_file_transfer_get_cancellable(transfer);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
195
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
196 task = g_task_new(r, cancellable, callback, data);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
197 if(protocol_file_transfer->should_error) {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
198 GError *error = g_error_new_literal(TEST_PURPLE_PROTOCOL_FILE_TRANSFER_DOMAIN,
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
199 0, "error");
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
200 g_task_return_error(task, error);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
201 } else {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
202 g_task_return_boolean(task, TRUE);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
203 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
204
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
205 g_clear_object(&task);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
206 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
207
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
208 static gboolean
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
209 test_purple_protocol_file_transfer_send_finish(PurpleProtocolFileTransfer *r,
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
210 GAsyncResult *result,
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
211 GError **error)
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
212 {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
213 TestPurpleProtocolFileTransfer *protocol_file_transfer = NULL;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
214
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
215 protocol_file_transfer = TEST_PURPLE_PROTOCOL_FILE_TRANSFER(r);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
216 protocol_file_transfer->send_finish += 1;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
217
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
218 return g_task_propagate_boolean(G_TASK(result), error);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
219 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
220
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
221 static void
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
222 test_purple_protocol_file_transfer_receive_async(PurpleProtocolFileTransfer *r,
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
223 PurpleFileTransfer *transfer,
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
224 GAsyncReadyCallback callback,
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
225 gpointer data)
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
226 {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
227 TestPurpleProtocolFileTransfer *protocol_file_transfer = NULL;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
228 GCancellable *cancellable = NULL;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
229 GTask *task = NULL;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
230
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
231 protocol_file_transfer = TEST_PURPLE_PROTOCOL_FILE_TRANSFER(r);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
232 protocol_file_transfer->receive_async += 1;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
233
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
234 cancellable = purple_file_transfer_get_cancellable(transfer);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
235
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
236 task = g_task_new(r, cancellable, callback, data);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
237 if(protocol_file_transfer->should_error) {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
238 GError *error = g_error_new_literal(TEST_PURPLE_PROTOCOL_FILE_TRANSFER_DOMAIN,
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
239 0, "error");
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
240 g_task_return_error(task, error);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
241 } else {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
242 g_task_return_boolean(task, TRUE);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
243 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
244
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
245 g_clear_object(&task);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
246 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
247
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
248 static gboolean
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
249 test_purple_protocol_file_transfer_receive_finish(PurpleProtocolFileTransfer *r,
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
250 GAsyncResult *result,
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
251 GError **error)
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
252 {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
253 TestPurpleProtocolFileTransfer *protocol_file_transfer = NULL;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
254
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
255 protocol_file_transfer = TEST_PURPLE_PROTOCOL_FILE_TRANSFER(r);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
256 protocol_file_transfer->receive_finish += 1;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
257
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
258 return g_task_propagate_boolean(G_TASK(result), error);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
259 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
260
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
261 static void
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
262 test_purple_protocol_file_transfer_iface_init(PurpleProtocolFileTransferInterface *iface) {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
263 iface->send_async = test_purple_protocol_file_transfer_send_async;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
264 iface->send_finish = test_purple_protocol_file_transfer_send_finish;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
265 iface->receive_async = test_purple_protocol_file_transfer_receive_async;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
266 iface->receive_finish = test_purple_protocol_file_transfer_receive_finish;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
267 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
268
42576
ab1ca778ddb2 Make sure all of the final types in libpurple are defined as such
Gary Kramlich <grim@reaperworld.com>
parents: 42375
diff changeset
269 G_DEFINE_FINAL_TYPE_WITH_CODE(TestPurpleProtocolFileTransfer,
ab1ca778ddb2 Make sure all of the final types in libpurple are defined as such
Gary Kramlich <grim@reaperworld.com>
parents: 42375
diff changeset
270 test_purple_protocol_file_transfer,
ab1ca778ddb2 Make sure all of the final types in libpurple are defined as such
Gary Kramlich <grim@reaperworld.com>
parents: 42375
diff changeset
271 PURPLE_TYPE_PROTOCOL,
ab1ca778ddb2 Make sure all of the final types in libpurple are defined as such
Gary Kramlich <grim@reaperworld.com>
parents: 42375
diff changeset
272 G_IMPLEMENT_INTERFACE(PURPLE_TYPE_PROTOCOL_FILE_TRANSFER,
ab1ca778ddb2 Make sure all of the final types in libpurple are defined as such
Gary Kramlich <grim@reaperworld.com>
parents: 42375
diff changeset
273 test_purple_protocol_file_transfer_iface_init))
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
274
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
275 static void
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
276 test_purple_protocol_file_transfer_init(TestPurpleProtocolFileTransfer *protocol_file_transfer)
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
277 {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
278 protocol_file_transfer->send_async = 0;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
279 protocol_file_transfer->send_finish = 0;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
280 protocol_file_transfer->receive_async = 0;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
281 protocol_file_transfer->receive_finish = 0;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
282 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
283
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
284 static void
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
285 test_purple_protocol_file_transfer_class_init(G_GNUC_UNUSED TestPurpleProtocolFileTransferClass *klass)
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
286 {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
287 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
288
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
289 /******************************************************************************
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
290 * TestProtocolFileTransfer send tests
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
291 *****************************************************************************/
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
292 static void
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
293 test_purple_protocol_file_transfer_send_cb(GObject *obj, GAsyncResult *res,
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
294 G_GNUC_UNUSED gpointer data)
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
295 {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
296 TestPurpleProtocolFileTransfer *test_protocol_file_transfer = NULL;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
297 PurpleProtocolFileTransfer *protocol_file_transfer = NULL;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
298 GError *error = NULL;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
299 gboolean result = FALSE;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
300
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
301 protocol_file_transfer = PURPLE_PROTOCOL_FILE_TRANSFER(obj);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
302 test_protocol_file_transfer = TEST_PURPLE_PROTOCOL_FILE_TRANSFER(obj);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
303
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
304 result = purple_protocol_file_transfer_send_finish(protocol_file_transfer,
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
305 res, &error);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
306
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
307 if(test_protocol_file_transfer->should_error) {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
308 g_assert_error(error, TEST_PURPLE_PROTOCOL_FILE_TRANSFER_DOMAIN, 0);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
309 g_clear_error(&error);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
310 g_assert_false(result);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
311 } else {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
312 g_assert_no_error(error);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
313 g_assert_true(result);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
314 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
315 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
316
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
317 static void
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
318 test_purple_protocol_file_transfer_send_normal(gconstpointer data) {
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
319 TestPurpleProtocolFileTransfer *protocol_file_transfer = NULL;
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
320 PurpleAccount *account = NULL;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
321 PurpleContactInfo *remote = NULL;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
322 PurpleFileTransfer *transfer = NULL;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
323 GFile *local_file = NULL;
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
324 const char *filename = data;
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
325
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
326 protocol_file_transfer = g_object_new(test_purple_protocol_file_transfer_get_type(),
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
327 NULL);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
328
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
329 account = purple_account_new("test", "test");
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
330 remote = purple_contact_info_new(NULL);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
331 local_file = g_file_new_for_path(filename);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
332
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
333 transfer = purple_file_transfer_new_send(account, remote, local_file);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
334
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
335 purple_protocol_file_transfer_send_async(PURPLE_PROTOCOL_FILE_TRANSFER(protocol_file_transfer),
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
336 transfer,
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
337 test_purple_protocol_file_transfer_send_cb,
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
338 NULL);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
339
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
340 g_main_context_iteration(NULL, FALSE);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
341
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
342 g_assert_cmpuint(protocol_file_transfer->send_async, ==, 1);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
343 g_assert_cmpuint(protocol_file_transfer->send_finish, ==, 1);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
344
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
345 g_clear_object(&account);
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
346 g_assert_finalize_object(transfer);
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
347 g_assert_finalize_object(remote);
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
348 g_assert_finalize_object(local_file);
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
349 g_assert_finalize_object(protocol_file_transfer);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
350 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
351
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
352 static void
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
353 test_purple_protocol_file_transfer_send_error_normal(gconstpointer data) {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
354 TestPurpleProtocolFileTransfer *protocol_file_transfer = NULL;
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
355 PurpleAccount *account = NULL;
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
356 PurpleContactInfo *remote = NULL;
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
357 PurpleFileTransfer *transfer = NULL;
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
358 GFile *local_file = NULL;
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
359 const char *filename = data;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
360
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
361 protocol_file_transfer = g_object_new(test_purple_protocol_file_transfer_get_type(),
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
362 NULL);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
363 g_object_set_data(G_OBJECT(protocol_file_transfer), "filename",
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
364 (gpointer)filename);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
365 protocol_file_transfer->should_error = TRUE;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
366
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
367 account = purple_account_new("test", "test");
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
368 remote = purple_contact_info_new(NULL);
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
369 local_file = g_file_new_for_path(filename);
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
370
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
371 transfer = purple_file_transfer_new_send(account, remote, local_file);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
372
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
373 purple_protocol_file_transfer_send_async(PURPLE_PROTOCOL_FILE_TRANSFER(protocol_file_transfer),
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
374 transfer,
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
375 test_purple_protocol_file_transfer_send_cb,
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
376 NULL);
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
377
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
378 g_main_context_iteration(NULL, FALSE);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
379
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
380 g_assert_cmpuint(protocol_file_transfer->send_async, ==, 1);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
381 g_assert_cmpuint(protocol_file_transfer->send_finish, ==, 1);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
382
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
383 g_clear_object(&account);
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
384 g_assert_finalize_object(transfer);
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
385 g_assert_finalize_object(remote);
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
386 g_assert_finalize_object(local_file);
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
387 g_assert_finalize_object(protocol_file_transfer);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
388 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
389
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
390 /******************************************************************************
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
391 * TestProtocolFileTransfer receive tests
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
392 *****************************************************************************/
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
393 static void
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
394 test_purple_protocol_file_transfer_receive_cb(GObject *obj, GAsyncResult *res,
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
395 G_GNUC_UNUSED gpointer data)
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
396 {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
397 TestPurpleProtocolFileTransfer *test_protocol_file_transfer = NULL;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
398 PurpleProtocolFileTransfer *protocol_file_transfer = NULL;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
399 GError *error = NULL;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
400 gboolean result = FALSE;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
401
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
402 protocol_file_transfer = PURPLE_PROTOCOL_FILE_TRANSFER(obj);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
403 test_protocol_file_transfer = TEST_PURPLE_PROTOCOL_FILE_TRANSFER(obj);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
404
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
405 result = purple_protocol_file_transfer_receive_finish(protocol_file_transfer,
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
406 res, &error);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
407
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
408 if(test_protocol_file_transfer->should_error) {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
409 g_assert_error(error, TEST_PURPLE_PROTOCOL_FILE_TRANSFER_DOMAIN, 0);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
410 g_clear_error(&error);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
411 g_assert_false(result);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
412 } else {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
413 g_assert_no_error(error);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
414 g_assert_true(result);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
415 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
416 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
417
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
418 static void
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
419 test_purple_protocol_file_transfer_receive_normal(void) {
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
420 TestPurpleProtocolFileTransfer *protocol_file_transfer = NULL;
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
421 PurpleAccount *account = NULL;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
422 PurpleContactInfo *remote = NULL;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
423 PurpleFileTransfer *transfer = NULL;
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
424
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
425 protocol_file_transfer = g_object_new(test_purple_protocol_file_transfer_get_type(),
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
426 NULL);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
427
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
428 account = purple_account_new("test", "test");
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
429 remote = purple_contact_info_new(NULL);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
430
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
431 transfer = purple_file_transfer_new_receive(account, remote, "file.png",
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
432 0);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
433
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
434 purple_protocol_file_transfer_receive_async(PURPLE_PROTOCOL_FILE_TRANSFER(protocol_file_transfer),
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
435 transfer,
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
436 test_purple_protocol_file_transfer_receive_cb,
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
437 NULL);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
438
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
439 g_main_context_iteration(NULL, FALSE);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
440
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
441 g_assert_cmpuint(protocol_file_transfer->receive_async, ==, 1);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
442 g_assert_cmpuint(protocol_file_transfer->receive_finish, ==, 1);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
443
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
444 g_clear_object(&account);
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
445 g_assert_finalize_object(transfer);
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
446 g_assert_finalize_object(remote);
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
447 g_assert_finalize_object(protocol_file_transfer);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
448 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
449
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
450 static void
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
451 test_purple_protocol_file_transfer_receive_error_normal(void) {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
452 TestPurpleProtocolFileTransfer *protocol_file_transfer = NULL;
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
453 PurpleAccount *account = NULL;
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
454 PurpleContactInfo *remote = NULL;
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
455 PurpleFileTransfer *transfer = NULL;
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
456
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
457 protocol_file_transfer = g_object_new(test_purple_protocol_file_transfer_get_type(),
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
458 NULL);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
459 protocol_file_transfer->should_error = TRUE;
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
460
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
461 account = purple_account_new("test", "test");
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
462 remote = purple_contact_info_new(NULL);
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
463
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
464 transfer = purple_file_transfer_new_receive(account, remote, "file.png",
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
465 0);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
466
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
467 purple_protocol_file_transfer_receive_async(PURPLE_PROTOCOL_FILE_TRANSFER(protocol_file_transfer),
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
468 transfer,
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
469 test_purple_protocol_file_transfer_receive_cb,
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
470 NULL);
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
471
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
472 g_main_context_iteration(NULL, FALSE);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
473
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
474 g_assert_cmpuint(protocol_file_transfer->receive_async, ==, 1);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
475 g_assert_cmpuint(protocol_file_transfer->receive_finish, ==, 1);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
476
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
477 g_clear_object(&account);
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
478 g_assert_finalize_object(transfer);
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
479 g_assert_finalize_object(remote);
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
480 g_assert_finalize_object(protocol_file_transfer);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
481 }
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
482
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
483 /******************************************************************************
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
484 * Main
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
485 *****************************************************************************/
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
486 int
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
487 main(int argc, char **argv) {
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
488 g_test_init(&argc, &argv, NULL);
42821
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
489 g_test_set_nonfatal_assertions();
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
490
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
491 g_test_add_data_func("/protocol-contacts/empty/send", argv[0],
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
492 test_purple_protocol_file_transfer_empty_send);
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
493 g_test_add_func("/protocol-contacts/empty/receive",
4032fe617b2a Use GTask.report_new_error in Purple.ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
494 test_purple_protocol_file_transfer_empty_receive);
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
495
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
496 g_test_add_data_func("/protocol-contacts/normal/send-normal", argv[0],
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
497 test_purple_protocol_file_transfer_send_normal);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
498 g_test_add_data_func("/protocol-contacts/normal/send-error", argv[0],
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
499 test_purple_protocol_file_transfer_send_error_normal);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
500 g_test_add_func("/protocol-contacts/normal/receive-normal",
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
501 test_purple_protocol_file_transfer_receive_normal);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
502 g_test_add_func("/protocol-contacts/normal/receive-error",
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
503 test_purple_protocol_file_transfer_receive_error_normal);
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
504
42868
213d7b930ba5 Modernize the Purple.ProtocolFileTransfer tests
Gary Kramlich <grim@reaperworld.com>
parents: 42821
diff changeset
505 return g_test_run();
42375
8e61249e9b10 Implement ProtocolFileTransfer
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
506 }

mercurial