diff options
Diffstat (limited to 'tests/test_encode3.c')
-rw-r--r-- | tests/test_encode3.c | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/tests/test_encode3.c b/tests/test_encode3.c index 8128ea4a..1a48f06b 100644 --- a/tests/test_encode3.c +++ b/tests/test_encode3.c @@ -1,14 +1,16 @@ /* Attempts to test all the datatypes supported by ProtoBuf. - * Currently only tests the 'required' variety. */ #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <pb_encode.h> #include "alltypes.pb.h" -int main() +int main(int argc, char **argv) { + int mode = (argc > 1) ? atoi(argv[1]) : 0; + /* Initialize the structure with constants */ AllTypes alltypes = {0}; @@ -58,12 +60,58 @@ int main() alltypes.rep_submsg_count = 5; strcpy(alltypes.rep_submsg[4].substuff1, "2016"); alltypes.rep_submsg[4].substuff2 = 2016; + alltypes.rep_submsg[4].has_substuff3 = true; + alltypes.rep_submsg[4].substuff3 = 2016; alltypes.rep_enum_count = 5; alltypes.rep_enum[4] = MyEnum_Truth; + if (mode != 0) + { + /* Fill in values for optional fields */ + alltypes.has_opt_int32 = true; + alltypes.opt_int32 = 3041; + alltypes.has_opt_int64 = true; + alltypes.opt_int64 = 3042; + alltypes.has_opt_uint32 = true; + alltypes.opt_uint32 = 3043; + alltypes.has_opt_uint64 = true; + alltypes.opt_uint64 = 3044; + alltypes.has_opt_sint32 = true; + alltypes.opt_sint32 = 3045; + alltypes.has_opt_sint64 = true; + alltypes.opt_sint64 = 3046; + alltypes.has_opt_bool = true; + alltypes.opt_bool = true; + + alltypes.has_opt_fixed32 = true; + alltypes.opt_fixed32 = 3048; + alltypes.has_opt_sfixed32 = true; + alltypes.opt_sfixed32 = 3049; + alltypes.has_opt_float = true; + alltypes.opt_float = 3050.0f; + + alltypes.has_opt_fixed64 = true; + alltypes.opt_fixed64 = 3051; + alltypes.has_opt_sfixed64 = true; + alltypes.opt_sfixed64 = 3052; + alltypes.has_opt_double = true; + alltypes.opt_double = 3053.0; + + alltypes.has_opt_string = true; + strcpy(alltypes.opt_string, "3054"); + alltypes.has_opt_bytes = true; + alltypes.opt_bytes.size = 4; + memcpy(alltypes.opt_bytes.bytes, "3055", 4); + alltypes.has_opt_submsg = true; + strcpy(alltypes.opt_submsg.substuff1, "3056"); + alltypes.opt_submsg.substuff2 = 3056; + alltypes.has_opt_enum = true; + alltypes.opt_enum = MyEnum_Truth; + } + alltypes.end = 1099; - uint8_t buffer[512]; + uint8_t buffer[1024]; pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); /* Now encode it and check if we succeeded. */ @@ -74,6 +122,7 @@ int main() } else { + fprintf(stderr, "Encoding failed!\n"); return 1; /* Failure */ } } |