diff options
| author | Vicent Marti <tanoku@gmail.com> | 2011-09-16 05:12:56 +0200 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2011-09-16 05:13:44 +0200 |
| commit | 11385c3c4b91274fd8bbf3547b700ba8defabc08 (patch) | |
| tree | 5d220ab1a7b5fbc481a6629d9fea9a152efa1153 /tests-clay/status/single.c | |
| parent | d8b903dab0ab1a9fa6d8515825fa5dd19de68fca (diff) | |
| download | libgit2-11385c3c4b91274fd8bbf3547b700ba8defabc08.tar.gz | |
Add sample "Status" clay tests
Diffstat (limited to 'tests-clay/status/single.c')
| -rw-r--r-- | tests-clay/status/single.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests-clay/status/single.c b/tests-clay/status/single.c new file mode 100644 index 000000000..7800eef22 --- /dev/null +++ b/tests-clay/status/single.c @@ -0,0 +1,38 @@ +#include "clay_libgit2.h" +#include "posix.h" + +static void +cleanup__remove_file(void *_file) +{ + cl_must_pass(p_unlink((char *)_file)); +} + +static void +file_create(const char *filename, const char *content) +{ + int fd = p_creat(filename, 0644); + cl_assert(fd >= 0); + cl_must_pass(p_write(fd, content, strlen(content))); + cl_must_pass(p_close(fd)); +} + +/* test retrieving OID from a file apart from the ODB */ +void test_status_single__hash_single_file() +{ + static const char file_name[] = "new_file"; + static const char file_contents[] = "new_file\n"; + static const char file_hash[] = "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a"; + + git_oid expected_id, actual_id; + + /* initialization */ + git_oid_fromstr(&expected_id, file_hash); + file_create(file_name, file_contents); + cl_set_cleanup(&cleanup__remove_file, (void *)file_name); + + cl_git_pass(git_odb_hashfile(&actual_id, file_name, GIT_OBJ_BLOB)); + cl_assert(git_oid_cmp(&expected_id, &actual_id) == 0); +} + + + |
