diff options
| author | Vicent Marti <tanoku@gmail.com> | 2010-12-18 02:35:45 +0200 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2010-12-18 02:35:45 +0200 |
| commit | b5ced41e85d4657376d3d6f53d8dc08ed3dcdacc (patch) | |
| tree | fdf9dace53aff8e531d162097fb76b5845df34d2 /tests | |
| parent | 1f080e2da4833004fd178f622271879336085e22 (diff) | |
| parent | 638c2ca4281589b73f2d402bb80775242045144a (diff) | |
| download | libgit2-b5ced41e85d4657376d3d6f53d8dc08ed3dcdacc.tar.gz | |
Merge branch 'timezone'
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/t0401-parse.c | 104 | ||||
| -rw-r--r-- | tests/t0402-details.c | 4 | ||||
| -rw-r--r-- | tests/t0403-write.c | 47 | ||||
| -rw-r--r-- | tests/t0502-list.c | 10 |
4 files changed, 97 insertions, 68 deletions
diff --git a/tests/t0401-parse.c b/tests/t0401-parse.c index b82a9b168..d734e5d23 100644 --- a/tests/t0401-parse.c +++ b/tests/t0401-parse.c @@ -1,7 +1,7 @@ #include "test_lib.h" #include "test_helpers.h" #include "commit.h" -#include "person.h" +#include "signature.h" #include <git2/odb.h> #include <git2/commit.h> #include <git2/revwalk.h> @@ -129,96 +129,134 @@ BEGIN_TEST(parse_oid_test) END_TEST -BEGIN_TEST(parse_person_test) +BEGIN_TEST(parse_sig_test) -#define TEST_PERSON_PASS(_string, _header, _name, _email, _time) { \ +#define TEST_SIGNATURE_PASS(_string, _header, _name, _email, _time, _offset) { \ char *ptr = _string; \ size_t len = strlen(_string);\ - git_person person = {NULL, NULL, 0}; \ - must_pass(git_person__parse(&person, &ptr, ptr + len, _header));\ + git_signature person = {NULL, NULL, {0, 0}}; \ + must_pass(git_signature__parse(&person, &ptr, ptr + len, _header));\ must_be_true(strcmp(_name, person.name) == 0);\ must_be_true(strcmp(_email, person.email) == 0);\ - must_be_true(_time == person.time);\ + must_be_true(_time == person.when.time);\ + must_be_true(_offset == person.when.offset);\ free(person.name); free(person.email);\ } -#define TEST_PERSON_FAIL(_string, _header) { \ +#define TEST_SIGNATURE_FAIL(_string, _header) { \ char *ptr = _string; \ size_t len = strlen(_string);\ - git_person person = {NULL, NULL, 0}; \ - must_fail(git_person__parse(&person, &ptr, ptr + len, _header));\ + git_signature person = {NULL, NULL, {0, 0}}; \ + must_fail(git_signature__parse(&person, &ptr, ptr + len, _header));\ free(person.name); free(person.email);\ } - TEST_PERSON_PASS( - "author Vicent Marti <tanoku@gmail.com> 12345 \n", - "author ", - "Vicent Marti", - "tanoku@gmail.com", - 12345); + TEST_SIGNATURE_PASS( + "author Vicent Marti <tanoku@gmail.com> 12345 \n", + "author ", + "Vicent Marti", + "tanoku@gmail.com", + 12345, + 0); - TEST_PERSON_PASS( + TEST_SIGNATURE_PASS( "author Vicent Marti <> 12345 \n", "author ", "Vicent Marti", "", - 12345); + 12345, + 0); - TEST_PERSON_PASS( - "author Vicent Marti <tanoku@gmail.com> 231301 +2020\n", + TEST_SIGNATURE_PASS( + "author Vicent Marti <tanoku@gmail.com> 231301 +1020\n", "author ", "Vicent Marti", "tanoku@gmail.com", - 231301); + 231301, + 620); - TEST_PERSON_PASS( + TEST_SIGNATURE_PASS( "author Vicent Marti with an outrageously long name \ which will probably overflow the buffer <tanoku@gmail.com> 12345 \n", "author ", "Vicent Marti with an outrageously long name \ which will probably overflow the buffer", "tanoku@gmail.com", - 12345); + 12345, + 0); - TEST_PERSON_PASS( + TEST_SIGNATURE_PASS( "author Vicent Marti <tanokuwithaveryveryverylongemail\ whichwillprobablyvoverflowtheemailbuffer@gmail.com> 12345 \n", "author ", "Vicent Marti", "tanokuwithaveryveryverylongemail\ whichwillprobablyvoverflowtheemailbuffer@gmail.com", - 12345); + 12345, + 0); + + TEST_SIGNATURE_PASS( + "committer Vicent Marti <tanoku@gmail.com> 123456 +0000 \n", + "committer ", + "Vicent Marti", + "tanoku@gmail.com", + 123456, + 0); + + TEST_SIGNATURE_PASS( + "committer Vicent Marti <tanoku@gmail.com> 123456 +0100 \n", + "committer ", + "Vicent Marti", + "tanoku@gmail.com", + 123456, + 60); + + TEST_SIGNATURE_PASS( + "committer Vicent Marti <tanoku@gmail.com> 123456 -0100 \n", + "committer ", + "Vicent Marti", + "tanoku@gmail.com", + 123456, + -60); + + TEST_SIGNATURE_FAIL( + "committer Vicent Marti <tanoku@gmail.com> 123456 -1500 \n", + "committer "); + + TEST_SIGNATURE_FAIL( + "committer Vicent Marti <tanoku@gmail.com> 123456 +0163 \n", + "committer "); - TEST_PERSON_FAIL( + TEST_SIGNATURE_FAIL( "author Vicent Marti <tanoku@gmail.com> 12345 \n", "author "); - TEST_PERSON_FAIL( + TEST_SIGNATURE_FAIL( "author Vicent Marti <tanoku@gmail.com> 12345 \n", "committer "); - TEST_PERSON_FAIL( + TEST_SIGNATURE_FAIL( "author Vicent Marti 12345 \n", "author "); - TEST_PERSON_FAIL( + TEST_SIGNATURE_FAIL( "author Vicent Marti <broken@email 12345 \n", "author "); - TEST_PERSON_FAIL( + TEST_SIGNATURE_FAIL( "author Vicent Marti <tanoku@gmail.com> notime \n", "author "); - TEST_PERSON_FAIL( + TEST_SIGNATURE_FAIL( "author Vicent Marti <tanoku@gmail.com>\n", "author "); - TEST_PERSON_FAIL( + TEST_SIGNATURE_FAIL( "author ", "author "); -#undef TEST_PERSON_PASS -#undef TEST_PERSON_FAIL +#undef TEST_SIGNATURE_PASS +#undef TEST_SIGNATURE_FAIL END_TEST diff --git a/tests/t0402-details.c b/tests/t0402-details.c index 489b3ff67..0b2fe229b 100644 --- a/tests/t0402-details.c +++ b/tests/t0402-details.c @@ -1,7 +1,7 @@ #include "test_lib.h" #include "test_helpers.h" #include "commit.h" -#include "person.h" +#include "signature.h" #include <git2/odb.h> #include <git2/commit.h> @@ -28,7 +28,7 @@ BEGIN_TEST(query_details_test) git_oid id; git_commit *commit; - const git_person *author, *committer; + const git_signature *author, *committer; const char *message, *message_short; time_t commit_time; unsigned int parents, p; diff --git a/tests/t0403-write.c b/tests/t0403-write.c index 8b29b05ea..c8e72da5f 100644 --- a/tests/t0403-write.c +++ b/tests/t0403-write.c @@ -1,11 +1,12 @@ #include "test_lib.h" #include "test_helpers.h" #include "commit.h" -#include "person.h" +#include "signature.h" #include <git2/odb.h> #include <git2/commit.h> #include <git2/revwalk.h> +#include <git2/signature.h> static const char *commit_ids[] = { "a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */ @@ -27,7 +28,7 @@ BEGIN_TEST(writenew_test) git_commit *commit, *parent; git_tree *tree; git_oid id; - const git_person *author, *committer; + const git_signature *author, *committer; /* char hex_oid[41]; */ must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); @@ -42,23 +43,33 @@ BEGIN_TEST(writenew_test) git_commit_add_parent(commit, parent); /* Set other attributes */ - git_commit_set_committer(commit, COMMITTER_NAME, COMMITTER_EMAIL, 123456789); - git_commit_set_author(commit, COMMITTER_NAME, COMMITTER_EMAIL, 987654321); + committer = git_signature_new(COMMITTER_NAME, COMMITTER_EMAIL, 123456789, 60); + must_be_true(committer != NULL); + + author = git_signature_new(COMMITTER_NAME, COMMITTER_EMAIL, 987654321, 90); + must_be_true(author != NULL); + + git_commit_set_committer(commit, committer); + git_commit_set_author(commit, author); git_commit_set_message(commit, COMMIT_MESSAGE); + git_signature_free((git_signature *)committer); + git_signature_free((git_signature *)author); + /* Check attributes were set correctly */ author = git_commit_author(commit); must_be_true(author != NULL); must_be_true(strcmp(author->name, COMMITTER_NAME) == 0); must_be_true(strcmp(author->email, COMMITTER_EMAIL) == 0); - must_be_true(author->time == 987654321); + must_be_true(author->when.time == 987654321); + must_be_true(author->when.offset == 90); committer = git_commit_committer(commit); must_be_true(committer != NULL); must_be_true(strcmp(committer->name, COMMITTER_NAME) == 0); must_be_true(strcmp(committer->email, COMMITTER_EMAIL) == 0); - must_be_true(committer->time == 123456789); - must_be_true(git_commit_time(commit) == 123456789); + must_be_true(committer->when.time == 123456789); + must_be_true(committer->when.offset == 60); must_be_true(strcmp(git_commit_message(commit), COMMIT_MESSAGE) == 0); @@ -74,18 +85,8 @@ BEGIN_TEST(writenew_test) /* Write to disk */ must_pass(git_object_write((git_object *)commit)); - /* Show new SHA1 */ -/* - git_oid_fmt(hex_oid, git_commit_id(commit)); - hex_oid[40] = 0; - printf("Written new commit, SHA1: %s\n", hex_oid); -*/ - must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)commit)); - //git_person_free(&author); - //git_person_free(&committer); - git_repository_free(repo); END_TEST @@ -104,12 +105,6 @@ BEGIN_TEST(writeback_test) message = git_commit_message(commit); -/* - git_oid_fmt(hex_oid, git_commit_id(commit)); - hex_oid[40] = 0; - printf("Old SHA1: %s\n", hex_oid); -*/ - git_commit_set_message(commit, "This is a new test message. Cool!\n"); git_oid_mkstr(&id, commit_ids[4]); @@ -119,12 +114,6 @@ BEGIN_TEST(writeback_test) must_pass(git_object_write((git_object *)commit)); -/* - git_oid_fmt(hex_oid, git_commit_id(commit)); - hex_oid[40] = 0; - printf("New SHA1: %s\n", hex_oid); -*/ - must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)commit)); git_repository_free(repo); diff --git a/tests/t0502-list.c b/tests/t0502-list.c index 04427f51a..119f15f99 100644 --- a/tests/t0502-list.c +++ b/tests/t0502-list.c @@ -4,6 +4,7 @@ #include "revwalk.h" #include <git2/odb.h> #include <git2/commit.h> +#include <git2/signature.h> BEGIN_TEST(list_timesort_test) @@ -15,12 +16,13 @@ BEGIN_TEST(list_timesort_test) #define TEST_SORTED() \ previous_time = INT_MAX;\ for (n = list.head; n != NULL; n = n->next) {\ - must_be_true(n->walk_commit->commit_object->commit_time <= previous_time);\ - previous_time = n->walk_commit->commit_object->commit_time;\ + must_be_true(n->walk_commit->commit_object->committer->when.time <= previous_time);\ + previous_time = n->walk_commit->commit_object->committer->when.time;\ } #define CLEAR_LIST() \ for (n = list.head; n != NULL; n = n->next) {\ + git_signature_free(n->walk_commit->commit_object->committer);\ free(n->walk_commit->commit_object);\ free(n->walk_commit);\ }\ @@ -37,7 +39,7 @@ BEGIN_TEST(list_timesort_test) git_commit *c = git__malloc(sizeof(git_commit)); git_revwalk_commit *rc = git__malloc(sizeof(git_revwalk_commit)); - c->commit_time = (time_t)rand(); + c->committer = git_signature_new("", "", (time_t)rand(), 0); rc->commit_object = c; git_revwalk_list_push_back(&list, rc); @@ -53,7 +55,7 @@ BEGIN_TEST(list_timesort_test) git_commit *c = git__malloc(sizeof(git_commit)); git_revwalk_commit *rc = git__malloc(sizeof(git_revwalk_commit)); - c->commit_time = 0; + c->committer = git_signature_new("", "", 0, 0); rc->commit_object = c; git_revwalk_list_push_back(&list, rc); |
