static void assert_commit_parses(const char *data, size_t datalen, const char *expected_treeid, const char *expected_author, const char *expected_committer, const char *expected_encoding, const char *expected_message, size_t expected_parents) { git_commit *commit; if (!datalen) datalen = strlen(data); cl_git_pass(git_object__from_raw((git_object **) &commit, data, datalen, GIT_OBJECT_COMMIT)); if (expected_author) { git_signature *author; cl_git_pass(git_signature_from_buffer(&author, expected_author)); cl_assert(git_signature__equal(author, commit->author)); cl_assert_equal_s(author->name, commit->author->name); cl_assert_equal_s(author->email, commit->author->email); cl_assert_equal_i(author->when.time, commit->author->when.time); cl_assert_equal_i(author->when.offset, commit->author->when.offset); cl_assert_equal_i(author->when.sign, commit->author->when.sign); git_signature_free(author); } if (expected_committer) { git_signature *committer; cl_git_pass(git_signature_from_buffer(&committer, expected_committer)); cl_assert_equal_s(committer->name, commit->committer->name); cl_assert_equal_s(committer->email, commit->committer->email); cl_assert_equal_i(committer->when.time, commit->committer->when.time); cl_assert_equal_i(committer->when.offset, commit->committer->when.offset); cl_assert_equal_i(committer->when.sign, commit->committer->when.sign); git_signature_free(committer); } if (expected_encoding) cl_assert_equal_s(commit->message_encoding, expected_encoding); else cl_assert_equal_p(commit->message_encoding, NULL); if (expected_message) cl_assert_equal_s(commit->raw_message, expected_message); else cl_assert_equal_p(commit->message_encoding, NULL); if (expected_treeid) { git_oid tree_oid; cl_git_pass(git_oid_fromstr(&tree_oid, expected_treeid)); cl_assert_equal_oid(&tree_oid, &commit->tree_id); } cl_assert_equal_i(commit->parent_ids.size, expected_parents); git_object__free(&commit->object); }
void test_commit_signature__pos_and_neg_zero_offsets_dont_match(void) { git_signature *with_neg_zero; git_signature *with_pos_zero; cl_git_pass(git_signature_from_buffer(&with_neg_zero, "Test User <*****@*****.**> 1461698487 -0000")); cl_git_pass(git_signature_from_buffer(&with_pos_zero, "Test User <*****@*****.**> 1461698487 +0000")); cl_assert(!git_signature__equal(with_neg_zero, with_pos_zero)); git_signature_free((git_signature *)with_neg_zero); git_signature_free((git_signature *)with_pos_zero); }
void test_commit_signature__from_buf(void) { git_signature *sign; cl_git_pass(git_signature_from_buffer(&sign, "Test User <*****@*****.**> 1461698487 +0200")); cl_assert_equal_s("Test User", sign->name); cl_assert_equal_s("*****@*****.**", sign->email); cl_assert_equal_i(1461698487, sign->when.time); cl_assert_equal_i(120, sign->when.offset); git_signature_free(sign); }