aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am7
-rw-r--r--tests/check-empathy-irc-network-manager.c824
-rw-r--r--tests/check-empathy-irc-network.c240
-rw-r--r--tests/check-empathy-irc-server.c93
-rw-r--r--tests/check-irc-helper.c80
-rw-r--r--tests/check-irc-helper.h27
-rw-r--r--tests/check-libempathy.h3
-rw-r--r--tests/check-main.c3
-rw-r--r--tests/xml/.gitignore1
-rw-r--r--tests/xml/default-irc-networks-sample.xml30
-rw-r--r--tests/xml/user-irc-networks-sample.xml26
11 files changed, 1333 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c72173818..9eb54132f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -26,7 +26,12 @@ check_main_SOURCES = \
check-helpers.c \
check-helpers.h \
check-libempathy.h \
- check-empathy-utils.c
+ check-empathy-utils.c \
+ check-irc-helper.h \
+ check-irc-helper.c \
+ check-empathy-irc-server.c \
+ check-empathy-irc-network.c \
+ check-empathy-irc-network-manager.c
check_main_LDADD = \
@CHECK_LIBS@ \
diff --git a/tests/check-empathy-irc-network-manager.c b/tests/check-empathy-irc-network-manager.c
new file mode 100644
index 000000000..c3e853135
--- /dev/null
+++ b/tests/check-empathy-irc-network-manager.c
@@ -0,0 +1,824 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <glib/gstdio.h>
+
+#include <check.h>
+#include "check-helpers.h"
+#include "check-libempathy.h"
+#include "check-irc-helper.h"
+
+#include <libempathy/empathy-irc-network-manager.h>
+
+#define GLOBAL_SAMPLE "xml/default-irc-networks-sample.xml"
+#define USER_SAMPLE "xml/user-irc-networks-sample.xml"
+#define USER_FILE "xml/user-irc-networks.xml"
+
+START_TEST (test_empathy_irc_network_manager_add)
+{
+ EmpathyIrcNetworkManager *mgr;
+ EmpathyIrcNetwork *network;
+ GSList *networks;
+ gchar *name;
+
+ mgr = empathy_irc_network_manager_new (NULL, NULL);
+ fail_if (mgr == NULL);
+
+ networks = empathy_irc_network_manager_get_networks (mgr);
+ fail_if (networks != NULL);
+
+ /* add a network */
+ network = empathy_irc_network_new ("My Network");
+ fail_if (network == NULL);
+ empathy_irc_network_manager_add (mgr, network);
+ g_object_unref (network);
+
+ networks = empathy_irc_network_manager_get_networks (mgr);
+ fail_if (g_slist_length (networks) != 1);
+ g_object_get (networks->data, "name", &name, NULL);
+ fail_if (name == NULL || strcmp (name, "My Network") != 0);
+ g_free (name);
+ g_slist_foreach (networks, (GFunc) g_object_unref, NULL);
+ g_slist_free (networks);
+
+ /* add another network having the same name */
+ network = empathy_irc_network_new ("My Network");
+ fail_if (network == NULL);
+ empathy_irc_network_manager_add (mgr, network);
+ g_object_unref (network);
+
+ networks = empathy_irc_network_manager_get_networks (mgr);
+ fail_if (g_slist_length (networks) != 2);
+ g_object_get (networks->data, "name", &name, NULL);
+ fail_if (name == NULL || strcmp (name, "My Network") != 0);
+ g_free (name);
+ g_object_get (g_slist_next(networks)->data, "name", &name, NULL);
+ fail_if (name == NULL || strcmp (name, "My Network") != 0);
+ g_free (name);
+ g_slist_foreach (networks, (GFunc) g_object_unref, NULL);
+ g_slist_free (networks);
+
+ g_object_unref (mgr);
+}
+END_TEST
+
+START_TEST (test_load_global_file)
+{
+ EmpathyIrcNetworkManager *mgr;
+ gchar *global_file, *user_file;
+ GSList *networks, *l;
+ struct server_t freenode_servers[] = {
+ { "irc.freenode.net", 6667, FALSE },
+ { "irc.eu.freenode.net", 6667, FALSE }};
+ struct server_t gimpnet_servers[] = {
+ { "irc.gimp.org", 6667, FALSE },
+ { "irc.us.gimp.org", 6667, FALSE }};
+ struct server_t test_servers[] = {
+ { "irc.test.org", 6669, TRUE }};
+ struct server_t undernet_servers[] = {
+ { "eu.undernet.org", 6667, FALSE }};
+ gboolean network_checked[4];
+
+ mgr = empathy_irc_network_manager_new (GLOBAL_SAMPLE, NULL);
+
+ g_object_get (mgr,
+ "global-file", &global_file,
+ "user-file", &user_file,
+ NULL);
+ fail_if (global_file == NULL || strcmp (global_file, GLOBAL_SAMPLE) != 0);
+ fail_if (user_file != NULL);
+ g_free (global_file);
+ g_free (user_file);
+
+ networks = empathy_irc_network_manager_get_networks (mgr);
+ fail_if (g_slist_length (networks) != 4);
+
+ network_checked[0] = network_checked[1] = network_checked[2] =
+ network_checked[3] = FALSE;
+ /* check networks and servers */
+ for (l = networks; l != NULL; l = g_slist_next (l))
+ {
+ gchar *name;
+
+ g_object_get (l->data, "name", &name, NULL);
+ fail_if (name == NULL);
+
+ if (strcmp (name, "Freenode") == 0)
+ {
+ check_network (l->data, "Freenode", "UTF-8", freenode_servers, 2);
+ network_checked[0] = TRUE;
+ }
+ else if (strcmp (name, "GIMPNet") == 0)
+ {
+ check_network (l->data, "GIMPNet", "UTF-8", gimpnet_servers, 2);
+ network_checked[1] = TRUE;
+ }
+ else if (strcmp (name, "Test Server") == 0)
+ {
+ check_network (l->data, "Test Server", "ISO-8859-1", test_servers, 1);
+ network_checked[2] = TRUE;
+ }
+ else if (strcmp (name, "Undernet") == 0)
+ {
+ check_network (l->data, "Undernet", "UTF-8", undernet_servers, 1);
+ network_checked[3] = TRUE;
+ }
+ else
+ {
+ fail_if (TRUE);
+ }
+
+ g_free (name);
+ }
+ fail_if (!network_checked[0] || !network_checked[1] || !network_checked[2] ||
+ !network_checked[3]);
+
+ g_slist_foreach (networks, (GFunc) g_object_unref, NULL);
+ g_slist_free (networks);
+ g_object_unref (mgr);
+}
+END_TEST
+
+static gboolean
+remove_network_named (EmpathyIrcNetworkManager *mgr,
+ const gchar *network_name)
+{
+ GSList *networks, *l;
+ gboolean removed = FALSE;
+
+ networks = empathy_irc_network_manager_get_networks (mgr);
+
+ /* check networks and servers */
+ for (l = networks; l != NULL && !removed; l = g_slist_next (l))
+ {
+ EmpathyIrcNetwork *network = l->data;
+ gchar *name;
+
+ g_object_get (network, "name", &name, NULL);
+ fail_if (name == NULL);
+
+ if (strcmp (name, network_name) == 0)
+ {
+ empathy_irc_network_manager_remove (mgr, network);
+ removed = TRUE;
+ }
+
+ g_free (name);
+ }
+
+ g_slist_foreach (networks, (GFunc) g_object_unref, NULL);
+ g_slist_free (networks);
+
+ return removed;
+}
+
+START_TEST (test_empathy_irc_network_manager_remove)
+{
+ EmpathyIrcNetworkManager *mgr;
+ GSList *networks, *l;
+ struct server_t freenode_servers[] = {
+ { "irc.freenode.net", 6667, FALSE },
+ { "irc.eu.freenode.net", 6667, FALSE }};
+ struct server_t test_servers[] = {
+ { "irc.test.org", 6669, TRUE }};
+ struct server_t undernet_servers[] = {
+ { "eu.undernet.org", 6667, FALSE }};
+ gboolean network_checked[3];
+ gboolean result;
+
+ mgr = empathy_irc_network_manager_new (GLOBAL_SAMPLE, NULL);
+
+ result = remove_network_named (mgr, "GIMPNet");
+ fail_if (!result);
+
+ networks = empathy_irc_network_manager_get_networks (mgr);
+ fail_if (g_slist_length (networks) != 3);
+
+ network_checked[0] = network_checked[1] = network_checked[2] = FALSE;
+ /* check networks and servers */
+ for (l = networks; l != NULL; l = g_slist_next (l))
+ {
+ gchar *name;
+
+ g_object_get (l->data, "name", &name, NULL);
+ fail_if (name == NULL);
+
+ if (strcmp (name, "Freenode") == 0)
+ {
+ check_network (l->data, "Freenode", "UTF-8", freenode_servers, 2);
+ network_checked[0] = TRUE;
+ }
+ else if (strcmp (name, "Test Server") == 0)
+ {
+ check_network (l->data, "Test Server", "ISO-8859-1", test_servers, 1);
+ network_checked[1] = TRUE;
+ }
+ else if (strcmp (name, "Undernet") == 0)
+ {
+ check_network (l->data, "Undernet", "UTF-8", undernet_servers, 1);
+ network_checked[2] = TRUE;
+ }
+ else
+ {
+ fail_if (TRUE);
+ }
+
+ g_free (name);
+ }
+ fail_if (!network_checked[0] || !network_checked[1] || !network_checked[2]);
+
+ g_slist_foreach (networks, (GFunc) g_object_unref, NULL);
+ g_slist_free (networks);
+ g_object_unref (mgr);
+}
+END_TEST
+
+static void
+copy_user_file (void)
+{
+ gboolean result;
+ gchar *buffer;
+ gsize length;
+
+ result = g_file_get_contents (USER_SAMPLE, &buffer, &length, NULL);
+ fail_if (!result);
+
+ result = g_file_set_contents (USER_FILE, buffer, length, NULL);
+ fail_if (!result);
+
+ g_free (buffer);
+}
+
+START_TEST (test_load_user_file)
+{
+ EmpathyIrcNetworkManager *mgr;
+ gchar *global_file, *user_file;
+ GSList *networks, *l;
+ struct server_t gimpnet_servers[] = {
+ { "irc.gimp.org", 6667, FALSE },
+ { "irc.us.gimp.org", 6667, FALSE },
+ { "irc.au.gimp.org", 6667, FALSE }};
+ struct server_t my_server[] = {
+ { "irc.mysrv.net", 7495, TRUE }};
+ struct server_t another_server[] = {
+ { "irc.anothersrv.be", 6660, FALSE }};
+ gboolean network_checked[3];
+
+ copy_user_file ();
+ mgr = empathy_irc_network_manager_new (NULL, USER_FILE);
+
+ g_object_get (mgr,
+ "global-file", &global_file,
+ "user-file", &user_file,
+ NULL);
+ fail_if (global_file != NULL);
+ fail_if (user_file == NULL || strcmp (user_file, USER_FILE) != 0);
+ g_free (global_file);
+ g_free (user_file);
+
+ networks = empathy_irc_network_manager_get_networks (mgr);
+ fail_if (g_slist_length (networks) != 3);
+
+ network_checked[0] = network_checked[1] = network_checked[2] = FALSE;
+ /* check networks and servers */
+ for (l = networks; l != NULL; l = g_slist_next (l))
+ {
+ gchar *name;
+
+ g_object_get (l->data, "name", &name, NULL);
+ fail_if (name == NULL);
+
+ if (strcmp (name, "GIMPNet") == 0)
+ {
+ check_network (l->data, "GIMPNet", "UTF-8", gimpnet_servers, 3);
+ network_checked[0] = TRUE;
+ }
+ else if (strcmp (name, "My Server") == 0)
+ {
+ check_network (l->data, "My Server", "UTF-8", my_server, 1);
+ network_checked[1] = TRUE;
+ }
+ else if (strcmp (name, "Another Server") == 0)
+ {
+ check_network (l->data, "Another Server", "UTF-8", another_server, 1);
+ network_checked[2] = TRUE;
+ }
+ else
+ {
+ fail_if (TRUE);
+ }
+
+ g_free (name);
+ }
+ fail_if (!network_checked[0] || !network_checked[1] || !network_checked[2]);
+
+ g_slist_foreach (networks, (GFunc) g_object_unref, NULL);
+ g_slist_free (networks);
+ g_object_unref (mgr);
+}
+END_TEST
+
+START_TEST (test_load_both_files)
+{
+ EmpathyIrcNetworkManager *mgr;
+ gchar *global_file, *user_file;
+ GSList *networks, *l;
+ struct server_t freenode_servers[] = {
+ { "irc.freenode.net", 6667, FALSE },
+ { "irc.eu.freenode.net", 6667, FALSE }};
+ struct server_t gimpnet_servers[] = {
+ { "irc.gimp.org", 6667, FALSE },
+ { "irc.us.gimp.org", 6667, FALSE },
+ { "irc.au.gimp.org", 6667, FALSE }};
+ struct server_t my_server[] = {
+ { "irc.mysrv.net", 7495, TRUE }};
+ struct server_t another_server[] = {
+ { "irc.anothersrv.be", 6660, FALSE }};
+ struct server_t undernet_servers[] = {
+ { "eu.undernet.org", 6667, FALSE }};
+ gboolean network_checked[5];
+
+ mgr = empathy_irc_network_manager_new (GLOBAL_SAMPLE, USER_FILE);
+
+ g_object_get (mgr,
+ "global-file", &global_file,
+ "user-file", &user_file,
+ NULL);
+ fail_if (global_file == NULL || strcmp (global_file, GLOBAL_SAMPLE) != 0);
+ fail_if (user_file == NULL || strcmp (user_file, USER_FILE) != 0);
+ g_free (global_file);
+ g_free (user_file);
+
+ networks = empathy_irc_network_manager_get_networks (mgr);
+ fail_if (g_slist_length (networks) != 5);
+
+ network_checked[0] = network_checked[1] = network_checked[2] =
+ network_checked[3] = network_checked[4] = FALSE;
+ /* check networks and servers */
+ for (l = networks; l != NULL; l = g_slist_next (l))
+ {
+ gchar *name;
+
+ g_object_get (l->data, "name", &name, NULL);
+ fail_if (name == NULL);
+
+ if (strcmp (name, "Freenode") == 0)
+ {
+ check_network (l->data, "Freenode", "UTF-8", freenode_servers, 2);
+ network_checked[0] = TRUE;
+ }
+ else if (strcmp (name, "GIMPNet") == 0)
+ {
+ check_network (l->data, "GIMPNet", "UTF-8", gimpnet_servers, 3);
+ network_checked[1] = TRUE;
+ }
+ else if (strcmp (name, "My Server") == 0)
+ {
+ check_network (l->data, "My Server", "UTF-8", my_server, 1);
+ network_checked[2] = TRUE;
+ }
+ else if (strcmp (name, "Another Server") == 0)
+ {
+ check_network (l->data, "Another Server", "UTF-8", another_server, 1);
+ network_checked[3] = TRUE;
+ }
+ else if (strcmp (name, "Undernet") == 0)
+ {
+ check_network (l->data, "Undernet", "UTF-8", undernet_servers, 1);
+ network_checked[4] = TRUE;
+ }
+ else
+ {
+ fail_if (TRUE);
+ }
+
+ g_free (name);
+ }
+ fail_if (!network_checked[0] || !network_checked[1] || !network_checked[2] ||
+ !network_checked[3] || !network_checked[4]);
+
+ g_slist_foreach (networks, (GFunc) g_object_unref, NULL);
+ g_slist_free (networks);
+ g_object_unref (mgr);
+}
+END_TEST
+
+START_TEST (test_modify_user_file)
+{
+ EmpathyIrcNetworkManager *mgr;
+ EmpathyIrcNetwork *network;
+ EmpathyIrcServer *server;
+ gchar *global_file, *user_file;
+ GSList *networks, *l;
+ struct server_t gimpnet_servers[] = {
+ { "irc.gimp.org", 6667, TRUE },
+ { "irc.us.gimp.org", 6668, FALSE }};
+ struct server_t great_server[] = {
+ { "irc.greatserver.com", 7873, TRUE }};
+ struct server_t another_server[] = {
+ { "irc.anothersrv.be", 6660, FALSE }};
+ gboolean network_modified[2];
+ gboolean network_checked[3];
+
+ copy_user_file ();
+ mgr = empathy_irc_network_manager_new (NULL, USER_FILE);
+
+ g_object_get (mgr,
+ "global-file", &global_file,
+ "user-file", &user_file,
+ NULL);
+ fail_if (global_file != NULL);
+ fail_if (user_file == NULL || strcmp (user_file, USER_FILE) != 0);
+ g_free (global_file);
+ g_free (user_file);
+
+ networks = empathy_irc_network_manager_get_networks (mgr);
+ fail_if (g_slist_length (networks) != 3);
+
+ network_modified[0] = network_modified[1] = FALSE;
+ /* check networks and servers */
+ for (l = networks; l != NULL; l = g_slist_next (l))
+ {
+ EmpathyIrcNetwork *network;
+ gchar *name;
+
+ network = l->data;
+ g_object_get (network, "name", &name, NULL);
+ fail_if (name == NULL);
+
+ if (strcmp (name, "GIMPNet") == 0)
+ {
+ GSList *servers, *ll;
+
+ /* change charset */
+ g_object_set (network, "charset", "ISO-8859-1", NULL);
+
+ servers = empathy_irc_network_get_servers (network);
+ for (ll = servers; ll != NULL; ll = g_slist_next (ll))
+ {
+ EmpathyIrcServer *server;
+ gchar *address;
+
+ server = ll->data;
+ g_object_get (server, "address", &address, NULL);
+ if (strcmp (address, "irc.gimp.org") == 0)
+ {
+ /* change SSL */
+ g_object_set (server, "ssl", TRUE, NULL);
+ }
+ else if (strcmp (address, "irc.us.gimp.org") == 0)
+ {
+ /* change port */
+ g_object_set (server, "port", 6668, NULL);
+ }
+ else if (strcmp (address, "irc.au.gimp.org") == 0)
+ {
+ /* remove this server */
+ empathy_irc_network_remove_server (network, server);
+ }
+ else
+ {
+ fail_if (TRUE);
+ }
+
+ g_free (address);
+ }
+
+ network_modified[0] = TRUE;
+
+ g_slist_foreach (servers, (GFunc) g_object_unref, NULL);
+ g_slist_free (servers);
+ }
+ else if (strcmp (name, "My Server") == 0)
+ {
+ /* remove this network */
+ empathy_irc_network_manager_remove (mgr, network);
+ network_modified[1] = TRUE;
+ }
+ else if (strcmp (name, "Another Server") == 0)
+ {
+ /* Don't change this one */
+ }
+ else
+ {
+ fail_if (TRUE);
+ }
+
+ g_free (name);
+ }
+ fail_if (!network_modified[0] || !network_modified[1]);
+
+ /* Add a new network */
+ network = empathy_irc_network_new ("Great Server");
+ server = empathy_irc_server_new ("irc.greatserver.com", 7873, TRUE);
+ empathy_irc_network_append_server (network, server);
+ empathy_irc_network_manager_add (mgr, network);
+ g_object_unref (server);
+ g_object_unref (network);
+
+ g_slist_foreach (networks, (GFunc) g_object_unref, NULL);
+ g_slist_free (networks);
+ g_object_unref (mgr);
+
+
+ /* Now let's reload the file and check its contain */
+ mgr = empathy_irc_network_manager_new (NULL, USER_FILE);
+
+ networks = empathy_irc_network_manager_get_networks (mgr);
+ fail_if (g_slist_length (networks) != 3);
+
+ network_checked[0] = network_checked[1] = network_checked[2] = FALSE;
+ /* check networks and servers */
+ for (l = networks; l != NULL; l = g_slist_next (l))
+ {
+ gchar *name;
+
+ g_object_get (l->data, "name", &name, NULL);
+ fail_if (name == NULL);
+
+ if (strcmp (name, "GIMPNet") == 0)
+ {
+ check_network (l->data, "GIMPNet", "ISO-8859-1", gimpnet_servers, 2);
+ network_checked[0] = TRUE;
+ }
+ else if (strcmp (name, "Great Server") == 0)
+ {
+ check_network (l->data, "Great Server", "UTF-8", great_server, 1);
+ network_checked[1] = TRUE;
+ }
+ else if (strcmp (name, "Another Server") == 0)
+ {
+ check_network (l->data, "Another Server", "UTF-8", another_server, 1);
+ network_checked[2] = TRUE;
+ }
+ else
+ {
+ fail_if (TRUE);
+ }
+
+ g_free (name);
+ }
+ fail_if (!network_checked[0] || !network_checked[1] || !network_checked[2]);
+
+ g_slist_foreach (networks, (GFunc) g_object_unref, NULL);
+ g_slist_free (networks);
+ g_object_unref (mgr);
+}
+END_TEST
+
+START_TEST (test_modify_both_files)
+{
+ EmpathyIrcNetworkManager *mgr;
+ EmpathyIrcNetwork *network;
+ EmpathyIrcServer *server;
+ gchar *global_file, *user_file;
+ GSList *networks, *l;
+ struct server_t gimpnet_servers[] = {
+ { "irc.gimp.org", 6667, TRUE },
+ { "irc.us.gimp.org", 6668, FALSE }};
+ struct server_t great_server[] = {
+ { "irc.greatserver.com", 7873, TRUE }};
+ struct server_t another_server[] = {
+ { "irc.anothersrv.be", 6660, FALSE }};
+ struct server_t undernet_servers[] = {
+ { "eu.undernet.org", 6667, FALSE },
+ { "us.undernet.org", 6667, FALSE }};
+ gboolean network_modified[4];
+ gboolean network_checked[4];
+
+ copy_user_file ();
+ mgr = empathy_irc_network_manager_new (GLOBAL_SAMPLE, USER_FILE);
+
+ g_object_get (mgr,
+ "global-file", &global_file,
+ "user-file", &user_file,
+ NULL);
+ fail_if (global_file == NULL || strcmp (global_file, GLOBAL_SAMPLE) != 0);
+ fail_if (user_file == NULL || strcmp (user_file, USER_FILE) != 0);
+ g_free (global_file);
+ g_free (user_file);
+
+ networks = empathy_irc_network_manager_get_networks (mgr);
+ fail_if (g_slist_length (networks) != 5);
+
+ network_modified[0] = network_modified[1] = network_modified[2] =
+ network_modified[3] = FALSE;
+ /* check networks and servers */
+ for (l = networks; l != NULL; l = g_slist_next (l))
+ {
+ EmpathyIrcNetwork *network;
+ gchar *name;
+
+ network = l->data;
+ g_object_get (network, "name", &name, NULL);
+ fail_if (name == NULL);
+
+ if (strcmp (name, "GIMPNet") == 0)
+ {
+ /* Modify user network */
+ GSList *servers, *ll;
+
+ servers = empathy_irc_network_get_servers (network);
+ for (ll = servers; ll != NULL; ll = g_slist_next (ll))
+ {
+ EmpathyIrcServer *server;
+ gchar *address;
+
+ server = ll->data;
+ g_object_get (server, "address", &address, NULL);
+ if (strcmp (address, "irc.gimp.org") == 0)
+ {
+ /* change SSL */
+ g_object_set (server, "ssl", TRUE, NULL);
+ }
+ else if (strcmp (address, "irc.us.gimp.org") == 0)
+ {
+ /* change port */
+ g_object_set (server, "port", 6668, NULL);
+ }
+ else if (strcmp (address, "irc.au.gimp.org") == 0)
+ {
+ /* remove this server */
+ empathy_irc_network_remove_server (network, server);
+ }
+ else
+ {
+ fail_if (TRUE);
+ }
+
+ g_free (address);
+ }
+
+ network_modified[0] = TRUE;
+
+ g_slist_foreach (servers, (GFunc) g_object_unref, NULL);
+ g_slist_free (servers);
+ }
+ else if (strcmp (name, "My Server") == 0)
+ {
+ /* remove user network */
+ empathy_irc_network_manager_remove (mgr, network);
+ network_modified[1] = TRUE;
+ }
+ else if (strcmp (name, "Freenode") == 0)
+ {
+ /* remove global network */
+ empathy_irc_network_manager_remove (mgr, network);
+ network_modified[2] = TRUE;
+ }
+ else if (strcmp (name, "Undernet") == 0)
+ {
+ /* modify global network */
+ EmpathyIrcServer *server;
+
+ server = empathy_irc_server_new ("us.undernet.org", 6667, FALSE);
+ empathy_irc_network_append_server (network, server);
+ g_object_unref (server);
+
+ network_modified[3] = TRUE;
+ }
+ else if (strcmp (name, "Another Server") == 0)
+ {
+ /* Don't change this one */
+ }
+ else
+ {
+ fail_if (TRUE);
+ }
+
+ g_free (name);
+ }
+ fail_if (!network_modified[0] || !network_modified[1] || !network_modified[2]
+ || !network_modified[3]);
+
+ /* Add a new network */
+ network = empathy_irc_network_new ("Great Server");
+ server = empathy_irc_server_new ("irc.greatserver.com", 7873, TRUE);
+ empathy_irc_network_append_server (network, server);
+ empathy_irc_network_manager_add (mgr, network);
+ g_object_unref (server);
+ g_object_unref (network);
+
+ g_slist_foreach (networks, (GFunc) g_object_unref, NULL);
+ g_slist_free (networks);
+ g_object_unref (mgr);
+
+
+ /* Now let's reload the file and check its contain */
+ mgr = empathy_irc_network_manager_new (GLOBAL_SAMPLE, USER_FILE);
+
+ networks = empathy_irc_network_manager_get_networks (mgr);
+ fail_if (g_slist_length (networks) != 4);
+
+ network_checked[0] = network_checked[1] = network_checked[2] =
+ network_checked[3] = FALSE;
+ /* check networks and servers */
+ for (l = networks; l != NULL; l = g_slist_next (l))
+ {
+ gchar *name;
+
+ g_object_get (l->data, "name", &name, NULL);
+ fail_if (name == NULL);
+
+ if (strcmp (name, "GIMPNet") == 0)
+ {
+ check_network (l->data, "GIMPNet", "UTF-8", gimpnet_servers, 2);
+ network_checked[0] = TRUE;
+ }
+ else if (strcmp (name, "Great Server") == 0)
+ {
+ check_network (l->data, "Great Server", "UTF-8", great_server, 1);
+ network_checked[1] = TRUE;
+ }
+ else if (strcmp (name, "Another Server") == 0)
+ {
+ check_network (l->data, "Another Server", "UTF-8", another_server, 1);
+ network_checked[2] = TRUE;
+ }
+ else if (strcmp (name, "Undernet") == 0)
+ {
+ check_network (l->data, "Undernet", "UTF-8", undernet_servers, 2);
+ network_checked[3] = TRUE;
+ }
+ else
+ {
+ fail_if (TRUE);
+ }
+
+ g_free (name);
+ }
+ fail_if (!network_checked[0] || !network_checked[1] || !network_checked[2] ||
+ !network_checked[3]);
+
+ g_slist_foreach (networks, (GFunc) g_object_unref, NULL);
+ g_slist_free (networks);
+ g_object_unref (mgr);
+}
+END_TEST
+
+START_TEST (test_empathy_irc_network_manager_find_network_by_address)
+{
+ EmpathyIrcNetworkManager *mgr;
+ EmpathyIrcNetwork *network;
+ struct server_t freenode_servers[] = {
+ { "irc.freenode.net", 6667, FALSE },
+ { "irc.eu.freenode.net", 6667, FALSE }};
+
+ mgr = empathy_irc_network_manager_new (GLOBAL_SAMPLE, NULL);
+
+ network = empathy_irc_network_manager_find_network_by_address (mgr,
+ "irc.freenode.net");
+ fail_if (network == NULL);
+ check_network (network, "Freenode", "UTF-8", freenode_servers, 2);
+
+ network = empathy_irc_network_manager_find_network_by_address (mgr,
+ "irc.eu.freenode.net");
+ fail_if (network == NULL);
+ check_network (network, "Freenode", "UTF-8", freenode_servers, 2);
+
+ network = empathy_irc_network_manager_find_network_by_address (mgr,
+ "unknown");
+ fail_if (network != NULL);
+
+ g_object_unref (mgr);
+}
+END_TEST
+
+START_TEST (test_no_modify_with_empty_user_file)
+{
+ EmpathyIrcNetworkManager *mgr;
+ GSList *networks;
+
+ /* user don't have a networks file yet */
+ g_unlink (USER_FILE);
+
+ mgr = empathy_irc_network_manager_new (GLOBAL_SAMPLE, USER_FILE);
+ g_object_unref (mgr);
+
+ /* We didn't modify anything so USER_FILE should be empty */
+ mgr = empathy_irc_network_manager_new (NULL, USER_FILE);
+
+ networks = empathy_irc_network_manager_get_networks (mgr);
+ fail_if (g_slist_length (networks) != 0);
+
+ g_slist_foreach (networks, (GFunc) g_object_unref, NULL);
+ g_slist_free (networks);
+ g_object_unref (mgr);
+}
+END_TEST
+
+TCase *
+make_empathy_irc_network_manager_tcase (void)
+{
+ TCase *tc = tcase_create ("empathy-irc-network-manager");
+ tcase_add_test (tc, test_empathy_irc_network_manager_add);
+ tcase_add_test (tc, test_load_global_file);
+ tcase_add_test (tc, test_empathy_irc_network_manager_remove);
+ tcase_add_test (tc, test_load_user_file);
+ tcase_add_test (tc, test_load_both_files);
+ tcase_add_test (tc, test_modify_user_file);
+ tcase_add_test (tc, test_modify_both_files);
+ tcase_add_test (tc, test_empathy_irc_network_manager_find_network_by_address);
+ tcase_add_test (tc, test_no_modify_with_empty_user_file);
+ return tc;
+}
diff --git a/tests/check-empathy-irc-network.c b/tests/check-empathy-irc-network.c
new file mode 100644
index 000000000..b8124a305
--- /dev/null
+++ b/tests/check-empathy-irc-network.c
@@ -0,0 +1,240 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <check.h>
+#include "check-helpers.h"
+#include "check-libempathy.h"
+#include "check-irc-helper.h"
+
+#include <libempathy/empathy-irc-network.h>
+
+START_TEST (test_empathy_irc_network_new)
+{
+ EmpathyIrcNetwork *network;
+
+ network = empathy_irc_network_new ("Network1");
+ check_network (network, "Network1", "UTF-8", NULL, 0);
+
+ g_object_unref (network);
+}
+END_TEST
+
+START_TEST (test_property_change)
+{
+ EmpathyIrcNetwork *network;
+
+ network = empathy_irc_network_new ("Network1");
+ check_network (network, "Network1", "UTF-8", NULL, 0);
+
+ g_object_set (network,
+ "name", "Network2",
+ "charset", "ISO-8859-1",
+ NULL);
+
+ check_network (network, "Network2", "ISO-8859-1", NULL, 0);
+
+ g_object_unref (network);
+
+}
+END_TEST
+
+static gboolean modified;
+
+static void
+modified_cb (EmpathyIrcNetwork *network,
+ gpointer unused)
+{
+ modified = TRUE;
+}
+
+START_TEST (test_modified_signal)
+{
+ EmpathyIrcNetwork *network;
+
+ network = empathy_irc_network_new ("Network1");
+ check_network (network, "Network1", "UTF-8", NULL, 0);
+
+ modified = FALSE;
+ g_signal_connect (network, "modified", G_CALLBACK (modified_cb), NULL);
+
+ g_object_set (network, "name", "Network2", NULL);
+ fail_if (!modified);
+ modified = FALSE;
+ g_object_set (network, "name", "Network2", NULL);
+ fail_if (modified);
+
+ g_object_unref (network);
+}
+END_TEST
+
+static void
+add_servers (EmpathyIrcNetwork *network,
+ struct server_t *servers,
+ guint nb_servers)
+{
+ guint i;
+
+ for (i = 0; i < nb_servers; i ++)
+ {
+ EmpathyIrcServer *server;
+
+ server = empathy_irc_server_new (servers[i].address,
+ servers[i].port, servers[i].ssl);
+ modified = FALSE;
+ empathy_irc_network_append_server (network, server);
+ fail_if (!modified);
+ g_object_unref (server);
+ }
+}
+
+START_TEST (test_add_server)
+{
+ EmpathyIrcNetwork *network;
+ EmpathyIrcServer *server;
+ GSList *servers, *l;
+ struct server_t test_servers[] = {
+ { "server1", 6667, FALSE },
+ { "server2", 6668, TRUE },
+ { "server3", 6667, FALSE },
+ { "server4", 6669, TRUE }};
+ struct server_t servers_without_3[] = {
+ { "server1", 6667, FALSE },
+ { "server2", 6668, TRUE },
+ { "server4", 6669, TRUE }};
+
+ network = empathy_irc_network_new ("Network1");
+ check_network (network, "Network1", "UTF-8", NULL, 0);
+
+ modified = FALSE;
+ g_signal_connect (network, "modified", G_CALLBACK (modified_cb), NULL);
+
+ check_network (network, "Network1", "UTF-8", NULL, 0);
+
+ /* add the servers */
+ add_servers (network, test_servers, 4);
+
+ check_network (network, "Network1", "UTF-8", test_servers, 4);
+
+ /* Now let's remove the 3rd server */
+ servers = empathy_irc_network_get_servers (network);
+ l = g_slist_nth (servers, 2);
+ fail_if (l == NULL);
+ server = l->data;
+ modified = FALSE;
+ empathy_irc_network_remove_server (network, server);
+ fail_if (!modified);
+
+ /* free the list */
+ g_slist_foreach (servers, (GFunc) g_object_unref, NULL);
+ g_slist_free (servers);
+
+ /* The 3rd server should have disappear */
+ check_network (network, "Network1", "UTF-8", servers_without_3, 3);
+
+ g_object_unref (network);
+}
+END_TEST
+
+START_TEST (test_modified_signal_because_of_server)
+{
+ EmpathyIrcNetwork *network;
+ EmpathyIrcServer *server;
+
+ network = empathy_irc_network_new ("Network1");
+ check_network (network, "Network1", "UTF-8", NULL, 0);
+
+ g_signal_connect (network, "modified", G_CALLBACK (modified_cb), NULL);
+
+ server = empathy_irc_server_new ("server1", 6667, FALSE);
+ empathy_irc_network_append_server (network, server);
+
+ /* Change server properties */
+ modified = FALSE;
+ g_object_set (server, "address", "server2", NULL);
+ fail_if (!modified);
+ modified = FALSE;
+ g_object_set (server, "port", 6668, NULL);
+ fail_if (!modified);
+ modified = FALSE;
+ g_object_set (server, "ssl", TRUE, NULL);
+ fail_if (!modified);
+
+ empathy_irc_network_remove_server (network, server);
+ modified = FALSE;
+ g_object_set (server, "address", "server3", NULL);
+ /* We removed the server so the network is not modified anymore */
+ fail_if (modified);
+
+ g_object_unref (network);
+}
+END_TEST
+
+START_TEST (test_empathy_irc_network_set_server_position)
+{
+ EmpathyIrcNetwork *network;
+ GSList *servers, *l;
+ struct server_t test_servers[] = {
+ { "server1", 6667, FALSE },
+ { "server2", 6668, TRUE },
+ { "server3", 6667, FALSE },
+ { "server4", 6669, TRUE }};
+ struct server_t test_servers_sorted[] = {
+ { "server2", 6668, TRUE },
+ { "server4", 6669, TRUE },
+ { "server3", 6667, FALSE },
+ { "server1", 6667, FALSE }};
+
+ network = empathy_irc_network_new ("Network1");
+ check_network (network, "Network1", "UTF-8", NULL, 0);
+
+ modified = FALSE;
+ g_signal_connect (network, "modified", G_CALLBACK (modified_cb), NULL);
+
+ /* add the servers */
+ add_servers (network, test_servers, 4);
+ check_network (network, "Network1", "UTF-8", test_servers, 4);
+
+ /* get servers list */
+ servers = empathy_irc_network_get_servers (network);
+ fail_if (g_slist_length (servers) != 4);
+ modified = FALSE;
+
+ /* server1 go to the last position */
+ empathy_irc_network_set_server_position (network, servers->data, -1);
+
+ /* server2 go to the first position */
+ l = servers->next;
+ empathy_irc_network_set_server_position (network, l->data, 0);
+
+ /* server3 go to the third position */
+ l = l->next;
+ empathy_irc_network_set_server_position (network, l->data, 2);
+
+ /* server4 go to the second position*/
+ l = l->next;
+ empathy_irc_network_set_server_position (network, l->data, 1);
+
+ fail_if (!modified);
+
+ /* free the list */
+ g_slist_foreach (servers, (GFunc) g_object_unref, NULL);
+ g_slist_free (servers);
+
+ /* Check if servers are sorted */
+ check_network (network, "Network1", "UTF-8", test_servers_sorted, 4);
+}
+END_TEST
+
+TCase *
+make_empathy_irc_network_tcase (void)
+{
+ TCase *tc = tcase_create ("empathy-irc-network");
+ tcase_add_test (tc, test_empathy_irc_network_new);
+ tcase_add_test (tc, test_property_change);
+ tcase_add_test (tc, test_modified_signal);
+ tcase_add_test (tc, test_add_server);
+ tcase_add_test (tc, test_modified_signal_because_of_server);
+ tcase_add_test (tc, test_empathy_irc_network_set_server_position);
+ return tc;
+}
diff --git a/tests/check-empathy-irc-server.c b/tests/check-empathy-irc-server.c
new file mode 100644
index 000000000..52607f221
--- /dev/null
+++ b/tests/check-empathy-irc-server.c
@@ -0,0 +1,93 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <check.h>
+#include "check-helpers.h"
+#include "check-libempathy.h"
+#include "check-irc-helper.h"
+
+#include <libempathy/empathy-irc-server.h>
+
+START_TEST (test_empathy_irc_server_new)
+{
+ EmpathyIrcServer *server;
+
+ server = empathy_irc_server_new ("test.localhost", 6667, TRUE);
+ check_server (server, "test.localhost", 6667, TRUE);
+
+ g_object_unref (server);
+}
+END_TEST
+
+START_TEST (test_property_change)
+{
+ EmpathyIrcServer *server;
+
+ server = empathy_irc_server_new ("test.localhost", 6667, TRUE);
+ fail_if (server == NULL);
+
+ g_object_set (server,
+ "address", "test2.localhost",
+ "port", 6668,
+ "ssl", FALSE,
+ NULL);
+
+ check_server (server, "test2.localhost", 6668, FALSE);
+
+ g_object_unref (server);
+}
+END_TEST
+
+static gboolean modified = FALSE;
+
+static void
+modified_cb (EmpathyIrcServer *server,
+ gpointer unused)
+{
+ modified = TRUE;
+}
+
+START_TEST (test_modified_signal)
+{
+ EmpathyIrcServer *server;
+
+ server = empathy_irc_server_new ("test.localhost", 6667, TRUE);
+ fail_if (server == NULL);
+
+ g_signal_connect (server, "modified", G_CALLBACK (modified_cb), NULL);
+
+ /* address */
+ g_object_set (server, "address", "test2.localhost", NULL);
+ fail_if (!modified);
+ modified = FALSE;
+ g_object_set (server, "address", "test2.localhost", NULL);
+ fail_if (modified);
+
+ /* port */
+ g_object_set (server, "port", 6668, NULL);
+ fail_if (!modified);
+ modified = FALSE;
+ g_object_set (server, "port", 6668, NULL);
+ fail_if (modified);
+
+ /* ssl */
+ g_object_set (server, "ssl", FALSE, NULL);
+ fail_if (!modified);
+ modified = FALSE;
+ g_object_set (server, "ssl", FALSE, NULL);
+ fail_if (modified);
+
+ g_object_unref (server);
+}
+END_TEST
+
+TCase *
+make_empathy_irc_server_tcase (void)
+{
+ TCase *tc = tcase_create ("empathy-irc-server");
+ tcase_add_test (tc, test_empathy_irc_server_new);
+ tcase_add_test (tc, test_property_change);
+ tcase_add_test (tc, test_modified_signal);
+ return tc;
+}
diff --git a/tests/check-irc-helper.c b/tests/check-irc-helper.c
new file mode 100644
index 000000000..477b134c2
--- /dev/null
+++ b/tests/check-irc-helper.c
@@ -0,0 +1,80 @@
+#include "check-irc-helper.h"
+
+void
+check_server (EmpathyIrcServer *server,
+ const gchar *_address,
+ guint _port,
+ gboolean _ssl)
+{
+ gchar *address;
+ guint port;
+ gboolean ssl;
+
+ fail_if (server == NULL);
+
+ g_object_get (server,
+ "address", &address,
+ "port", &port,
+ "ssl", &ssl,
+ NULL);
+
+ fail_if (address == NULL || strcmp (address, _address) != 0);
+ fail_if (port != _port);
+ fail_if (ssl != _ssl);
+
+ g_free (address);
+}
+
+void
+check_network (EmpathyIrcNetwork *network,
+ const gchar *_name,
+ const gchar *_charset,
+ struct server_t *_servers,
+ guint nb_servers)
+{
+ gchar *name, *charset;
+ GSList *servers, *l;
+ guint i;
+
+ fail_if (network == NULL);
+
+ g_object_get (network,
+ "name", &name,
+ "charset", &charset,
+ NULL);
+
+ fail_if (name == NULL || strcmp (name, _name) != 0);
+ fail_if (charset == NULL || strcmp (charset, _charset) != 0);
+
+ servers = empathy_irc_network_get_servers (network);
+ fail_if (g_slist_length (servers) != nb_servers);
+
+ /* Is that the right servers ? */
+ for (l = servers, i = 0; l != NULL; l = g_slist_next (l), i++)
+ {
+ EmpathyIrcServer *server;
+ gchar *address;
+ guint port;
+ gboolean ssl;
+
+ server = l->data;
+
+ g_object_get (server,
+ "address", &address,
+ "port", &port,
+ "ssl", &ssl,
+ NULL);
+
+ fail_if (address == NULL || strcmp (address, _servers[i].address)
+ != 0);
+ fail_if (port != _servers[i].port);
+ fail_if (ssl != _servers[i].ssl);
+
+ g_free (address);
+ }
+
+ g_slist_foreach (servers, (GFunc) g_object_unref, NULL);
+ g_slist_free (servers);
+ g_free (name);
+ g_free (charset);
+}
diff --git a/tests/check-irc-helper.h b/tests/check-irc-helper.h
new file mode 100644
index 000000000..32a34b60d
--- /dev/null
+++ b/tests/check-irc-helper.h
@@ -0,0 +1,27 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include <check.h>
+#include "check-helpers.h"
+
+#include <libempathy/empathy-irc-server.h>
+#include <libempathy/empathy-irc-network.h>
+#include <libempathy/empathy-irc-network-manager.h>
+
+#ifndef __CHECK_IRC_HELPER_H__
+#define __CHECK_IRC_HELPER_H__
+
+struct server_t
+{
+ gchar *address;
+ guint port;
+ gboolean ssl;
+};
+
+void check_server (EmpathyIrcServer *server, const gchar *_address,
+ guint _port, gboolean _ssl);
+
+void check_network (EmpathyIrcNetwork *network, const gchar *_name,
+ const gchar *_charset, struct server_t *_servers, guint nb_servers);
+
+#endif /* __CHECK_IRC_HELPER_H__ */
diff --git a/tests/check-libempathy.h b/tests/check-libempathy.h
index 1f3302583..0f9388dcf 100644
--- a/tests/check-libempathy.h
+++ b/tests/check-libempathy.h
@@ -2,5 +2,8 @@
#define __CHECK_LIBEMPATHY__
TCase * make_empathy_utils_tcase (void);
+TCase * make_empathy_irc_server_tcase (void);
+TCase * make_empathy_irc_network_tcase (void);
+TCase * make_empathy_irc_network_manager_tcase (void);
#endif /* #ifndef __CHECK_LIBEMPATHY__ */
diff --git a/tests/check-main.c b/tests/check-main.c
index 6dcfe3237..f0e366d03 100644
--- a/tests/check-main.c
+++ b/tests/check-main.c
@@ -16,6 +16,9 @@ make_libempathy_suite (void)
Suite *s = suite_create ("libempathy");
suite_add_tcase (s, make_empathy_utils_tcase ());
+ suite_add_tcase (s, make_empathy_irc_server_tcase ());
+ suite_add_tcase (s, make_empathy_irc_network_tcase ());
+ suite_add_tcase (s, make_empathy_irc_network_manager_tcase ());
return s;
}
diff --git a/tests/xml/.gitignore b/tests/xml/.gitignore
new file mode 100644
index 000000000..01af91dc1
--- /dev/null
+++ b/tests/xml/.gitignore
@@ -0,0 +1 @@
+user-irc-networks.xml
diff --git a/tests/xml/default-irc-networks-sample.xml b/tests/xml/default-irc-networks-sample.xml
new file mode 100644
index 000000000..257919c27
--- /dev/null
+++ b/tests/xml/default-irc-networks-sample.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<networks>
+ <network id="freenode" name="Freenode">
+ <servers>
+ <server address="irc.freenode.net" port="6667" ssl="FALSE" />
+ <server address="irc.eu.freenode.net" port="6667" ssl="FALSE" />
+ </servers>
+ </network>
+
+ <network id="gimpnet" name="GIMPNet">
+ <servers>
+ <server address="irc.gimp.org" port="6667" ssl="FALSE" />
+ <server address="irc.us.gimp.org" port="6667" ssl="FALSE" />
+ </servers>
+ </network>
+
+ <network id="testsrv" name="Test Server" network_charset="ISO-8859-1">
+ <servers>
+ <server address="irc.test.org" port="6669" ssl="TRUE" />
+ </servers>
+ </network>
+
+ <network id="undernet" name="Undernet">
+ <servers>
+ <server address="eu.undernet.org" port="6667" ssl="FALSE" />
+ </servers>
+ </network>
+
+</networks>
diff --git a/tests/xml/user-irc-networks-sample.xml b/tests/xml/user-irc-networks-sample.xml
new file mode 100644
index 000000000..9e4f08693
--- /dev/null
+++ b/tests/xml/user-irc-networks-sample.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<networks>
+ <network id="gimpnet" name="GIMPNet">
+ <servers>
+ <server address="irc.gimp.org" port="6667" ssl="FALSE" />
+ <server address="irc.us.gimp.org" port="6667" ssl="FALSE" />
+ <server address="irc.au.gimp.org" port="6667" ssl="FALSE" />
+ </servers>
+ </network>
+
+ <network id="testsrv" name="Test Server" dropped="1"/>
+
+ <network id="mysrv" name="My Server">
+ <servers>
+ <server address="irc.mysrv.net" port="7495" ssl="TRUE" />
+ </servers>
+ </network>
+
+ <network id="anothersrv" name="Another Server">
+ <servers>
+ <server address="irc.anothersrv.be" port="6660" ssl="FALSE" />
+ </servers>
+ </network>
+
+</networks>