Support dynamic allocation for string, bytes and message fields.

This is turned on by passing -p to nanopb_generator.py or setting the
(nanopb).pointer option for a .proto field.

git-svn-id: https://svn.kapsi.fi/jpa/nanopb-dev@1081 e3a754e5-d11d-0410-8d38-ebb782a927b9
This commit is contained in:
Michael Poole
2011-12-20 03:30:52 +00:00
committed by Petteri Aimonen
parent 8e5337e9ef
commit c66c6b43c4
14 changed files with 403 additions and 48 deletions

View File

@@ -279,6 +279,30 @@ int main()
TEST((s = S("\x08"), !pb_decode(&s, IntegerArray_msg, &dest)))
}
#ifdef MALLOC_HEADER
{
pb_istream_t s;
PointerContainer dest;
COMMENT("Testing pb_decode with pointer fields")
memset(&dest, 0, sizeof(dest));
TEST((s = S("\x0A\x01\x61\x12\x01\x62\x2A\x01\x65\x32\x01\x66\x3A\x00"
"\x42\x01\x63\x4A\x01\x64"),
pb_decode(&s, PointerContainer_msg, &dest)))
TEST(0 == strcmp(dest.text, "a"))
TEST(dest.blob.size == 1 && dest.blob.bytes[0] == 'b')
TEST(dest.submsg == NULL)
TEST(dest.rtext_count == 1 && (0 == strcmp(dest.rtext[0], "e")))
TEST(dest.rblob_count == 1 && dest.rblob[0].size == 1 &&
dest.rblob[0].bytes[0] == 'f')
TEST(dest.rsubmsg_count == 1)
TEST(0 == strcmp(dest.otext, "c"))
TEST(dest.oblob.size == 1 && dest.oblob.bytes[0] == 'd')
TEST(pb_clean(PointerContainer_msg, &dest));
}
#endif
if (status != 0)
fprintf(stdout, "\n\nSome tests FAILED!\n");