summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMorten Mjelva <morten.mjelva@gmail.com>2011-04-11 11:50:17 +0200
committerMorten Mjelva <morten.mjelva@gmail.com>2011-06-15 10:00:03 +0200
commit7550abd389226de84796d7ffea9d16e5b8839ab5 (patch)
tree70bcd300d28a8583f86f99d3257463d2f786e193
parenta87d230ba99ae711f2144180e256dccc08ba902a (diff)
Moved destroy_socket_control_list() in tests/dbus/stream-tube.c to utilfdo#36110
Function is now called _tp_destroy_socket_control_list()
-rw-r--r--tests/lib/util.c105
-rw-r--r--tests/lib/util.h8
2 files changed, 113 insertions, 0 deletions
diff --git a/tests/lib/util.c b/tests/lib/util.c
index fc2ecdb0..a5532954 100644
--- a/tests/lib/util.c
+++ b/tests/lib/util.c
@@ -10,6 +10,11 @@
#include "tests/lib/util.h"
+#include <gio/gunixsocketaddress.h>
+#include <gio/gunixconnection.h>
+
+#include <glib/gstdio.h>
+
#ifdef G_OS_UNIX
# include <unistd.h> /* for alarm() */
#endif
@@ -300,3 +305,103 @@ tp_tests_init (int *argc,
g_test_init (argc, argv, NULL);
}
+
+void
+_tp_destroy_socket_control_list (gpointer data)
+{
+ GArray *tab = data;
+ g_array_free (tab, TRUE);
+}
+
+GValue *
+_tp_create_local_socket (GSocketService **service,
+ gchar **unix_address,
+ TpSocketAddressType address_type,
+ TpSocketAccessControl access_control,
+ GError **error)
+{
+ gboolean success;
+ GSocketAddress *address, *effective_address;
+ GValue *address_gvalue;
+
+ switch (access_control)
+ {
+ case TP_SOCKET_ACCESS_CONTROL_LOCALHOST:
+ case TP_SOCKET_ACCESS_CONTROL_CREDENTIALS:
+ case TP_SOCKET_ACCESS_CONTROL_PORT:
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+
+ switch (address_type)
+ {
+ case TP_SOCKET_ADDRESS_TYPE_UNIX:
+ {
+ address = g_unix_socket_address_new (tmpnam (NULL));
+ break;
+ }
+
+ case TP_SOCKET_ADDRESS_TYPE_IPV4:
+ case TP_SOCKET_ADDRESS_TYPE_IPV6:
+ {
+ GInetAddress *localhost;
+
+ localhost = g_inet_address_new_loopback (
+ address_type == TP_SOCKET_ADDRESS_TYPE_IPV4 ?
+ G_SOCKET_FAMILY_IPV4 : G_SOCKET_FAMILY_IPV6);
+ address = g_inet_socket_address_new (localhost, 0);
+
+ g_object_unref (localhost);
+ break;
+ }
+
+ default:
+ g_assert_not_reached ();
+ }
+
+ *service = g_socket_service_new ();
+
+ success = g_socket_listener_add_address (
+ G_SOCKET_LISTENER (*service),
+ address, G_SOCKET_TYPE_STREAM,
+ G_SOCKET_PROTOCOL_DEFAULT,
+ NULL, &effective_address, NULL);
+ g_assert (success);
+
+ switch (address_type)
+ {
+ case TP_SOCKET_ADDRESS_TYPE_UNIX:
+ *unix_address = g_strdup (g_unix_socket_address_get_path (
+ G_UNIX_SOCKET_ADDRESS (effective_address)));
+ address_gvalue = tp_g_value_slice_new_bytes (
+ g_unix_socket_address_get_path_len (
+ G_UNIX_SOCKET_ADDRESS (effective_address)),
+ g_unix_socket_address_get_path (
+ G_UNIX_SOCKET_ADDRESS (effective_address)));
+ break;
+
+ case TP_SOCKET_ADDRESS_TYPE_IPV4:
+ case TP_SOCKET_ADDRESS_TYPE_IPV6:
+ address_gvalue = tp_g_value_slice_new_take_boxed (
+ TP_STRUCT_TYPE_SOCKET_ADDRESS_IPV4,
+ dbus_g_type_specialized_construct (
+ TP_STRUCT_TYPE_SOCKET_ADDRESS_IPV4));
+
+ dbus_g_type_struct_set (address_gvalue,
+ 0, address_type == TP_SOCKET_ADDRESS_TYPE_IPV4 ?
+ "127.0.0.1" : "::1",
+ 1, g_inet_socket_address_get_port (
+ G_INET_SOCKET_ADDRESS (effective_address)),
+ G_MAXUINT);
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+
+ g_object_unref (address);
+ g_object_unref (effective_address);
+ return address_gvalue;
+}
diff --git a/tests/lib/util.h b/tests/lib/util.h
index 689cf91f..4eb36f42 100644
--- a/tests/lib/util.h
+++ b/tests/lib/util.h
@@ -57,4 +57,12 @@ void tp_tests_abort_after (guint sec);
void tp_tests_init (int *argc,
char ***argv);
+void _tp_destroy_socket_control_list (gpointer data);
+
+GValue *_tp_create_local_socket (GSocketService **service,
+ gchar **unix_address,
+ TpSocketAddressType address_type,
+ TpSocketAccessControl access_control,
+ GError **error);
+
#endif /* #ifndef __TP_TESTS_LIB_UTIL_H__ */