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);
21 typedef struct _ParseTest ParseTest;
26 const gchar *hostname;
31 static ParseTest tests[] =
33 { "www.gnome.org", "www.gnome.org", 1234, -1 },
34 { "www.gnome.org:8080", "www.gnome.org", 8080, -1 },
35 { "www.gnome.org:http", "www.gnome.org", 80, -1 },
36 { "[2001:db8::1]", "2001:db8::1", 1234, -1 },
37 { "[2001:db8::1]:888", "2001:db8::1", 888, -1 },
38 { "[hostname", NULL, 0, G_IO_ERROR_INVALID_ARGUMENT },
39 { "[hostnam]e", NULL, 0, G_IO_ERROR_INVALID_ARGUMENT },
40 { "hostname:", NULL, 0, G_IO_ERROR_INVALID_ARGUMENT },
41 { "hostname:-1", NULL, 0, G_IO_ERROR_INVALID_ARGUMENT },
42 { "hostname:9999999", NULL, 0, G_IO_ERROR_INVALID_ARGUMENT }
46 test_parse (gconstpointer d)
48 const ParseTest *test = d;
49 GNetworkAddress *address;
53 address = (GNetworkAddress*)g_network_address_parse (test->input, 1234, &error);
57 g_assert_cmpstr (g_network_address_get_hostname (address), ==, test->hostname);
58 g_assert_cmpint (g_network_address_get_port (address), ==, test->port);
59 g_assert_no_error (error);
63 g_assert_error (error, G_IO_ERROR, test->error_code);
67 g_object_unref (address);
73 main (int argc, char *argv[])
80 g_test_init (&argc, &argv, NULL);
82 g_test_add_func ("/network-address/basic", test_basic);
84 for (i = 0; i < G_N_ELEMENTS (tests); i++)
86 path = g_strdup_printf ("/network-address/parse/%d", i);
87 g_test_add_data_func (path, &tests[i], test_parse);