summaryrefslogtreecommitdiff
path: root/unit/util.c
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2011-07-06 10:59:01 +0300
committerMarcel Holtmann <marcel@holtmann.org>2012-12-04 22:22:00 +0100
commit33324a068ae465fd60871c59ea39263c466ae99c (patch)
tree16fd506008ff4ed1b7b2efb0a74d59b5790c833e /unit/util.c
parentbd5957292f22888f2b97d96184b33d75abfe976b (diff)
downloadbluez-33324a068ae465fd60871c59ea39263c466ae99c.tar.gz
gobex: Move more unit test helpers to util.c
Diffstat (limited to 'unit/util.c')
-rw-r--r--unit/util.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/unit/util.c b/unit/util.c
index 7045e4f38..7e23860e5 100644
--- a/unit/util.c
+++ b/unit/util.c
@@ -19,8 +19,13 @@
*
*/
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#include <stdlib.h>
#include <stdint.h>
#include <string.h>
+#include <errno.h>
#include <glib.h>
@@ -59,3 +64,51 @@ void assert_memequal(const void *mem1, size_t len1,
g_assert(0);
}
+
+GObex *create_gobex(int fd, GObexTransportType transport_type,
+ gboolean close_on_unref)
+{
+ GIOChannel *io;
+ GObex *obex;
+
+ io = g_io_channel_unix_new(fd);
+ g_assert(io != NULL);
+
+ g_io_channel_set_close_on_unref(io, close_on_unref);
+
+ obex = g_obex_new(io, transport_type, -1, -1);
+ g_io_channel_unref(io);
+
+ return obex;
+}
+
+void create_endpoints(GObex **obex, GIOChannel **io, int sock_type)
+{
+ GObexTransportType transport_type;
+ int sv[2];
+
+ if (socketpair(AF_UNIX, sock_type | SOCK_NONBLOCK, 0, sv) < 0) {
+ g_printerr("socketpair: %s", strerror(errno));
+ abort();
+ }
+
+ if (sock_type == SOCK_STREAM)
+ transport_type = G_OBEX_TRANSPORT_STREAM;
+ else
+ transport_type = G_OBEX_TRANSPORT_PACKET;
+
+ *obex = create_gobex(sv[0], transport_type, TRUE);
+ g_assert(*obex != NULL);
+
+ if (io == NULL) {
+ close(sv[1]);
+ return;
+ }
+
+ *io = g_io_channel_unix_new(sv[1]);
+ g_assert(*io != NULL);
+
+ g_io_channel_set_encoding(*io, NULL, NULL);
+ g_io_channel_set_buffered(*io, FALSE);
+ g_io_channel_set_close_on_unref(*io, TRUE);
+}