Commit 7367a9d5 by Edward Thomson

tests: don't cast raw data to a `git_oid``

Create an object id from raw data instead of casting.
parent c569738c
......@@ -24,20 +24,23 @@ static char *bye_text = "bye world\n";
void test_object_raw_hash__hash_by_blocks(void)
{
git_hash_ctx ctx;
unsigned char hash[GIT_HASH_SHA1_SIZE];
git_oid id1, id2;
cl_git_pass(git_hash_ctx_init(&ctx, GIT_HASH_ALGORITHM_SHA1));
/* should already be init'd */
cl_git_pass(git_hash_update(&ctx, hello_text, strlen(hello_text)));
cl_git_pass(git_hash_final(id2.id, &ctx));
cl_git_pass(git_hash_final(hash, &ctx));
cl_git_pass(git_oid_fromraw(&id2, hash));
cl_git_pass(git_oid_fromstr(&id1, hello_id));
cl_assert(git_oid_cmp(&id1, &id2) == 0);
/* reinit should permit reuse */
cl_git_pass(git_hash_init(&ctx));
cl_git_pass(git_hash_update(&ctx, bye_text, strlen(bye_text)));
cl_git_pass(git_hash_final(id2.id, &ctx));
cl_git_pass(git_hash_final(hash, &ctx));
cl_git_pass(git_oid_fromraw(&id2, hash));
cl_git_pass(git_oid_fromstr(&id1, bye_id));
cl_assert(git_oid_cmp(&id1, &id2) == 0);
......@@ -47,9 +50,11 @@ void test_object_raw_hash__hash_by_blocks(void)
void test_object_raw_hash__hash_buffer_in_single_call(void)
{
git_oid id1, id2;
unsigned char hash[GIT_HASH_SHA1_SIZE];
cl_git_pass(git_oid_fromstr(&id1, hello_id));
git_hash_buf(id2.id, hello_text, strlen(hello_text), GIT_HASH_ALGORITHM_SHA1);
cl_git_pass(git_hash_buf(hash, hello_text, strlen(hello_text), GIT_HASH_ALGORITHM_SHA1));
cl_git_pass(git_oid_fromraw(&id2, hash));
cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
......
......@@ -28,12 +28,15 @@ static int insert_sequential_oids(
int i, min_len = 0;
char numbuf[16];
git_oid oid;
unsigned char hashbuf[GIT_HASH_SHA1_SIZE];
char **oids = git__calloc(n, sizeof(char *));
cl_assert(oids != NULL);
for (i = 0; i < n; ++i) {
p_snprintf(numbuf, sizeof(numbuf), "%u", (unsigned int)i);
git_hash_buf(oid.id, numbuf, strlen(numbuf), GIT_HASH_ALGORITHM_SHA1);
git_hash_buf(hashbuf, numbuf, strlen(numbuf), GIT_HASH_ALGORITHM_SHA1);
git_oid_fromraw(&oid, hashbuf);
oids[i] = git__malloc(GIT_OID_HEXSZ + 1);
cl_assert(oids[i]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment