summaryrefslogtreecommitdiff
path: root/unit/test-gobex-transfer.c
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2011-07-08 12:01:29 +0200
committerJohan Hedberg <johan.hedberg@intel.com>2011-07-16 17:50:51 +0300
commit52ca13fd0e850cfa2536451ecc186bbaf60119d1 (patch)
treed5c8fa40277f97a9dfb95989fc252787c384dd4f /unit/test-gobex-transfer.c
parentf40a85d69fb66737b05410d57d0d188a5b5f473f (diff)
downloadobexd-52ca13fd0e850cfa2536451ecc186bbaf60119d1.tar.gz
gobex: Add unit tests for g_obex_suspend & g_obex_resume
Diffstat (limited to 'unit/test-gobex-transfer.c')
-rw-r--r--unit/test-gobex-transfer.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/unit/test-gobex-transfer.c b/unit/test-gobex-transfer.c
index e583d37..9f496a9 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;