Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion test/map_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,24 @@ static void test_indef_map_decode(void** _state _CBOR_UNUSED) {
map = cbor_load(test_indef_map, 6, &res);

assert_null(map);
assert_size_equal(res.error.code, CBOR_ERR_MEMERROR);
assert_int_equal(res.error.code, CBOR_ERR_MEMERROR);
},
4, MALLOC, MALLOC, MALLOC, REALLOC_FAIL);
}

// The value in the third pair is missing, 0xFF instead.
static unsigned char test_break_in_def_map[] = {0xA3, 0x30, 0x30, 0x30,
0x30, 0x00, 0xFF};
static void test_break_in_def_map_decode(void** _state _CBOR_UNUSED) {
cbor_item_t* map;
struct cbor_load_result res;
map = cbor_load(test_break_in_def_map, 7, &res);

assert_null(map);
assert_int_equal(res.error.code, CBOR_ERR_SYNTAXERROR);
assert_size_equal(res.error.position, 7);
}

int main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_empty_map),
Expand All @@ -265,6 +278,7 @@ int main(void) {
cmocka_unit_test(test_map_creation),
cmocka_unit_test(test_map_add),
cmocka_unit_test(test_indef_map_decode),
cmocka_unit_test(test_break_in_def_map_decode),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}