diff options
author | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2014-02-14 14:44:30 +0200 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2014-02-20 13:43:08 +0200 |
commit | fa0701592b1638302159f5bb72f7fd71ce02df7c (patch) | |
tree | 6e2e6b35c7284ab7c55a5ffc45008af34ee0f62e /unit | |
parent | 7c862eb533699ae0e7e390326ea24eecfcb26e34 (diff) | |
download | bluez-fa0701592b1638302159f5bb72f7fd71ce02df7c.tar.gz |
unit/test-gobex-transfer: Add /gobex/test_packet_get_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')
-rw-r--r-- | unit/test-gobex-transfer.c | 81 |
1 files changed, 77 insertions, 4 deletions
diff --git a/unit/test-gobex-transfer.c b/unit/test-gobex-transfer.c index 90818b16a..ffb5bdc5a 100644 --- a/unit/test-gobex-transfer.c +++ b/unit/test-gobex-transfer.c @@ -106,6 +106,9 @@ static guint8 get_req_first_srm_wait[] = { G_OBEX_OP_GET | FINAL_BIT, 0x00, 0x27 0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0, G_OBEX_HDR_SRMP, 0x01 }; +static guint8 get_req_srm_wait[] = { G_OBEX_OP_GET | FINAL_BIT, 0x00, 0x05, + G_OBEX_HDR_SRMP, 0x01 }; + static guint8 get_req_last[] = { G_OBEX_OP_GET | FINAL_BIT, 0x00, 0x03, }; static guint8 get_rsp_first_app[] = { G_OBEX_RSP_CONTINUE | FINAL_BIT, 0x00, 0x0A, @@ -124,6 +127,8 @@ static guint8 get_rsp_first_srm_wait_next[] = { G_OBEX_RSP_CONTINUE | FINAL_BIT, G_OBEX_HDR_SRMP, 0x02, G_OBEX_HDR_BODY, 0x00, 0x0d, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; +static guint8 get_rsp_srm_wait[] = { G_OBEX_RSP_CONTINUE | FINAL_BIT, + 0x00, 0x03 }; static guint8 get_rsp_zero[255] = { G_OBEX_RSP_CONTINUE | FINAL_BIT, 0x00, 0xff, G_OBEX_HDR_BODY, 0x00, 0xfc }; static guint8 get_rsp_zero_wait_next[255] = { G_OBEX_RSP_CONTINUE | FINAL_BIT, @@ -191,7 +196,13 @@ static void transfer_complete(GObex *obex, GError *err, gpointer user_data) static gboolean resume_obex(gpointer user_data) { - g_obex_resume(user_data); + struct test_data *d = user_data; + + if (!g_main_loop_is_running(d->mainloop)) + return FALSE; + + g_obex_resume(d->obex); + return FALSE; } @@ -232,7 +243,7 @@ static gssize provide_eagain(void *buf, gsize len, gpointer user_data) } if (d->provide_delay > 0) { - g_timeout_add(d->provide_delay, resume_obex, d->obex); + g_timeout_add(d->provide_delay, resume_obex, d); d->provide_delay = 0; return -EAGAIN; } @@ -260,7 +271,7 @@ static gssize provide_data(void *buf, gsize len, gpointer user_data) if (d->provide_delay > 0) { g_obex_suspend(d->obex); - g_timeout_add(d->provide_delay, resume_obex, d->obex); + g_timeout_add(d->provide_delay, resume_obex, d); } d->total += sizeof(body_data); @@ -852,6 +863,66 @@ static void test_packet_get_req_wait(void) g_assert_no_error(d.err); } +static gboolean rcv_seq_delay(const void *buf, gsize len, gpointer user_data) +{ + struct test_data *d = user_data; + + if (d->provide_delay > 0) { + g_obex_suspend(d->obex); + g_timeout_add_seconds(d->provide_delay, resume_obex, d); + d->provide_delay = 0; + } + + return TRUE; +} + +static void test_packet_get_req_suspend_resume(void) +{ + GIOChannel *io; + GIOCondition cond; + guint io_id, timer_id; + GObex *obex; + struct test_data d = { 0, NULL, { + { get_req_first_srm, sizeof(get_req_first_srm) }, + { get_req_srm_wait, sizeof(get_req_srm_wait) }, + { get_req_srm_wait, sizeof(get_req_srm_wait) }, + { get_req_last, sizeof(get_req_last) } }, { + { get_rsp_first_srm, sizeof(get_rsp_first_srm) }, + { get_rsp_srm_wait, sizeof(get_rsp_srm_wait) }, + { get_rsp_srm_wait, sizeof(get_rsp_srm_wait) }, + { get_rsp_last, sizeof(get_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); + + timer_id = g_timeout_add_seconds(1, test_timeout, &d); + + g_obex_get_req(obex, rcv_seq_delay, transfer_complete, &d, &d.err, + G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type), + G_OBEX_HDR_NAME, "file.txt", + G_OBEX_HDR_INVALID); + g_assert_no_error(d.err); + + g_main_loop_run(d.mainloop); + + g_assert_cmpuint(d.count, ==, 4); + + g_main_loop_unref(d.mainloop); + + g_source_remove(timer_id); + g_io_channel_unref(io); + g_source_remove(io_id); + g_obex_unref(obex); + + g_assert_no_error(d.err); +} + static void test_packet_get_req_wait_next(void) { GIOChannel *io; @@ -1621,7 +1692,7 @@ static gboolean rcv_data_delay(const void *buf, gsize len, gpointer user_data) if (d->provide_delay > 0) { g_obex_suspend(d->obex); - g_timeout_add(d->provide_delay, resume_obex, d->obex); + g_timeout_add(d->provide_delay, resume_obex, d); } return TRUE; @@ -2327,6 +2398,8 @@ int main(int argc, char *argv[]) g_test_add_func("/gobex/test_packet_get_req", test_packet_get_req); g_test_add_func("/gobex/test_packet_get_req_wait", test_packet_get_req_wait); + g_test_add_func("/gobex/test_packet_get_req_suspend_resume", + test_packet_get_req_suspend_resume); g_test_add_func("/gobex/test_packet_get_req_wait_next", test_packet_get_req_wait_next); |