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