diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2017-02-12 10:45:07 +0200 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2017-02-12 10:50:05 +0200 |
commit | 9dd81c51b3c64221117ad2c71daff0980baaf1c2 (patch) | |
tree | 4cd3824e3f4438a4f397f2f84fa707642274f823 /tests/regression/issue_242/zero_value.c | |
parent | afdbca39edfaef58073f661d23300e1133c4e8af (diff) |
Add regression test for issue 242
Diffstat (limited to 'tests/regression/issue_242/zero_value.c')
-rw-r--r-- | tests/regression/issue_242/zero_value.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/regression/issue_242/zero_value.c b/tests/regression/issue_242/zero_value.c new file mode 100644 index 00000000..b3d96b7a --- /dev/null +++ b/tests/regression/issue_242/zero_value.c @@ -0,0 +1,51 @@ +#include <unittests.h> +#include <pb_encode.h> +#include <pb_decode.h> +#include <string.h> +#include "zero_value.pb.h" + +int main() +{ + int status = 0; + + COMMENT("Test extension fields with zero values"); + { + uint8_t buffer[256] = {0}; + pb_ostream_t ostream; + int32_t value = 0; + Extendable source = {0}; + + pb_extension_t source_ext = {0}; + source_ext.type = &opt_int32; + source_ext.dest = &value; + source.extensions = &source_ext; + + ostream = pb_ostream_from_buffer(buffer, sizeof(buffer)); + TEST(pb_encode(&ostream, Extendable_fields, &source)); + + TEST(ostream.bytes_written == 2); + TEST(memcmp(buffer, "\x58\x00", 2) == 0); + } + + /* Note: There never was a bug here, but this check is included + * in the regression test because the logic is closely related. + */ + COMMENT("Test pointer fields with zero values"); + { + uint8_t buffer[256] = {0}; + pb_ostream_t ostream; + int32_t value = 0; + PointerMessage source = {0}; + + source.opt_int32 = &value; + + ostream = pb_ostream_from_buffer(buffer, sizeof(buffer)); + TEST(pb_encode(&ostream, PointerMessage_fields, &source)); + + TEST(ostream.bytes_written == 2); + TEST(memcmp(buffer, "\x58\x00", 2) == 0); + } + + return status; +} + |