54 uint8_t buffer1[] =
"foobartest1234";
55 uint8_t buffer2[
sizeof(buffer1)];
58 COMMENT(
"Test pb_write and pb_ostream_t");
60 TEST(
memcmp(buffer1, buffer2,
sizeof(buffer1)) == 0);
62 TEST(stream.bytes_written ==
sizeof(buffer1));
69 COMMENT(
"Test pb_write with custom callback");
79 COMMENT(
"Test pb_encode_varint")
92 COMMENT(
"Test pb_encode_varint 32-bit fast path")
114 COMMENT(
"Test pb_encode_svarint 32-bit fast path")
145 pb_field_iter_t field;
148 COMMENT(
"Test pb_encode_tag_for_field")
166 COMMENT(
"Test pb_encode_string")
180 pb_field_iter_t field;
182 COMMENT(
"Test pb_enc_varint and pb_enc_svarint")
184 field.data_size =
sizeof(value);
185 field.pData = &value;
189 field.data_size =
sizeof(max);
194 field.data_size =
sizeof(min);
199 field.data_size =
sizeof(lmax);
204 field.data_size =
sizeof(lmin);
214 pb_field_iter_t field;
216 COMMENT(
"Test pb_enc_fixed using float")
218 field.data_size =
sizeof(fvalue);
219 field.pData = &fvalue;
224 fvalue = -12345678.0f;
227 COMMENT(
"Test pb_enc_fixed using double")
229 field.data_size =
sizeof(dvalue);
230 field.pData = &dvalue;
235 dvalue = -12345678.0;
243 pb_field_iter_t field;
255 char value[30] =
"xyzzy";
256 pb_field_iter_t field;
271 IntegerArray msg = {5, {1, 2, 3, 4, 5}};
273 COMMENT(
"Test pb_encode with int32 array")
287 FloatArray msg = {1, {99.0f}};
289 COMMENT(
"Test pb_encode with float array")
292 "\x0A\x04\x00\x00\xc6\x42"))
304 FloatArray msg = {1, {99.0f}};
306 COMMENT(
"Test array size limit in pb_encode")
309 TEST((msg.data_count = 10) &&
pb_encode(&s, FloatArray_fields, &msg))
312 TEST((msg.data_count = 11) && !
pb_encode(&s, FloatArray_fields, &msg))
322 COMMENT(
"Test pb_encode with callback field.")
329 IntegerContainer msg = {{5, {1,2,3,4,5}}};
331 COMMENT(
"Test pb_encode with packed array in a submessage.")
333 "\x0A\x07\x0A\x05\x01\x02\x03\x04\x05"))
339 BytesMessage msg = {{3,
"xyz"}};
341 COMMENT(
"Test pb_encode with bytes message.")
353 IntegerContainer msg = {{5, {1,2,3,4,5}}};
355 COMMENT(
"Test pb_encode_delimited.")
357 "\x09\x0A\x07\x0A\x05\x01\x02\x03\x04\x05"))
361 IntegerContainer msg = {{5, {1,2,3,4,5}}};
364 COMMENT(
"Test pb_get_encoded_size.")
372 CallbackContainer msg;
373 CallbackContainerContainer msg2;
379 COMMENT(
"Test pb_encode with callback field in a submessage.")
382 "\x0A\x04\x0A\x02\x08\x55"))
386 msg.submsg.data.arg = &state;
388 msg2.submsg.submsg.data.arg = &state;
392 TEST(!
pb_encode(&s, CallbackContainerContainer_fields, &msg2))
398 StringMessage msg = {
"0123456789"};
402 COMMENT(
"Test that StringMessage_size is correct")
405 TEST(s.bytes_written == StringMessage_size);
411 StringPointerContainer msg = StringPointerContainer_init_zero;
412 char *strs[1] = {
NULL};
415 COMMENT(
"Test string pointer encoding.");
418 msg.rep_str_count = 1;
426 fprintf(
stdout,
"\n\nSome tests FAILED!\n");