[glib] Add tests for GNetworkAddress
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Add tests for GNetworkAddress
- Date: Fri, 30 Jul 2010 23:56:43 +0000 (UTC)
commit a8f83ea8340459e22a2f2d18f4aa410ccf1cde34
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Jul 26 19:07:16 2010 -0400
Add tests for GNetworkAddress
gio/tests/Makefile.am | 8 ++--
gio/tests/network-address.c | 91 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 95 insertions(+), 4 deletions(-)
---
diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am
index 03da206..b15e3d8 100644
--- a/gio/tests/Makefile.am
+++ b/gio/tests/Makefile.am
@@ -43,6 +43,7 @@ TEST_PROGS += \
gschema-compile \
async-close-output-stream \
gdbus-addresses \
+ network-address \
$(NULL)
if OS_UNIX
@@ -60,7 +61,6 @@ TEST_PROGS += \
application \
testapps \
appinfo \
- icons \
contenttype \
file \
$(NULL)
@@ -192,6 +192,9 @@ send_data_LDADD = $(progs_ldadd) \
srvtarget_SOURCES = srvtarget.c
srvtarget_LDADD = $(progs_ldadd)
+network_address_SOURCE = network-address.c
+network_address_LDADD = $(progs_ldadd)
+
contexts_SOURCES = contexts.c
contexts_LDADD = $(progs_ldadd) \
$(top_builddir)/gthread/libgthread-2.0.la
@@ -287,9 +290,6 @@ testapp_LDADD = $(progs_ldadd)
testapps_SOURCES = testapps.c gdbus-sessionbus.c gdbus-sessionbus.h
testapps_LDADD = $(progs_ldadd)
-icons_SOURCES = icons.c
-icons_LDADD = $(progs_ldadd)
-
contenttype_SOURCES = contenttype.c
contenttype_LDADD = $(progs_ldadd)
diff --git a/gio/tests/network-address.c b/gio/tests/network-address.c
new file mode 100644
index 0000000..43521d7
--- /dev/null
+++ b/gio/tests/network-address.c
@@ -0,0 +1,91 @@
+#include <gio/gio.h>
+
+static void
+test_basic (void)
+{
+ GNetworkAddress *address;
+ guint16 port;
+ gchar *hostname;
+
+ address = (GNetworkAddress*)g_network_address_new ("www.gnome.org", 8080);
+
+ g_assert_cmpstr (g_network_address_get_hostname (address), ==, "www.gnome.org");
+ g_assert_cmpint (g_network_address_get_port (address), ==, 8080);
+
+ g_object_get (address, "hostname", &hostname, "port", &port, NULL);
+ g_assert_cmpstr (hostname, ==, "www.gnome.org");
+ g_assert_cmpint (port, ==, 8080);
+ g_free (hostname);
+}
+
+typedef struct _ParseTest ParseTest;
+
+struct _ParseTest
+{
+ const gchar *input;
+ const gchar *hostname;
+ guint16 port;
+ gint error_code;
+};
+
+static ParseTest tests[] =
+{
+ { "www.gnome.org", "www.gnome.org", 1234, -1 },
+ { "www.gnome.org:8080", "www.gnome.org", 8080, -1 },
+ { "[2001:db8::1]", "2001:db8::1", 1234, -1 },
+ { "[2001:db8::1]:888", "2001:db8::1", 888, -1 },
+ { "[hostname", NULL, 0, G_IO_ERROR_INVALID_ARGUMENT },
+ { "[hostnam]e", NULL, 0, G_IO_ERROR_INVALID_ARGUMENT },
+ { "hostname:", NULL, 0, G_IO_ERROR_INVALID_ARGUMENT },
+ { "hostname:-1", NULL, 0, G_IO_ERROR_INVALID_ARGUMENT },
+ { "hostname:9999999", NULL, 0, G_IO_ERROR_INVALID_ARGUMENT }
+};
+
+static void
+test_parse (gconstpointer d)
+{
+ ParseTest *test = d;
+ GNetworkAddress *address;
+ GError *error;
+
+ error = NULL;
+ address = (GNetworkAddress*)g_network_address_parse (test->input, 1234, &error);
+
+ if (address)
+ {
+ g_assert_cmpstr (g_network_address_get_hostname (address), ==, test->hostname);
+ g_assert_cmpint (g_network_address_get_port (address), ==, test->port);
+ g_assert_no_error (error);
+ }
+ else
+ {
+ g_assert_error (error, G_IO_ERROR, test->error_code);
+ }
+
+ if (address)
+ g_object_unref (address);
+ if (error)
+ g_error_free (error);
+}
+
+int
+main (int argc, char *argv[])
+{
+ gint i;
+ gchar *path;
+
+ g_type_init ();
+
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/network-address/basic", test_basic);
+
+ for (i = 0; i < G_N_ELEMENTS (tests); i++)
+ {
+ path = g_strdup_printf ("/network-address/parse/%d", i);
+ g_test_add_data_func (path, &tests[i], test_parse);
+ g_free (path);
+ }
+
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]