3 * OBEX library with GLib integration
5 * Copyright (C) 2011 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <sys/types.h>
24 #include <sys/socket.h>
32 #include <gobex/gobex.h>
36 #define FINAL_BIT 0x80
37 #define RANDOM_PACKETS 4
39 static guint8 put_req_first[] = { G_OBEX_OP_PUT, 0x00, 0x30,
40 G_OBEX_HDR_TYPE, 0x00, 0x0b,
41 'f', 'o', 'o', '/', 'b', 'a', 'r', '\0',
42 G_OBEX_HDR_NAME, 0x00, 0x15,
43 0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0,
44 G_OBEX_HDR_BODY, 0x00, 0x0d,
45 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
47 static guint8 put_req_first_srm[] = { G_OBEX_OP_PUT, 0x00, 0x32,
48 G_OBEX_HDR_TYPE, 0x00, 0x0b,
49 'f', 'o', 'o', '/', 'b', 'a', 'r', '\0',
50 G_OBEX_HDR_NAME, 0x00, 0x15,
51 0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0,
52 G_OBEX_HDR_SRM, G_OBEX_SRM_ENABLE,
53 G_OBEX_HDR_BODY, 0x00, 0x0d,
54 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
56 static guint8 put_req_zero[255] = { G_OBEX_OP_PUT, 0x00, 0xff,
57 G_OBEX_HDR_BODY, 0x00, 0xfc };
59 static guint8 put_req_last[] = { G_OBEX_OP_PUT | FINAL_BIT, 0x00, 0x06,
60 G_OBEX_HDR_BODY_END, 0x00, 0x03 };
62 static guint8 abort_req[] = { G_OBEX_OP_ABORT | FINAL_BIT, 0x00, 0x03 };
64 static guint8 put_rsp_first[] = { G_OBEX_RSP_CONTINUE | FINAL_BIT,
66 static guint8 put_rsp_first_srm[] = { G_OBEX_RSP_CONTINUE | FINAL_BIT,
68 G_OBEX_HDR_SRM, 0x01 };
69 static guint8 put_rsp_first_srm_wait[] = { G_OBEX_RSP_CONTINUE | FINAL_BIT,
72 G_OBEX_HDR_SRMP, 0x01 };
73 static guint8 put_rsp_last[] = { G_OBEX_RSP_SUCCESS | FINAL_BIT, 0x00, 0x03 };
75 static guint8 get_req_first[] = { G_OBEX_OP_GET | FINAL_BIT, 0x00, 0x23,
76 G_OBEX_HDR_TYPE, 0x00, 0x0b,
77 'f', 'o', 'o', '/', 'b', 'a', 'r', '\0',
78 G_OBEX_HDR_NAME, 0x00, 0x15,
79 0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0 };
81 static guint8 get_req_first_app[] = { G_OBEX_OP_GET | FINAL_BIT, 0x00, 0x2a,
82 G_OBEX_HDR_TYPE, 0x00, 0x0b,
83 'f', 'o', 'o', '/', 'b', 'a', 'r', '\0',
84 G_OBEX_HDR_NAME, 0x00, 0x15,
85 0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0,
86 G_OBEX_HDR_APPARAM, 0x00, 0x07,
89 static guint8 get_req_first_srm[] = { G_OBEX_OP_GET | FINAL_BIT, 0x00, 0x25,
91 G_OBEX_HDR_TYPE, 0x00, 0x0b,
92 'f', 'o', 'o', '/', 'b', 'a', 'r', '\0',
93 G_OBEX_HDR_NAME, 0x00, 0x15,
94 0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0 };
96 static guint8 get_req_first_srm_wait[] = { G_OBEX_OP_GET | FINAL_BIT, 0x00, 0x27,
98 G_OBEX_HDR_TYPE, 0x00, 0x0b,
99 'f', 'o', 'o', '/', 'b', 'a', 'r', '\0',
100 G_OBEX_HDR_NAME, 0x00, 0x15,
101 0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0,
102 G_OBEX_HDR_SRMP, 0x01 };
104 static guint8 get_req_last[] = { G_OBEX_OP_GET | FINAL_BIT, 0x00, 0x03, };
106 static guint8 get_rsp_first_app[] = { G_OBEX_RSP_CONTINUE | FINAL_BIT, 0x00, 0x0A,
107 G_OBEX_HDR_APPARAM, 0x00, 0x07,
109 static guint8 get_rsp_first[] = { G_OBEX_RSP_CONTINUE | FINAL_BIT, 0x00, 0x10,
110 G_OBEX_HDR_BODY, 0x00, 0x0d,
111 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
112 static guint8 get_rsp_first_srm[] = { G_OBEX_RSP_CONTINUE | FINAL_BIT, 0x00, 0x12,
113 G_OBEX_HDR_SRM, 0x01,
114 G_OBEX_HDR_BODY, 0x00, 0x0d,
115 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
116 static guint8 get_rsp_first_srm_wait_next[] = { G_OBEX_RSP_CONTINUE | FINAL_BIT,
118 G_OBEX_HDR_SRM, 0x01,
119 G_OBEX_HDR_SRMP, 0x02,
120 G_OBEX_HDR_BODY, 0x00, 0x0d,
121 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
122 static guint8 get_rsp_zero[255] = { G_OBEX_RSP_CONTINUE | FINAL_BIT, 0x00, 0xff,
123 G_OBEX_HDR_BODY, 0x00, 0xfc };
124 static guint8 get_rsp_zero_wait_next[255] = { G_OBEX_RSP_CONTINUE | FINAL_BIT,
126 G_OBEX_HDR_SRMP, 0x02,
127 G_OBEX_HDR_BODY, 0x00, 0xfa };
128 static guint8 get_rsp_last[] = { G_OBEX_RSP_SUCCESS | FINAL_BIT, 0x00, 0x06,
129 G_OBEX_HDR_BODY_END, 0x00, 0x03 };
131 static guint8 conn_req[] = { G_OBEX_OP_CONNECT | FINAL_BIT, 0x00, 0x07,
132 0x10, 0x00, 0x10, 0x00 };
133 static guint8 conn_rsp[] = { G_OBEX_RSP_SUCCESS | FINAL_BIT, 0x00, 0x0c,
134 0x10, 0x00, 0x10, 0x00,
135 G_OBEX_HDR_CONNECTION, 0x00, 0x00,
138 static guint8 conn_req_srm[] = { G_OBEX_OP_CONNECT | FINAL_BIT, 0x00, 0x09,
139 0x10, 0x00, 0x10, 0x00,
140 G_OBEX_HDR_SRM, 0x02 };
141 static guint8 conn_rsp_srm[] = { G_OBEX_RSP_SUCCESS | FINAL_BIT, 0x00, 0x0e,
142 0x10, 0x00, 0x10, 0x00,
143 G_OBEX_HDR_CONNECTION, 0x00, 0x00,
145 G_OBEX_HDR_SRM, 0x01 };
147 static guint8 unavailable_rsp[] = { G_OBEX_RSP_SERVICE_UNAVAILABLE | FINAL_BIT,
150 static guint8 conn_get_req_first[] = { G_OBEX_OP_GET | FINAL_BIT, 0x00, 0x28,
151 G_OBEX_HDR_CONNECTION, 0x00, 0x00, 0x00, 0x01,
152 G_OBEX_HDR_TYPE, 0x00, 0x0b,
153 'f', 'o', 'o', '/', 'b', 'a', 'r', '\0',
154 G_OBEX_HDR_NAME, 0x00, 0x15,
155 0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0 };
157 static guint8 conn_get_req_wrg[] = { G_OBEX_OP_GET | FINAL_BIT, 0x00, 0x28,
158 G_OBEX_HDR_CONNECTION, 0x00, 0x00, 0x00, 0xFF,
159 G_OBEX_HDR_TYPE, 0x00, 0x0b,
160 'f', 'o', 'o', '/', 'b', 'a', 'r', '\0',
161 G_OBEX_HDR_NAME, 0x00, 0x15,
162 0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0 };
164 static guint8 conn_put_req_first[] = { G_OBEX_OP_PUT, 0x00, 0x35,
165 G_OBEX_HDR_CONNECTION, 0x00, 0x00, 0x00, 0x01,
166 G_OBEX_HDR_TYPE, 0x00, 0x0b,
167 'f', 'o', 'o', '/', 'b', 'a', 'r', '\0',
168 G_OBEX_HDR_NAME, 0x00, 0x15,
169 0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0,
170 G_OBEX_HDR_BODY, 0x00, 0x0d,
171 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
173 static guint8 hdr_type[] = "foo/bar";
174 static guint8 hdr_app[] = { 0, 1, 2, 3 };
175 static guint8 body_data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
177 static void transfer_complete(GObex *obex, GError *err, gpointer user_data)
179 struct test_data *d = user_data;
182 d->err = g_error_copy(err);
184 g_main_loop_quit(d->mainloop);
187 static gboolean resume_obex(gpointer user_data)
189 g_obex_resume(user_data);
193 static gssize provide_seq(void *buf, gsize len, gpointer user_data)
195 struct test_data *d = user_data;
199 if (d->count == RANDOM_PACKETS - 1)
202 fd = open("/dev/urandom", O_RDONLY | O_NOCTTY, 0);
204 g_set_error(&d->err, TEST_ERROR, TEST_ERROR_UNEXPECTED,
205 "open(/dev/urandom): %s", strerror(errno));
206 g_main_loop_quit(d->mainloop);
210 ret = read(fd, buf, len);
215 static gssize provide_eagain(void *buf, gsize len, gpointer user_data)
217 struct test_data *d = user_data;
222 if (len < sizeof(body_data)) {
223 g_set_error(&d->err, TEST_ERROR, TEST_ERROR_UNEXPECTED,
224 "Got data request for only %zu bytes", len);
225 g_main_loop_quit(d->mainloop);
229 if (d->provide_delay > 0) {
230 g_timeout_add(d->provide_delay, resume_obex, d->obex);
231 d->provide_delay = 0;
235 memcpy(buf, body_data, sizeof(body_data));
237 return sizeof(body_data);
240 static gssize provide_data(void *buf, gsize len, gpointer user_data)
242 struct test_data *d = user_data;
247 if (len < sizeof(body_data)) {
248 g_set_error(&d->err, TEST_ERROR, TEST_ERROR_UNEXPECTED,
249 "Got data request for only %zu bytes", len);
250 g_main_loop_quit(d->mainloop);
254 memcpy(buf, body_data, sizeof(body_data));
256 if (d->provide_delay > 0) {
257 g_obex_suspend(d->obex);
258 g_timeout_add(d->provide_delay, resume_obex, d->obex);
261 d->total += sizeof(body_data);
263 return sizeof(body_data);
266 static void test_put_req(void)
270 guint io_id, timer_id;
272 struct test_data d = { 0, NULL, {
273 { put_req_first, sizeof(put_req_first) },
274 { put_req_last, sizeof(put_req_last) } }, {
275 { put_rsp_first, sizeof(put_rsp_first) },
276 { put_rsp_last, sizeof(put_rsp_last) } } };
278 create_endpoints(&obex, &io, SOCK_STREAM);
280 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
281 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
283 d.mainloop = g_main_loop_new(NULL, FALSE);
285 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
287 g_obex_put_req(obex, provide_data, transfer_complete, &d, &d.err,
288 G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
289 G_OBEX_HDR_NAME, "file.txt",
291 g_assert_no_error(d.err);
293 g_main_loop_run(d.mainloop);
295 g_assert_cmpuint(d.count, ==, 2);
297 g_main_loop_unref(d.mainloop);
299 g_source_remove(timer_id);
300 g_io_channel_unref(io);
301 g_source_remove(io_id);
304 g_assert_no_error(d.err);
307 static gboolean rcv_data(const void *buf, gsize len, gpointer user_data)
309 struct test_data *d = user_data;
311 if (len != sizeof(body_data))
312 d->err = g_error_new(TEST_ERROR, TEST_ERROR_UNEXPECTED,
313 "Unexpected byte count %zu", len);
315 if (memcmp(buf, body_data, sizeof(body_data)) != 0) {
316 dump_bufs(body_data, sizeof(body_data), buf, len);
317 d->err = g_error_new(TEST_ERROR, TEST_ERROR_UNEXPECTED,
318 "Unexpected byte count %zu", len);
324 static void handle_put(GObex *obex, GObexPacket *req, gpointer user_data)
326 struct test_data *d = user_data;
327 guint8 op = g_obex_packet_get_operation(req, NULL);
330 if (op != G_OBEX_OP_PUT) {
331 d->err = g_error_new(TEST_ERROR, TEST_ERROR_UNEXPECTED,
332 "Unexpected opcode 0x%02x", op);
333 g_main_loop_quit(d->mainloop);
337 id = g_obex_put_rsp(obex, req, rcv_data, transfer_complete, d, &d->err,
340 g_main_loop_quit(d->mainloop);
343 static void test_put_rsp(void)
347 guint io_id, timer_id;
349 struct test_data d = { 0, NULL, {
350 { put_rsp_first, sizeof(put_rsp_first) },
351 { put_rsp_last, sizeof(put_rsp_last) } }, {
352 { put_req_last, sizeof(put_req_last) },
355 create_endpoints(&obex, &io, SOCK_STREAM);
357 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
358 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
360 d.mainloop = g_main_loop_new(NULL, FALSE);
362 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
364 g_obex_add_request_function(obex, G_OBEX_OP_PUT, handle_put, &d);
366 g_io_channel_write_chars(io, (char *) put_req_first,
367 sizeof(put_req_first), NULL, &d.err);
368 g_assert_no_error(d.err);
370 g_main_loop_run(d.mainloop);
372 g_assert_cmpuint(d.count, ==, 1);
374 g_main_loop_unref(d.mainloop);
376 g_source_remove(timer_id);
377 g_io_channel_unref(io);
378 g_source_remove(io_id);
381 g_assert_no_error(d.err);
384 static gboolean rcv_seq(const void *buf, gsize len, gpointer user_data)
389 static void handle_put_seq(GObex *obex, GObexPacket *req,
392 struct test_data *d = user_data;
393 guint8 op = g_obex_packet_get_operation(req, NULL);
396 if (op != G_OBEX_OP_PUT) {
397 d->err = g_error_new(TEST_ERROR, TEST_ERROR_UNEXPECTED,
398 "Unexpected opcode 0x%02x", op);
399 g_main_loop_quit(d->mainloop);
403 id = g_obex_put_rsp(obex, req, rcv_seq, transfer_complete, d,
404 &d->err, G_OBEX_HDR_INVALID);
406 g_main_loop_quit(d->mainloop);
409 static void test_stream_put_rsp(void)
413 guint io_id, timer_id;
415 struct test_data d = { 0, NULL, {
416 { put_rsp_first, sizeof(put_rsp_first) },
417 { put_rsp_first, sizeof(put_rsp_first) },
418 { put_rsp_first, sizeof(put_rsp_first) },
419 { put_rsp_last, sizeof(put_rsp_last) } }, {
420 { put_req_zero, sizeof(put_req_zero) },
421 { put_req_zero, sizeof(put_req_zero) },
422 { put_req_last, sizeof(put_req_last) },
425 create_endpoints(&obex, &io, SOCK_STREAM);
427 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
428 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
430 d.mainloop = g_main_loop_new(NULL, FALSE);
432 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
434 g_obex_add_request_function(obex, G_OBEX_OP_PUT, handle_put_seq,
437 g_io_channel_write_chars(io, (char *) put_req_first,
438 sizeof(put_req_first), NULL, &d.err);
439 g_assert_no_error(d.err);
441 g_main_loop_run(d.mainloop);
443 g_assert_cmpuint(d.count, ==, RANDOM_PACKETS - 1);
445 g_main_loop_unref(d.mainloop);
447 g_source_remove(timer_id);
448 g_io_channel_unref(io);
449 g_source_remove(io_id);
452 g_assert_no_error(d.err);
455 static gboolean cancel_transfer(gpointer user_data)
457 struct test_data *d = user_data;
460 g_obex_cancel_transfer(d->id, transfer_complete, user_data);
465 static gssize abort_data(void *buf, gsize len, gpointer user_data)
467 g_idle_add_full(G_PRIORITY_HIGH, cancel_transfer, user_data, NULL);
468 return provide_data(buf, len, user_data);
471 static void test_stream_put_req_abort(void)
475 guint io_id, timer_id;
477 struct test_data d = { 0, NULL, {
478 { put_req_first, sizeof(put_req_first) },
479 { abort_req, sizeof(abort_req) } }, {
480 { put_rsp_last, sizeof(put_rsp_last) } } };
482 create_endpoints(&obex, &io, SOCK_STREAM);
484 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
485 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
487 d.mainloop = g_main_loop_new(NULL, FALSE);
489 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
491 d.id = g_obex_put_req(obex, abort_data, transfer_complete, &d, &d.err,
492 G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
493 G_OBEX_HDR_NAME, "file.txt",
495 g_assert_no_error(d.err);
497 g_main_loop_run(d.mainloop);
499 g_assert_cmpuint(d.count, ==, 2);
501 g_main_loop_unref(d.mainloop);
503 g_source_remove(timer_id);
504 g_io_channel_unref(io);
505 g_source_remove(io_id);
508 g_assert_error(d.err, G_OBEX_ERROR, G_OBEX_ERROR_CANCELLED);
511 static void test_stream_put_rsp_abort(void)
515 guint io_id, timer_id;
517 struct test_data d = { 0, NULL, {
518 { put_rsp_first, sizeof(put_rsp_first) },
519 { put_rsp_first, sizeof(put_rsp_first) },
520 { put_rsp_first, sizeof(put_rsp_first) },
521 { put_rsp_last, sizeof(put_rsp_last) } }, {
522 { put_req_zero, sizeof(put_req_zero) },
523 { abort_req, sizeof(abort_req) },
527 create_endpoints(&obex, &io, SOCK_STREAM);
529 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
530 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
532 d.mainloop = g_main_loop_new(NULL, FALSE);
534 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
536 g_obex_add_request_function(obex, G_OBEX_OP_PUT, handle_put_seq, &d);
538 g_io_channel_write_chars(io, (char *) put_req_first,
539 sizeof(put_req_first), NULL, &d.err);
540 g_assert_no_error(d.err);
542 g_main_loop_run(d.mainloop);
544 g_assert_cmpuint(d.count, ==, RANDOM_PACKETS - 2);
546 g_main_loop_unref(d.mainloop);
548 g_source_remove(timer_id);
549 g_io_channel_unref(io);
550 g_source_remove(io_id);
553 g_assert_error(d.err, G_OBEX_ERROR, G_OBEX_ERROR_CANCELLED);
556 static void handle_put_seq_wait(GObex *obex, GObexPacket *req,
559 struct test_data *d = user_data;
560 guint8 op = g_obex_packet_get_operation(req, NULL);
563 if (op != G_OBEX_OP_PUT) {
564 d->err = g_error_new(TEST_ERROR, TEST_ERROR_UNEXPECTED,
565 "Unexpected opcode 0x%02x", op);
566 g_main_loop_quit(d->mainloop);
570 id = g_obex_put_rsp(obex, req, rcv_seq, transfer_complete, d,
572 G_OBEX_HDR_SRMP, G_OBEX_SRMP_WAIT,
575 g_main_loop_quit(d->mainloop);
578 static void test_packet_put_rsp_wait(void)
582 guint io_id, timer_id;
584 struct test_data d = { 0, NULL, {
585 { put_rsp_first_srm_wait, sizeof(put_rsp_first_srm_wait) },
586 { put_rsp_first, sizeof(put_rsp_first) },
588 { put_rsp_last, sizeof(put_rsp_last) } }, {
589 { put_req_zero, sizeof(put_req_zero) },
590 { put_req_zero, sizeof(put_req_zero) },
591 { put_req_last, sizeof(put_req_last) },
594 create_endpoints(&obex, &io, SOCK_SEQPACKET);
596 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
597 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
599 d.mainloop = g_main_loop_new(NULL, FALSE);
601 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
603 g_obex_add_request_function(obex, G_OBEX_OP_PUT,
604 handle_put_seq_wait, &d);
606 g_io_channel_write_chars(io, (char *) put_req_first_srm,
607 sizeof(put_req_first_srm), NULL,
609 g_assert_no_error(d.err);
611 g_main_loop_run(d.mainloop);
613 g_assert_cmpuint(d.count, ==, RANDOM_PACKETS);
615 g_main_loop_unref(d.mainloop);
617 g_source_remove(timer_id);
618 g_io_channel_unref(io);
619 g_source_remove(io_id);
622 g_assert_no_error(d.err);
625 static void test_packet_put_rsp(void)
629 guint io_id, timer_id;
631 struct test_data d = { 0, NULL, {
632 { put_rsp_first_srm, sizeof(put_rsp_first_srm) },
635 { put_rsp_last, sizeof(put_rsp_last) } }, {
636 { put_req_zero, sizeof(put_req_zero) },
637 { put_req_zero, sizeof(put_req_zero) },
638 { put_req_last, sizeof(put_req_last) },
641 create_endpoints(&obex, &io, SOCK_SEQPACKET);
643 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
644 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
646 d.mainloop = g_main_loop_new(NULL, FALSE);
648 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
650 g_obex_add_request_function(obex, G_OBEX_OP_PUT, handle_put_seq, &d);
652 g_io_channel_write_chars(io, (char *) put_req_first_srm,
653 sizeof(put_req_first_srm), NULL,
655 g_assert_no_error(d.err);
657 g_main_loop_run(d.mainloop);
659 g_assert_cmpuint(d.count, ==, RANDOM_PACKETS);
661 g_main_loop_unref(d.mainloop);
663 g_source_remove(timer_id);
664 g_io_channel_unref(io);
665 g_source_remove(io_id);
668 g_assert_no_error(d.err);
671 static void test_get_req(void)
675 guint io_id, timer_id;
677 struct test_data d = { 0, NULL, {
678 { get_req_first, sizeof(get_req_first) },
679 { get_req_last, sizeof(get_req_last) } }, {
680 { get_rsp_first, sizeof(get_rsp_first) },
681 { get_rsp_last, sizeof(get_rsp_last) } } };
683 create_endpoints(&obex, &io, SOCK_STREAM);
685 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
686 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
688 d.mainloop = g_main_loop_new(NULL, FALSE);
690 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
692 g_obex_get_req(obex, rcv_data, transfer_complete, &d, &d.err,
693 G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
694 G_OBEX_HDR_NAME, "file.txt",
696 g_assert_no_error(d.err);
698 g_main_loop_run(d.mainloop);
700 g_assert_cmpuint(d.count, ==, 2);
702 g_main_loop_unref(d.mainloop);
704 g_source_remove(timer_id);
705 g_io_channel_unref(io);
706 g_source_remove(io_id);
709 g_assert_no_error(d.err);
712 static void test_stream_get_req(void)
716 guint io_id, timer_id;
718 struct test_data d = { 0, NULL, {
719 { get_req_first, sizeof(get_req_first) },
722 { get_req_last, sizeof(get_req_last) } }, {
723 { get_rsp_first, sizeof(get_rsp_first) },
724 { get_rsp_zero, sizeof(get_rsp_zero) },
725 { get_rsp_zero, sizeof(get_rsp_zero) },
726 { get_rsp_last, sizeof(get_rsp_last) } } };
728 create_endpoints(&obex, &io, SOCK_STREAM);
730 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
731 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
733 d.mainloop = g_main_loop_new(NULL, FALSE);
735 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
737 g_obex_get_req(obex, rcv_seq, transfer_complete, &d, &d.err,
738 G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
739 G_OBEX_HDR_NAME, "file.txt",
741 g_assert_no_error(d.err);
743 g_main_loop_run(d.mainloop);
745 g_assert_cmpuint(d.count, ==, RANDOM_PACKETS);
747 g_main_loop_unref(d.mainloop);
749 g_source_remove(timer_id);
750 g_io_channel_unref(io);
751 g_source_remove(io_id);
754 g_assert_no_error(d.err);
757 static void test_packet_get_req(void)
761 guint io_id, timer_id;
763 struct test_data d = { 0, NULL, {
764 { get_req_first_srm, sizeof(get_req_first_srm) },
767 { get_req_last, sizeof(get_req_last) } }, {
768 { get_rsp_first_srm, sizeof(get_rsp_first_srm) },
769 { get_rsp_zero, sizeof(get_rsp_zero) },
770 { get_rsp_zero, sizeof(get_rsp_zero) },
771 { get_rsp_last, sizeof(get_rsp_last) } } };
773 create_endpoints(&obex, &io, SOCK_SEQPACKET);
775 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
776 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
778 d.mainloop = g_main_loop_new(NULL, FALSE);
780 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
782 g_obex_get_req(obex, rcv_seq, transfer_complete, &d, &d.err,
783 G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
784 G_OBEX_HDR_NAME, "file.txt",
786 g_assert_no_error(d.err);
788 g_main_loop_run(d.mainloop);
790 g_assert_cmpuint(d.count, ==, RANDOM_PACKETS);
792 g_main_loop_unref(d.mainloop);
794 g_source_remove(timer_id);
795 g_io_channel_unref(io);
796 g_source_remove(io_id);
799 g_assert_no_error(d.err);
802 static void test_packet_get_req_wait(void)
806 guint io_id, timer_id;
808 struct test_data d = { 0, NULL, {
809 { get_req_first_srm_wait, sizeof(get_req_first_srm_wait) },
810 { get_req_last, sizeof(get_req_last) },
812 { get_req_last, sizeof(get_req_last) } }, {
813 { get_rsp_first_srm, sizeof(get_rsp_first_srm) },
814 { get_rsp_zero, sizeof(get_rsp_zero) },
815 { get_rsp_zero, sizeof(get_rsp_zero) },
816 { get_rsp_last, sizeof(get_rsp_last) } } };
818 create_endpoints(&obex, &io, SOCK_SEQPACKET);
820 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
821 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
823 d.mainloop = g_main_loop_new(NULL, FALSE);
825 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
827 g_obex_get_req(obex, rcv_seq, transfer_complete, &d, &d.err,
828 G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
829 G_OBEX_HDR_NAME, "file.txt",
830 G_OBEX_HDR_SRMP, G_OBEX_SRMP_WAIT,
832 g_assert_no_error(d.err);
834 g_main_loop_run(d.mainloop);
836 g_assert_cmpuint(d.count, ==, RANDOM_PACKETS);
838 g_main_loop_unref(d.mainloop);
840 g_source_remove(timer_id);
841 g_io_channel_unref(io);
842 g_source_remove(io_id);
845 g_assert_no_error(d.err);
848 static void test_packet_get_req_wait_next(void)
852 guint io_id, timer_id;
854 struct test_data d = { 0, NULL, {
855 { get_req_first_srm, sizeof(get_req_first_srm) },
856 { get_req_last, sizeof(get_req_last) },
857 { get_req_last, sizeof(get_req_last) },
858 { get_req_last, sizeof(get_req_last) } }, {
859 { get_rsp_first_srm_wait_next,
860 sizeof(get_rsp_first_srm_wait_next) },
861 { get_rsp_zero_wait_next, sizeof(get_rsp_zero_wait_next) },
862 { get_rsp_zero_wait_next, sizeof(get_rsp_zero_wait_next) },
863 { get_rsp_last, sizeof(get_rsp_last) } } };
865 create_endpoints(&obex, &io, SOCK_SEQPACKET);
867 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
868 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
870 d.mainloop = g_main_loop_new(NULL, FALSE);
872 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
874 g_obex_get_req(obex, rcv_seq, transfer_complete, &d, &d.err,
875 G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
876 G_OBEX_HDR_NAME, "file.txt",
878 g_assert_no_error(d.err);
880 g_main_loop_run(d.mainloop);
882 g_assert_cmpuint(d.count, ==, RANDOM_PACKETS);
884 g_main_loop_unref(d.mainloop);
886 g_source_remove(timer_id);
887 g_io_channel_unref(io);
888 g_source_remove(io_id);
891 g_assert_no_error(d.err);
894 static void test_get_req_app(void)
898 guint io_id, timer_id;
900 struct test_data d = { 0, NULL, {
901 { get_req_first_app, sizeof(get_req_first_app) },
902 { get_req_last, sizeof(get_req_last) },
903 { get_req_last, sizeof(get_req_last) } }, {
904 { get_rsp_first_app, sizeof(get_rsp_first_app) },
905 { get_rsp_first, sizeof(get_rsp_first) },
906 { get_rsp_last, sizeof(get_rsp_last) } } };
908 create_endpoints(&obex, &io, SOCK_STREAM);
910 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
911 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
913 d.mainloop = g_main_loop_new(NULL, FALSE);
915 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
917 g_obex_get_req(obex, rcv_data, transfer_complete, &d, &d.err,
918 G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
919 G_OBEX_HDR_NAME, "file.txt",
920 G_OBEX_HDR_APPARAM, hdr_app, sizeof(hdr_app),
922 g_assert_no_error(d.err);
924 g_main_loop_run(d.mainloop);
926 g_assert_cmpuint(d.count, ==, 3);
928 g_main_loop_unref(d.mainloop);
930 g_source_remove(timer_id);
931 g_io_channel_unref(io);
932 g_source_remove(io_id);
935 g_assert_no_error(d.err);
938 static void handle_get_eagain(GObex *obex, GObexPacket *req,
941 struct test_data *d = user_data;
942 guint8 op = g_obex_packet_get_operation(req, NULL);
945 if (op != G_OBEX_OP_GET) {
946 d->err = g_error_new(TEST_ERROR, TEST_ERROR_UNEXPECTED,
947 "Unexpected opcode 0x%02x", op);
948 g_main_loop_quit(d->mainloop);
952 id = g_obex_get_rsp(obex, provide_eagain, transfer_complete, d,
953 &d->err, G_OBEX_HDR_INVALID);
955 g_main_loop_quit(d->mainloop);
958 static void handle_get(GObex *obex, GObexPacket *req, gpointer user_data)
960 struct test_data *d = user_data;
961 guint8 op = g_obex_packet_get_operation(req, NULL);
964 if (op != G_OBEX_OP_GET) {
965 d->err = g_error_new(TEST_ERROR, TEST_ERROR_UNEXPECTED,
966 "Unexpected opcode 0x%02x", op);
967 g_main_loop_quit(d->mainloop);
971 id = g_obex_get_rsp(obex, provide_data, transfer_complete, d, &d->err,
974 g_main_loop_quit(d->mainloop);
977 static void test_stream_put_req(void)
981 guint io_id, timer_id;
983 struct test_data d = { 0, NULL, {
987 { put_req_last, sizeof(put_req_last) } }, {
988 { put_rsp_first, sizeof(put_rsp_first) },
989 { put_rsp_first, sizeof(put_rsp_first) },
990 { put_rsp_first, sizeof(put_rsp_first) },
991 { put_rsp_last, sizeof(put_rsp_last) } } };
993 create_endpoints(&obex, &io, SOCK_STREAM);
996 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
997 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
999 d.mainloop = g_main_loop_new(NULL, FALSE);
1001 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
1003 g_obex_put_req(obex, provide_seq, transfer_complete, &d, &d.err,
1004 G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
1005 G_OBEX_HDR_NAME, "random.bin",
1006 G_OBEX_HDR_INVALID);
1007 g_assert_no_error(d.err);
1009 g_main_loop_run(d.mainloop);
1011 g_assert_cmpuint(d.count, ==, RANDOM_PACKETS);
1013 g_main_loop_unref(d.mainloop);
1015 g_source_remove(timer_id);
1016 g_io_channel_unref(io);
1017 g_source_remove(io_id);
1020 g_assert_no_error(d.err);
1023 static void test_packet_put_req_wait(void)
1027 guint io_id, timer_id;
1029 struct test_data d = { 0, NULL, {
1033 { put_req_last, sizeof(put_req_last) } }, {
1034 { put_rsp_first_srm_wait, sizeof(put_rsp_first_srm_wait) },
1035 { put_rsp_first, sizeof(put_rsp_first) },
1037 { put_rsp_last, sizeof(put_rsp_last) } } };
1039 create_endpoints(&obex, &io, SOCK_SEQPACKET);
1042 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
1043 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
1045 d.mainloop = g_main_loop_new(NULL, FALSE);
1047 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
1049 g_obex_put_req(obex, provide_seq, transfer_complete, &d, &d.err,
1050 G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
1051 G_OBEX_HDR_NAME, "random.bin",
1052 G_OBEX_HDR_INVALID);
1053 g_assert_no_error(d.err);
1055 g_main_loop_run(d.mainloop);
1057 g_assert_cmpuint(d.count, ==, RANDOM_PACKETS);
1059 g_main_loop_unref(d.mainloop);
1061 g_source_remove(timer_id);
1062 g_io_channel_unref(io);
1063 g_source_remove(io_id);
1066 g_assert_no_error(d.err);
1069 static void test_packet_put_req(void)
1073 guint io_id, timer_id;
1075 struct test_data d = { 0, NULL, {
1079 { put_req_last, sizeof(put_req_last) } }, {
1080 { put_rsp_first_srm, sizeof(put_rsp_first_srm) },
1083 { put_rsp_last, sizeof(put_rsp_last) } } };
1085 create_endpoints(&obex, &io, SOCK_SEQPACKET);
1088 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
1089 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
1091 d.mainloop = g_main_loop_new(NULL, FALSE);
1093 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
1095 g_obex_put_req(obex, provide_seq, transfer_complete, &d, &d.err,
1096 G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
1097 G_OBEX_HDR_NAME, "random.bin",
1098 G_OBEX_HDR_INVALID);
1099 g_assert_no_error(d.err);
1101 g_main_loop_run(d.mainloop);
1103 g_assert_cmpuint(d.count, ==, RANDOM_PACKETS);
1105 g_main_loop_unref(d.mainloop);
1107 g_source_remove(timer_id);
1108 g_io_channel_unref(io);
1109 g_source_remove(io_id);
1112 g_assert_no_error(d.err);
1115 static void test_put_req_eagain(void)
1119 guint io_id, timer_id;
1121 struct test_data d = { 0, NULL, {
1122 { put_req_first, sizeof(put_req_first) },
1123 { put_req_last, sizeof(put_req_last) } }, {
1124 { put_rsp_first, sizeof(put_rsp_first) },
1125 { put_rsp_last, sizeof(put_rsp_last) } } };
1127 create_endpoints(&obex, &io, SOCK_STREAM);
1129 d.provide_delay = 200;
1131 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
1132 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
1134 d.mainloop = g_main_loop_new(NULL, FALSE);
1136 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
1138 g_obex_put_req(obex, provide_eagain, transfer_complete, &d, &d.err,
1139 G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
1140 G_OBEX_HDR_NAME, "file.txt",
1141 G_OBEX_HDR_INVALID);
1142 g_assert_no_error(d.err);
1144 g_main_loop_run(d.mainloop);
1146 g_assert_cmpuint(d.count, ==, 2);
1148 g_main_loop_unref(d.mainloop);
1150 g_source_remove(timer_id);
1151 g_io_channel_unref(io);
1152 g_source_remove(io_id);
1155 g_assert_no_error(d.err);
1158 static void test_get_rsp(void)
1162 guint io_id, timer_id;
1164 struct test_data d = { 0, NULL, {
1165 { get_rsp_first, sizeof(get_rsp_first) },
1166 { get_rsp_last, sizeof(get_rsp_last) } }, {
1167 { get_req_last, sizeof(get_req_last) },
1170 create_endpoints(&obex, &io, SOCK_STREAM);
1172 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
1173 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
1175 d.mainloop = g_main_loop_new(NULL, FALSE);
1177 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
1179 g_obex_add_request_function(obex, G_OBEX_OP_GET, handle_get, &d);
1181 g_io_channel_write_chars(io, (char *) get_req_first,
1182 sizeof(get_req_first), NULL, &d.err);
1183 g_assert_no_error(d.err);
1185 g_main_loop_run(d.mainloop);
1187 g_assert_cmpuint(d.count, ==, 1);
1189 g_main_loop_unref(d.mainloop);
1191 g_source_remove(timer_id);
1192 g_io_channel_unref(io);
1193 g_source_remove(io_id);
1196 g_assert_no_error(d.err);
1199 static void handle_get_seq(GObex *obex, GObexPacket *req,
1202 struct test_data *d = user_data;
1203 guint8 op = g_obex_packet_get_operation(req, NULL);
1206 if (op != G_OBEX_OP_GET) {
1207 d->err = g_error_new(TEST_ERROR, TEST_ERROR_UNEXPECTED,
1208 "Unexpected opcode 0x%02x", op);
1209 g_main_loop_quit(d->mainloop);
1213 id = g_obex_get_rsp(obex, provide_seq, transfer_complete, d,
1214 &d->err, G_OBEX_HDR_INVALID);
1216 g_main_loop_quit(d->mainloop);
1219 static void test_stream_get_rsp(void)
1223 guint io_id, timer_id;
1225 struct test_data d = { 0, NULL, {
1229 { get_rsp_last, sizeof(get_rsp_last) } }, {
1230 { get_req_last, sizeof(get_req_last) },
1231 { get_req_last, sizeof(get_req_last) },
1232 { get_req_last, sizeof(get_req_last) } } };
1234 create_endpoints(&obex, &io, SOCK_STREAM);
1236 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
1237 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
1239 d.mainloop = g_main_loop_new(NULL, FALSE);
1241 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
1243 g_obex_add_request_function(obex, G_OBEX_OP_GET, handle_get_seq, &d);
1245 g_io_channel_write_chars(io, (char *) get_req_first,
1246 sizeof(get_req_first), NULL, &d.err);
1247 g_assert_no_error(d.err);
1249 g_main_loop_run(d.mainloop);
1251 g_assert_cmpuint(d.count, ==, RANDOM_PACKETS - 1);
1253 g_main_loop_unref(d.mainloop);
1255 g_source_remove(timer_id);
1256 g_io_channel_unref(io);
1257 g_source_remove(io_id);
1260 g_assert_no_error(d.err);
1263 static void test_packet_get_rsp(void)
1267 guint io_id, timer_id;
1269 struct test_data d = { 0, NULL, {
1273 { get_rsp_last, sizeof(get_rsp_last) } }, {
1276 { get_req_last, sizeof(get_req_last) } } };
1278 create_endpoints(&obex, &io, SOCK_SEQPACKET);
1280 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
1281 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
1283 d.mainloop = g_main_loop_new(NULL, FALSE);
1285 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
1287 g_obex_add_request_function(obex, G_OBEX_OP_GET, handle_get_seq, &d);
1289 g_io_channel_write_chars(io, (char *) get_req_first_srm,
1290 sizeof(get_req_first_srm), NULL,
1292 g_assert_no_error(d.err);
1294 g_main_loop_run(d.mainloop);
1296 g_assert_cmpuint(d.count, ==, RANDOM_PACKETS - 1);
1298 g_main_loop_unref(d.mainloop);
1300 g_source_remove(timer_id);
1301 g_io_channel_unref(io);
1302 g_source_remove(io_id);
1305 g_assert_no_error(d.err);
1308 static void handle_get_seq_srm_wait(GObex *obex, GObexPacket *req,
1311 struct test_data *d = user_data;
1312 guint8 op = g_obex_packet_get_operation(req, NULL);
1315 if (op != G_OBEX_OP_GET) {
1316 d->err = g_error_new(TEST_ERROR, TEST_ERROR_UNEXPECTED,
1317 "Unexpected opcode 0x%02x", op);
1318 g_main_loop_quit(d->mainloop);
1322 id = g_obex_get_rsp(obex, provide_seq, transfer_complete, d,
1324 G_OBEX_HDR_SRMP, G_OBEX_SRMP_WAIT,
1325 G_OBEX_HDR_INVALID);
1327 g_main_loop_quit(d->mainloop);
1330 static void test_packet_get_rsp_wait(void)
1334 guint io_id, timer_id;
1336 struct test_data d = { 0, NULL, {
1340 { get_rsp_last, sizeof(get_rsp_last) } }, {
1341 { get_req_last, sizeof(get_req_last) },
1343 { get_req_last, sizeof(get_req_last) } } };
1345 create_endpoints(&obex, &io, SOCK_SEQPACKET);
1347 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
1348 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
1350 d.mainloop = g_main_loop_new(NULL, FALSE);
1352 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
1354 g_obex_add_request_function(obex, G_OBEX_OP_GET,
1355 handle_get_seq_srm_wait, &d);
1357 g_io_channel_write_chars(io, (char *) get_req_first_srm,
1358 sizeof(get_req_first_srm), NULL,
1360 g_assert_no_error(d.err);
1362 g_main_loop_run(d.mainloop);
1364 g_assert_cmpuint(d.count, ==, RANDOM_PACKETS - 1);
1366 g_main_loop_unref(d.mainloop);
1368 g_source_remove(timer_id);
1369 g_io_channel_unref(io);
1370 g_source_remove(io_id);
1373 g_assert_no_error(d.err);
1376 static void handle_get_app(GObex *obex, GObexPacket *req, gpointer user_data)
1378 struct test_data *d = user_data;
1379 guint8 op = g_obex_packet_get_operation(req, NULL);
1382 if (op != G_OBEX_OP_GET) {
1383 d->err = g_error_new(TEST_ERROR, TEST_ERROR_UNEXPECTED,
1384 "Unexpected opcode 0x%02x", op);
1385 g_main_loop_quit(d->mainloop);
1389 g_obex_add_request_function(d->obex, G_OBEX_OP_GET, handle_get, d);
1391 rsp = g_obex_packet_new(G_OBEX_RSP_CONTINUE, TRUE,
1392 G_OBEX_HDR_APPARAM, hdr_app, sizeof(hdr_app),
1393 G_OBEX_HDR_INVALID);
1395 if (g_obex_send(d->obex, rsp, NULL) == FALSE)
1396 g_main_loop_quit(d->mainloop);
1399 static void test_get_rsp_app(void)
1403 guint io_id, timer_id;
1405 struct test_data d = { 0, NULL, {
1406 { get_rsp_first_app, sizeof(get_rsp_first_app) },
1407 { get_rsp_first, sizeof(get_rsp_first) },
1408 { get_rsp_last, sizeof(get_rsp_last) } }, {
1409 { get_req_first, sizeof(get_req_first) },
1410 { get_req_last, sizeof(get_req_last) },
1413 create_endpoints(&obex, &io, SOCK_STREAM);
1416 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
1417 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
1419 d.mainloop = g_main_loop_new(NULL, FALSE);
1421 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
1423 g_obex_add_request_function(obex, G_OBEX_OP_GET, handle_get_app, &d);
1425 g_io_channel_write_chars(io, (char *) get_req_first_app,
1426 sizeof(get_req_first_app), NULL, &d.err);
1427 g_assert_no_error(d.err);
1429 g_main_loop_run(d.mainloop);
1431 g_assert_cmpuint(d.count, ==, 2);
1433 g_main_loop_unref(d.mainloop);
1435 g_source_remove(timer_id);
1436 g_io_channel_unref(io);
1437 g_source_remove(io_id);
1440 g_assert_no_error(d.err);
1443 static void test_put_req_delay(void)
1447 guint io_id, timer_id;
1449 struct test_data d = { 0, NULL, {
1450 { put_req_first, sizeof(put_req_first) },
1451 { put_req_last, sizeof(put_req_last) } }, {
1452 { put_rsp_first, sizeof(put_rsp_first) },
1453 { put_rsp_last, sizeof(put_rsp_last) } } };
1455 create_endpoints(&obex, &io, SOCK_STREAM);
1457 d.provide_delay = 200;
1459 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
1460 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
1462 d.mainloop = g_main_loop_new(NULL, FALSE);
1464 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
1466 g_obex_put_req(obex, provide_data, transfer_complete, &d, &d.err,
1467 G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
1468 G_OBEX_HDR_NAME, "file.txt",
1469 G_OBEX_HDR_INVALID);
1470 g_assert_no_error(d.err);
1472 g_main_loop_run(d.mainloop);
1474 g_assert_cmpuint(d.count, ==, 2);
1476 g_main_loop_unref(d.mainloop);
1478 g_source_remove(timer_id);
1479 g_io_channel_unref(io);
1480 g_source_remove(io_id);
1483 g_assert_no_error(d.err);
1486 static void test_get_rsp_delay(void)
1490 guint io_id, timer_id;
1492 struct test_data d = { 0, NULL, {
1493 { get_rsp_first, sizeof(get_rsp_first) },
1494 { get_rsp_last, sizeof(get_rsp_last) } }, {
1495 { get_req_last, sizeof(get_req_last) },
1498 create_endpoints(&obex, &io, SOCK_STREAM);
1500 d.provide_delay = 200;
1502 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
1503 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
1505 d.mainloop = g_main_loop_new(NULL, FALSE);
1507 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
1509 g_obex_add_request_function(obex, G_OBEX_OP_GET, handle_get, &d);
1511 g_io_channel_write_chars(io, (char *) get_req_first,
1512 sizeof(get_req_first), NULL, &d.err);
1513 g_assert_no_error(d.err);
1515 g_main_loop_run(d.mainloop);
1517 g_assert_cmpuint(d.count, ==, 1);
1519 g_main_loop_unref(d.mainloop);
1521 g_source_remove(timer_id);
1522 g_io_channel_unref(io);
1523 g_source_remove(io_id);
1526 g_assert_no_error(d.err);
1529 static gboolean rcv_data_delay(const void *buf, gsize len, gpointer user_data)
1531 struct test_data *d = user_data;
1533 if (len != sizeof(body_data))
1534 d->err = g_error_new(TEST_ERROR, TEST_ERROR_UNEXPECTED,
1535 "Unexpected byte count %zu", len);
1537 if (memcmp(buf, body_data, sizeof(body_data)) != 0) {
1538 dump_bufs(body_data, sizeof(body_data), buf, len);
1539 d->err = g_error_new(TEST_ERROR, TEST_ERROR_UNEXPECTED,
1540 "Unexpected byte count %zu", len);
1543 if (d->provide_delay > 0) {
1544 g_obex_suspend(d->obex);
1545 g_timeout_add(d->provide_delay, resume_obex, d->obex);
1551 static void handle_put_delay(GObex *obex, GObexPacket *req, gpointer user_data)
1553 struct test_data *d = user_data;
1554 guint8 op = g_obex_packet_get_operation(req, NULL);
1557 if (op != G_OBEX_OP_PUT) {
1558 d->err = g_error_new(TEST_ERROR, TEST_ERROR_UNEXPECTED,
1559 "Unexpected opcode 0x%02x", op);
1560 g_main_loop_quit(d->mainloop);
1564 id = g_obex_put_rsp(obex, req, rcv_data_delay, transfer_complete, d,
1565 &d->err, G_OBEX_HDR_INVALID);
1567 g_main_loop_quit(d->mainloop);
1570 static void test_put_rsp_delay(void)
1574 guint io_id, timer_id;
1576 struct test_data d = { 0, NULL, {
1577 { put_rsp_first, sizeof(put_rsp_first) },
1578 { put_rsp_last, sizeof(put_rsp_last) } }, {
1579 { put_req_last, sizeof(put_req_last) },
1582 create_endpoints(&obex, &io, SOCK_STREAM);
1584 d.provide_delay = 200;
1586 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
1587 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
1589 d.mainloop = g_main_loop_new(NULL, FALSE);
1591 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
1593 g_obex_add_request_function(obex, G_OBEX_OP_PUT, handle_put_delay, &d);
1595 g_io_channel_write_chars(io, (char *) put_req_first,
1596 sizeof(put_req_first), NULL, &d.err);
1597 g_assert_no_error(d.err);
1599 g_main_loop_run(d.mainloop);
1601 g_assert_cmpuint(d.count, ==, 1);
1603 g_main_loop_unref(d.mainloop);
1605 g_source_remove(timer_id);
1606 g_io_channel_unref(io);
1607 g_source_remove(io_id);
1610 g_assert_no_error(d.err);
1613 static void test_get_req_delay(void)
1617 guint io_id, timer_id;
1619 struct test_data d = { 0, NULL, {
1620 { get_req_first, sizeof(get_req_first) },
1621 { get_req_last, sizeof(get_req_last) } }, {
1622 { get_rsp_first, sizeof(get_rsp_first) },
1623 { get_rsp_last, sizeof(get_rsp_last) } } };
1625 create_endpoints(&obex, &io, SOCK_STREAM);
1627 d.provide_delay = 200;
1629 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
1630 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
1632 d.mainloop = g_main_loop_new(NULL, FALSE);
1634 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
1636 g_obex_get_req(obex, rcv_data_delay, transfer_complete, &d, &d.err,
1637 G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
1638 G_OBEX_HDR_NAME, "file.txt",
1639 G_OBEX_HDR_INVALID);
1640 g_assert_no_error(d.err);
1642 g_main_loop_run(d.mainloop);
1644 g_assert_cmpuint(d.count, ==, 2);
1646 g_main_loop_unref(d.mainloop);
1648 g_source_remove(timer_id);
1649 g_io_channel_unref(io);
1650 g_source_remove(io_id);
1653 g_assert_no_error(d.err);
1656 static void test_get_rsp_eagain(void)
1660 guint io_id, timer_id;
1662 struct test_data d = { 0, NULL, {
1663 { get_rsp_first, sizeof(get_rsp_first) },
1664 { get_rsp_last, sizeof(get_rsp_last) } }, {
1665 { get_req_last, sizeof(get_req_last) },
1668 create_endpoints(&obex, &io, SOCK_STREAM);
1670 d.provide_delay = 200;
1672 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
1673 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
1675 d.mainloop = g_main_loop_new(NULL, FALSE);
1677 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
1679 g_obex_add_request_function(obex, G_OBEX_OP_GET, handle_get_eagain,
1682 g_io_channel_write_chars(io, (char *) get_req_first,
1683 sizeof(get_req_first), NULL, &d.err);
1684 g_assert_no_error(d.err);
1686 g_main_loop_run(d.mainloop);
1688 g_assert_cmpuint(d.count, ==, 1);
1690 g_main_loop_unref(d.mainloop);
1692 g_source_remove(timer_id);
1693 g_io_channel_unref(io);
1694 g_source_remove(io_id);
1697 g_assert_no_error(d.err);
1700 static void conn_complete(GObex *obex, GError *err, GObexPacket *rsp,
1703 struct test_data *d = user_data;
1706 d->err = g_error_copy(err);
1708 g_main_loop_quit(d->mainloop);
1711 static void test_conn_req(void)
1715 guint io_id, timer_id;
1717 struct test_data d = { 0, NULL, {
1718 { conn_req, sizeof(conn_req) } }, {
1719 { conn_rsp, sizeof(conn_rsp) } } };
1721 create_endpoints(&obex, &io, SOCK_STREAM);
1724 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
1725 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
1727 d.mainloop = g_main_loop_new(NULL, FALSE);
1729 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
1731 g_obex_connect(obex, conn_complete, &d, &d.err, G_OBEX_HDR_INVALID);
1732 g_assert_no_error(d.err);
1734 g_main_loop_run(d.mainloop);
1736 g_assert_cmpuint(d.count, ==, 1);
1738 g_main_loop_unref(d.mainloop);
1740 g_source_remove(timer_id);
1741 g_io_channel_unref(io);
1742 g_source_remove(io_id);
1745 g_assert_no_error(d.err);
1748 static void handle_conn_rsp(GObex *obex, GObexPacket *req,
1751 struct test_data *d = user_data;
1752 guint8 op = g_obex_packet_get_operation(req, NULL);
1755 if (op != G_OBEX_OP_CONNECT) {
1756 d->err = g_error_new(TEST_ERROR, TEST_ERROR_UNEXPECTED,
1757 "Unexpected opcode 0x%02x", op);
1758 g_main_loop_quit(d->mainloop);
1762 rsp = g_obex_packet_new(G_OBEX_RSP_SUCCESS, TRUE,
1763 G_OBEX_HDR_CONNECTION, 1,
1764 G_OBEX_HDR_INVALID);
1765 g_obex_send(obex, rsp, &d->err);
1768 static void test_conn_rsp(void)
1772 guint io_id, timer_id;
1774 struct test_data d = { 0, NULL, {
1775 { conn_rsp, sizeof(conn_rsp) } }, {
1778 create_endpoints(&obex, &io, SOCK_STREAM);
1781 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
1782 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
1784 d.mainloop = g_main_loop_new(NULL, FALSE);
1786 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
1788 g_obex_add_request_function(obex, G_OBEX_OP_CONNECT,
1789 handle_conn_rsp, &d);
1791 g_io_channel_write_chars(io, (char *) conn_req, sizeof(conn_req),
1793 g_assert_no_error(d.err);
1795 g_main_loop_run(d.mainloop);
1797 g_assert_cmpuint(d.count, ==, 1);
1799 g_main_loop_unref(d.mainloop);
1801 g_source_remove(timer_id);
1802 g_io_channel_unref(io);
1803 g_source_remove(io_id);
1806 g_assert_no_error(d.err);
1809 static void conn_complete_get_req(GObex *obex, GError *err, GObexPacket *rsp,
1812 struct test_data *d = user_data;
1815 d->err = g_error_copy(err);
1816 g_main_loop_quit(d->mainloop);
1819 g_obex_get_req(obex, rcv_data, transfer_complete, d, &d->err,
1820 G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
1821 G_OBEX_HDR_NAME, "file.txt",
1822 G_OBEX_HDR_INVALID);
1825 static void test_conn_get_req(void)
1829 guint io_id, timer_id;
1831 struct test_data d = { 0, NULL, {
1832 { conn_req, sizeof(conn_req) },
1833 { conn_get_req_first, sizeof(conn_get_req_first) },
1834 { get_req_last, sizeof(get_req_last) }}, {
1835 { conn_rsp, sizeof(conn_rsp) } ,
1836 { get_rsp_first, sizeof(get_rsp_first) },
1837 { get_rsp_last, sizeof(get_rsp_last) } } };
1839 create_endpoints(&obex, &io, SOCK_STREAM);
1842 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
1843 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
1845 d.mainloop = g_main_loop_new(NULL, FALSE);
1847 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
1849 g_obex_connect(obex, conn_complete_get_req, &d, &d.err,
1850 G_OBEX_HDR_INVALID);
1851 g_assert_no_error(d.err);
1853 g_main_loop_run(d.mainloop);
1855 g_assert_cmpuint(d.count, ==, 3);
1857 g_main_loop_unref(d.mainloop);
1859 g_source_remove(timer_id);
1860 g_io_channel_unref(io);
1861 g_source_remove(io_id);
1864 g_assert_no_error(d.err);
1867 static void test_conn_get_rsp(void)
1871 guint io_id, timer_id;
1873 struct test_data d = { 0, NULL, {
1874 { conn_rsp, sizeof(conn_rsp) },
1875 { get_rsp_first, sizeof(get_rsp_first) },
1876 { get_rsp_last, sizeof(get_rsp_last) } }, {
1877 { conn_get_req_first, sizeof(conn_get_req_first) },
1878 { get_req_last, sizeof(get_req_last) },
1881 create_endpoints(&obex, &io, SOCK_STREAM);
1884 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
1885 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
1887 d.mainloop = g_main_loop_new(NULL, FALSE);
1889 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
1891 g_obex_add_request_function(obex, G_OBEX_OP_CONNECT,
1892 handle_conn_rsp, &d);
1894 g_obex_add_request_function(obex, G_OBEX_OP_GET,
1897 g_io_channel_write_chars(io, (char *) conn_req, sizeof(conn_req),
1899 g_assert_no_error(d.err);
1901 g_main_loop_run(d.mainloop);
1903 g_assert_cmpuint(d.count, ==, 2);
1905 g_main_loop_unref(d.mainloop);
1907 g_source_remove(timer_id);
1908 g_io_channel_unref(io);
1909 g_source_remove(io_id);
1912 g_assert_no_error(d.err);
1915 static void conn_complete_put_req(GObex *obex, GError *err, GObexPacket *rsp,
1918 struct test_data *d = user_data;
1921 d->err = g_error_copy(err);
1922 g_main_loop_quit(d->mainloop);
1925 g_obex_put_req(obex, provide_data, transfer_complete, d, &d->err,
1926 G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
1927 G_OBEX_HDR_NAME, "file.txt",
1928 G_OBEX_HDR_INVALID);
1931 static void test_conn_put_req(void)
1935 guint io_id, timer_id;
1937 struct test_data d = { 0, NULL, {
1938 { conn_req, sizeof(conn_req) },
1939 { conn_put_req_first, sizeof(conn_put_req_first) },
1940 { put_req_last, sizeof(put_req_last) }}, {
1941 { conn_rsp, sizeof(conn_rsp) } ,
1942 { put_rsp_first, sizeof(put_rsp_first) },
1943 { put_rsp_last, sizeof(put_rsp_last) } } };
1945 create_endpoints(&obex, &io, SOCK_STREAM);
1948 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
1949 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
1951 d.mainloop = g_main_loop_new(NULL, FALSE);
1953 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
1955 g_obex_connect(obex, conn_complete_put_req, &d, &d.err,
1956 G_OBEX_HDR_INVALID);
1957 g_assert_no_error(d.err);
1959 g_main_loop_run(d.mainloop);
1961 g_assert_cmpuint(d.count, ==, 3);
1963 g_main_loop_unref(d.mainloop);
1965 g_source_remove(timer_id);
1966 g_io_channel_unref(io);
1967 g_source_remove(io_id);
1970 g_assert_no_error(d.err);
1973 static void test_conn_put_rsp(void)
1977 guint io_id, timer_id;
1979 struct test_data d = { 0, NULL, {
1980 { conn_rsp, sizeof(conn_rsp) },
1981 { put_rsp_first, sizeof(put_rsp_first) },
1982 { put_rsp_last, sizeof(put_rsp_last) } }, {
1983 { conn_put_req_first, sizeof(conn_put_req_first) },
1984 { put_req_last, sizeof(put_req_last) },
1987 create_endpoints(&obex, &io, SOCK_STREAM);
1990 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
1991 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
1993 d.mainloop = g_main_loop_new(NULL, FALSE);
1995 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
1997 g_obex_add_request_function(obex, G_OBEX_OP_CONNECT,
1998 handle_conn_rsp, &d);
2000 g_obex_add_request_function(obex, G_OBEX_OP_PUT,
2003 g_io_channel_write_chars(io, (char *) conn_req, sizeof(conn_req),
2005 g_assert_no_error(d.err);
2007 g_main_loop_run(d.mainloop);
2009 g_assert_cmpuint(d.count, ==, 2);
2011 g_main_loop_unref(d.mainloop);
2013 g_source_remove(timer_id);
2014 g_io_channel_unref(io);
2015 g_source_remove(io_id);
2018 g_assert_no_error(d.err);
2021 static void test_conn_get_wrg_rsp(void)
2025 guint io_id, timer_id;
2027 struct test_data d = { 0, NULL, {
2028 { conn_rsp, sizeof(conn_rsp) },
2029 { unavailable_rsp, sizeof(unavailable_rsp) } }, {
2030 { conn_get_req_wrg, sizeof(conn_get_req_wrg) },
2033 create_endpoints(&obex, &io, SOCK_STREAM);
2036 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
2037 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
2039 d.mainloop = g_main_loop_new(NULL, FALSE);
2041 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
2043 g_obex_add_request_function(obex, G_OBEX_OP_CONNECT,
2044 handle_conn_rsp, &d);
2046 g_io_channel_write_chars(io, (char *) conn_req, sizeof(conn_req),
2048 g_assert_no_error(d.err);
2050 g_main_loop_run(d.mainloop);
2052 g_assert_cmpuint(d.count, ==, 2);
2054 g_main_loop_unref(d.mainloop);
2056 g_source_remove(timer_id);
2057 g_io_channel_unref(io);
2058 g_source_remove(io_id);
2061 g_assert_no_error(d.err);
2064 static void conn_complete_put_req_seq(GObex *obex, GError *err,
2065 GObexPacket *rsp, gpointer user_data)
2067 struct test_data *d = user_data;
2070 d->err = g_error_copy(err);
2071 g_main_loop_quit(d->mainloop);
2074 g_obex_put_req(obex, provide_seq, transfer_complete, d, &d->err,
2075 G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
2076 G_OBEX_HDR_NAME, "random.bin",
2077 G_OBEX_HDR_INVALID);
2080 static void test_conn_put_req_seq(void)
2084 guint io_id, timer_id;
2086 struct test_data d = { 0, NULL, {
2087 { conn_req, sizeof(conn_req) } ,
2090 { put_req_last, sizeof(put_req_last) } }, {
2091 { conn_rsp, sizeof(conn_rsp) } ,
2092 { put_rsp_first, sizeof(put_rsp_first) },
2093 { put_rsp_first, sizeof(put_rsp_first) },
2094 { put_rsp_last, sizeof(put_rsp_last) } } };
2096 create_endpoints(&obex, &io, SOCK_STREAM);
2099 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
2100 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
2102 d.mainloop = g_main_loop_new(NULL, FALSE);
2104 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
2106 g_obex_connect(obex, conn_complete_put_req_seq, &d, &d.err,
2107 G_OBEX_HDR_INVALID);
2108 g_assert_no_error(d.err);
2110 g_main_loop_run(d.mainloop);
2112 g_assert_cmpuint(d.count, ==, RANDOM_PACKETS);
2114 g_main_loop_unref(d.mainloop);
2116 g_source_remove(timer_id);
2117 g_io_channel_unref(io);
2118 g_source_remove(io_id);
2121 g_assert_no_error(d.err);
2124 static void conn_complete_put_req_seq_srm(GObex *obex, GError *err,
2125 GObexPacket *rsp, gpointer user_data)
2127 struct test_data *d = user_data;
2130 d->err = g_error_copy(err);
2131 g_main_loop_quit(d->mainloop);
2134 g_obex_put_req(obex, provide_seq, transfer_complete, d, &d->err,
2135 G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
2136 G_OBEX_HDR_NAME, "random.bin",
2137 G_OBEX_HDR_INVALID);
2140 static void test_conn_put_req_seq_srm(void)
2144 guint io_id, timer_id;
2146 struct test_data d = { 0, NULL, {
2147 { conn_req_srm, sizeof(conn_req_srm) } ,
2150 { put_req_last, sizeof(put_req_last) } }, {
2151 { conn_rsp_srm, sizeof(conn_rsp_srm) } ,
2154 { put_rsp_last, sizeof(put_rsp_last) } } };
2156 create_endpoints(&obex, &io, SOCK_SEQPACKET);
2159 cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
2160 io_id = g_io_add_watch(io, cond, test_io_cb, &d);
2162 d.mainloop = g_main_loop_new(NULL, FALSE);
2164 timer_id = g_timeout_add_seconds(1, test_timeout, &d);
2166 g_obex_connect(obex, conn_complete_put_req_seq_srm, &d, &d.err,
2167 G_OBEX_HDR_SRM, G_OBEX_SRM_INDICATE,
2168 G_OBEX_HDR_INVALID);
2169 g_assert_no_error(d.err);
2171 g_main_loop_run(d.mainloop);
2173 g_assert_cmpuint(d.count, ==, RANDOM_PACKETS);
2175 g_main_loop_unref(d.mainloop);
2177 g_source_remove(timer_id);
2178 g_io_channel_unref(io);
2179 g_source_remove(io_id);
2182 g_assert_no_error(d.err);
2185 int main(int argc, char *argv[])
2187 g_test_init(&argc, &argv, NULL);
2189 g_test_add_func("/gobex/test_conn_req", test_conn_req);
2190 g_test_add_func("/gobex/test_conn_rsp", test_conn_rsp);
2192 g_test_add_func("/gobex/test_put_req", test_put_req);
2193 g_test_add_func("/gobex/test_put_rsp", test_put_rsp);
2195 g_test_add_func("/gobex/test_get_req", test_get_req);
2196 g_test_add_func("/gobex/test_get_rsp", test_get_rsp);
2198 g_test_add_func("/gobex/test_get_req_app", test_get_req_app);
2199 g_test_add_func("/gobex/test_get_rsp_app", test_get_rsp_app);
2201 g_test_add_func("/gobex/test_put_req_delay", test_put_req_delay);
2202 g_test_add_func("/gobex/test_put_rsp_delay", test_put_rsp_delay);
2204 g_test_add_func("/gobex/test_get_req_delay", test_get_req_delay);
2205 g_test_add_func("/gobex/test_get_rsp_delay", test_get_rsp_delay);
2207 g_test_add_func("/gobex/test_put_req_eagain", test_put_req_eagain);
2208 g_test_add_func("/gobex/test_get_req_eagain", test_get_rsp_eagain);
2210 g_test_add_func("/gobex/test_stream_put_req", test_stream_put_req);
2211 g_test_add_func("/gobex/test_stream_put_rsp", test_stream_put_rsp);
2213 g_test_add_func("/gobex/test_stream_put_req_abort",
2214 test_stream_put_req_abort);
2215 g_test_add_func("/gobex/test_stream_put_rsp_abort",
2216 test_stream_put_rsp_abort);
2218 g_test_add_func("/gobex/test_stream_get_req", test_stream_get_req);
2219 g_test_add_func("/gobex/test_stream_get_rsp", test_stream_get_rsp);
2221 g_test_add_func("/gobex/test_conn_get_req", test_conn_get_req);
2222 g_test_add_func("/gobex/test_conn_get_rsp", test_conn_get_rsp);
2224 g_test_add_func("/gobex/test_conn_put_req", test_conn_put_req);
2225 g_test_add_func("/gobex/test_conn_put_rsp", test_conn_put_rsp);
2227 g_test_add_func("/gobex/test_conn_get_wrg_rsp", test_conn_get_wrg_rsp);
2229 g_test_add_func("/gobex/test_conn_put_req_seq",
2230 test_conn_put_req_seq);
2232 g_test_add_func("/gobex/test_packet_put_req", test_packet_put_req);
2233 g_test_add_func("/gobex/test_packet_put_req_wait",
2234 test_packet_put_req_wait);
2236 g_test_add_func("/gobex/test_packet_put_rsp", test_packet_put_rsp);
2237 g_test_add_func("/gobex/test_packet_put_rsp_wait",
2238 test_packet_put_rsp_wait);
2240 g_test_add_func("/gobex/test_packet_get_rsp", test_packet_get_rsp);
2241 g_test_add_func("/gobex/test_packet_get_rsp_wait",
2242 test_packet_get_rsp_wait);
2244 g_test_add_func("/gobex/test_packet_get_req", test_packet_get_req);
2245 g_test_add_func("/gobex/test_packet_get_req_wait",
2246 test_packet_get_req_wait);
2248 g_test_add_func("/gobex/test_packet_get_req_wait_next",
2249 test_packet_get_req_wait_next);
2251 g_test_add_func("/gobex/test_conn_put_req_seq_srm",
2252 test_conn_put_req_seq_srm);