diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2017-03-02 22:40:15 +0200 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2017-03-02 22:40:15 +0200 |
commit | 102a1aaa1474130e0921f9e69c9b3949eb0954ad (patch) | |
tree | e109a229e7475a6d5d16bc1d8f1519b0e501a95c /tests | |
parent | 6ea1047a7f868796621f1ec9f7324f101e135733 (diff) |
Fix alltypes_callback testcase
The test case was erroneously comparing whole submsg structures,
which could result in false errors when padding bytes differed.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/alltypes_callback/alltypes.options | 1 | ||||
-rw-r--r-- | tests/alltypes_callback/decode_alltypes_callback.c | 17 | ||||
-rw-r--r-- | tests/alltypes_proto3_callback/alltypes.options | 1 | ||||
-rw-r--r-- | tests/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 f01cc9d5..74d7a9c0 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 2cdffafa..576ce307 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 f01cc9d5..74d7a9c0 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 17e7f122..2b3c2f32 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; } |