1 /* Checks that missing required fields are detected properly */
6 #include "missing_fields.pb.h"
13 /* Create a message with one missing field */
15 MissingField msg = {0};
16 pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
18 if (!pb_encode(&stream, MissingField_fields, &msg))
20 printf("Encode failed.\n");
24 size = stream.bytes_written;
27 /* Test that it decodes properly if we don't require that field */
29 MissingField msg = {0};
30 pb_istream_t stream = pb_istream_from_buffer(buffer, size);
32 if (!pb_decode(&stream, MissingField_fields, &msg))
34 printf("Decode failed: %s\n", PB_GET_ERROR(&stream));
39 /* Test that it does *not* decode properly if we require the field */
42 pb_istream_t stream = pb_istream_from_buffer(buffer, size);
44 if (pb_decode(&stream, AllFields_fields, &msg))
46 printf("Decode didn't detect missing field.\n");
51 return 0; /* All ok */