summaryrefslogtreecommitdiffstats
path: root/tests/callbacks/decode_callbacks.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/callbacks/decode_callbacks.c')
-rw-r--r--tests/callbacks/decode_callbacks.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/tests/callbacks/decode_callbacks.c b/tests/callbacks/decode_callbacks.c
index b5056923..c8daed29 100644
--- a/tests/callbacks/decode_callbacks.c
+++ b/tests/callbacks/decode_callbacks.c
@@ -5,6 +5,7 @@
#include <stdio.h>
#include <pb_decode.h>
#include "callbacks.pb.h"
+#include "test_helpers.h"
bool print_string(pb_istream_t *stream, const pb_field_t *field, void **arg)
{
@@ -50,21 +51,24 @@ bool print_fixed64(pb_istream_t *stream, const pb_field_t *field, void **arg)
if (!pb_decode_fixed64(stream, &value))
return false;
- printf((char*)*arg, (long long)value);
+ printf((char*)*arg, (long)value);
return true;
}
int main()
{
uint8_t buffer[1024];
- size_t length = fread(buffer, 1, 1024, stdin);
- pb_istream_t stream = pb_istream_from_buffer(buffer, length);
-
+ size_t length;
+ pb_istream_t stream;
/* Note: empty initializer list initializes the struct with all-0.
* This is recommended so that unused callbacks are set to NULL instead
* of crashing at runtime.
*/
- TestMessage testmessage = {};
+ TestMessage testmessage = {{{NULL}}};
+
+ SET_BINARY_MODE(stdin);
+ length = fread(buffer, 1, 1024, stdin);
+ stream = pb_istream_from_buffer(buffer, length);
testmessage.submsg.stringvalue.funcs.decode = &print_string;
testmessage.submsg.stringvalue.arg = "submsg {\n stringvalue: \"%s\"\n";
@@ -73,7 +77,7 @@ int main()
testmessage.submsg.fixed32value.funcs.decode = &print_fixed32;
testmessage.submsg.fixed32value.arg = " fixed32value: %ld\n";
testmessage.submsg.fixed64value.funcs.decode = &print_fixed64;
- testmessage.submsg.fixed64value.arg = " fixed64value: %lld\n}\n";
+ testmessage.submsg.fixed64value.arg = " fixed64value: %ld\n}\n";
testmessage.stringvalue.funcs.decode = &print_string;
testmessage.stringvalue.arg = "stringvalue: \"%s\"\n";