OSDN Git Service

gobex: Add g_obex_delete
authorJohan Hedberg <johan.hedberg@intel.com>
Sat, 9 Jul 2011 11:36:05 +0000 (13:36 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Tue, 4 Dec 2012 21:22:01 +0000 (22:22 +0100)
gobex/gobex.c
gobex/gobex.h
unit/test-gobex.c

index 7610342..b4e809a 100644 (file)
@@ -965,3 +965,17 @@ guint g_obex_mkdir(GObex *obex, const char *path, GObexResponseFunc func,
 
        return g_obex_send_req(obex, req, -1, func, user_data, err);
 }
+
+guint g_obex_delete(GObex *obex, const char *name, GObexResponseFunc func,
+                                       gpointer user_data, GError **err)
+{
+       GObexPacket *req;
+       GObexHeader *hdr;
+
+       req = g_obex_packet_new(G_OBEX_OP_PUT, TRUE, NULL);
+
+       hdr = g_obex_header_new_unicode(G_OBEX_HDR_ID_NAME, name);
+       g_obex_packet_add_header(req, hdr);
+
+       return g_obex_send_req(obex, req, -1, func, user_data, err);
+}
index dcdc72f..1c0e170 100644 (file)
@@ -75,4 +75,7 @@ guint g_obex_setpath(GObex *obex, const char *path, GObexResponseFunc func,
 guint g_obex_mkdir(GObex *obex, const char *path, GObexResponseFunc func,
                                        gpointer user_data, GError **err);
 
+guint g_obex_delete(GObex *obex, const char *name, GObexResponseFunc func,
+                                       gpointer user_data, GError **err);
+
 #endif /* __GOBEX_H */
index 52d01e4..7a7cbe9 100644 (file)
@@ -46,13 +46,17 @@ static uint8_t pkt_setpath_req[] = { G_OBEX_OP_SETPATH | FINAL_BIT, 0x00, 0x10,
                                        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_success_rsp[] = { 0x20 | FINAL_BIT, 0x00, 0x03 };
 
 static uint8_t pkt_mkdir_req[] = { G_OBEX_OP_SETPATH | FINAL_BIT, 0x00, 0x10,
                                        0x00, 0x00,
                                        G_OBEX_HDR_ID_NAME, 0x00, 0x0b,
                                        0, 'd', 0, 'i', 0, 'r', 0, 0 };
 
+static uint8_t pkt_delete_req[] = { G_OBEX_OP_PUT | FINAL_BIT, 0x00, 0x16,
+               G_OBEX_HDR_ID_NAME, 0x00, 0x13,
+               0, 'f', 0, 'o', 0, 'o', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0 };
+
 static uint8_t pkt_nval_connect_rsp[] = { 0x10 | FINAL_BIT, 0x00, 0x05,
                                        0x10, 0x00, };
 static uint8_t pkt_abort_rsp[] = { 0x90, 0x00, 0x03 };
@@ -860,8 +864,8 @@ static void test_setpath(void)
        guint io_id, timer_id;
        GObex *obex;
        struct test_data d = { 0, NULL, {
-                               { pkt_setpath_req, sizeof(pkt_setpath_req) } }, {
-                               { pkt_setpath_rsp, sizeof(pkt_setpath_rsp) } } };
+                       { pkt_setpath_req, sizeof(pkt_setpath_req) } }, {
+                       { pkt_success_rsp, sizeof(pkt_success_rsp) } } };
 
        create_endpoints(&obex, &io, SOCK_STREAM);
 
@@ -897,7 +901,7 @@ static void test_setpath_up(void)
        GObex *obex;
        struct test_data d = { 0, NULL, {
                        { pkt_setpath_up_req, sizeof(pkt_setpath_up_req) } }, {
-                       { pkt_setpath_rsp, sizeof(pkt_setpath_rsp) } } };
+                       { pkt_success_rsp, sizeof(pkt_success_rsp) } } };
 
        create_endpoints(&obex, &io, SOCK_STREAM);
 
@@ -932,8 +936,8 @@ static void test_mkdir(void)
        guint io_id, timer_id;
        GObex *obex;
        struct test_data d = { 0, NULL, {
-                               { pkt_mkdir_req, sizeof(pkt_mkdir_req) } }, {
-                               { pkt_setpath_rsp, sizeof(pkt_setpath_rsp) } } };
+                       { pkt_mkdir_req, sizeof(pkt_mkdir_req) } }, {
+                       { pkt_success_rsp, sizeof(pkt_success_rsp) } } };
 
        create_endpoints(&obex, &io, SOCK_STREAM);
 
@@ -961,6 +965,42 @@ static void test_mkdir(void)
        g_assert_no_error(d.err);
 }
 
+static void test_delete(void)
+{
+       GIOChannel *io;
+       GIOCondition cond;
+       guint io_id, timer_id;
+       GObex *obex;
+       struct test_data d = { 0, NULL, {
+                       { pkt_delete_req, sizeof(pkt_delete_req) } }, {
+                       { pkt_success_rsp, sizeof(pkt_success_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_delete(obex, "foo.txt", 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);
@@ -1019,6 +1059,8 @@ int main(int argc, char *argv[])
 
        g_test_add_func("/gobex/test_mkdir", test_mkdir);
 
+       g_test_add_func("/gobex/test_delete", test_delete);
+
        g_test_run();
 
        return 0;