1 #include "multiple_oneof.pb.h" 2 #include <unittests.h> 3 #include <pb_encode.h> 4 #include <pb_decode.h> 5 6 int main() 7 { 8 int status = 0; 9 uint8_t buf[128]; 10 size_t msglen; 11 12 { 13 pb_ostream_t stream = pb_ostream_from_buffer(buf, sizeof(buf)); 14 MainMessage msg = MainMessage_init_zero; 15 msg.which_oneof1 = MainMessage_oneof1_uint32_tag; 16 msg.oneof1.oneof1_uint32 = 1234; 17 msg.which_oneof2 = MainMessage_oneof2_uint32_tag; 18 msg.oneof2.oneof2_uint32 = 5678; 19 TEST(pb_encode(&stream, MainMessage_fields, &msg)); 20 msglen = stream.bytes_written; 21 } 22 23 { 24 pb_istream_t stream = pb_istream_from_buffer(buf, msglen); 25 MainMessage msg = MainMessage_init_zero; 26 TEST(pb_decode(&stream, MainMessage_fields, &msg)); 27 TEST(msg.which_oneof1 == MainMessage_oneof1_uint32_tag); 28 TEST(msg.oneof1.oneof1_uint32 == 1234); 29 TEST(msg.which_oneof2 == MainMessage_oneof2_uint32_tag); 30 TEST(msg.oneof2.oneof2_uint32 == 5678); 31 } 32 33 return status; 34 } 35 36