summaryrefslogtreecommitdiffstats
path: root/tests/test_encode_callbacks.c
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-04-14 09:26:42 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-04-14 09:26:42 +0300
commit9939910833a9289b5913eff29f951195e7bc61c6 (patch)
tree3455554408cbfec6503f92935732201571c7311f /tests/test_encode_callbacks.c
parent6a022985845a0a50b32b7c1fb22f9aee1f675825 (diff)
Fix bug with empty strings in repeated string callbacks.
Fix suggested by Henrik Carlgren. Added also unit test for the bug. Update issue 73 Status: FixedInGit
Diffstat (limited to 'tests/test_encode_callbacks.c')
-rw-r--r--tests/test_encode_callbacks.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/test_encode_callbacks.c b/tests/test_encode_callbacks.c
index afab48e8..3bb6a45e 100644
--- a/tests/test_encode_callbacks.c
+++ b/tests/test_encode_callbacks.c
@@ -41,6 +41,22 @@ bool encode_fixed64(pb_ostream_t *stream, const pb_field_t *field, void * const
return pb_encode_fixed64(stream, &value);
}
+bool encode_repeatedstring(pb_ostream_t *stream, const pb_field_t *field, void * const *arg)
+{
+ char *str[4] = {"Hello world!", "", "Test", "Test2"};
+ int i;
+
+ for (i = 0; i < 4; i++)
+ {
+ if (!pb_encode_tag_for_field(stream, field))
+ return false;
+
+ if (!pb_encode_string(stream, (uint8_t*)str[i], strlen(str[i])))
+ return false;
+ }
+ return true;
+}
+
int main()
{
uint8_t buffer[1024];
@@ -57,6 +73,8 @@ int main()
testmessage.submsg.int32value.funcs.encode = &encode_int32;
testmessage.submsg.fixed32value.funcs.encode = &encode_fixed32;
testmessage.submsg.fixed64value.funcs.encode = &encode_fixed64;
+
+ testmessage.repeatedstring.funcs.encode = &encode_repeatedstring;
if (!pb_encode(&stream, TestMessage_fields, &testmessage))
return 1;