Line data Source code
1 : #include <unittests.h> 2 : #include <pb_encode.h> 3 : #include <pb_decode.h> 4 : #include <string.h> 5 : #include "zero_value.pb.h" 6 : 7 1 : int main() 8 : { 9 1 : int status = 0; 10 : 11 1 : COMMENT("Test extension fields with zero values"); 12 : { 13 1 : uint8_t buffer[256] = {0}; 14 : pb_ostream_t ostream; 15 1 : int32_t value = 0; 16 1 : Extendable source = {0}; 17 : 18 1 : pb_extension_t source_ext = {0}; 19 1 : source_ext.type = &opt_int32; 20 1 : source_ext.dest = &value; 21 1 : source.extensions = &source_ext; 22 : 23 1 : ostream = pb_ostream_from_buffer(buffer, sizeof(buffer)); 24 1 : TEST(pb_encode(&ostream, Extendable_fields, &source)); 25 : 26 1 : TEST(ostream.bytes_written == 2); 27 1 : TEST(memcmp(buffer, "\x58\x00", 2) == 0); 28 : } 29 : 30 : /* Note: There never was a bug here, but this check is included 31 : * in the regression test because the logic is closely related. 32 : */ 33 1 : COMMENT("Test pointer fields with zero values"); 34 : { 35 1 : uint8_t buffer[256] = {0}; 36 : pb_ostream_t ostream; 37 1 : int32_t value = 0; 38 1 : PointerMessage source = {0}; 39 : 40 1 : source.opt_int32 = &value; 41 : 42 1 : ostream = pb_ostream_from_buffer(buffer, sizeof(buffer)); 43 1 : TEST(pb_encode(&ostream, PointerMessage_fields, &source)); 44 : 45 1 : TEST(ostream.bytes_written == 2); 46 1 : TEST(memcmp(buffer, "\x58\x00", 2) == 0); 47 : } 48 : 49 1 : return status; 50 : } 51 :