Added an encode/decode test for 'required' fields of all types.
[apps/agl-service-can-low-level.git] / tests / test_encode3.c
1 /* Attempts to test all the datatypes supported by ProtoBuf.
2  * Currently only tests the 'required' variety.
3  */
4
5 #include <stdio.h>
6 #include <pb_encode.h>
7 #include "alltypes.pb.h"
8
9 int main()
10 {
11     /* Initialize the structure with constants */
12     AllTypes alltypes = {
13         1001,
14         1002,
15         1003,
16         1004,
17         1005,
18         1006,
19         true,
20         
21         1008,
22         1009,
23         1010.0f,
24         
25         1011,
26         1012,
27         1013.0,
28         
29         "1014",
30         {4, "1015"},
31         {"1016", 1016},
32         MyEnum_Truth,
33         
34         1099
35     };
36     
37     uint8_t buffer[512];
38     pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
39     
40     /* Now encode it and check if we succeeded. */
41     if (pb_encode(&stream, AllTypes_fields, &alltypes))
42     {
43         fwrite(buffer, 1, stream.bytes_written, stdout);
44         return 0; /* Success */
45     }
46     else
47     {
48         return 1; /* Failure */
49     }
50 }