diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2014-06-02 21:20:57 +0300 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2014-06-02 21:20:57 +0300 |
commit | 788d2825b06426f50064dc5f29b07ce0be105b2b (patch) | |
tree | 48899b97cecb708315a0d3db8e366599aaf81e7d /tests | |
parent | 99bc1d4f97710cc71612869d3d7e0f501a4626ff (diff) |
Add unit tests for allocate_field().
Diffstat (limited to 'tests')
-rw-r--r-- | tests/decode_unittests/decode_unittests.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/decode_unittests/decode_unittests.c b/tests/decode_unittests/decode_unittests.c index 1be01913..98055df3 100644 --- a/tests/decode_unittests/decode_unittests.c +++ b/tests/decode_unittests/decode_unittests.c @@ -1,4 +1,5 @@ /* This includes the whole .c file to get access to static functions. */ +#define PB_ENABLE_MALLOC #include "pb_decode.c" #include <stdio.h> @@ -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"); |