diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2017-02-24 20:49:36 +0200 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2017-02-24 20:49:36 +0200 |
commit | 599387d2446bc622d27fd13291ad12b365926c49 (patch) | |
tree | c05fbe54fd668b4db77ce68413049fbd61b2a846 /tests | |
parent | 91dcdf573707a823bc450d3913b8b87c7adba212 (diff) |
Add test coverage for calling pb_release() on a message with callback fields.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/alltypes_callback/SConscript | 6 | ||||
-rw-r--r-- | tests/alltypes_callback/decode_alltypes_callback.c | 9 |
2 files changed, 13 insertions, 2 deletions
diff --git a/tests/alltypes_callback/SConscript b/tests/alltypes_callback/SConscript index a241f24e..1cef3972 100644 --- a/tests/alltypes_callback/SConscript +++ b/tests/alltypes_callback/SConscript @@ -1,6 +1,6 @@ # Test the AllTypes encoding & decoding using callbacks for all fields. -Import("env") +Import("env", "malloc_env") c = Copy("$TARGET", "$SOURCE") env.Command("alltypes.proto", "#alltypes/alltypes.proto", c) @@ -21,3 +21,7 @@ env.RunTest("optionals.output", enc, ARGS = ['1']) env.RunTest("optionals.refdecout", [refdec, "optionals.output"], ARGS = ['1']) env.RunTest("optionals.decout", [dec, "optionals.output"], ARGS = ['1']) +# Try with malloc support also +mallocbin = malloc_env.Object("decode_with_malloc.o", "decode_alltypes_callback.c") +mallocdec = malloc_env.Program("decode_with_malloc", [mallocbin, "alltypes.pb.o", "$COMMON/pb_decode_with_malloc.o", "$COMMON/pb_common_with_malloc.o", "$COMMON/malloc_wrappers.o"]) +env.RunTest("decode_with_malloc.output", [mallocdec, "encode_alltypes_callback.output"]) diff --git a/tests/alltypes_callback/decode_alltypes_callback.c b/tests/alltypes_callback/decode_alltypes_callback.c index 4366cf3f..1d8c268c 100644 --- a/tests/alltypes_callback/decode_alltypes_callback.c +++ b/tests/alltypes_callback/decode_alltypes_callback.c @@ -395,7 +395,14 @@ bool check_alltypes(pb_istream_t *stream, int mode) alltypes.oneof_msg1.arg = &oneof_msg1; } - return pb_decode(stream, AllTypes_fields, &alltypes); + bool status = pb_decode(stream, AllTypes_fields, &alltypes); + +#ifdef PB_ENABLE_MALLOC + /* Just to check for any interference between pb_release() and callback fields */ + pb_release(AllTypes_fields, &alltypes); +#endif + + return status; } int main(int argc, char **argv) |