15 Message1 msg_a = Message1_init_zero;
16 Message1 msg_b = Message1_init_zero;
20 size_t message_length;
26 COMMENT(
"Test encode and decode with three entries");
30 message_length = ostream.bytes_written;
35 TEST(istream.bytes_left == 0);
36 TEST(
memcmp(&msg_b, &msg_a,
sizeof(msg_a)) == 0);
40 pb_byte_t input[] = {0x08, 0x00, 0x08, 0x01, 0x08, 0x02, 0x08, 0x03};
42 Message1 msg = Message1_init_zero;
44 COMMENT(
"Test wrong number of entries");
48 TEST(msg.data[0] == 0 && msg.data[1] == 1 && msg.data[2] == 2);
52 TEST(
strcmp(stream.errmsg,
"array overflow") == 0);
56 TEST(
strcmp(stream.errmsg,
"wrong size for fixed count field") == 0);
61 Message2 msg_a = Message2_init_zero;
62 Message2 msg_b = Message2_init_zero;
66 size_t message_length;
68 COMMENT(
"Test encode and decode with nested messages");
70 msg_a.data[0].data[0] = 1;
71 msg_a.data[0].data[1] = 2;
72 msg_a.data[0].data[2] = 3;
73 msg_a.data[1].data[0] = 4;
74 msg_a.data[1].data[1] = 5;
75 msg_a.data[1].data[2] = 6;
79 message_length = ostream.bytes_written;
84 TEST(istream.bytes_left == 0);
85 TEST(
memcmp(&msg_b, &msg_a,
sizeof(msg_a)) == 0);
90 Message3 msg_a = Message3_init_zero;
91 Message3 msg_b = Message3_init_zero;
95 size_t message_length;
97 COMMENT(
"Test encode and decode with two nested messages");
99 msg_a.data1[0].data[0].data[0] = 1;
100 msg_a.data1[0].data[0].data[1] = 2;
101 msg_a.data1[0].data[0].data[2] = 3;
102 msg_a.data1[0].data[1].data[0] = 4;
103 msg_a.data1[0].data[1].data[1] = 5;
104 msg_a.data1[0].data[1].data[2] = 6;
106 msg_a.data1[1].data[0].data[0] = 7;
107 msg_a.data1[1].data[0].data[1] = 8;
108 msg_a.data1[1].data[0].data[2] = 9;
109 msg_a.data1[1].data[1].data[0] = 10;
110 msg_a.data1[1].data[1].data[1] = 11;
111 msg_a.data1[1].data[1].data[2] = 12;
113 msg_a.data2[0].data[0].data[0] = 11;
114 msg_a.data2[0].data[0].data[1] = 12;
115 msg_a.data2[0].data[0].data[2] = 13;
116 msg_a.data2[0].data[1].data[0] = 14;
117 msg_a.data2[0].data[1].data[1] = 15;
118 msg_a.data2[0].data[1].data[2] = 16;
120 msg_a.data2[1].data[0].data[0] = 17;
121 msg_a.data2[1].data[0].data[1] = 18;
122 msg_a.data2[1].data[0].data[2] = 19;
123 msg_a.data2[1].data[1].data[0] = 110;
124 msg_a.data2[1].data[1].data[1] = 111;
125 msg_a.data2[1].data[1].data[2] = 112;
129 message_length = ostream.bytes_written;
134 TEST(istream.bytes_left == 0);
135 TEST(
memcmp(&msg_b, &msg_a,
sizeof(msg_a)) == 0);
140 Message4 msg_a = Message4_init_zero;
141 Message4 msg_b = Message4_init_zero;
143 pb_ostream_t ostream;
144 pb_istream_t istream;
145 size_t message_length;
147 COMMENT(
"Test encode and decode with pointer type fixarray");
157 char *strings[
pb_arraysize(Message4, strings[0])] = {a, b, abc};
159 msg_a.submsgs = &submsgs;
160 msg_a.strings = &strings;
164 message_length = ostream.bytes_written;
171 TEST(istream.bytes_left == 0);
173 TEST((*msg_b.submsgs)[0].a == 1);
174 TEST((*msg_b.submsgs)[1].a == 5);
175 TEST((*msg_b.submsgs)[2].a == 999);
179 TEST(
strcmp((*msg_b.strings)[2],
"abc") == 0);
187 fprintf(
stdout,
"\n\nSome tests FAILED!\n");