xref: /aosp_15_r20/external/nanopb-c/tests/regression/issue_547/test.c (revision c8d645cafcee3f91213d30caa0fe303887010b9b)
1 #include <string.h>
2 #include <pb_encode.h>
3 #include <unittests.h>
4 #include "test.pb.h"
5 
main()6 int main()
7 {
8     pb_byte_t buf[512];
9     MyMessage msg = MyMessage_init_zero;
10     pb_ostream_t stream = pb_ostream_from_buffer(buf, sizeof(buf));
11 
12     msg.mybytes.size = 0xFFFFFFFF;
13 
14     if (pb_encode(&stream, MyMessage_fields, &msg))
15     {
16         fprintf(stderr, "Failure: expected pb_encode() to fail.\n");
17         return 1;
18     }
19     else if (strcmp(PB_GET_ERROR(&stream), "bytes size exceeded") != 0)
20     {
21         fprintf(stderr, "Unexpected encoding error: %s\n", PB_GET_ERROR(&stream));
22         return 2;
23     }
24     else
25     {
26         return 0;
27     }
28 }
29