test.c 911 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <pb_encode.h>
  5. #include <pb_decode.h>
  6. #include "test.pb.h"
  7. #include "unittests.h"
  8. int main(int argc, char **argv)
  9. {
  10. int status = 0;
  11. uint8_t buffer[512] = {0};
  12. int i;
  13. pb_ostream_t ostream;
  14. Reply reply = Reply_init_zero;
  15. Reply_Result request_result = Reply_Result_OK;
  16. ostream = pb_ostream_from_buffer(buffer, sizeof(buffer));
  17. reply.result = request_result;
  18. if (!pb_encode(&ostream, Reply_fields, &reply)) {
  19. fprintf(stderr, "Encode failed: %s\n", PB_GET_ERROR(&ostream));
  20. return 1;
  21. }
  22. printf("response payload (%d):", (int)ostream.bytes_written);
  23. for (i = 0; i < ostream.bytes_written; i++) {
  24. printf("%02X", buffer[i]);
  25. }
  26. printf("\n");
  27. TEST(ostream.bytes_written == 2);
  28. TEST(buffer[0] == 0x08);
  29. TEST(buffer[1] == 0x01);
  30. return status;
  31. }