Standardize all protocol header guard macros.
[pidgin-git.git] / libpurple / tests / test_protocol_xfer.c
blob4751582459297d0611ac667b76fa26e9bad5c70a
1 /*
2 * Purple
4 * Purple is the legal property of its developers, whose names are too
5 * numerous to list here. Please refer to the COPYRIGHT file distributed
6 * with this source distribution
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23 #include <glib.h>
24 #include <string.h>
26 #include <purple.h>
28 #include "test_ui.h"
30 /******************************************************************************
31 * PurpleProtcolXfer Implementations
32 *****************************************************************************/
33 static GType test_purple_protocol_xfer_get_type(void);
35 typedef struct {
36 PurpleProtocol parent;
38 gboolean can_send;
39 gboolean new_xfer_called;
40 gboolean send_called;
41 } TestPurpleProtocolXfer;
43 typedef struct {
44 PurpleProtocolClass parent;
45 } TestPurpleProtocolXferClass;
48 static gboolean
49 test_purple_protocol_xfer_can_receive(PurpleProtocolXfer *prplxfer, PurpleConnection *c, const gchar *who) {
50 TestPurpleProtocolXfer *test_xfer = (TestPurpleProtocolXfer *)prplxfer;
52 return test_xfer->can_send;
55 static void
56 test_purple_protocol_xfer_send_file(PurpleProtocolXfer *prplxfer, PurpleConnection *c, const gchar *who, const gchar *filename) {
57 TestPurpleProtocolXfer *test_xfer = (TestPurpleProtocolXfer *)prplxfer;
59 test_xfer->send_called = TRUE;
62 static PurpleXfer *
63 test_purple_protocol_xfer_new_xfer(PurpleProtocolXfer *prplxfer, PurpleConnection *c, const gchar *who) {
64 TestPurpleProtocolXfer *test_xfer = (TestPurpleProtocolXfer *)prplxfer;
65 PurpleAccount *a = purple_connection_get_account(c);
67 test_xfer->new_xfer_called = TRUE;
69 return purple_xfer_new(a, PURPLE_XFER_TYPE_SEND, who);
72 static void
73 test_purple_protocol_xfer_iface_init(PurpleProtocolXferInterface *iface) {
74 iface->can_receive = test_purple_protocol_xfer_can_receive;
75 iface->send_file = test_purple_protocol_xfer_send_file;
76 iface->new_xfer = test_purple_protocol_xfer_new_xfer;
79 G_DEFINE_TYPE_WITH_CODE(
80 TestPurpleProtocolXfer,
81 test_purple_protocol_xfer,
82 PURPLE_TYPE_PROTOCOL,
83 G_IMPLEMENT_INTERFACE(
84 PURPLE_TYPE_PROTOCOL_XFER,
85 test_purple_protocol_xfer_iface_init
89 static void
90 test_purple_protocol_xfer_init(TestPurpleProtocolXfer *prplxfer) {
91 PurpleProtocol *prpl = PURPLE_PROTOCOL(prplxfer);
93 prpl->id = "prpl-xfer";
96 static void
97 test_purple_protocol_xfer_class_init(TestPurpleProtocolXferClass *klass) {
100 /******************************************************************************
101 * Tests
102 *****************************************************************************/
103 static void
104 test_purple_protocol_xfer_can_receive_func(void) {
105 TestPurpleProtocolXfer *xfer = g_object_new(test_purple_protocol_xfer_get_type(), NULL);
106 PurpleAccount *a = purple_account_new("prpl-xfer-can-receive", "prpl-xfer");
107 PurpleConnection *c = g_object_new(PURPLE_TYPE_CONNECTION, "account", a, NULL);
108 gboolean actual = FALSE;
110 g_assert_true(PURPLE_IS_PROTOCOL_XFER(xfer));
112 xfer->can_send = FALSE;
113 actual = purple_protocol_xfer_can_receive(
114 PURPLE_PROTOCOL_XFER(xfer),
116 "foo"
118 g_assert_false(actual);
120 xfer->can_send = TRUE;
121 actual = purple_protocol_xfer_can_receive(
122 PURPLE_PROTOCOL_XFER(xfer),
124 "foo"
126 g_assert_true(actual);
129 static void
130 test_purple_protocol_xfer_send_file_func(void) {
131 TestPurpleProtocolXfer *prplxfer = g_object_new(test_purple_protocol_xfer_get_type(), NULL);
132 PurpleAccount *a = purple_account_new("prpl-xfer-send", "prpl-xfer");
133 PurpleConnection *c = g_object_new(PURPLE_TYPE_CONNECTION, "account", a, NULL);
135 purple_protocol_xfer_send_file(PURPLE_PROTOCOL_XFER(prplxfer), c, "foo", "somefile");
136 g_assert_true(prplxfer->send_called);
139 static void
140 test_purple_protocol_xfer_new_func(void) {
141 TestPurpleProtocolXfer *prplxfer = g_object_new(test_purple_protocol_xfer_get_type(), NULL);
142 PurpleAccount *a = purple_account_new("prpl-xfer-new-xfer", "prpl-xfer");
143 PurpleConnection *c = g_object_new(PURPLE_TYPE_CONNECTION, "account", a, NULL);
144 PurpleXfer *xfer = NULL;
146 xfer = purple_protocol_xfer_new_xfer(PURPLE_PROTOCOL_XFER(prplxfer), c, "foo");
147 g_assert_true(PURPLE_IS_XFER(xfer));
148 g_assert_cmpstr("foo", ==, purple_xfer_get_remote_user(xfer));
149 g_assert_true(prplxfer->new_xfer_called);
152 /******************************************************************************
153 * Main
154 *****************************************************************************/
155 gint
156 main(gint argc, gchar **argv) {
157 gint res = 0;
159 g_test_init(&argc, &argv, NULL);
161 g_test_set_nonfatal_assertions();
163 test_ui_purple_init();
165 g_test_add_func(
166 "/protocol-xfer/can-receive",
167 test_purple_protocol_xfer_can_receive_func
170 g_test_add_func(
171 "/protocol-xfer/send-file",
172 test_purple_protocol_xfer_send_file_func
175 g_test_add_func(
176 "/protocol-xfer/new",
177 test_purple_protocol_xfer_new_func
180 res = g_test_run();
182 return res;