aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2012-10-18 19:45:28 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2012-10-18 19:45:28 +0300
commitdcab39a41c0a403db38860c22426075e6ae9f25d (patch)
tree7f1824628371ec59353b0765a209e6e5518401f7 /tests
parent900c8dd1252afe2b2474b852ae48dcb46e100505 (diff)
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
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile3
-rw-r--r--tests/person_with_extra_field.pbbin0 -> 90 bytes
-rw-r--r--tests/person_with_extra_field.txt3
-rw-r--r--tests/test_decode2.c7
4 files changed, 6 insertions, 7 deletions
diff --git a/tests/Makefile b/tests/Makefile
index 9b02817..73efbe6 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 0000000..00d153c
--- /dev/null
+++ b/tests/person_with_extra_field.pb
Binary files differ
diff --git a/tests/person_with_extra_field.txt b/tests/person_with_extra_field.txt
new file mode 100644
index 0000000..fae9f87
--- /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 762b2b3..2142977 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))