Replace functions which called once with their bodies
[pidgin-git.git] / libpurple / tests / test_protocol_attention.c
blobfacd3c4157bdf52464e4b256eefc02d61d214d28
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 * PurpleProtcolAttention Implementations
32 *****************************************************************************/
33 static GType test_purple_protocol_attention_get_type(void);
35 typedef struct {
36 PurpleProtocol parent;
38 gboolean send_called;
39 } TestPurpleProtocolAttention;
41 typedef struct {
42 PurpleProtocolClass parent;
43 } TestPurpleProtocolAttentionClass;
46 static gboolean
47 test_purple_protocol_attention_send(PurpleProtocolAttention *attn, PurpleConnection *c, const gchar *username, guint type) {
48 TestPurpleProtocolAttention *test_attn = (TestPurpleProtocolAttention *)attn;
50 test_attn->send_called = TRUE;
52 return TRUE;
55 static GList *
56 test_purple_protocol_attention_get_types(PurpleProtocolAttention *attn, PurpleAccount *acct) {
57 GList *types = NULL;
59 types = g_list_append(types, purple_attention_type_new("id", "name", "incoming", "outgoing"));
61 return types;
64 static void
65 test_purple_protocol_attention_iface_init(PurpleProtocolAttentionInterface *iface) {
66 iface->send = test_purple_protocol_attention_send;
67 iface->get_types = test_purple_protocol_attention_get_types;
70 G_DEFINE_TYPE_WITH_CODE(
71 TestPurpleProtocolAttention,
72 test_purple_protocol_attention,
73 PURPLE_TYPE_PROTOCOL,
74 G_IMPLEMENT_INTERFACE(
75 PURPLE_TYPE_PROTOCOL_ATTENTION,
76 test_purple_protocol_attention_iface_init
80 static void
81 test_purple_protocol_attention_init(TestPurpleProtocolAttention *prplattn) {
82 PurpleProtocol *prpl = PURPLE_PROTOCOL(prplattn);
84 prpl->id = "prpl-attention";
87 static void
88 test_purple_protocol_attention_class_init(TestPurpleProtocolAttentionClass *klass) {
91 /******************************************************************************
92 * Tests
93 *****************************************************************************/
94 static void
95 test_purple_protocol_attention_can_send(void) {
96 TestPurpleProtocolAttention *attn = g_object_new(test_purple_protocol_attention_get_type(), NULL);
97 PurpleAccount *a = purple_account_new("prpl-attn-can-send", "prpl-attn");
98 PurpleConnection *c = g_object_new(PURPLE_TYPE_CONNECTION, "account", a, NULL);
99 gboolean actual = FALSE;
101 attn->send_called = FALSE;
102 actual = purple_protocol_attention_send(PURPLE_PROTOCOL_ATTENTION(attn), c, "someguy", 0);
103 g_assert_true(actual);
105 g_assert_true(attn->send_called);
108 static void
109 test_purple_protocol_attention_can_get_types(void) {
110 TestPurpleProtocolAttention *attn = g_object_new(test_purple_protocol_attention_get_type(), NULL);
111 PurpleAccount *a = purple_account_new("prpl-attn-can-get-types", "prpl-attn");
112 GList *types = NULL;
113 PurpleAttentionType *type = NULL;
115 types = purple_protocol_attention_get_types(PURPLE_PROTOCOL_ATTENTION(attn), a);
116 g_assert_true(g_list_length(types) == 1);
118 /* take the first item and cast it into type */
119 type = (PurpleAttentionType *)(types->data);
120 g_assert(type);
122 g_assert_cmpstr(purple_attention_type_get_unlocalized_name(type), ==, "id");
123 g_assert_cmpstr(purple_attention_type_get_name(type), ==, "name");
124 g_assert_cmpstr(purple_attention_type_get_incoming_desc(type), ==, "incoming");
125 g_assert_cmpstr(purple_attention_type_get_outgoing_desc(type), ==, "outgoing");
128 /******************************************************************************
129 * Main
130 *****************************************************************************/
131 gint
132 main(gint argc, gchar **argv) {
133 gint res = 0;
135 g_test_init(&argc, &argv, NULL);
137 g_test_set_nonfatal_assertions();
139 test_ui_purple_init();
141 g_test_add_func(
142 "/protocol-attention/send",
143 test_purple_protocol_attention_can_send
146 g_test_add_func(
147 "/protocol-attention/get-types",
148 test_purple_protocol_attention_can_get_types
151 res = g_test_run();
153 return res;