Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/core/pqueue.c97
-rw-r--r--tests/index/tests.c42
-rw-r--r--tests/object/tree/write.c100
-rw-r--r--tests/repo/head.c2
-rw-r--r--tests/repo/message.c28
-rw-r--r--tests/revwalk/basic.c38
6 files changed, 278 insertions, 29 deletions
diff --git a/tests/core/pqueue.c b/tests/core/pqueue.c
new file mode 100644
index 000000000..d91dbb0cd
--- /dev/null
+++ b/tests/core/pqueue.c
@@ -0,0 +1,97 @@
+#include "clar_libgit2.h"
+#include "pqueue.h"
+
+static int cmp_ints(const void *v1, const void *v2)
+{
+ int i1 = *(int *)v1, i2 = *(int *)v2;
+ return (i1 < i2) ? -1 : (i1 > i2) ? 1 : 0;
+}
+
+void test_core_pqueue__items_are_put_in_order(void)
+{
+ git_pqueue pq;
+ int i, vals[20];
+
+ cl_git_pass(git_pqueue_init(&pq, 0, 20, cmp_ints));
+
+ for (i = 0; i < 20; ++i) {
+ if (i < 10)
+ vals[i] = 10 - i; /* 10 down to 1 */
+ else
+ vals[i] = i + 1; /* 11 up to 20 */
+
+ cl_git_pass(git_pqueue_insert(&pq, &vals[i]));
+ }
+
+ cl_assert_equal_i(20, git_pqueue_size(&pq));
+
+ for (i = 1; i <= 20; ++i) {
+ void *p = git_pqueue_pop(&pq);
+ cl_assert(p);
+ cl_assert_equal_i(i, *(int *)p);
+ }
+
+ cl_assert_equal_i(0, git_pqueue_size(&pq));
+
+ git_pqueue_free(&pq);
+}
+
+void test_core_pqueue__interleave_inserts_and_pops(void)
+{
+ git_pqueue pq;
+ int chunk, v, i, vals[200];
+
+ cl_git_pass(git_pqueue_init(&pq, 0, 20, cmp_ints));
+
+ for (v = 0, chunk = 20; chunk <= 200; chunk += 20) {
+ /* push the next 20 */
+ for (; v < chunk; ++v) {
+ vals[v] = (v & 1) ? 200 - v : v;
+ cl_git_pass(git_pqueue_insert(&pq, &vals[v]));
+ }
+
+ /* pop the lowest 10 */
+ for (i = 0; i < 10; ++i)
+ (void)git_pqueue_pop(&pq);
+ }
+
+ cl_assert_equal_i(100, git_pqueue_size(&pq));
+
+ /* at this point, we've popped 0-99 */
+
+ for (v = 100; v < 200; ++v) {
+ void *p = git_pqueue_pop(&pq);
+ cl_assert(p);
+ cl_assert_equal_i(v, *(int *)p);
+ }
+
+ cl_assert_equal_i(0, git_pqueue_size(&pq));
+
+ git_pqueue_free(&pq);
+}
+
+void test_core_pqueue__max_heap_size(void)
+{
+ git_pqueue pq;
+ int i, vals[100];
+
+ cl_git_pass(git_pqueue_init(&pq, GIT_PQUEUE_FIXED_SIZE, 50, cmp_ints));
+
+ for (i = 0; i < 100; ++i) {
+ vals[i] = (i & 1) ? 100 - i : i;
+ cl_git_pass(git_pqueue_insert(&pq, &vals[i]));
+ }
+
+ cl_assert_equal_i(50, git_pqueue_size(&pq));
+
+ for (i = 50; i < 100; ++i) {
+ void *p = git_pqueue_pop(&pq);
+ cl_assert(p);
+ cl_assert_equal_i(i, *(int *)p);
+ }
+
+ cl_assert_equal_i(0, git_pqueue_size(&pq));
+
+ git_pqueue_free(&pq);
+
+}
diff --git a/tests/index/tests.c b/tests/index/tests.c
index bd90bc557..6e28af1f7 100644
--- a/tests/index/tests.c
+++ b/tests/index/tests.c
@@ -80,7 +80,7 @@ void test_index_tests__empty_index(void)
cl_assert(index->on_disk == 0);
cl_assert(git_index_entrycount(index) == 0);
- cl_assert(index->entries.sorted);
+ cl_assert(git_vector_is_sorted(&index->entries));
git_index_free(index);
}
@@ -95,7 +95,7 @@ void test_index_tests__default_test_index(void)
cl_assert(index->on_disk);
cl_assert(git_index_entrycount(index) == index_entry_count);
- cl_assert(index->entries.sorted);
+ cl_assert(git_vector_is_sorted(&index->entries));
entries = (git_index_entry **)index->entries.contents;
@@ -118,7 +118,7 @@ void test_index_tests__gitgit_index(void)
cl_assert(index->on_disk);
cl_assert(git_index_entrycount(index) == index_entry_count_2);
- cl_assert(index->entries.sorted);
+ cl_assert(git_vector_is_sorted(&index->entries));
cl_assert(index->tree != NULL);
git_index_free(index);
@@ -195,7 +195,7 @@ void test_index_tests__sort1(void)
cl_git_pass(git_index_open(&index, "fake-index"));
/* FIXME: this test is slightly dumb */
- cl_assert(index->entries.sorted);
+ cl_assert(git_vector_is_sorted(&index->entries));
git_index_free(index);
}
@@ -543,3 +543,37 @@ void test_index_tests__corrupted_extension(void)
cl_git_fail_with(git_index_open(&index, TEST_INDEXBAD_PATH), GIT_ERROR);
}
+
+static void assert_index_is_sorted(git_index *index)
+{
+ git_vector *entries = &index->entries;
+ size_t i;
+
+ cl_assert(git_vector_is_sorted(entries));
+
+ for (i = 1; i < git_vector_length(entries); ++i) {
+ git_index_entry *prev = git_vector_get(entries, i - 1);
+ git_index_entry *curr = git_vector_get(entries, i);
+ cl_assert(index->entries._cmp(prev, curr) <= 0);
+ }
+}
+
+void test_index_tests__reload_while_ignoring_case(void)
+{
+ git_index *index;
+ unsigned int caps;
+
+ cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
+ assert_index_is_sorted(index);
+
+ caps = git_index_caps(index);
+ cl_git_pass(git_index_set_caps(index, caps &= ~GIT_INDEXCAP_IGNORE_CASE));
+ cl_git_pass(git_index_read(index, true));
+ assert_index_is_sorted(index);
+
+ cl_git_pass(git_index_set_caps(index, caps | GIT_INDEXCAP_IGNORE_CASE));
+ cl_git_pass(git_index_read(index, true));
+ assert_index_is_sorted(index);
+
+ git_index_free(index);
+}
diff --git a/tests/object/tree/write.c b/tests/object/tree/write.c
index 3bea0ed4d..45356e807 100644
--- a/tests/object/tree/write.c
+++ b/tests/object/tree/write.c
@@ -9,7 +9,7 @@ static const char *third_tree = "eb86d8b81d6adbd5290a935d6c9976882de98488";
static git_repository *g_repo;
-// Fixture setup and teardown
+/* Fixture setup and teardown */
void test_object_tree_write__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo");
@@ -22,7 +22,7 @@ void test_object_tree_write__cleanup(void)
void test_object_tree_write__from_memory(void)
{
- // write a tree from a memory
+ /* write a tree from a memory */
git_treebuilder *builder;
git_tree *tree;
git_oid id, bid, rid, id2;
@@ -31,7 +31,9 @@ void test_object_tree_write__from_memory(void)
git_oid_fromstr(&id2, second_tree);
git_oid_fromstr(&bid, blob_oid);
- //create a second tree from first tree using `git_treebuilder_insert` on REPOSITORY_FOLDER.
+ /* create a second tree from first tree using `git_treebuilder_insert`
+ * on REPOSITORY_FOLDER.
+ */
cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
cl_git_pass(git_treebuilder_create(&builder, tree));
@@ -61,7 +63,7 @@ void test_object_tree_write__from_memory(void)
void test_object_tree_write__subtree(void)
{
- // write a hierarchical tree from a memory
+ /* write a hierarchical tree from a memory */
git_treebuilder *builder;
git_tree *tree;
git_oid id, bid, subtree_id, id2, id3;
@@ -72,25 +74,25 @@ void test_object_tree_write__subtree(void)
git_oid_fromstr(&id3, third_tree);
git_oid_fromstr(&bid, blob_oid);
- //create subtree
+ /* create subtree */
cl_git_pass(git_treebuilder_create(&builder, NULL));
cl_git_pass(git_treebuilder_insert(
- NULL, builder, "new.txt", &bid, GIT_FILEMODE_BLOB)); //-V536
+ NULL, builder, "new.txt", &bid, GIT_FILEMODE_BLOB)); /* -V536 */
cl_git_pass(git_treebuilder_write(&subtree_id, g_repo, builder));
git_treebuilder_free(builder);
- // create parent tree
+ /* create parent tree */
cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
cl_git_pass(git_treebuilder_create(&builder, tree));
cl_git_pass(git_treebuilder_insert(
- NULL, builder, "new", &subtree_id, GIT_FILEMODE_TREE)); //-V536
+ NULL, builder, "new", &subtree_id, GIT_FILEMODE_TREE)); /* -V536 */
cl_git_pass(git_treebuilder_write(&id_hiearar, g_repo, builder));
git_treebuilder_free(builder);
git_tree_free(tree);
cl_assert(git_oid_cmp(&id_hiearar, &id3) == 0);
- // check data is correct
+ /* check data is correct */
cl_git_pass(git_tree_lookup(&tree, g_repo, &id_hiearar));
cl_assert(2 == git_tree_entrycount(tree));
git_tree_free(tree);
@@ -314,3 +316,83 @@ void test_object_tree_write__filtering(void)
git_tree_free(tree);
}
+
+void test_object_tree_write__cruel_paths(void)
+{
+ static const char *the_paths[] = {
+ "C:\\",
+ " : * ? \" \n < > |",
+ "a\\b",
+ "\\\\b\a",
+ ":\\",
+ "COM1",
+ "foo.aux",
+ REP1024("1234"), /* 4096 char string */
+ REP1024("12345678"), /* 8192 char string */
+ "\xC5\xAA\x6E\xC4\xAD\x63\xC5\x8D\x64\x65\xCC\xBD", /* Ūnĭcōde̽ */
+ NULL
+ };
+ git_treebuilder *builder;
+ git_tree *tree;
+ git_oid id, bid, subid;
+ const char **scan;
+ int count = 0, i, j;
+ git_tree_entry *te;
+
+ git_oid_fromstr(&bid, blob_oid);
+
+ /* create tree */
+ cl_git_pass(git_treebuilder_create(&builder, NULL));
+ for (scan = the_paths; *scan; ++scan) {
+ cl_git_pass(git_treebuilder_insert(
+ NULL, builder, *scan, &bid, GIT_FILEMODE_BLOB));
+ count++;
+ }
+ cl_git_pass(git_treebuilder_write(&id, g_repo, builder));
+ git_treebuilder_free(builder);
+
+ /* check data is correct */
+ cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
+
+ cl_assert_equal_i(count, git_tree_entrycount(tree));
+
+ for (scan = the_paths; *scan; ++scan) {
+ const git_tree_entry *cte = git_tree_entry_byname(tree, *scan);
+ cl_assert(cte != NULL);
+ cl_assert_equal_s(*scan, git_tree_entry_name(cte));
+ }
+ for (scan = the_paths; *scan; ++scan) {
+ cl_git_pass(git_tree_entry_bypath(&te, tree, *scan));
+ cl_assert_equal_s(*scan, git_tree_entry_name(te));
+ git_tree_entry_free(te);
+ }
+
+ git_tree_free(tree);
+
+ /* let's try longer paths */
+ cl_git_pass(git_treebuilder_create(&builder, NULL));
+ for (scan = the_paths; *scan; ++scan) {
+ cl_git_pass(git_treebuilder_insert(
+ NULL, builder, *scan, &id, GIT_FILEMODE_TREE));
+ }
+ cl_git_pass(git_treebuilder_write(&subid, g_repo, builder));
+ git_treebuilder_free(builder);
+
+ /* check data is correct */
+ cl_git_pass(git_tree_lookup(&tree, g_repo, &subid));
+
+ cl_assert_equal_i(count, git_tree_entrycount(tree));
+
+ for (i = 0; i < count; ++i) {
+ for (j = 0; j < count; ++j) {
+ git_buf b = GIT_BUF_INIT;
+ cl_git_pass(git_buf_joinpath(&b, the_paths[i], the_paths[j]));
+ cl_git_pass(git_tree_entry_bypath(&te, tree, b.ptr));
+ cl_assert_equal_s(the_paths[j], git_tree_entry_name(te));
+ git_tree_entry_free(te);
+ git_buf_free(&b);
+ }
+ }
+
+ git_tree_free(tree);
+}
diff --git a/tests/repo/head.c b/tests/repo/head.c
index 8ea9a0f42..127176d12 100644
--- a/tests/repo/head.c
+++ b/tests/repo/head.c
@@ -200,7 +200,7 @@ static void test_reflog(git_repository *repo, size_t idx,
const char *email, const char *message)
{
git_reflog *log;
- git_reflog_entry *entry;
+ const git_reflog_entry *entry;
cl_git_pass(git_reflog_read(&log, repo, "HEAD"));
entry = git_reflog_entry_byindex(log, idx);
diff --git a/tests/repo/message.c b/tests/repo/message.c
index 57e8e5f4d..87574590b 100644
--- a/tests/repo/message.c
+++ b/tests/repo/message.c
@@ -4,38 +4,36 @@
#include "posix.h"
static git_repository *_repo;
-static git_buf _path;
-static git_buf _actual;
void test_repo_message__initialize(void)
{
- _repo = cl_git_sandbox_init("testrepo.git");
- git_buf_init(&_actual, 0);
+ _repo = cl_git_sandbox_init("testrepo.git");
}
void test_repo_message__cleanup(void)
{
- cl_git_sandbox_cleanup();
- git_buf_free(&_path);
- git_buf_free(&_actual);
+ cl_git_sandbox_cleanup();
}
void test_repo_message__none(void)
{
- cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(&_actual, _repo));
+ git_buf actual = GIT_BUF_INIT;
+ cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(&actual, _repo));
}
void test_repo_message__message(void)
{
+ git_buf path = GIT_BUF_INIT, actual = GIT_BUF_INIT;
const char expected[] = "Test\n\nThis is a test of the emergency broadcast system\n";
- cl_git_pass(git_buf_joinpath(&_path, git_repository_path(_repo), "MERGE_MSG"));
- cl_git_mkfile(git_buf_cstr(&_path), expected);
+ cl_git_pass(git_buf_joinpath(&path, git_repository_path(_repo), "MERGE_MSG"));
+ cl_git_mkfile(git_buf_cstr(&path), expected);
- cl_git_pass(git_repository_message(&_actual, _repo));
- cl_assert_equal_s(expected, _actual);
- git_buf_free(&_actual);
+ cl_git_pass(git_repository_message(&actual, _repo));
+ cl_assert_equal_s(expected, git_buf_cstr(&actual));
+ git_buf_free(&actual);
- cl_git_pass(p_unlink(git_buf_cstr(&_path)));
- cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(&_actual, _repo));
+ cl_git_pass(p_unlink(git_buf_cstr(&path)));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(&actual, _repo));
+ git_buf_free(&path);
}
diff --git a/tests/revwalk/basic.c b/tests/revwalk/basic.c
index 6d55aed54..9fe8a350b 100644
--- a/tests/revwalk/basic.c
+++ b/tests/revwalk/basic.c
@@ -252,3 +252,41 @@ void test_revwalk_basic__push_range(void)
cl_git_pass(git_revwalk_push_range(_walk, "9fd738e~2..9fd738e"));
cl_git_pass(test_walk_only(_walk, commit_sorting_segment, 1));
}
+
+void test_revwalk_basic__push_mixed(void)
+{
+ git_oid oid;
+ int i = 0;
+
+ revwalk_basic_setup_walk(NULL);
+
+ git_revwalk_reset(_walk);
+ git_revwalk_sorting(_walk, 0);
+ cl_git_pass(git_revwalk_push_glob(_walk, "tags"));
+
+ while (git_revwalk_next(&oid, _walk) == 0) {
+ i++;
+ }
+
+ /* git rev-list --count --glob=tags #=> 9 */
+ cl_assert_equal_i(9, i);
+}
+
+void test_revwalk_basic__push_all(void)
+{
+ git_oid oid;
+ int i = 0;
+
+ revwalk_basic_setup_walk(NULL);
+
+ git_revwalk_reset(_walk);
+ git_revwalk_sorting(_walk, 0);
+ cl_git_pass(git_revwalk_push_glob(_walk, "*"));
+
+ while (git_revwalk_next(&oid, _walk) == 0) {
+ i++;
+ }
+
+ /* git rev-list --count --all #=> 15 */
+ cl_assert_equal_i(15, i);
+}