From: Johan Hedberg Date: Wed, 6 Jul 2011 07:59:01 +0000 (+0300) Subject: gobex: Move more unit test helpers to util.c X-Git-Tag: android-x86-4.4-r3~11777 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=33324a068ae465fd60871c59ea39263c466ae99c;p=android-x86%2Fexternal-bluetooth-bluez.git gobex: Move more unit test helpers to util.c --- diff --git a/unit/test-gobex.c b/unit/test-gobex.c index c537ae93d..22c66654b 100644 --- a/unit/test-gobex.c +++ b/unit/test-gobex.c @@ -61,54 +61,6 @@ static gboolean test_timeout(gpointer user_data) return FALSE; } -static 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; -} - -static 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); -} - static void connect_rsp(GObex *obex, GError *err, GObexPacket *rsp, gpointer user_data) { 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 +#include +#include +#include #include #include +#include #include @@ -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); +} diff --git a/unit/util.h b/unit/util.h index cf41494bc..73b637277 100644 --- a/unit/util.h +++ b/unit/util.h @@ -19,6 +19,8 @@ * */ +#include + enum { TEST_ERROR_TIMEOUT, TEST_ERROR_UNEXPECTED, @@ -30,3 +32,7 @@ GQuark test_error_quark(void); void dump_bufs(const void *mem1, size_t len1, const void *mem2, size_t len2); void assert_memequal(const void *mem1, size_t len1, const void *mem2, size_t len2); + +GObex *create_gobex(int fd, GObexTransportType transport_type, + gboolean close_on_unref); +void create_endpoints(GObex **obex, GIOChannel **io, int sock_type);