]> git.proxmox.com Git - libgit2.git/blob - tests/core/buf.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / core / buf.c
1 #include "clar_libgit2.h"
2 #include "buf.h"
3
4 void test_core_buf__sanitize(void)
5 {
6 git_buf buf = { (char *)0x42, 0, 16 };
7
8 cl_git_pass(git_buf_sanitize(&buf));
9 cl_assert_equal_s(buf.ptr, "");
10 cl_assert_equal_i(buf.reserved, 0);
11 cl_assert_equal_i(buf.size, 0);
12
13 git_buf_dispose(&buf);
14 }
15
16 void test_core_buf__tostr(void)
17 {
18 git_str str = GIT_STR_INIT;
19 git_buf buf = { (char *)0x42, 0, 16 };
20
21 cl_git_pass(git_buf_tostr(&str, &buf));
22
23 cl_assert_equal_s(buf.ptr, "");
24 cl_assert_equal_i(buf.reserved, 0);
25 cl_assert_equal_i(buf.size, 0);
26
27 cl_assert_equal_s(str.ptr, "");
28 cl_assert_equal_i(str.asize, 0);
29 cl_assert_equal_i(str.size, 0);
30
31 git_buf_dispose(&buf);
32 git_str_dispose(&str);
33 }
34
35 void test_core_buf__fromstr(void)
36 {
37 git_str str = GIT_STR_INIT;
38 git_buf buf = { (char *)0x42, 0, 16 };
39
40 cl_git_pass(git_buf_tostr(&str, &buf));
41 cl_git_pass(git_str_puts(&str, "Hello, world."));
42 cl_git_pass(git_buf_fromstr(&buf, &str));
43
44 cl_assert(buf.reserved > 14);
45 cl_assert_equal_i(buf.size, 13);
46 cl_assert_equal_s(buf.ptr, "Hello, world.");
47
48 cl_assert_equal_s(str.ptr, "");
49 cl_assert_equal_i(str.asize, 0);
50 cl_assert_equal_i(str.size, 0);
51
52 git_buf_dispose(&buf);
53 git_str_dispose(&str);
54 }