X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=tests%2Fdecode_unittests%2Fdecode_unittests.c;h=98055df3ba797a8e8e088edd833e420941c4dfee;hb=788d2825b06426f50064dc5f29b07ce0be105b2b;hp=6ad05f0092f1cf802f216627200743ec4ae4c961;hpb=262c62676cf740ec3ce14a22bde47b7968fec8f0;p=apps%2Fagl-service-can-low-level.git diff --git a/tests/decode_unittests/decode_unittests.c b/tests/decode_unittests/decode_unittests.c index 6ad05f00..98055df3 100644 --- a/tests/decode_unittests/decode_unittests.c +++ b/tests/decode_unittests/decode_unittests.c @@ -1,8 +1,9 @@ -#define NANOPB_INTERNALS +/* This includes the whole .c file to get access to static functions. */ +#define PB_ENABLE_MALLOC +#include "pb_decode.c" #include #include -#include "pb_decode.h" #include "unittests.h" #include "unittestproto.pb.h" @@ -291,7 +292,7 @@ int main() { pb_istream_t s; - IntegerContainer dest = {}; + IntegerContainer dest = {{0}}; COMMENT("Testing pb_decode_delimited") TEST((s = S("\x09\x0A\x07\x0A\x05\x01\x02\x03\x04\x05"), @@ -299,6 +300,28 @@ int main() dest.submsg.data_count == 5) } + { + pb_istream_t s = {0}; + void *data = NULL; + + COMMENT("Testing allocate_field") + TEST(allocate_field(&s, &data, 10, 10) && data != NULL); + TEST(allocate_field(&s, &data, 10, 20) && data != NULL); + + { + void *oldvalue = data; + size_t very_big = (size_t)-1; + size_t somewhat_big = very_big / 2 + 1; + size_t not_so_big = (size_t)1 << (4 * sizeof(size_t)); + + TEST(!allocate_field(&s, &data, very_big, 2) && data == oldvalue); + TEST(!allocate_field(&s, &data, somewhat_big, 2) && data == oldvalue); + TEST(!allocate_field(&s, &data, not_so_big, not_so_big) && data == oldvalue); + } + + pb_free(data); + } + if (status != 0) fprintf(stdout, "\n\nSome tests FAILED!\n");