diff options
| author | Vicent Marti <tanoku@gmail.com> | 2011-02-22 15:15:35 +0200 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2011-02-22 15:19:35 +0200 |
| commit | 4378e8d470abae5e9e8f32f98869516c8b86b191 (patch) | |
| tree | 9f18697d1c58a09f52850b4185a2d58866963c3c /tests/test_helpers.c | |
| parent | 5591ea15a50d3214830a3d152a78a34bcb5f1966 (diff) | |
| download | libgit2-4378e8d470abae5e9e8f32f98869516c8b86b191.tar.gz | |
Add unit test for writing a big index file
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'tests/test_helpers.c')
| -rw-r--r-- | tests/test_helpers.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/test_helpers.c b/tests/test_helpers.c index 5fd9a565a..c93d31b57 100644 --- a/tests/test_helpers.c +++ b/tests/test_helpers.c @@ -131,3 +131,47 @@ int cmp_objects(git_rawobj *o, object_data *d) return -1; return 0; } + +int copy_file(const char *src, const char *dst) +{ + gitfo_buf source_buf; + git_file dst_fd; + int error = GIT_ERROR; + + if (gitfo_read_file(&source_buf, src) < GIT_SUCCESS) + return GIT_ENOTFOUND; + + dst_fd = gitfo_creat(dst, 0644); + if (dst_fd < 0) + goto cleanup; + + error = gitfo_write(dst_fd, source_buf.data, source_buf.len); + +cleanup: + gitfo_free_buf(&source_buf); + gitfo_close(dst_fd); + + return error; +} + +int cmp_files(const char *a, const char *b) +{ + gitfo_buf buf_a, buf_b; + int error = GIT_ERROR; + + if (gitfo_read_file(&buf_a, a) < GIT_SUCCESS) + return GIT_ERROR; + + if (gitfo_read_file(&buf_b, b) < GIT_SUCCESS) { + gitfo_free_buf(&buf_a); + return GIT_ERROR; + } + + if (buf_a.len == buf_b.len && !memcmp(buf_a.data, buf_b.data, buf_a.len)) + error = GIT_SUCCESS; + + gitfo_free_buf(&buf_a); + gitfo_free_buf(&buf_b); + + return error; +} |
