diff options
author | Johan Hedberg <johan.hedberg@intel.com> | 2011-06-29 14:08:50 +0300 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2012-12-04 22:21:57 +0100 |
commit | a8f0a73b48f19690e00c920774690e8d93c978bf (patch) | |
tree | 927c620473a290ed7f379c5e65489f7298150cb3 /unit/test-gobex-header.c | |
parent | f2b4c7bc5d2b3d789520765425c109259aee20ca (diff) | |
download | bluez-a8f0a73b48f19690e00c920774690e8d93c978bf.tar.gz |
gobex: Add invalid header data decoding tests
Diffstat (limited to 'unit/test-gobex-header.c')
-rw-r--r-- | unit/test-gobex-header.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/unit/test-gobex-header.c b/unit/test-gobex-header.c index 2ac0c4332..d2dd99a40 100644 --- a/unit/test-gobex-header.c +++ b/unit/test-gobex-header.c @@ -35,6 +35,16 @@ static uint8_t hdr_name_umlaut[] = { G_OBEX_HDR_ID_NAME, 0x00, 0x0b, static uint8_t hdr_body[] = { G_OBEX_HDR_ID_BODY, 0x00, 0x07, 1, 2, 3, 4 }; static uint8_t hdr_actionid[] = { G_OBEX_HDR_ID_ACTION, 0xab }; +static uint8_t hdr_uint32_nval[] = { G_OBEX_HDR_ID_CONNECTION, 1, 2 }; +static uint8_t hdr_unicode_nval_short[] = { G_OBEX_HDR_ID_NAME, 0x12, 0x34, + 0x00, 'a', 0x00, 'b', + 0x00, 0x00 }; +static uint8_t hdr_unicode_nval_data[] = { G_OBEX_HDR_ID_NAME, 0x00, 0x01, + 0x00, 'a', 0x00, 'b' }; +static uint8_t hdr_bytes_nval_short[] = { G_OBEX_HDR_ID_BODY, 0xab, 0xcd, + 0x01, 0x02, 0x03 }; +static uint8_t hdr_bytes_nval_data[] = { G_OBEX_HDR_ID_BODY, 0xab }; + static void test_header_name_ascii(void) { GObexHeader *header; @@ -310,6 +320,46 @@ static void test_decode_header_actionid(void) g_obex_header_free(header); } +static void decode_header_nval(uint8_t *buf, size_t len) +{ + GObexHeader *header; + size_t parsed; + GError *err = NULL; + + header = g_obex_header_decode(buf, len, G_OBEX_DATA_REF, &parsed, + &err); + g_assert_error(err, G_OBEX_ERROR, G_OBEX_ERROR_PARSE_ERROR); + g_assert(header == NULL); + g_error_free(err); +} + +static void test_decode_header_uint32_nval(void) +{ + decode_header_nval(hdr_uint32_nval, sizeof(hdr_uint32_nval)); +} + +static void test_decode_header_unicode_nval_short(void) +{ + decode_header_nval(hdr_unicode_nval_short, + sizeof(hdr_unicode_nval_short)); +} + +static void test_decode_header_unicode_nval_data(void) +{ + decode_header_nval(hdr_unicode_nval_data, + sizeof(hdr_unicode_nval_data)); +} + +static void test_decode_header_bytes_nval_short(void) +{ + decode_header_nval(hdr_bytes_nval_short, sizeof(hdr_bytes_nval_short)); +} + +static void test_decode_header_bytes_nval_data(void) +{ + decode_header_nval(hdr_bytes_nval_data, sizeof(hdr_bytes_nval_data)); +} + static void test_decode_header_multi(void) { GObexHeader *header; @@ -377,6 +427,17 @@ int main(int argc, char *argv[]) g_test_add_func("/gobex/test_decode_header_multi", test_decode_header_multi); + g_test_add_func("/gobex/test_decode_header_uint32_nval", + test_decode_header_uint32_nval); + g_test_add_func("/gobex/test_decode_header_unicode_nval_short", + test_decode_header_unicode_nval_short); + g_test_add_func("/gobex/test_decode_header_unicode_nval_data", + test_decode_header_unicode_nval_data); + g_test_add_func("/gobex/test_decode_header_bytes_nval_short", + test_decode_header_bytes_nval_short); + g_test_add_func("/gobex/test_decode_header_bytes_nval_data", + test_decode_header_bytes_nval_data); + g_test_add_func("/gobex/test_header_encode_connid", test_header_encode_connid); g_test_add_func("/gobex/test_header_encode_name_ascii", |