diff options
author | Patrick Steinhardt <ps@pks.im> | 2019-10-11 11:38:14 +0200 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2023-05-15 09:30:48 +0100 |
commit | 8e5281c88b860cce7a6a2f4a00c28b6fb00720b0 (patch) | |
tree | fac692612268790f1ec4ba53bedda1c822be26d7 | |
parent | 90cc07711c43b12a4bb270583026cbc71db3823e (diff) | |
download | libgit2-8e5281c88b860cce7a6a2f4a00c28b6fb00720b0.tar.gz |
tests: add allocation failure test for buffers
Test that `git_buf` correctly fails if no more bytes can be allocated.
This is mostly for demonstration purposes.
-rw-r--r-- | tests/util/str/oom.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/util/str/oom.c b/tests/util/str/oom.c index dd3796674..810c1f25a 100644 --- a/tests/util/str/oom.c +++ b/tests/util/str/oom.c @@ -1,4 +1,5 @@ #include "clar_libgit2.h" +#include "clar_libgit2_alloc.h" /* Override default allocators with ones that will fail predictably. */ @@ -56,3 +57,15 @@ void test_str_oom__grow_by(void) cl_assert(git_str_grow_by(&buf, 101) == -1); cl_assert(git_str_oom(&buf)); } + +void test_str_oom__allocation_failure(void) +{ + git_str buf = GIT_STR_INIT; + + cl_alloc_limit(10); + + cl_git_pass(git_str_puts(&buf, "foobar")); + cl_git_fail(git_str_puts(&buf, "foobar")); + + cl_alloc_reset(); +} |