6 GNetworkAddress *address;
10 address = (GNetworkAddress*)g_network_address_new ("www.gnome.org", 8080);
12 g_assert_cmpstr (g_network_address_get_hostname (address), ==, "www.gnome.org");
13 g_assert_cmpint (g_network_address_get_port (address), ==, 8080);
15 g_object_get (address, "hostname", &hostname, "port", &port, NULL);
16 g_assert_cmpstr (hostname, ==, "www.gnome.org");
17 g_assert_cmpint (port, ==, 8080);
20 g_object_unref (address);
23 typedef struct _ParseTest ParseTest;
28 const gchar *hostname;
33 static ParseTest tests[] =
35 { "www.gnome.org", "www.gnome.org", 1234, -1 },
36 { "www.gnome.org:8080", "www.gnome.org", 8080, -1 },
37 { "www.gnome.org:http", "www.gnome.org", 80, -1 },
38 { "[2001:db8::1]", "2001:db8::1", 1234, -1 },
39 { "[2001:db8::1]:888", "2001:db8::1", 888, -1 },
40 { "[hostname", NULL, 0, G_IO_ERROR_INVALID_ARGUMENT },
41 { "[hostnam]e", NULL, 0, G_IO_ERROR_INVALID_ARGUMENT },
42 { "hostname:", NULL, 0, G_IO_ERROR_INVALID_ARGUMENT },
43 { "hostname:-1", NULL, 0, G_IO_ERROR_INVALID_ARGUMENT },
44 { "hostname:9999999", NULL, 0, G_IO_ERROR_INVALID_ARGUMENT }
48 test_parse (gconstpointer d)
50 const ParseTest *test = d;
51 GNetworkAddress *address;
55 address = (GNetworkAddress*)g_network_address_parse (test->input, 1234, &error);
59 g_assert_cmpstr (g_network_address_get_hostname (address), ==, test->hostname);
60 g_assert_cmpint (g_network_address_get_port (address), ==, test->port);
61 g_assert_no_error (error);
65 g_assert_error (error, G_IO_ERROR, test->error_code);
69 g_object_unref (address);
75 main (int argc, char *argv[])
82 g_test_init (&argc, &argv, NULL);
84 g_test_add_func ("/network-address/basic", test_basic);
86 for (i = 0; i < G_N_ELEMENTS (tests); i++)
88 path = g_strdup_printf ("/network-address/parse/%d", i);
89 g_test_add_data_func (path, &tests[i], test_parse);