Merge remote-tracking branch 'nulltoken/topic/oid-generation' into development Conflicts: tests-clay/clay.h tests-clay/clay_main.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
diff --git a/tests-clay/clay.h b/tests-clay/clay.h
index 7afc250..bdb11e8 100644
--- a/tests-clay/clay.h
+++ b/tests-clay/clay.h
@@ -159,6 +159,9 @@ extern void test_object_raw_size__validate_oid_size(void);
extern void test_object_raw_type2string__check_type_is_loose(void);
extern void test_object_raw_type2string__convert_string_to_type(void);
extern void test_object_raw_type2string__convert_type_to_string(void);
+extern void test_object_tree_buildfromindex__cleanup(void);
+extern void test_object_tree_buildfromindex__generate_predictable_object_ids(void);
+extern void test_object_tree_buildfromindex__initialize(void);
extern void test_object_tree_diff__addition(void);
extern void test_object_tree_diff__cleanup(void);
extern void test_object_tree_diff__deletion(void);
diff --git a/tests-clay/clay_main.c b/tests-clay/clay_main.c
index b8fde20..93e15f4 100644
--- a/tests-clay/clay_main.c
+++ b/tests-clay/clay_main.c
@@ -246,6 +246,9 @@ static const struct clay_func _clay_cb_object_raw_type2string[] = {
{"convert_string_to_type", &test_object_raw_type2string__convert_string_to_type},
{"convert_type_to_string", &test_object_raw_type2string__convert_type_to_string}
};
+static const struct clay_func _clay_cb_object_tree_buildfromindex[] = {
+ {"generate_predictable_object_ids", &test_object_tree_buildfromindex__generate_predictable_object_ids}
+};
static const struct clay_func _clay_cb_object_tree_diff[] = {
{"addition", &test_object_tree_diff__addition},
{"deletion", &test_object_tree_diff__deletion},
@@ -445,6 +448,12 @@ static const struct clay_suite _clay_suites[] = {
_clay_cb_object_raw_type2string, 3
},
{
+ "object::tree::buildfromindex",
+ {"initialize", &test_object_tree_buildfromindex__initialize},
+ {"cleanup", &test_object_tree_buildfromindex__cleanup},
+ _clay_cb_object_tree_buildfromindex, 1
+ },
+ {
"object::tree::diff",
{"initialize", &test_object_tree_diff__initialize},
{"cleanup", &test_object_tree_diff__cleanup},
@@ -506,8 +515,8 @@ static const struct clay_suite _clay_suites[] = {
}
};
-static size_t _clay_suite_count = 35;
-static size_t _clay_callback_count = 118;
+static size_t _clay_suite_count = 36;
+static size_t _clay_callback_count = 119;
/* Core test functions */
static void
diff --git a/tests-clay/object/tree/buildfromindex.c b/tests-clay/object/tree/buildfromindex.c
new file mode 100644
index 0000000..d4a5206
--- /dev/null
+++ b/tests-clay/object/tree/buildfromindex.c
@@ -0,0 +1,60 @@
+#include "clay_libgit2.h"
+#include "posix.h"
+
+static git_repository *repo;
+
+static void file_create(const char *filename, const char *content)
+{
+ int fd;
+
+ fd = p_creat(filename, 0666);
+ cl_assert(fd != 0);
+ cl_git_pass(p_write(fd, content, strlen(content)));
+ cl_git_pass(p_close(fd));
+}
+
+void test_object_tree_buildfromindex__initialize(void)
+{
+ cl_fixture("treebuilder");
+ cl_git_pass(git_repository_init(&repo, "treebuilder/", 0));
+ cl_git_pass(git_repository_open(&repo, "treebuilder/.git"));
+ cl_assert(repo != NULL);
+}
+
+void test_object_tree_buildfromindex__cleanup(void)
+{
+ git_repository_free(repo);
+ cl_fixture_cleanup("treebuilder");
+}
+
+void test_object_tree_buildfromindex__generate_predictable_object_ids(void)
+{
+ git_index *index;
+ git_oid blob_oid, tree_oid, expected_tree_oid;
+ git_index_entry *entry;
+
+ /*
+ * Add a new file to the index
+ */
+ cl_git_pass(git_repository_index(&index, repo));
+
+ file_create("treebuilder/test.txt", "test\n");
+ cl_git_pass(git_index_add(index, "test.txt", 0));
+
+ entry = git_index_get(index, 0);
+
+ /* $ echo "test" | git hash-object --stdin */
+ cl_git_pass(git_oid_fromstr(&blob_oid, "9daeafb9864cf43055ae93beb0afd6c7d144bfa4"));
+
+ cl_assert(git_oid_cmp(&blob_oid, &entry->oid) == 0);
+
+ /*
+ * Build the tree from the index
+ */
+ cl_git_pass(git_tree_create_fromindex(&tree_oid, index));
+
+ cl_git_pass(git_oid_fromstr(&expected_tree_oid, "2b297e643c551e76cfa1f93810c50811382f9117"));
+ cl_assert(git_oid_cmp(&expected_tree_oid, &tree_oid) == 0);
+
+ git_index_free(index);
+}