Commit 8e5281c8 by Patrick Steinhardt Committed by Edward Thomson

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.
parent 90cc0771
#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();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment