6 #include "check-helpers.h"
7 #include "check-libempathy.h"
8 #include "check-irc-helper.h"
10 #include <libempathy/empathy-irc-network.h>
12 START_TEST (test_empathy_irc_network_new
)
14 EmpathyIrcNetwork
*network
;
16 network
= empathy_irc_network_new ("Network1");
17 check_network (network
, "Network1", "UTF-8", NULL
, 0);
19 g_object_unref (network
);
23 START_TEST (test_property_change
)
25 EmpathyIrcNetwork
*network
;
27 network
= empathy_irc_network_new ("Network1");
28 check_network (network
, "Network1", "UTF-8", NULL
, 0);
30 g_object_set (network
,
32 "charset", "ISO-8859-1",
35 check_network (network
, "Network2", "ISO-8859-1", NULL
, 0);
37 g_object_unref (network
);
42 static gboolean modified
;
45 modified_cb (EmpathyIrcNetwork
*network
,
51 START_TEST (test_modified_signal
)
53 EmpathyIrcNetwork
*network
;
55 network
= empathy_irc_network_new ("Network1");
56 check_network (network
, "Network1", "UTF-8", NULL
, 0);
59 g_signal_connect (network
, "modified", G_CALLBACK (modified_cb
), NULL
);
61 g_object_set (network
, "name", "Network2", NULL
);
64 g_object_set (network
, "name", "Network2", NULL
);
67 g_object_unref (network
);
72 add_servers (EmpathyIrcNetwork
*network
,
73 struct server_t
*servers
,
78 for (i
= 0; i
< nb_servers
; i
++)
80 EmpathyIrcServer
*server
;
82 server
= empathy_irc_server_new (servers
[i
].address
,
83 servers
[i
].port
, servers
[i
].ssl
);
85 empathy_irc_network_append_server (network
, server
);
87 g_object_unref (server
);
91 START_TEST (test_add_server
)
93 EmpathyIrcNetwork
*network
;
94 EmpathyIrcServer
*server
;
96 struct server_t test_servers
[] = {
97 { "server1", 6667, FALSE
},
98 { "server2", 6668, TRUE
},
99 { "server3", 6667, FALSE
},
100 { "server4", 6669, TRUE
}};
101 struct server_t servers_without_3
[] = {
102 { "server1", 6667, FALSE
},
103 { "server2", 6668, TRUE
},
104 { "server4", 6669, TRUE
}};
106 network
= empathy_irc_network_new ("Network1");
107 check_network (network
, "Network1", "UTF-8", NULL
, 0);
110 g_signal_connect (network
, "modified", G_CALLBACK (modified_cb
), NULL
);
112 check_network (network
, "Network1", "UTF-8", NULL
, 0);
114 /* add the servers */
115 add_servers (network
, test_servers
, 4);
117 check_network (network
, "Network1", "UTF-8", test_servers
, 4);
119 /* Now let's remove the 3rd server */
120 servers
= empathy_irc_network_get_servers (network
);
121 l
= g_slist_nth (servers
, 2);
125 empathy_irc_network_remove_server (network
, server
);
129 g_slist_foreach (servers
, (GFunc
) g_object_unref
, NULL
);
130 g_slist_free (servers
);
132 /* The 3rd server should have disappear */
133 check_network (network
, "Network1", "UTF-8", servers_without_3
, 3);
135 g_object_unref (network
);
139 START_TEST (test_modified_signal_because_of_server
)
141 EmpathyIrcNetwork
*network
;
142 EmpathyIrcServer
*server
;
144 network
= empathy_irc_network_new ("Network1");
145 check_network (network
, "Network1", "UTF-8", NULL
, 0);
147 g_signal_connect (network
, "modified", G_CALLBACK (modified_cb
), NULL
);
149 server
= empathy_irc_server_new ("server1", 6667, FALSE
);
150 empathy_irc_network_append_server (network
, server
);
152 /* Change server properties */
154 g_object_set (server
, "address", "server2", NULL
);
157 g_object_set (server
, "port", 6668, NULL
);
160 g_object_set (server
, "ssl", TRUE
, NULL
);
163 empathy_irc_network_remove_server (network
, server
);
165 g_object_set (server
, "address", "server3", NULL
);
166 /* We removed the server so the network is not modified anymore */
169 g_object_unref (network
);
173 START_TEST (test_empathy_irc_network_set_server_position
)
175 EmpathyIrcNetwork
*network
;
177 struct server_t test_servers
[] = {
178 { "server1", 6667, FALSE
},
179 { "server2", 6668, TRUE
},
180 { "server3", 6667, FALSE
},
181 { "server4", 6669, TRUE
}};
182 struct server_t test_servers_sorted
[] = {
183 { "server2", 6668, TRUE
},
184 { "server4", 6669, TRUE
},
185 { "server3", 6667, FALSE
},
186 { "server1", 6667, FALSE
}};
188 network
= empathy_irc_network_new ("Network1");
189 check_network (network
, "Network1", "UTF-8", NULL
, 0);
192 g_signal_connect (network
, "modified", G_CALLBACK (modified_cb
), NULL
);
194 /* add the servers */
195 add_servers (network
, test_servers
, 4);
196 check_network (network
, "Network1", "UTF-8", test_servers
, 4);
198 /* get servers list */
199 servers
= empathy_irc_network_get_servers (network
);
200 fail_if (g_slist_length (servers
) != 4);
203 /* server1 go to the last position */
204 empathy_irc_network_set_server_position (network
, servers
->data
, -1);
206 /* server2 go to the first position */
208 empathy_irc_network_set_server_position (network
, l
->data
, 0);
210 /* server3 go to the third position */
212 empathy_irc_network_set_server_position (network
, l
->data
, 2);
214 /* server4 go to the second position*/
216 empathy_irc_network_set_server_position (network
, l
->data
, 1);
221 g_slist_foreach (servers
, (GFunc
) g_object_unref
, NULL
);
222 g_slist_free (servers
);
224 /* Check if servers are sorted */
225 check_network (network
, "Network1", "UTF-8", test_servers_sorted
, 4);
230 make_empathy_irc_network_tcase (void)
232 TCase
*tc
= tcase_create ("empathy-irc-network");
233 tcase_add_test (tc
, test_empathy_irc_network_new
);
234 tcase_add_test (tc
, test_property_change
);
235 tcase_add_test (tc
, test_modified_signal
);
236 tcase_add_test (tc
, test_add_server
);
237 tcase_add_test (tc
, test_modified_signal_because_of_server
);
238 tcase_add_test (tc
, test_empathy_irc_network_set_server_position
);