6 #include <tp-account-widgets/tpaw-irc-network.h>
8 #include "test-helper.h"
9 #include "test-irc-helper.h"
12 test_tpaw_irc_network_new (void)
14 TpawIrcNetwork
*network
;
16 network
= tpaw_irc_network_new ("Network1");
17 check_network (network
, "Network1", "UTF-8", NULL
, 0);
19 g_object_unref (network
);
23 test_property_change (void)
25 TpawIrcNetwork
*network
;
27 network
= tpaw_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
);
41 static gboolean modified
;
44 modified_cb (TpawIrcNetwork
*network
,
51 test_modified_signal (void)
53 TpawIrcNetwork
*network
;
55 network
= tpaw_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
);
71 add_servers (TpawIrcNetwork
*network
,
72 struct server_t
*servers
,
77 for (i
= 0; i
< nb_servers
; i
++)
79 TpawIrcServer
*server
;
81 server
= tpaw_irc_server_new (servers
[i
].address
,
82 servers
[i
].port
, servers
[i
].ssl
);
84 tpaw_irc_network_append_server (network
, server
);
86 g_object_unref (server
);
91 test_add_server (void)
93 TpawIrcNetwork
*network
;
94 TpawIrcServer
*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
= tpaw_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
= tpaw_irc_network_get_servers (network
);
121 l
= g_slist_nth (servers
, 2);
122 g_assert (l
!= NULL
);
125 tpaw_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 test_modified_signal_because_of_server (void)
141 TpawIrcNetwork
*network
;
142 TpawIrcServer
*server
;
144 network
= tpaw_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
= tpaw_irc_server_new ("server1", 6667, FALSE
);
150 tpaw_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 tpaw_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 */
167 g_assert (!modified
);
169 g_object_unref (network
);
173 test_tpaw_irc_network_set_server_position (void)
175 TpawIrcNetwork
*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
= tpaw_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
= tpaw_irc_network_get_servers (network
);
200 g_assert (g_slist_length (servers
) == 4);
203 /* server1 go to the last position */
204 tpaw_irc_network_set_server_position (network
, servers
->data
, -1);
206 /* server2 go to the first position */
208 tpaw_irc_network_set_server_position (network
, l
->data
, 0);
210 /* server3 go to the third position */
212 tpaw_irc_network_set_server_position (network
, l
->data
, 2);
214 /* server4 go to the second position*/
216 tpaw_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);
234 test_init (argc
, argv
);
236 g_test_add_func ("/irc-network/new", test_tpaw_irc_network_new
);
237 g_test_add_func ("/irc-network/property-change", test_property_change
);
238 g_test_add_func ("/irc-network/modified-signal", test_modified_signal
);
239 g_test_add_func ("/irc-network/add-server", test_add_server
);
240 g_test_add_func ("/irc-network/modified-signal-because-of-server",
241 test_modified_signal_because_of_server
);
242 g_test_add_func ("/irc-network/set-server-position",
243 test_tpaw_irc_network_set_server_position
);
245 result
= g_test_run ();