diff options
author | Vicent Martà <tanoku@gmail.com> | 2011-08-03 18:54:25 -0700 |
---|---|---|
committer | Vicent Martà <tanoku@gmail.com> | 2011-08-03 18:54:25 -0700 |
commit | 42c5b64aa25aa6072baccba1f1845ae7afdc47ed (patch) | |
tree | 718bf96b9d66d3bfd42fbfd749c85ae72dc9234b /tests/t04-commit.c | |
parent | 03d88ed415a09faf161d8a081c18f51826be584a (diff) | |
parent | 63396a3998610ea1e3555b15a26051525e00e58e (diff) | |
download | libgit2-42c5b64aa25aa6072baccba1f1845ae7afdc47ed.tar.gz |
Merge pull request #348 from schu/sig-new
signature.c: fix off-by-one error
Diffstat (limited to 'tests/t04-commit.c')
-rw-r--r-- | tests/t04-commit.c | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/tests/t04-commit.c b/tests/t04-commit.c index 53f0faefb..b042e1515 100644 --- a/tests/t04-commit.c +++ b/tests/t04-commit.c @@ -450,10 +450,8 @@ static int try_build_signature(const char *name, const char *email, git_time_t t git_signature *sign; int error = GIT_SUCCESS; - sign = git_signature_new(name, email, time, offset); - - if (sign == NULL) - error = GIT_ERROR; + if ((error = git_signature_new(&sign, name, email, time, offset)) < GIT_SUCCESS) + return error; git_signature_free((git_signature *)sign); @@ -462,8 +460,7 @@ static int try_build_signature(const char *name, const char *email, git_time_t t BEGIN_TEST(signature0, "creating a signature trims leading and trailing spaces") git_signature *sign; - sign = git_signature_new(" nulltoken ", " emeric.fermas@gmail.com ", 1234567890, 60); - must_be_true(sign != NULL); + must_pass(git_signature_new(&sign, " nulltoken ", " emeric.fermas@gmail.com ", 1234567890, 60)); must_pass(strcmp(sign->name, "nulltoken")); must_pass(strcmp(sign->email, "emeric.fermas@gmail.com")); git_signature_free((git_signature *)sign); @@ -478,6 +475,29 @@ BEGIN_TEST(signature1, "can not create a signature with empty name or email") must_fail(try_build_signature("nulltoken", " ", 1234567890, 60)); END_TEST +BEGIN_TEST(signature2, "creating a one character signature") + git_signature *sign; + must_pass(git_signature_new(&sign, "x", "foo@bar.baz", 1234567890, 60)); + must_pass(strcmp(sign->name, "x")); + must_pass(strcmp(sign->email, "foo@bar.baz")); + git_signature_free((git_signature *)sign); +END_TEST + +BEGIN_TEST(signature3, "creating a two character signature") + git_signature *sign; + must_pass(git_signature_new(&sign, "xx", "x@y.z", 1234567890, 60)); + must_pass(strcmp(sign->name, "x")); + must_pass(strcmp(sign->email, "foo@bar.baz")); + git_signature_free((git_signature *)sign); +END_TEST + +BEGIN_TEST(signature4, "creating a zero character signature") + git_signature *sign; + must_fail(git_signature_new(&sign, "", "x@y.z", 1234567890, 60)); + must_be_true(sign == NULL); +END_TEST + + /* External declaration for testing the buffer parsing method */ int commit_parse_buffer(git_commit *commit, void *data, size_t len, unsigned int parse_flags); @@ -629,11 +649,8 @@ BEGIN_TEST(write0, "write a new commit object from memory to disk") must_pass(git_commit_lookup(&parent, repo, &parent_id)); /* create signatures */ - 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); + must_pass(git_signature_new(&committer, COMMITTER_NAME, COMMITTER_EMAIL, 123456789, 60)); + must_pass(git_signature_new(&author, COMMITTER_NAME, COMMITTER_EMAIL, 987654321, 90)); must_pass(git_commit_create_v( &commit_id, /* out id */ @@ -696,11 +713,8 @@ BEGIN_TEST(root0, "create a root commit") must_pass(git_tree_lookup(&tree, repo, &tree_id)); /* create signatures */ - 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); + must_pass(git_signature_new(&committer, COMMITTER_NAME, COMMITTER_EMAIL, 123456789, 60)); + must_pass(git_signature_new(&author, COMMITTER_NAME, COMMITTER_EMAIL, 987654321, 90)); /* First we need to update HEAD so it points to our non-existant branch */ must_pass(git_reference_lookup(&head, repo, "HEAD")); @@ -758,4 +772,7 @@ BEGIN_SUITE(commit) ADD_TEST(signature0); ADD_TEST(signature1); + ADD_TEST(signature2); + ADD_TEST(signature3); + ADD_TEST(signature4); END_SUITE |