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