1 #include <gio/gunixsocketaddress.h>
4 test_unix_socket_address_construct (void)
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
);
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
);
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
);
23 a
= g_object_new (G_TYPE_UNIX_SOCKET_ADDRESS
,
25 "address-type", G_UNIX_SOCKET_ADDRESS_PATH
,
27 g_assert_cmpint (g_unix_socket_address_get_address_type (a
), ==, G_UNIX_SOCKET_ADDRESS_PATH
);
30 a
= g_object_new (G_TYPE_UNIX_SOCKET_ADDRESS
,
31 "address-type", G_UNIX_SOCKET_ADDRESS_PATH
,
34 g_assert_cmpint (g_unix_socket_address_get_address_type (a
), ==, G_UNIX_SOCKET_ADDRESS_PATH
);
37 /* Try explicitly setting abstract to TRUE */
38 a
= g_object_new (G_TYPE_UNIX_SOCKET_ADDRESS
,
41 g_assert_cmpint (g_unix_socket_address_get_address_type (a
), ==, G_UNIX_SOCKET_ADDRESS_ABSTRACT_PADDED
);
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
,
48 g_assert_cmpint (g_unix_socket_address_get_address_type (a
), ==, G_UNIX_SOCKET_ADDRESS_ANONYMOUS
);
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
,
56 "address-type", G_UNIX_SOCKET_ADDRESS_ANONYMOUS
,
58 g_assert_cmpint (g_unix_socket_address_get_address_type (a
), ==, G_UNIX_SOCKET_ADDRESS_ANONYMOUS
);
61 /* And the other way around */
62 a
= g_object_new (G_TYPE_UNIX_SOCKET_ADDRESS
,
63 "address-type", G_UNIX_SOCKET_ADDRESS_ANONYMOUS
,
66 g_assert_cmpint (g_unix_socket_address_get_address_type (a
), ==, G_UNIX_SOCKET_ADDRESS_ANONYMOUS
);
71 test_unix_socket_address_to_string (void)
73 GSocketAddress
*addr
= NULL
;
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");
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");
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");
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");
106 g_object_unref (addr
);
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 ();