summaryrefslogtreecommitdiffstats
path: root/tests/test_decode1.c
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@npb.mail.kapsi.fi>2011-12-30 08:57:27 +0000
committerPetteri Aimonen <jpa@npb.mail.kapsi.fi>2011-12-30 08:57:27 +0000
commita3f5e4d81f8d81e208f33dded6d892fbbdce90bc (patch)
treef68076e4d986d7121d59723befa802af17954d1f /tests/test_decode1.c
parent1506450b119a504259983692cca4c8cd3daddaf1 (diff)
Expanding the tests to better cover decoding from memory buffer.
git-svn-id: https://svn.kapsi.fi/jpa/nanopb@1090 e3a754e5-d11d-0410-8d38-ebb782a927b9
Diffstat (limited to 'tests/test_decode1.c')
-rw-r--r--tests/test_decode1.c31
1 files changed, 7 insertions, 24 deletions
diff --git a/tests/test_decode1.c b/tests/test_decode1.c
index 3b72f664..78781dd4 100644
--- a/tests/test_decode1.c
+++ b/tests/test_decode1.c
@@ -57,33 +57,16 @@ bool print_person(pb_istream_t *stream)
return true;
}
-/* This binds the pb_istream_t to stdin */
-bool callback(pb_istream_t *stream, uint8_t *buf, size_t count)
+int main()
{
- 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);
+ /* Read the data into buffer */
+ uint8_t buffer[512];
+ size_t count = fread(buffer, 1, sizeof(buffer), stdin);
- if (feof(file))
- stream->bytes_left = 0;
+ /* Construct a pb_istream_t for reading from the buffer */
+ pb_istream_t stream = pb_istream_from_buffer(buffer, count);
- return status;
-}
-
-int main()
-{
- /* Maximum size is specified to prevent infinite length messages from
- * hanging this in the fuzz test.
- */
- pb_istream_t stream = {&callback, stdin, 10000};
+ /* Decode and print out the stuff */
if (!print_person(&stream))
{
printf("Parsing failed.\n");