1 /* Checks that missing required fields are detected properly */
6 #include "missing_fields.pb.h"
12 /* Create a message with one missing field */
14 MissingField msg = {0};
15 pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
17 if (!pb_encode(&stream, MissingField_fields, &msg))
19 printf("Encode failed.\n");
24 /* Test that it decodes properly if we don't require that field */
26 MissingField msg = {0};
27 pb_istream_t stream = pb_istream_from_buffer(buffer, sizeof(buffer));
29 if (!pb_decode(&stream, MissingField_fields, &msg))
31 printf("Decode failed: %s\n", PB_GET_ERROR(&stream));
36 /* Test that it does *not* decode properly if we require the field */
39 pb_istream_t stream = pb_istream_from_buffer(buffer, sizeof(buffer));
41 if (pb_decode(&stream, AllFields_fields, &msg))
43 printf("Decode didn't detect missing field.\n");
48 return 0; /* All ok */