summaryrefslogtreecommitdiff
path: root/unit/test-gobex-transfer.c
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2014-02-20 13:42:01 +0200
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2014-02-20 13:43:08 +0200
commit7c862eb533699ae0e7e390326ea24eecfcb26e34 (patch)
treeac6143c993afaf53e815e4f089dfaf7c91099545 /unit/test-gobex-transfer.c
parent7cbdb40a8838466055d47b6bd76749ca7e3c0e11 (diff)
downloadbluez-7c862eb533699ae0e7e390326ea24eecfcb26e34.tar.gz
unit/test-gobex-transfer: Add /gobex/test_packet_put_req_suspend_resume
This adds a test to call g_obex_suspend and latter g_obex_resume while SRM is enabled.
Diffstat (limited to 'unit/test-gobex-transfer.c')
-rw-r--r--unit/test-gobex-transfer.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/unit/test-gobex-transfer.c b/unit/test-gobex-transfer.c
index 7c9fd43df..90818b16a 100644
--- a/unit/test-gobex-transfer.c
+++ b/unit/test-gobex-transfer.c
@@ -1027,6 +1027,78 @@ static void test_stream_put_req(void)
g_assert_no_error(d.err);
}
+static gssize provide_seq_delay(void *buf, gsize len, gpointer user_data)
+{
+ struct test_data *d = user_data;
+ int fd;
+ gssize ret;
+
+ if (d->provide_delay > 0) {
+ g_obex_suspend(d->obex);
+ g_timeout_add_seconds(d->provide_delay, resume_obex, d);
+ d->provide_delay = 0;
+ }
+
+ if (d->count == RANDOM_PACKETS - 1)
+ return 0;
+
+ fd = open("/dev/urandom", O_RDONLY | O_NOCTTY, 0);
+ if (fd < 0) {
+ g_set_error(&d->err, TEST_ERROR, TEST_ERROR_UNEXPECTED,
+ "open(/dev/urandom): %s", strerror(errno));
+ g_main_loop_quit(d->mainloop);
+ return -1;
+ }
+
+ ret = read(fd, buf, len);
+ close(fd);
+ return ret;
+}
+
+static void test_packet_put_req_suspend_resume(void)
+{
+ GIOChannel *io;
+ GIOCondition cond;
+ guint io_id;
+ GObex *obex;
+ struct test_data d = { 0, NULL, {
+ { NULL, 0 },
+ { NULL, 0 },
+ { NULL, 0 },
+ { put_req_last, sizeof(put_req_last) } }, {
+ { put_rsp_first_srm, sizeof(put_rsp_first_srm) },
+ { NULL, 0 },
+ { NULL, 0 },
+ { put_rsp_last, sizeof(put_rsp_last) } } };
+
+ create_endpoints(&obex, &io, SOCK_SEQPACKET);
+ d.obex = obex;
+ d.provide_delay = 1;
+
+ cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
+ io_id = g_io_add_watch(io, cond, test_io_cb, &d);
+
+ d.mainloop = g_main_loop_new(NULL, FALSE);
+
+ g_obex_put_req(obex, provide_seq_delay, transfer_complete, &d, &d.err,
+ G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
+ G_OBEX_HDR_NAME, "random.bin",
+ G_OBEX_HDR_INVALID);
+ g_assert_no_error(d.err);
+
+ g_main_loop_run(d.mainloop);
+
+ g_assert_cmpuint(d.count, ==, RANDOM_PACKETS);
+
+ g_main_loop_unref(d.mainloop);
+
+ g_io_channel_unref(io);
+ g_source_remove(io_id);
+ g_obex_unref(obex);
+
+ g_assert_no_error(d.err);
+}
+
static void test_packet_put_req_wait(void)
{
GIOChannel *io;
@@ -2241,6 +2313,8 @@ int main(int argc, char *argv[])
g_test_add_func("/gobex/test_packet_put_req", test_packet_put_req);
g_test_add_func("/gobex/test_packet_put_req_wait",
test_packet_put_req_wait);
+ g_test_add_func("/gobex/test_packet_put_req_suspend_resume",
+ test_packet_put_req_suspend_resume);
g_test_add_func("/gobex/test_packet_put_rsp", test_packet_put_rsp);
g_test_add_func("/gobex/test_packet_put_rsp_wait",