6 #include <glib/gstdio.h>
7 #include <tp-account-widgets/tpaw-irc-network-manager.h>
9 #include "test-helper.h"
10 #include "test-irc-helper.h"
12 #define GLOBAL_SAMPLE "default-irc-networks-sample.xml"
13 #define USER_SAMPLE "user-irc-networks-sample.xml"
14 #define USER_FILE "user-irc-networks.xml"
17 test_tpaw_irc_network_manager_add (void)
19 TpawIrcNetworkManager
*mgr
;
20 TpawIrcNetwork
*network
;
24 mgr
= tpaw_irc_network_manager_new (NULL
, NULL
);
25 g_assert (mgr
!= NULL
);
27 networks
= tpaw_irc_network_manager_get_networks (mgr
);
28 g_assert (networks
== NULL
);
31 network
= tpaw_irc_network_new ("My Network");
32 g_assert (network
!= NULL
);
33 tpaw_irc_network_manager_add (mgr
, network
);
34 g_object_unref (network
);
36 networks
= tpaw_irc_network_manager_get_networks (mgr
);
37 g_assert_cmpuint (g_slist_length (networks
), ==, 1);
38 g_object_get (networks
->data
, "name", &name
, NULL
);
39 g_assert_cmpstr (name
, ==, "My Network");
41 g_slist_foreach (networks
, (GFunc
) g_object_unref
, NULL
);
42 g_slist_free (networks
);
44 /* add another network having the same name */
45 network
= tpaw_irc_network_new ("My Network");
46 g_assert (network
!= NULL
);
47 tpaw_irc_network_manager_add (mgr
, network
);
48 g_object_unref (network
);
50 networks
= tpaw_irc_network_manager_get_networks (mgr
);
51 g_assert_cmpuint (g_slist_length (networks
), ==, 2);
52 g_object_get (networks
->data
, "name", &name
, NULL
);
53 g_assert_cmpstr (name
, ==, "My Network");
55 g_object_get (g_slist_next (networks
)->data
, "name", &name
, NULL
);
56 g_assert_cmpstr (name
, ==, "My Network");
58 g_slist_foreach (networks
, (GFunc
) g_object_unref
, NULL
);
59 g_slist_free (networks
);
65 test_load_global_file (void)
67 TpawIrcNetworkManager
*mgr
;
68 gchar
*global_file
, *user_file
;
70 struct server_t freenode_servers
[] = {
71 { "irc.freenode.net", 6667, FALSE
},
72 { "irc.eu.freenode.net", 6667, FALSE
}};
73 struct server_t gimpnet_servers
[] = {
74 { "irc.gimp.org", 6667, FALSE
},
75 { "irc.us.gimp.org", 6667, FALSE
}};
76 struct server_t test_servers
[] = {
77 { "irc.test.org", 6669, TRUE
}};
78 struct server_t undernet_servers
[] = {
79 { "eu.undernet.org", 6667, FALSE
}};
80 gboolean network_checked
[4];
81 gchar
*global_file_orig
;
83 global_file_orig
= get_xml_file (GLOBAL_SAMPLE
);
84 mgr
= tpaw_irc_network_manager_new (global_file_orig
, NULL
);
87 "global-file", &global_file
,
88 "user-file", &user_file
,
90 g_assert_cmpstr (global_file
, ==, global_file_orig
);
92 g_free (global_file_orig
);
95 networks
= tpaw_irc_network_manager_get_networks (mgr
);
96 g_assert_cmpuint (g_slist_length (networks
), ==, 4);
98 network_checked
[0] = network_checked
[1] = network_checked
[2] =
99 network_checked
[3] = FALSE
;
100 /* check networks and servers */
101 for (l
= networks
; l
!= NULL
; l
= g_slist_next (l
))
105 g_object_get (l
->data
, "name", &name
, NULL
);
106 g_assert (name
!= NULL
);
108 if (strcmp (name
, "Freenode") == 0)
110 check_network (l
->data
, "Freenode", "UTF-8", freenode_servers
, 2);
111 network_checked
[0] = TRUE
;
113 else if (strcmp (name
, "GIMPNet") == 0)
115 check_network (l
->data
, "GIMPNet", "UTF-8", gimpnet_servers
, 2);
116 network_checked
[1] = TRUE
;
118 else if (strcmp (name
, "Test Server") == 0)
120 check_network (l
->data
, "Test Server", "ISO-8859-1", test_servers
, 1);
121 network_checked
[2] = TRUE
;
123 else if (strcmp (name
, "Undernet") == 0)
125 check_network (l
->data
, "Undernet", "UTF-8", undernet_servers
, 1);
126 network_checked
[3] = TRUE
;
130 g_assert_not_reached ();
135 g_assert (network_checked
[0] && network_checked
[1] && network_checked
[2] &&
138 g_slist_foreach (networks
, (GFunc
) g_object_unref
, NULL
);
139 g_slist_free (networks
);
140 g_object_unref (mgr
);
144 remove_network_named (TpawIrcNetworkManager
*mgr
,
145 const gchar
*network_name
)
147 GSList
*networks
, *l
;
148 gboolean removed
= FALSE
;
150 networks
= tpaw_irc_network_manager_get_networks (mgr
);
152 /* check networks and servers */
153 for (l
= networks
; l
!= NULL
&& !removed
; l
= g_slist_next (l
))
155 TpawIrcNetwork
*network
= l
->data
;
158 g_object_get (network
, "name", &name
, NULL
);
159 g_assert (name
!= NULL
);
161 if (strcmp (name
, network_name
) == 0)
163 tpaw_irc_network_manager_remove (mgr
, network
);
170 g_slist_foreach (networks
, (GFunc
) g_object_unref
, NULL
);
171 g_slist_free (networks
);
177 test_tpaw_irc_network_manager_remove (void)
179 TpawIrcNetworkManager
*mgr
;
180 GSList
*networks
, *l
;
181 struct server_t freenode_servers
[] = {
182 { "irc.freenode.net", 6667, FALSE
},
183 { "irc.eu.freenode.net", 6667, FALSE
}};
184 struct server_t test_servers
[] = {
185 { "irc.test.org", 6669, TRUE
}};
186 struct server_t undernet_servers
[] = {
187 { "eu.undernet.org", 6667, FALSE
}};
188 gboolean network_checked
[3];
190 gchar
*global_file_orig
;
192 global_file_orig
= get_xml_file (GLOBAL_SAMPLE
);
193 mgr
= tpaw_irc_network_manager_new (global_file_orig
, NULL
);
194 g_free (global_file_orig
);
196 result
= remove_network_named (mgr
, "GIMPNet");
199 networks
= tpaw_irc_network_manager_get_networks (mgr
);
200 g_assert_cmpuint (g_slist_length (networks
), ==, 3);
202 network_checked
[0] = network_checked
[1] = network_checked
[2] = FALSE
;
203 /* check networks and servers */
204 for (l
= networks
; l
!= NULL
; l
= g_slist_next (l
))
208 g_object_get (l
->data
, "name", &name
, NULL
);
209 g_assert (name
!= NULL
);
211 if (strcmp (name
, "Freenode") == 0)
213 check_network (l
->data
, "Freenode", "UTF-8", freenode_servers
, 2);
214 network_checked
[0] = TRUE
;
216 else if (strcmp (name
, "Test Server") == 0)
218 check_network (l
->data
, "Test Server", "ISO-8859-1", test_servers
, 1);
219 network_checked
[1] = TRUE
;
221 else if (strcmp (name
, "Undernet") == 0)
223 check_network (l
->data
, "Undernet", "UTF-8", undernet_servers
, 1);
224 network_checked
[2] = TRUE
;
228 g_assert_not_reached ();
233 g_assert (network_checked
[0] && network_checked
[1] && network_checked
[2]);
235 g_slist_foreach (networks
, (GFunc
) g_object_unref
, NULL
);
236 g_slist_free (networks
);
237 g_object_unref (mgr
);
241 test_load_user_file (void)
243 TpawIrcNetworkManager
*mgr
;
244 gchar
*global_file
, *user_file
;
245 GSList
*networks
, *l
;
246 struct server_t gimpnet_servers
[] = {
247 { "irc.gimp.org", 6667, FALSE
},
248 { "irc.us.gimp.org", 6667, FALSE
},
249 { "irc.au.gimp.org", 6667, FALSE
}};
250 struct server_t my_server
[] = {
251 { "irc.mysrv.net", 7495, TRUE
}};
252 struct server_t another_server
[] = {
253 { "irc.anothersrv.be", 6660, FALSE
}};
254 gboolean network_checked
[3];
255 gchar
*user_file_orig
;
257 copy_xml_file (USER_SAMPLE
, USER_FILE
);
258 user_file_orig
= get_user_xml_file (USER_FILE
);
259 mgr
= tpaw_irc_network_manager_new (NULL
, user_file_orig
);
262 "global-file", &global_file
,
263 "user-file", &user_file
,
265 g_assert (global_file
== NULL
);
266 g_assert_cmpstr (user_file
, ==, user_file_orig
);
267 g_free (global_file
);
269 g_free (user_file_orig
);
271 networks
= tpaw_irc_network_manager_get_networks (mgr
);
272 g_assert_cmpuint (g_slist_length (networks
), ==, 3);
274 network_checked
[0] = network_checked
[1] = network_checked
[2] = FALSE
;
275 /* check networks and servers */
276 for (l
= networks
; l
!= NULL
; l
= g_slist_next (l
))
280 g_object_get (l
->data
, "name", &name
, NULL
);
281 g_assert (name
!= NULL
);
283 if (strcmp (name
, "GIMPNet") == 0)
285 check_network (l
->data
, "GIMPNet", "UTF-8", gimpnet_servers
, 3);
286 network_checked
[0] = TRUE
;
288 else if (strcmp (name
, "My Server") == 0)
290 check_network (l
->data
, "My Server", "UTF-8", my_server
, 1);
291 network_checked
[1] = TRUE
;
293 else if (strcmp (name
, "Another Server") == 0)
295 check_network (l
->data
, "Another Server", "UTF-8", another_server
, 1);
296 network_checked
[2] = TRUE
;
300 g_assert_not_reached ();
305 g_assert (network_checked
[0] && network_checked
[1] && network_checked
[2]);
307 g_slist_foreach (networks
, (GFunc
) g_object_unref
, NULL
);
308 g_slist_free (networks
);
309 g_object_unref (mgr
);
313 test_load_both_files (void)
315 TpawIrcNetworkManager
*mgr
;
316 gchar
*global_file
, *user_file
;
317 GSList
*networks
, *l
;
318 struct server_t freenode_servers
[] = {
319 { "irc.freenode.net", 6667, FALSE
},
320 { "irc.eu.freenode.net", 6667, FALSE
}};
321 struct server_t gimpnet_servers
[] = {
322 { "irc.gimp.org", 6667, FALSE
},
323 { "irc.us.gimp.org", 6667, FALSE
},
324 { "irc.au.gimp.org", 6667, FALSE
}};
325 struct server_t my_server
[] = {
326 { "irc.mysrv.net", 7495, TRUE
}};
327 struct server_t another_server
[] = {
328 { "irc.anothersrv.be", 6660, FALSE
}};
329 struct server_t undernet_servers
[] = {
330 { "eu.undernet.org", 6667, FALSE
}};
331 gboolean network_checked
[5];
332 gchar
*global_file_orig
, *user_file_orig
;
334 global_file_orig
= get_xml_file (GLOBAL_SAMPLE
);
335 user_file_orig
= get_user_xml_file (USER_FILE
);
336 mgr
= tpaw_irc_network_manager_new (global_file_orig
, user_file_orig
);
339 "global-file", &global_file
,
340 "user-file", &user_file
,
342 g_assert_cmpstr (global_file
, ==, global_file_orig
);
343 g_assert_cmpstr (user_file
, ==, user_file_orig
);
344 g_free (global_file
);
345 g_free (global_file_orig
);
347 g_free (user_file_orig
);
349 networks
= tpaw_irc_network_manager_get_networks (mgr
);
350 g_assert_cmpuint (g_slist_length (networks
), ==, 5);
352 network_checked
[0] = network_checked
[1] = network_checked
[2] =
353 network_checked
[3] = network_checked
[4] = FALSE
;
354 /* check networks and servers */
355 for (l
= networks
; l
!= NULL
; l
= g_slist_next (l
))
359 g_object_get (l
->data
, "name", &name
, NULL
);
360 g_assert (name
!= NULL
);
362 if (strcmp (name
, "Freenode") == 0)
364 check_network (l
->data
, "Freenode", "UTF-8", freenode_servers
, 2);
365 network_checked
[0] = TRUE
;
367 else if (strcmp (name
, "GIMPNet") == 0)
369 check_network (l
->data
, "GIMPNet", "UTF-8", gimpnet_servers
, 3);
370 network_checked
[1] = TRUE
;
372 else if (strcmp (name
, "My Server") == 0)
374 check_network (l
->data
, "My Server", "UTF-8", my_server
, 1);
375 network_checked
[2] = TRUE
;
377 else if (strcmp (name
, "Another Server") == 0)
379 check_network (l
->data
, "Another Server", "UTF-8", another_server
, 1);
380 network_checked
[3] = TRUE
;
382 else if (strcmp (name
, "Undernet") == 0)
384 check_network (l
->data
, "Undernet", "UTF-8", undernet_servers
, 1);
385 network_checked
[4] = TRUE
;
389 g_assert_not_reached ();
394 g_assert (network_checked
[0] && network_checked
[1] && network_checked
[2] &&
395 network_checked
[3] && network_checked
[4]);
397 g_slist_foreach (networks
, (GFunc
) g_object_unref
, NULL
);
398 g_slist_free (networks
);
399 g_object_unref (mgr
);
403 test_modify_user_file (void)
405 TpawIrcNetworkManager
*mgr
;
406 TpawIrcNetwork
*network
;
407 TpawIrcServer
*server
;
408 gchar
*global_file
, *user_file
;
409 GSList
*networks
, *l
;
410 struct server_t gimpnet_servers
[] = {
411 { "irc.gimp.org", 6667, TRUE
},
412 { "irc.us.gimp.org", 6668, FALSE
}};
413 struct server_t great_server
[] = {
414 { "irc.greatserver.com", 7873, TRUE
}};
415 struct server_t another_server
[] = {
416 { "irc.anothersrv.be", 6660, FALSE
}};
417 gboolean network_modified
[2];
418 gboolean network_checked
[3];
419 gchar
*user_file_orig
;
421 copy_xml_file (USER_SAMPLE
, USER_FILE
);
422 user_file_orig
= get_user_xml_file (USER_FILE
);
423 mgr
= tpaw_irc_network_manager_new (NULL
, user_file_orig
);
426 "global-file", &global_file
,
427 "user-file", &user_file
,
429 g_assert (global_file
== NULL
);
430 g_assert_cmpstr (user_file
, ==, user_file_orig
);
431 g_free (global_file
);
434 networks
= tpaw_irc_network_manager_get_networks (mgr
);
435 g_assert_cmpuint (g_slist_length (networks
), ==, 3);
437 network_modified
[0] = network_modified
[1] = FALSE
;
438 /* check networks and servers */
439 for (l
= networks
; l
!= NULL
; l
= g_slist_next (l
))
444 g_object_get (network
, "name", &name
, NULL
);
445 g_assert (name
!= NULL
);
447 if (strcmp (name
, "GIMPNet") == 0)
449 GSList
*servers
, *ll
;
452 g_object_set (network
, "charset", "ISO-8859-1", NULL
);
454 servers
= tpaw_irc_network_get_servers (network
);
455 for (ll
= servers
; ll
!= NULL
; ll
= g_slist_next (ll
))
460 g_object_get (server
, "address", &address
, NULL
);
461 if (strcmp (address
, "irc.gimp.org") == 0)
464 g_object_set (server
, "ssl", TRUE
, NULL
);
466 else if (strcmp (address
, "irc.us.gimp.org") == 0)
469 g_object_set (server
, "port", 6668, NULL
);
471 else if (strcmp (address
, "irc.au.gimp.org") == 0)
473 /* remove this server */
474 tpaw_irc_network_remove_server (network
, server
);
478 g_assert_not_reached ();
484 network_modified
[0] = TRUE
;
486 g_slist_foreach (servers
, (GFunc
) g_object_unref
, NULL
);
487 g_slist_free (servers
);
489 else if (strcmp (name
, "My Server") == 0)
491 /* remove this network */
492 tpaw_irc_network_manager_remove (mgr
, network
);
493 network_modified
[1] = TRUE
;
495 else if (strcmp (name
, "Another Server") == 0)
497 /* Don't change this one */
501 g_assert_not_reached ();
506 g_assert (network_modified
[0] && network_modified
[1]);
508 /* Add a new network */
509 network
= tpaw_irc_network_new ("Great Server");
510 server
= tpaw_irc_server_new ("irc.greatserver.com", 7873, TRUE
);
511 tpaw_irc_network_append_server (network
, server
);
512 tpaw_irc_network_manager_add (mgr
, network
);
513 g_object_unref (server
);
514 g_object_unref (network
);
516 g_slist_foreach (networks
, (GFunc
) g_object_unref
, NULL
);
517 g_slist_free (networks
);
518 g_object_unref (mgr
);
521 /* Now let's reload the file and check its contain */
522 mgr
= tpaw_irc_network_manager_new (NULL
, user_file_orig
);
523 g_free (user_file_orig
);
525 networks
= tpaw_irc_network_manager_get_networks (mgr
);
526 g_assert_cmpuint (g_slist_length (networks
), ==, 3);
528 network_checked
[0] = network_checked
[1] = network_checked
[2] = FALSE
;
529 /* check networks and servers */
530 for (l
= networks
; l
!= NULL
; l
= g_slist_next (l
))
534 g_object_get (l
->data
, "name", &name
, NULL
);
535 g_assert (name
!= NULL
);
537 if (strcmp (name
, "GIMPNet") == 0)
539 check_network (l
->data
, "GIMPNet", "ISO-8859-1", gimpnet_servers
, 2);
540 network_checked
[0] = TRUE
;
542 else if (strcmp (name
, "Great Server") == 0)
544 check_network (l
->data
, "Great Server", "UTF-8", great_server
, 1);
545 network_checked
[1] = TRUE
;
547 else if (strcmp (name
, "Another Server") == 0)
549 check_network (l
->data
, "Another Server", "UTF-8", another_server
, 1);
550 network_checked
[2] = TRUE
;
554 g_assert_not_reached ();
559 g_assert (network_checked
[0] && network_checked
[1] && network_checked
[2]);
561 g_slist_foreach (networks
, (GFunc
) g_object_unref
, NULL
);
562 g_slist_free (networks
);
563 g_object_unref (mgr
);
567 test_modify_both_files (void)
569 TpawIrcNetworkManager
*mgr
;
570 TpawIrcNetwork
*network
;
571 TpawIrcServer
*server
;
572 gchar
*global_file
, *user_file
;
573 GSList
*networks
, *l
;
574 struct server_t gimpnet_servers
[] = {
575 { "irc.gimp.org", 6667, TRUE
},
576 { "irc.us.gimp.org", 6668, FALSE
}};
577 struct server_t great_server
[] = {
578 { "irc.greatserver.com", 7873, TRUE
}};
579 struct server_t another_server
[] = {
580 { "irc.anothersrv.be", 6660, FALSE
}};
581 struct server_t undernet_servers
[] = {
582 { "eu.undernet.org", 6667, FALSE
},
583 { "us.undernet.org", 6667, FALSE
}};
584 gboolean network_modified
[4];
585 gboolean network_checked
[4];
586 gchar
*global_file_orig
, *user_file_orig
;
588 copy_xml_file (USER_SAMPLE
, USER_FILE
);
589 global_file_orig
= get_xml_file (GLOBAL_SAMPLE
);
590 user_file_orig
= get_user_xml_file (USER_FILE
);
591 mgr
= tpaw_irc_network_manager_new (global_file_orig
, user_file_orig
);
594 "global-file", &global_file
,
595 "user-file", &user_file
,
597 g_assert_cmpstr (global_file
, ==, global_file_orig
);
598 g_assert_cmpstr (user_file
, ==, user_file_orig
);
599 g_free (global_file
);
600 g_free (global_file_orig
);
602 g_free (user_file_orig
);
604 networks
= tpaw_irc_network_manager_get_networks (mgr
);
605 g_assert_cmpuint (g_slist_length (networks
), ==, 5);
607 network_modified
[0] = network_modified
[1] = network_modified
[2] =
608 network_modified
[3] = FALSE
;
609 /* check networks and servers */
610 for (l
= networks
; l
!= NULL
; l
= g_slist_next (l
))
615 g_object_get (network
, "name", &name
, NULL
);
616 g_assert (name
!= NULL
);
618 if (strcmp (name
, "GIMPNet") == 0)
620 /* Modify user network */
621 GSList
*servers
, *ll
;
623 servers
= tpaw_irc_network_get_servers (network
);
624 for (ll
= servers
; ll
!= NULL
; ll
= g_slist_next (ll
))
629 g_object_get (server
, "address", &address
, NULL
);
630 if (strcmp (address
, "irc.gimp.org") == 0)
633 g_object_set (server
, "ssl", TRUE
, NULL
);
635 else if (strcmp (address
, "irc.us.gimp.org") == 0)
638 g_object_set (server
, "port", 6668, NULL
);
640 else if (strcmp (address
, "irc.au.gimp.org") == 0)
642 /* remove this server */
643 tpaw_irc_network_remove_server (network
, server
);
647 g_assert_not_reached ();
653 network_modified
[0] = TRUE
;
655 g_slist_foreach (servers
, (GFunc
) g_object_unref
, NULL
);
656 g_slist_free (servers
);
658 else if (strcmp (name
, "My Server") == 0)
660 /* remove user network */
661 tpaw_irc_network_manager_remove (mgr
, network
);
662 network_modified
[1] = TRUE
;
664 else if (strcmp (name
, "Freenode") == 0)
666 /* remove global network */
667 tpaw_irc_network_manager_remove (mgr
, network
);
668 network_modified
[2] = TRUE
;
670 else if (strcmp (name
, "Undernet") == 0)
672 /* modify global network */
673 server
= tpaw_irc_server_new ("us.undernet.org", 6667, FALSE
);
674 tpaw_irc_network_append_server (network
, server
);
675 g_object_unref (server
);
677 network_modified
[3] = TRUE
;
679 else if (strcmp (name
, "Another Server") == 0)
681 /* Don't change this one */
685 g_assert_not_reached ();
690 g_assert (network_modified
[0] && network_modified
[1] && network_modified
[2]
691 && network_modified
[3]);
693 /* Add a new network */
694 network
= tpaw_irc_network_new ("Great Server");
695 server
= tpaw_irc_server_new ("irc.greatserver.com", 7873, TRUE
);
696 tpaw_irc_network_append_server (network
, server
);
697 tpaw_irc_network_manager_add (mgr
, network
);
698 g_object_unref (server
);
699 g_object_unref (network
);
701 g_slist_foreach (networks
, (GFunc
) g_object_unref
, NULL
);
702 g_slist_free (networks
);
703 g_object_unref (mgr
);
706 /* Now let's reload the file and check its contain */
707 global_file_orig
= get_xml_file (GLOBAL_SAMPLE
);
708 user_file_orig
= get_user_xml_file (USER_FILE
);
709 mgr
= tpaw_irc_network_manager_new (global_file_orig
, user_file_orig
);
710 g_free (global_file_orig
);
711 g_free (user_file_orig
);
713 networks
= tpaw_irc_network_manager_get_networks (mgr
);
714 g_assert_cmpuint (g_slist_length (networks
), ==, 4);
716 network_checked
[0] = network_checked
[1] = network_checked
[2] =
717 network_checked
[3] = FALSE
;
718 /* check networks and servers */
719 for (l
= networks
; l
!= NULL
; l
= g_slist_next (l
))
723 g_object_get (l
->data
, "name", &name
, NULL
);
724 g_assert (name
!= NULL
);
726 if (strcmp (name
, "GIMPNet") == 0)
728 check_network (l
->data
, "GIMPNet", "UTF-8", gimpnet_servers
, 2);
729 network_checked
[0] = TRUE
;
731 else if (strcmp (name
, "Great Server") == 0)
733 check_network (l
->data
, "Great Server", "UTF-8", great_server
, 1);
734 network_checked
[1] = TRUE
;
736 else if (strcmp (name
, "Another Server") == 0)
738 check_network (l
->data
, "Another Server", "UTF-8", another_server
, 1);
739 network_checked
[2] = TRUE
;
741 else if (strcmp (name
, "Undernet") == 0)
743 check_network (l
->data
, "Undernet", "UTF-8", undernet_servers
, 2);
744 network_checked
[3] = TRUE
;
748 g_assert_not_reached ();
753 g_assert (network_checked
[0] && network_checked
[1] && network_checked
[2] &&
756 g_slist_foreach (networks
, (GFunc
) g_object_unref
, NULL
);
757 g_slist_free (networks
);
758 g_object_unref (mgr
);
762 test_tpaw_irc_network_manager_find_network_by_address (void)
764 TpawIrcNetworkManager
*mgr
;
765 TpawIrcNetwork
*network
;
766 struct server_t freenode_servers
[] = {
767 { "irc.freenode.net", 6667, FALSE
},
768 { "irc.eu.freenode.net", 6667, FALSE
}};
769 gchar
*global_file_orig
;
771 global_file_orig
= get_xml_file (GLOBAL_SAMPLE
);
772 mgr
= tpaw_irc_network_manager_new (global_file_orig
, NULL
);
773 g_free (global_file_orig
);
775 network
= tpaw_irc_network_manager_find_network_by_address (mgr
,
777 g_assert (network
!= NULL
);
778 check_network (network
, "Freenode", "UTF-8", freenode_servers
, 2);
780 network
= tpaw_irc_network_manager_find_network_by_address (mgr
,
781 "irc.eu.freenode.net");
782 g_assert (network
!= NULL
);
783 check_network (network
, "Freenode", "UTF-8", freenode_servers
, 2);
785 network
= tpaw_irc_network_manager_find_network_by_address (mgr
,
787 g_assert (network
== NULL
);
789 g_object_unref (mgr
);
793 test_no_modify_with_empty_user_file (void)
795 TpawIrcNetworkManager
*mgr
;
797 gchar
*global_file_orig
;
798 gchar
*user_file_orig
;
800 /* user don't have a networks file yet */
801 user_file_orig
= get_user_xml_file (USER_FILE
);
802 g_unlink (user_file_orig
);
804 global_file_orig
= get_xml_file (GLOBAL_SAMPLE
);
805 mgr
= tpaw_irc_network_manager_new (global_file_orig
, user_file_orig
);
806 g_free (global_file_orig
);
807 g_object_unref (mgr
);
809 /* We didn't modify anything so USER_FILE should be empty */
810 mgr
= tpaw_irc_network_manager_new (NULL
, user_file_orig
);
811 g_free (user_file_orig
);
813 networks
= tpaw_irc_network_manager_get_networks (mgr
);
814 g_assert_cmpuint (g_slist_length (networks
), ==, 0);
816 g_slist_foreach (networks
, (GFunc
) g_object_unref
, NULL
);
817 g_slist_free (networks
);
818 g_object_unref (mgr
);
827 test_init (argc
, argv
);
829 g_test_add_func ("/irc-network-manager/add",
830 test_tpaw_irc_network_manager_add
);
831 g_test_add_func ("/irc-network-manager/load-global-file",
832 test_load_global_file
);
833 g_test_add_func ("/irc-network-manager/remove",
834 test_tpaw_irc_network_manager_remove
);
835 g_test_add_func ("/irc-network-manager/load-user-file", test_load_user_file
);
836 g_test_add_func ("/irc-network-manager/load-both-files",
837 test_load_both_files
);
838 g_test_add_func ("/irc-network-manager/modify-user-file",
839 test_modify_user_file
);
840 g_test_add_func ("/irc-network-manager/modify-both-files",
841 test_modify_both_files
);
842 g_test_add_func ("/irc-network-manager/find-network-by-address",
843 test_tpaw_irc_network_manager_find_network_by_address
);
844 g_test_add_func ("/irc-network-manager/no-modify-with-empty-user-file",
845 test_no_modify_with_empty_user_file
);
847 result
= g_test_run ();