summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/attr/file.c16
-rw-r--r--tests/attr/lookup.c16
-rw-r--r--tests/threads/diff.c49
-rw-r--r--tests/threads/iterator.c49
-rw-r--r--tests/threads/thread_helpers.c44
-rw-r--r--tests/threads/thread_helpers.h8
6 files changed, 122 insertions, 60 deletions
diff --git a/tests/attr/file.c b/tests/attr/file.c
index 4eb1d22fe..e35957b51 100644
--- a/tests/attr/file.c
+++ b/tests/attr/file.c
@@ -11,9 +11,9 @@ void test_attr_file__simple_read(void)
git_attr_assignment *assign;
git_attr_rule *rule;
- cl_git_pass(git_attr_file__new_and_load(&file, cl_fixture("attr/attr0")));
+ cl_git_pass(git_attr_file__load_standalone(&file, cl_fixture("attr/attr0")));
- cl_assert_equal_s(cl_fixture("attr/attr0"), file->key + 2);
+ cl_assert_equal_s(cl_fixture("attr/attr0"), file->ce->path);
cl_assert(file->rules.length == 1);
rule = get_rule(0);
@@ -37,9 +37,9 @@ void test_attr_file__match_variants(void)
git_attr_rule *rule;
git_attr_assignment *assign;
- cl_git_pass(git_attr_file__new_and_load(&file, cl_fixture("attr/attr1")));
+ cl_git_pass(git_attr_file__load_standalone(&file, cl_fixture("attr/attr1")));
- cl_assert_equal_s(cl_fixture("attr/attr1"), file->key + 2);
+ cl_assert_equal_s(cl_fixture("attr/attr1"), file->ce->path);
cl_assert(file->rules.length == 10);
/* let's do a thorough check of this rule, then just verify
@@ -121,9 +121,9 @@ void test_attr_file__assign_variants(void)
git_attr_rule *rule;
git_attr_assignment *assign;
- cl_git_pass(git_attr_file__new_and_load(&file, cl_fixture("attr/attr2")));
+ cl_git_pass(git_attr_file__load_standalone(&file, cl_fixture("attr/attr2")));
- cl_assert_equal_s(cl_fixture("attr/attr2"), file->key + 2);
+ cl_assert_equal_s(cl_fixture("attr/attr2"), file->ce->path);
cl_assert(file->rules.length == 11);
check_one_assign(file, 0, 0, "pat0", "simple", EXPECT_TRUE, NULL);
@@ -187,8 +187,8 @@ void test_attr_file__check_attr_examples(void)
git_attr_rule *rule;
git_attr_assignment *assign;
- cl_git_pass(git_attr_file__new_and_load(&file, cl_fixture("attr/attr3")));
- cl_assert_equal_s(cl_fixture("attr/attr3"), file->key + 2);
+ cl_git_pass(git_attr_file__load_standalone(&file, cl_fixture("attr/attr3")));
+ cl_assert_equal_s(cl_fixture("attr/attr3"), file->ce->path);
cl_assert(file->rules.length == 3);
rule = get_rule(0);
diff --git a/tests/attr/lookup.c b/tests/attr/lookup.c
index 200bdd2c7..099597efc 100644
--- a/tests/attr/lookup.c
+++ b/tests/attr/lookup.c
@@ -9,8 +9,8 @@ void test_attr_lookup__simple(void)
git_attr_path path;
const char *value = NULL;
- cl_git_pass(git_attr_file__new_and_load(&file, cl_fixture("attr/attr0")));
- cl_assert_equal_s(cl_fixture("attr/attr0"), file->key + 2);
+ cl_git_pass(git_attr_file__load_standalone(&file, cl_fixture("attr/attr0")));
+ cl_assert_equal_s(cl_fixture("attr/attr0"), file->ce->path);
cl_assert(file->rules.length == 1);
cl_git_pass(git_attr_path__init(&path, "test", NULL));
@@ -129,8 +129,8 @@ void test_attr_lookup__match_variants(void)
{ NULL, NULL, 0, NULL }
};
- cl_git_pass(git_attr_file__new_and_load(&file, cl_fixture("attr/attr1")));
- cl_assert_equal_s(cl_fixture("attr/attr1"), file->key + 2);
+ cl_git_pass(git_attr_file__load_standalone(&file, cl_fixture("attr/attr1")));
+ cl_assert_equal_s(cl_fixture("attr/attr1"), file->ce->path);
cl_assert(file->rules.length == 10);
cl_git_pass(git_attr_path__init(&path, "/testing/for/pat0", NULL));
@@ -190,7 +190,7 @@ void test_attr_lookup__assign_variants(void)
{ NULL, NULL, 0, NULL }
};
- cl_git_pass(git_attr_file__new_and_load(&file, cl_fixture("attr/attr2")));
+ cl_git_pass(git_attr_file__load_standalone(&file, cl_fixture("attr/attr2")));
cl_assert(file->rules.length == 11);
run_test_cases(file, cases, 0);
@@ -225,7 +225,7 @@ void test_attr_lookup__check_attr_examples(void)
{ NULL, NULL, 0, NULL }
};
- cl_git_pass(git_attr_file__new_and_load(&file, cl_fixture("attr/attr3")));
+ cl_git_pass(git_attr_file__load_standalone(&file, cl_fixture("attr/attr3")));
cl_assert(file->rules.length == 3);
run_test_cases(file, cases, 0);
@@ -250,9 +250,9 @@ void test_attr_lookup__from_buffer(void)
{ NULL, NULL, 0, NULL }
};
- cl_git_pass(git_attr_file__new(&file, 0, NULL, NULL));
+ cl_git_pass(git_attr_file__new(&file, NULL, 0));
- cl_git_pass(git_attr_file__parse_buffer(NULL, NULL, "a* foo\nabc bar\n* baz", file));
+ cl_git_pass(git_attr_file__parse_buffer(NULL, file, "a* foo\nabc bar\n* baz", NULL));
cl_assert(file->rules.length == 3);
diff --git a/tests/threads/diff.c b/tests/threads/diff.c
index 5565c4bf1..562eec71c 100644
--- a/tests/threads/diff.c
+++ b/tests/threads/diff.c
@@ -1,59 +1,22 @@
#include "clar_libgit2.h"
-#include "thread-utils.h"
+#include "thread_helpers.h"
static git_repository *_repo;
static git_tree *_a, *_b;
static git_atomic _counts[4];
static int _check_counts;
+#define THREADS 20
+
void test_threads_diff__cleanup(void)
{
cl_git_sandbox_cleanup();
}
-static void run_in_parallel(
- int repeats, int threads, void *(*func)(void *),
- void (*before_test)(void), void (*after_test)(void))
-{
- int r, t, *id = git__calloc(threads, sizeof(int));
-#ifdef GIT_THREADS
- git_thread *th = git__calloc(threads, sizeof(git_thread));
- cl_assert(th != NULL);
-#else
- void *th = NULL;
-#endif
-
- cl_assert(id != NULL);
-
- for (r = 0; r < repeats; ++r) {
- _repo = cl_git_sandbox_reopen(); /* reopen sandbox to flush caches */
-
- if (before_test) before_test();
-
- for (t = 0; t < threads; ++t) {
- id[t] = t;
-#ifdef GIT_THREADS
- cl_git_pass(git_thread_create(&th[t], NULL, func, &id[t]));
-#else
- cl_assert(func(&id[t]) == &id[t]);
-#endif
- }
-
-#ifdef GIT_THREADS
- for (t = 0; t < threads; ++t)
- cl_git_pass(git_thread_join(th[t], NULL));
- memset(th, 0, threads * sizeof(git_thread));
-#endif
-
- if (after_test) after_test();
- }
-
- git__free(id);
- git__free(th);
-}
-
static void setup_trees(void)
{
+ _repo = cl_git_sandbox_reopen(); /* reopen sandbox to flush caches */
+
cl_git_pass(git_revparse_single(
(git_object **)&_a, _repo, "0017bd4ab1^{tree}"));
cl_git_pass(git_revparse_single(
@@ -62,8 +25,6 @@ static void setup_trees(void)
memset(_counts, 0, sizeof(_counts));
}
-#define THREADS 20
-
static void free_trees(void)
{
git_tree_free(_a); _a = NULL;
diff --git a/tests/threads/iterator.c b/tests/threads/iterator.c
new file mode 100644
index 000000000..4dd251fa5
--- /dev/null
+++ b/tests/threads/iterator.c
@@ -0,0 +1,49 @@
+#include "clar_libgit2.h"
+#include "thread_helpers.h"
+#include "iterator.h"
+
+static git_repository *_repo;
+
+void test_threads_iterator__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+static void *run_workdir_iterator(void *arg)
+{
+ int error = 0, thread = *(int *)arg;
+ git_iterator *iter;
+ const git_index_entry *entry = NULL;
+
+ cl_git_pass(git_iterator_for_workdir(
+ &iter, _repo, GIT_ITERATOR_DONT_AUTOEXPAND, NULL, NULL));
+
+ while (!error) {
+ if (entry && entry->mode == GIT_FILEMODE_TREE) {
+ error = git_iterator_advance_into(&entry, iter);
+
+ if (error == GIT_ENOTFOUND)
+ error = git_iterator_advance(&entry, iter);
+ } else {
+ error = git_iterator_advance(&entry, iter);
+ }
+
+ if (!error)
+ (void)git_iterator_current_is_ignored(iter);
+ }
+
+ cl_assert_equal_i(GIT_ITEROVER, error);
+
+ git_iterator_free(iter);
+
+ return arg;
+}
+
+
+void test_threads_iterator__workdir(void)
+{
+ _repo = cl_git_sandbox_init("status");
+
+ run_in_parallel(
+ 1, 20, run_workdir_iterator, NULL, NULL);
+}
diff --git a/tests/threads/thread_helpers.c b/tests/threads/thread_helpers.c
new file mode 100644
index 000000000..25370dddb
--- /dev/null
+++ b/tests/threads/thread_helpers.c
@@ -0,0 +1,44 @@
+#include "clar_libgit2.h"
+#include "thread_helpers.h"
+
+void run_in_parallel(
+ int repeats,
+ int threads,
+ void *(*func)(void *),
+ void (*before_test)(void),
+ void (*after_test)(void))
+{
+ int r, t, *id = git__calloc(threads, sizeof(int));
+#ifdef GIT_THREADS
+ git_thread *th = git__calloc(threads, sizeof(git_thread));
+ cl_assert(th != NULL);
+#else
+ void *th = NULL;
+#endif
+
+ cl_assert(id != NULL);
+
+ for (r = 0; r < repeats; ++r) {
+ if (before_test) before_test();
+
+ for (t = 0; t < threads; ++t) {
+ id[t] = t;
+#ifdef GIT_THREADS
+ cl_git_pass(git_thread_create(&th[t], NULL, func, &id[t]));
+#else
+ cl_assert(func(&id[t]) == &id[t]);
+#endif
+ }
+
+#ifdef GIT_THREADS
+ for (t = 0; t < threads; ++t)
+ cl_git_pass(git_thread_join(th[t], NULL));
+ memset(th, 0, threads * sizeof(git_thread));
+#endif
+
+ if (after_test) after_test();
+ }
+
+ git__free(id);
+ git__free(th);
+}
diff --git a/tests/threads/thread_helpers.h b/tests/threads/thread_helpers.h
new file mode 100644
index 000000000..3c13cfb6b
--- /dev/null
+++ b/tests/threads/thread_helpers.h
@@ -0,0 +1,8 @@
+#include "thread-utils.h"
+
+void run_in_parallel(
+ int repeats,
+ int threads,
+ void *(*func)(void *),
+ void (*before_test)(void),
+ void (*after_test)(void));