]>
Commit | Line | Data |
---|---|---|
3fd1520c | 1 | #include "clar_libgit2.h" |
1d09a1c8 VM |
2 | #include "buffer.h" |
3 | ||
4 | static const char *test_string = "Have you seen that? Have you seeeen that??"; | |
5 | ||
6 | void test_buf_basic__resize(void) | |
7 | { | |
8 | git_buf buf1 = GIT_BUF_INIT; | |
9 | git_buf_puts(&buf1, test_string); | |
10 | cl_assert(git_buf_oom(&buf1) == 0); | |
946a6dc4 | 11 | cl_assert_equal_s(git_buf_cstr(&buf1), test_string); |
1d09a1c8 VM |
12 | |
13 | git_buf_puts(&buf1, test_string); | |
14 | cl_assert(strlen(git_buf_cstr(&buf1)) == strlen(test_string) * 2); | |
ac3d33df | 15 | git_buf_dispose(&buf1); |
1d09a1c8 VM |
16 | } |
17 | ||
4aa664ae ET |
18 | void test_buf_basic__resize_incremental(void) |
19 | { | |
20 | git_buf buf1 = GIT_BUF_INIT; | |
21 | ||
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); | |
26 | ||
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); | |
31 | ||
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); | |
d97d9559 | 36 | |
ac3d33df | 37 | git_buf_dispose(&buf1); |
4aa664ae ET |
38 | } |
39 | ||
1d09a1c8 VM |
40 | void test_buf_basic__printf(void) |
41 | { | |
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); | |
946a6dc4 | 45 | cl_assert_equal_s(git_buf_cstr(&buf2), "shoop da 23 "); |
1d09a1c8 VM |
46 | |
47 | git_buf_printf(&buf2, "%s %d", "woop", 42); | |
48 | cl_assert(git_buf_oom(&buf2) == 0); | |
946a6dc4 | 49 | cl_assert_equal_s(git_buf_cstr(&buf2), "shoop da 23 woop 42"); |
ac3d33df | 50 | git_buf_dispose(&buf2); |
3fd1520c | 51 | } |