diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2013-08-20 20:44:12 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2013-08-21 18:34:46 +0100 |
commit | 7edfadb8352d9b25059a7788df97e105d1a6496a (patch) | |
tree | d51220776440c94fdc7c348d94dcc6b90b2ce827 | |
parent | c77aeab6164c20761f3478ba0b13c273934248ae (diff) |
Regression tests: also avoid tmpnam() hereno-tmpnam-68350
This is a bit simpler than in production code, because we can just
abort on errors that "should never happen".
-rw-r--r-- | tests/lib/file-transfer-chan.c | 12 | ||||
-rw-r--r-- | tests/lib/stream-tube-chan.c | 9 | ||||
-rw-r--r-- | tests/lib/util.c | 16 | ||||
-rw-r--r-- | tests/lib/util.h | 1 |
4 files changed, 34 insertions, 4 deletions
diff --git a/tests/lib/file-transfer-chan.c b/tests/lib/file-transfer-chan.c index 8f5894360..2afea1dbb 100644 --- a/tests/lib/file-transfer-chan.c +++ b/tests/lib/file-transfer-chan.c @@ -79,6 +79,7 @@ struct _TpTestsFileTransferChannelPrivate { TpSocketAddressType address_type; GValue *address; gchar *unix_address; + gchar *unix_tmpdir; guint connection_id; TpSocketAccessControl access_control; @@ -160,6 +161,11 @@ dispose (GObject *object) tp_clear_pointer (&self->priv->unix_address, g_free); + if (self->priv->unix_tmpdir != NULL) + g_rmdir (self->priv->unix_tmpdir); + + tp_clear_pointer (&self->priv->unix_tmpdir, g_free); + ((GObjectClass *) tp_tests_file_transfer_channel_parent_class)->dispose ( object); } @@ -481,7 +487,8 @@ file_transfer_provide_file (TpSvcChannelTypeFileTransfer *iface, } self->priv->address = _tp_create_local_socket (address_type, access_control, - &self->priv->service, &self->priv->unix_address, &error); + &self->priv->service, &self->priv->unix_address, + &self->priv->unix_tmpdir, &error); if (self->priv->address == NULL) { @@ -547,7 +554,8 @@ file_transfer_accept_file (TpSvcChannelTypeFileTransfer *iface, } address = _tp_create_local_socket (address_type, access_control, - &self->priv->service, &self->priv->unix_address, &error); + &self->priv->service, &self->priv->unix_address, + &self->priv->unix_tmpdir, &error); tp_g_signal_connect_object (self->priv->service, "incoming", G_CALLBACK (service_incoming_cb), self, 0); diff --git a/tests/lib/stream-tube-chan.c b/tests/lib/stream-tube-chan.c index 95388d013..e2fd2e086 100644 --- a/tests/lib/stream-tube-chan.c +++ b/tests/lib/stream-tube-chan.c @@ -56,6 +56,7 @@ struct _TpTestsStreamTubeChannelPrivate { TpSocketAddressType address_type; GValue *address; gchar *unix_address; + gchar *unix_tmpdir; guint connection_id; TpSocketAccessControl access_control; @@ -211,6 +212,11 @@ dispose (GObject *object) tp_clear_pointer (&self->priv->unix_address, g_free); + if (self->priv->unix_tmpdir != NULL) + g_rmdir (self->priv->unix_tmpdir); + + tp_clear_pointer (&self->priv->unix_tmpdir, g_free); + ((GObjectClass *) tp_tests_stream_tube_channel_parent_class)->dispose ( object); } @@ -482,7 +488,8 @@ stream_tube_accept (TpSvcChannelTypeStreamTube *iface, } address = _tp_create_local_socket (address_type, access_control, - &self->priv->service, &self->priv->unix_address, &error); + &self->priv->service, &self->priv->unix_address, + &self->priv->unix_tmpdir, &error); tp_g_signal_connect_object (self->priv->service, "incoming", G_CALLBACK (service_incoming_cb), self, 0); diff --git a/tests/lib/util.c b/tests/lib/util.c index 9510cb025..022c56b30 100644 --- a/tests/lib/util.c +++ b/tests/lib/util.c @@ -338,6 +338,7 @@ _tp_create_local_socket (TpSocketAddressType address_type, TpSocketAccessControl access_control, GSocketService **service, gchar **unix_address, + gchar **unix_tmpdir, GError **error) { gboolean success; @@ -363,7 +364,20 @@ _tp_create_local_socket (TpSocketAddressType address_type, #ifdef HAVE_GIO_UNIX case TP_SOCKET_ADDRESS_TYPE_UNIX: { - address = g_unix_socket_address_new (tmpnam (NULL)); + GError *e = NULL; + gchar *dir = g_dir_make_tmp ("tp-glib-tests.XXXXXX", &e); + gchar *name; + + g_assert_no_error (e); + + name = g_build_filename (dir, "s", NULL); + address = g_unix_socket_address_new (name); + g_free (name); + + if (unix_tmpdir != NULL) + *unix_tmpdir = dir; + else + g_free (dir); break; } #endif diff --git a/tests/lib/util.h b/tests/lib/util.h index ce19d666a..18d868790 100644 --- a/tests/lib/util.h +++ b/tests/lib/util.h @@ -69,6 +69,7 @@ GValue *_tp_create_local_socket (TpSocketAddressType address_type, TpSocketAccessControl access_control, GSocketService **service, gchar **unix_address, + gchar **unix_tmpdir, GError **error); void _tp_destroy_socket_control_list (gpointer data); |