Fuzztest: test extensions
diff --git a/tests/alltypes/alltypes.proto b/tests/alltypes/alltypes.proto
index 93016e6..de0e26a 100644
--- a/tests/alltypes/alltypes.proto
+++ b/tests/alltypes/alltypes.proto
@@ -134,3 +134,9 @@
extensions 200 to 255;
}
+message TestExtension {
+ extend AllTypes {
+ optional TestExtension testextension = 250;
+ }
+ optional string strval = 1;
+}
diff --git a/tests/fuzztest/alltypes_static.options b/tests/fuzztest/alltypes_static.options
index 6b99ae2..c16bfd5 100644
--- a/tests/fuzztest/alltypes_static.options
+++ b/tests/fuzztest/alltypes_static.options
@@ -1,6 +1,5 @@
* max_size:32
* max_count:8
-*.extensions type:FT_IGNORE
*.*fbytes fixed_length:true max_size:4
*.*farray fixed_count:true max_count:5
*.DescriptorSize8 descriptorsize:DS_8
diff --git a/tests/fuzztest/fuzztest.c b/tests/fuzztest/fuzztest.c
index 20018a6..00fd76c 100644
--- a/tests/fuzztest/fuzztest.c
+++ b/tests/fuzztest/fuzztest.c
@@ -68,6 +68,23 @@
uint8_t *buf3 = malloc_with_check(g_bufsize);
size_t msglen2, msglen3;
void *msg = malloc_with_check(structsize);
+
+ /* For proto2 types, we also test extension fields */
+ alltypes_static_TestExtension extmsg = alltypes_static_TestExtension_init_zero;
+ pb_extension_t ext = pb_extension_init_zero;
+ pb_extension_t **ext_field = NULL;
+ ext.type = &alltypes_static_TestExtension_testextension;
+ ext.dest = &extmsg;
+ ext.next = NULL;
+
+ if (msgtype == alltypes_static_AllTypes_fields)
+ {
+ ext_field = &((alltypes_static_AllTypes*)msg)->extensions;
+ }
+ else if (msgtype == alltypes_pointer_AllTypes_fields)
+ {
+ ext_field = &((alltypes_pointer_AllTypes*)msg)->extensions;
+ }
/* Decode and encode the input data.
* This will bring it into canonical format.
@@ -75,6 +92,7 @@
{
pb_istream_t stream = pb_istream_from_buffer(buffer, msglen);
memset(msg, 0, structsize);
+ if (ext_field) *ext_field = &ext;
status = pb_decode(&stream, msgtype, msg);
if (!status) fprintf(stderr, "pb_decode: %s\n", PB_GET_ERROR(&stream));
assert(status);
@@ -96,6 +114,7 @@
{
pb_istream_t stream = pb_istream_from_buffer(buf2, msglen2);
memset(msg, 0, structsize);
+ if (ext_field) *ext_field = &ext;
status = pb_decode(&stream, msgtype, msg);
if (!status) fprintf(stderr, "pb_decode: %s\n", PB_GET_ERROR(&stream));
assert(status);
@@ -182,6 +201,8 @@
while (rand_int(0, 7))
rand_mess((uint8_t*)msg, sizeof(alltypes_static_AllTypes));
+ msg->extensions = NULL;
+
stream = pb_ostream_from_buffer(buffer, g_bufsize);
status = pb_encode(&stream, alltypes_static_AllTypes_fields, msg);
assert(stream.bytes_written <= g_bufsize);