diff options
Diffstat (limited to 'tests/test_decode1.c')
-rw-r--r-- | tests/test_decode1.c | 31 |
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"); |