test.c 652 B

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