Add some more cases to the app-id unit tests
[glib.git] / gio / tests / socket-address.c
blobb3323c249245fba89f1ba9172d69595279883089
1 #include <gio/gunixsocketaddress.h>
3 static void
4 test_unix_socket_address_construct (void)
6 GUnixSocketAddress *a;
8 a = g_object_new (G_TYPE_UNIX_SOCKET_ADDRESS, NULL);
9 g_assert_cmpint (g_unix_socket_address_get_address_type (a), ==, G_UNIX_SOCKET_ADDRESS_PATH);
10 g_object_unref (a);
12 /* Try passing some default values for the arguments explicitly and
13 * make sure it makes no difference.
15 a = g_object_new (G_TYPE_UNIX_SOCKET_ADDRESS, "address-type", G_UNIX_SOCKET_ADDRESS_PATH, NULL);
16 g_assert_cmpint (g_unix_socket_address_get_address_type (a), ==, G_UNIX_SOCKET_ADDRESS_PATH);
17 g_object_unref (a);
19 a = g_object_new (G_TYPE_UNIX_SOCKET_ADDRESS, "abstract", FALSE, NULL);
20 g_assert_cmpint (g_unix_socket_address_get_address_type (a), ==, G_UNIX_SOCKET_ADDRESS_PATH);
21 g_object_unref (a);
23 a = g_object_new (G_TYPE_UNIX_SOCKET_ADDRESS,
24 "abstract", FALSE,
25 "address-type", G_UNIX_SOCKET_ADDRESS_PATH,
26 NULL);
27 g_assert_cmpint (g_unix_socket_address_get_address_type (a), ==, G_UNIX_SOCKET_ADDRESS_PATH);
28 g_object_unref (a);
30 a = g_object_new (G_TYPE_UNIX_SOCKET_ADDRESS,
31 "address-type", G_UNIX_SOCKET_ADDRESS_PATH,
32 "abstract", FALSE,
33 NULL);
34 g_assert_cmpint (g_unix_socket_address_get_address_type (a), ==, G_UNIX_SOCKET_ADDRESS_PATH);
35 g_object_unref (a);
37 /* Try explicitly setting abstract to TRUE */
38 a = g_object_new (G_TYPE_UNIX_SOCKET_ADDRESS,
39 "abstract", TRUE,
40 NULL);
41 g_assert_cmpint (g_unix_socket_address_get_address_type (a), ==, G_UNIX_SOCKET_ADDRESS_ABSTRACT_PADDED);
42 g_object_unref (a);
44 /* Try explicitly setting a different kind of address */
45 a = g_object_new (G_TYPE_UNIX_SOCKET_ADDRESS,
46 "address-type", G_UNIX_SOCKET_ADDRESS_ANONYMOUS,
47 NULL);
48 g_assert_cmpint (g_unix_socket_address_get_address_type (a), ==, G_UNIX_SOCKET_ADDRESS_ANONYMOUS);
49 g_object_unref (a);
51 /* Now try explicitly setting a different type of address after
52 * setting abstract to FALSE.
54 a = g_object_new (G_TYPE_UNIX_SOCKET_ADDRESS,
55 "abstract", FALSE,
56 "address-type", G_UNIX_SOCKET_ADDRESS_ANONYMOUS,
57 NULL);
58 g_assert_cmpint (g_unix_socket_address_get_address_type (a), ==, G_UNIX_SOCKET_ADDRESS_ANONYMOUS);
59 g_object_unref (a);
61 /* And the other way around */
62 a = g_object_new (G_TYPE_UNIX_SOCKET_ADDRESS,
63 "address-type", G_UNIX_SOCKET_ADDRESS_ANONYMOUS,
64 "abstract", FALSE,
65 NULL);
66 g_assert_cmpint (g_unix_socket_address_get_address_type (a), ==, G_UNIX_SOCKET_ADDRESS_ANONYMOUS);
67 g_object_unref (a);
70 static void
71 test_unix_socket_address_to_string (void)
73 GSocketAddress *addr = NULL;
74 gchar *str = NULL;
76 /* ADDRESS_PATH. */
77 addr = g_unix_socket_address_new_with_type ("/some/path", -1,
78 G_UNIX_SOCKET_ADDRESS_PATH);
79 str = g_socket_connectable_to_string (G_SOCKET_CONNECTABLE (addr));
80 g_assert_cmpstr (str, ==, "/some/path");
81 g_free (str);
82 g_object_unref (addr);
84 /* ADDRESS_ANONYMOUS. */
85 addr = g_unix_socket_address_new_with_type ("", 0,
86 G_UNIX_SOCKET_ADDRESS_ANONYMOUS);
87 str = g_socket_connectable_to_string (G_SOCKET_CONNECTABLE (addr));
88 g_assert_cmpstr (str, ==, "anonymous");
89 g_free (str);
90 g_object_unref (addr);
92 /* ADDRESS_ABSTRACT. */
93 addr = g_unix_socket_address_new_with_type ("abstract-path\0✋", 17,
94 G_UNIX_SOCKET_ADDRESS_ABSTRACT);
95 str = g_socket_connectable_to_string (G_SOCKET_CONNECTABLE (addr));
96 g_assert_cmpstr (str, ==, "abstract-path\\x00\\xe2\\x9c\\x8b");
97 g_free (str);
98 g_object_unref (addr);
100 /* ADDRESS_ABSTRACT_PADDED. */
101 addr = g_unix_socket_address_new_with_type ("abstract-path\0✋", 17,
102 G_UNIX_SOCKET_ADDRESS_ABSTRACT_PADDED);
103 str = g_socket_connectable_to_string (G_SOCKET_CONNECTABLE (addr));
104 g_assert_cmpstr (str, ==, "abstract-path\\x00\\xe2\\x9c\\x8b");
105 g_free (str);
106 g_object_unref (addr);
110 main (int argc,
111 char **argv)
113 g_test_init (&argc, &argv, NULL);
115 g_test_add_func ("/socket/address/unix/construct", test_unix_socket_address_construct);
116 g_test_add_func ("/socket/address/unix/to-string", test_unix_socket_address_to_string);
118 return g_test_run ();