summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/commit/parse.c76
-rw-r--r--tests/object/raw/type2string.c22
-rw-r--r--tests/odb/loose.c2
3 files changed, 57 insertions, 43 deletions
diff --git a/tests/commit/parse.c b/tests/commit/parse.c
index 41e162440..00e763d9c 100644
--- a/tests/commit/parse.c
+++ b/tests/commit/parse.c
@@ -22,50 +22,62 @@ typedef struct {
} parse_test_case;
static parse_test_case passing_header_cases[] = {
- { "parent 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "parent " },
- { "tree 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree " },
- { "random_heading 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "random_heading " },
- { "stuck_heading05452d6349abcd67aa396dfb28660d765d8b2a36\n", "stuck_heading" },
- { "tree 5F4BEFFC0759261D015AA63A3A85613FF2F235DE\n", "tree " },
- { "tree 1A669B8AB81B5EB7D9DB69562D34952A38A9B504\n", "tree " },
- { "tree 5B20DCC6110FCC75D31C6CEDEBD7F43ECA65B503\n", "tree " },
- { "tree 173E7BF00EA5C33447E99E6C1255954A13026BE4\n", "tree " },
+ { "parent 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "parent" },
+ { "tree 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree" },
+ { "random_heading 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "random_heading" },
+ { "tree 5F4BEFFC0759261D015AA63A3A85613FF2F235DE\n", "tree" },
+ { "tree 1A669B8AB81B5EB7D9DB69562D34952A38A9B504\n", "tree" },
+ { "tree 5B20DCC6110FCC75D31C6CEDEBD7F43ECA65B503\n", "tree" },
+ { "tree 173E7BF00EA5C33447E99E6C1255954A13026BE4\n", "tree" },
{ NULL, NULL }
};
static parse_test_case failing_header_cases[] = {
- { "parent 05452d6349abcd67aa396dfb28660d765d8b2a36", "parent " },
- { "05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree " },
- { "parent05452d6349abcd67aa396dfb28660d765d8b2a6a\n", "parent " },
- { "parent 05452d6349abcd67aa396dfb280d765d8b2a6\n", "parent " },
- { "tree 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree " },
- { "parent 0545xd6349abcd67aa396dfb28660d765d8b2a36\n", "parent " },
- { "parent 0545xd6349abcd67aa396dfb28660d765d8b2a36FF\n", "parent " },
- { "", "tree " },
+ { "parent 05452d6349abcd67aa396dfb28660d765d8b2a36", "parent" },
+ { "05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree" },
+ { "parent05452d6349abcd67aa396dfb28660d765d8b2a6a\n", "parent" },
+ { "parent 05452d6349abcd67aa396dfb280d765d8b2a6\n", "parent" },
+ { "tree 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree" },
+ { "parent 0545xd6349abcd67aa396dfb28660d765d8b2a36\n", "parent" },
+ { "parent 0545xd6349abcd67aa396dfb28660d765d8b2a36FF\n", "parent" },
+ { "", "tree" },
{ "", "" },
+ { "stuck_heading05452d6349abcd67aa396dfb28660d765d8b2a36\n", "stuck_heading" },
{ NULL, NULL }
};
void test_commit_parse__header(void)
{
- git_oid oid;
+ git_oid oid, exp;
+ git_object_parse_t template[2] = {
+ { NULL, 0, GIT_PARSE_OID, { .id = &oid } },
+ { NULL, 0, GIT_PARSE_BODY_OPTIONAL },
+ };
+ parse_test_case *test;
- parse_test_case *testcase;
- for (testcase = passing_header_cases; testcase->line != NULL; testcase++)
- {
- const char *line = testcase->line;
+ for (test = passing_header_cases; test->line != NULL; test++) {
+ const char *line = test->line;
const char *line_end = line + strlen(line);
- cl_git_pass(git_oid__parse(&oid, &line, line_end, testcase->header));
- cl_assert(line == line_end);
+ template[0].tag = test->header;
+ template[0].taglen = strlen(test->header);
+
+ cl_git_pass(git_object__parse_lines(
+ GIT_OBJ_COMMIT, template, line, line_end));
+
+ cl_git_pass(git_oid_fromstr(&exp, line + strlen(test->header) + 1));
+ cl_assert(git_oid_equal(&exp, &oid));
}
- for (testcase = failing_header_cases; testcase->line != NULL; testcase++)
- {
- const char *line = testcase->line;
+ for (test = failing_header_cases; test->line != NULL; test++) {
+ const char *line = test->line;
const char *line_end = line + strlen(line);
- cl_git_fail(git_oid__parse(&oid, &line, line_end, testcase->header));
+ template[0].tag = test->header;
+ template[0].taglen = strlen(test->header);
+
+ cl_git_fail(git_object__parse_lines(
+ GIT_OBJ_COMMIT, template, line, line_end));
}
}
@@ -152,12 +164,13 @@ void test_commit_parse__signature(void)
size_t len = strlen(passcase->string);
struct git_signature person = {0};
- cl_git_pass(git_signature__parse(&person, &str, str + len, passcase->header, '\n'));
+ cl_git_pass(git_signature__parse(
+ &person, &str, str + len, passcase->header, '\n'));
cl_assert_equal_s(passcase->name, person.name);
cl_assert_equal_s(passcase->email, person.email);
cl_assert_equal_i((int)passcase->time, (int)person.when.time);
cl_assert_equal_i(passcase->offset, person.when.offset);
- git__free(person.name); git__free(person.email);
+ git_signature__clear(&person);
}
for (failcase = failing_signature_cases; failcase->string != NULL; failcase++)
@@ -165,8 +178,9 @@ void test_commit_parse__signature(void)
const char *str = failcase->string;
size_t len = strlen(failcase->string);
git_signature person = {0};
- cl_git_fail(git_signature__parse(&person, &str, str + len, failcase->header, '\n'));
- git__free(person.name); git__free(person.email);
+ cl_git_fail(git_signature__parse(
+ &person, &str, str + len, failcase->header, '\n'));
+ git_signature__clear(&person);
}
}
diff --git a/tests/object/raw/type2string.c b/tests/object/raw/type2string.c
index a3585487f..45045a062 100644
--- a/tests/object/raw/type2string.c
+++ b/tests/object/raw/type2string.c
@@ -23,17 +23,17 @@ void test_object_raw_type2string__convert_type_to_string(void)
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);
+ cl_assert(git_object_string2type(NULL, 0) == GIT_OBJ_BAD);
+ cl_assert(git_object_string2type("", 0) == GIT_OBJ_BAD);
+ cl_assert(git_object_string2type("commit", 0) == GIT_OBJ_COMMIT);
+ cl_assert(git_object_string2type("tree", 0) == GIT_OBJ_TREE);
+ cl_assert(git_object_string2type("blob", 0) == GIT_OBJ_BLOB);
+ cl_assert(git_object_string2type("tag", 0) == GIT_OBJ_TAG);
+ cl_assert(git_object_string2type("OFS_DELTA", 0) == GIT_OBJ_OFS_DELTA);
+ cl_assert(git_object_string2type("REF_DELTA", 0) == GIT_OBJ_REF_DELTA);
+
+ cl_assert(git_object_string2type("CoMmIt", 0) == GIT_OBJ_BAD);
+ cl_assert(git_object_string2type("hohoho", 0) == GIT_OBJ_BAD);
}
void test_object_raw_type2string__check_type_is_loose(void)
diff --git a/tests/odb/loose.c b/tests/odb/loose.c
index c91927c4a..da5518990 100644
--- a/tests/odb/loose.c
+++ b/tests/odb/loose.c
@@ -24,7 +24,7 @@ static void write_object_files(object_data *d)
static void cmp_objects(git_rawobj *o, object_data *d)
{
- cl_assert(o->type == git_object_string2type(d->type));
+ cl_assert(o->type == git_object_string2type(d->type, 0));
cl_assert(o->len == d->dlen);
if (o->len > 0)