From dcab39a41c0a403db38860c22426075e6ae9f25d Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Thu, 18 Oct 2012 19:45:28 +0300 Subject: Remove the "buf = NULL" => skip requirement from pb_istream_t callbacks. Rationale: it's easy to implement the callback wrong. Doing so introduces io errors when unknown fields are present in the input. If code is not tested with unknown fields, these bugs can remain hidden for long time. Added a special case for the memory buffer stream, where it gives a small speed benefit. Added testcase for skipping fields with test_decode2 implementation. Update issue 37 Status: FixedInGit --- tests/Makefile | 3 +++ tests/person_with_extra_field.pb | Bin 0 -> 90 bytes tests/person_with_extra_field.txt | 3 +++ tests/test_decode2.c | 7 ------- 4 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 tests/person_with_extra_field.pb create mode 100644 tests/person_with_extra_field.txt (limited to 'tests') diff --git a/tests/Makefile b/tests/Makefile index 9b02817f..73efbe63 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -70,6 +70,9 @@ run_unittests: decode_unittests encode_unittests test_cxxcompile test_encode1 te [ "`./test_encode2 | ./test_decode2`" = \ "`./test_encode2 | protoc --decode=Person -I. -I../generator -I/usr/include person.proto`" ] + [ "`./test_decode2 < person_with_extra_field.pb`" = \ + "`cat person_with_extra_field.txt`" ] + [ "`./test_encode_callbacks | ./test_decode_callbacks`" = \ "`./test_encode_callbacks | protoc --decode=TestMessage callbacks.proto`" ] diff --git a/tests/person_with_extra_field.pb b/tests/person_with_extra_field.pb new file mode 100644 index 00000000..00d153cb Binary files /dev/null and b/tests/person_with_extra_field.pb differ diff --git a/tests/person_with_extra_field.txt b/tests/person_with_extra_field.txt new file mode 100644 index 00000000..fae9f87d --- /dev/null +++ b/tests/person_with_extra_field.txt @@ -0,0 +1,3 @@ +name: "Test Person 99" +id: 99 +email: "test@person.com" diff --git a/tests/test_decode2.c b/tests/test_decode2.c index 762b2b3f..2142977e 100644 --- a/tests/test_decode2.c +++ b/tests/test_decode2.c @@ -59,13 +59,6 @@ bool callback(pb_istream_t *stream, uint8_t *buf, size_t count) FILE *file = (FILE*)stream->state; bool status; - if (buf == NULL) - { - /* Skipping data */ - while (count-- && fgetc(file) != EOF); - return count == 0; - } - status = (fread(buf, 1, count, file) == count); if (feof(file)) -- cgit 1.2.3-korg