diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2022-01-22 09:07:26 -0500 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2022-04-10 15:56:57 -0400 |
commit | 7367a9d5f71ae8a4c7e3e97e5c42c0cd034672c9 (patch) | |
tree | 6566373154adbd7ba2631c1946e54f07ae638dd7 /tests | |
parent | c569738ce65a4b8f4dd0bc8c66f2885ceed8d86e (diff) | |
download | libgit2-7367a9d5f71ae8a4c7e3e97e5c42c0cd034672c9.tar.gz |
tests: don't cast raw data to a `git_oid``
Create an object id from raw data instead of casting.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/libgit2/object/raw/hash.c | 11 | ||||
-rw-r--r-- | tests/libgit2/object/raw/short.c | 5 |
2 files changed, 12 insertions, 4 deletions
diff --git a/tests/libgit2/object/raw/hash.c b/tests/libgit2/object/raw/hash.c index 5a3e81855..8f22fe0ee 100644 --- a/tests/libgit2/object/raw/hash.c +++ b/tests/libgit2/object/raw/hash.c @@ -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); } diff --git a/tests/libgit2/object/raw/short.c b/tests/libgit2/object/raw/short.c index e8d2cf5a5..cc2b5f62a 100644 --- a/tests/libgit2/object/raw/short.c +++ b/tests/libgit2/object/raw/short.c @@ -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]); |