]> git.proxmox.com Git - libgit2.git/blob - tests/status/single.c
e7f92097cd864b9c3fbb796eeb143a1efce2a18a
[libgit2.git] / tests / status / single.c
1 #include "clar_libgit2.h"
2 #include "posix.h"
3
4 static void
5 cleanup__remove_file(void *_file)
6 {
7 cl_must_pass(p_unlink((char *)_file));
8 }
9
10 /* test retrieving OID from a file apart from the ODB */
11 void test_status_single__hash_single_file(void)
12 {
13 static const char file_name[] = "new_file";
14 static const char file_contents[] = "new_file\n";
15 static const char file_hash[] = "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a";
16
17 git_oid expected_id, actual_id;
18
19 /* initialization */
20 git_oid_fromstr(&expected_id, file_hash);
21 cl_git_mkfile(file_name, file_contents);
22 cl_set_cleanup(&cleanup__remove_file, (void *)file_name);
23
24 cl_git_pass(git_odb_hashfile(&actual_id, file_name, GIT_OBJECT_BLOB));
25 cl_assert_equal_oid(&expected_id, &actual_id);
26 }
27
28 /* test retrieving OID from an empty file apart from the ODB */
29 void test_status_single__hash_single_empty_file(void)
30 {
31 static const char file_name[] = "new_empty_file";
32 static const char file_contents[] = "";
33 static const char file_hash[] = "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391";
34
35 git_oid expected_id, actual_id;
36
37 /* initialization */
38 git_oid_fromstr(&expected_id, file_hash);
39 cl_git_mkfile(file_name, file_contents);
40 cl_set_cleanup(&cleanup__remove_file, (void *)file_name);
41
42 cl_git_pass(git_odb_hashfile(&actual_id, file_name, GIT_OBJECT_BLOB));
43 cl_assert_equal_oid(&expected_id, &actual_id);
44 }
45