diff options
author | Johan Hedberg <johan.hedberg@intel.com> | 2011-07-08 12:01:29 +0200 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2012-12-04 22:22:00 +0100 |
commit | d1ad690084f04efc36800abac0c653e362267d18 (patch) | |
tree | 990a2d97760a67a9bab1e1788f75e490be4cd36e /unit | |
parent | 5eb7afa856aa2e5f4733c8db6dc21fa8d63ba964 (diff) |
gobex: Add unit tests for g_obex_suspend & g_obex_resume
Diffstat (limited to 'unit')
-rw-r--r-- | unit/test-gobex-transfer.c | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/unit/test-gobex-transfer.c b/unit/test-gobex-transfer.c index e583d37ed..9f496a960 100644 --- a/unit/test-gobex-transfer.c +++ b/unit/test-gobex-transfer.c @@ -91,6 +91,8 @@ struct test_data { GError *err; struct test_buf recv[3]; struct test_buf send[3]; + guint provide_delay; + GObex *obex; }; static gboolean io_cb(GIOChannel *io, GIOCondition cond, gpointer user_data) @@ -158,6 +160,12 @@ static void transfer_complete(GObex *obex, GError *err, gpointer user_data) g_main_loop_quit(mainloop); } +static gboolean resume_obex(gpointer user_data) +{ + g_obex_resume(user_data); + return FALSE; +} + static gssize provide_data(void *buf, gsize len, gpointer user_data) { struct test_data *d = user_data; @@ -174,6 +182,11 @@ static gssize provide_data(void *buf, gsize len, gpointer user_data) memcpy(buf, body_data, sizeof(body_data)); + if (d->provide_delay > 0) { + g_obex_suspend(d->obex); + g_timeout_add(d->provide_delay, resume_obex, d->obex); + } + return sizeof(body_data); } @@ -396,6 +409,92 @@ static void test_get_rsp(void) g_assert_no_error(d.err); } +static void test_put_req_delay(void) +{ + GIOChannel *io; + GIOCondition cond; + guint io_id, timer_id; + GObex *obex; + struct test_data d = { 0, NULL, { + { put_req_first, sizeof(put_req_first) }, + { put_req_last, sizeof(put_req_last) } }, { + { put_rsp_first, sizeof(put_rsp_first) }, + { put_rsp_last, sizeof(put_rsp_last) } } }; + + create_endpoints(&obex, &io, SOCK_STREAM); + d.obex = obex; + d.provide_delay = 200; + + cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL; + io_id = g_io_add_watch(io, cond, io_cb, &d); + + mainloop = g_main_loop_new(NULL, FALSE); + + timer_id = g_timeout_add_seconds(1, test_timeout, &d); + + g_obex_put_req(obex, "foo/bar", "file.txt", provide_data, + transfer_complete, &d, &d.err); + g_assert_no_error(d.err); + + g_main_loop_run(mainloop); + + g_assert_cmpuint(d.count, ==, 2); + + g_main_loop_unref(mainloop); + mainloop = NULL; + + 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_get_rsp_delay(void) +{ + GIOChannel *io; + GIOCondition cond; + guint io_id, timer_id; + GObex *obex; + struct test_data d = { 0, NULL, { + { get_rsp_first, sizeof(get_rsp_first) }, + { get_rsp_last, sizeof(get_rsp_last) } }, { + { get_req_last, sizeof(get_req_last) }, + { NULL, 0 } } }; + + create_endpoints(&obex, &io, SOCK_STREAM); + d.obex = obex; + d.provide_delay = 200; + + cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL; + io_id = g_io_add_watch(io, cond, io_cb, &d); + + mainloop = g_main_loop_new(NULL, FALSE); + + timer_id = g_timeout_add_seconds(1, test_timeout, &d); + + g_obex_add_request_function(obex, G_OBEX_OP_GET, handle_get, &d); + + g_io_channel_write_chars(io, (char *) get_req_first, + sizeof(get_req_first), NULL, &d.err); + g_assert_no_error(d.err); + + g_main_loop_run(mainloop); + + g_assert_cmpuint(d.count, ==, 1); + + g_main_loop_unref(mainloop); + mainloop = NULL; + + 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); +} + int main(int argc, char *argv[]) { g_test_init(&argc, &argv, NULL); @@ -406,6 +505,9 @@ int main(int argc, char *argv[]) g_test_add_func("/gobex/test_get_req", test_get_req); g_test_add_func("/gobex/test_get_rsp", test_get_rsp); + g_test_add_func("/gobex/test_put_req_delay", test_put_req_delay); + g_test_add_func("/gobex/test_get_rsp_delay", test_get_rsp_delay); + g_test_run(); return 0; |