]>
git.proxmox.com Git - libgit2.git/blob - tests/buf/basic.c
f90c4c6ed0d0cfd95cb7e6eea28110646ed9a78b
1 #include "clar_libgit2.h"
4 static const char *test_string
= "Have you seen that? Have you seeeen that??";
6 void test_buf_basic__resize(void)
8 git_buf buf1
= GIT_BUF_INIT
;
9 git_buf_puts(&buf1
, test_string
);
10 cl_assert(git_buf_oom(&buf1
) == 0);
11 cl_assert_equal_s(git_buf_cstr(&buf1
), test_string
);
13 git_buf_puts(&buf1
, test_string
);
14 cl_assert(strlen(git_buf_cstr(&buf1
)) == strlen(test_string
) * 2);
15 git_buf_dispose(&buf1
);
18 void test_buf_basic__resize_incremental(void)
20 git_buf buf1
= GIT_BUF_INIT
;
22 /* Presently, asking for 6 bytes will round up to 8. */
23 cl_git_pass(git_buf_puts(&buf1
, "Hello"));
24 cl_assert_equal_i(5, buf1
.size
);
25 cl_assert_equal_i(8, buf1
.asize
);
27 /* Ensure an additional byte does not realloc. */
28 cl_git_pass(git_buf_grow_by(&buf1
, 1));
29 cl_assert_equal_i(5, buf1
.size
);
30 cl_assert_equal_i(8, buf1
.asize
);
32 /* But requesting many does. */
33 cl_git_pass(git_buf_grow_by(&buf1
, 16));
34 cl_assert_equal_i(5, buf1
.size
);
35 cl_assert(buf1
.asize
> 8);
37 git_buf_dispose(&buf1
);
40 void test_buf_basic__printf(void)
42 git_buf buf2
= GIT_BUF_INIT
;
43 git_buf_printf(&buf2
, "%s %s %d ", "shoop", "da", 23);
44 cl_assert(git_buf_oom(&buf2
) == 0);
45 cl_assert_equal_s(git_buf_cstr(&buf2
), "shoop da 23 ");
47 git_buf_printf(&buf2
, "%s %d", "woop", 42);
48 cl_assert(git_buf_oom(&buf2
) == 0);
49 cl_assert_equal_s(git_buf_cstr(&buf2
), "shoop da 23 woop 42");
50 git_buf_dispose(&buf2
);