Fix copy: More map tests
@@ -404,6 +404,23 @@ static void test_map_add_failure(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
+static void test_map_second_key_failure(void **_CBOR_UNUSED(_state)) {
+ item = cbor_new_indefinite_map();
+ assert_true(
+ cbor_map_add(item, (struct cbor_pair){cbor_move(cbor_build_uint8(42)),
+ cbor_move(cbor_build_bool(true))}));
+ assert_true(cbor_map_add(
+ item, (struct cbor_pair){cbor_move(cbor_build_uint8(43)),
+ cbor_move(cbor_build_bool(false))}));
+
+ WITH_MOCK_MALLOC({ assert_null(cbor_copy(item)); }, 5,
+ // New map, key copy, value copy, add, second key copy
+ MALLOC, MALLOC, MALLOC, REALLOC, MALLOC_FAIL);
+ assert_int_equal(cbor_refcount(item), 1);
+
+ cbor_decref(&item);
+}
+
// }
int main(void) {
@@ -438,9 +455,7 @@ int main(void) {
cmocka_unit_test(test_map_key_alloc_failure),
cmocka_unit_test(test_map_value_alloc_failure),
cmocka_unit_test(test_map_add_failure),
- // cmocka_unit_test(),
- // cmocka_unit_test(),
- // cmocka_unit_test(),
+ cmocka_unit_test(test_map_second_key_failure),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}
