MOS Source Code
Loading...
Searching...
No Matches
submsg_array.c
Go to the documentation of this file.
1#include <unittests.h>
2#include <pb_encode.h>
3#include <pb_decode.h>
4#include "submsg_array.pb.h"
5
6int main()
7{
8 int status = 0;
9
10 COMMENT("Test encoding for submessage with array");
11 {
12 uint8_t buffer[TestMessage_size] = {0};
13 pb_ostream_t ostream = pb_ostream_from_buffer(buffer, TestMessage_size);
14 TestMessage msg = TestMessage_init_zero;
15
16 msg.submsg.rep_uint32_count = 3;
17 msg.submsg.rep_uint32[0] = 0;
18 msg.submsg.rep_uint32[1] = 1;
19 msg.submsg.rep_uint32[2] = 2;
20
21 TEST(pb_encode(&ostream, TestMessage_fields, &msg));
22 TEST(ostream.bytes_written > 0);
23
24 {
25 pb_istream_t istream = pb_istream_from_buffer(buffer, ostream.bytes_written);
26 TestMessage msg2 = TestMessage_init_zero;
27
28 TEST(pb_decode(&istream, TestMessage_fields, &msg2));
29 TEST(msg2.submsg.rep_uint32_count == 3);
30 TEST(msg2.submsg.rep_uint32[0] == 0);
31 TEST(msg2.submsg.rep_uint32[1] == 1);
32 TEST(msg2.submsg.rep_uint32[2] == 2);
33 }
34 }
35
36 return status;
37}
38
bool pb_decode(pb_istream_t *stream, const pb_msgdesc_t *fields, void *dest_struct)
Definition pb_decode.c:1182
pb_istream_t pb_istream_from_buffer(const pb_byte_t *buf, size_t msglen)
Definition pb_decode.c:143
pb_ostream_t pb_ostream_from_buffer(pb_byte_t *buf, size_t bufsize)
Definition pb_encode.c:63
bool pb_encode(pb_ostream_t *stream, const pb_msgdesc_t *fields, const void *src_struct)
Definition pb_encode.c:512
unsigned char uint8_t
Definition pb_syshdr.h:20
int main()
Definition submsg_array.c:6
#define TEST(x)
Definition test.h:3
static char buffer[2048]
Definition test_printf.c:7
#define COMMENT(x)
Definition unittests.h:17