Fix alltypes_callback testcase
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>
Thu, 2 Mar 2017 20:40:15 +0000 (22:40 +0200)
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>
Thu, 2 Mar 2017 20:40:15 +0000 (22:40 +0200)
The test case was erroneously comparing whole submsg structures,
which could result in false errors when padding bytes differed.

tests/alltypes_callback/alltypes.options
tests/alltypes_callback/decode_alltypes_callback.c
tests/alltypes_proto3_callback/alltypes.options
tests/alltypes_proto3_callback/decode_alltypes_callback.c

index f01cc9d..74d7a9c 100644 (file)
@@ -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
index 2cdffaf..576ce30 100644 (file)
@@ -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;
 }
 
index f01cc9d..74d7a9c 100644 (file)
@@ -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
index 17e7f12..2b3c2f3 100644 (file)
@@ -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;
 }