From 102a1aaa1474130e0921f9e69c9b3949eb0954ad Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Thu, 2 Mar 2017 22:40:15 +0200 Subject: Fix alltypes_callback testcase The test case was erroneously comparing whole submsg structures, which could result in false errors when padding bytes differed. --- tests/alltypes_callback/alltypes.options | 1 - tests/alltypes_callback/decode_alltypes_callback.c | 17 +++++++++++++---- tests/alltypes_proto3_callback/alltypes.options | 1 - .../alltypes_proto3_callback/decode_alltypes_callback.c | 15 +++++++++++---- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/tests/alltypes_callback/alltypes.options b/tests/alltypes_callback/alltypes.options index f01cc9d..74d7a9c 100644 --- a/tests/alltypes_callback/alltypes.options +++ b/tests/alltypes_callback/alltypes.options @@ -2,7 +2,6 @@ AllTypes.* type:FT_CALLBACK SubMessage.substuff1 max_size:16 AllTypes.oneof no_unions:true -* packed: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 2cdffaf..576ce30 100644 --- a/tests/alltypes_callback/decode_alltypes_callback.c +++ b/tests/alltypes_callback/decode_alltypes_callback.c @@ -70,11 +70,15 @@ static bool read_string(pb_istream_t *stream, const pb_field_t *field, void **ar static bool read_submsg(pb_istream_t *stream, const pb_field_t *field, void **arg) { SubMessage submsg = {""}; + SubMessage *ref = *arg; if (!pb_decode(stream, SubMessage_fields, &submsg)) return false; - TEST(memcmp(&submsg, *arg, sizeof(submsg)) == 0); + TEST(strcmp(submsg.substuff1, ref->substuff1) == 0); + TEST(submsg.substuff2 == ref->substuff2); + TEST(submsg.has_substuff3 == ref->has_substuff3); + TEST(submsg.substuff3 == ref->substuff3); return true; } @@ -144,11 +148,16 @@ static bool read_repeated_string(pb_istream_t *stream, const pb_field_t *field, static bool read_repeated_submsg(pb_istream_t *stream, const pb_field_t *field, void **arg) { SubMessage** expected = (SubMessage**)arg; - SubMessage decoded = {""}; - if (!pb_decode(stream, SubMessage_fields, &decoded)) + SubMessage submsg = {""}; + if (!pb_decode(stream, SubMessage_fields, &submsg)) return false; - TEST(memcmp((*expected)++, &decoded, sizeof(decoded)) == 0); + TEST(strcmp(submsg.substuff1, (*expected)->substuff1) == 0); + TEST(submsg.substuff2 == (*expected)->substuff2); + TEST(submsg.has_substuff3 == (*expected)->has_substuff3); + TEST(submsg.substuff3 == (*expected)->substuff3); + (*expected)++; + return true; } diff --git a/tests/alltypes_proto3_callback/alltypes.options b/tests/alltypes_proto3_callback/alltypes.options index f01cc9d..74d7a9c 100644 --- a/tests/alltypes_proto3_callback/alltypes.options +++ b/tests/alltypes_proto3_callback/alltypes.options @@ -2,7 +2,6 @@ AllTypes.* type:FT_CALLBACK SubMessage.substuff1 max_size:16 AllTypes.oneof no_unions:true -* packed:true # With FT_CALLBACK, these options should get ignored *.*fbytes fixed_length:true max_size:4 diff --git a/tests/alltypes_proto3_callback/decode_alltypes_callback.c b/tests/alltypes_proto3_callback/decode_alltypes_callback.c index 17e7f12..2b3c2f3 100644 --- a/tests/alltypes_proto3_callback/decode_alltypes_callback.c +++ b/tests/alltypes_proto3_callback/decode_alltypes_callback.c @@ -70,11 +70,14 @@ static bool read_string(pb_istream_t *stream, const pb_field_t *field, void **ar static bool read_submsg(pb_istream_t *stream, const pb_field_t *field, void **arg) { SubMessage submsg = {""}; + SubMessage *ref = *arg; if (!pb_decode(stream, SubMessage_fields, &submsg)) return false; - TEST(memcmp(&submsg, *arg, sizeof(submsg)) == 0); + TEST(strcmp(submsg.substuff1, ref->substuff1) == 0); + TEST(submsg.substuff2 == ref->substuff2); + TEST(submsg.substuff3 == ref->substuff3); return true; } @@ -144,11 +147,15 @@ static bool read_repeated_string(pb_istream_t *stream, const pb_field_t *field, static bool read_repeated_submsg(pb_istream_t *stream, const pb_field_t *field, void **arg) { SubMessage** expected = (SubMessage**)arg; - SubMessage decoded = {""}; - if (!pb_decode(stream, SubMessage_fields, &decoded)) + SubMessage submsg = {""}; + if (!pb_decode(stream, SubMessage_fields, &submsg)) return false; - TEST(memcmp((*expected)++, &decoded, sizeof(decoded)) == 0); + TEST(strcmp(submsg.substuff1, (*expected)->substuff1) == 0); + TEST(submsg.substuff2 == (*expected)->substuff2); + TEST(submsg.substuff3 == (*expected)->substuff3); + (*expected)++; + return true; } -- cgit 1.2.3-korg