diff options
author | Vicent Martà <tanoku@gmail.com> | 2012-01-24 20:35:15 -0800 |
---|---|---|
committer | Vicent Martà <tanoku@gmail.com> | 2012-01-24 20:35:15 -0800 |
commit | 3fd1520cd4d8b4d6b6493a7d3dc393ffd9abf1db (patch) | |
tree | 51b29f5d8ffeb31ba751ab2a099e4f2a32d4be07 /tests-clay | |
parent | a9fe8ae0ee1ddcc289fad53f1a671f02a3e9a88f (diff) | |
download | libgit2-3fd1520cd4d8b4d6b6493a7d3dc393ffd9abf1db.tar.gz |
Rename the Clay test suite to Clar
Clay is the name of a programming language on the makings, and we want
to avoid confusions. Sorry for the huge diff!
Diffstat (limited to 'tests-clay')
53 files changed, 0 insertions, 6193 deletions
diff --git a/tests-clay/README.md b/tests-clay/README.md deleted file mode 100644 index f7720610a..000000000 --- a/tests-clay/README.md +++ /dev/null @@ -1,22 +0,0 @@ -Writing Clay tests for libgit2 -============================== - -For information on the Clay testing framework and a detailed introduction -please visit: - -https://github.com/tanoku/clay - - -* Write your modules and tests. Use good, meaningful names. - -* Make sure you actually build the tests by setting: - - cmake -DBUILD_CLAY=ON build/ - -* Test: - - ./build/libgit2_clay - -* Make sure everything is fine. - -* Send your pull request. That's it. diff --git a/tests-clay/attr/file.c b/tests-clay/attr/file.c deleted file mode 100644 index 652ee273c..000000000 --- a/tests-clay/attr/file.c +++ /dev/null @@ -1,229 +0,0 @@ -#include "clay_libgit2.h" -#include "attr_file.h" - -#define get_rule(X) ((git_attr_rule *)git_vector_get(&file->rules,(X))) -#define get_assign(R,Y) ((git_attr_assignment *)git_vector_get(&(R)->assigns,(Y))) - -void test_attr_file__simple_read(void) -{ - git_attr_file *file; - git_attr_assignment *assign; - git_attr_rule *rule; - - cl_git_pass(git_attr_file__new(&file)); - cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr0"), file)); - cl_assert_strequal(cl_fixture("attr/attr0"), file->path); - cl_assert(file->rules.length == 1); - - rule = get_rule(0); - cl_assert(rule != NULL); - cl_assert_strequal("*", rule->match.pattern); - cl_assert(rule->match.length == 1); - cl_assert(rule->match.flags == 0); - - cl_assert(rule->assigns.length == 1); - assign = get_assign(rule, 0); - cl_assert(assign != NULL); - cl_assert_strequal("binary", assign->name); - cl_assert(assign->value == GIT_ATTR_TRUE); - cl_assert(!assign->is_allocated); - - git_attr_file__free(file); -} - -void test_attr_file__match_variants(void) -{ - git_attr_file *file; - git_attr_rule *rule; - git_attr_assignment *assign; - - cl_git_pass(git_attr_file__new(&file)); - cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr1"), file)); - cl_assert_strequal(cl_fixture("attr/attr1"), file->path); - cl_assert(file->rules.length == 10); - - /* let's do a thorough check of this rule, then just verify - * the things that are unique for the later rules - */ - rule = get_rule(0); - cl_assert(rule); - cl_assert_strequal("pat0", rule->match.pattern); - cl_assert(rule->match.length == strlen("pat0")); - cl_assert(rule->match.flags == 0); - cl_assert(rule->assigns.length == 1); - assign = get_assign(rule,0); - cl_assert_strequal("attr0", assign->name); - cl_assert(assign->name_hash == git_attr_file__name_hash(assign->name)); - cl_assert(assign->value == GIT_ATTR_TRUE); - cl_assert(!assign->is_allocated); - - rule = get_rule(1); - cl_assert_strequal("pat1", rule->match.pattern); - cl_assert(rule->match.length == strlen("pat1")); - cl_assert(rule->match.flags == GIT_ATTR_FNMATCH_NEGATIVE); - - rule = get_rule(2); - cl_assert_strequal("pat2", rule->match.pattern); - cl_assert(rule->match.length == strlen("pat2")); - cl_assert(rule->match.flags == GIT_ATTR_FNMATCH_DIRECTORY); - - rule = get_rule(3); - cl_assert_strequal("pat3dir/pat3file", rule->match.pattern); - cl_assert(rule->match.flags == GIT_ATTR_FNMATCH_FULLPATH); - - rule = get_rule(4); - cl_assert_strequal("pat4.*", rule->match.pattern); - cl_assert(rule->match.flags == 0); - - rule = get_rule(5); - cl_assert_strequal("*.pat5", rule->match.pattern); - - rule = get_rule(7); - cl_assert_strequal("pat7[a-e]??[xyz]", rule->match.pattern); - cl_assert(rule->assigns.length == 1); - assign = get_assign(rule,0); - cl_assert_strequal("attr7", assign->name); - cl_assert(assign->value == GIT_ATTR_TRUE); - - rule = get_rule(8); - cl_assert_strequal("pat8 with spaces", rule->match.pattern); - cl_assert(rule->match.length == strlen("pat8 with spaces")); - cl_assert(rule->match.flags == 0); - - rule = get_rule(9); - cl_assert_strequal("pat9", rule->match.pattern); - - git_attr_file__free(file); -} - -static void check_one_assign( - git_attr_file *file, - int rule_idx, - int assign_idx, - const char *pattern, - const char *name, - const char *value, - int is_allocated) -{ - git_attr_rule *rule = get_rule(rule_idx); - git_attr_assignment *assign = get_assign(rule, assign_idx); - - cl_assert_strequal(pattern, rule->match.pattern); - cl_assert(rule->assigns.length == 1); - cl_assert_strequal(name, assign->name); - cl_assert(assign->name_hash == git_attr_file__name_hash(assign->name)); - cl_assert(assign->is_allocated == is_allocated); - if (is_allocated) - cl_assert_strequal(value, assign->value); - else - cl_assert(assign->value == value); -} - -void test_attr_file__assign_variants(void) -{ - git_attr_file *file; - git_attr_rule *rule; - git_attr_assignment *assign; - - cl_git_pass(git_attr_file__new(&file)); - cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr2"), file)); - cl_assert_strequal(cl_fixture("attr/attr2"), file->path); - cl_assert(file->rules.length == 11); - - check_one_assign(file, 0, 0, "pat0", "simple", GIT_ATTR_TRUE, 0); - check_one_assign(file, 1, 0, "pat1", "neg", GIT_ATTR_FALSE, 0); - check_one_assign(file, 2, 0, "*", "notundef", GIT_ATTR_TRUE, 0); - check_one_assign(file, 3, 0, "pat2", "notundef", NULL, 0); - check_one_assign(file, 4, 0, "pat3", "assigned", "test-value", 1); - check_one_assign(file, 5, 0, "pat4", "rule-with-more-chars", "value-with-more-chars", 1); - check_one_assign(file, 6, 0, "pat5", "empty", GIT_ATTR_TRUE, 0); - check_one_assign(file, 7, 0, "pat6", "negempty", GIT_ATTR_FALSE, 0); - - rule = get_rule(8); - cl_assert_strequal("pat7", rule->match.pattern); - cl_assert(rule->assigns.length == 5); - /* assignments will be sorted by hash value, so we have to do - * lookups by search instead of by position - */ - assign = git_attr_rule__lookup_assignment(rule, "multiple"); - cl_assert(assign); - cl_assert_strequal("multiple", assign->name); - cl_assert(assign->value == GIT_ATTR_TRUE); - assign = git_attr_rule__lookup_assignment(rule, "single"); - cl_assert(assign); - cl_assert_strequal("single", assign->name); - cl_assert(assign->value == GIT_ATTR_FALSE); - assign = git_attr_rule__lookup_assignment(rule, "values"); - cl_assert(assign); - cl_assert_strequal("values", assign->name); - cl_assert_strequal("1", assign->value); - assign = git_attr_rule__lookup_assignment(rule, "also"); - cl_assert(assign); - cl_assert_strequal("also", assign->name); - cl_assert_strequal("a-really-long-value/*", assign->value); - assign = git_attr_rule__lookup_assignment(rule, "happy"); - cl_assert(assign); - cl_assert_strequal("happy", assign->name); - cl_assert_strequal("yes!", assign->value); - assign = git_attr_rule__lookup_assignment(rule, "other"); - cl_assert(!assign); - - rule = get_rule(9); - cl_assert_strequal("pat8", rule->match.pattern); - cl_assert(rule->assigns.length == 2); - assign = git_attr_rule__lookup_assignment(rule, "again"); - cl_assert(assign); - cl_assert_strequal("again", assign->name); - cl_assert(assign->value == GIT_ATTR_TRUE); - assign = git_attr_rule__lookup_assignment(rule, "another"); - cl_assert(assign); - cl_assert_strequal("another", assign->name); - cl_assert_strequal("12321", assign->value); - - check_one_assign(file, 10, 0, "pat9", "at-eof", GIT_ATTR_FALSE, 0); - - git_attr_file__free(file); -} - -void test_attr_file__check_attr_examples(void) -{ - git_attr_file *file; - git_attr_rule *rule; - git_attr_assignment *assign; - - cl_git_pass(git_attr_file__new(&file)); - cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr3"), file)); - cl_assert_strequal(cl_fixture("attr/attr3"), file->path); - cl_assert(file->rules.length == 3); - - rule = get_rule(0); - cl_assert_strequal("*.java", rule->match.pattern); - cl_assert(rule->assigns.length == 3); - assign = git_attr_rule__lookup_assignment(rule, "diff"); - cl_assert_strequal("diff", assign->name); - cl_assert_strequal("java", assign->value); - assign = git_attr_rule__lookup_assignment(rule, "crlf"); - cl_assert_strequal("crlf", assign->name); - cl_assert(GIT_ATTR_FALSE == assign->value); - assign = git_attr_rule__lookup_assignment(rule, "myAttr"); - cl_assert_strequal("myAttr", assign->name); - cl_assert(GIT_ATTR_TRUE == assign->value); - assign = git_attr_rule__lookup_assignment(rule, "missing"); - cl_assert(assign == NULL); - - rule = get_rule(1); - cl_assert_strequal("NoMyAttr.java", rule->match.pattern); - cl_assert(rule->assigns.length == 1); - assign = get_assign(rule, 0); - cl_assert_strequal("myAttr", assign->name); - cl_assert(assign->value == NULL); - - rule = get_rule(2); - cl_assert_strequal("README", rule->match.pattern); - cl_assert(rule->assigns.length == 1); - assign = get_assign(rule, 0); - cl_assert_strequal("caveat", assign->name); - cl_assert_strequal("unspecified", assign->value); - - git_attr_file__free(file); -} diff --git a/tests-clay/attr/lookup.c b/tests-clay/attr/lookup.c deleted file mode 100644 index b251562ba..000000000 --- a/tests-clay/attr/lookup.c +++ /dev/null @@ -1,262 +0,0 @@ -#include "clay_libgit2.h" -#include "attr_file.h" - -void test_attr_lookup__simple(void) -{ - git_attr_file *file; - git_attr_path path; - const char *value = NULL; - - cl_git_pass(git_attr_file__new(&file)); - cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr0"), file)); - cl_assert_strequal(cl_fixture("attr/attr0"), file->path); - cl_assert(file->rules.length == 1); - - cl_git_pass(git_attr_path__init(&path, "test")); - cl_assert_strequal("test", path.path); - cl_assert_strequal("test", path.basename); - cl_assert(!path.is_dir); - - cl_git_pass(git_attr_file__lookup_one(file,&path,"binary",&value)); - cl_assert(value == GIT_ATTR_TRUE); - - cl_git_pass(git_attr_file__lookup_one(file,&path,"missing",&value)); - cl_assert(!value); - - git_attr_file__free(file); -} - -typedef struct { - const char *path; - const char *attr; - const char *expected; - int use_strcmp; - int force_dir; -} test_case; - -static void run_test_cases(git_attr_file *file, test_case *cases) -{ - git_attr_path path; - const char *value = NULL; - test_case *c; - int error; - - for (c = cases; c->path != NULL; c++) { - cl_git_pass(git_attr_path__init(&path, c->path)); - - if (c->force_dir) - path.is_dir = 1; - - error = git_attr_file__lookup_one(file,&path,c->attr,&value); - if (error != GIT_SUCCESS) - fprintf(stderr, "failure with %s %s %s\n", c->path, c->attr, c->expected); - cl_git_pass(error); - - if (c->use_strcmp) - cl_assert_strequal(c->expected, value); - else - cl_assert(c->expected == value); - } -} - -void test_attr_lookup__match_variants(void) -{ - git_attr_file *file; - git_attr_path path; - test_case cases[] = { - /* pat0 -> simple match */ - { "pat0", "attr0", GIT_ATTR_TRUE, 0, 0 }, - { "/testing/for/pat0", "attr0", GIT_ATTR_TRUE, 0, 0 }, - { "relative/to/pat0", "attr0", GIT_ATTR_TRUE, 0, 0 }, - { "this-contains-pat0-inside", "attr0", NULL, 0, 0 }, - { "this-aint-right", "attr0", NULL, 0, 0 }, - { "/this/pat0/dont/match", "attr0", NULL, 0, 0 }, - /* negative match */ - { "pat0", "attr1", GIT_ATTR_TRUE, 0, 0 }, - { "pat1", "attr1", NULL, 0, 0 }, - { "/testing/for/pat1", "attr1", NULL, 0, 0 }, - { "/testing/for/pat0", "attr1", GIT_ATTR_TRUE, 0, 0 }, - { "/testing/for/pat1/inside", "attr1", GIT_ATTR_TRUE, 0, 0 }, - { "misc", "attr1", GIT_ATTR_TRUE, 0, 0 }, - /* dir match */ - { "pat2", "attr2", NULL, 0, 0 }, - { "pat2", "attr2", GIT_ATTR_TRUE, 0, 1 }, - { "/testing/for/pat2", "attr2", NULL, 0, 0 }, - { "/testing/for/pat2", "attr2", GIT_ATTR_TRUE, 0, 1 }, - { "/not/pat2/yousee", "attr2", NULL, 0, 0 }, - { "/not/pat2/yousee", "attr2", NULL, 0, 1 }, - /* path match */ - { "pat3file", "attr3", NULL, 0, 0 }, - { "/pat3dir/pat3file", "attr3", NULL, 0, 0 }, - { "pat3dir/pat3file", "attr3", GIT_ATTR_TRUE, 0, 0 }, - /* pattern* match */ - { "pat4.txt", "attr4", GIT_ATTR_TRUE, 0, 0 }, - { "/fun/fun/fun/pat4.c", "attr4", GIT_ATTR_TRUE, 0, 0 }, - { "pat4.", "attr4", GIT_ATTR_TRUE, 0, 0 }, - { "pat4", "attr4", NULL, 0, 0 }, - { "/fun/fun/fun/pat4.dir", "attr4", GIT_ATTR_TRUE, 0, 1 }, - /* *pattern match */ - { "foo.pat5", "attr5", GIT_ATTR_TRUE, 0, 0 }, - { "foo.pat5", "attr5", GIT_ATTR_TRUE, 0, 1 }, - { "/this/is/ok.pat5", "attr5", GIT_ATTR_TRUE, 0, 0 }, - { "/this/is/bad.pat5/yousee.txt", "attr5", NULL, 0, 0 }, - { "foo.pat5", "attr100", NULL, 0, 0 }, - /* glob match with slashes */ - { "foo.pat6", "attr6", NULL, 0, 0 }, - { "pat6/pat6/foobar.pat6", "attr6", GIT_ATTR_TRUE, 0, 0 }, - { "pat6/pat6/.pat6", "attr6", GIT_ATTR_TRUE, 0, 0 }, - { "pat6/pat6/extra/foobar.pat6", "attr6", NULL, 0, 0 }, - { "/prefix/pat6/pat6/foobar.pat6", "attr6", NULL, 0, 0 }, - { "/pat6/pat6/foobar.pat6", "attr6", NULL, 0, 0 }, - /* complex pattern */ - { "pat7a12z", "attr7", GIT_ATTR_TRUE, 0, 0 }, - { "pat7e__x", "attr7", GIT_ATTR_TRUE, 0, 0 }, - { "pat7b/1y", "attr7", NULL, 0, 0 }, /* ? does not match / */ - { "pat7e_x", "attr7", NULL, 0, 0 }, - { "pat7aaaa", "attr7", NULL, 0, 0 }, - { "pat7zzzz", "attr7", NULL, 0, 0 }, - { "/this/can/be/anything/pat7a12z", "attr7", GIT_ATTR_TRUE, 0, 0 }, - { "but/it/still/must/match/pat7aaaa", "attr7", NULL, 0, 0 }, - { "pat7aaay.fail", "attr7", NULL, 0, 0 }, - /* pattern with spaces */ - { "pat8 with spaces", "attr8", GIT_ATTR_TRUE, 0, 0 }, - { "/gotta love/pat8 with spaces", "attr8", GIT_ATTR_TRUE, 0, 0 }, - { "failing pat8 with spaces", "attr8", NULL, 0, 0 }, - { "spaces", "attr8", NULL, 0, 0 }, - /* pattern at eof */ - { "pat9", "attr9", GIT_ATTR_TRUE, 0, 0 }, - { "/eof/pat9", "attr9", GIT_ATTR_TRUE, 0, 0 }, - { "pat", "attr9", NULL, 0, 0 }, - { "at9", "attr9", NULL, 0, 0 }, - { "pat9.fail", "attr9", NULL, 0, 0 }, - /* sentinel at end */ - { NULL, NULL, NULL, 0, 0 } - }; - - cl_git_pass(git_attr_file__new(&file)); - cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr1"), file)); - cl_assert_strequal(cl_fixture("attr/attr1"), file->path); - cl_assert(file->rules.length == 10); - - cl_git_pass(git_attr_path__init(&path, "/testing/for/pat0")); - cl_assert_strequal("pat0", path.basename); - - run_test_cases(file, cases); - - git_attr_file__free(file); -} - -void test_attr_lookup__assign_variants(void) -{ - git_attr_file *file; - test_case cases[] = { - /* pat0 -> simple assign */ - { "pat0", "simple", GIT_ATTR_TRUE, 0, 0 }, - { "/testing/pat0", "simple", GIT_ATTR_TRUE, 0, 0 }, - { "pat0", "fail", NULL, 0, 0 }, - { "/testing/pat0", "fail", NULL, 0, 0 }, - /* negative assign */ - { "pat1", "neg", GIT_ATTR_FALSE, 0, 0 }, - { "/testing/pat1", "neg", GIT_ATTR_FALSE, 0, 0 }, - { "pat1", "fail", NULL, 0, 0 }, - { "/testing/pat1", "fail", NULL, 0, 0 }, - /* forced undef */ - { "pat1", "notundef", GIT_ATTR_TRUE, 0, 0 }, - { "pat2", "notundef", NULL, 0, 0 }, - { "/lead/in/pat1", "notundef", GIT_ATTR_TRUE, 0, 0 }, - { "/lead/in/pat2", "notundef", NULL, 0, 0 }, - /* assign value */ - { "pat3", "assigned", "test-value", 1, 0 }, - { "pat3", "notassigned", NULL, 0, 0 }, - /* assign value */ - { "pat4", "rule-with-more-chars", "value-with-more-chars", 1, 0 }, - { "pat4", "notassigned-rule-with-more-chars", NULL, 0, 0 }, - /* empty assignments */ - { "pat5", "empty", GIT_ATTR_TRUE, 0, 0 }, - { "pat6", "negempty", GIT_ATTR_FALSE, 0, 0 }, - /* multiple assignment */ - { "pat7", "multiple", GIT_ATTR_TRUE, 0, 0 }, - { "pat7", "single", GIT_ATTR_FALSE, 0, 0 }, - { "pat7", "values", "1", 1, 0 }, - { "pat7", "also", "a-really-long-value/*", 1, 0 }, - { "pat7", "happy", "yes!", 1, 0 }, - { "pat8", "again", GIT_ATTR_TRUE, 0, 0 }, - { "pat8", "another", "12321", 1, 0 }, - /* bad assignment */ - { "patbad0", "simple", NULL, 0, 0 }, - { "patbad0", "notundef", GIT_ATTR_TRUE, 0, 0 }, - { "patbad1", "simple", NULL, 0, 0 }, - /* eof assignment */ - { "pat9", "at-eof", GIT_ATTR_FALSE, 0, 0 }, - /* sentinel at end */ - { NULL, NULL, NULL, 0, 0 } - }; - - cl_git_pass(git_attr_file__new(&file)); - cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr2"), file)); - cl_assert(file->rules.length == 11); - - run_test_cases(file, cases); - - git_attr_file__free(file); -} - -void test_attr_lookup__check_attr_examples(void) -{ - git_attr_file *file; - test_case cases[] = { - { "foo.java", "diff", "java", 1, 0 }, - { "foo.java", "crlf", GIT_ATTR_FALSE, 0, 0 }, - { "foo.java", "myAttr", GIT_ATTR_TRUE, 0, 0 }, - { "foo.java", "other", NULL, 0, 0 }, - { "/prefix/dir/foo.java", "diff", "java", 1, 0 }, - { "/prefix/dir/foo.java", "crlf", GIT_ATTR_FALSE, 0, 0 }, - { "/prefix/dir/foo.java", "myAttr", GIT_ATTR_TRUE, 0, 0 }, - { "/prefix/dir/foo.java", "other", NULL, 0, 0 }, - { "NoMyAttr.java", "crlf", GIT_ATTR_FALSE, 0, 0 }, - { "NoMyAttr.java", "myAttr", NULL, 0, 0 }, - { "NoMyAttr.java", "other", NULL, 0, 0 }, - { "/prefix/dir/NoMyAttr.java", "crlf", GIT_ATTR_FALSE, 0, 0 }, - { "/prefix/dir/NoMyAttr.java", "myAttr", NULL, 0, 0 }, - { "/prefix/dir/NoMyAttr.java", "other", NULL, 0, 0 }, - { "README", "caveat", "unspecified", 1, 0 }, - { "/specific/path/README", "caveat", "unspecified", 1, 0 }, - { "README", "missing", NULL, 0, 0 }, - { "/specific/path/README", "missing", NULL, 0, 0 }, - /* sentinel at end */ - { NULL, NULL, NULL, 0, 0 } - }; - - cl_git_pass(git_attr_file__new(&file)); - cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr3"), file)); - cl_assert(file->rules.length == 3); - - run_test_cases(file, cases); - - git_attr_file__free(file); -} - -void test_attr_lookup__from_buffer(void) -{ - git_attr_file *file; - test_case cases[] = { - { "abc", "foo", GIT_ATTR_TRUE, 0, 0 }, - { "abc", "bar", GIT_ATTR_TRUE, 0, 0 }, - { "abc", "baz", GIT_ATTR_TRUE, 0, 0 }, - { "aaa", "foo", GIT_ATTR_TRUE, 0, 0 }, - { "aaa", "bar", NULL, 0, 0 }, - { "aaa", "baz", GIT_ATTR_TRUE, 0, 0 }, - { "qqq", "foo", NULL, 0, 0 }, - { "qqq", "bar", NULL, 0, 0 }, - { "qqq", "baz", GIT_ATTR_TRUE, 0, 0 }, - { NULL, NULL, NULL, 0, 0 } - }; - - cl_git_pass(git_attr_file__new(&file)); - cl_git_pass(git_attr_file__from_buffer(NULL, "a* foo\nabc bar\n* baz", file)); - cl_assert(file->rules.length == 3); - - run_test_cases(file, cases); - - git_attr_file__free(file); -} diff --git a/tests-clay/attr/repo.c b/tests-clay/attr/repo.c deleted file mode 100644 index 13f28ca84..000000000 --- a/tests-clay/attr/repo.c +++ /dev/null @@ -1,242 +0,0 @@ -#include "clay_libgit2.h" -#include "fileops.h" -#include "git2/attr.h" - -static git_repository *g_repo = NULL; - -void test_attr_repo__initialize(void) -{ - /* Before each test, instantiate the attr repo from the fixtures and - * rename the .gitted to .git so it is a repo with a working dir. - * Also rename gitattributes to .gitattributes, because it contains - * macro definitions which are only allowed in the root. - */ - cl_fixture_sandbox("attr"); - cl_git_pass(p_rename("attr/.gitted", "attr/.git")); - cl_git_pass(p_rename("attr/gitattributes", "attr/.gitattributes")); - cl_git_pass(git_repository_open(&g_repo, "attr/.git")); -} - -void test_attr_repo__cleanup(void) -{ - git_repository_free(g_repo); - g_repo = NULL; - cl_fixture_cleanup("attr"); -} - -void test_attr_repo__get_one(void) -{ - const char *value; - struct { - const char *file; - const char *attr; - const char *expected; - } test_cases[] = { - { "root_test1", "repoattr", GIT_ATTR_TRUE }, - { "root_test1", "rootattr", GIT_ATTR_TRUE }, - { "root_test1", "missingattr", NULL }, - { "root_test1", "subattr", NULL }, - { "root_test1", "negattr", NULL }, - { "root_test2", "repoattr", GIT_ATTR_TRUE }, - { "root_test2", "rootattr", GIT_ATTR_FALSE }, - { "root_test2", "missingattr", NULL }, - { "root_test2", "multiattr", GIT_ATTR_FALSE }, - { "root_test3", "repoattr", GIT_ATTR_TRUE }, - { "root_test3", "rootattr", NULL }, - { "root_test3", "multiattr", "3" }, - { "root_test3", "multi2", NULL }, - { "sub/subdir_test1", "repoattr", GIT_ATTR_TRUE }, - { "sub/subdir_test1", "rootattr", GIT_ATTR_TRUE }, - { "sub/subdir_test1", "missingattr", NULL }, - { "sub/subdir_test1", "subattr", "yes" }, - { "sub/subdir_test1", "negattr", GIT_ATTR_FALSE }, - { "sub/subdir_test1", "another", NULL }, - { "sub/subdir_test2.txt", "repoattr", GIT_ATTR_TRUE }, - { "sub/subdir_test2.txt", "rootattr", GIT_ATTR_TRUE }, - { "sub/subdir_test2.txt", "missingattr", NULL }, - { "sub/subdir_test2.txt", "subattr", "yes" }, - { "sub/subdir_test2.txt", "negattr", GIT_ATTR_FALSE }, - { "sub/subdir_test2.txt", "another", "zero" }, - { "sub/subdir_test2.txt", "reposub", GIT_ATTR_TRUE }, - { "sub/sub/subdir.txt", "another", "one" }, - { "sub/sub/subdir.txt", "reposubsub", GIT_ATTR_TRUE }, - { "sub/sub/subdir.txt", "reposub", NULL }, - { "does-not-exist", "foo", "yes" }, - { "sub/deep/file", "deepdeep", GIT_ATTR_TRUE }, - { NULL, NULL, NULL } - }, *scan; - - for (scan = test_cases; scan->file != NULL; scan++) { - git_buf b = GIT_BUF_INIT; - - git_buf_printf(&b, "%s:%s == expect %s", - scan->file, scan->attr, scan->expected); - - cl_must_pass_( - git_attr_get(g_repo, scan->file, scan->attr, &value) == GIT_SUCCESS, - b.ptr); - - git_buf_printf(&b, ", got %s", value); - - if (scan->expected == NULL || - scan->expected == GIT_ATTR_TRUE || - scan->expected == GIT_ATTR_FALSE) - { - cl_assert_(scan->expected == value, b.ptr); - } else { - cl_assert_strequal(scan->expected, value); - } - - git_buf_free(&b); - } -} - -void test_attr_repo__get_many(void) -{ - const char *names[4] = { "repoattr", "rootattr", "missingattr", "subattr" }; - const char *values[4]; - - cl_git_pass(git_attr_get_many(g_repo, "root_test1", 4, names, values)); - - cl_assert(values[0] == GIT_ATTR_TRUE); - cl_assert(values[1] == GIT_ATTR_TRUE); - cl_assert(values[2] == NULL); - cl_assert(values[3] == NULL); - - cl_git_pass(git_attr_get_many(g_repo, "root_test2", 4, names, values)); - - cl_assert(values[0] == GIT_ATTR_TRUE); - cl_assert(values[1] == GIT_ATTR_FALSE); - cl_assert(values[2] == NULL); - cl_assert(values[3] == NULL); - - cl_git_pass(git_attr_get_many(g_repo, "sub/subdir_test1", 4, names, values)); - - cl_assert(values[0] == GIT_ATTR_TRUE); - cl_assert(values[1] == GIT_ATTR_TRUE); - cl_assert(values[2] == NULL); - cl_assert_strequal("yes", values[3]); - -} - -static int count_attrs( - const char *GIT_UNUSED(name), - const char *GIT_UNUSED(value), - void *payload) -{ - GIT_UNUSED_ARG(name); - GIT_UNUSED_ARG(value); - - *((int *)payload) += 1; - - return GIT_SUCCESS; -} - -void test_attr_repo__foreach(void) -{ - int count; - - count = 0; - cl_git_pass(git_attr_foreach(g_repo, "root_test1", &count_attrs, &count)); - cl_assert(count == 2); - - count = 0; - cl_git_pass(git_attr_foreach(g_repo, "sub/subdir_test1", - &count_attrs, &count)); - cl_assert(count == 4); /* repoattr, rootattr, subattr, negattr */ - - count = 0; - cl_git_pass(git_attr_foreach(g_repo, "sub/subdir_test2.txt", - &count_attrs, &count)); - cl_assert(count == 6); /* repoattr, rootattr, subattr, reposub, negattr, another */ -} - -void test_attr_repo__manpage_example(void) -{ - const char *value; - - cl_git_pass(git_attr_get(g_repo, "sub/abc", "foo", &value)); - cl_assert(value == GIT_ATTR_TRUE); - - cl_git_pass(git_attr_get(g_repo, "sub/abc", "bar", &value)); - cl_assert(value == NULL); - - cl_git_pass(git_attr_get(g_repo, "sub/abc", "baz", &value)); - cl_assert(value == GIT_ATTR_FALSE); - - cl_git_pass(git_attr_get(g_repo, "sub/abc", "merge", &value)); - cl_assert_strequal("filfre", value); - - cl_git_pass(git_attr_get(g_repo, "sub/abc", "frotz", &value)); - cl_assert(value == NULL); -} - -void test_attr_repo__macros(void) -{ - const char *names[5] = { "rootattr", "binary", "diff", "crlf", "frotz" }; - const char *names2[5] = { "mymacro", "positive", "negative", "rootattr", "another" }; - const char *names3[3] = { "macro2", "multi2", "multi3" }; - const char *values[5]; - - cl_git_pass(git_attr_get_many(g_repo, "binfile", 5, names, values)); - - cl_assert(values[0] == GIT_ATTR_TRUE); - cl_assert(values[1] == GIT_ATTR_TRUE); - cl_assert(values[2] == GIT_ATTR_FALSE); - cl_assert(values[3] == GIT_ATTR_FALSE); - cl_assert(values[4] == NULL); - - cl_git_pass(git_attr_get_many(g_repo, "macro_test", 5, names2, values)); - - cl_assert(values[0] == GIT_ATTR_TRUE); - cl_assert(values[1] == GIT_ATTR_TRUE); - cl_assert(values[2] == GIT_ATTR_FALSE); - cl_assert(values[3] == NULL); - cl_assert_strequal("77", values[4]); - - cl_git_pass(git_attr_get_many(g_repo, "macro_test", 3, names3, values)); - - cl_assert(values[0] == GIT_ATTR_TRUE); - cl_assert(values[1] == GIT_ATTR_FALSE); - cl_assert_strequal("answer", values[2]); -} - -void test_attr_repo__bad_macros(void) -{ - const char *names[6] = { "rootattr", "positive", "negative", - "firstmacro", "secondmacro", "thirdmacro" }; - const char *values[6]; - - cl_git_pass(git_attr_get_many(g_repo, "macro_bad", 6, names, values)); - - /* these three just confirm that the "mymacro" rule ran */ - cl_assert(values[0] == NULL); - cl_assert(values[1] == GIT_ATTR_TRUE); - cl_assert(values[2] == GIT_ATTR_FALSE); - - /* file contains: - * # let's try some malicious macro defs - * [attr]firstmacro -thirdmacro -secondmacro - * [attr]secondmacro firstmacro -firstmacro - * [attr]thirdmacro secondmacro=hahaha -firstmacro - * macro_bad firstmacro secondmacro thirdmacro - * - * firstmacro assignment list ends up with: - * -thirdmacro -secondmacro - * secondmacro assignment list expands "firstmacro" and ends up with: - * -thirdmacro -secondmacro -firstmacro - * thirdmacro assignment don't expand so list ends up with: - * secondmacro="hahaha" - * - * macro_bad assignment list ends up with: - * -thirdmacro -secondmacro firstmacro && - * -thirdmacro -secondmacro -firstmacro secondmacro && - * secondmacro="hahaha" thirdmacro - * - * so summary results should be: - * -firstmacro secondmacro="hahaha" thirdmacro - */ - cl_assert(values[3] == GIT_ATTR_FALSE); - cl_assert_strequal("hahaha", values[4]); - cl_assert(values[5] == GIT_ATTR_TRUE); -} diff --git a/tests-clay/buf/basic.c b/tests-clay/buf/basic.c deleted file mode 100644 index 860564d13..000000000 --- a/tests-clay/buf/basic.c +++ /dev/null @@ -1,29 +0,0 @@ -#include "clay_libgit2.h" -#include "buffer.h" - -static const char *test_string = "Have you seen that? Have you seeeen that??"; - -void test_buf_basic__resize(void) -{ - git_buf buf1 = GIT_BUF_INIT; - git_buf_puts(&buf1, test_string); - cl_assert(git_buf_oom(&buf1) == 0); - cl_assert(strcmp(git_buf_cstr(&buf1), test_string) == 0); - - git_buf_puts(&buf1, test_string); - cl_assert(strlen(git_buf_cstr(&buf1)) == strlen(test_string) * 2); - git_buf_free(&buf1); -} - -void test_buf_basic__printf(void) -{ - git_buf buf2 = GIT_BUF_INIT; - git_buf_printf(&buf2, "%s %s %d ", "shoop", "da", 23); - cl_assert(git_buf_oom(&buf2) == 0); - cl_assert(strcmp(git_buf_cstr(&buf2), "shoop da 23 ") == 0); - - git_buf_printf(&buf2, "%s %d", "woop", 42); - cl_assert(git_buf_oom(&buf2) == 0); - cl_assert(strcmp(git_buf_cstr(&buf2), "shoop da 23 woop 42") == 0); - git_buf_free(&buf2); -}
\ No newline at end of file diff --git a/tests-clay/clay b/tests-clay/clay deleted file mode 100755 index b5512d09e..000000000 --- a/tests-clay/clay +++ /dev/null @@ -1,309 +0,0 @@ -#!/usr/bin/env python - -from __future__ import with_statement -from string import Template -import re, fnmatch, os - -VERSION = "0.10.0" - -TEST_FUNC_REGEX = r"^(void\s+(test_%s__(\w+))\(\s*void\s*\))\s*\{" - -EVENT_CB_REGEX = re.compile( - r"^(void\s+clay_on_(\w+)\(\s*void\s*\))\s*\{", - re.MULTILINE) - -SKIP_COMMENTS_REGEX = re.compile( - r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"', - re.DOTALL | re.MULTILINE) - -CLAY_HEADER = """ -/* - * Clay v%s - * - * This is an autogenerated file. Do not modify. - * To add new unit tests or suites, regenerate the whole - * file with `./clay` - */ -""" % VERSION - -CLAY_EVENTS = [ - 'init', - 'shutdown', - 'test', - 'suite' -] - -def main(): - from optparse import OptionParser - - parser = OptionParser() - - parser.add_option('-c', '--clay-path', dest='clay_path') - parser.add_option('-v', '--report-to', dest='print_mode', default='default') - - options, args = parser.parse_args() - - for folder in args or ['.']: - builder = ClayTestBuilder(folder, - clay_path = options.clay_path, - print_mode = options.print_mode) - - builder.render() - - -class ClayTestBuilder: - def __init__(self, path, clay_path = None, print_mode = 'default'): - self.declarations = [] - self.suite_names = [] - self.callback_data = {} - self.suite_data = {} - self.event_callbacks = [] - - self.clay_path = os.path.abspath(clay_path) if clay_path else None - - self.path = os.path.abspath(path) - self.modules = [ - "clay_sandbox.c", - "clay_fixtures.c", - "clay_fs.c" - ] - - self.modules.append("clay_print_%s.c" % print_mode) - - print("Loading test suites...") - - for root, dirs, files in os.walk(self.path): - module_root = root[len(self.path):] - module_root = [c for c in module_root.split(os.sep) if c] - - tests_in_module = fnmatch.filter(files, "*.c") - - for test_file in tests_in_module: - full_path = os.path.join(root, test_file) - test_name = "_".join(module_root + [test_file[:-2]]) - - with open(full_path) as f: - self._process_test_file(test_name, f.read()) - - if not self.suite_data: - raise RuntimeError( - 'No tests found under "%s"' % folder_name) - - def render(self): - main_file = os.path.join(self.path, 'clay_main.c') - with open(main_file, "w") as out: - out.write(self._render_main()) - - header_file = os.path.join(self.path, 'clay.h') - with open(header_file, "w") as out: - out.write(self._render_header()) - - print ('Written Clay suite to "%s"' % self.path) - - ##################################################### - # Internal methods - ##################################################### - - def _render_cb(self, cb): - return '{"%s", &%s}' % (cb['short_name'], cb['symbol']) - - def _render_suite(self, suite): - template = Template( -r""" - { - "${clean_name}", - ${initialize}, - ${cleanup}, - ${cb_ptr}, ${cb_count} - } -""") - - callbacks = {} - for cb in ['initialize', 'cleanup']: - callbacks[cb] = (self._render_cb(suite[cb]) - if suite[cb] else "{NULL, NULL}") - - return template.substitute( - clean_name = suite['name'].replace("_", "::"), - initialize = callbacks['initialize'], - cleanup = callbacks['cleanup'], - cb_ptr = "_clay_cb_%s" % suite['name'], - cb_count = suite['cb_count'] - ).strip() - - def _render_callbacks(self, suite_name, callbacks): - template = Template( -r""" -static const struct clay_func _clay_cb_${suite_name}[] = { - ${callbacks} -}; -""") - callbacks = [ - self._render_cb(cb) - for cb in callbacks - if cb['short_name'] not in ('initialize', 'cleanup') - ] - - return template.substitute( - suite_name = suite_name, - callbacks = ",\n\t".join(callbacks) - ).strip() - - def _render_event_overrides(self): - overrides = [] - for event in CLAY_EVENTS: - if event in self.event_callbacks: - continue - - overrides.append( - "#define clay_on_%s() /* nop */" % event - ) - - return '\n'.join(overrides) - - def _render_header(self): - template = Template(self._load_file('clay.h')) - - declarations = "\n".join( - "extern %s;" % decl - for decl in sorted(self.declarations) - ) - - return template.substitute( - extern_declarations = declarations, - ) - - def _render_main(self): - template = Template(self._load_file('clay.c')) - suite_names = sorted(self.suite_names) - - suite_data = [ - self._render_suite(self.suite_data[s]) - for s in suite_names - ] - - callbacks = [ - self._render_callbacks(s, self.callback_data[s]) - for s in suite_names - ] - - callback_count = sum( - len(cbs) for cbs in self.callback_data.values() - ) - - return template.substitute( - clay_modules = self._get_modules(), - clay_callbacks = "\n".join(callbacks), - clay_suites = ",\n\t".join(suite_data), - clay_suite_count = len(suite_data), - clay_callback_count = callback_count, - clay_event_overrides = self._render_event_overrides(), - ) - - def _load_file(self, filename): - if self.clay_path: - filename = os.path.join(self.clay_path, filename) - with open(filename) as cfile: - return cfile.read() - - else: - import zlib, base64, sys - content = CLAY_FILES[filename] - - if sys.version_info >= (3, 0): - content = bytearray(content, 'utf_8') - content = base64.b64decode(content) - content = zlib.decompress(content) - return str(content) - else: - content = base64.b64decode(content) - return zlib.decompress(content) - - def _get_modules(self): - return "\n".join(self._load_file(f) for f in self.modules) - - def _skip_comments(self, text): - def _replacer(match): - s = match.group(0) - return "" if s.startswith('/') else s - - return re.sub(SKIP_COMMENTS_REGEX, _replacer, text) - - def _process_test_file(self, suite_name, contents): - contents = self._skip_comments(contents) - - self._process_events(contents) - self._process_declarations(suite_name, contents) - - def _process_events(self, contents): - for (decl, event) in EVENT_CB_REGEX.findall(contents): - if event not in CLAY_EVENTS: - continue - - self.declarations.append(decl) - self.event_callbacks.append(event) - - def _process_declarations(self, suite_name, contents): - callbacks = [] - initialize = cleanup = None - - regex_string = TEST_FUNC_REGEX % suite_name - regex = re.compile(regex_string, re.MULTILINE) - - for (declaration, symbol, short_name) in regex.findall(contents): - data = { - "short_name" : short_name, - "declaration" : declaration, - "symbol" : symbol - } - - if short_name == 'initialize': - initialize = data - elif short_name == 'cleanup': - cleanup = data - else: - callbacks.append(data) - - if not callbacks: - return - - tests_in_suite = len(callbacks) - - suite = { - "name" : suite_name, - "initialize" : initialize, - "cleanup" : cleanup, - "cb_count" : tests_in_suite - } - - if initialize: - self.declarations.append(initialize['declaration']) - - if cleanup: - self.declarations.append(cleanup['declaration']) - - self.declarations += [ - callback['declaration'] - for callback in callbacks - ] - - callbacks.sort(key=lambda x: x['short_name']) - self.callback_data[suite_name] = callbacks - self.suite_data[suite_name] = suite - self.suite_names.append(suite_name) - - print(" %s (%d tests)" % (suite_name, tests_in_suite)) - - - -CLAY_FILES = { -"clay.c" : r"""eJyNGdtu2zb0Wf4Kzt0aOVEcJ32L1wBFtw7BtgxoU3RAEwi0RMdcJdETqVzW+d93eHgRdXG6vsQ6d5472Re8yoomZ+RHKiWr1XxzMXnhYZKpv8ptD6bygq8GMC76oJpXd11YSdVmwEhrpJqcHJKa/d3wmuVkLWoiaZWvxCMIIYcnIcuTPFFPWyZ7kgAsFcUDAHidszVJP11evTqbvIg81QOvcvFgWFuotb0FyA0rCrrlPXAOxmVWQwQKeMVI+vuby6v07VuSplnOsiJAaXPiLZw5gZ8zkna/W7ryCwi2iFLkDEhbUECXbTyQpMFHS0GzjEnZFTWEhRbWebON4Q+a5z/0Ifi6Qh+mv19e/fLp1VmaAjDa1vSupCQTZckqFUMmJGSK7np1NtWSA9FVtn2KlUjIuhZlQpRIJf8HTLKoVCLSgh1Vev3+49XbN9c/h8I+pX/8ShZnAeRDevnhp8v38eOMxPEjeUlSgLwDyIx895osQubyi2LlNnUuKFiFDh4AgYVVOV9PIp1e+uxgaJMpEzjy4frNdXq9nLxghWSdZIHMe6Bc5wWBJNY/tzyPz2aYty1dU3FId5NSveQZqOxpRLPaZJ9mBX2ab6aTiabjGbkXHIpGpnUZZ6KSClKF1uQwlaKpMzZb9ukyAZEZoUxICMwZpOnSKwlRkzV/VE3NUu2+jqQVlT0xjrSiJTPi8Ij6DCmrayj1r5MoZFCgdzkBxymif6ZVU65YvewSyYYr1oOtecEsYwHuHWdElWkp7zTcnTOr+VZxUYF50dC+w4o9gkW71heWpmc4zRS/Z6m1fwRjjTYm4ofRIN1xhaKFBwUuyERTqT3GeQkjuIICM/7WzBj++LAQGWjJCkarZjuLEXoIkTH4LhoC/FQImmt2GAXpqlkTVdNyK7SHndkekLKKrgoG5DtoUWBIL97rpsr6XtN5sfTGbaH9oEkz5/CWGz22h32ghVdccVpAaxnD2uP5MA0IMAvRqyAh7YZB2wWV/g4aluHYwqxT6eE80yUf1lqA1fbE3YAmpM0DCxikOJaN7JVwIFZuGgUjrfq2aA0wyY+A/SKRCOVBATmT9iXefjGi0ubE/crGAxlrguo2gDWFCs6fE4knise99BwfXYm6awt0gITM5/NZP5h28dgTzKayeJeklkKbH7I7tJb98z3TWFoUK5p9IeIePMeh62gF3381LtUkqcfskO9No8Qdq1hNFSxF2lskp4qS1ROqCtidbM3YadfD8knb3/LzLXkN9UTgnxVk4LtOrzMFEPCZBALWkMkAd8tRNmdfn7MLt3X1VtTMnFZXom7LsheKCTLXTYW9Nn6+iJP96LZHPEPkGuXkq+l2poakPgUebt5t5CBI8wprm+6rhmzYJUHCKbb5NYnNqh33SWfktV5ndNNDstbi4wtolXrZufr4228zQEc9nFYNYG2F/44gP54zZ+HMMTSdURDqGkGPsbjpMXNiLXxgewg3dlsjfUM7OtJQvCSUUCaEVk8EdR2D51w7JyVTG5FjuozZSIzG5SjSGeuJbCQ73cw7FLuY90TQeAEWD/OCXPi8gfPq2TYZSWi2hS5lOUwDcUnHTa7snf+JW1ImkQG75PTbwcMGeiuJDda5HvNKMwI9YuBgKCYKz24HwtFRQlzPj6J1zVhseYINqofDT2eRFd3moPWNs7XdVnwMRt0EdR/OgWGPM0MBnfdcZwAtSHh80Rv2fBB8o89S22HjC90gg7QN171Wid1URpLDFp6+9sYcvyDgP4bG2dWDHB1xE7SOInsY/eczv51bRVG3S7606IS8tIKD9udhrtthnHZ4lSYLfa/R9yVR05oXTyTn0nSMfW1ZwrW9GIvPN9ryIHz7nPX/HT10kSOY9ByEVv1P5+z8rWxw/kbSu+6KQus7PAwm0zqeftQU5+QHST4LLBp5e1PdVNOEaMplS/iHwZ4DDsAnJx5ByLH6888bdaPeNxURFcREbezQNAsVATRyhTxyhMf4rs/EHmFbPT7d06i2tJYsBWMlronwI0vsWfVh79u21UnrU5PWmjzIZO+jRj8pAJmWAHm6dDiamatZFNmdFOeaHieO6fPiVre0g+MDHIRBGFDW4taMQiPIaDB8p6gFROrkUbUShZdJjsgZRN59JuR0MfOKW3O12pvFAfn3X20ZnG7xrAnygatsA5ajKdYBcGUmB/LgHIc4SI9NG5ppgRevh5uXYYu6HcpsuNMPYTh/yEkuYM+sBKwtj1yqOWYZYLEvR0GY4UP35aBpmK72srMvAuetIV7VjH7BI+VsTZtCne89tpZsmkm7K5s8wrLbn0H925MerfAxG9spky4yvPkAZjrFoeuWkGBNn2HITBxG3PkObyRwMXfvkW2dgY9gNZ/bgglduQuWQDTcq9bnhFXgNFTY1pLxAh5fSyH6pQkJ27EUDYbE4LymtL4ZSn7bMbV3m9y32ez1sKUOHjCsx/2QdKJbaHuX0qbUTDV1RYaCsAe1zSc1L9Wx6TDQZ3OuaykZvgUl7VtQsucRqAcPFhnLLDeiKfIU0wGTct8G5rPLGaRDYM4UbmU6a0UWnyZ4QRLreCBvNusu4W7s9bdvPw476geb1HBr9ziz7IUSRvYwj7MsdpAOhuuyQ2Gv9Z4wfD5xdG5qD0d5S6PDCCT2Zc8Cg8c9wNmHKIvzkXWmm6c+45wgvKFfhlusGQf6Oby72o4tJPpmMpL+5sKCV7swhfxN7rt91zDb3Ue6EbZsaEmgxJztnNDe1YfUlEtoWLSChp8xtHtuGlSn2WOvL0R1N3bpTIjrY7bwQEkK1yx/1bNvdf0nxMS8kxyKLf27Cfe3/iWsfX17/h5mBGH92weDUuRNge8jujj9f76UlFeDQYIT6FaboR84bHtp506n2+4m/wEygwL1""", -"clay_print_default.c" : r"""eJyFU01P4zAQPSe/YqgU1a5Cuafa3RunistqT4AiEztgKbUje9LVCvHfsccpOGhbTs48z3t+85HSo0DdwdFqCd0g/rWj0wZbbTSy8AGoPLadnQzWEGM/aVQnoLPGI3QvwsEmXRhxUJ6Xr2XBoiT/pO/KgqR7ttpbIZWESiY130DlH8yqhvgiX7yQq2YKv1E4VDKQAvpWlmeq8C8TSvvXfF9JBJRz1iXgXAUJypgfWEbelZ9GH0zyWJArp0brsKVczy5apxzybabDqdMe3dRhSqME2NBBdk9PQmgsh1uhh8mphvoaJHjuqvJNU3lgledwH4JKPsL9NYYjppdFQarXP6nQLI69iOHKWJDKd06PqO2C0ushZwzahPFNhyflvujM6MIXnBZhzktNPfhnytI9sPkiexyufsDdn/2eB/lzOlk6X07n8v5YE52yfM2T9bCPaWeyShLQh74r+XV/ImG3RIiTrXTVBb+JDb9gfbuGBtbb9Tf+aELs//8hmbjZgLF2hM3NcnuTo0vS4ins6kI6DKKG7XZLwkfRDjpcCfc87ij08adkMa4hzaw49nN5HmWYBeE1UXjiKCPZHL6V7yZUhjs=""", -"clay_print_tap.c" : r"""eJyNVMFu2zAMPVtfwbgIYBu2gWK3BtuwnYthh+02wFBtORXmSIYkZyiG/vso2m6lJG12skk9ko+PlJh13MkWjlp20A78qRmNVK6RSroMf8AJ65pWT8qV4G07SSdWR6uVddA+cgPFfKD4Qdic/WVJ5lPmr+G71RUAT3wrjij0Wfrjy3c4CmOlVnD74ZdK8x17ZuwNyvZxcp3+o67T9g5hjDaz43/oxr4geMdYInvINlHC5KWHGxi5taIDPgyw7YhYZnNspgxIYmOJGKyIAnsuBwzEIH7Qan8aHRQsMS6Js61pbut6251Xe1tGSksaqumwjtg6M7VuhhEACvoE0iHaa7HWBaiqah5Z4MOZW74XcAdb+9pE9Wnu5WD3MdwKHL90T3ekxVk2Gg3AWTbyx1DfPFyAen+M7FH0S0jvj5GDVCuyC5He36AcD8Lk63osR52wrZGj8xu9+Qjfft7fh8sCEABOCQRHeax0XdfXLodWtDrhhaV98NdwvhCzSaxnx7x+NOG11Nb6JawWYkh8WdHPkCrtQP9OUYwUP/4sTPhiYjmWEH0iZ8SozbJzNrvSAY01u/zmRDRvoCgKJOk/pGCAe78Ef0A6UQncydILTAWOvBkkHnGzH3dkYiYM8HYJy/r2Cw2Lr9GEr036FUUC/N0A7e/xFEAlfIp8zilUly3mM/sHrvXXzQ==""", -"clay_sandbox.c" : r"""eJyNVV1P20AQfLZ/xRIkYpNATItaVSkPlaBVVEoiEgQSRJaxz+SEfY7uLmkD4r931+fEHwRahBST3Zudmb0xSgeahxDOAgl+mAQrfx7o2e2x9+XTtG/bypS50DZX/jJIeOTrdJ43OWEmlDZH9+kL1362rfHk28SfgNJ42uIxOAThULkLe0q7sHMCnmtblmR6IQV4676dsT8Ynw4u8cCh0n6aRcxt9hXPThCGTKkC9dof/nThhGD79kuNc8xFlW/O9H4Rx0x2QfEn5mtImHgw1Hd5LCIWg389uPj4wbYKHKOy6F4G0g+zhdBwAsf9Ro/BZ2KJRkl1O8UeNMRqTX6NUFerC/SUf5yZz6vx2eXocvh9cH7WssF6QYlgFZM46Y0zCQ5HHK8PHL6W4/vQ6XA3h2/MxuYHpvHB2RDhUzTGMibjl2QqndJcLBhNySuv10utZgTKlCKcr5y1d1jqrp0j6MqSLOvFxl/b6u3DIAY9Y9TNZSZShrZFGVOijX4GKwjESs+4eOiClivQGSwUgx7Oh/2e/QapFtVbBa8mLVOsMasQQ1K7LFHMQP9gesLS+YhAndPr4eWpa451wcA1Lt8uExGPja7JjCtQK6VZuhGU8EeGAmpaSHy4kDIXziULdYbFd8Qdvqns8D1Z6z8PjqoBWGY8gjzSC6ECEd1nfxz6Lo8pEajk3ZtSgNp3XrtUjVcDI1FNRDhDFcgSaVYMiZUv0wpYM4XoJ08iv6BglG54VG4vFXwd8CRPTivHI2tu8p8WpW0T2fVLox7wkoOJdxZXabkYoOqbh9yyLQTDaeg3PtRFNNU/A65eZDLFpT2xnC4tejQcD24Ak/o7kBGoJFAzpvIlV6JsvYoyiShD3NwHL/Zxl+/DsholaPfam6htFtHAIGUHcDSlNy72m0H1eqdTgtE9Wl+7sgs6xLRbLmebszgGm7ZYRozSR4zJ3Ff/3E7jH4NZj0Gga1c97n32vK0HKgHHUzS4xhM9vbg6P391qDCwTFX9AucI/x8h2Nvbdue33z9CMbmqEt3qRY3eX120XBI=""", -"clay_fixtures.c" : r"""eJyFUV1LwzAUfW5+xZU9rLUVJ4ggZQ9DFAUfRCZMRglZmrBAl5Qkk03xv9v0a82U+Zabc+45595rLLGCAlXSWKBrouEccbGzW81wSew6HCIrYljicTuqJBsWoS8UmFbPobXA8npye5OlFSI+GbaglbK4YDJFKOjeMAVjdfUInUPkyFZLWu7DWiKBxtgpKN78RZETEByactlLXcBVBmdTGF+OIxQEPhrHGdRQ1zzMv5xUYN84ROLY8b1MEPeTJEdsV3tRq0wdt06tWcWVzXpS9I3QSPCccbh7nr3jh6fF/O31Hr/M5o9ouGpa4NYlPHmBVt074i/lBLy+OsWHEjkcXLAhMl+p3Wk3bjBV1VIG6TxOApgWZN8s4k8bWjAit+W/NnoTejMddI+GqW1GTOaCox8pOffr""", -"clay_fs.c" : r"""eJylVdtu20YQfSa/YkAD8TKWY8dJX6L0wXDEVqgsBhINN7UFhiGX1qIkl9hd+dLG/57ZCynJUWEkfZE0s7NnZufMGe2xsqAlpJfj6ZsT399DgzUUojhKo8npb3Mg+ud8PBlNE/hq/NP4LJ5G49n5aTKOp71zNJvFs4vx06DzPz6MZ6HvS5UplkO+zAS89EtWUd7KtM3UkuS8kcqdGE/o/+t71tYm/ArTi8lk6HuS/UNTBRVtbtRyAGzo+x4rgaQ2zMaFvucJqlaicdd8z15AHKkE/rbxIQI6+DqrKp4TF3YAJ2GH/AxwTeu8fTBRA0jtl0Xp0K+sucAsx9suzPPauX2v5AIIMxYweO9AhnBwwELAbvTFXLGFrmf/aF+X4/Uu2L++3scEjwjmitRnQ/+x7/0tZ0XXecIaBTUv6AC22i/5SuRPnQWVynAy/z3CSYg/zpPZxVkCJQLp4m2YvYqVbJHrEHU7bJgG+y7IZNBQf1HBz2nNxQN5oeEHoDnnJdlOHYa2aa18dRetmlxziI8ZOl8bCV5ruk3u3ptw9OlUnaeMquxGorOfd/OcKs2kpEKlBFuMibHUuKUCm8gbW1aoOTge4HFwyZqC30l4EgdlhmYR+J4tVVBK1q0wpnv0U4JkKmqygxTDQEdfFKcfRpNRMsKx6zgzM7oLL+c4oz9A80aSs/jjp40U6bpmA46t0vgVzZpVS7TLApg3lOwe55A6ivMqe3AKCV4GoQXZo5WkXbk4kr5c0qpK+UoRW5SrMBM3t1cLg60HV19YSS0nVuA+wE/dY/zSg8XF32StX/S9h2OrobIVeLskUhVUCM2eF8wfpKI1oM3FO/hsb3+GHDeCo/DVdRNozjx6zxQ5fB06lXXwehIsPr2n+S0xtR4vBqboLvguYwqD9YUBvLD1D/DesFfr5ejPcTJPTpOLObHn/4PLnkprmpJ+WQy3pbpeqNZOcenovvVCxm1ZIK0bEl4Hrpdpf2pbYs2rjchDs+f6nfVfAXYRuu6hGRx9Yc1R3gZD5zVBweGsd5wsNjVuXG+0y81O6KRuDt4u+r8Ro/B6JRWOo5RG5OuxM6QZYUeGfVAcdM9B6b3lRlpqr8ya4gu/363wZ0W9oekNjt4udvVA1N/1oNxuQvfiHc342TdbTYNa0u2XPiN9I/NV464Qs/e1a8PxiLJvClb63wD3Q6FA""", -"clay.h" : r"""eJy9Vctu2zAQPEdfwVo9WIIQp9c0DWAENmLACIrWQdsTQZOriKhMqiTVqCj67yUp+aGH46YHn0wtdzizu0M65KlgkCKM75bTb3g1+7zC9xgHoQ1yAb14EHJB85IButGG5Xx9md0GwU/JGaI5+YUx0RqUGQcXXBhEpWDccCmS4MKutY1kRKE45TkkdUpuWTq7oJRUnRgDTRUvmrMcUGeyzBkma6lM9H6nAWswmOZARFmMfWwcN59R/R1HCaoXsiA/SrDgLTbVLag7NuSp64/vwnzxdfX4aYY/Tlf3waE6B+WVKRWM22X6GBZk02JpwpoItpbVayBbdS9AQrA9T4NgEscBitHUz8O2DW0IVVKjZ24yBFWRc8oN8r1GG9CaPIHNn+wmb1k3pTa4sBPFYwtQCXJTiNqD9jsRuv2ArhLrlvliOcPYrZaLB78azUtBvQBK8hylxM6eXaMRCvdnJuhd1CN2maeJb47yzqoCqAGG0pYAI72GEwpqktP0b47XbfmV7asj5hoJaZBRJQzxbmd1lwH9/h9zog53pkFdRX3mM09qSMIZBnUVnbhUQv7jdWokDd2wh8flcvgqdECHPe+BmtJ3iLab6/TjpjtVx95ue4a+BXui9l7pwl6sxad0EYOVzKWizkT2NPseTp6JElw8ddV7AQM+OeaOFdiXtr4Ml6Phx6Jhes2pX2oIYqVyP8aRQAW0dK66Hg14zuvYgMkks5uWRBGXq319b39DZUAJfLjzJ9j+GfwFGCyeSg==""" -} -if __name__ == '__main__': - main() diff --git a/tests-clay/clay_helpers.c b/tests-clay/clay_helpers.c deleted file mode 100644 index 081fb087e..000000000 --- a/tests-clay/clay_helpers.c +++ /dev/null @@ -1,29 +0,0 @@ -#include "clay_libgit2.h" -#include "posix.h" - -void clay_on_init(void) -{ - git_threads_init(); -} - -void clay_on_shutdown(void) -{ - git_threads_shutdown(); -} - -void cl_git_mkfile(const char *filename, const char *content) -{ - int fd; - - fd = p_creat(filename, 0666); - cl_assert(fd != 0); - - if (content) { - cl_must_pass(p_write(fd, content, strlen(content))); - } else { - cl_must_pass(p_write(fd, filename, strlen(filename))); - cl_must_pass(p_write(fd, "\n", 1)); - } - - cl_must_pass(p_close(fd)); -} diff --git a/tests-clay/clay_libgit2.h b/tests-clay/clay_libgit2.h deleted file mode 100644 index 1364eb06b..000000000 --- a/tests-clay/clay_libgit2.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef __CLAY_LIBGIT2__ -#define __CLAY_LIBGIT2__ - -#include "clay.h" -#include <git2.h> -#include "common.h" - -/** - * Special wrapper for `clay_must_pass` that passes - * the last library error as the test failure message. - * - * Use this wrapper around all `git_` library calls that - * return error codes! - */ -#define cl_git_pass(expr) do { \ - git_clearerror(); \ - if ((expr) != GIT_SUCCESS) \ - clay__assert(0, __FILE__, __LINE__, "Function call failed: " #expr, git_lasterror(), 1); \ - } while(0) - -/** - * Wrapper for `clay_must_fail` -- this one is - * just for consistency. Use with `git_` library - * calls that are supposed to fail! - */ -#define cl_git_fail(expr) cl_must_fail(expr) - -/** - * Wrapper for string comparison that knows about nulls. - */ -#define cl_assert_strequal(a,b) \ - cl_assert_strequal_internal(a,b,__FILE__,__LINE__,"string mismatch: " #a " != " #b) - -GIT_INLINE(void) cl_assert_strequal_internal( - const char *a, const char *b, const char *file, int line, const char *err) -{ - int match = (a == NULL || b == NULL) ? (a == b) : (strcmp(a, b) == 0); - if (!match) { - char buf[4096]; - snprintf(buf, 4096, "'%s' != '%s'", a, b); - clay__assert(0, file, line, buf, err, 1); - } -} - -/* - * Some utility macros for building long strings - */ -#define REP4(STR) STR STR STR STR -#define REP15(STR) REP4(STR) REP4(STR) REP4(STR) STR STR STR -#define REP16(STR) REP4(REP4(STR)) -#define REP256(STR) REP16(REP16(STR)) -#define REP1024(STR) REP4(REP256(STR)) - -/* Write the contents of a buffer to disk */ -void cl_git_mkfile(const char *filename, const char *content); - -#endif diff --git a/tests-clay/config/add.c b/tests-clay/config/add.c deleted file mode 100644 index de549af15..000000000 --- a/tests-clay/config/add.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "clay_libgit2.h" - -void test_config_add__initialize(void) -{ - cl_fixture_sandbox("config/config10"); -} - -void test_config_add__cleanup(void) -{ - cl_fixture_cleanup("config10"); -} - -void test_config_add__to_existing_section(void) -{ - git_config *cfg; - int32_t i; - - cl_git_pass(git_config_open_ondisk(&cfg, "config10")); - cl_git_pass(git_config_set_int32(cfg, "empty.tmp", 5)); - cl_git_pass(git_config_get_int32(cfg, "empty.tmp", &i)); - cl_assert(i == 5); - cl_git_pass(git_config_delete(cfg, "empty.tmp")); - git_config_free(cfg); -} - -void test_config_add__to_new_section(void) -{ - git_config *cfg; - int32_t i; - - cl_git_pass(git_config_open_ondisk(&cfg, "config10")); - cl_git_pass(git_config_set_int32(cfg, "section.tmp", 5)); - cl_git_pass(git_config_get_int32(cfg, "section.tmp", &i)); - cl_assert(i == 5); - cl_git_pass(git_config_delete(cfg, "section.tmp")); - git_config_free(cfg); -} diff --git a/tests-clay/config/new.c b/tests-clay/config/new.c deleted file mode 100644 index 285cc4af8..000000000 --- a/tests-clay/config/new.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "clay_libgit2.h" - -#include "filebuf.h" -#include "fileops.h" -#include "posix.h" - -#define TEST_CONFIG "git-new-config" - -void test_config_new__write_new_config(void) -{ - const char *out; - struct git_config_file *file; - git_config *config; - - cl_git_pass(git_config_file__ondisk(&file, TEST_CONFIG)); - cl_git_pass(git_config_new(&config)); - cl_git_pass(git_config_add_file(config, file, 0)); - - cl_git_pass(git_config_set_string(config, "color.ui", "auto")); - cl_git_pass(git_config_set_string(config, "core.editor", "ed")); - - git_config_free(config); - - cl_git_pass(git_config_file__ondisk(&file, TEST_CONFIG)); - cl_git_pass(git_config_new(&config)); - cl_git_pass(git_config_add_file(config, file, 0)); - - cl_git_pass(git_config_get_string(config, "color.ui", &out)); - cl_assert(strcmp(out, "auto") == 0); - cl_git_pass(git_config_get_string(config, "core.editor", &out)); - cl_assert(strcmp(out, "ed") == 0); - - git_config_free(config); - - p_unlink(TEST_CONFIG); -} diff --git a/tests-clay/config/read.c b/tests-clay/config/read.c deleted file mode 100644 index 08dc03a88..000000000 --- a/tests-clay/config/read.c +++ /dev/null @@ -1,209 +0,0 @@ -#include "clay_libgit2.h" - -void test_config_read__simple_read(void) -{ - git_config *cfg; - int32_t i; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config0"))); - - cl_git_pass(git_config_get_int32(cfg, "core.repositoryformatversion", &i)); - cl_assert(i == 0); - cl_git_pass(git_config_get_bool(cfg, "core.filemode", &i)); - cl_assert(i == 1); - cl_git_pass(git_config_get_bool(cfg, "core.bare", &i)); - cl_assert(i == 0); - cl_git_pass(git_config_get_bool(cfg, "core.logallrefupdates", &i)); - cl_assert(i == 1); - - git_config_free(cfg); -} - -void test_config_read__case_sensitive(void) -{ - git_config *cfg; - int i; - const char *str; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config1"))); - - cl_git_pass(git_config_get_string(cfg, "this.that.other", &str)); - cl_assert(!strcmp(str, "true")); - cl_git_pass(git_config_get_string(cfg, "this.That.other", &str)); - cl_assert(!strcmp(str, "yes")); - - cl_git_pass(git_config_get_bool(cfg, "this.that.other", &i)); - cl_assert(i == 1); - cl_git_pass(git_config_get_bool(cfg, "this.That.other", &i)); - cl_assert(i == 1); - - /* This one doesn't exist */ - cl_must_fail(git_config_get_bool(cfg, "this.thaT.other", &i)); - - git_config_free(cfg); -} - -/* - * If \ is the last non-space character on the line, we read the next - * one, separating each line with SP. - */ -void test_config_read__multiline_value(void) -{ - git_config *cfg; - const char *str; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config2"))); - - cl_git_pass(git_config_get_string(cfg, "this.That.and", &str)); - cl_assert(!strcmp(str, "one one one two two three three")); - - git_config_free(cfg); -} - -/* - * This kind of subsection declaration is case-insensitive - */ -void test_config_read__subsection_header(void) -{ - git_config *cfg; - const char *str; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config3"))); - - cl_git_pass(git_config_get_string(cfg, "section.subsection.var", &str)); - cl_assert(!strcmp(str, "hello")); - - /* The subsection is transformed to lower-case */ - cl_must_fail(git_config_get_string(cfg, "section.subSectIon.var", &str)); - - git_config_free(cfg); -} - -void test_config_read__lone_variable(void) -{ - git_config *cfg; - const char *str; - int i; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config4"))); - - cl_git_pass(git_config_get_string(cfg, "some.section.variable", &str)); - cl_assert(str == NULL); - - cl_git_pass(git_config_get_bool(cfg, "some.section.variable", &i)); - cl_assert(i == 1); - - git_config_free(cfg); -} - -void test_config_read__number_suffixes(void) -{ - git_config *cfg; - int64_t i; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config5"))); - - cl_git_pass(git_config_get_int64(cfg, "number.simple", &i)); - cl_assert(i == 1); - - cl_git_pass(git_config_get_int64(cfg, "number.k", &i)); - cl_assert(i == 1 * 1024); - - cl_git_pass(git_config_get_int64(cfg, "number.kk", &i)); - cl_assert(i == 1 * 1024); - - cl_git_pass(git_config_get_int64(cfg, "number.m", &i)); - cl_assert(i == 1 * 1024 * 1024); - - cl_git_pass(git_config_get_int64(cfg, "number.mm", &i)); - cl_assert(i == 1 * 1024 * 1024); - - cl_git_pass(git_config_get_int64(cfg, "number.g", &i)); - cl_assert(i == 1 * 1024 * 1024 * 1024); - - cl_git_pass(git_config_get_int64(cfg, "number.gg", &i)); - cl_assert(i == 1 * 1024 * 1024 * 1024); - - git_config_free(cfg); -} - -void test_config_read__blank_lines(void) -{ - git_config *cfg; - int i; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config6"))); - - cl_git_pass(git_config_get_bool(cfg, "valid.subsection.something", &i)); - cl_assert(i == 1); - - cl_git_pass(git_config_get_bool(cfg, "something.else.something", &i)); - cl_assert(i == 0); - - git_config_free(cfg); -} - -void test_config_read__invalid_ext_headers(void) -{ - git_config *cfg; - cl_must_fail(git_config_open_ondisk(&cfg, cl_fixture("config/config7"))); -} - -void test_config_read__empty_files(void) -{ - git_config *cfg; - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config8"))); - git_config_free(cfg); -} - -void test_config_read__header_in_last_line(void) -{ - git_config *cfg; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config10"))); - git_config_free(cfg); -} - -void test_config_read__prefixes(void) -{ - git_config *cfg; - const char *str; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config9"))); - cl_git_pass(git_config_get_string(cfg, "remote.ab.url", &str)); - cl_assert(strcmp(str, "http://example.com/git/ab") == 0); - - cl_git_pass(git_config_get_string(cfg, "remote.abba.url", &str)); - cl_assert(strcmp(str, "http://example.com/git/abba") == 0); - - git_config_free(cfg); -} - -#if 0 - -BEGIN_TEST(config10, "a repo's config overrides the global config") - git_repository *repo; - git_config *cfg; - int32_t version; - - cl_git_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - cl_git_pass(git_repository_config(&cfg, repo, GLOBAL_CONFIG, NULL)); - cl_git_pass(git_config_get_int32(cfg, "core.repositoryformatversion", &version)); - cl_assert(version == 0); - git_config_free(cfg); - git_repository_free(repo); -END_TEST - -BEGIN_TEST(config11, "fall back to the global config") - git_repository *repo; - git_config *cfg; - int32_t num; - - cl_git_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - cl_git_pass(git_repository_config(&cfg, repo, GLOBAL_CONFIG, NULL)); - cl_git_pass(git_config_get_int32(cfg, "core.something", &num)); - cl_assert(num == 2); - git_config_free(cfg); - git_repository_free(repo); -END_TEST -#endif diff --git a/tests-clay/config/stress.c b/tests-clay/config/stress.c deleted file mode 100644 index 3d3729c41..000000000 --- a/tests-clay/config/stress.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "clay_libgit2.h" - -#include "filebuf.h" -#include "fileops.h" -#include "posix.h" - -void test_config_stress__initialize(void) -{ - git_filebuf file = GIT_FILEBUF_INIT; - - cl_git_pass(git_filebuf_open(&file, "git-test-config", 0)); - - git_filebuf_printf(&file, "[color]\n\tui = auto\n"); - git_filebuf_printf(&file, "[core]\n\teditor = \n"); - - cl_git_pass(git_filebuf_commit(&file, 0666)); -} - -void test_config_stress__cleanup(void) -{ - p_unlink("git-test-config"); -} - -void test_config_stress__dont_break_on_invalid_input(void) -{ - const char *editor, *color; - struct git_config_file *file; - git_config *config; - - cl_git_pass(git_path_exists("git-test-config")); - cl_git_pass(git_config_file__ondisk(&file, "git-test-config")); - cl_git_pass(git_config_new(&config)); - cl_git_pass(git_config_add_file(config, file, 0)); - - cl_git_pass(git_config_get_string(config, "color.ui", &color)); - cl_git_pass(git_config_get_string(config, "core.editor", &editor)); - - git_config_free(config); -} diff --git a/tests-clay/config/write.c b/tests-clay/config/write.c deleted file mode 100644 index 57610ab63..000000000 --- a/tests-clay/config/write.c +++ /dev/null @@ -1,77 +0,0 @@ -#include "clay_libgit2.h" - -void test_config_write__initialize(void) -{ - cl_fixture_sandbox("config/config9"); -} - -void test_config_write__cleanup(void) -{ - cl_fixture_cleanup("config9"); -} - -void test_config_write__replace_value(void) -{ - git_config *cfg; - int i; - int64_t l, expected = +9223372036854775803; - - /* By freeing the config, we make sure we flush the values */ - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_set_int32(cfg, "core.dummy", 5)); - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_get_int32(cfg, "core.dummy", &i)); - cl_assert(i == 5); - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_set_int32(cfg, "core.dummy", 1)); - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_set_int64(cfg, "core.verylong", expected)); - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_get_int64(cfg, "core.verylong", &l)); - cl_assert(l == expected); - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_must_fail(git_config_get_int32(cfg, "core.verylong", &i)); - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_set_int64(cfg, "core.verylong", 1)); - git_config_free(cfg); -} - -void test_config_write__delete_value(void) -{ - git_config *cfg; - int32_t i; - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_set_int32(cfg, "core.dummy", 5)); - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_delete(cfg, "core.dummy")); - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_assert(git_config_get_int32(cfg, "core.dummy", &i) == GIT_ENOTFOUND); - cl_git_pass(git_config_set_int32(cfg, "core.dummy", 1)); - git_config_free(cfg); -} - -void test_config_write__delete_inexistent(void) -{ - git_config *cfg; - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_assert(git_config_delete(cfg, "core.imaginary") == GIT_ENOTFOUND); - git_config_free(cfg); -} diff --git a/tests-clay/core/buffer.c b/tests-clay/core/buffer.c deleted file mode 100644 index 2f376c50a..000000000 --- a/tests-clay/core/buffer.c +++ /dev/null @@ -1,546 +0,0 @@ -#include "clay_libgit2.h" -#include "buffer.h" - -#define TESTSTR "Have you seen that? Have you seeeen that??" -const char *test_string = TESTSTR; -const char *test_string_x2 = TESTSTR TESTSTR; - -#define TESTSTR_4096 REP1024("1234") -#define TESTSTR_8192 REP1024("12341234") -const char *test_4096 = TESTSTR_4096; -const char *test_8192 = TESTSTR_8192; - -/* test basic data concatenation */ -void test_core_buffer__0(void) -{ - git_buf buf = GIT_BUF_INIT; - - cl_assert(buf.size == 0); - - git_buf_puts(&buf, test_string); - cl_assert(git_buf_oom(&buf) == 0); - cl_assert_strequal(test_string, git_buf_cstr(&buf)); - - git_buf_puts(&buf, test_string); - cl_assert(git_buf_oom(&buf) == 0); - cl_assert_strequal(test_string_x2, git_buf_cstr(&buf)); - - git_buf_free(&buf); -} - -/* test git_buf_printf */ -void test_core_buffer__1(void) -{ - git_buf buf = GIT_BUF_INIT; - - git_buf_printf(&buf, "%s %s %d ", "shoop", "da", 23); - cl_assert(git_buf_oom(&buf) == 0); - cl_assert_strequal("shoop da 23 ", git_buf_cstr(&buf)); - - git_buf_printf(&buf, "%s %d", "woop", 42); - cl_assert(git_buf_oom(&buf) == 0); - cl_assert_strequal("shoop da 23 woop 42", git_buf_cstr(&buf)); - - git_buf_free(&buf); -} - -/* more thorough test of concatenation options */ -void test_core_buffer__2(void) -{ - git_buf buf = GIT_BUF_INIT; - int i; - char data[128]; - - cl_assert(buf.size == 0); - - /* this must be safe to do */ - git_buf_free(&buf); - cl_assert(buf.size == 0); - cl_assert(buf.asize == 0); - - /* empty buffer should be empty string */ - cl_assert_strequal("", git_buf_cstr(&buf)); - cl_assert(buf.size == 0); - /* cl_assert(buf.asize == 0); -- should not assume what git_buf does */ - - /* free should set us back to the beginning */ - git_buf_free(&buf); - cl_assert(buf.size == 0); - cl_assert(buf.asize == 0); - - /* add letter */ - git_buf_putc(&buf, '+'); - cl_assert(git_buf_oom(&buf) == 0); - cl_assert_strequal("+", git_buf_cstr(&buf)); - - /* add letter again */ - git_buf_putc(&buf, '+'); - cl_assert(git_buf_oom(&buf) == 0); - cl_assert_strequal("++", git_buf_cstr(&buf)); - - /* let's try that a few times */ - for (i = 0; i < 16; ++i) { - git_buf_putc(&buf, '+'); - cl_assert(git_buf_oom(&buf) == 0); - } - cl_assert_strequal("++++++++++++++++++", git_buf_cstr(&buf)); - - git_buf_free(&buf); - - /* add data */ - git_buf_put(&buf, "xo", 2); - cl_assert(git_buf_oom(&buf) == 0); - cl_assert_strequal("xo", git_buf_cstr(&buf)); - - /* add letter again */ - git_buf_put(&buf, "xo", 2); - cl_assert(git_buf_oom(&buf) == 0); - cl_assert_strequal("xoxo", git_buf_cstr(&buf)); - - /* let's try that a few times */ - for (i = 0; i < 16; ++i) { - git_buf_put(&buf, "xo", 2); - cl_assert(git_buf_oom(&buf) == 0); - } - cl_assert_strequal("xoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxo", - git_buf_cstr(&buf)); - - git_buf_free(&buf); - - /* set to string */ - git_buf_sets(&buf, test_string); - cl_assert(git_buf_oom(&buf) == 0); - cl_assert_strequal(test_string, git_buf_cstr(&buf)); - - /* append string */ - git_buf_puts(&buf, test_string); - cl_assert(git_buf_oom(&buf) == 0); - cl_assert_strequal(test_string_x2, git_buf_cstr(&buf)); - - /* set to string again (should overwrite - not append) */ - git_buf_sets(&buf, test_string); - cl_assert(git_buf_oom(&buf) == 0); - cl_assert_strequal(test_string, git_buf_cstr(&buf)); - - /* test clear */ - git_buf_clear(&buf); - cl_assert_strequal("", git_buf_cstr(&buf)); - - git_buf_free(&buf); - - /* test extracting data into buffer */ - git_buf_puts(&buf, REP4("0123456789")); - cl_assert(git_buf_oom(&buf) == 0); - - git_buf_copy_cstr(data, sizeof(data), &buf); - cl_assert_strequal(REP4("0123456789"), data); - git_buf_copy_cstr(data, 11, &buf); - cl_assert_strequal("0123456789", data); - git_buf_copy_cstr(data, 3, &buf); - cl_assert_strequal("01", data); - git_buf_copy_cstr(data, 1, &buf); - cl_assert_strequal("", data); - - git_buf_copy_cstr(data, sizeof(data), &buf); - cl_assert_strequal(REP4("0123456789"), data); - - git_buf_sets(&buf, REP256("x")); - git_buf_copy_cstr(data, sizeof(data), &buf); - /* since sizeof(data) == 128, only 127 bytes should be copied */ - cl_assert_strequal(REP4(REP16("x")) REP16("x") REP16("x") - REP16("x") "xxxxxxxxxxxxxxx", data); - - git_buf_free(&buf); - - git_buf_copy_cstr(data, sizeof(data), &buf); - cl_assert_strequal("", data); -} - -/* let's do some tests with larger buffers to push our limits */ -void test_core_buffer__3(void) -{ - git_buf buf = GIT_BUF_INIT; - - /* set to string */ - git_buf_set(&buf, test_4096, 4096); - cl_assert(git_buf_oom(&buf) == 0); - cl_assert_strequal(test_4096, git_buf_cstr(&buf)); - - /* append string */ - git_buf_puts(&buf, test_4096); - cl_assert(git_buf_oom(&buf) == 0); - cl_assert_strequal(test_8192, git_buf_cstr(&buf)); - - /* set to string again (should overwrite - not append) */ - git_buf_set(&buf, test_4096, 4096); - cl_assert(git_buf_oom(&buf) == 0); - cl_assert_strequal(test_4096, git_buf_cstr(&buf)); - - git_buf_free(&buf); -} - -/* let's try some producer/consumer tests */ -void test_core_buffer__4(void) -{ - git_buf buf = GIT_BUF_INIT; - int i; - - for (i = 0; i < 10; ++i) { - git_buf_puts(&buf, "1234"); /* add 4 */ - cl_assert(git_buf_oom(&buf) == 0); - git_buf_consume(&buf, buf.ptr + 2); /* eat the first two */ - cl_assert(strlen(git_buf_cstr(&buf)) == (size_t)((i + 1) * 2)); - } - /* we have appended 1234 10x and removed the first 20 letters */ - cl_assert_strequal("12341234123412341234", git_buf_cstr(&buf)); - - git_buf_consume(&buf, NULL); - cl_assert_strequal("12341234123412341234", git_buf_cstr(&buf)); - - git_buf_consume(&buf, "invalid pointer"); - cl_assert_strequal("12341234123412341234", git_buf_cstr(&buf)); - - git_buf_consume(&buf, buf.ptr); - cl_assert_strequal("12341234123412341234", git_buf_cstr(&buf)); - - git_buf_consume(&buf, buf.ptr + 1); - cl_assert_strequal("2341234123412341234", git_buf_cstr(&buf)); - - git_buf_consume(&buf, buf.ptr + buf.size); - cl_assert_strequal("", git_buf_cstr(&buf)); - - git_buf_free(&buf); -} - - -static void -check_buf_append( - const char* data_a, - const char* data_b, - const char* expected_data, - ssize_t expected_size, - ssize_t expected_asize) -{ - git_buf tgt = GIT_BUF_INIT; - - git_buf_sets(&tgt, data_a); - cl_assert(git_buf_oom(&tgt) == 0); - git_buf_puts(&tgt, data_b); - cl_assert(git_buf_oom(&tgt) == 0); - cl_assert_strequal(expected_data, git_buf_cstr(&tgt)); - cl_assert(tgt.size == expected_size); - if (expected_asize > 0) - cl_assert(tgt.asize == expected_asize); - - git_buf_free(&tgt); -} - -static void -check_buf_append_abc( - const char* buf_a, - const char* buf_b, - const char* buf_c, - const char* expected_ab, - const char* expected_abc, - const char* expected_abca, - const char* expected_abcab, - const char* expected_abcabc) -{ - git_buf buf = GIT_BUF_INIT; - - git_buf_sets(&buf, buf_a); - cl_assert(git_buf_oom(&buf) == 0); - cl_assert_strequal(buf_a, git_buf_cstr(&buf)); - - git_buf_puts(&buf, buf_b); - cl_assert(git_buf_oom(&buf) == 0); - cl_assert_strequal(expected_ab, git_buf_cstr(&buf)); - - git_buf_puts(&buf, buf_c); - cl_assert(git_buf_oom(&buf) == 0); - cl_assert_strequal(expected_abc, git_buf_cstr(&buf)); - - git_buf_puts(&buf, buf_a); - cl_assert(git_buf_oom(&buf) == 0); - cl_assert_strequal(expected_abca, git_buf_cstr(&buf)); - - git_buf_puts(&buf, buf_b); - cl_assert(git_buf_oom(&buf) == 0); - cl_assert_strequal(expected_abcab, git_buf_cstr(&buf)); - - git_buf_puts(&buf, buf_c); - cl_assert(git_buf_oom(&buf) == 0); - cl_assert_strequal(expected_abcabc, git_buf_cstr(&buf)); - - git_buf_free(&buf); -} - -/* more variations on append tests */ -void test_core_buffer__5(void) -{ - check_buf_append("", "", "", 0, 8); - check_buf_append("a", "", "a", 1, 8); - check_buf_append("", "a", "a", 1, 8); - check_buf_append("", "a", "a", 1, 8); - check_buf_append("a", "", "a", 1, 8); - check_buf_append("a", "b", "ab", 2, 8); - check_buf_append("", "abcdefgh", "abcdefgh", 8, 16); - check_buf_append("abcdefgh", "", "abcdefgh", 8, 16); - - /* buffer with starting asize will grow to: - * 1 -> 2, 2 -> 3, 3 -> 5, 4 -> 6, 5 -> 8, 6 -> 9, - * 7 -> 11, 8 -> 12, 9 -> 14, 10 -> 15, 11 -> 17, 12 -> 18, - * 13 -> 20, 14 -> 21, 15 -> 23, 16 -> 24, 17 -> 26, 18 -> 27, - * 19 -> 29, 20 -> 30, 21 -> 32, 22 -> 33, 23 -> 35, 24 -> 36, - * ... - * follow sequence until value > target size, - * then round up to nearest multiple of 8. - */ - - check_buf_append("abcdefgh", "/", "abcdefgh/", 9, 16); - check_buf_append("abcdefgh", "ijklmno", "abcdefghijklmno", 15, 16); - check_buf_append("abcdefgh", "ijklmnop", "abcdefghijklmnop", 16, 24); - check_buf_append("0123456789", "0123456789", - "01234567890123456789", 20, 24); - check_buf_append(REP16("x"), REP16("o"), - REP16("x") REP16("o"), 32, 40); - - check_buf_append(test_4096, "", test_4096, 4096, 4104); - check_buf_append(test_4096, test_4096, test_8192, 8192, 9240); - - /* check sequences of appends */ - check_buf_append_abc("a", "b", "c", - "ab", "abc", "abca", "abcab", "abcabc"); - check_buf_append_abc("a1", "b2", "c3", - "a1b2", "a1b2c3", "a1b2c3a1", - "a1b2c3a1b2", "a1b2c3a1b2c3"); - check_buf_append_abc("a1/", "b2/", "c3/", - "a1/b2/", "a1/b2/c3/", "a1/b2/c3/a1/", - "a1/b2/c3/a1/b2/", "a1/b2/c3/a1/b2/c3/"); -} - -/* test swap */ -void test_core_buffer__6(void) -{ - git_buf a = GIT_BUF_INIT; - git_buf b = GIT_BUF_INIT; - - git_buf_sets(&a, "foo"); - cl_assert(git_buf_oom(&a) == 0); - git_buf_sets(&b, "bar"); - cl_assert(git_buf_oom(&b) == 0); - - cl_assert_strequal("foo", git_buf_cstr(&a)); - cl_assert_strequal("bar", git_buf_cstr(&b)); - - git_buf_swap(&a, &b); - - cl_assert_strequal("bar", git_buf_cstr(&a)); - cl_assert_strequal("foo", git_buf_cstr(&b)); - - git_buf_free(&a); - git_buf_free(&b); -} - - -/* test detach/attach data */ -void test_core_buffer__7(void) -{ - const char *fun = "This is fun"; - git_buf a = GIT_BUF_INIT; - char *b = NULL; - - git_buf_sets(&a, "foo"); - cl_assert(git_buf_oom(&a) == 0); - cl_assert_strequal("foo", git_buf_cstr(&a)); - - b = git_buf_detach(&a); - - cl_assert_strequal("foo", b); - cl_assert_strequal("", a.ptr); - git__free(b); - - b = git_buf_detach(&a); - - cl_assert_strequal(NULL, b); - cl_assert_strequal("", a.ptr); - - git_buf_free(&a); - - b = git__strdup(fun); - git_buf_attach(&a, b, 0); - - cl_assert_strequal(fun, a.ptr); - cl_assert(a.size == (ssize_t)strlen(fun)); - cl_assert(a.asize == (ssize_t)strlen(fun) + 1); - - git_buf_free(&a); - - b = git__strdup(fun); - git_buf_attach(&a, b, strlen(fun) + 1); - - cl_assert_strequal(fun, a.ptr); - cl_assert(a.size == (ssize_t)strlen(fun)); - cl_assert(a.asize == (ssize_t)strlen(fun) + 1); - - git_buf_free(&a); -} - - -static void -check_joinbuf_2( - const char *a, - const char *b, - const char *expected) -{ - char sep = '/'; - git_buf buf = GIT_BUF_INIT; - - git_buf_join(&buf, sep, a, b); - cl_assert(git_buf_oom(&buf) == 0); - cl_assert_strequal(expected, git_buf_cstr(&buf)); - git_buf_free(&buf); -} - -static void -check_joinbuf_n_2( - const char *a, - const char *b, - const char *expected) -{ - char sep = '/'; - git_buf buf = GIT_BUF_INIT; - - git_buf_sets(&buf, a); - cl_assert(git_buf_oom(&buf) == 0); - - git_buf_join_n(&buf, sep, 1, b); - cl_assert(git_buf_oom(&buf) == 0); - cl_assert_strequal(expected, git_buf_cstr(&buf)); - - git_buf_free(&buf); -} - -static void -check_joinbuf_n_4( - const char *a, - const char *b, - const char *c, - const char *d, - const char *expected) -{ - char sep = ';'; - git_buf buf = GIT_BUF_INIT; - git_buf_join_n(&buf, sep, 4, a, b, c, d); - cl_assert(git_buf_oom(&buf) == 0); - cl_assert_strequal(expected, git_buf_cstr(&buf)); - git_buf_free(&buf); -} - -/* test join */ -void test_core_buffer__8(void) -{ - git_buf a = GIT_BUF_INIT; - - git_buf_join_n(&a, '/', 1, "foo"); - cl_assert(git_buf_oom(&a) == 0); - cl_assert_strequal("foo", git_buf_cstr(&a)); - - git_buf_join_n(&a, '/', 1, "bar"); - cl_assert(git_buf_oom(&a) == 0); - cl_assert_strequal("foo/bar", git_buf_cstr(&a)); - - git_buf_join_n(&a, '/', 1, "baz"); - cl_assert(git_buf_oom(&a) == 0); - cl_assert_strequal("foo/bar/baz", git_buf_cstr(&a)); - - git_buf_free(&a); - - check_joinbuf_2("", "", ""); - check_joinbuf_2("", "a", "a"); - check_joinbuf_2("", "/a", "/a"); - check_joinbuf_2("a", "", "a/"); - check_joinbuf_2("a", "/", "a/"); - check_joinbuf_2("a", "b", "a/b"); - check_joinbuf_2("/", "a", "/a"); - check_joinbuf_2("/", "", "/"); - check_joinbuf_2("/a", "/b", "/a/b"); - check_joinbuf_2("/a", "/b/", "/a/b/"); - check_joinbuf_2("/a/", "b/", "/a/b/"); - check_joinbuf_2("/a/", "/b/", "/a/b/"); - check_joinbuf_2("/a/", "//b/", "/a/b/"); - check_joinbuf_2("/abcd", "/defg", "/abcd/defg"); - check_joinbuf_2("/abcd", "/defg/", "/abcd/defg/"); - check_joinbuf_2("/abcd/", "defg/", "/abcd/defg/"); - check_joinbuf_2("/abcd/", "/defg/", "/abcd/defg/"); - - check_joinbuf_n_2("", "", ""); - check_joinbuf_n_2("", "a", "a"); - check_joinbuf_n_2("", "/a", "/a"); - check_joinbuf_n_2("a", "", "a/"); - check_joinbuf_n_2("a", "/", "a/"); - check_joinbuf_n_2("a", "b", "a/b"); - check_joinbuf_n_2("/", "a", "/a"); - check_joinbuf_n_2("/", "", "/"); - check_joinbuf_n_2("/a", "/b", "/a/b"); - check_joinbuf_n_2("/a", "/b/", "/a/b/"); - check_joinbuf_n_2("/a/", "b/", "/a/b/"); - check_joinbuf_n_2("/a/", "/b/", "/a/b/"); - check_joinbuf_n_2("/abcd", "/defg", "/abcd/defg"); - check_joinbuf_n_2("/abcd", "/defg/", "/abcd/defg/"); - check_joinbuf_n_2("/abcd/", "defg/", "/abcd/defg/"); - check_joinbuf_n_2("/abcd/", "/defg/", "/abcd/defg/"); - - check_joinbuf_n_4("", "", "", "", ""); - check_joinbuf_n_4("", "a", "", "", "a;"); - check_joinbuf_n_4("a", "", "", "", "a;"); - check_joinbuf_n_4("", "", "", "a", "a"); - check_joinbuf_n_4("a", "b", "", ";c;d;", "a;b;c;d;"); - check_joinbuf_n_4("a", "b", "", ";c;d", "a;b;c;d"); - check_joinbuf_n_4("abcd", "efgh", "ijkl", "mnop", "abcd;efgh;ijkl;mnop"); - check_joinbuf_n_4("abcd;", "efgh;", "ijkl;", "mnop;", "abcd;efgh;ijkl;mnop;"); - check_joinbuf_n_4(";abcd;", ";efgh;", ";ijkl;", ";mnop;", ";abcd;efgh;ijkl;mnop;"); -} - -void test_core_buffer__9(void) -{ - git_buf buf = GIT_BUF_INIT; - - /* just some exhaustive tests of various separator placement */ - char *a[] = { "", "-", "a-", "-a", "-a-" }; - char *b[] = { "", "-", "b-", "-b", "-b-" }; - char sep[] = { 0, '-', '/' }; - char *expect_null[] = { "", "-", "a-", "-a", "-a-", - "-", "--", "a--", "-a-", "-a--", - "b-", "-b-", "a-b-", "-ab-", "-a-b-", - "-b", "--b", "a--b", "-a-b", "-a--b", - "-b-", "--b-", "a--b-", "-a-b-", "-a--b-" }; - char *expect_dash[] = { "", "-", "a-", "-a-", "-a-", - "-", "-", "a-", "-a-", "-a-", - "b-", "-b-", "a-b-", "-a-b-", "-a-b-", - "-b", "-b", "a-b", "-a-b", "-a-b", - "-b-", "-b-", "a-b-", "-a-b-", "-a-b-" }; - char *expect_slas[] = { "", "-/", "a-/", "-a/", "-a-/", - "-", "-/-", "a-/-", "-a/-", "-a-/-", - "b-", "-/b-", "a-/b-", "-a/b-", "-a-/b-", - "-b", "-/-b", "a-/-b", "-a/-b", "-a-/-b", - "-b-", "-/-b-", "a-/-b-", "-a/-b-", "-a-/-b-" }; - char **expect_values[] = { expect_null, expect_dash, expect_slas }; - char separator, **expect; - unsigned int s, i, j; - - for (s = 0; s < sizeof(sep) / sizeof(char); ++s) { - separator = sep[s]; - expect = expect_values[s]; - - for (j = 0; j < sizeof(b) / sizeof(char*); ++j) { - for (i = 0; i < sizeof(a) / sizeof(char*); ++i) { - git_buf_join(&buf, separator, a[i], b[j]); - cl_assert_strequal(*expect, buf.ptr); - expect++; - } - } - } - - git_buf_free(&buf); -} diff --git a/tests-clay/core/dirent.c b/tests-clay/core/dirent.c deleted file mode 100644 index c9ab1c103..000000000 --- a/tests-clay/core/dirent.c +++ /dev/null @@ -1,224 +0,0 @@ -#include "clay_libgit2.h" -#include "fileops.h" - -typedef struct name_data { - int count; /* return count */ - char *name; /* filename */ -} name_data; - -typedef struct walk_data { - char *sub; /* sub-directory name */ - name_data *names; /* name state data */ - git_buf path; -} walk_data; - - -static char *top_dir = "dir-walk"; -static walk_data *state_loc; - -static void setup(walk_data *d) -{ - name_data *n; - - cl_must_pass(p_mkdir(top_dir, 0777)); - - cl_must_pass(p_chdir(top_dir)); - - if (strcmp(d->sub, ".") != 0) - cl_must_pass(p_mkdir(d->sub, 0777)); - - cl_git_pass(git_buf_sets(&d->path, d->sub)); - - state_loc = d; - - for (n = d->names; n->name; n++) { - git_file fd = p_creat(n->name, 0666); - cl_assert(fd >= 0); - p_close(fd); - n->count = 0; - } -} - -static void dirent_cleanup__cb(void *_d) -{ - walk_data *d = _d; - name_data *n; - - for (n = d->names; n->name; n++) { - cl_must_pass(p_unlink(n->name)); - } - - if (strcmp(d->sub, ".") != 0) - cl_must_pass(p_rmdir(d->sub)); - - cl_must_pass(p_chdir("..")); - - cl_must_pass(p_rmdir(top_dir)); - - git_buf_free(&d->path); -} - -static void check_counts(walk_data *d) -{ - name_data *n; - - for (n = d->names; n->name; n++) { - cl_assert(n->count == 1); - } -} - -static int one_entry(void *state, git_buf *path) -{ - walk_data *d = (walk_data *) state; - name_data *n; - - if (state != state_loc) - return GIT_ERROR; - - if (path != &d->path) - return GIT_ERROR; - - for (n = d->names; n->name; n++) { - if (!strcmp(n->name, path->ptr)) { - n->count++; - return 0; - } - } - - return GIT_ERROR; -} - -static int dont_call_me(void *GIT_UNUSED(state), git_buf *GIT_UNUSED(path)) -{ - GIT_UNUSED_ARG(state) - GIT_UNUSED_ARG(path) - return GIT_ERROR; -} - - - -static name_data dot_names[] = { - { 0, "./a" }, - { 0, "./asdf" }, - { 0, "./pack-foo.pack" }, - { 0, NULL } -}; -static walk_data dot = { - ".", - dot_names, - GIT_BUF_INIT -}; - -/* make sure that the '.' folder is not traversed */ -void test_core_dirent__dont_traverse_dot(void) -{ - cl_set_cleanup(&dirent_cleanup__cb, &dot); - setup(&dot); - - cl_git_pass(git_path_direach(&dot.path, - one_entry, - &dot)); - - check_counts(&dot); -} - - -static name_data sub_names[] = { - { 0, "sub/a" }, - { 0, "sub/asdf" }, - { 0, "sub/pack-foo.pack" }, - { 0, NULL } -}; -static walk_data sub = { - "sub", - sub_names, - GIT_BUF_INIT -}; - -/* traverse a subfolder */ -void test_core_dirent__traverse_subfolder(void) -{ - cl_set_cleanup(&dirent_cleanup__cb, &sub); - setup(&sub); - - cl_git_pass(git_path_direach(&sub.path, - one_entry, - &sub)); - - check_counts(&sub); -} - - -static walk_data sub_slash = { - "sub/", - sub_names, - GIT_BUF_INIT -}; - -/* traverse a slash-terminated subfolder */ -void test_core_dirent__traverse_slash_terminated_folder(void) -{ - cl_set_cleanup(&dirent_cleanup__cb, &sub_slash); - setup(&sub_slash); - - cl_git_pass(git_path_direach(&sub_slash.path, - one_entry, - &sub_slash)); - - check_counts(&sub_slash); -} - - -static name_data empty_names[] = { - { 0, NULL } -}; -static walk_data empty = { - "empty", - empty_names, - GIT_BUF_INIT -}; - -/* make sure that empty folders are not traversed */ -void test_core_dirent__dont_traverse_empty_folders(void) -{ - cl_set_cleanup(&dirent_cleanup__cb, &empty); - setup(&empty); - - cl_git_pass(git_path_direach(&empty.path, - one_entry, - &empty)); - - check_counts(&empty); - - /* make sure callback not called */ - cl_git_pass(git_path_direach(&empty.path, - dont_call_me, - &empty)); -} - -static name_data odd_names[] = { - { 0, "odd/.a" }, - { 0, "odd/..c" }, - /* the following don't work on cygwin/win32 */ - /* { 0, "odd/.b." }, */ - /* { 0, "odd/..d.." }, */ - { 0, NULL } -}; -static walk_data odd = { - "odd", - odd_names, - GIT_BUF_INIT -}; - -/* make sure that strange looking filenames ('..c') are traversed */ -void test_core_dirent__traverse_weird_filenames(void) -{ - cl_set_cleanup(&dirent_cleanup__cb, &odd); - setup(&odd); - - cl_git_pass(git_path_direach(&odd.path, - one_entry, - &odd)); - - check_counts(&odd); -} diff --git a/tests-clay/core/filebuf.c b/tests-clay/core/filebuf.c deleted file mode 100644 index 6a87902fe..000000000 --- a/tests-clay/core/filebuf.c +++ /dev/null @@ -1,106 +0,0 @@ -#include "clay_libgit2.h" -#include "filebuf.h" - -/* make sure git_filebuf_open doesn't delete an existing lock */ -void test_core_filebuf__0(void) -{ - git_filebuf file = GIT_FILEBUF_INIT; - int fd; - char test[] = "test", testlock[] = "test.lock"; - - fd = p_creat(testlock, 0744); - - cl_must_pass(fd); - cl_must_pass(p_close(fd)); - - cl_git_fail(git_filebuf_open(&file, test, 0)); - cl_git_pass(git_path_exists(testlock)); - - cl_must_pass(p_unlink(testlock)); -} - - -/* make sure GIT_FILEBUF_APPEND works as expected */ -void test_core_filebuf__1(void) -{ - git_filebuf file = GIT_FILEBUF_INIT; - int fd; - char test[] = "test"; - - fd = p_creat(test, 0666); - cl_must_pass(fd); - cl_must_pass(p_write(fd, "libgit2 rocks\n", 14)); - cl_must_pass(p_close(fd)); - - cl_git_pass(git_filebuf_open(&file, test, GIT_FILEBUF_APPEND)); - cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks")); - cl_git_pass(git_filebuf_commit(&file, 0666)); - - cl_must_pass(p_unlink(test)); -} - - -/* make sure git_filebuf_write writes large buffer correctly */ -void test_core_filebuf__2(void) -{ - git_filebuf file = GIT_FILEBUF_INIT; - char test[] = "test"; - unsigned char buf[4096 * 4]; /* 2 * WRITE_BUFFER_SIZE */ - - memset(buf, 0xfe, sizeof(buf)); - - cl_git_pass(git_filebuf_open(&file, test, 0)); - cl_git_pass(git_filebuf_write(&file, buf, sizeof(buf))); - cl_git_pass(git_filebuf_commit(&file, 0666)); - - cl_must_pass(p_unlink(test)); -} - - -/* make sure git_filebuf_open won't reopen an open buffer */ -void test_core_filebuf__3(void) -{ - git_filebuf file = GIT_FILEBUF_INIT; - char test[] = "test"; - - cl_git_pass(git_filebuf_open(&file, test, 0)); - cl_git_fail(git_filebuf_open(&file, test, 0)); - - git_filebuf_cleanup(&file); -} - - -/* make sure git_filebuf_cleanup clears the buffer */ -void test_core_filebuf__4(void) -{ - git_filebuf file = GIT_FILEBUF_INIT; - char test[] = "test"; - - cl_assert(file.buffer == NULL); - - cl_git_pass(git_filebuf_open(&file, test, 0)); - cl_assert(file.buffer != NULL); - - git_filebuf_cleanup(&file); - cl_assert(file.buffer == NULL); -} - - -/* make sure git_filebuf_commit clears the buffer */ -void test_core_filebuf__5(void) -{ - git_filebuf file = GIT_FILEBUF_INIT; - char test[] = "test"; - - cl_assert(file.buffer == NULL); - - cl_git_pass(git_filebuf_open(&file, test, 0)); - cl_assert(file.buffer != NULL); - cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks")); - cl_assert(file.buffer != NULL); - - cl_git_pass(git_filebuf_commit(&file, 0666)); - cl_assert(file.buffer == NULL); - - cl_must_pass(p_unlink(test)); -} diff --git a/tests-clay/core/hex.c b/tests-clay/core/hex.c deleted file mode 100644 index 391a286be..000000000 --- a/tests-clay/core/hex.c +++ /dev/null @@ -1,22 +0,0 @@ -#include "clay_libgit2.h" -#include "util.h" - -void test_core_hex__fromhex(void) -{ - /* Passing cases */ - cl_assert(git__fromhex('0') == 0x0); - cl_assert(git__fromhex('1') == 0x1); - cl_assert(git__fromhex('3') == 0x3); - cl_assert(git__fromhex('9') == 0x9); - cl_assert(git__fromhex('A') == 0xa); - cl_assert(git__fromhex('C') == 0xc); - cl_assert(git__fromhex('F') == 0xf); - cl_assert(git__fromhex('a') == 0xa); - cl_assert(git__fromhex('c') == 0xc); - cl_assert(git__fromhex('f') == 0xf); - - /* Failing cases */ - cl_assert(git__fromhex('g') == -1); - cl_assert(git__fromhex('z') == -1); - cl_assert(git__fromhex('X') == -1); -} diff --git a/tests-clay/core/oid.c b/tests-clay/core/oid.c deleted file mode 100644 index 44597c5ae..000000000 --- a/tests-clay/core/oid.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "clay_libgit2.h" - -static git_oid id; -const char *str_oid = "ae90f12eea699729ed24555e40b9fd669da12a12"; - -void test_core_oid__initialize(void) -{ - cl_git_pass(git_oid_fromstr(&id, str_oid)); -} - -void test_core_oid__streq(void) -{ - cl_assert(git_oid_streq(&id, str_oid) == GIT_SUCCESS); - cl_assert(git_oid_streq(&id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef") == GIT_ERROR); - - cl_assert(git_oid_streq(&id, "deadbeef") == GIT_ENOTOID); - cl_assert(git_oid_streq(&id, "I'm not an oid.... :)") == GIT_ENOTOID); -}
\ No newline at end of file diff --git a/tests-clay/core/path.c b/tests-clay/core/path.c deleted file mode 100644 index 1a77a1f15..000000000 --- a/tests-clay/core/path.c +++ /dev/null @@ -1,390 +0,0 @@ -#include "clay_libgit2.h" -#include <fileops.h> - -static void -check_dirname(const char *A, const char *B) -{ - git_buf dir = GIT_BUF_INIT; - char *dir2; - - cl_assert(git_path_dirname_r(&dir, A) >= 0); - cl_assert_strequal(B, dir.ptr); - git_buf_free(&dir); - - cl_assert((dir2 = git_path_dirname(A)) != NULL); - cl_assert_strequal(B, dir2); - git__free(dir2); -} - -static void -check_basename(const char *A, const char *B) -{ - git_buf base = GIT_BUF_INIT; - char *base2; - - cl_assert(git_path_basename_r(&base, A) >= 0); - cl_assert_strequal(B, base.ptr); - git_buf_free(&base); - - cl_assert((base2 = git_path_basename(A)) != NULL); - cl_assert_strequal(B, base2); - git__free(base2); -} - -static void -check_topdir(const char *A, const char *B) -{ - const char *dir; - - cl_assert((dir = git_path_topdir(A)) != NULL); - cl_assert_strequal(B, dir); -} - -static void -check_joinpath(const char *path_a, const char *path_b, const char *expected_path) -{ - git_buf joined_path = GIT_BUF_INIT; - - cl_git_pass(git_buf_joinpath(&joined_path, path_a, path_b)); - cl_assert_strequal(expected_path, joined_path.ptr); - - git_buf_free(&joined_path); -} - -static void -check_joinpath_n( - const char *path_a, - const char *path_b, - const char *path_c, - const char *path_d, - const char *expected_path) -{ - git_buf joined_path = GIT_BUF_INIT; - - cl_git_pass(git_buf_join_n(&joined_path, '/', 4, - path_a, path_b, path_c, path_d)); - cl_assert_strequal(expected_path, joined_path.ptr); - - git_buf_free(&joined_path); -} - - -/* get the dirname of a path */ -void test_core_path__00_dirname(void) -{ - check_dirname(NULL, "."); - check_dirname("", "."); - check_dirname("a", "."); - check_dirname("/", "/"); - check_dirname("/usr", "/"); - check_dirname("/usr/", "/"); - check_dirname("/usr/lib", "/usr"); - check_dirname("/usr/lib/", "/usr"); - check_dirname("/usr/lib//", "/usr"); - check_dirname("usr/lib", "usr"); - check_dirname("usr/lib/", "usr"); - check_dirname("usr/lib//", "usr"); - check_dirname(".git/", "."); - - check_dirname(REP16("/abc"), REP15("/abc")); -} - -/* get the base name of a path */ -void test_core_path__01_basename(void) -{ - check_basename(NULL, "."); - check_basename("", "."); - check_basename("a", "a"); - check_basename("/", "/"); - check_basename("/usr", "usr"); - check_basename("/usr/", "usr"); - check_basename("/usr/lib", "lib"); - check_basename("/usr/lib//", "lib"); - check_basename("usr/lib", "lib"); - - check_basename(REP16("/abc"), "abc"); - check_basename(REP1024("/abc"), "abc"); -} - -/* get the latest component in a path */ -void test_core_path__02_topdir(void) -{ - check_topdir(".git/", ".git/"); - check_topdir("/.git/", ".git/"); - check_topdir("usr/local/.git/", ".git/"); - check_topdir("./.git/", ".git/"); - check_topdir("/usr/.git/", ".git/"); - check_topdir("/", "/"); - check_topdir("a/", "a/"); - - cl_assert(git_path_topdir("/usr/.git") == NULL); - cl_assert(git_path_topdir(".") == NULL); - cl_assert(git_path_topdir("") == NULL); - cl_assert(git_path_topdir("a") == NULL); -} - -/* properly join path components */ -void test_core_path__05_joins(void) -{ - check_joinpath("", "", ""); - check_joinpath("", "a", "a"); - check_joinpath("", "/a", "/a"); - check_joinpath("a", "", "a/"); - check_joinpath("a", "/", "a/"); - check_joinpath("a", "b", "a/b"); - check_joinpath("/", "a", "/a"); - check_joinpath("/", "", "/"); - check_joinpath("/a", "/b", "/a/b"); - check_joinpath("/a", "/b/", "/a/b/"); - check_joinpath("/a/", "b/", "/a/b/"); - check_joinpath("/a/", "/b/", "/a/b/"); - - check_joinpath("/abcd", "/defg", "/abcd/defg"); - check_joinpath("/abcd", "/defg/", "/abcd/defg/"); - check_joinpath("/abcd/", "defg/", "/abcd/defg/"); - check_joinpath("/abcd/", "/defg/", "/abcd/defg/"); - - check_joinpath("/abcdefgh", "/12345678", "/abcdefgh/12345678"); - check_joinpath("/abcdefgh", "/12345678/", "/abcdefgh/12345678/"); - check_joinpath("/abcdefgh/", "12345678/", "/abcdefgh/12345678/"); - - check_joinpath(REP1024("aaaa"), "", REP1024("aaaa") "/"); - check_joinpath(REP1024("aaaa/"), "", REP1024("aaaa/")); - check_joinpath(REP1024("/aaaa"), "", REP1024("/aaaa") "/"); - - check_joinpath(REP1024("aaaa"), REP1024("bbbb"), - REP1024("aaaa") "/" REP1024("bbbb")); - check_joinpath(REP1024("/aaaa"), REP1024("/bbbb"), - REP1024("/aaaa") REP1024("/bbbb")); -} - -/* properly join path components for more than one path */ -void test_core_path__06_long_joins(void) -{ - check_joinpath_n("", "", "", "", ""); - check_joinpath_n("", "a", "", "", "a/"); - check_joinpath_n("a", "", "", "", "a/"); - check_joinpath_n("", "", "", "a", "a"); - check_joinpath_n("a", "b", "", "/c/d/", "a/b/c/d/"); - check_joinpath_n("a", "b", "", "/c/d", "a/b/c/d"); - check_joinpath_n("abcd", "efgh", "ijkl", "mnop", "abcd/efgh/ijkl/mnop"); - check_joinpath_n("abcd/", "efgh/", "ijkl/", "mnop/", "abcd/efgh/ijkl/mnop/"); - check_joinpath_n("/abcd/", "/efgh/", "/ijkl/", "/mnop/", "/abcd/efgh/ijkl/mnop/"); - - check_joinpath_n(REP1024("a"), REP1024("b"), REP1024("c"), REP1024("d"), - REP1024("a") "/" REP1024("b") "/" - REP1024("c") "/" REP1024("d")); - check_joinpath_n(REP1024("/a"), REP1024("/b"), REP1024("/c"), REP1024("/d"), - REP1024("/a") REP1024("/b") - REP1024("/c") REP1024("/d")); -} - - -static void -check_path_to_dir( - const char* path, - const char* expected) -{ - git_buf tgt = GIT_BUF_INIT; - - git_buf_sets(&tgt, path); - cl_git_pass(git_path_to_dir(&tgt)); - cl_assert_strequal(expected, tgt.ptr); - - git_buf_free(&tgt); -} - -static void -check_string_to_dir( - const char* path, - int maxlen, - const char* expected) -{ - int len = strlen(path); - char *buf = git__malloc(len + 2); - strncpy(buf, path, len + 2); - - git_path_string_to_dir(buf, maxlen); - - cl_assert_strequal(expected, buf); - - git__free(buf); -} - -/* convert paths to dirs */ -void test_core_path__07_path_to_dir(void) -{ - check_path_to_dir("", ""); - check_path_to_dir(".", "./"); - check_path_to_dir("./", "./"); - check_path_to_dir("a/", "a/"); - check_path_to_dir("ab", "ab/"); - /* make sure we try just under and just over an expansion that will - * require a realloc - */ - check_path_to_dir("abcdef", "abcdef/"); - check_path_to_dir("abcdefg", "abcdefg/"); - check_path_to_dir("abcdefgh", "abcdefgh/"); - check_path_to_dir("abcdefghi", "abcdefghi/"); - check_path_to_dir(REP1024("abcd") "/", REP1024("abcd") "/"); - check_path_to_dir(REP1024("abcd"), REP1024("abcd") "/"); - - check_string_to_dir("", 1, ""); - check_string_to_dir(".", 1, "."); - check_string_to_dir(".", 2, "./"); - check_string_to_dir(".", 3, "./"); - check_string_to_dir("abcd", 3, "abcd"); - check_string_to_dir("abcd", 4, "abcd"); - check_string_to_dir("abcd", 5, "abcd/"); - check_string_to_dir("abcd", 6, "abcd/"); -} - -/* join path to itself */ -void test_core_path__08_self_join(void) -{ - git_buf path = GIT_BUF_INIT; - ssize_t asize = 0; - - asize = path.asize; - cl_git_pass(git_buf_sets(&path, "/foo")); - cl_assert_strequal(path.ptr, "/foo"); - cl_assert(asize < path.asize); - - asize = path.asize; - cl_git_pass(git_buf_joinpath(&path, path.ptr, "this is a new string")); - cl_assert_strequal(path.ptr, "/foo/this is a new string"); - cl_assert(asize < path.asize); - - asize = path.asize; - cl_git_pass(git_buf_joinpath(&path, path.ptr, "/grow the buffer, grow the buffer, grow the buffer")); - cl_assert_strequal(path.ptr, "/foo/this is a new string/grow the buffer, grow the buffer, grow the buffer"); - cl_assert(asize < path.asize); - - git_buf_free(&path); - cl_git_pass(git_buf_sets(&path, "/foo/bar")); - - cl_git_pass(git_buf_joinpath(&path, path.ptr + 4, "baz")); - cl_assert_strequal(path.ptr, "/bar/baz"); - - asize = path.asize; - cl_git_pass(git_buf_joinpath(&path, path.ptr + 4, "somethinglongenoughtorealloc")); - cl_assert_strequal(path.ptr, "/baz/somethinglongenoughtorealloc"); - cl_assert(asize < path.asize); - - git_buf_free(&path); -} - -static void check_percent_decoding(const char *expected_result, const char *input) -{ - git_buf buf = GIT_BUF_INIT; - - cl_git_pass(git__percent_decode(&buf, input)); - cl_assert_strequal(expected_result, git_buf_cstr(&buf)); - - git_buf_free(&buf); -} - -void test_core_path__09_percent_decode(void) -{ - check_percent_decoding("abcd", "abcd"); - check_percent_decoding("a2%", "a2%"); - check_percent_decoding("a2%3", "a2%3"); - check_percent_decoding("a2%%3", "a2%%3"); - check_percent_decoding("a2%3z", "a2%3z"); - check_percent_decoding("a,", "a%2c"); - check_percent_decoding("a21", "a2%31"); - check_percent_decoding("a2%1", "a2%%31"); - check_percent_decoding("a bc ", "a%20bc%20"); - check_percent_decoding("Vicent Mart" "\355", "Vicent%20Mart%ED"); -} - -static void check_fromurl(const char *expected_result, const char *input, int should_fail) -{ - git_buf buf = GIT_BUF_INIT; - - assert(should_fail || expected_result); - - if (!should_fail) { - cl_git_pass(git_path_fromurl(&buf, input)); - cl_assert_strequal(expected_result, git_buf_cstr(&buf)); - } else - cl_git_fail(git_path_fromurl(&buf, input)); - - git_buf_free(&buf); -} - -#ifdef _MSC_VER -#define ABS_PATH_MARKER "" -#else -#define ABS_PATH_MARKER "/" -#endif - -void test_core_path__10_fromurl(void) -{ - /* Failing cases */ - check_fromurl(NULL, "a", 1); - check_fromurl(NULL, "http:///c:/Temp%20folder/note.txt", 1); - check_fromurl(NULL, "file://c:/Temp%20folder/note.txt", 1); - check_fromurl(NULL, "file:////c:/Temp%20folder/note.txt", 1); - check_fromurl(NULL, "file:///", 1); - check_fromurl(NULL, "file:////", 1); - check_fromurl(NULL, "file://servername/c:/Temp%20folder/note.txt", 1); - - /* Passing cases */ - check_fromurl(ABS_PATH_MARKER "c:/Temp folder/note.txt", "file:///c:/Temp%20folder/note.txt", 0); - check_fromurl(ABS_PATH_MARKER "c:/Temp folder/note.txt", "file://localhost/c:/Temp%20folder/note.txt", 0); - check_fromurl(ABS_PATH_MARKER "c:/Temp+folder/note.txt", "file:///c:/Temp+folder/note.txt", 0); - check_fromurl(ABS_PATH_MARKER "a", "file:///a", 0); -} - -typedef struct { - int expect_idx; - char **expect; -} check_walkup_info; - -static int check_one_walkup_step(void *ref, git_buf *path) -{ - check_walkup_info *info = (check_walkup_info *)ref; - cl_assert(info->expect[info->expect_idx] != NULL); - cl_assert_strequal(info->expect[info->expect_idx], path->ptr); - info->expect_idx++; - return GIT_SUCCESS; -} - -void test_core_path__11_walkup(void) -{ - git_buf p = GIT_BUF_INIT; - char *expect[] = { - "/a/b/c/d/e/", "/a/b/c/d/", "/a/b/c/", "/a/b/", "/a/", "/", NULL, - "/a/b/c/d/e", "/a/b/c/d/", "/a/b/c/", "/a/b/", "/a/", "/", NULL, - "/a/b/c/d/e", "/a/b/c/d/", "/a/b/c/", "/a/b/", "/a/", "/", NULL, - "/a/b/c/d/e", "/a/b/c/d/", "/a/b/c/", "/a/b/", "/a/", "/", NULL, - "/a/b/c/d/e", "/a/b/c/d/", "/a/b/c/", "/a/b/", NULL, - "/a/b/c/d/e", "/a/b/c/d/", "/a/b/c/", "/a/b/", NULL, - "this is a path", NULL, - "///a///b///c///d///e///", "///a///b///c///d///", "///a///b///c///", "///a///b///", "///a///", "///", NULL, - NULL - }; - char *root[] = { NULL, NULL, "/", "", "/a/b", "/a/b/", NULL, NULL, NULL }; - int i, j; - check_walkup_info info; - - info.expect = expect; - - for (i = 0, j = 0; expect[i] != NULL; i++, j++) { - - git_buf_sets(&p, expect[i]); - - info.expect_idx = i; - cl_git_pass( - git_path_walk_up(&p, root[j], check_one_walkup_step, &info) - ); - - cl_assert_strequal(p.ptr, expect[i]); - - /* skip to next run of expectations */ - while (expect[i] != NULL) i++; - } - - git_buf_free(&p); -} diff --git a/tests-clay/core/rmdir.c b/tests-clay/core/rmdir.c deleted file mode 100644 index 369c0232a..000000000 --- a/tests-clay/core/rmdir.c +++ /dev/null @@ -1,54 +0,0 @@ -#include "clay_libgit2.h" -#include "fileops.h" - -static const char *empty_tmp_dir = "test_gitfo_rmdir_recurs_test"; - -void test_core_rmdir__initialize(void) -{ - git_buf path = GIT_BUF_INIT; - - cl_must_pass(p_mkdir(empty_tmp_dir, 0777)); - - cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one")); - cl_must_pass(p_mkdir(path.ptr, 0777)); - - cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one/two_one")); - cl_must_pass(p_mkdir(path.ptr, 0777)); - - cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one/two_two")); - cl_must_pass(p_mkdir(path.ptr, 0777)); - - cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one/two_two/three")); - cl_must_pass(p_mkdir(path.ptr, 0777)); - - cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/two")); - cl_must_pass(p_mkdir(path.ptr, 0777)); - - git_buf_free(&path); -} - -/* make sure empty dir can be deleted recusively */ -void test_core_rmdir__delete_recursive(void) -{ - cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, 0)); -} - -/* make sure non-empty dir cannot be deleted recusively */ -void test_core_rmdir__fail_to_delete_non_empty_dir(void) -{ - git_buf file = GIT_BUF_INIT; - int fd; - - cl_git_pass(git_buf_joinpath(&file, empty_tmp_dir, "/two/file.txt")); - - fd = p_creat(file.ptr, 0666); - cl_assert(fd >= 0); - - cl_must_pass(p_close(fd)); - cl_git_fail(git_futils_rmdir_r(empty_tmp_dir, 0)); - - cl_must_pass(p_unlink(file.ptr)); - cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, 0)); - - git_buf_free(&file); -} diff --git a/tests-clay/core/string.c b/tests-clay/core/string.c deleted file mode 100644 index c154aaf18..000000000 --- a/tests-clay/core/string.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "clay_libgit2.h" - -/* compare prefixes */ -void test_core_string__0(void) -{ - cl_assert(git__prefixcmp("", "") == 0); - cl_assert(git__prefixcmp("a", "") == 0); - cl_assert(git__prefixcmp("", "a") < 0); - cl_assert(git__prefixcmp("a", "b") < 0); - cl_assert(git__prefixcmp("b", "a") > 0); - cl_assert(git__prefixcmp("ab", "a") == 0); - cl_assert(git__prefixcmp("ab", "ac") < 0); - cl_assert(git__prefixcmp("ab", "aa") > 0); -} - -/* compare suffixes */ -void test_core_string__1(void) -{ - cl_assert(git__suffixcmp("", "") == 0); - cl_assert(git__suffixcmp("a", "") == 0); - cl_assert(git__suffixcmp("", "a") < 0); - cl_assert(git__suffixcmp("a", "b") < 0); - cl_assert(git__suffixcmp("b", "a") > 0); - cl_assert(git__suffixcmp("ba", "a") == 0); - cl_assert(git__suffixcmp("zaa", "ac") < 0); - cl_assert(git__suffixcmp("zaz", "ac") > 0); -} - diff --git a/tests-clay/core/strtol.c b/tests-clay/core/strtol.c deleted file mode 100644 index 41bf7f835..000000000 --- a/tests-clay/core/strtol.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "clay_libgit2.h" - -void test_core_strtol__int32(void) -{ - int32_t i; - - cl_git_pass(git__strtol32(&i, "123", NULL, 10)); - cl_assert(i == 123); - cl_git_pass(git__strtol32(&i, " +123 ", NULL, 10)); - cl_assert(i == 123); - cl_git_pass(git__strtol32(&i, " +2147483647 ", NULL, 10)); - cl_assert(i == 2147483647); - cl_git_pass(git__strtol32(&i, " -2147483648 ", NULL, 10)); - cl_assert(i == -2147483648LL); - - cl_git_fail(git__strtol32(&i, " 2147483657 ", NULL, 10)); - cl_git_fail(git__strtol32(&i, " -2147483657 ", NULL, 10)); -} - -void test_core_strtol__int64(void) -{ - int64_t i; - - cl_git_pass(git__strtol64(&i, "123", NULL, 10)); - cl_assert(i == 123); - cl_git_pass(git__strtol64(&i, " +123 ", NULL, 10)); - cl_assert(i == 123); - cl_git_pass(git__strtol64(&i, " +2147483647 ", NULL, 10)); - cl_assert(i == 2147483647); - cl_git_pass(git__strtol64(&i, " -2147483648 ", NULL, 10)); - cl_assert(i == -2147483648LL); - cl_git_pass(git__strtol64(&i, " 2147483657 ", NULL, 10)); - cl_assert(i == 2147483657LL); - cl_git_pass(git__strtol64(&i, " -2147483657 ", NULL, 10)); - cl_assert(i == -2147483657LL); -} - diff --git a/tests-clay/core/vector.c b/tests-clay/core/vector.c deleted file mode 100644 index fdcfb3a77..000000000 --- a/tests-clay/core/vector.c +++ /dev/null @@ -1,191 +0,0 @@ -#include "clay_libgit2.h" -#include "vector.h" - -/* initial size of 1 would cause writing past array bounds */ -void test_core_vector__0(void) -{ - git_vector x; - int i; - git_vector_init(&x, 1, NULL); - for (i = 0; i < 10; ++i) { - git_vector_insert(&x, (void*) 0xabc); - } - git_vector_free(&x); -} - - -/* don't read past array bounds on remove() */ -void test_core_vector__1(void) -{ - git_vector x; - // make initial capacity exact for our insertions. - git_vector_init(&x, 3, NULL); - git_vector_insert(&x, (void*) 0xabc); - git_vector_insert(&x, (void*) 0xdef); - git_vector_insert(&x, (void*) 0x123); - - git_vector_remove(&x, 0); // used to read past array bounds. - git_vector_free(&x); -} - - -static int test_cmp(const void *a, const void *b) -{ - return *(const int *)a - *(const int *)b; -} - -/* remove duplicates */ -void test_core_vector__2(void) -{ - git_vector x; - int *ptrs[2]; - - ptrs[0] = git__malloc(sizeof(int)); - ptrs[1] = git__malloc(sizeof(int)); - - *ptrs[0] = 2; - *ptrs[1] = 1; - - cl_git_pass(git_vector_init(&x, 5, test_cmp)); - cl_git_pass(git_vector_insert(&x, ptrs[0])); - cl_git_pass(git_vector_insert(&x, ptrs[1])); - cl_git_pass(git_vector_insert(&x, ptrs[1])); - cl_git_pass(git_vector_insert(&x, ptrs[0])); - cl_git_pass(git_vector_insert(&x, ptrs[1])); - cl_assert(x.length == 5); - - git_vector_uniq(&x); - cl_assert(x.length == 2); - - git_vector_free(&x); - - git__free(ptrs[0]); - git__free(ptrs[1]); -} - - -static int compare_them(const void *a, const void *b) -{ - return (int)((long)a - (long)b); -} - -/* insert_sorted */ -void test_core_vector__3(void) -{ - git_vector x; - long i; - git_vector_init(&x, 1, &compare_them); - - for (i = 0; i < 10; i += 2) { - git_vector_insert_sorted(&x, (void*)(i + 1), NULL); - } - - for (i = 9; i > 0; i -= 2) { - git_vector_insert_sorted(&x, (void*)(i + 1), NULL); - } - - cl_assert(x.length == 10); - for (i = 0; i < 10; ++i) { - cl_assert(git_vector_get(&x, i) == (void*)(i + 1)); - } - - git_vector_free(&x); -} - -/* insert_sorted with duplicates */ -void test_core_vector__4(void) -{ - git_vector x; - long i; - git_vector_init(&x, 1, &compare_them); - - for (i = 0; i < 10; i += 2) { - git_vector_insert_sorted(&x, (void*)(i + 1), NULL); - } - - for (i = 9; i > 0; i -= 2) { - git_vector_insert_sorted(&x, (void*)(i + 1), NULL); - } - - for (i = 0; i < 10; i += 2) { - git_vector_insert_sorted(&x, (void*)(i + 1), NULL); - } - - for (i = 9; i > 0; i -= 2) { - git_vector_insert_sorted(&x, (void*)(i + 1), NULL); - } - - cl_assert(x.length == 20); - for (i = 0; i < 20; ++i) { - cl_assert(git_vector_get(&x, i) == (void*)(i / 2 + 1)); - } - - git_vector_free(&x); -} - -typedef struct { - int content; - int count; -} my_struct; - -static int _struct_count = 0; - -static int compare_structs(const void *a, const void *b) -{ - return ((const my_struct *)a)->content - - ((const my_struct *)b)->content; -} - -static int merge_structs(void **old_raw, void *new) -{ - my_struct *old = *(my_struct **)old_raw; - cl_assert(((my_struct *)old)->content == ((my_struct *)new)->content); - ((my_struct *)old)->count += 1; - git__free(new); - _struct_count--; - return GIT_EEXISTS; -} - -static my_struct *alloc_struct(int value) -{ - my_struct *st = git__malloc(sizeof(my_struct)); - st->content = value; - st->count = 0; - _struct_count++; - return st; -} - -/* insert_sorted with duplicates and special handling */ -void test_core_vector__5(void) -{ - git_vector x; - int i; - - git_vector_init(&x, 1, &compare_structs); - - for (i = 0; i < 10; i += 2) - git_vector_insert_sorted(&x, alloc_struct(i), &merge_structs); - - for (i = 9; i > 0; i -= 2) - git_vector_insert_sorted(&x, alloc_struct(i), &merge_structs); - - cl_assert(x.length == 10); - cl_assert(_struct_count == 10); - - for (i = 0; i < 10; i += 2) - git_vector_insert_sorted(&x, alloc_struct(i), &merge_structs); - - for (i = 9; i > 0; i -= 2) - git_vector_insert_sorted(&x, alloc_struct(i), &merge_structs); - - cl_assert(x.length == 10); - cl_assert(_struct_count == 10); - - for (i = 0; i < 10; ++i) { - cl_assert(((my_struct *)git_vector_get(&x, i))->content == i); - git__free(git_vector_get(&x, i)); - _struct_count--; - } - - git_vector_free(&x); -} diff --git a/tests-clay/index/read_tree.c b/tests-clay/index/read_tree.c deleted file mode 100644 index 09a1d94c4..000000000 --- a/tests-clay/index/read_tree.c +++ /dev/null @@ -1,46 +0,0 @@ -#include "clay_libgit2.h" -#include "posix.h" - -/* Test that reading and writing a tree is a no-op */ -void test_index_read_tree__read_write_involution(void) -{ - git_repository *repo; - git_index *index; - git_oid tree_oid; - git_tree *tree; - git_oid expected; - - p_mkdir("read_tree", 0700); - - cl_git_pass(git_repository_init(&repo, "./read_tree", 0)); - cl_git_pass(git_repository_index(&index, repo)); - - cl_assert(git_index_entrycount(index) == 0); - - p_mkdir("./read_tree/abc", 0700); - - /* Sort order: '-' < '/' < '_' */ - cl_git_mkfile("./read_tree/abc-d", NULL); - cl_git_mkfile("./read_tree/abc/d", NULL); - cl_git_mkfile("./read_tree/abc_d", NULL); - - cl_git_pass(git_index_add(index, "abc-d", 0)); - cl_git_pass(git_index_add(index, "abc_d", 0)); - cl_git_pass(git_index_add(index, "abc/d", 0)); - - /* write-tree */ - cl_git_pass(git_tree_create_fromindex(&expected, index)); - - /* read-tree */ - git_tree_lookup(&tree, repo, &expected); - cl_git_pass(git_index_read_tree(index, tree)); - git_tree_free(tree); - - cl_git_pass(git_tree_create_fromindex(&tree_oid, index)); - cl_assert(git_oid_cmp(&expected, &tree_oid) == 0); - - git_index_free(index); - git_repository_free(repo); - - cl_fixture_cleanup("read_tree"); -} diff --git a/tests-clay/index/rename.c b/tests-clay/index/rename.c deleted file mode 100644 index 104982a15..000000000 --- a/tests-clay/index/rename.c +++ /dev/null @@ -1,50 +0,0 @@ -#include "clay_libgit2.h" -#include "posix.h" - -void test_index_rename__single_file(void) -{ - git_repository *repo; - git_index *index; - int position; - git_oid expected; - git_index_entry *entry; - - p_mkdir("rename", 0700); - - cl_git_pass(git_repository_init(&repo, "./rename", 0)); - cl_git_pass(git_repository_index(&index, repo)); - - cl_assert(git_index_entrycount(index) == 0); - - cl_git_mkfile("./rename/lame.name.txt", "new_file\n"); - - /* This should add a new blob to the object database in 'd4/fa8600b4f37d7516bef4816ae2c64dbf029e3a' */ - cl_git_pass(git_index_add(index, "lame.name.txt", 0)); - cl_assert(git_index_entrycount(index) == 1); - - cl_git_pass(git_oid_fromstr(&expected, "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a")); - - position = git_index_find(index, "lame.name.txt"); - - entry = git_index_get(index, position); - cl_assert(git_oid_cmp(&expected, &entry->oid) == 0); - - /* This removes the entry from the index, but not from the object database */ - cl_git_pass(git_index_remove(index, position)); - cl_assert(git_index_entrycount(index) == 0); - - p_rename("./rename/lame.name.txt", "./rename/fancy.name.txt"); - - cl_git_pass(git_index_add(index, "fancy.name.txt", 0)); - cl_assert(git_index_entrycount(index) == 1); - - position = git_index_find(index, "fancy.name.txt"); - - entry = git_index_get(index, position); - cl_assert(git_oid_cmp(&expected, &entry->oid) == 0); - - git_index_free(index); - git_repository_free(repo); - - cl_fixture_cleanup("rename"); -} diff --git a/tests-clay/network/createremotethenload.c b/tests-clay/network/createremotethenload.c deleted file mode 100644 index 16d430e7e..000000000 --- a/tests-clay/network/createremotethenload.c +++ /dev/null @@ -1,33 +0,0 @@ -#include "clay_libgit2.h" - -static git_remote *_remote; -static git_repository *_repo; -static git_config *_config; -static char url[] = "http://github.com/libgit2/libgit2.git"; - -void test_network_createremotethenload__initialize(void) -{ - cl_fixture_sandbox("testrepo.git"); - - cl_git_pass(git_repository_open(&_repo, "testrepo.git")); - - cl_git_pass(git_repository_config(&_config, _repo)); - cl_git_pass(git_config_set_string(_config, "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*")); - cl_git_pass(git_config_set_string(_config, "remote.origin.url", url)); - git_config_free(_config); - - cl_git_pass(git_remote_load(&_remote, _repo, "origin")); -} - -void test_network_createremotethenload__cleanup(void) -{ - git_remote_free(_remote); - git_repository_free(_repo); - cl_fixture_cleanup("testrepo.git"); -} - -void test_network_createremotethenload__parsing(void) -{ - cl_assert(!strcmp(git_remote_name(_remote), "origin")); - cl_assert(!strcmp(git_remote_url(_remote), url)); -} diff --git a/tests-clay/network/remotelocal.c b/tests-clay/network/remotelocal.c deleted file mode 100644 index 961c623a1..000000000 --- a/tests-clay/network/remotelocal.c +++ /dev/null @@ -1,108 +0,0 @@ -#include "clay_libgit2.h" -#include "transport.h" -#include "buffer.h" -#include "path.h" -#include "posix.h" - -static git_repository *repo; -static git_buf file_path_buf = GIT_BUF_INIT; -static git_remote *remote; - -static void build_local_file_url(git_buf *out, const char *fixture) -{ - const char *in_buf; - - git_buf path_buf = GIT_BUF_INIT; - - cl_git_pass(git_path_prettify_dir(&path_buf, fixture, NULL)); - cl_git_pass(git_buf_puts(out, "file://")); - -#ifdef _MSC_VER - /* - * A FILE uri matches the following format: file://[host]/path - * where "host" can be empty and "path" is an absolute path to the resource. - * - * In this test, no hostname is used, but we have to ensure the leading triple slashes: - * - * *nix: file:///usr/home/... - * Windows: file:///C:/Users/... - */ - cl_git_pass(git_buf_putc(out, '/')); -#endif - - in_buf = git_buf_cstr(&path_buf); - - /* - * A very hacky Url encoding that only takes care of escaping the spaces - */ - while (*in_buf) { - if (*in_buf == ' ') - cl_git_pass(git_buf_puts(out, "%20")); - else - cl_git_pass(git_buf_putc(out, *in_buf)); - - in_buf++; - } - - git_buf_free(&path_buf); -} - -void test_network_remotelocal__initialize(void) -{ - cl_git_pass(git_repository_init(&repo, "remotelocal/", 0)); - cl_assert(repo != NULL); -} - -void test_network_remotelocal__cleanup(void) -{ - git_remote_free(remote); - git_buf_free(&file_path_buf); - git_repository_free(repo); - cl_fixture_cleanup("remotelocal"); -} - -static int count_ref__cb(git_remote_head *head, void *payload) -{ - int *count = (int *)payload; - - (void)head; - (*count)++; - - return GIT_SUCCESS; -} - -static void connect_to_local_repository(const char *local_repository) -{ - build_local_file_url(&file_path_buf, local_repository); - - cl_git_pass(git_remote_new(&remote, repo, git_buf_cstr(&file_path_buf), NULL)); - cl_git_pass(git_remote_connect(remote, GIT_DIR_FETCH)); - -} - -void test_network_remotelocal__retrieve_advertised_references(void) -{ - int how_many_refs = 0; - - connect_to_local_repository(cl_fixture("testrepo.git")); - - cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs)); - - cl_assert(how_many_refs == 12); /* 1 HEAD + 9 refs + 2 peeled tags */ -} - -void test_network_remotelocal__retrieve_advertised_references_from_spaced_repository(void) -{ - int how_many_refs = 0; - - cl_fixture_sandbox("testrepo.git"); - cl_git_pass(p_rename("testrepo.git", "spaced testrepo.git")); - - connect_to_local_repository("spaced testrepo.git"); - - cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs)); - - cl_assert(how_many_refs == 12); /* 1 HEAD */ - - cl_fixture_cleanup("spaced testrepo.git"); -} diff --git a/tests-clay/network/remotes.c b/tests-clay/network/remotes.c deleted file mode 100644 index 2c3a32e7f..000000000 --- a/tests-clay/network/remotes.c +++ /dev/null @@ -1,50 +0,0 @@ -#include "clay_libgit2.h" - -static git_remote *_remote; -static git_repository *_repo; -static const git_refspec *_refspec; - -void test_network_remotes__initialize(void) -{ - cl_fixture_sandbox("testrepo.git"); - - cl_git_pass(git_repository_open(&_repo, "testrepo.git")); - cl_git_pass(git_remote_load(&_remote, _repo, "test")); - - _refspec = git_remote_fetchspec(_remote); - cl_assert(_refspec != NULL); -} - -void test_network_remotes__cleanup(void) -{ - git_remote_free(_remote); - git_repository_free(_repo); - cl_fixture_cleanup("testrepo.git"); -} - -void test_network_remotes__parsing(void) -{ - cl_assert(!strcmp(git_remote_name(_remote), "test")); - cl_assert(!strcmp(git_remote_url(_remote), "git://github.com/libgit2/libgit2")); -} - -void test_network_remotes__refspec_parsing(void) -{ - cl_assert(!strcmp(git_refspec_src(_refspec), "refs/heads/*")); - cl_assert(!strcmp(git_refspec_dst(_refspec), "refs/remotes/test/*")); -} - -void test_network_remotes__fnmatch(void) -{ - cl_git_pass(git_refspec_src_match(_refspec, "refs/heads/master")); - cl_git_pass(git_refspec_src_match(_refspec, "refs/heads/multi/level/branch")); -} - -void test_network_remotes__transform(void) -{ - char ref[1024]; - - memset(ref, 0x0, sizeof(ref)); - cl_git_pass(git_refspec_transform(ref, sizeof(ref), _refspec, "refs/heads/master")); - cl_assert(!strcmp(ref, "refs/remotes/test/master")); -} diff --git a/tests-clay/object/commit/commitstagedfile.c b/tests-clay/object/commit/commitstagedfile.c deleted file mode 100644 index 764013b38..000000000 --- a/tests-clay/object/commit/commitstagedfile.c +++ /dev/null @@ -1,118 +0,0 @@ -#include "clay_libgit2.h" -#include "posix.h" - -static git_repository *repo; - -void test_object_commit_commitstagedfile__initialize(void) -{ - cl_fixture("treebuilder"); - cl_git_pass(git_repository_init(&repo, "treebuilder/", 0)); - cl_assert(repo != NULL); -} - -void test_object_commit_commitstagedfile__cleanup(void) -{ - git_repository_free(repo); - cl_fixture_cleanup("treebuilder"); -} - -void test_object_commit_commitstagedfile__generate_predictable_object_ids(void) -{ - git_index *index; - git_index_entry *entry; - git_oid expected_blob_oid, tree_oid, expected_tree_oid, commit_oid, expected_commit_oid; - git_signature *signature; - git_tree *tree; - - /* - * The test below replicates the following git scenario - * - * $ echo "test" > test.txt - * $ git hash-object test.txt - * 9daeafb9864cf43055ae93beb0afd6c7d144bfa4 - * - * $ git add . - * $ git commit -m "Initial commit" - * - * $ git log - * commit 1fe3126578fc4eca68c193e4a3a0a14a0704624d - * Author: nulltoken <emeric.fermas@gmail.com> - * Date: Wed Dec 14 08:29:03 2011 +0100 - * - * Initial commit - * - * $ git show 1fe3 --format=raw - * commit 1fe3126578fc4eca68c193e4a3a0a14a0704624d - * tree 2b297e643c551e76cfa1f93810c50811382f9117 - * author nulltoken <emeric.fermas@gmail.com> 1323847743 +0100 - * committer nulltoken <emeric.fermas@gmail.com> 1323847743 +0100 - * - * Initial commit - * - * diff --git a/test.txt b/test.txt - * new file mode 100644 - * index 0000000..9daeafb - * --- /dev/null - * +++ b/test.txt - * @@ -0,0 +1 @@ - * +test - * - * $ git ls-tree 2b297 - * 100644 blob 9daeafb9864cf43055ae93beb0afd6c7d144bfa4 test.txt - */ - - cl_git_pass(git_oid_fromstr(&expected_commit_oid, "1fe3126578fc4eca68c193e4a3a0a14a0704624d")); - cl_git_pass(git_oid_fromstr(&expected_tree_oid, "2b297e643c551e76cfa1f93810c50811382f9117")); - cl_git_pass(git_oid_fromstr(&expected_blob_oid, "9daeafb9864cf43055ae93beb0afd6c7d144bfa4")); - - /* - * Add a new file to the index - */ - cl_git_mkfile("treebuilder/test.txt", "test\n"); - cl_git_pass(git_repository_index(&index, repo)); - cl_git_pass(git_index_add(index, "test.txt", 0)); - - entry = git_index_get(index, 0); - - cl_assert(git_oid_cmp(&expected_blob_oid, &entry->oid) == 0); - - /* - * Information about index entry should match test file - */ - { - struct stat st; - cl_must_pass(p_lstat("treebuilder/test.txt", &st)); - cl_assert(entry->file_size == st.st_size); - cl_assert(entry->uid == st.st_uid); - cl_assert(entry->gid == st.st_gid); - } - - /* - * Build the tree from the index - */ - cl_git_pass(git_tree_create_fromindex(&tree_oid, index)); - - cl_assert(git_oid_cmp(&expected_tree_oid, &tree_oid) == 0); - - /* - * Commit the staged file - */ - cl_git_pass(git_signature_new(&signature, "nulltoken", "emeric.fermas@gmail.com", 1323847743, 60)); - cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid)); - cl_git_pass(git_commit_create_v( - &commit_oid, - repo, - "HEAD", - signature, - signature, - NULL, - "Initial commit\n", // Note: the trailing linefeed is mandatory to replicate git behavior - tree, - 0)); - - cl_assert(git_oid_cmp(&expected_commit_oid, &commit_oid) == 0); - - git_signature_free(signature); - git_tree_free(tree); - git_index_free(index); -} diff --git a/tests-clay/object/raw/chars.c b/tests-clay/object/raw/chars.c deleted file mode 100644 index 83bcbeb79..000000000 --- a/tests-clay/object/raw/chars.c +++ /dev/null @@ -1,41 +0,0 @@ - -#include "clay_libgit2.h" - -#include "odb.h" - -void test_object_raw_chars__find_invalid_chars_in_oid(void) -{ - git_oid out; - unsigned char exp[] = { - 0x16, 0xa6, 0x77, 0x70, 0xb7, - 0xd8, 0xd7, 0x23, 0x17, 0xc4, - 0xb7, 0x75, 0x21, 0x3c, 0x23, - 0xa8, 0xbd, 0x74, 0xf5, 0xe0, - }; - char in[41] = "16a67770b7d8d72317c4b775213c23a8bd74f5e0"; - unsigned int i; - - for (i = 0; i < 256; i++) { - in[38] = (char)i; - if (git__fromhex(i) >= 0) { - exp[19] = (unsigned char)(git__fromhex(i) << 4); - cl_git_pass(git_oid_fromstr(&out, in)); - cl_assert(memcmp(out.id, exp, sizeof(out.id)) == 0); - } else { - cl_git_fail(git_oid_fromstr(&out, in)); - } - } -} - -void test_object_raw_chars__build_valid_oid_from_raw_bytes(void) -{ - git_oid out; - unsigned char exp[] = { - 0x16, 0xa6, 0x77, 0x70, 0xb7, - 0xd8, 0xd7, 0x23, 0x17, 0xc4, - 0xb7, 0x75, 0x21, 0x3c, 0x23, - 0xa8, 0xbd, 0x74, 0xf5, 0xe0, - }; - git_oid_fromraw(&out, exp); - cl_git_pass(memcmp(out.id, exp, sizeof(out.id))); -} diff --git a/tests-clay/object/raw/compare.c b/tests-clay/object/raw/compare.c deleted file mode 100644 index 94b196945..000000000 --- a/tests-clay/object/raw/compare.c +++ /dev/null @@ -1,124 +0,0 @@ - -#include "clay_libgit2.h" - -#include "odb.h" - -void test_object_raw_compare__succeed_on_copy_oid(void) -{ - git_oid a, b; - unsigned char exp[] = { - 0x16, 0xa6, 0x77, 0x70, 0xb7, - 0xd8, 0xd7, 0x23, 0x17, 0xc4, - 0xb7, 0x75, 0x21, 0x3c, 0x23, - 0xa8, 0xbd, 0x74, 0xf5, 0xe0, - }; - memset(&b, 0, sizeof(b)); - git_oid_fromraw(&a, exp); - git_oid_cpy(&b, &a); - cl_git_pass(memcmp(a.id, exp, sizeof(a.id))); -} - -void test_object_raw_compare__succeed_on_oid_comparison_lesser(void) -{ - git_oid a, b; - unsigned char a_in[] = { - 0x16, 0xa6, 0x77, 0x70, 0xb7, - 0xd8, 0xd7, 0x23, 0x17, 0xc4, - 0xb7, 0x75, 0x21, 0x3c, 0x23, - 0xa8, 0xbd, 0x74, 0xf5, 0xe0, - }; - unsigned char b_in[] = { - 0x16, 0xa6, 0x77, 0x70, 0xb7, - 0xd8, 0xd7, 0x23, 0x17, 0xc4, - 0xb7, 0x75, 0x21, 0x3c, 0x23, - 0xa8, 0xbd, 0x74, 0xf5, 0xf0, - }; - git_oid_fromraw(&a, a_in); - git_oid_fromraw(&b, b_in); - cl_assert(git_oid_cmp(&a, &b) < 0); -} - -void test_object_raw_compare__succeed_on_oid_comparison_equal(void) -{ - git_oid a, b; - unsigned char a_in[] = { - 0x16, 0xa6, 0x77, 0x70, 0xb7, - 0xd8, 0xd7, 0x23, 0x17, 0xc4, - 0xb7, 0x75, 0x21, 0x3c, 0x23, - 0xa8, 0xbd, 0x74, 0xf5, 0xe0, - }; - git_oid_fromraw(&a, a_in); - git_oid_fromraw(&b, a_in); - cl_assert(git_oid_cmp(&a, &b) == 0); -} - -void test_object_raw_compare__succeed_on_oid_comparison_greater(void) -{ - git_oid a, b; - unsigned char a_in[] = { - 0x16, 0xa6, 0x77, 0x70, 0xb7, - 0xd8, 0xd7, 0x23, 0x17, 0xc4, - 0xb7, 0x75, 0x21, 0x3c, 0x23, - 0xa8, 0xbd, 0x74, 0xf5, 0xe0, - }; - unsigned char b_in[] = { - 0x16, 0xa6, 0x77, 0x70, 0xb7, - 0xd8, 0xd7, 0x23, 0x17, 0xc4, - 0xb7, 0x75, 0x21, 0x3c, 0x23, - 0xa8, 0xbd, 0x74, 0xf5, 0xd0, - }; - git_oid_fromraw(&a, a_in); - git_oid_fromraw(&b, b_in); - cl_assert(git_oid_cmp(&a, &b) > 0); -} - -void test_object_raw_compare__compare_fmt_oids(void) -{ - const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0"; - git_oid in; - char out[GIT_OID_HEXSZ + 1]; - - cl_git_pass(git_oid_fromstr(&in, exp)); - - /* Format doesn't touch the last byte */ - out[GIT_OID_HEXSZ] = 'Z'; - git_oid_fmt(out, &in); - cl_assert(out[GIT_OID_HEXSZ] == 'Z'); - - /* Format produced the right result */ - out[GIT_OID_HEXSZ] = '\0'; - cl_assert(strcmp(exp, out) == 0); -} - -void test_object_raw_compare__compare_allocfmt_oids(void) -{ - const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0"; - git_oid in; - char *out; - - cl_git_pass(git_oid_fromstr(&in, exp)); - - out = git_oid_allocfmt(&in); - cl_assert(out); - cl_assert(strcmp(exp, out) == 0); - git__free(out); -} - -void test_object_raw_compare__compare_pathfmt_oids(void) -{ - const char *exp1 = "16a0123456789abcdef4b775213c23a8bd74f5e0"; - const char *exp2 = "16/a0123456789abcdef4b775213c23a8bd74f5e0"; - git_oid in; - char out[GIT_OID_HEXSZ + 2]; - - cl_git_pass(git_oid_fromstr(&in, exp1)); - - /* Format doesn't touch the last byte */ - out[GIT_OID_HEXSZ + 1] = 'Z'; - git_oid_pathfmt(out, &in); - cl_assert(out[GIT_OID_HEXSZ + 1] == 'Z'); - - /* Format produced the right result */ - out[GIT_OID_HEXSZ + 1] = '\0'; - cl_assert(strcmp(exp2, out) == 0); -} diff --git a/tests-clay/object/raw/convert.c b/tests-clay/object/raw/convert.c deleted file mode 100644 index f69f5f924..000000000 --- a/tests-clay/object/raw/convert.c +++ /dev/null @@ -1,75 +0,0 @@ - -#include "clay_libgit2.h" - -#include "odb.h" - -void test_object_raw_convert__succeed_on_oid_to_string_conversion(void) -{ - const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0"; - git_oid in; - char out[GIT_OID_HEXSZ + 1]; - char *str; - int i; - - cl_git_pass(git_oid_fromstr(&in, exp)); - - /* NULL buffer pointer, returns static empty string */ - str = git_oid_to_string(NULL, sizeof(out), &in); - cl_assert(str && *str == '\0' && str != out); - - /* zero buffer size, returns static empty string */ - str = git_oid_to_string(out, 0, &in); - cl_assert(str && *str == '\0' && str != out); - - /* NULL oid pointer, returns static empty string */ - str = git_oid_to_string(out, sizeof(out), NULL); - cl_assert(str && *str == '\0' && str != out); - - /* n == 1, returns out as an empty string */ - str = git_oid_to_string(out, 1, &in); - cl_assert(str && *str == '\0' && str == out); - - for (i = 1; i < GIT_OID_HEXSZ; i++) { - out[i+1] = 'Z'; - str = git_oid_to_string(out, i+1, &in); - /* returns out containing c-string */ - cl_assert(str && str == out); - /* must be '\0' terminated */ - cl_assert(*(str+i) == '\0'); - /* must not touch bytes past end of string */ - cl_assert(*(str+(i+1)) == 'Z'); - /* i == n-1 charaters of string */ - cl_git_pass(strncmp(exp, out, i)); - } - - /* returns out as hex formatted c-string */ - str = git_oid_to_string(out, sizeof(out), &in); - cl_assert(str && str == out && *(str+GIT_OID_HEXSZ) == '\0'); - cl_assert(strcmp(exp, out) == 0); -} - -void test_object_raw_convert__succeed_on_oid_to_string_conversion_big(void) -{ - const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0"; - git_oid in; - char big[GIT_OID_HEXSZ + 1 + 3]; /* note + 4 => big buffer */ - char *str; - - cl_git_pass(git_oid_fromstr(&in, exp)); - - /* place some tail material */ - big[GIT_OID_HEXSZ+0] = 'W'; /* should be '\0' afterwards */ - big[GIT_OID_HEXSZ+1] = 'X'; /* should remain untouched */ - big[GIT_OID_HEXSZ+2] = 'Y'; /* ditto */ - big[GIT_OID_HEXSZ+3] = 'Z'; /* ditto */ - - /* returns big as hex formatted c-string */ - str = git_oid_to_string(big, sizeof(big), &in); - cl_assert(str && str == big && *(str+GIT_OID_HEXSZ) == '\0'); - cl_assert(strcmp(exp, big) == 0); - - /* check tail material is untouched */ - cl_assert(str && str == big && *(str+GIT_OID_HEXSZ+1) == 'X'); - cl_assert(str && str == big && *(str+GIT_OID_HEXSZ+2) == 'Y'); - cl_assert(str && str == big && *(str+GIT_OID_HEXSZ+3) == 'Z'); -} diff --git a/tests-clay/object/raw/data.h b/tests-clay/object/raw/data.h deleted file mode 100644 index cf23819f1..000000000 --- a/tests-clay/object/raw/data.h +++ /dev/null @@ -1,323 +0,0 @@ - -/* - * Raw data - */ -static unsigned char commit_data[] = { - 0x74, 0x72, 0x65, 0x65, 0x20, 0x64, 0x66, 0x66, - 0x32, 0x64, 0x61, 0x39, 0x30, 0x62, 0x32, 0x35, - 0x34, 0x65, 0x31, 0x62, 0x65, 0x62, 0x38, 0x38, - 0x39, 0x64, 0x31, 0x66, 0x31, 0x66, 0x31, 0x32, - 0x38, 0x38, 0x62, 0x65, 0x31, 0x38, 0x30, 0x33, - 0x37, 0x38, 0x32, 0x64, 0x66, 0x0a, 0x61, 0x75, - 0x74, 0x68, 0x6f, 0x72, 0x20, 0x41, 0x20, 0x55, - 0x20, 0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61, - 0x75, 0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78, - 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, - 0x6d, 0x3e, 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, - 0x31, 0x34, 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, - 0x30, 0x30, 0x30, 0x0a, 0x63, 0x6f, 0x6d, 0x6d, - 0x69, 0x74, 0x74, 0x65, 0x72, 0x20, 0x43, 0x20, - 0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72, - 0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, - 0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d, - 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e, - 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34, - 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30, - 0x30, 0x0a, 0x0a, 0x41, 0x20, 0x6f, 0x6e, 0x65, - 0x2d, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x63, 0x6f, - 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x73, 0x75, 0x6d, - 0x6d, 0x61, 0x72, 0x79, 0x0a, 0x0a, 0x54, 0x68, - 0x65, 0x20, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x6f, - 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, - 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x6d, 0x65, 0x73, - 0x73, 0x61, 0x67, 0x65, 0x2c, 0x20, 0x63, 0x6f, - 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x69, 0x6e, 0x67, - 0x20, 0x66, 0x75, 0x72, 0x74, 0x68, 0x65, 0x72, - 0x20, 0x65, 0x78, 0x70, 0x6c, 0x61, 0x6e, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x6f, 0x66, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x70, 0x75, 0x72, 0x70, - 0x6f, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x63, 0x68, 0x61, 0x6e, 0x67, - 0x65, 0x73, 0x20, 0x69, 0x6e, 0x74, 0x72, 0x6f, - 0x64, 0x75, 0x63, 0x65, 0x64, 0x20, 0x62, 0x79, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x6d, - 0x6d, 0x69, 0x74, 0x2e, 0x0a, 0x0a, 0x53, 0x69, - 0x67, 0x6e, 0x65, 0x64, 0x2d, 0x6f, 0x66, 0x2d, - 0x62, 0x79, 0x3a, 0x20, 0x41, 0x20, 0x55, 0x20, - 0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61, 0x75, - 0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78, 0x61, - 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, - 0x3e, 0x0a, -}; - - -static unsigned char tree_data[] = { - 0x31, 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x6f, - 0x6e, 0x65, 0x00, 0x8b, 0x13, 0x78, 0x91, 0x79, - 0x1f, 0xe9, 0x69, 0x27, 0xad, 0x78, 0xe6, 0x4b, - 0x0a, 0xad, 0x7b, 0xde, 0xd0, 0x8b, 0xdc, 0x31, - 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x73, 0x6f, - 0x6d, 0x65, 0x00, 0xfd, 0x84, 0x30, 0xbc, 0x86, - 0x4c, 0xfc, 0xd5, 0xf1, 0x0e, 0x55, 0x90, 0xf8, - 0xa4, 0x47, 0xe0, 0x1b, 0x94, 0x2b, 0xfe, 0x31, - 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x74, 0x77, - 0x6f, 0x00, 0x78, 0x98, 0x19, 0x22, 0x61, 0x3b, - 0x2a, 0xfb, 0x60, 0x25, 0x04, 0x2f, 0xf6, 0xbd, - 0x87, 0x8a, 0xc1, 0x99, 0x4e, 0x85, 0x31, 0x30, - 0x30, 0x36, 0x34, 0x34, 0x20, 0x7a, 0x65, 0x72, - 0x6f, 0x00, 0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1, - 0xd6, 0x43, 0x4b, 0x8b, 0x29, 0xae, 0x77, 0x5a, - 0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91, -}; - -static unsigned char tag_data[] = { - 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x33, - 0x64, 0x37, 0x66, 0x38, 0x61, 0x36, 0x61, 0x66, - 0x30, 0x37, 0x36, 0x63, 0x38, 0x63, 0x33, 0x66, - 0x32, 0x30, 0x30, 0x37, 0x31, 0x61, 0x38, 0x39, - 0x33, 0x35, 0x63, 0x64, 0x62, 0x65, 0x38, 0x32, - 0x32, 0x38, 0x35, 0x39, 0x34, 0x64, 0x31, 0x0a, - 0x74, 0x79, 0x70, 0x65, 0x20, 0x63, 0x6f, 0x6d, - 0x6d, 0x69, 0x74, 0x0a, 0x74, 0x61, 0x67, 0x20, - 0x76, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x0a, 0x74, - 0x61, 0x67, 0x67, 0x65, 0x72, 0x20, 0x43, 0x20, - 0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72, - 0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, - 0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d, - 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e, - 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34, - 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30, - 0x30, 0x0a, 0x0a, 0x54, 0x68, 0x69, 0x73, 0x20, - 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, - 0x61, 0x67, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, - 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x72, 0x65, - 0x6c, 0x65, 0x61, 0x73, 0x65, 0x20, 0x76, 0x30, - 0x2e, 0x30, 0x2e, 0x31, 0x0a, -}; - -/* - * Dummy data - */ -static unsigned char zero_data[] = { - 0x00, -}; - -static unsigned char one_data[] = { - 0x0a, -}; - -static unsigned char two_data[] = { - 0x61, 0x0a, -}; - -static unsigned char some_data[] = { - 0x2f, 0x2a, 0x0a, 0x20, 0x2a, 0x20, 0x54, 0x68, - 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, - 0x69, 0x73, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20, - 0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, - 0x3b, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x63, 0x61, - 0x6e, 0x20, 0x72, 0x65, 0x64, 0x69, 0x73, 0x74, - 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x69, - 0x74, 0x20, 0x61, 0x6e, 0x64, 0x2f, 0x6f, 0x72, - 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x0a, - 0x20, 0x2a, 0x20, 0x69, 0x74, 0x20, 0x75, 0x6e, - 0x64, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x74, 0x65, 0x72, 0x6d, 0x73, 0x20, 0x6f, 0x66, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x47, 0x4e, 0x55, - 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, - 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, - 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2c, - 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, - 0x20, 0x32, 0x2c, 0x0a, 0x20, 0x2a, 0x20, 0x61, - 0x73, 0x20, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, - 0x68, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x46, 0x72, 0x65, 0x65, 0x20, - 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, - 0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x2e, 0x0a, 0x20, 0x2a, 0x0a, - 0x20, 0x2a, 0x20, 0x49, 0x6e, 0x20, 0x61, 0x64, - 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74, - 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x65, - 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e, - 0x73, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, - 0x20, 0x47, 0x4e, 0x55, 0x20, 0x47, 0x65, 0x6e, - 0x65, 0x72, 0x61, 0x6c, 0x20, 0x50, 0x75, 0x62, - 0x6c, 0x69, 0x63, 0x20, 0x4c, 0x69, 0x63, 0x65, - 0x6e, 0x73, 0x65, 0x2c, 0x0a, 0x20, 0x2a, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x61, 0x75, 0x74, 0x68, - 0x6f, 0x72, 0x73, 0x20, 0x67, 0x69, 0x76, 0x65, - 0x20, 0x79, 0x6f, 0x75, 0x20, 0x75, 0x6e, 0x6c, - 0x69, 0x6d, 0x69, 0x74, 0x65, 0x64, 0x20, 0x70, - 0x65, 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, - 0x6e, 0x20, 0x74, 0x6f, 0x20, 0x6c, 0x69, 0x6e, - 0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x0a, 0x20, - 0x2a, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, - 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x69, - 0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x69, - 0x6e, 0x74, 0x6f, 0x20, 0x63, 0x6f, 0x6d, 0x62, - 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, - 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x6f, 0x74, - 0x68, 0x65, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x67, - 0x72, 0x61, 0x6d, 0x73, 0x2c, 0x0a, 0x20, 0x2a, - 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x6f, 0x20, - 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, - 0x74, 0x65, 0x20, 0x74, 0x68, 0x6f, 0x73, 0x65, - 0x20, 0x63, 0x6f, 0x6d, 0x62, 0x69, 0x6e, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x77, 0x69, - 0x74, 0x68, 0x6f, 0x75, 0x74, 0x20, 0x61, 0x6e, - 0x79, 0x20, 0x72, 0x65, 0x73, 0x74, 0x72, 0x69, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x20, 0x2a, - 0x20, 0x63, 0x6f, 0x6d, 0x69, 0x6e, 0x67, 0x20, - 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65, - 0x20, 0x75, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, - 0x74, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, - 0x65, 0x2e, 0x20, 0x20, 0x28, 0x54, 0x68, 0x65, - 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, - 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, - 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x0a, - 0x20, 0x2a, 0x20, 0x72, 0x65, 0x73, 0x74, 0x72, - 0x69, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, - 0x64, 0x6f, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, - 0x20, 0x69, 0x6e, 0x20, 0x6f, 0x74, 0x68, 0x65, - 0x72, 0x20, 0x72, 0x65, 0x73, 0x70, 0x65, 0x63, - 0x74, 0x73, 0x3b, 0x20, 0x66, 0x6f, 0x72, 0x20, - 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2c, - 0x20, 0x74, 0x68, 0x65, 0x79, 0x20, 0x63, 0x6f, - 0x76, 0x65, 0x72, 0x0a, 0x20, 0x2a, 0x20, 0x6d, - 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x2c, - 0x20, 0x61, 0x6e, 0x64, 0x20, 0x64, 0x69, 0x73, - 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, - 0x6e, 0x20, 0x77, 0x68, 0x65, 0x6e, 0x20, 0x6e, - 0x6f, 0x74, 0x20, 0x6c, 0x69, 0x6e, 0x6b, 0x65, - 0x64, 0x20, 0x69, 0x6e, 0x74, 0x6f, 0x0a, 0x20, - 0x2a, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x6d, 0x62, - 0x69, 0x6e, 0x65, 0x64, 0x20, 0x65, 0x78, 0x65, - 0x63, 0x75, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, - 0x29, 0x0a, 0x20, 0x2a, 0x0a, 0x20, 0x2a, 0x20, - 0x54, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, - 0x65, 0x20, 0x69, 0x73, 0x20, 0x64, 0x69, 0x73, - 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, - 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x68, 0x6f, 0x70, 0x65, 0x20, 0x74, 0x68, 0x61, - 0x74, 0x20, 0x69, 0x74, 0x20, 0x77, 0x69, 0x6c, - 0x6c, 0x20, 0x62, 0x65, 0x20, 0x75, 0x73, 0x65, - 0x66, 0x75, 0x6c, 0x2c, 0x20, 0x62, 0x75, 0x74, - 0x0a, 0x20, 0x2a, 0x20, 0x57, 0x49, 0x54, 0x48, - 0x4f, 0x55, 0x54, 0x20, 0x41, 0x4e, 0x59, 0x20, - 0x57, 0x41, 0x52, 0x52, 0x41, 0x4e, 0x54, 0x59, - 0x3b, 0x20, 0x77, 0x69, 0x74, 0x68, 0x6f, 0x75, - 0x74, 0x20, 0x65, 0x76, 0x65, 0x6e, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x69, - 0x65, 0x64, 0x20, 0x77, 0x61, 0x72, 0x72, 0x61, - 0x6e, 0x74, 0x79, 0x20, 0x6f, 0x66, 0x0a, 0x20, - 0x2a, 0x20, 0x4d, 0x45, 0x52, 0x43, 0x48, 0x41, - 0x4e, 0x54, 0x41, 0x42, 0x49, 0x4c, 0x49, 0x54, - 0x59, 0x20, 0x6f, 0x72, 0x20, 0x46, 0x49, 0x54, - 0x4e, 0x45, 0x53, 0x53, 0x20, 0x46, 0x4f, 0x52, - 0x20, 0x41, 0x20, 0x50, 0x41, 0x52, 0x54, 0x49, - 0x43, 0x55, 0x4c, 0x41, 0x52, 0x20, 0x50, 0x55, - 0x52, 0x50, 0x4f, 0x53, 0x45, 0x2e, 0x20, 0x20, - 0x53, 0x65, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x47, 0x4e, 0x55, 0x0a, 0x20, 0x2a, 0x20, 0x47, - 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x50, - 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, 0x4c, 0x69, - 0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x66, 0x6f, - 0x72, 0x20, 0x6d, 0x6f, 0x72, 0x65, 0x20, 0x64, - 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x2e, 0x0a, - 0x20, 0x2a, 0x0a, 0x20, 0x2a, 0x20, 0x59, 0x6f, - 0x75, 0x20, 0x73, 0x68, 0x6f, 0x75, 0x6c, 0x64, - 0x20, 0x68, 0x61, 0x76, 0x65, 0x20, 0x72, 0x65, - 0x63, 0x65, 0x69, 0x76, 0x65, 0x64, 0x20, 0x61, - 0x20, 0x63, 0x6f, 0x70, 0x79, 0x20, 0x6f, 0x66, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x47, 0x4e, 0x55, - 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, - 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, - 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x0a, - 0x20, 0x2a, 0x20, 0x61, 0x6c, 0x6f, 0x6e, 0x67, - 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68, - 0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72, - 0x61, 0x6d, 0x3b, 0x20, 0x73, 0x65, 0x65, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65, - 0x20, 0x43, 0x4f, 0x50, 0x59, 0x49, 0x4e, 0x47, - 0x2e, 0x20, 0x20, 0x49, 0x66, 0x20, 0x6e, 0x6f, - 0x74, 0x2c, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, - 0x20, 0x74, 0x6f, 0x0a, 0x20, 0x2a, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x46, 0x72, 0x65, 0x65, 0x20, - 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, - 0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x35, 0x31, 0x20, - 0x46, 0x72, 0x61, 0x6e, 0x6b, 0x6c, 0x69, 0x6e, - 0x20, 0x53, 0x74, 0x72, 0x65, 0x65, 0x74, 0x2c, - 0x20, 0x46, 0x69, 0x66, 0x74, 0x68, 0x20, 0x46, - 0x6c, 0x6f, 0x6f, 0x72, 0x2c, 0x0a, 0x20, 0x2a, - 0x20, 0x42, 0x6f, 0x73, 0x74, 0x6f, 0x6e, 0x2c, - 0x20, 0x4d, 0x41, 0x20, 0x30, 0x32, 0x31, 0x31, - 0x30, 0x2d, 0x31, 0x33, 0x30, 0x31, 0x2c, 0x20, - 0x55, 0x53, 0x41, 0x2e, 0x0a, 0x20, 0x2a, 0x2f, - 0x0a, -}; - -/* - * SHA1 Hashes - */ -static char *commit_id = "3d7f8a6af076c8c3f20071a8935cdbe8228594d1"; -static char *tree_id = "dff2da90b254e1beb889d1f1f1288be1803782df"; -static char *tag_id = "09d373e1dfdc16b129ceec6dd649739911541e05"; -static char *zero_id = "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"; -static char *one_id = "8b137891791fe96927ad78e64b0aad7bded08bdc"; -static char *two_id = "78981922613b2afb6025042ff6bd878ac1994e85"; -static char *some_id = "fd8430bc864cfcd5f10e5590f8a447e01b942bfe"; - -/* - * In-memory objects - */ -static git_rawobj tree_obj = { - tree_data, - sizeof(tree_data), - GIT_OBJ_TREE -}; - -static git_rawobj tag_obj = { - tag_data, - sizeof(tag_data), - GIT_OBJ_TAG -}; - -static git_rawobj zero_obj = { - zero_data, - 0, - GIT_OBJ_BLOB -}; - -static git_rawobj one_obj = { - one_data, - sizeof(one_data), - GIT_OBJ_BLOB -}; - -static git_rawobj two_obj = { - two_data, - sizeof(two_data), - GIT_OBJ_BLOB -}; - -static git_rawobj commit_obj = { - commit_data, - sizeof(commit_data), - GIT_OBJ_COMMIT -}; - -static git_rawobj some_obj = { - some_data, - sizeof(some_data), - GIT_OBJ_BLOB -}; - -static git_rawobj junk_obj = { - NULL, - 0, - GIT_OBJ_BAD -}; diff --git a/tests-clay/object/raw/fromstr.c b/tests-clay/object/raw/fromstr.c deleted file mode 100644 index 6d732d4eb..000000000 --- a/tests-clay/object/raw/fromstr.c +++ /dev/null @@ -1,30 +0,0 @@ - -#include "clay_libgit2.h" - -#include "odb.h" - -void test_object_raw_fromstr__fail_on_invalid_oid_string(void) -{ - git_oid out; - cl_git_fail(git_oid_fromstr(&out, "")); - cl_git_fail(git_oid_fromstr(&out, "moo")); - cl_git_fail(git_oid_fromstr(&out, "16a67770b7d8d72317c4b775213c23a8bd74f5ez")); -} - -void test_object_raw_fromstr__succeed_on_valid_oid_string(void) -{ - git_oid out; - unsigned char exp[] = { - 0x16, 0xa6, 0x77, 0x70, 0xb7, - 0xd8, 0xd7, 0x23, 0x17, 0xc4, - 0xb7, 0x75, 0x21, 0x3c, 0x23, - 0xa8, 0xbd, 0x74, 0xf5, 0xe0, - }; - - cl_git_pass(git_oid_fromstr(&out, "16a67770b7d8d72317c4b775213c23a8bd74f5e0")); - cl_git_pass(memcmp(out.id, exp, sizeof(out.id))); - - cl_git_pass(git_oid_fromstr(&out, "16A67770B7D8D72317C4b775213C23A8BD74F5E0")); - cl_git_pass(memcmp(out.id, exp, sizeof(out.id))); - -} diff --git a/tests-clay/object/raw/hash.c b/tests-clay/object/raw/hash.c deleted file mode 100644 index 9974ed6ef..000000000 --- a/tests-clay/object/raw/hash.c +++ /dev/null @@ -1,162 +0,0 @@ - -#include "clay_libgit2.h" - -#include "odb.h" -#include "hash.h" - -#include "data.h" - -static int hash_object(git_oid *oid, git_rawobj *obj) -{ - return git_odb_hash(oid, obj->data, obj->len, obj->type); -} - -static char *hello_id = "22596363b3de40b06f981fb85d82312e8c0ed511"; -static char *hello_text = "hello world\n"; - -static char *bye_id = "ce08fe4884650f067bd5703b6a59a8b3b3c99a09"; -static char *bye_text = "bye world\n"; - -void test_object_raw_hash__hash_by_blocks(void) -{ - git_hash_ctx *ctx; - git_oid id1, id2; - - cl_assert((ctx = git_hash_new_ctx()) != NULL); - - /* should already be init'd */ - git_hash_update(ctx, hello_text, strlen(hello_text)); - git_hash_final(&id2, ctx); - cl_git_pass(git_oid_fromstr(&id1, hello_id)); - cl_assert(git_oid_cmp(&id1, &id2) == 0); - - /* reinit should permit reuse */ - git_hash_init(ctx); - git_hash_update(ctx, bye_text, strlen(bye_text)); - git_hash_final(&id2, ctx); - cl_git_pass(git_oid_fromstr(&id1, bye_id)); - cl_assert(git_oid_cmp(&id1, &id2) == 0); - - git_hash_free_ctx(ctx); -} - -void test_object_raw_hash__hash_buffer_in_single_call(void) -{ - git_oid id1, id2; - - cl_git_pass(git_oid_fromstr(&id1, hello_id)); - git_hash_buf(&id2, hello_text, strlen(hello_text)); - cl_assert(git_oid_cmp(&id1, &id2) == 0); -} - -void test_object_raw_hash__hash_vector(void) -{ - git_oid id1, id2; - git_buf_vec vec[2]; - - cl_git_pass(git_oid_fromstr(&id1, hello_id)); - - vec[0].data = hello_text; - vec[0].len = 4; - vec[1].data = hello_text+4; - vec[1].len = strlen(hello_text)-4; - - git_hash_vec(&id2, vec, 2); - - cl_assert(git_oid_cmp(&id1, &id2) == 0); -} - -void test_object_raw_hash__hash_junk_data(void) -{ - git_oid id, id_zero; - - cl_git_pass(git_oid_fromstr(&id_zero, zero_id)); - - /* invalid types: */ - junk_obj.data = some_data; - cl_git_fail(hash_object(&id, &junk_obj)); - - junk_obj.type = GIT_OBJ__EXT1; - cl_git_fail(hash_object(&id, &junk_obj)); - - junk_obj.type = GIT_OBJ__EXT2; - cl_git_fail(hash_object(&id, &junk_obj)); - - junk_obj.type = GIT_OBJ_OFS_DELTA; - cl_git_fail(hash_object(&id, &junk_obj)); - - junk_obj.type = GIT_OBJ_REF_DELTA; - cl_git_fail(hash_object(&id, &junk_obj)); - - /* data can be NULL only if len is zero: */ - junk_obj.type = GIT_OBJ_BLOB; - junk_obj.data = NULL; - cl_git_pass(hash_object(&id, &junk_obj)); - cl_assert(git_oid_cmp(&id, &id_zero) == 0); - - junk_obj.len = 1; - cl_git_fail(hash_object(&id, &junk_obj)); -} - -void test_object_raw_hash__hash_commit_object(void) -{ - git_oid id1, id2; - - cl_git_pass(git_oid_fromstr(&id1, commit_id)); - cl_git_pass(hash_object(&id2, &commit_obj)); - cl_assert(git_oid_cmp(&id1, &id2) == 0); -} - -void test_object_raw_hash__hash_tree_object(void) -{ - git_oid id1, id2; - - cl_git_pass(git_oid_fromstr(&id1, tree_id)); - cl_git_pass(hash_object(&id2, &tree_obj)); - cl_assert(git_oid_cmp(&id1, &id2) == 0); -} - -void test_object_raw_hash__hash_tag_object(void) -{ - git_oid id1, id2; - - cl_git_pass(git_oid_fromstr(&id1, tag_id)); - cl_git_pass(hash_object(&id2, &tag_obj)); - cl_assert(git_oid_cmp(&id1, &id2) == 0); -} - -void test_object_raw_hash__hash_zero_length_object(void) -{ - git_oid id1, id2; - - cl_git_pass(git_oid_fromstr(&id1, zero_id)); - cl_git_pass(hash_object(&id2, &zero_obj)); - cl_assert(git_oid_cmp(&id1, &id2) == 0); -} - -void test_object_raw_hash__hash_one_byte_object(void) -{ - git_oid id1, id2; - - cl_git_pass(git_oid_fromstr(&id1, one_id)); - cl_git_pass(hash_object(&id2, &one_obj)); - cl_assert(git_oid_cmp(&id1, &id2) == 0); -} - -void test_object_raw_hash__hash_two_byte_object(void) -{ - git_oid id1, id2; - - cl_git_pass(git_oid_fromstr(&id1, two_id)); - cl_git_pass(hash_object(&id2, &two_obj)); - cl_assert(git_oid_cmp(&id1, &id2) == 0); -} - -void test_object_raw_hash__hash_multi_byte_object(void) -{ - git_oid id1, id2; - - cl_git_pass(git_oid_fromstr(&id1, some_id)); - cl_git_pass(hash_object(&id2, &some_obj)); - cl_assert(git_oid_cmp(&id1, &id2) == 0); -} diff --git a/tests-clay/object/raw/short.c b/tests-clay/object/raw/short.c deleted file mode 100644 index 996f3f7b4..000000000 --- a/tests-clay/object/raw/short.c +++ /dev/null @@ -1,94 +0,0 @@ - -#include "clay_libgit2.h" - -#include "odb.h" -#include "hash.h" - -void test_object_raw_short__oid_shortener_no_duplicates(void) -{ - git_oid_shorten *os; - int min_len; - - os = git_oid_shorten_new(0); - cl_assert(os != NULL); - - git_oid_shorten_add(os, "22596363b3de40b06f981fb85d82312e8c0ed511"); - git_oid_shorten_add(os, "ce08fe4884650f067bd5703b6a59a8b3b3c99a09"); - git_oid_shorten_add(os, "16a0123456789abcdef4b775213c23a8bd74f5e0"); - min_len = git_oid_shorten_add(os, "ce08fe4884650f067bd5703b6a59a8b3b3c99a09"); - - cl_assert(min_len == GIT_OID_HEXSZ + 1); - - git_oid_shorten_free(os); -} - -void test_object_raw_short__oid_shortener_stresstest_git_oid_shorten(void) -{ -#define MAX_OIDS 1000 - - git_oid_shorten *os; - char *oids[MAX_OIDS]; - char number_buffer[16]; - git_oid oid; - size_t i, j; - - int min_len = 0, found_collision; - - os = git_oid_shorten_new(0); - cl_assert(os != NULL); - - /* - * Insert in the shortener 1000 unique SHA1 ids - */ - for (i = 0; i < MAX_OIDS; ++i) { - char *oid_text; - - sprintf(number_buffer, "%u", (unsigned int)i); - git_hash_buf(&oid, number_buffer, strlen(number_buffer)); - - oid_text = git__malloc(GIT_OID_HEXSZ + 1); - git_oid_fmt(oid_text, &oid); - oid_text[GIT_OID_HEXSZ] = 0; - - min_len = git_oid_shorten_add(os, oid_text); - cl_assert(min_len >= 0); - - oids[i] = oid_text; - } - - /* - * Compare the first `min_char - 1` characters of each - * SHA1 OID. If the minimizer worked, we should find at - * least one collision - */ - found_collision = 0; - for (i = 0; i < MAX_OIDS; ++i) { - for (j = 0; j < MAX_OIDS; ++j) { - if (i != j && memcmp(oids[i], oids[j], min_len - 1) == 0) - found_collision = 1; - } - } - cl_assert(found_collision == 1); - - /* - * Compare the first `min_char` characters of each - * SHA1 OID. If the minimizer worked, every single preffix - * should be unique. - */ - found_collision = 0; - for (i = 0; i < MAX_OIDS; ++i) { - for (j = 0; j < MAX_OIDS; ++j) { - if (i != j && memcmp(oids[i], oids[j], min_len) == 0) - found_collision = 1; - } - } - cl_assert(found_collision == 0); - - /* cleanup */ - for (i = 0; i < MAX_OIDS; ++i) - git__free(oids[i]); - - git_oid_shorten_free(os); - -#undef MAX_OIDS -} diff --git a/tests-clay/object/raw/size.c b/tests-clay/object/raw/size.c deleted file mode 100644 index 44c5b6cd1..000000000 --- a/tests-clay/object/raw/size.c +++ /dev/null @@ -1,13 +0,0 @@ - -#include "clay_libgit2.h" - -#include "odb.h" - -void test_object_raw_size__validate_oid_size(void) -{ - git_oid out; - cl_assert(20 == GIT_OID_RAWSZ); - cl_assert(40 == GIT_OID_HEXSZ); - cl_assert(sizeof(out) == GIT_OID_RAWSZ); - cl_assert(sizeof(out.id) == GIT_OID_RAWSZ); -} diff --git a/tests-clay/object/raw/type2string.c b/tests-clay/object/raw/type2string.c deleted file mode 100644 index 109bc1112..000000000 --- a/tests-clay/object/raw/type2string.c +++ /dev/null @@ -1,54 +0,0 @@ - -#include "clay_libgit2.h" - -#include "odb.h" -#include "hash.h" - -void test_object_raw_type2string__convert_type_to_string(void) -{ - cl_assert(!strcmp(git_object_type2string(GIT_OBJ_BAD), "")); - cl_assert(!strcmp(git_object_type2string(GIT_OBJ__EXT1), "")); - cl_assert(!strcmp(git_object_type2string(GIT_OBJ_COMMIT), "commit")); - cl_assert(!strcmp(git_object_type2string(GIT_OBJ_TREE), "tree")); - cl_assert(!strcmp(git_object_type2string(GIT_OBJ_BLOB), "blob")); - cl_assert(!strcmp(git_object_type2string(GIT_OBJ_TAG), "tag")); - cl_assert(!strcmp(git_object_type2string(GIT_OBJ__EXT2), "")); - cl_assert(!strcmp(git_object_type2string(GIT_OBJ_OFS_DELTA), "OFS_DELTA")); - cl_assert(!strcmp(git_object_type2string(GIT_OBJ_REF_DELTA), "REF_DELTA")); - - cl_assert(!strcmp(git_object_type2string(-2), "")); - cl_assert(!strcmp(git_object_type2string(8), "")); - cl_assert(!strcmp(git_object_type2string(1234), "")); -} - -void test_object_raw_type2string__convert_string_to_type(void) -{ - cl_assert(git_object_string2type(NULL) == GIT_OBJ_BAD); - cl_assert(git_object_string2type("") == GIT_OBJ_BAD); - cl_assert(git_object_string2type("commit") == GIT_OBJ_COMMIT); - cl_assert(git_object_string2type("tree") == GIT_OBJ_TREE); - cl_assert(git_object_string2type("blob") == GIT_OBJ_BLOB); - cl_assert(git_object_string2type("tag") == GIT_OBJ_TAG); - cl_assert(git_object_string2type("OFS_DELTA") == GIT_OBJ_OFS_DELTA); - cl_assert(git_object_string2type("REF_DELTA") == GIT_OBJ_REF_DELTA); - - cl_assert(git_object_string2type("CoMmIt") == GIT_OBJ_BAD); - cl_assert(git_object_string2type("hohoho") == GIT_OBJ_BAD); -} - -void test_object_raw_type2string__check_type_is_loose(void) -{ - cl_assert(git_object_typeisloose(GIT_OBJ_BAD) == 0); - cl_assert(git_object_typeisloose(GIT_OBJ__EXT1) == 0); - cl_assert(git_object_typeisloose(GIT_OBJ_COMMIT) == 1); - cl_assert(git_object_typeisloose(GIT_OBJ_TREE) == 1); - cl_assert(git_object_typeisloose(GIT_OBJ_BLOB) == 1); - cl_assert(git_object_typeisloose(GIT_OBJ_TAG) == 1); - cl_assert(git_object_typeisloose(GIT_OBJ__EXT2) == 0); - cl_assert(git_object_typeisloose(GIT_OBJ_OFS_DELTA) == 0); - cl_assert(git_object_typeisloose(GIT_OBJ_REF_DELTA) == 0); - - cl_assert(git_object_typeisloose(-2) == 0); - cl_assert(git_object_typeisloose(8) == 0); - cl_assert(git_object_typeisloose(1234) == 0); -} diff --git a/tests-clay/object/tree/diff.c b/tests-clay/object/tree/diff.c deleted file mode 100644 index 315e0fa47..000000000 --- a/tests-clay/object/tree/diff.c +++ /dev/null @@ -1,168 +0,0 @@ -#include "clay_libgit2.h" -#include "tree.h" -#include "repository.h" - -static git_repository *repo; -static git_index *theindex; -static git_tree *atree, *btree; -static git_oid aoid, boid; - -static void diff_cmp(const git_tree_diff_data *a, const git_tree_diff_data *b) -{ - cl_assert(a->old_attr - b->old_attr == 0); - - cl_assert(a->new_attr - b->new_attr == 0); - - cl_assert(git_oid_cmp(&a->old_oid, &b->old_oid) == 0); - cl_assert(git_oid_cmp(&a->new_oid, &b->new_oid) == 0); - - cl_assert(a->status - b->status == 0); - - cl_assert(strcmp(a->path, b->path) == 0); -} - -static int diff_cb(const git_tree_diff_data *diff, void *data) -{ - diff_cmp(diff, data); - return GIT_SUCCESS; -} - -static void test_diff(git_tree *a, git_tree *b, git_tree_diff_cb cb, void *data) -{ - cl_must_pass(git_tree_diff(a, b, cb, data)); - - cl_git_pass(git_index_read_tree(theindex, b)); - cl_git_pass(git_tree_diff_index_recursive(a, theindex, cb, data)); -} - -void test_object_tree_diff__initialize(void) -{ - cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git"))); - cl_git_pass(git_repository_index(&theindex, repo)); -} - -void test_object_tree_diff__cleanup(void) -{ - git_tree_free(atree); - git_tree_free(btree); - git_index_free(theindex); - git_repository_free(repo); -} - -void test_object_tree_diff__addition(void) -{ - char *astr = "181037049a54a1eb5fab404658a3a250b44335d7"; - char *bstr = "f60079018b664e4e79329a7ef9559c8d9e0378d1"; - git_tree_diff_data expect; - - memset(&expect, 0x0, sizeof(git_tree_diff_data)); - expect.old_attr = 0; - expect.new_attr = 0100644; - git_oid_fromstr(&expect.new_oid, "fa49b077972391ad58037050f2a75f74e3671e92"); - expect.status = GIT_STATUS_ADDED; - expect.path = "new.txt"; - - cl_must_pass(git_oid_fromstr(&aoid, astr)); - cl_must_pass(git_oid_fromstr(&boid, bstr)); - - cl_must_pass(git_tree_lookup(&atree, repo, &aoid)); - cl_must_pass(git_tree_lookup(&btree, repo, &boid)); - - test_diff(atree, btree, diff_cb, &expect); -} - -void test_object_tree_diff__deletion(void) -{ - char *astr = "f60079018b664e4e79329a7ef9559c8d9e0378d1"; - char *bstr = "181037049a54a1eb5fab404658a3a250b44335d7"; - git_tree_diff_data expect; - - memset(&expect, 0x0, sizeof(git_tree_diff_data)); - expect.old_attr = 0100644; - expect.new_attr = 0; - git_oid_fromstr(&expect.old_oid, "fa49b077972391ad58037050f2a75f74e3671e92"); - expect.status = GIT_STATUS_DELETED; - expect.path = "new.txt"; - cl_must_pass(git_oid_fromstr(&aoid, astr)); - cl_must_pass(git_oid_fromstr(&boid, bstr)); - - cl_must_pass(git_tree_lookup(&atree, repo, &aoid)); - cl_must_pass(git_tree_lookup(&btree, repo, &boid)); - - test_diff(atree, btree, diff_cb, &expect); -} - -void test_object_tree_diff__modification(void) -{ - char *astr = "1810dff58d8a660512d4832e740f692884338ccd"; - char *bstr = "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162"; - git_tree_diff_data expect; - - expect.old_attr = 0100644; - expect.new_attr = 0100644; - git_oid_fromstr(&expect.old_oid, "45b983be36b73c0788dc9cbcb76cbb80fc7bb057"); - git_oid_fromstr(&expect.new_oid, "3697d64be941a53d4ae8f6a271e4e3fa56b022cc"); - expect.status = GIT_STATUS_MODIFIED; - expect.path = "branch_file.txt"; - - cl_must_pass(git_oid_fromstr(&aoid, astr)); - cl_must_pass(git_oid_fromstr(&boid, bstr)); - - cl_must_pass(git_tree_lookup(&atree, repo, &aoid)); - cl_must_pass(git_tree_lookup(&btree, repo, &boid)); - - test_diff(atree, btree, diff_cb, &expect); -} - -struct diff_more_data { - git_tree_diff_data expect[3]; - int expect_idx; -}; - -static int diff_more_cb(const git_tree_diff_data *diff, void *data) -{ - struct diff_more_data *more_data = data; - diff_cmp(diff, &more_data->expect[more_data->expect_idx]); - - more_data->expect_idx = (more_data->expect_idx + 1) % ARRAY_SIZE(more_data->expect); - - return GIT_SUCCESS; -} - -void test_object_tree_diff__more(void) -{ - char *astr = "814889a078c031f61ed08ab5fa863aea9314344d"; - char *bstr = "75057dd4114e74cca1d750d0aee1647c903cb60a"; - struct diff_more_data more_data; - git_tree_diff_data *expect = more_data.expect; - - memset(&more_data, 0x0, sizeof(struct diff_more_data)); - /* M README */ - expect[0].old_attr = 0100644; - expect[0].new_attr = 0100644; - git_oid_fromstr(&expect[0].old_oid, "a8233120f6ad708f843d861ce2b7228ec4e3dec6"); - git_oid_fromstr(&expect[0].new_oid, "1385f264afb75a56a5bec74243be9b367ba4ca08"); - expect[0].status = GIT_STATUS_MODIFIED; - expect[0].path = "README"; - /* A branch_file.txt */ - expect[1].old_attr = 0; - expect[1].new_attr = 0100644; - git_oid_fromstr(&expect[1].new_oid, "45b983be36b73c0788dc9cbcb76cbb80fc7bb057"); - expect[1].status = GIT_STATUS_ADDED; - expect[1].path = "branch_file.txt"; - /* M new.txt */ - expect[2].old_attr = 0100644; - expect[2].new_attr = 0100644; - git_oid_fromstr(&expect[2].old_oid, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd"); - git_oid_fromstr(&expect[2].new_oid, "fa49b077972391ad58037050f2a75f74e3671e92"); - expect[2].status = GIT_STATUS_MODIFIED; - expect[2].path = "new.txt"; - - cl_must_pass(git_oid_fromstr(&aoid, astr)); - cl_must_pass(git_oid_fromstr(&boid, bstr)); - - cl_must_pass(git_tree_lookup(&atree, repo, &aoid)); - cl_must_pass(git_tree_lookup(&btree, repo, &boid)); - - test_diff(atree, btree, diff_more_cb, &more_data); -} diff --git a/tests-clay/object/tree/frompath.c b/tests-clay/object/tree/frompath.c deleted file mode 100644 index 06d08ac7b..000000000 --- a/tests-clay/object/tree/frompath.c +++ /dev/null @@ -1,75 +0,0 @@ -#include "clay_libgit2.h" - -static git_repository *repo; -const char *tree_with_subtrees_oid = "ae90f12eea699729ed24555e40b9fd669da12a12"; -static git_tree *tree; - -void test_object_tree_frompath__initialize(void) -{ - git_oid id; - - cl_fixture_sandbox("testrepo.git"); - cl_git_pass(git_repository_open(&repo, "testrepo.git")); - cl_assert(repo != NULL); - - cl_git_pass(git_oid_fromstr(&id, tree_with_subtrees_oid)); - cl_git_pass(git_tree_lookup(&tree, repo, &id)); - cl_assert(tree != NULL); -} - -void test_object_tree_frompath__cleanup(void) -{ - git_tree_free(tree); - git_repository_free(repo); - cl_fixture_cleanup("testrepo.git"); -} - -static void assert_tree_from_path(git_tree *root, const char *path, git_error expected_result, const char *expected_raw_oid) -{ - git_tree *containing_tree = NULL; - - cl_assert(git_tree_get_subtree(&containing_tree, root, path) == expected_result); - - if (containing_tree == NULL && expected_result != GIT_SUCCESS) - return; - - cl_assert(containing_tree != NULL && expected_result == GIT_SUCCESS); - - cl_assert(git_oid_streq(git_object_id((const git_object *)containing_tree), expected_raw_oid) == GIT_SUCCESS); - - git_tree_free(containing_tree); -} - -void test_object_tree_frompath__retrieve_tree_from_path_to_treeentry(void) -{ - /* Will return self if given a one path segment... */ - assert_tree_from_path(tree, "README", GIT_SUCCESS, tree_with_subtrees_oid); - - /* ...even one that lead to a non existent tree entry. */ - assert_tree_from_path(tree, "i-do-not-exist.txt", GIT_SUCCESS, tree_with_subtrees_oid); - - /* Will return fgh tree oid given this following path... */ - assert_tree_from_path(tree, "ab/de/fgh/1.txt", GIT_SUCCESS, "3259a6bd5b57fb9c1281bb7ed3167b50f224cb54"); - - /* ... and ab tree oid given this one. */ - assert_tree_from_path(tree, "ab/de", GIT_SUCCESS, "f1425cef211cc08caa31e7b545ffb232acb098c3"); - - /* Will succeed if given a valid path which leads to a tree entry which doesn't exist */ - assert_tree_from_path(tree, "ab/de/fgh/i-do-not-exist.txt", GIT_SUCCESS, "3259a6bd5b57fb9c1281bb7ed3167b50f224cb54"); -} - -void test_object_tree_frompath__fail_when_processing_an_unknown_tree_segment(void) -{ - assert_tree_from_path(tree, "nope/de/fgh/1.txt", GIT_ENOTFOUND, NULL); - assert_tree_from_path(tree, "ab/me-neither/fgh/2.txt", GIT_ENOTFOUND, NULL); -} - -void test_object_tree_frompath__fail_when_processing_an_invalid_path(void) -{ - assert_tree_from_path(tree, "/", GIT_EINVALIDPATH, NULL); - assert_tree_from_path(tree, "/ab", GIT_EINVALIDPATH, NULL); - assert_tree_from_path(tree, "/ab/de", GIT_EINVALIDPATH, NULL); - assert_tree_from_path(tree, "ab/", GIT_EINVALIDPATH, NULL); - assert_tree_from_path(tree, "ab//de", GIT_EINVALIDPATH, NULL); - assert_tree_from_path(tree, "ab/de/", GIT_EINVALIDPATH, NULL); -} diff --git a/tests-clay/odb/loose.c b/tests-clay/odb/loose.c deleted file mode 100644 index 1d534704e..000000000 --- a/tests-clay/odb/loose.c +++ /dev/null @@ -1,84 +0,0 @@ -#include "clay_libgit2.h" -#include "odb.h" -#include "posix.h" -#include "loose_data.h" - -static void write_object_files(object_data *d) -{ - int fd; - - if (p_mkdir(d->dir, GIT_OBJECT_DIR_MODE) < 0) - cl_assert(errno == EEXIST); - - cl_assert((fd = p_creat(d->file, S_IREAD | S_IWRITE)) >= 0); - cl_must_pass(p_write(fd, d->bytes, d->blen)); - - p_close(fd); -} - -static void cmp_objects(git_rawobj *o, object_data *d) -{ - cl_assert(o->type == git_object_string2type(d->type)); - cl_assert(o->len == d->dlen); - - if (o->len > 0) - cl_assert(memcmp(o->data, d->data, o->len) == 0); -} - -static void test_read_object(object_data *data) -{ - git_oid id; - git_odb_object *obj; - git_odb *odb; - - write_object_files(data); - - cl_git_pass(git_odb_open(&odb, "test-objects")); - cl_git_pass(git_oid_fromstr(&id, data->id)); - cl_git_pass(git_odb_read(&obj, odb, &id)); - - cmp_objects((git_rawobj *)&obj->raw, data); - - git_odb_object_free(obj); - git_odb_free(odb); -} - -void test_odb_loose__initialize(void) -{ - cl_must_pass(p_mkdir("test-objects", GIT_OBJECT_DIR_MODE)); -} - -void test_odb_loose__cleanup(void) -{ - cl_fixture_cleanup("test-objects"); -} - -void test_odb_loose__exists(void) -{ - git_oid id, id2; - git_odb *odb; - - write_object_files(&one); - cl_git_pass(git_odb_open(&odb, "test-objects")); - - cl_git_pass(git_oid_fromstr(&id, one.id)); - - cl_assert(git_odb_exists(odb, &id)); - - /* Test for a non-existant object */ - cl_git_pass(git_oid_fromstr(&id2, "8b137891791fe96927ad78e64b0aad7bded08baa")); - cl_assert(!git_odb_exists(odb, &id2)); - - git_odb_free(odb); -} - -void test_odb_loose__simple_reads(void) -{ - test_read_object(&commit); - test_read_object(&tree); - test_read_object(&tag); - test_read_object(&zero); - test_read_object(&one); - test_read_object(&two); - test_read_object(&some); -} diff --git a/tests-clay/odb/loose_data.h b/tests-clay/odb/loose_data.h deleted file mode 100644 index c10c9bc7f..000000000 --- a/tests-clay/odb/loose_data.h +++ /dev/null @@ -1,522 +0,0 @@ -typedef struct object_data { - unsigned char *bytes; /* (compressed) bytes stored in object store */ - size_t blen; /* length of data in object store */ - char *id; /* object id (sha1) */ - char *type; /* object type */ - char *dir; /* object store (fan-out) directory name */ - char *file; /* object store filename */ - unsigned char *data; /* (uncompressed) object data */ - size_t dlen; /* length of (uncompressed) object data */ -} object_data; - -/* one == 8b137891791fe96927ad78e64b0aad7bded08bdc */ -static unsigned char one_bytes[] = { - 0x31, 0x78, 0x9c, 0xe3, 0x02, 0x00, 0x00, 0x0b, - 0x00, 0x0b, -}; - -static unsigned char one_data[] = { - 0x0a, -}; - -static object_data one = { - one_bytes, - sizeof(one_bytes), - "8b137891791fe96927ad78e64b0aad7bded08bdc", - "blob", - "test-objects/8b", - "test-objects/8b/137891791fe96927ad78e64b0aad7bded08bdc", - one_data, - sizeof(one_data), -}; - - -/* commit == 3d7f8a6af076c8c3f20071a8935cdbe8228594d1 */ -static unsigned char commit_bytes[] = { - 0x78, 0x01, 0x85, 0x50, 0xc1, 0x6a, 0xc3, 0x30, - 0x0c, 0xdd, 0xd9, 0x5f, 0xa1, 0xfb, 0x96, 0x12, - 0xbb, 0x29, 0x71, 0x46, 0x19, 0x2b, 0x3d, 0x97, - 0x1d, 0xd6, 0x7d, 0x80, 0x1d, 0xcb, 0x89, 0x21, - 0xb6, 0x82, 0xed, 0x40, 0xf3, 0xf7, 0xf3, 0x48, - 0x29, 0x3b, 0x6d, 0xd2, 0xe5, 0xbd, 0x27, 0xbd, - 0x27, 0x50, 0x4f, 0xde, 0xbb, 0x0c, 0xfb, 0x43, - 0xf3, 0x94, 0x23, 0x22, 0x18, 0x6b, 0x85, 0x51, - 0x5d, 0xad, 0xc5, 0xa1, 0x41, 0xae, 0x51, 0x4b, - 0xd9, 0x19, 0x6e, 0x4b, 0x0b, 0x29, 0x35, 0x72, - 0x59, 0xef, 0x5b, 0x29, 0x8c, 0x65, 0x6a, 0xc9, - 0x23, 0x45, 0x38, 0xc1, 0x17, 0x5c, 0x7f, 0xc0, - 0x71, 0x13, 0xde, 0xf1, 0xa6, 0xfc, 0x3c, 0xe1, - 0xae, 0x27, 0xff, 0x06, 0x5c, 0x88, 0x56, 0xf2, - 0x46, 0x74, 0x2d, 0x3c, 0xd7, 0xa5, 0x58, 0x51, - 0xcb, 0xb9, 0x8c, 0x11, 0xce, 0xf0, 0x01, 0x97, - 0x0d, 0x1e, 0x1f, 0xea, 0x3f, 0x6e, 0x76, 0x02, - 0x0a, 0x58, 0x4d, 0x2e, 0x20, 0x6c, 0x1e, 0x48, - 0x8b, 0xf7, 0x2a, 0xae, 0x8c, 0x5d, 0x47, 0x04, - 0x4d, 0x66, 0x05, 0xb2, 0x90, 0x0b, 0xbe, 0xcf, - 0x3d, 0xa6, 0xa4, 0x06, 0x7c, 0x29, 0x3c, 0x64, - 0xe5, 0x82, 0x0b, 0x03, 0xd8, 0x25, 0x96, 0x8d, - 0x08, 0x78, 0x9b, 0x27, 0x15, 0x54, 0x76, 0x14, - 0xd8, 0xdd, 0x35, 0x2f, 0x71, 0xa6, 0x84, 0x8f, - 0x90, 0x51, 0x85, 0x01, 0x13, 0xb8, 0x90, 0x23, - 0x99, 0xa5, 0x47, 0x03, 0x7a, 0xfd, 0x15, 0xbf, - 0x63, 0xec, 0xd3, 0x0d, 0x01, 0x4d, 0x45, 0xb6, - 0xd2, 0xeb, 0xeb, 0xdf, 0xef, 0x60, 0xdf, 0xef, - 0x1f, 0x78, 0x35, -}; - -static unsigned char commit_data[] = { - 0x74, 0x72, 0x65, 0x65, 0x20, 0x64, 0x66, 0x66, - 0x32, 0x64, 0x61, 0x39, 0x30, 0x62, 0x32, 0x35, - 0x34, 0x65, 0x31, 0x62, 0x65, 0x62, 0x38, 0x38, - 0x39, 0x64, 0x31, 0x66, 0x31, 0x66, 0x31, 0x32, - 0x38, 0x38, 0x62, 0x65, 0x31, 0x38, 0x30, 0x33, - 0x37, 0x38, 0x32, 0x64, 0x66, 0x0a, 0x61, 0x75, - 0x74, 0x68, 0x6f, 0x72, 0x20, 0x41, 0x20, 0x55, - 0x20, 0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61, - 0x75, 0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78, - 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, - 0x6d, 0x3e, 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, - 0x31, 0x34, 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, - 0x30, 0x30, 0x30, 0x0a, 0x63, 0x6f, 0x6d, 0x6d, - 0x69, 0x74, 0x74, 0x65, 0x72, 0x20, 0x43, 0x20, - 0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72, - 0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, - 0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d, - 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e, - 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34, - 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30, - 0x30, 0x0a, 0x0a, 0x41, 0x20, 0x6f, 0x6e, 0x65, - 0x2d, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x63, 0x6f, - 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x73, 0x75, 0x6d, - 0x6d, 0x61, 0x72, 0x79, 0x0a, 0x0a, 0x54, 0x68, - 0x65, 0x20, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x6f, - 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, - 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x6d, 0x65, 0x73, - 0x73, 0x61, 0x67, 0x65, 0x2c, 0x20, 0x63, 0x6f, - 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x69, 0x6e, 0x67, - 0x20, 0x66, 0x75, 0x72, 0x74, 0x68, 0x65, 0x72, - 0x20, 0x65, 0x78, 0x70, 0x6c, 0x61, 0x6e, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x6f, 0x66, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x70, 0x75, 0x72, 0x70, - 0x6f, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x63, 0x68, 0x61, 0x6e, 0x67, - 0x65, 0x73, 0x20, 0x69, 0x6e, 0x74, 0x72, 0x6f, - 0x64, 0x75, 0x63, 0x65, 0x64, 0x20, 0x62, 0x79, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x6d, - 0x6d, 0x69, 0x74, 0x2e, 0x0a, 0x0a, 0x53, 0x69, - 0x67, 0x6e, 0x65, 0x64, 0x2d, 0x6f, 0x66, 0x2d, - 0x62, 0x79, 0x3a, 0x20, 0x41, 0x20, 0x55, 0x20, - 0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61, 0x75, - 0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78, 0x61, - 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, - 0x3e, 0x0a, -}; - -static object_data commit = { - commit_bytes, - sizeof(commit_bytes), - "3d7f8a6af076c8c3f20071a8935cdbe8228594d1", - "commit", - "test-objects/3d", - "test-objects/3d/7f8a6af076c8c3f20071a8935cdbe8228594d1", - commit_data, - sizeof(commit_data), -}; - -/* tree == dff2da90b254e1beb889d1f1f1288be1803782df */ -static unsigned char tree_bytes[] = { - 0x78, 0x01, 0x2b, 0x29, 0x4a, 0x4d, 0x55, 0x30, - 0x34, 0x32, 0x63, 0x30, 0x34, 0x30, 0x30, 0x33, - 0x31, 0x51, 0xc8, 0xcf, 0x4b, 0x65, 0xe8, 0x16, - 0xae, 0x98, 0x58, 0x29, 0xff, 0x32, 0x53, 0x7d, - 0x6d, 0xc5, 0x33, 0x6f, 0xae, 0xb5, 0xd5, 0xf7, - 0x2e, 0x74, 0xdf, 0x81, 0x4a, 0x17, 0xe7, 0xe7, - 0xa6, 0x32, 0xfc, 0x6d, 0x31, 0xd8, 0xd3, 0xe6, - 0xf3, 0xe7, 0xea, 0x47, 0xbe, 0xd0, 0x09, 0x3f, - 0x96, 0xb8, 0x3f, 0x90, 0x9e, 0xa2, 0xfd, 0x0f, - 0x2a, 0x5f, 0x52, 0x9e, 0xcf, 0x50, 0x31, 0x43, - 0x52, 0x29, 0xd1, 0x5a, 0xeb, 0x77, 0x82, 0x2a, - 0x8b, 0xfe, 0xb7, 0xbd, 0xed, 0x5d, 0x07, 0x67, - 0xfa, 0xb5, 0x42, 0xa5, 0xab, 0x52, 0x8b, 0xf2, - 0x19, 0x9e, 0xcd, 0x7d, 0x34, 0x7b, 0xd3, 0xc5, - 0x6b, 0xce, 0xde, 0xdd, 0x9a, 0xeb, 0xca, 0xa3, - 0x6e, 0x1c, 0x7a, 0xd2, 0x13, 0x3c, 0x11, 0x00, - 0xe2, 0xaa, 0x38, 0x57, -}; - -static unsigned char tree_data[] = { - 0x31, 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x6f, - 0x6e, 0x65, 0x00, 0x8b, 0x13, 0x78, 0x91, 0x79, - 0x1f, 0xe9, 0x69, 0x27, 0xad, 0x78, 0xe6, 0x4b, - 0x0a, 0xad, 0x7b, 0xde, 0xd0, 0x8b, 0xdc, 0x31, - 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x73, 0x6f, - 0x6d, 0x65, 0x00, 0xfd, 0x84, 0x30, 0xbc, 0x86, - 0x4c, 0xfc, 0xd5, 0xf1, 0x0e, 0x55, 0x90, 0xf8, - 0xa4, 0x47, 0xe0, 0x1b, 0x94, 0x2b, 0xfe, 0x31, - 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x74, 0x77, - 0x6f, 0x00, 0x78, 0x98, 0x19, 0x22, 0x61, 0x3b, - 0x2a, 0xfb, 0x60, 0x25, 0x04, 0x2f, 0xf6, 0xbd, - 0x87, 0x8a, 0xc1, 0x99, 0x4e, 0x85, 0x31, 0x30, - 0x30, 0x36, 0x34, 0x34, 0x20, 0x7a, 0x65, 0x72, - 0x6f, 0x00, 0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1, - 0xd6, 0x43, 0x4b, 0x8b, 0x29, 0xae, 0x77, 0x5a, - 0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91, -}; - -static object_data tree = { - tree_bytes, - sizeof(tree_bytes), - "dff2da90b254e1beb889d1f1f1288be1803782df", - "tree", - "test-objects/df", - "test-objects/df/f2da90b254e1beb889d1f1f1288be1803782df", - tree_data, - sizeof(tree_data), -}; - -/* tag == 09d373e1dfdc16b129ceec6dd649739911541e05 */ -static unsigned char tag_bytes[] = { - 0x78, 0x01, 0x35, 0x4e, 0xcb, 0x0a, 0xc2, 0x40, - 0x10, 0xf3, 0xbc, 0x5f, 0x31, 0x77, 0xa1, 0xec, - 0xa3, 0xed, 0x6e, 0x41, 0x44, 0xf0, 0x2c, 0x5e, - 0xfc, 0x81, 0xe9, 0x76, 0xb6, 0xad, 0xb4, 0xb4, - 0x6c, 0x07, 0xd1, 0xbf, 0x77, 0x44, 0x0d, 0x39, - 0x84, 0x10, 0x92, 0x30, 0xf6, 0x60, 0xbc, 0xdb, - 0x2d, 0xed, 0x9d, 0x22, 0x83, 0xeb, 0x7c, 0x0a, - 0x58, 0x63, 0xd2, 0xbe, 0x8e, 0x21, 0xba, 0x64, - 0xb5, 0xf6, 0x06, 0x43, 0xe3, 0xaa, 0xd8, 0xb5, - 0x14, 0xac, 0x0d, 0x55, 0x53, 0x76, 0x46, 0xf1, - 0x6b, 0x25, 0x88, 0xcb, 0x3c, 0x8f, 0xac, 0x58, - 0x3a, 0x1e, 0xba, 0xd0, 0x85, 0xd8, 0xd8, 0xf7, - 0x94, 0xe1, 0x0c, 0x57, 0xb8, 0x8c, 0xcc, 0x22, - 0x0f, 0xdf, 0x90, 0xc8, 0x13, 0x3d, 0x71, 0x5e, - 0x27, 0x2a, 0xc4, 0x39, 0x82, 0xb1, 0xd6, 0x07, - 0x53, 0xda, 0xc6, 0xc3, 0x5e, 0x0b, 0x94, 0xba, - 0x0d, 0xe3, 0x06, 0x42, 0x1e, 0x08, 0x3e, 0x95, - 0xbf, 0x4b, 0x69, 0xc9, 0x90, 0x69, 0x22, 0xdc, - 0xe8, 0xbf, 0xf2, 0x06, 0x42, 0x9a, 0x36, 0xb1, -}; - -static unsigned char tag_data[] = { - 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x33, - 0x64, 0x37, 0x66, 0x38, 0x61, 0x36, 0x61, 0x66, - 0x30, 0x37, 0x36, 0x63, 0x38, 0x63, 0x33, 0x66, - 0x32, 0x30, 0x30, 0x37, 0x31, 0x61, 0x38, 0x39, - 0x33, 0x35, 0x63, 0x64, 0x62, 0x65, 0x38, 0x32, - 0x32, 0x38, 0x35, 0x39, 0x34, 0x64, 0x31, 0x0a, - 0x74, 0x79, 0x70, 0x65, 0x20, 0x63, 0x6f, 0x6d, - 0x6d, 0x69, 0x74, 0x0a, 0x74, 0x61, 0x67, 0x20, - 0x76, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x0a, 0x74, - 0x61, 0x67, 0x67, 0x65, 0x72, 0x20, 0x43, 0x20, - 0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72, - 0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, - 0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d, - 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e, - 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34, - 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30, - 0x30, 0x0a, 0x0a, 0x54, 0x68, 0x69, 0x73, 0x20, - 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, - 0x61, 0x67, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, - 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x72, 0x65, - 0x6c, 0x65, 0x61, 0x73, 0x65, 0x20, 0x76, 0x30, - 0x2e, 0x30, 0x2e, 0x31, 0x0a, -}; - -static object_data tag = { - tag_bytes, - sizeof(tag_bytes), - "09d373e1dfdc16b129ceec6dd649739911541e05", - "tag", - "test-objects/09", - "test-objects/09/d373e1dfdc16b129ceec6dd649739911541e05", - tag_data, - sizeof(tag_data), -}; - -/* zero == e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 */ -static unsigned char zero_bytes[] = { - 0x78, 0x01, 0x4b, 0xca, 0xc9, 0x4f, 0x52, 0x30, - 0x60, 0x00, 0x00, 0x09, 0xb0, 0x01, 0xf0, -}; - -static unsigned char zero_data[] = { - 0x00 /* dummy data */ -}; - -static object_data zero = { - zero_bytes, - sizeof(zero_bytes), - "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", - "blob", - "test-objects/e6", - "test-objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391", - zero_data, - 0, -}; - -/* two == 78981922613b2afb6025042ff6bd878ac1994e85 */ -static unsigned char two_bytes[] = { - 0x78, 0x01, 0x4b, 0xca, 0xc9, 0x4f, 0x52, 0x30, - 0x62, 0x48, 0xe4, 0x02, 0x00, 0x0e, 0x64, 0x02, - 0x5d, -}; - -static unsigned char two_data[] = { - 0x61, 0x0a, -}; - -static object_data two = { - two_bytes, - sizeof(two_bytes), - "78981922613b2afb6025042ff6bd878ac1994e85", - "blob", - "test-objects/78", - "test-objects/78/981922613b2afb6025042ff6bd878ac1994e85", - two_data, - sizeof(two_data), -}; - -/* some == fd8430bc864cfcd5f10e5590f8a447e01b942bfe */ -static unsigned char some_bytes[] = { - 0x78, 0x01, 0x7d, 0x54, 0xc1, 0x4e, 0xe3, 0x30, - 0x10, 0xdd, 0x33, 0x5f, 0x31, 0xc7, 0x5d, 0x94, - 0xa5, 0x84, 0xd5, 0x22, 0xad, 0x7a, 0x0a, 0x15, - 0x85, 0x48, 0xd0, 0x56, 0x49, 0x2a, 0xd4, 0xa3, - 0x13, 0x4f, 0x88, 0x85, 0x63, 0x47, 0xb6, 0x43, - 0xc9, 0xdf, 0xef, 0x8c, 0x69, 0x17, 0x56, 0x0b, - 0x7b, 0xaa, 0x62, 0x7b, 0xde, 0xbc, 0xf7, 0xe6, - 0x4d, 0x6b, 0x6d, 0x6b, 0x48, 0xd3, 0xcb, 0x5f, - 0x5f, 0x66, 0xa7, 0x27, 0x70, 0x0a, 0x55, 0xa7, - 0x3c, 0xb4, 0x4a, 0x23, 0xf0, 0xaf, 0x43, 0x04, - 0x6f, 0xdb, 0xb0, 0x17, 0x0e, 0xe7, 0x30, 0xd9, - 0x11, 0x1a, 0x61, 0xc0, 0xa1, 0x54, 0x3e, 0x38, - 0x55, 0x8f, 0x81, 0x9e, 0x05, 0x10, 0x46, 0xce, - 0xac, 0x83, 0xde, 0x4a, 0xd5, 0x4e, 0x0c, 0x42, - 0x67, 0xa3, 0x91, 0xe8, 0x20, 0x74, 0x08, 0x01, - 0x5d, 0xef, 0xc1, 0xb6, 0xf1, 0xe3, 0x66, 0xb5, - 0x85, 0x1b, 0x34, 0xe8, 0x84, 0x86, 0xcd, 0x58, - 0x6b, 0xd5, 0xc0, 0x9d, 0x6a, 0xd0, 0x78, 0x4c, - 0xe0, 0x19, 0x9d, 0x57, 0xd6, 0xc0, 0x45, 0xc2, - 0x18, 0xc2, 0xc3, 0xc0, 0x0f, 0x7c, 0x87, 0x12, - 0xea, 0x29, 0x56, 0x2f, 0x99, 0x4f, 0x79, 0xe0, - 0x03, 0x4b, 0x4b, 0x4d, 0x44, 0xa0, 0x92, 0x33, - 0x2a, 0xe0, 0x9a, 0xdc, 0x80, 0x90, 0x52, 0xf1, - 0x11, 0x04, 0x1b, 0x4b, 0x06, 0xea, 0xae, 0x3c, - 0xe3, 0x7a, 0x50, 0x74, 0x4a, 0x84, 0xfe, 0xc3, - 0x81, 0x41, 0xf8, 0x89, 0x18, 0x43, 0x67, 0x9d, - 0x87, 0x47, 0xf5, 0x8c, 0x51, 0xf6, 0x68, 0xb4, - 0xea, 0x55, 0x20, 0x2a, 0x6f, 0x80, 0xdc, 0x42, - 0x2b, 0xf3, 0x14, 0x2b, 0x1a, 0xdb, 0x0f, 0xe4, - 0x9a, 0x64, 0x84, 0xa3, 0x90, 0xa8, 0xf9, 0x8f, - 0x9d, 0x86, 0x9e, 0xd3, 0xab, 0x5a, 0x99, 0xc8, - 0xd9, 0xc3, 0x5e, 0x85, 0x0e, 0x2c, 0xb5, 0x73, - 0x30, 0x38, 0xfb, 0xe8, 0x44, 0xef, 0x5f, 0x95, - 0x1b, 0xc9, 0xd0, 0xef, 0x3c, 0x26, 0x32, 0x1e, - 0xff, 0x2d, 0xb6, 0x23, 0x7b, 0x3f, 0xd1, 0x3c, - 0x78, 0x1a, 0x0d, 0xcb, 0xe6, 0xf6, 0xd4, 0x44, - 0x99, 0x47, 0x1a, 0x9e, 0xed, 0x23, 0xb5, 0x91, - 0x6a, 0xdf, 0x53, 0x39, 0x03, 0xf8, 0x5a, 0xb1, - 0x0f, 0x1f, 0xce, 0x81, 0x11, 0xde, 0x01, 0x7a, - 0x90, 0x16, 0xc4, 0x30, 0xe8, 0x89, 0xed, 0x7b, - 0x65, 0x4b, 0xd7, 0x03, 0x36, 0xc1, 0xcf, 0xa1, - 0xa5, 0xb1, 0xe3, 0x8b, 0xe8, 0x07, 0x4d, 0xf3, - 0x23, 0x25, 0x13, 0x35, 0x27, 0xf5, 0x8c, 0x11, - 0xd3, 0xa0, 0x9a, 0xa8, 0xf5, 0x38, 0x7d, 0xce, - 0x55, 0xc2, 0x71, 0x79, 0x13, 0xc7, 0xa3, 0xda, - 0x77, 0x68, 0xc0, 0xd8, 0x10, 0xdd, 0x24, 0x8b, - 0x15, 0x59, 0xc5, 0x10, 0xe2, 0x20, 0x99, 0x8e, - 0xf0, 0x05, 0x9b, 0x31, 0x88, 0x5a, 0xe3, 0xd9, - 0x37, 0xba, 0xe2, 0xdb, 0xbf, 0x92, 0xfa, 0x66, - 0x16, 0x97, 0x47, 0xd9, 0x9d, 0x1d, 0x28, 0x7c, - 0x9d, 0x08, 0x1c, 0xc7, 0xbd, 0xd2, 0x1a, 0x6a, - 0x04, 0xf2, 0xa2, 0x1d, 0x75, 0x02, 0x14, 0x5d, - 0xc6, 0x78, 0xc8, 0xab, 0xdb, 0xf5, 0xb6, 0x82, - 0x6c, 0xb5, 0x83, 0x87, 0xac, 0x28, 0xb2, 0x55, - 0xb5, 0x9b, 0xc7, 0xc1, 0xb0, 0xb7, 0xf8, 0x4c, - 0xbc, 0x38, 0x0e, 0x8a, 0x04, 0x2a, 0x62, 0x41, - 0x6b, 0xe0, 0x84, 0x09, 0x13, 0xe9, 0xe1, 0xea, - 0xfb, 0xeb, 0x62, 0x71, 0x4b, 0x25, 0xd9, 0x55, - 0x7e, 0x97, 0x57, 0x3b, 0x20, 0x33, 0x96, 0x79, - 0xb5, 0xba, 0x2e, 0x4b, 0x58, 0xae, 0x0b, 0xc8, - 0x60, 0x93, 0x15, 0x55, 0xbe, 0xd8, 0xde, 0x65, - 0x05, 0x6c, 0xb6, 0xc5, 0x66, 0x5d, 0x5e, 0x93, - 0xf7, 0x25, 0x65, 0x98, 0x41, 0x29, 0x86, 0x0c, - 0xf2, 0xf1, 0x14, 0xa2, 0xb3, 0xbd, 0x75, 0x08, - 0x12, 0x83, 0x50, 0xda, 0x1f, 0x23, 0xbe, 0xa3, - 0x1d, 0xf4, 0x9d, 0x1d, 0xb5, 0x84, 0x4e, 0x50, - 0x38, 0x1d, 0x36, 0x48, 0x21, 0x95, 0xd1, 0xac, - 0x81, 0x99, 0x1d, 0xc1, 0x3f, 0x41, 0xe6, 0x9e, - 0x42, 0x5b, 0x0a, 0x48, 0xcc, 0x5f, 0xe0, 0x7d, - 0x3f, 0xc4, 0x6f, 0x0e, 0xfe, 0xc0, 0x2d, 0xfe, - 0x01, 0x2c, 0xd6, 0x9b, 0x5d, 0xbe, 0xba, 0x21, - 0xca, 0x79, 0xcb, 0xe3, 0x49, 0x60, 0xef, 0x68, - 0x05, 0x28, 0x9b, 0x8c, 0xc1, 0x12, 0x3e, 0xdb, - 0xc7, 0x04, 0x7e, 0xa6, 0x74, 0x29, 0xcc, 0x13, - 0xed, 0x07, 0x94, 0x81, 0xd6, 0x96, 0xaa, 0x97, - 0xaa, 0xa5, 0xc0, 0x2f, 0xb5, 0xb5, 0x2e, 0xe6, - 0xfc, 0xca, 0xfa, 0x60, 0x4d, 0x02, 0xf7, 0x19, - 0x9c, 0x5f, 0xa4, 0xe9, 0xf9, 0xf7, 0xf4, 0xc7, - 0x79, 0x9a, 0xc0, 0xb6, 0xcc, 0x58, 0xec, 0xec, - 0xe4, 0x37, 0x22, 0xfa, 0x8b, 0x53, -}; - -static unsigned char some_data[] = { - 0x2f, 0x2a, 0x0a, 0x20, 0x2a, 0x20, 0x54, 0x68, - 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, - 0x69, 0x73, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20, - 0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, - 0x3b, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x63, 0x61, - 0x6e, 0x20, 0x72, 0x65, 0x64, 0x69, 0x73, 0x74, - 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x69, - 0x74, 0x20, 0x61, 0x6e, 0x64, 0x2f, 0x6f, 0x72, - 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x0a, - 0x20, 0x2a, 0x20, 0x69, 0x74, 0x20, 0x75, 0x6e, - 0x64, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x74, 0x65, 0x72, 0x6d, 0x73, 0x20, 0x6f, 0x66, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x47, 0x4e, 0x55, - 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, - 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, - 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2c, - 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, - 0x20, 0x32, 0x2c, 0x0a, 0x20, 0x2a, 0x20, 0x61, - 0x73, 0x20, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, - 0x68, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x46, 0x72, 0x65, 0x65, 0x20, - 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, - 0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x2e, 0x0a, 0x20, 0x2a, 0x0a, - 0x20, 0x2a, 0x20, 0x49, 0x6e, 0x20, 0x61, 0x64, - 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74, - 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x65, - 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e, - 0x73, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, - 0x20, 0x47, 0x4e, 0x55, 0x20, 0x47, 0x65, 0x6e, - 0x65, 0x72, 0x61, 0x6c, 0x20, 0x50, 0x75, 0x62, - 0x6c, 0x69, 0x63, 0x20, 0x4c, 0x69, 0x63, 0x65, - 0x6e, 0x73, 0x65, 0x2c, 0x0a, 0x20, 0x2a, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x61, 0x75, 0x74, 0x68, - 0x6f, 0x72, 0x73, 0x20, 0x67, 0x69, 0x76, 0x65, - 0x20, 0x79, 0x6f, 0x75, 0x20, 0x75, 0x6e, 0x6c, - 0x69, 0x6d, 0x69, 0x74, 0x65, 0x64, 0x20, 0x70, - 0x65, 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, - 0x6e, 0x20, 0x74, 0x6f, 0x20, 0x6c, 0x69, 0x6e, - 0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x0a, 0x20, - 0x2a, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, - 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x69, - 0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x69, - 0x6e, 0x74, 0x6f, 0x20, 0x63, 0x6f, 0x6d, 0x62, - 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, - 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x6f, 0x74, - 0x68, 0x65, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x67, - 0x72, 0x61, 0x6d, 0x73, 0x2c, 0x0a, 0x20, 0x2a, - 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x6f, 0x20, - 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, - 0x74, 0x65, 0x20, 0x74, 0x68, 0x6f, 0x73, 0x65, - 0x20, 0x63, 0x6f, 0x6d, 0x62, 0x69, 0x6e, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x77, 0x69, - 0x74, 0x68, 0x6f, 0x75, 0x74, 0x20, 0x61, 0x6e, - 0x79, 0x20, 0x72, 0x65, 0x73, 0x74, 0x72, 0x69, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x20, 0x2a, - 0x20, 0x63, 0x6f, 0x6d, 0x69, 0x6e, 0x67, 0x20, - 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65, - 0x20, 0x75, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, - 0x74, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, - 0x65, 0x2e, 0x20, 0x20, 0x28, 0x54, 0x68, 0x65, - 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, - 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, - 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x0a, - 0x20, 0x2a, 0x20, 0x72, 0x65, 0x73, 0x74, 0x72, - 0x69, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, - 0x64, 0x6f, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, - 0x20, 0x69, 0x6e, 0x20, 0x6f, 0x74, 0x68, 0x65, - 0x72, 0x20, 0x72, 0x65, 0x73, 0x70, 0x65, 0x63, - 0x74, 0x73, 0x3b, 0x20, 0x66, 0x6f, 0x72, 0x20, - 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2c, - 0x20, 0x74, 0x68, 0x65, 0x79, 0x20, 0x63, 0x6f, - 0x76, 0x65, 0x72, 0x0a, 0x20, 0x2a, 0x20, 0x6d, - 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x2c, - 0x20, 0x61, 0x6e, 0x64, 0x20, 0x64, 0x69, 0x73, - 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, - 0x6e, 0x20, 0x77, 0x68, 0x65, 0x6e, 0x20, 0x6e, - 0x6f, 0x74, 0x20, 0x6c, 0x69, 0x6e, 0x6b, 0x65, - 0x64, 0x20, 0x69, 0x6e, 0x74, 0x6f, 0x0a, 0x20, - 0x2a, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x6d, 0x62, - 0x69, 0x6e, 0x65, 0x64, 0x20, 0x65, 0x78, 0x65, - 0x63, 0x75, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, - 0x29, 0x0a, 0x20, 0x2a, 0x0a, 0x20, 0x2a, 0x20, - 0x54, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, - 0x65, 0x20, 0x69, 0x73, 0x20, 0x64, 0x69, 0x73, - 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, - 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x68, 0x6f, 0x70, 0x65, 0x20, 0x74, 0x68, 0x61, - 0x74, 0x20, 0x69, 0x74, 0x20, 0x77, 0x69, 0x6c, - 0x6c, 0x20, 0x62, 0x65, 0x20, 0x75, 0x73, 0x65, - 0x66, 0x75, 0x6c, 0x2c, 0x20, 0x62, 0x75, 0x74, - 0x0a, 0x20, 0x2a, 0x20, 0x57, 0x49, 0x54, 0x48, - 0x4f, 0x55, 0x54, 0x20, 0x41, 0x4e, 0x59, 0x20, - 0x57, 0x41, 0x52, 0x52, 0x41, 0x4e, 0x54, 0x59, - 0x3b, 0x20, 0x77, 0x69, 0x74, 0x68, 0x6f, 0x75, - 0x74, 0x20, 0x65, 0x76, 0x65, 0x6e, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x69, - 0x65, 0x64, 0x20, 0x77, 0x61, 0x72, 0x72, 0x61, - 0x6e, 0x74, 0x79, 0x20, 0x6f, 0x66, 0x0a, 0x20, - 0x2a, 0x20, 0x4d, 0x45, 0x52, 0x43, 0x48, 0x41, - 0x4e, 0x54, 0x41, 0x42, 0x49, 0x4c, 0x49, 0x54, - 0x59, 0x20, 0x6f, 0x72, 0x20, 0x46, 0x49, 0x54, - 0x4e, 0x45, 0x53, 0x53, 0x20, 0x46, 0x4f, 0x52, - 0x20, 0x41, 0x20, 0x50, 0x41, 0x52, 0x54, 0x49, - 0x43, 0x55, 0x4c, 0x41, 0x52, 0x20, 0x50, 0x55, - 0x52, 0x50, 0x4f, 0x53, 0x45, 0x2e, 0x20, 0x20, - 0x53, 0x65, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x47, 0x4e, 0x55, 0x0a, 0x20, 0x2a, 0x20, 0x47, - 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x50, - 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, 0x4c, 0x69, - 0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x66, 0x6f, - 0x72, 0x20, 0x6d, 0x6f, 0x72, 0x65, 0x20, 0x64, - 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x2e, 0x0a, - 0x20, 0x2a, 0x0a, 0x20, 0x2a, 0x20, 0x59, 0x6f, - 0x75, 0x20, 0x73, 0x68, 0x6f, 0x75, 0x6c, 0x64, - 0x20, 0x68, 0x61, 0x76, 0x65, 0x20, 0x72, 0x65, - 0x63, 0x65, 0x69, 0x76, 0x65, 0x64, 0x20, 0x61, - 0x20, 0x63, 0x6f, 0x70, 0x79, 0x20, 0x6f, 0x66, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x47, 0x4e, 0x55, - 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, - 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, - 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x0a, - 0x20, 0x2a, 0x20, 0x61, 0x6c, 0x6f, 0x6e, 0x67, - 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68, - 0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72, - 0x61, 0x6d, 0x3b, 0x20, 0x73, 0x65, 0x65, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65, - 0x20, 0x43, 0x4f, 0x50, 0x59, 0x49, 0x4e, 0x47, - 0x2e, 0x20, 0x20, 0x49, 0x66, 0x20, 0x6e, 0x6f, - 0x74, 0x2c, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, - 0x20, 0x74, 0x6f, 0x0a, 0x20, 0x2a, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x46, 0x72, 0x65, 0x65, 0x20, - 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, - 0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x35, 0x31, 0x20, - 0x46, 0x72, 0x61, 0x6e, 0x6b, 0x6c, 0x69, 0x6e, - 0x20, 0x53, 0x74, 0x72, 0x65, 0x65, 0x74, 0x2c, - 0x20, 0x46, 0x69, 0x66, 0x74, 0x68, 0x20, 0x46, - 0x6c, 0x6f, 0x6f, 0x72, 0x2c, 0x0a, 0x20, 0x2a, - 0x20, 0x42, 0x6f, 0x73, 0x74, 0x6f, 0x6e, 0x2c, - 0x20, 0x4d, 0x41, 0x20, 0x30, 0x32, 0x31, 0x31, - 0x30, 0x2d, 0x31, 0x33, 0x30, 0x31, 0x2c, 0x20, - 0x55, 0x53, 0x41, 0x2e, 0x0a, 0x20, 0x2a, 0x2f, - 0x0a, -}; - -static object_data some = { - some_bytes, - sizeof(some_bytes), - "fd8430bc864cfcd5f10e5590f8a447e01b942bfe", - "blob", - "test-objects/fd", - "test-objects/fd/8430bc864cfcd5f10e5590f8a447e01b942bfe", - some_data, - sizeof(some_data), -}; diff --git a/tests-clay/odb/pack_data.h b/tests-clay/odb/pack_data.h deleted file mode 100644 index e6371beb1..000000000 --- a/tests-clay/odb/pack_data.h +++ /dev/null @@ -1,151 +0,0 @@ - -static const char *packed_objects[] = { - "0266163a49e280c4f5ed1e08facd36a2bd716bcf", - "53fc32d17276939fc79ed05badaef2db09990016", - "6336846bd5c88d32f93ae57d846683e61ab5c530", - "6dcf9bf7541ee10456529833502442f385010c3d", - "bed08a0b30b72a9d4aed7f1af8c8ca124e8d64b9", - "e90810b8df3e80c413d903f631643c716887138d", - "fc3c3a2083e9f6f89e6bd53e9420e70d1e357c9b", - "fc58168adf502d0c0ef614c3111a7038fc8c09c8", - "fd0ec0333948dfe23265ac46be0205a436a8c3a5", - "fd8430bc864cfcd5f10e5590f8a447e01b942bfe", - "fd899f45951c15c1c5f7c34b1c864e91bd6556c6", - "fda23b974899e7e1f938619099280bfda13bdca9", - "fdbec189efb657c8325962b494875987881a356b", - "fe1ca6bd22b5d8353ce6c2f3aba80805c438a7a5", - "fe3a6a42c87ff1239370c741a265f3997add87c1", - "deb106bfd2d36ecf9f0079224c12022201a39ad1", - "dec93efc79e60f2680de3e666755d335967eec30", - "def425bf8568b9c1e20879bf5be6f9c52b7361c4", - "df48000ac4f48570054e3a71a81916357997b680", - "dfae6ed8f6dd8acc3b40a31811ea316239223559", - "dff79e27d3d2cdc09790ded80fe2ea8ff5d61034", - "e00e46abe4c542e17c8bc83d72cf5be8018d7b0e", - "e01b107b4f77f8f98645adac0206a504f2d29d7c", - "e032d863f512c47b479bd984f8b6c8061f66b7d4", - "e044baa468a1c74f9f9da36805445f6888358b49", - "e04529998989ba8ae3419538dd57969af819b241", - "e0637ddfbea67c8d7f557c709e095af8906e9176", - "e0743ad4031231e71700abdc6fdbe94f189d20e5", - "cf33ac7a3d8b2b8f6bb266518aadbf59de397608", - "cf5f7235b9c9689b133f6ea12015720b411329bd", - "cf6cccf1297284833a9a03138a1f5738fa1c6c94", - "cf7992bde17ce7a79cab5f0c1fcbe8a0108721ed", - "cfe3a027ab12506d4144ee8a35669ae8fc4b7ab1", - "cfe96f31dfad7bab49977aa1df7302f7fafcb025", - "cff54d138945ef4de384e9d2759291d0c13ea90a", - "d01f7573ac34c2f502bd1cf18cde73480c741151", - "d03f567593f346a1ca96a57f8191def098d126e3", - "d047b47aadf88501238f36f5c17dd0a50dc62087", - "d0a0d63086fae3b0682af7261df21f7d0f7f066d", - "d0a44bd6ed0be21b725a96c0891bbc79bc1a540c", - "d0d7e736e536a41bcb885005f8bf258c61cad682", - "d0e7959d4b95ffec6198df6f5a7ae259b23a5f50", - "bf2fe2acca17d13356ce802ba9dc8343f710dfb7", - "bf55f407d6d9418e51f42ea7a3a6aadf17388349", - "bf92206f8b633b88a66dca4a911777630b06fbac", - "bfaf8c42eb8842abe206179fee864cfba87e3ca9", - "bfe05675d4e8f6b59d50932add8790f1a06b10ee", - "bff8618112330763327cfa6ce6e914db84f51ddf", - "bff873e9853ed99fed52c25f7ad29f78b27dcec2", - "c01c3fae7251098d7af1b459bcd0786e81d4616d", - "c0220fca67f48b8a5d4163d53b1486224be3a198", - "c02d0b160b82ee72469c269f13de4c26a7ea09cb", - "c059510ad1b45ab58390e042d7dee1ac46703854", - "c07204a1897aeeaa3c248d29dbfa9b033baf9755", - "c073337a4dd7276931b4b3fdbc3f0040e9441793", - "0fd7e4bfba5b3a82be88d1057757ca8b2c5e6d26", - "100746511cc45c9f1ad6721c4ef5be49222fee4d", - "1088490171d9b984d68b8b9be9ca003f4eafff59", - "1093c8ff4cb78fcf5f79dbbeedcb6e824bd4e253", - "10aa3fa72afab7ee31e116ae06442fe0f7b79df2", - "10b759e734e8299aa0dca08be935d95d886127b6", - "111d5ccf0bb010c4e8d7af3eedfa12ef4c5e265b", - "11261fbff21758444d426356ff6327ee01e90752", - "112998d425717bb922ce74e8f6f0f831d8dc4510", - "2ef4e5d838b6507bd61d457cf6466662b791c5c0", - "2ef4faa0f82efa00eeac6cae9e8b2abccc8566ee", - "2f06098183b0d7be350acbe39cdbaccff2df0c4a", - "2f1c5d509ac5bffb3c62f710a1c2c542e126dfd1", - "2f205b20fc16423c42b3ba51b2ea78d7b9ff3578", - "2f9b6b6e3d9250ba09360734aa47973a993b59d1", - "30c62a2d5a8d644f1311d4f7fe3f6a788e4c8188", - "31438e245492d85fd6da4d1406eba0fbde8332a4", - "3184a3abdfea231992254929ff4e275898e5bbf6", - "3188ffdbb3a3d52e0f78f30c484533899224436e", - "32581d0093429770d044a60eb0e9cc0462bedb13", - "32679a9544d83e5403202c4d5efb61ad02492847", - "4e7e9f60b7e2049b7f5697daf133161a18ef688f", - "4e8cda27ddc8be7db875ceb0f360c37734724c6d", - "4ea481c61c59ab55169b7cbaae536ad50b49d6f0", - "4f0adcd0e61eabe06fe32be66b16559537124b7a", - "4f1355c91100d12f9e7202f91b245df0c110867c", - "4f6eadeb08b9d0d1e8b1b3eac8a34940adf29a2d", - "4f9339df943c53117a5fc8e86e2f38716ff3a668", - "4fc3874b118752e40de556b1c3e7b4a9f1737d00", - "4ff1dd0992dd6baafdb5e166be6f9f23b59bdf87", - "5018a35e0b7e2eec7ce5050baf9c7343f3f74164", - "50298f44a45eda3a29dae82dbe911b5aa176ac07", - "502acd164fb115768d723144da2e7bb5a24891bb", - "50330c02bd4fd95c9db1fcf2f97f4218e42b7226", - "5052bf355d9f8c52446561a39733a8767bf31e37", - "6f2cd729ae42988c1dd43588d3a6661ba48ad7a0", - "6f4e2c42d9138bfbf3e0f908f1308828cc6f2178", - "6f6a17db05a83620cef4572761831c20a70ba9b9", - "6faad60901e36538634f0d8b8ff3f21f83503c71", - "6fc72e46de3df0c3842dab302bbacf697a63abab", - "6fdccd49f442a7204399ca9b418f017322dbded8", - "6fe7568fc3861c334cb008fd85d57d9647249ef5", - "700f55d91d7b55665594676a4bada1f1457a0598", - "702bd70595a7b19afc48a1f784a6505be68469d4", - "7033f9ee0e52b08cb5679cd49b7b7999eaf9eaf8", - "70957110ce446c4e250f865760fb3da513cdcc92", - "8ec696a4734f16479d091bc70574d23dd9fe7443", - "8ed341c55ed4d6f4cdc8bf4f0ca18a08c93f6962", - "8edc2805f1f11b63e44bf81f4557f8b473612b69", - "8ef9060a954118a698fc10e20acdc430566a100f", - "8f0c4b543f4bb6eb1518ecfc3d4699e43108d393", - "8fac94df3035405c2e60b3799153ce7c428af6b9", - "904c0ac12b23548de524adae712241b423d765a3", - "90bbaa9a809c3a768d873a9cc7d52b4f3bf3d1b9", - "90d4d2f0fc362beabbbf76b4ffda0828229c198d", - "90f9ff6755330b685feff6c3d81782ee3592ab04", - "91822c50ebe4f9bf5bbb8308ecf9f6557062775c", - "91d973263a55708fa8255867b3202d81ef9c2868", - "af292c99c6148d772af3315a1c74e83330e7ead7", - "af3b99d5be330dbbce0b9250c3a5fb05911908cc", - "af55d0cdeb280af2db8697e5afa506e081012719", - "af795e498d411142ddb073e8ca2c5447c3295a4c", - "afadc73a392f8cc8e2cc77dd62a7433dd3bafa8c", - "affd84ed8ec7ce67612fe3c12a80f8164b101f6a", - "b0941f9c70ffe67f0387a827b338e64ecf3190f0", - "b0a3077f9ef6e093f8d9869bdb0c07095bd722cb", - "b0a8568a7614806378a54db5706ee3b06ae58693", - "b0fb7372f242233d1d35ce7d8e74d3990cbc5841", - "b10489944b9ead17427551759d180d10203e06ba", - "b196a807b323f2748ffc6b1d42cd0812d04c9a40", - "b1bb1d888f0c5e19278536d49fa77db035fac7ae" -}; - -static const char *loose_objects[] = { - "45b983be36b73c0788dc9cbcb76cbb80fc7bb057", - "a8233120f6ad708f843d861ce2b7228ec4e3dec6", - "fd093bff70906175335656e6ce6ae05783708765", - "c47800c7266a2be04c571c04d5a6614691ea99bd", - "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd", - "8496071c1b46c854b31185ea97743be6a8774479", - "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", - "814889a078c031f61ed08ab5fa863aea9314344d", - "5b5b025afb0b4c913b4c338a42934a3863bf3644", - "1385f264afb75a56a5bec74243be9b367ba4ca08", - "f60079018b664e4e79329a7ef9559c8d9e0378d1", - "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", - "75057dd4114e74cca1d750d0aee1647c903cb60a", - "fa49b077972391ad58037050f2a75f74e3671e92", - "9fd738e8f7967c078dceed8190330fc8648ee56a", - "1810dff58d8a660512d4832e740f692884338ccd", - "181037049a54a1eb5fab404658a3a250b44335d7", - "a4a7dce85cf63874e984719f4fdd239f5145052f", - "4a202b346bb0fb0db7eff3cffeb3c70babbd2045" -}; diff --git a/tests-clay/odb/packed.c b/tests-clay/odb/packed.c deleted file mode 100644 index 4e9918d3e..000000000 --- a/tests-clay/odb/packed.c +++ /dev/null @@ -1,78 +0,0 @@ -#include "clay_libgit2.h" -#include "odb.h" -#include "pack_data.h" - -static git_odb *_odb; - -void test_odb_packed__initialize(void) -{ - cl_git_pass(git_odb_open(&_odb, cl_fixture("testrepo.git/objects"))); -} - -void test_odb_packed__cleanup(void) -{ - git_odb_free(_odb); -} - -void test_odb_packed__mass_read(void) -{ - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(packed_objects); ++i) { - git_oid id; - git_odb_object *obj; - - cl_git_pass(git_oid_fromstr(&id, packed_objects[i])); - cl_assert(git_odb_exists(_odb, &id) == 1); - cl_git_pass(git_odb_read(&obj, _odb, &id)); - - git_odb_object_free(obj); - } -} - -void test_odb_packed__read_header_0(void) -{ - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(packed_objects); ++i) { - git_oid id; - git_odb_object *obj; - size_t len; - git_otype type; - - cl_git_pass(git_oid_fromstr(&id, packed_objects[i])); - - cl_git_pass(git_odb_read(&obj, _odb, &id)); - cl_git_pass(git_odb_read_header(&len, &type, _odb, &id)); - - cl_assert(obj->raw.len == len); - cl_assert(obj->raw.type == type); - - git_odb_object_free(obj); - } -} - -void test_odb_packed__read_header_1(void) -{ - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(loose_objects); ++i) { - git_oid id; - git_odb_object *obj; - size_t len; - git_otype type; - - cl_git_pass(git_oid_fromstr(&id, loose_objects[i])); - - cl_assert(git_odb_exists(_odb, &id) == 1); - - cl_git_pass(git_odb_read(&obj, _odb, &id)); - cl_git_pass(git_odb_read_header(&len, &type, _odb, &id)); - - cl_assert(obj->raw.len == len); - cl_assert(obj->raw.type == type); - - git_odb_object_free(obj); - } -} - diff --git a/tests-clay/odb/sorting.c b/tests-clay/odb/sorting.c deleted file mode 100644 index 779660707..000000000 --- a/tests-clay/odb/sorting.c +++ /dev/null @@ -1,71 +0,0 @@ -#include "clay_libgit2.h" -#include "git2/odb_backend.h" -#include "odb.h" - -typedef struct { - git_odb_backend base; - int position; -} fake_backend; - -static git_odb_backend *new_backend(int position) -{ - fake_backend *b; - - b = git__malloc(sizeof(fake_backend)); - if (b == NULL) - return NULL; - - memset(b, 0x0, sizeof(fake_backend)); - b->position = position; - return (git_odb_backend *)b; -} - -static void check_backend_sorting(git_odb *odb) -{ - unsigned int i; - - for (i = 0; i < odb->backends.length; ++i) { - fake_backend *internal = - *((fake_backend **)git_vector_get(&odb->backends, i)); - - cl_assert(internal != NULL); - cl_assert(internal->position == (int)i); - } -} - -static git_odb *_odb; - -void test_odb_sorting__initialize(void) -{ - cl_git_pass(git_odb_new(&_odb)); -} - -void test_odb_sorting__cleanup(void) -{ - git_odb_free(_odb); - _odb = NULL; -} - -void test_odb_sorting__basic_backends_sorting(void) -{ - cl_git_pass(git_odb_add_backend(_odb, new_backend(0), 5)); - cl_git_pass(git_odb_add_backend(_odb, new_backend(2), 3)); - cl_git_pass(git_odb_add_backend(_odb, new_backend(1), 4)); - cl_git_pass(git_odb_add_backend(_odb, new_backend(3), 1)); - - check_backend_sorting(_odb); -} - -void test_odb_sorting__alternate_backends_sorting(void) -{ - cl_git_pass(git_odb_add_backend(_odb, new_backend(0), 5)); - cl_git_pass(git_odb_add_backend(_odb, new_backend(2), 3)); - cl_git_pass(git_odb_add_backend(_odb, new_backend(1), 4)); - cl_git_pass(git_odb_add_backend(_odb, new_backend(3), 1)); - cl_git_pass(git_odb_add_alternate(_odb, new_backend(4), 5)); - cl_git_pass(git_odb_add_alternate(_odb, new_backend(6), 3)); - cl_git_pass(git_odb_add_alternate(_odb, new_backend(5), 4)); - cl_git_pass(git_odb_add_alternate(_odb, new_backend(7), 1)); - - check_backend_sorting(_odb); -} diff --git a/tests-clay/refs/crashes.c b/tests-clay/refs/crashes.c deleted file mode 100644 index 339d4f8e1..000000000 --- a/tests-clay/refs/crashes.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "clay_libgit2.h" - -void test_refs_crashes__double_free(void) -{ - git_repository *repo; - git_reference *ref, *ref2; - const char *REFNAME = "refs/heads/xxx"; - - cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git"))); - cl_git_pass(git_reference_create_symbolic(&ref, repo, REFNAME, "refs/heads/master", 0)); - cl_git_pass(git_reference_lookup(&ref2, repo, REFNAME)); - cl_git_pass(git_reference_delete(ref)); - /* reference is gone from disk, so reloading it will fail */ - cl_must_fail(git_reference_reload(ref2)); - - git_repository_free(repo); -} diff --git a/tests-clay/repo/getters.c b/tests-clay/repo/getters.c deleted file mode 100644 index 426b83e54..000000000 --- a/tests-clay/repo/getters.c +++ /dev/null @@ -1,70 +0,0 @@ -#include "clay_libgit2.h" - -void test_repo_getters__initialize(void) -{ - cl_fixture_sandbox("testrepo.git"); -} - -void test_repo_getters__cleanup(void) -{ - cl_fixture_cleanup("testrepo.git"); -} - -void test_repo_getters__empty(void) -{ - git_repository *repo_empty, *repo_normal; - - cl_git_pass(git_repository_open(&repo_normal, cl_fixture("testrepo.git"))); - cl_assert(git_repository_is_empty(repo_normal) == 0); - git_repository_free(repo_normal); - - cl_git_pass(git_repository_open(&repo_empty, cl_fixture("empty_bare.git"))); - cl_assert(git_repository_is_empty(repo_empty) == 1); - git_repository_free(repo_empty); -} - -void test_repo_getters__head_detached(void) -{ - git_repository *repo; - git_reference *ref; - git_oid oid; - - cl_git_pass(git_repository_open(&repo, "testrepo.git")); - - cl_assert(git_repository_head_detached(repo) == 0); - - /* detach the HEAD */ - git_oid_fromstr(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd"); - cl_git_pass(git_reference_create_oid(&ref, repo, "HEAD", &oid, 1)); - cl_assert(git_repository_head_detached(repo) == 1); - git_reference_free(ref); - - /* take the reop back to it's original state */ - cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/master", 1)); - cl_assert(git_repository_head_detached(repo) == 0); - - git_reference_free(ref); - git_repository_free(repo); -} - -void test_repo_getters__head_orphan(void) -{ - git_repository *repo; - git_reference *ref; - - cl_git_pass(git_repository_open(&repo, "testrepo.git")); - - cl_assert(git_repository_head_orphan(repo) == 0); - - /* orphan HEAD */ - cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/orphan", 1)); - cl_assert(git_repository_head_orphan(repo) == 1); - git_reference_free(ref); - - /* take the reop back to it's original state */ - cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/master", 1)); - cl_assert(git_repository_head_orphan(repo) == 0); - - git_reference_free(ref); - git_repository_free(repo); -} diff --git a/tests-clay/repo/init.c b/tests-clay/repo/init.c deleted file mode 100644 index e235ffaeb..000000000 --- a/tests-clay/repo/init.c +++ /dev/null @@ -1,106 +0,0 @@ -#include "clay_libgit2.h" -#include "fileops.h" - -enum repo_mode { - STANDARD_REPOSITORY = 0, - BARE_REPOSITORY = 1 -}; - -static git_repository *_repo; - -void test_repo_init__initialize(void) -{ - _repo = NULL; -} - -static void cleanup_repository(void *path) -{ - git_repository_free(_repo); - cl_fixture_cleanup((const char *)path); -} - -static void ensure_repository_init( - const char *working_directory, - int is_bare, - const char *expected_path_repository, - const char *expected_working_directory) -{ - const char *workdir; - - cl_git_pass(git_repository_init(&_repo, working_directory, is_bare)); - - workdir = git_repository_workdir(_repo); - if (workdir != NULL || expected_working_directory != NULL) { - cl_assert( - git__suffixcmp(workdir, expected_working_directory) == 0 - ); - } - - cl_assert( - git__suffixcmp(git_repository_path(_repo), expected_path_repository) == 0 - ); - - cl_assert(git_repository_is_bare(_repo) == is_bare); - -#ifdef GIT_WIN32 - if (!is_bare) { - cl_assert((GetFileAttributes(git_repository_path(_repo)) & FILE_ATTRIBUTE_HIDDEN) != 0); - } -#endif - - cl_assert(git_repository_is_empty(_repo)); -} - -void test_repo_init__standard_repo(void) -{ - cl_set_cleanup(&cleanup_repository, "testrepo"); - ensure_repository_init("testrepo/", 0, "testrepo/.git/", "testrepo/"); -} - -void test_repo_init__standard_repo_noslash(void) -{ - cl_set_cleanup(&cleanup_repository, "testrepo"); - ensure_repository_init("testrepo", 0, "testrepo/.git/", "testrepo/"); -} - -void test_repo_init__bare_repo(void) -{ - cl_set_cleanup(&cleanup_repository, "testrepo.git"); - ensure_repository_init("testrepo.git/", 1, "testrepo.git/", NULL); -} - -void test_repo_init__bare_repo_noslash(void) -{ - cl_set_cleanup(&cleanup_repository, "testrepo.git"); - ensure_repository_init("testrepo.git", 1, "testrepo.git/", NULL); -} - -#if 0 -BEGIN_TEST(init2, "Initialize and open a bare repo with a relative path escaping out of the current working directory") - git_buf path_repository = GIT_BUF_INIT; - char current_workdir[GIT_PATH_MAX]; - const mode_t mode = 0777; - git_repository* repo; - - must_pass(p_getcwd(current_workdir, sizeof(current_workdir))); - - must_pass(git_buf_joinpath(&path_repository, TEMP_REPO_FOLDER, "a/b/c/")); - must_pass(git_futils_mkdir_r(path_repository.ptr, mode)); - - must_pass(chdir(path_repository.ptr)); - - git_buf_free(&path_repository); - - must_pass(git_repository_init(&repo, "../d/e.git", 1)); - must_pass(git__suffixcmp(git_repository_path(_repo), "/a/b/d/e.git/")); - - git_repository_free(repo); - - must_pass(git_repository_open(&repo, "../d/e.git")); - - git_repository_free(repo); - - must_pass(chdir(current_workdir)); - must_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, 1)); -END_TEST -#endif diff --git a/tests-clay/repo/open.c b/tests-clay/repo/open.c deleted file mode 100644 index 05b01ceb2..000000000 --- a/tests-clay/repo/open.c +++ /dev/null @@ -1,55 +0,0 @@ -#include "clay_libgit2.h" -#include "posix.h" - -void test_repo_open__bare_empty_repo(void) -{ - git_repository *repo; - - cl_git_pass(git_repository_open(&repo, cl_fixture("empty_bare.git"))); - cl_assert(git_repository_path(repo) != NULL); - cl_assert(git_repository_workdir(repo) == NULL); - - git_repository_free(repo); -} - -void test_repo_open__standard_empty_repo(void) -{ - git_repository *repo; - - cl_git_pass(git_repository_open(&repo, cl_fixture("empty_standard_repo/.gitted"))); - cl_assert(git_repository_path(repo) != NULL); - cl_assert(git_repository_workdir(repo) != NULL); - - git_repository_free(repo); -} - -/* TODO TODO */ -#if 0 -BEGIN_TEST(open2, "Open a bare repository with a relative path escaping out of the current working directory") - char current_workdir[GIT_PATH_MAX]; - git_buf new_current_workdir = GIT_BUF_INIT; - git_buf path_repository = GIT_BUF_INIT; - - const mode_t mode = 0777; - git_repository* repo; - - /* Setup the repository to open */ - must_pass(p_getcwd(current_workdir, sizeof(current_workdir))); - must_pass(git_buf_join_n(&path_repository, 3, current_workdir, TEMP_REPO_FOLDER, "a/d/e.git")); - must_pass(copydir_recurs(REPOSITORY_FOLDER, path_repository.ptr)); - git_buf_free(&path_repository); - - /* Change the current working directory */ - must_pass(git_buf_joinpath(&new_current_workdir, TEMP_REPO_FOLDER, "a/b/c/")); - must_pass(git_futils_mkdir_r(new_current_workdir.ptr, mode)); - must_pass(chdir(new_current_workdir.ptr)); - git_buf_free(&new_current_workdir); - - must_pass(git_repository_open(&repo, "../../d/e.git")); - - git_repository_free(repo); - - must_pass(chdir(current_workdir)); - must_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, 1)); -END_TEST -#endif diff --git a/tests-clay/status/ignore.c b/tests-clay/status/ignore.c deleted file mode 100644 index f14e10c8e..000000000 --- a/tests-clay/status/ignore.c +++ /dev/null @@ -1,49 +0,0 @@ -#include "clay_libgit2.h" -#include "fileops.h" -#include "git2/attr.h" - -static git_repository *g_repo = NULL; - -void test_status_ignore__initialize(void) -{ - /* Before each test, instantiate the attr repo from the fixtures and - * rename the .gitted to .git so it is a repo with a working dir. Also - * rename gitignore to .gitignore. - */ - cl_fixture_sandbox("attr"); - cl_git_pass(p_rename("attr/.gitted", "attr/.git")); - cl_git_pass(p_rename("attr/gitignore", "attr/.gitignore")); - cl_git_pass(git_repository_open(&g_repo, "attr/.git")); -} - -void test_status_ignore__cleanup(void) -{ - git_repository_free(g_repo); - g_repo = NULL; - cl_fixture_cleanup("attr"); -} - -void test_status_ignore__0(void) -{ - struct { - const char *path; - int expected; - } test_cases[] = { - { "file", 0 }, - { "ign", 1 }, - { "sub", 1 }, - { "sub/file", 0 }, - { "sub/ign", 1 }, - { "sub/sub", 1 }, - { "sub/sub/file", 0 }, - { "sub/sub/ign", 1 }, - { "sub/sub/sub", 1 }, - { NULL, 0 } - }, *one_test; - - for (one_test = test_cases; one_test->path != NULL; one_test++) { - int ignored; - cl_git_pass(git_status_should_ignore(g_repo, one_test->path, &ignored)); - cl_assert_(ignored == one_test->expected, one_test->path); - } -} diff --git a/tests-clay/status/single.c b/tests-clay/status/single.c deleted file mode 100644 index c290bddff..000000000 --- a/tests-clay/status/single.c +++ /dev/null @@ -1,29 +0,0 @@ -#include "clay_libgit2.h" -#include "posix.h" - -static void -cleanup__remove_file(void *_file) -{ - cl_must_pass(p_unlink((char *)_file)); -} - -/* test retrieving OID from a file apart from the ODB */ -void test_status_single__hash_single_file(void) -{ - static const char file_name[] = "new_file"; - static const char file_contents[] = "new_file\n"; - static const char file_hash[] = "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a"; - - git_oid expected_id, actual_id; - - /* initialization */ - git_oid_fromstr(&expected_id, file_hash); - cl_git_mkfile(file_name, file_contents); - cl_set_cleanup(&cleanup__remove_file, (void *)file_name); - - cl_git_pass(git_odb_hashfile(&actual_id, file_name, GIT_OBJ_BLOB)); - cl_assert(git_oid_cmp(&expected_id, &actual_id) == 0); -} - - - diff --git a/tests-clay/status/status_data.h b/tests-clay/status/status_data.h deleted file mode 100644 index 1a68648f4..000000000 --- a/tests-clay/status/status_data.h +++ /dev/null @@ -1,50 +0,0 @@ - -struct status_entry_counts { - int wrong_status_flags_count; - int wrong_sorted_path; - int entry_count; - const unsigned int* expected_statuses; - const char** expected_paths; - int expected_entry_count; -}; - -static const char *entry_paths0[] = { - "file_deleted", - "ignored_file", - "modified_file", - "new_file", - "staged_changes", - "staged_changes_file_deleted", - "staged_changes_modified_file", - "staged_delete_file_deleted", - "staged_delete_modified_file", - "staged_new_file", - "staged_new_file_deleted_file", - "staged_new_file_modified_file", - - "subdir/deleted_file", - "subdir/modified_file", - "subdir/new_file", -}; - -static const unsigned int entry_statuses0[] = { - GIT_STATUS_WT_DELETED, - GIT_STATUS_IGNORED, - GIT_STATUS_WT_MODIFIED, - GIT_STATUS_WT_NEW, - GIT_STATUS_INDEX_MODIFIED, - GIT_STATUS_INDEX_MODIFIED | GIT_STATUS_WT_DELETED, - GIT_STATUS_INDEX_MODIFIED | GIT_STATUS_WT_MODIFIED, - GIT_STATUS_INDEX_DELETED, - GIT_STATUS_INDEX_DELETED | GIT_STATUS_WT_NEW, - GIT_STATUS_INDEX_NEW, - GIT_STATUS_INDEX_NEW | GIT_STATUS_WT_DELETED, - GIT_STATUS_INDEX_NEW | GIT_STATUS_WT_MODIFIED, - - GIT_STATUS_WT_DELETED, - GIT_STATUS_WT_MODIFIED, - GIT_STATUS_WT_NEW, -}; - -static const size_t entry_count0 = 15; - diff --git a/tests-clay/status/worktree.c b/tests-clay/status/worktree.c deleted file mode 100644 index 2183649f2..000000000 --- a/tests-clay/status/worktree.c +++ /dev/null @@ -1,154 +0,0 @@ -#include "clay_libgit2.h" -#include "fileops.h" -#include "ignore.h" -#include "status_data.h" - - -/** - * Test fixtures - */ -static git_repository *_repository = NULL; - - -/** - * Auxiliary methods - */ -static int -cb_status__normal( const char *path, unsigned int status_flags, void *payload) -{ - struct status_entry_counts *counts = payload; - - if (counts->entry_count >= counts->expected_entry_count) { - counts->wrong_status_flags_count++; - goto exit; - } - - if (strcmp(path, counts->expected_paths[counts->entry_count])) { - counts->wrong_sorted_path++; - goto exit; - } - - if (status_flags != counts->expected_statuses[counts->entry_count]) - counts->wrong_status_flags_count++; - -exit: - counts->entry_count++; - return GIT_SUCCESS; -} - -static int -cb_status__count(const char *GIT_UNUSED(p), unsigned int GIT_UNUSED(s), void *payload) -{ - volatile int *count = (int *)payload; - - GIT_UNUSED_ARG(p); - GIT_UNUSED_ARG(s); - - *count++; - - return GIT_SUCCESS; -} - - - -/** - * Initializer - * - * This method is called once before starting each - * test, and will load the required fixtures - */ -void test_status_worktree__initialize(void) -{ - /* - * Sandbox the `status/` repository from our Fixtures. - * This will copy the whole folder to our sandbox, - * so now it can be accessed with `./status` - */ - cl_fixture_sandbox("status"); - - /* - * Rename `status/.gitted` to `status/.git` - * We do this because we cannot store a folder named `.git` - * inside the fixtures folder in our libgit2 repo. - */ - cl_git_pass( - p_rename("status/.gitted", "status/.git") - ); - - /* - * Open the sandboxed "status" repository - */ - cl_git_pass(git_repository_open(&_repository, "status/.git")); -} - -/** - * Cleanup - * - * This will be called once after each test finishes, even - * if the test failed - */ -void test_status_worktree__cleanup(void) -{ - git_repository_free(_repository); - _repository = NULL; - - cl_fixture_cleanup("status"); -} - -/** - * Tests - Status determination on a working tree - */ -void test_status_worktree__whole_repository(void) -{ - struct status_entry_counts counts; - - memset(&counts, 0x0, sizeof(struct status_entry_counts)); - counts.expected_entry_count = entry_count0; - counts.expected_paths = entry_paths0; - counts.expected_statuses = entry_statuses0; - - cl_git_pass( - git_status_foreach(_repository, cb_status__normal, &counts) - ); - - cl_assert(counts.entry_count == counts.expected_entry_count); - cl_assert(counts.wrong_status_flags_count == 0); - cl_assert(counts.wrong_sorted_path == 0); -} - -void test_status_worktree__empty_repository(void) -{ - int count = 0; - - git_status_foreach(_repository, cb_status__count, &count); - cl_assert(count == 0); -} - -void test_status_worktree__single_file(void) -{ - int i; - unsigned int status_flags; - - for (i = 0; i < (int)entry_count0; i++) { - cl_git_pass( - git_status_file(&status_flags, _repository, entry_paths0[i]) - ); - cl_assert(entry_statuses0[i] == status_flags); - } -} - -void test_status_worktree__ignores(void) -{ - int i, ignored; - - for (i = 0; i < (int)entry_count0; i++) { - cl_git_pass(git_status_should_ignore(_repository, entry_paths0[i], &ignored)); - cl_assert(ignored == (entry_statuses0[i] == GIT_STATUS_IGNORED)); - } - - cl_git_pass(git_status_should_ignore(_repository, "nonexistent_file", &ignored)); - cl_assert(!ignored); - - cl_git_pass(git_status_should_ignore(_repository, "ignored_nonexistent_file", &ignored)); - cl_assert(ignored); -} |