submsg_array.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <unittests.h>
  2. #include <pb_encode.h>
  3. #include <pb_decode.h>
  4. #include "submsg_array.pb.h"
  5. int main()
  6. {
  7. int status = 0;
  8. COMMENT("Test encoding for submessage with array");
  9. {
  10. uint8_t buffer[TestMessage_size] = {0};
  11. pb_ostream_t ostream = pb_ostream_from_buffer(buffer, TestMessage_size);
  12. TestMessage msg = TestMessage_init_zero;
  13. msg.submsg.rep_uint32_count = 3;
  14. msg.submsg.rep_uint32[0] = 0;
  15. msg.submsg.rep_uint32[1] = 1;
  16. msg.submsg.rep_uint32[2] = 2;
  17. TEST(pb_encode(&ostream, TestMessage_fields, &msg));
  18. TEST(ostream.bytes_written > 0);
  19. {
  20. pb_istream_t istream = pb_istream_from_buffer(buffer, ostream.bytes_written);
  21. TestMessage msg2 = TestMessage_init_zero;
  22. TEST(pb_decode(&istream, TestMessage_fields, &msg2));
  23. TEST(msg2.submsg.rep_uint32_count == 3);
  24. TEST(msg2.submsg.rep_uint32[0] == 0);
  25. TEST(msg2.submsg.rep_uint32[1] == 1);
  26. TEST(msg2.submsg.rep_uint32[2] == 2);
  27. }
  28. }
  29. return status;
  30. }