diff options
| author | Edward Thomson <ethomson@microsoft.com> | 2015-02-10 23:55:07 -0500 |
|---|---|---|
| committer | Edward Thomson <ethomson@edwardthomson.com> | 2015-02-12 22:54:47 -0500 |
| commit | 4aa664ae3953d99c2ae4cd769f02818bc122eebc (patch) | |
| tree | 7316e3d7febcbcde19dd4844af9503f4c6d57d69 /tests/buf/basic.c | |
| parent | 3603cb0978b7ef21ff9cd63693ebd6d27bc2bc53 (diff) | |
| download | libgit2-4aa664ae3953d99c2ae4cd769f02818bc122eebc.tar.gz | |
git_buf_grow_by: increase buf asize incrementally
Introduce `git_buf_grow_by` to incrementally increase the size of a
`git_buf`, performing an overflow calculation on the growth.
Diffstat (limited to 'tests/buf/basic.c')
| -rw-r--r-- | tests/buf/basic.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/buf/basic.c b/tests/buf/basic.c index d558757a9..dcc0916d2 100644 --- a/tests/buf/basic.c +++ b/tests/buf/basic.c @@ -15,6 +15,26 @@ void test_buf_basic__resize(void) git_buf_free(&buf1); } +void test_buf_basic__resize_incremental(void) +{ + git_buf buf1 = GIT_BUF_INIT; + + /* Presently, asking for 6 bytes will round up to 8. */ + cl_git_pass(git_buf_puts(&buf1, "Hello")); + cl_assert_equal_i(5, buf1.size); + cl_assert_equal_i(8, buf1.asize); + + /* Ensure an additional byte does not realloc. */ + cl_git_pass(git_buf_grow_by(&buf1, 1)); + cl_assert_equal_i(5, buf1.size); + cl_assert_equal_i(8, buf1.asize); + + /* But requesting many does. */ + cl_git_pass(git_buf_grow_by(&buf1, 16)); + cl_assert_equal_i(5, buf1.size); + cl_assert(buf1.asize > 8); +} + void test_buf_basic__printf(void) { git_buf buf2 = GIT_BUF_INIT; |
