diff options
Diffstat (limited to 'tests/test_encode3.c')
-rw-r--r-- | tests/test_encode3.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/test_encode3.c b/tests/test_encode3.c new file mode 100644 index 00000000..5e94be51 --- /dev/null +++ b/tests/test_encode3.c @@ -0,0 +1,50 @@ +/* Attempts to test all the datatypes supported by ProtoBuf. + * Currently only tests the 'required' variety. + */ + +#include <stdio.h> +#include <pb_encode.h> +#include "alltypes.pb.h" + +int main() +{ + /* Initialize the structure with constants */ + AllTypes alltypes = { + 1001, + 1002, + 1003, + 1004, + 1005, + 1006, + true, + + 1008, + 1009, + 1010.0f, + + 1011, + 1012, + 1013.0, + + "1014", + {4, "1015"}, + {"1016", 1016}, + MyEnum_Truth, + + 1099 + }; + + uint8_t buffer[512]; + pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); + + /* Now encode it and check if we succeeded. */ + if (pb_encode(&stream, AllTypes_fields, &alltypes)) + { + fwrite(buffer, 1, stream.bytes_written, stdout); + return 0; /* Success */ + } + else + { + return 1; /* Failure */ + } +} |