summaryrefslogtreecommitdiff
path: root/tests/test_helpers.c
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2010-10-07 00:42:55 +0300
committerVicent Marti <tanoku@gmail.com>2010-10-07 00:42:55 +0300
commit0ba7a0318652e5e89101e9ee72cb1356c21cef56 (patch)
tree45c5b86689315d68c238144805016b5a28bc81c8 /tests/test_helpers.c
parentec25391dbb5ee6800b48362deadd73599701224f (diff)
downloadlibgit2-0ba7a0318652e5e89101e9ee72cb1356c21cef56.tar.gz
Add unit tests for object write-back
Basic write-back & in-memory editing for objects is now tested in t0403 (commits), t0802 (tags) and t0902 (trees). Add new helper functions in test_helpers.c to remove the loose objects created when doing write-back tests. Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'tests/test_helpers.c')
-rw-r--r--tests/test_helpers.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/test_helpers.c b/tests/test_helpers.c
index e7c26926e..08434b8e1 100644
--- a/tests/test_helpers.c
+++ b/tests/test_helpers.c
@@ -26,6 +26,8 @@
#include "common.h"
#include "test_helpers.h"
#include "fileops.h"
+#include "git/oid.h"
+#include "git/repository.h"
int write_object_data(char *file, void *data, size_t len)
{
@@ -82,6 +84,40 @@ int remove_object_files(const char *odb_dir, object_data *d)
return 0;
}
+int remove_loose_object(const char *odb_dir, git_object *object)
+{
+ char *ptr, *full_path, *top_folder;
+ int path_length;
+
+ assert(odb_dir && object);
+
+ path_length = strlen(odb_dir);
+ ptr = full_path = git__malloc(path_length + GIT_OID_HEXSZ + 3);
+
+ strcpy(ptr, odb_dir);
+ ptr = top_folder = ptr + path_length;
+ *ptr++ = '/';
+ git_oid_pathfmt(ptr, git_object_id(object));
+ ptr += GIT_OID_HEXSZ + 1;
+ *ptr = 0;
+
+ if (gitfo_unlink(full_path) < 0) {
+ fprintf(stderr, "can't delete object file \"%s\"\n", full_path);
+ return -1;
+ }
+
+ *top_folder = 0;
+
+ if ((gitfo_rmdir(full_path) < 0) && (errno != ENOTEMPTY)) {
+ fprintf(stderr, "can't remove object directory \"%s\"\n", full_path);
+ return -1;
+ }
+
+ free(full_path);
+
+ return GIT_SUCCESS;
+}
+
int cmp_objects(git_rawobj *o, object_data *d)
{
if (o->type != git_obj_string_to_type(d->type))