From a3f5e4d81f8d81e208f33dded6d892fbbdce90bc Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Fri, 30 Dec 2011 08:57:27 +0000 Subject: 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 --- tests/test_decode1.c | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) (limited to 'tests/test_decode1.c') 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"); -- cgit 1.2.3-korg