1 #include <unittests.h>
2 #include <pb_encode.h>
3 #include <pb_decode.h>
4 #include <string.h>
5 #include "zero_value.pb.h"
6
main()7 int main()
8 {
9 int status = 0;
10
11 COMMENT("Test extension fields with zero values");
12 {
13 uint8_t buffer[256] = {0};
14 pb_ostream_t ostream;
15 int32_t value = 0;
16 Extendable source = {0};
17
18 pb_extension_t source_ext = {0};
19 source_ext.type = &opt_int32;
20 source_ext.dest = &value;
21 source.extensions = &source_ext;
22
23 ostream = pb_ostream_from_buffer(buffer, sizeof(buffer));
24 TEST(pb_encode(&ostream, Extendable_fields, &source));
25
26 TEST(ostream.bytes_written == 2);
27 TEST(memcmp(buffer, "\x58\x00", 2) == 0);
28 }
29
30 /* Note: There never was a bug here, but this check is included
31 * in the regression test because the logic is closely related.
32 */
33 COMMENT("Test pointer fields with zero values");
34 {
35 uint8_t buffer[256] = {0};
36 pb_ostream_t ostream;
37 int32_t value = 0;
38 PointerMessage source = {0};
39
40 source.opt_int32 = &value;
41
42 ostream = pb_ostream_from_buffer(buffer, sizeof(buffer));
43 TEST(pb_encode(&ostream, PointerMessage_fields, &source));
44
45 TEST(ostream.bytes_written == 2);
46 TEST(memcmp(buffer, "\x58\x00", 2) == 0);
47 }
48
49 return status;
50 }
51
52