diff options
author | Johan Hedberg <johan.hedberg@intel.com> | 2011-06-30 22:57:51 +0300 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2012-12-04 22:21:58 +0100 |
commit | ad811dd51eaee735446d7b53a37cdc1c3d029717 (patch) | |
tree | d34ac4cc8fd5f2df4db7ed5ed3cf08584f5fe316 /unit/test-gobex-header.c | |
parent | a14e52b4712a0457fe79e41608f876f77b04f3c1 (diff) | |
download | bluez-ad811dd51eaee735446d7b53a37cdc1c3d029717.tar.gz |
gobex: Add support for on-demand headers
Diffstat (limited to 'unit/test-gobex-header.c')
-rw-r--r-- | unit/test-gobex-header.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/unit/test-gobex-header.c b/unit/test-gobex-header.c index d2dd99a40..61536e268 100644 --- a/unit/test-gobex-header.c +++ b/unit/test-gobex-header.c @@ -20,6 +20,7 @@ */ #include <stdint.h> +#include <string.h> #include <gobex/gobex-header.h> @@ -129,6 +130,32 @@ static void test_header_uint32(void) g_obex_header_free(header); } +static guint16 get_body_data(GObexHeader *header, void *buf, gsize len, + gpointer user_data) +{ + uint8_t body_data[] = { 1, 2, 3, 4 }; + + memcpy(buf, body_data, sizeof(body_data)); + + return sizeof(body_data); +} + +static void test_header_on_demand(void) +{ + GObexHeader *header; + uint8_t buf[1024]; + size_t len; + + header = g_obex_header_new_on_demand(G_OBEX_HDR_ID_BODY, + get_body_data, NULL); + + len = g_obex_header_encode(header, buf, sizeof(buf)); + + assert_memequal(hdr_body, sizeof(hdr_body), buf, len); + + g_obex_header_free(header); +} + static GObexHeader *parse_and_encode(uint8_t *buf, size_t buf_len) { GObexHeader *header; @@ -457,6 +484,8 @@ int main(int argc, char *argv[]) g_test_add_func("/gobex/test_header_uint8", test_header_uint8); g_test_add_func("/gobex/test_header_uint32", test_header_uint32); + g_test_add_func("/gobex/test_header_on_demand", test_header_on_demand); + g_test_run(); return 0; |