Line data Source code
1 : #include <pb_encode.h> 2 : #include <unittests.h> 3 : #include <string.h> 4 : #include "padding.pb.h" 5 : 6 1 : int main() 7 : { 8 1 : int status = 0; 9 : 10 : TestMessage msg; 11 : 12 : /* Set padding bytes to garbage */ 13 1 : memset(&msg, 0xAA, sizeof(msg)); 14 : 15 : /* Set all meaningful fields to 0 */ 16 1 : msg.submsg.boolfield = false; 17 1 : msg.submsg.intfield = 0; 18 : 19 : /* Test encoding */ 20 : { 21 1 : pb_byte_t buf[128] = {0}; 22 1 : pb_ostream_t stream = pb_ostream_from_buffer(buf, sizeof(buf)); 23 1 : TEST(pb_encode(&stream, TestMessage_fields, &msg)); 24 : 25 : /* Because all fields have zero values, proto3 encoder 26 : * shouldn't write out anything. */ 27 1 : TEST(stream.bytes_written == 0); 28 : } 29 : 30 1 : return status; 31 : } 32 :