6 #include "enumsizes.pb.h"
12 UnpackedEnums msg1 = {
24 COMMENT("Step 1: unpacked enums -> protobuf");
26 pb_ostream_t s = pb_ostream_from_buffer(buf, sizeof(buf));
27 TEST(pb_encode(&s, UnpackedEnums_fields, &msg1));
28 msgsize = s.bytes_written;
31 COMMENT("Step 2: protobuf -> packed enums");
33 pb_istream_t s = pb_istream_from_buffer(buf, msgsize);
34 TEST(pb_decode(&s, PackedEnums_fields, &msg2));
36 TEST(msg1.u8_min == (int)msg2.u8_min);
37 TEST(msg1.u8_max == (int)msg2.u8_max);
38 TEST(msg1.i8_min == (int)msg2.i8_min);
39 TEST(msg1.i8_max == (int)msg2.i8_max);
40 TEST(msg1.u16_min == (int)msg2.u16_min);
41 TEST(msg1.u16_max == (int)msg2.u16_max);
42 TEST(msg1.i16_min == (int)msg2.i16_min);
43 TEST(msg1.i16_max == (int)msg2.i16_max);
46 COMMENT("Step 3: packed enums -> protobuf");
48 pb_ostream_t s = pb_ostream_from_buffer(buf, sizeof(buf));
49 TEST(pb_encode(&s, PackedEnums_fields, &msg2));
50 msgsize = s.bytes_written;
53 COMMENT("Step 4: protobuf -> unpacked enums");
55 pb_istream_t s = pb_istream_from_buffer(buf, msgsize);
56 TEST(pb_decode(&s, UnpackedEnums_fields, &msg3));
58 TEST(msg1.u8_min == (int)msg3.u8_min);
59 TEST(msg1.u8_max == (int)msg3.u8_max);
60 TEST(msg1.i8_min == (int)msg3.i8_min);
61 TEST(msg1.i8_max == (int)msg3.i8_max);
62 TEST(msg1.u16_min == (int)msg2.u16_min);
63 TEST(msg1.u16_max == (int)msg2.u16_max);
64 TEST(msg1.i16_min == (int)msg2.i16_min);
65 TEST(msg1.i16_max == (int)msg2.i16_max);
69 fprintf(stdout, "\n\nSome tests FAILED!\n");