Add test coverage for calling pb_release() on a message with callback fields.
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>
Fri, 24 Feb 2017 18:49:36 +0000 (20:49 +0200)
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>
Fri, 24 Feb 2017 18:49:36 +0000 (20:49 +0200)
tests/alltypes_callback/SConscript
tests/alltypes_callback/decode_alltypes_callback.c

index a241f24..1cef397 100644 (file)
@@ -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"])
index 4366cf3..1d8c268 100644 (file)
@@ -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)