diff options
22 files changed, 80 insertions, 20 deletions
diff --git a/tests/alltypes/alltypes.options b/tests/alltypes/alltypes.options index b31e3cf..0d5ab12 100644 --- a/tests/alltypes/alltypes.options +++ b/tests/alltypes/alltypes.options @@ -1,3 +1,3 @@ * max_size:16 * max_count:5 - +*.*fbytes fixed_length:true max_size:4 diff --git a/tests/alltypes/alltypes.proto b/tests/alltypes/alltypes.proto index 3995c55..b2250c0 100644 --- a/tests/alltypes/alltypes.proto +++ b/tests/alltypes/alltypes.proto @@ -58,7 +58,7 @@ message AllTypes { required SubMessage req_submsg = 16; required MyEnum req_enum = 17; required EmptyMessage req_emptymsg = 18; - + required bytes req_fbytes = 19; repeated int32 rep_int32 = 21 [packed = true]; repeated int64 rep_int64 = 22 [packed = true]; @@ -81,6 +81,7 @@ message AllTypes { repeated SubMessage rep_submsg = 36; repeated MyEnum rep_enum = 37 [packed = true]; repeated EmptyMessage rep_emptymsg = 38; + repeated bytes rep_fbytes = 39; optional int32 opt_int32 = 41 [default = 4041]; optional int64 opt_int64 = 42 [default = 4042]; @@ -103,11 +104,12 @@ message AllTypes { optional SubMessage opt_submsg = 56; optional MyEnum opt_enum = 57 [default = Second]; optional EmptyMessage opt_emptymsg = 58; + optional bytes opt_fbytes = 59 [default = "4059"]; oneof oneof { - SubMessage oneof_msg1 = 59; - EmptyMessage oneof_msg2 = 60; + SubMessage oneof_msg1 = 60; + EmptyMessage oneof_msg2 = 61; } // Check that extreme integer values are handled correctly diff --git a/tests/alltypes/decode_alltypes.c b/tests/alltypes/decode_alltypes.c index 458e511..2e609e5 100644 --- a/tests/alltypes/decode_alltypes.c +++ b/tests/alltypes/decode_alltypes.c @@ -52,6 +52,7 @@ bool check_alltypes(pb_istream_t *stream, int mode) TEST(alltypes.req_submsg.substuff2 == 1016); TEST(alltypes.req_submsg.substuff3 == 3); TEST(alltypes.req_enum == MyEnum_Truth); + TEST(memcmp(alltypes.req_fbytes, "1019", 4) == 0); TEST(alltypes.rep_int32_count == 5 && alltypes.rep_int32[4] == -2001 && alltypes.rep_int32[0] == 0); TEST(alltypes.rep_int64_count == 5 && alltypes.rep_int64[4] == -2002 && alltypes.rep_int64[0] == 0); @@ -80,6 +81,9 @@ bool check_alltypes(pb_istream_t *stream, int mode) TEST(alltypes.rep_enum_count == 5 && alltypes.rep_enum[4] == MyEnum_Truth && alltypes.rep_enum[0] == MyEnum_Zero); TEST(alltypes.rep_emptymsg_count == 5); + TEST(alltypes.rep_fbytes_count == 5); + TEST(alltypes.rep_fbytes[0][0] == 0 && alltypes.rep_fbytes[0][3] == 0); + TEST(memcmp(alltypes.rep_fbytes[4], "2019", 4) == 0); if (mode == 0) { @@ -125,6 +129,8 @@ bool check_alltypes(pb_istream_t *stream, int mode) TEST(alltypes.has_opt_enum == false); TEST(alltypes.opt_enum == MyEnum_Second); TEST(alltypes.has_opt_emptymsg == false); + TEST(alltypes.has_opt_fbytes == false); + TEST(memcmp(alltypes.opt_fbytes, "4059", 4) == 0); TEST(alltypes.which_oneof == 0); } @@ -172,6 +178,8 @@ bool check_alltypes(pb_istream_t *stream, int mode) TEST(alltypes.has_opt_enum == true); TEST(alltypes.opt_enum == MyEnum_Truth); TEST(alltypes.has_opt_emptymsg == true); + TEST(alltypes.has_opt_fbytes == true); + TEST(memcmp(alltypes.opt_fbytes, "3059", 4) == 0); TEST(alltypes.which_oneof == AllTypes_oneof_msg1_tag); TEST(strcmp(alltypes.oneof.oneof_msg1.substuff1, "4059") == 0); diff --git a/tests/alltypes/encode_alltypes.c b/tests/alltypes/encode_alltypes.c index 16f4b29..1b86355 100644 --- a/tests/alltypes/encode_alltypes.c +++ b/tests/alltypes/encode_alltypes.c @@ -37,6 +37,7 @@ int main(int argc, char **argv) strcpy(alltypes.req_submsg.substuff1, "1016"); alltypes.req_submsg.substuff2 = 1016; alltypes.req_enum = MyEnum_Truth; + memcpy(alltypes.req_fbytes, "1019", 4); alltypes.rep_int32_count = 5; alltypes.rep_int32[4] = -2001; alltypes.rep_int64_count = 5; alltypes.rep_int64[4] = -2002; @@ -67,6 +68,9 @@ int main(int argc, char **argv) alltypes.rep_enum_count = 5; alltypes.rep_enum[4] = MyEnum_Truth; alltypes.rep_emptymsg_count = 5; + alltypes.rep_fbytes_count = 5; + memcpy(alltypes.rep_fbytes[4], "2019", 4); + alltypes.req_limits.int32_min = INT32_MIN; alltypes.req_limits.int32_max = INT32_MAX; alltypes.req_limits.uint32_min = 0; @@ -121,6 +125,8 @@ int main(int argc, char **argv) alltypes.has_opt_enum = true; alltypes.opt_enum = MyEnum_Truth; alltypes.has_opt_emptymsg = true; + alltypes.has_opt_fbytes = true; + memcpy(alltypes.opt_fbytes, "3059", 4); alltypes.which_oneof = AllTypes_oneof_msg1_tag; strcpy(alltypes.oneof.oneof_msg1.substuff1, "4059"); diff --git a/tests/alltypes_callback/alltypes.options b/tests/alltypes_callback/alltypes.options index daee522..74d7a9c 100644 --- a/tests/alltypes_callback/alltypes.options +++ b/tests/alltypes_callback/alltypes.options @@ -2,3 +2,7 @@ AllTypes.* type:FT_CALLBACK SubMessage.substuff1 max_size:16 AllTypes.oneof no_unions:true + +# With FT_CALLBACK, these options should get ignored +*.*fbytes fixed_length:true max_size:4 + diff --git a/tests/alltypes_callback/decode_alltypes_callback.c b/tests/alltypes_callback/decode_alltypes_callback.c index c53ab6e..4366cf3 100644 --- a/tests/alltypes_callback/decode_alltypes_callback.c +++ b/tests/alltypes_callback/decode_alltypes_callback.c @@ -218,11 +218,7 @@ bool check_alltypes(pb_istream_t *stream, int mode) SubMessage oneof_msg1 = {"4059", 4059}; /* Bind callbacks for required fields */ - AllTypes alltypes; - - /* Fill with garbage to better detect initialization errors */ - memset(&alltypes, 0xAA, sizeof(alltypes)); - alltypes.extensions = 0; + AllTypes alltypes = AllTypes_init_zero; alltypes.req_int32.funcs.decode = &read_varint; alltypes.req_int32.arg = (void*)-1001; diff --git a/tests/alltypes_callback/encode_alltypes_callback.c b/tests/alltypes_callback/encode_alltypes_callback.c index abc43f5..b206783 100644 --- a/tests/alltypes_callback/encode_alltypes_callback.c +++ b/tests/alltypes_callback/encode_alltypes_callback.c @@ -263,6 +263,9 @@ int main(int argc, char **argv) alltypes.req_emptymsg.funcs.encode = &write_emptymsg; + alltypes.req_fbytes.funcs.encode = &write_string; + alltypes.req_fbytes.arg = "1019"; + /* Bind callbacks for repeated fields */ alltypes.rep_int32.funcs.encode = &write_repeated_varint; alltypes.rep_int32.arg = (void*)-2001; @@ -317,6 +320,9 @@ int main(int argc, char **argv) alltypes.rep_emptymsg.funcs.encode = &write_repeated_emptymsg; + alltypes.rep_fbytes.funcs.encode = &write_repeated_string; + alltypes.rep_fbytes.arg = "2019"; + alltypes.req_limits.funcs.encode = &write_limits; /* Bind callbacks for optional fields */ @@ -375,6 +381,9 @@ int main(int argc, char **argv) alltypes.opt_emptymsg.funcs.encode = &write_emptymsg; + alltypes.opt_fbytes.funcs.encode = &write_string; + alltypes.opt_fbytes.arg = "3059"; + alltypes.oneof_msg1.funcs.encode = &write_submsg; alltypes.oneof_msg1.arg = &oneof_msg1; } diff --git a/tests/alltypes_pointer/alltypes.options b/tests/alltypes_pointer/alltypes.options index 52abeb7..8699fe2 100644 --- a/tests/alltypes_pointer/alltypes.options +++ b/tests/alltypes_pointer/alltypes.options @@ -1,3 +1,4 @@ # Generate all fields as pointers. * type:FT_POINTER +*.*fbytes fixed_length:true max_size:4 diff --git a/tests/alltypes_pointer/decode_alltypes_pointer.c b/tests/alltypes_pointer/decode_alltypes_pointer.c index 1dbb6c5..4ee6f8b 100644 --- a/tests/alltypes_pointer/decode_alltypes_pointer.c +++ b/tests/alltypes_pointer/decode_alltypes_pointer.c @@ -47,7 +47,8 @@ bool check_alltypes(pb_istream_t *stream, int mode) && strcmp(alltypes.req_submsg->substuff1, "1016") == 0); TEST(alltypes.req_submsg && alltypes.req_submsg->substuff2 && *alltypes.req_submsg->substuff2 == 1016); - TEST(*alltypes.req_enum == MyEnum_Truth); + TEST(alltypes.req_enum && *alltypes.req_enum == MyEnum_Truth); + TEST(alltypes.req_fbytes && memcmp(alltypes.req_fbytes, "1019", 4) == 0); TEST(alltypes.rep_int32_count == 5 && alltypes.rep_int32[4] == -2001 && alltypes.rep_int32[0] == 0); TEST(alltypes.rep_int64_count == 5 && alltypes.rep_int64[4] == -2002 && alltypes.rep_int64[0] == 0); @@ -76,6 +77,9 @@ bool check_alltypes(pb_istream_t *stream, int mode) TEST(alltypes.rep_enum_count == 5 && alltypes.rep_enum[4] == MyEnum_Truth && alltypes.rep_enum[0] == MyEnum_Zero); TEST(alltypes.rep_emptymsg_count == 5); + TEST(alltypes.rep_fbytes_count == 5); + TEST(alltypes.rep_fbytes[0][0] == 0 && alltypes.rep_fbytes[0][3] == 0); + TEST(memcmp(alltypes.rep_fbytes[4], "2019", 4) == 0); if (mode == 0) { @@ -99,6 +103,7 @@ bool check_alltypes(pb_istream_t *stream, int mode) TEST(alltypes.opt_bytes == NULL); TEST(alltypes.opt_submsg == NULL); TEST(alltypes.opt_enum == NULL); + TEST(alltypes.opt_fbytes == NULL); TEST(alltypes.which_oneof == 0); } @@ -127,6 +132,7 @@ bool check_alltypes(pb_istream_t *stream, int mode) TEST(alltypes.opt_submsg && *alltypes.opt_submsg->substuff2 == 3056); TEST(alltypes.opt_enum && *alltypes.opt_enum == MyEnum_Truth); TEST(alltypes.opt_emptymsg); + TEST(alltypes.opt_fbytes && memcmp(alltypes.opt_fbytes, "3059", 4) == 0); TEST(alltypes.which_oneof == AllTypes_oneof_msg1_tag); TEST(alltypes.oneof.oneof_msg1 && strcmp(alltypes.oneof.oneof_msg1->substuff1, "4059") == 0); diff --git a/tests/alltypes_pointer/encode_alltypes_pointer.c b/tests/alltypes_pointer/encode_alltypes_pointer.c index 7b52662..a39af6f 100644 --- a/tests/alltypes_pointer/encode_alltypes_pointer.c +++ b/tests/alltypes_pointer/encode_alltypes_pointer.c @@ -32,6 +32,7 @@ int main(int argc, char **argv) SubMessage req_submsg = {"1016", &req_substuff}; MyEnum req_enum = MyEnum_Truth; EmptyMessage req_emptymsg = {0}; + pb_byte_t req_fbytes[4] = {'1', '0', '1', '9'}; int32_t end = 1099; @@ -62,6 +63,7 @@ int main(int argc, char **argv) {"2016", &rep_substuff2, &rep_substuff3}}; MyEnum rep_enum[5] = {0, 0, 0, 0, MyEnum_Truth}; EmptyMessage rep_emptymsg[5] = {{0}, {0}, {0}, {0}, {0}}; + pb_byte_t rep_fbytes[5][4] = {{0}, {0}, {0}, {0}, {'2', '0', '1', '9'}}; /* Values for optional fields */ int32_t opt_int32 = 3041; @@ -83,6 +85,7 @@ int main(int argc, char **argv) SubMessage opt_submsg = {"3056", &opt_substuff}; MyEnum opt_enum = MyEnum_Truth; EmptyMessage opt_emptymsg = {0}; + pb_byte_t opt_fbytes[4] = {'3', '0', '5', '9'}; static int32_t oneof_substuff = 4059; SubMessage oneof_msg1 = {"4059", &oneof_substuff}; @@ -125,6 +128,7 @@ int main(int argc, char **argv) alltypes.req_submsg = &req_submsg; alltypes.req_enum = &req_enum; alltypes.req_emptymsg = &req_emptymsg; + alltypes.req_fbytes = &req_fbytes; alltypes.req_limits = &req_limits; alltypes.rep_int32_count = 5; alltypes.rep_int32 = rep_int32; @@ -145,6 +149,7 @@ int main(int argc, char **argv) alltypes.rep_submsg_count = 5; alltypes.rep_submsg = rep_submsg; alltypes.rep_enum_count = 5; alltypes.rep_enum = rep_enum; alltypes.rep_emptymsg_count = 5; alltypes.rep_emptymsg = rep_emptymsg; + alltypes.rep_fbytes_count = 5; alltypes.rep_fbytes = rep_fbytes; if (mode != 0) { @@ -167,6 +172,7 @@ int main(int argc, char **argv) alltypes.opt_submsg = &opt_submsg; alltypes.opt_enum = &opt_enum; alltypes.opt_emptymsg = &opt_emptymsg; + alltypes.opt_fbytes = &opt_fbytes; alltypes.which_oneof = AllTypes_oneof_msg1_tag; alltypes.oneof.oneof_msg1 = &oneof_msg1; diff --git a/tests/alltypes_proto3/alltypes.options b/tests/alltypes_proto3/alltypes.options index b31e3cf..78dd08d 100644 --- a/tests/alltypes_proto3/alltypes.options +++ b/tests/alltypes_proto3/alltypes.options @@ -1,3 +1,4 @@ * max_size:16 * max_count:5 +*.*fbytes fixed_length:true max_size:4 diff --git a/tests/alltypes_proto3/alltypes.proto b/tests/alltypes_proto3/alltypes.proto index 10b48f2..f66109e 100644 --- a/tests/alltypes_proto3/alltypes.proto +++ b/tests/alltypes_proto3/alltypes.proto @@ -59,6 +59,7 @@ message AllTypes { SubMessage sng_submsg = 16; MyEnum sng_enum = 17; EmptyMessage sng_emptymsg = 18; + bytes sng_fbytes = 19; repeated int32 rep_int32 = 21 [packed = true]; repeated int64 rep_int64 = 22 [packed = true]; @@ -81,6 +82,7 @@ message AllTypes { repeated SubMessage rep_submsg = 36; repeated MyEnum rep_enum = 37 [packed = true]; repeated EmptyMessage rep_emptymsg = 38; + repeated bytes rep_fbytes = 39; oneof oneof { diff --git a/tests/alltypes_proto3/decode_alltypes.c b/tests/alltypes_proto3/decode_alltypes.c index c1b0d52..51c1c41 100644 --- a/tests/alltypes_proto3/decode_alltypes.c +++ b/tests/alltypes_proto3/decode_alltypes.c @@ -55,6 +55,10 @@ bool check_alltypes(pb_istream_t *stream, int mode) TEST(alltypes.rep_enum_count == 5 && alltypes.rep_enum[4] == MyEnum_Truth && alltypes.rep_enum[0] == MyEnum_Zero); TEST(alltypes.rep_emptymsg_count == 5); + TEST(alltypes.rep_fbytes_count == 5); + TEST(alltypes.rep_fbytes[0][0] == 0 && alltypes.rep_fbytes[0][3] == 0); + TEST(memcmp(alltypes.rep_fbytes[4], "2019", 4) == 0); + if (mode == 0) { /* Expect default values */ @@ -80,6 +84,10 @@ bool check_alltypes(pb_istream_t *stream, int mode) TEST(alltypes.sng_submsg.substuff2 == 0); TEST(alltypes.sng_submsg.substuff3 == 0); TEST(alltypes.sng_enum == MyEnum_Zero); + TEST(alltypes.sng_fbytes[0] == 0 && + alltypes.sng_fbytes[1] == 0 && + alltypes.sng_fbytes[2] == 0 && + alltypes.sng_fbytes[3] == 0); TEST(alltypes.which_oneof == 0); } @@ -109,6 +117,7 @@ bool check_alltypes(pb_istream_t *stream, int mode) TEST(alltypes.sng_submsg.substuff2 == 3056); TEST(alltypes.sng_submsg.substuff3 == 0); TEST(alltypes.sng_enum == MyEnum_Truth); + TEST(memcmp(alltypes.sng_fbytes, "3059", 4) == 0); TEST(alltypes.which_oneof == AllTypes_oneof_msg1_tag); TEST(strcmp(alltypes.oneof.oneof_msg1.substuff1, "4059") == 0); diff --git a/tests/alltypes_proto3/encode_alltypes.c b/tests/alltypes_proto3/encode_alltypes.c index e11acd5..1da0668 100644 --- a/tests/alltypes_proto3/encode_alltypes.c +++ b/tests/alltypes_proto3/encode_alltypes.c @@ -43,6 +43,9 @@ int main(int argc, char **argv) alltypes.rep_enum_count = 5; alltypes.rep_enum[4] = MyEnum_Truth; alltypes.rep_emptymsg_count = 5; + alltypes.rep_fbytes_count = 5; + memcpy(alltypes.rep_fbytes[4], "2019", 4); + alltypes.req_limits.int32_min = INT32_MIN; alltypes.req_limits.int32_max = INT32_MAX; alltypes.req_limits.uint32_min = 0; @@ -79,6 +82,7 @@ int main(int argc, char **argv) strcpy(alltypes.sng_submsg.substuff1, "3056"); alltypes.sng_submsg.substuff2 = 3056; alltypes.sng_enum = MyEnum_Truth; + memcpy(alltypes.sng_fbytes, "3059", 4); alltypes.which_oneof = AllTypes_oneof_msg1_tag; strcpy(alltypes.oneof.oneof_msg1.substuff1, "4059"); diff --git a/tests/field_size_16/alltypes.options b/tests/field_size_16/alltypes.options index b31e3cf..78dd08d 100644 --- a/tests/field_size_16/alltypes.options +++ b/tests/field_size_16/alltypes.options @@ -1,3 +1,4 @@ * max_size:16 * max_count:5 +*.*fbytes fixed_length:true max_size:4 diff --git a/tests/field_size_16/alltypes.proto b/tests/field_size_16/alltypes.proto index ba1ec38..46ac46a 100644 --- a/tests/field_size_16/alltypes.proto +++ b/tests/field_size_16/alltypes.proto @@ -57,7 +57,7 @@ message AllTypes { required SubMessage req_submsg = 16; required MyEnum req_enum = 17; required EmptyMessage req_emptymsg = 18; - + required bytes req_fbytes = 19; repeated int32 rep_int32 = 21; repeated int64 rep_int64 = 22; @@ -80,6 +80,7 @@ message AllTypes { repeated SubMessage rep_submsg = 10036; repeated MyEnum rep_enum = 10037; repeated EmptyMessage rep_emptymsg = 10038; + repeated bytes rep_fbytes = 10039; optional int32 opt_int32 = 10041 [default = 4041]; optional int64 opt_int64 = 10042 [default = 4042]; @@ -102,11 +103,12 @@ message AllTypes { optional SubMessage opt_submsg = 10056; optional MyEnum opt_enum = 10057 [default = Second]; optional EmptyMessage opt_emptymsg = 10058; + optional bytes opt_fbytes = 10059 [default = "4059"]; oneof oneof { - SubMessage oneof_msg1 = 10059; - EmptyMessage oneof_msg2 = 10060; + SubMessage oneof_msg1 = 10060; + EmptyMessage oneof_msg2 = 10061; } // Check that extreme integer values are handled correctly diff --git a/tests/field_size_32/alltypes.options b/tests/field_size_32/alltypes.options index b31e3cf..0d5ab12 100644 --- a/tests/field_size_32/alltypes.options +++ b/tests/field_size_32/alltypes.options @@ -1,3 +1,3 @@ * max_size:16 * max_count:5 - +*.*fbytes fixed_length:true max_size:4 diff --git a/tests/field_size_32/alltypes.proto b/tests/field_size_32/alltypes.proto index 02ee1a6..ac76c8e 100644 --- a/tests/field_size_32/alltypes.proto +++ b/tests/field_size_32/alltypes.proto @@ -57,7 +57,7 @@ message AllTypes { required SubMessage req_submsg = 16; required MyEnum req_enum = 17; required EmptyMessage req_emptymsg = 18; - + required bytes req_fbytes = 19; repeated int32 rep_int32 = 21; repeated int64 rep_int64 = 22; @@ -80,6 +80,7 @@ message AllTypes { repeated SubMessage rep_submsg = 10036; repeated MyEnum rep_enum = 10037; repeated EmptyMessage rep_emptymsg = 10038; + repeated bytes rep_fbytes = 10039; optional int32 opt_int32 = 10041 [default = 4041]; optional int64 opt_int64 = 10042 [default = 4042]; @@ -102,11 +103,12 @@ message AllTypes { optional SubMessage opt_submsg = 10056; optional MyEnum opt_enum = 10057 [default = Second]; optional EmptyMessage opt_emptymsg = 10058; + optional bytes opt_fbytes = 10059 [default = "4059"]; oneof oneof { - SubMessage oneof_msg1 = 10059; - EmptyMessage oneof_msg2 = 10060; + SubMessage oneof_msg1 = 10060; + EmptyMessage oneof_msg2 = 10061; } // Check that extreme integer values are handled correctly diff --git a/tests/fuzztest/alltypes_pointer.options b/tests/fuzztest/alltypes_pointer.options index 52abeb7..7e3ad1e 100644 --- a/tests/fuzztest/alltypes_pointer.options +++ b/tests/fuzztest/alltypes_pointer.options @@ -1,3 +1,3 @@ # Generate all fields as pointers. * type:FT_POINTER - +*.*fbytes fixed_length:true max_size:4 diff --git a/tests/fuzztest/alltypes_static.options b/tests/fuzztest/alltypes_static.options index 1c10637..e197e1d 100644 --- a/tests/fuzztest/alltypes_static.options +++ b/tests/fuzztest/alltypes_static.options @@ -1,3 +1,4 @@ * max_size:32 * max_count:8 *.extensions type:FT_IGNORE +*.*fbytes fixed_length:true max_size:4 diff --git a/tests/io_errors/alltypes.options b/tests/io_errors/alltypes.options index b31e3cf..0d5ab12 100644 --- a/tests/io_errors/alltypes.options +++ b/tests/io_errors/alltypes.options @@ -1,3 +1,3 @@ * max_size:16 * max_count:5 - +*.*fbytes fixed_length:true max_size:4 diff --git a/tests/io_errors_pointers/alltypes.options b/tests/io_errors_pointers/alltypes.options index 52abeb7..7e3ad1e 100644 --- a/tests/io_errors_pointers/alltypes.options +++ b/tests/io_errors_pointers/alltypes.options @@ -1,3 +1,3 @@ # Generate all fields as pointers. * type:FT_POINTER - +*.*fbytes fixed_length:true max_size:4 |