From 15402c02c1c4873e0e6bd20f7175d4cd6365af26 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Sat, 9 Jul 2011 13:26:01 +0200 Subject: [PATCH] gobex: Add unit test for SetPath("..") --- unit/test-gobex.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/unit/test-gobex.c b/unit/test-gobex.c index 78d1df596..64449d23c 100644 --- a/unit/test-gobex.c +++ b/unit/test-gobex.c @@ -44,6 +44,8 @@ static uint8_t pkt_setpath_req[] = { G_OBEX_OP_SETPATH | FINAL_BIT, 0x00, 0x10, 0x02, 0x00, G_OBEX_HDR_ID_NAME, 0x00, 0x0b, 0, 'd', 0, 'i', 0, 'r', 0, 0 }; +static uint8_t pkt_setpath_up_req[] = { G_OBEX_OP_SETPATH | FINAL_BIT, + 0x00, 0x05, 0x03, 0x00 }; static uint8_t pkt_setpath_rsp[] = { 0x20 | FINAL_BIT, 0x00, 0x03 }; static uint8_t pkt_nval_connect_rsp[] = { 0x10 | FINAL_BIT, 0x00, 0x05, @@ -882,6 +884,42 @@ static void test_setpath(void) g_assert_no_error(d.err); } +static void test_setpath_up(void) +{ + GIOChannel *io; + GIOCondition cond; + guint io_id, timer_id; + GObex *obex; + struct test_data d = { 0, NULL, { + { pkt_setpath_up_req, sizeof(pkt_setpath_up_req) } }, { + { pkt_setpath_rsp, sizeof(pkt_setpath_rsp) } } }; + + create_endpoints(&obex, &io, SOCK_STREAM); + + 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_setpath(obex, "..", req_complete, &d, &d.err); + g_assert_no_error(d.err); + + g_main_loop_run(d.mainloop); + + g_assert_cmpuint(d.count, ==, 1); + + 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); +} + int main(int argc, char *argv[]) { g_test_init(&argc, &argv, NULL); @@ -936,6 +974,7 @@ int main(int argc, char *argv[]) g_test_add_func("/gobex/test_connect", test_connect); g_test_add_func("/gobex/test_setpath", test_setpath); + g_test_add_func("/gobex/test_setpath_up", test_setpath_up); g_test_run(); -- 2.47.3