Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
7367a9d5
Commit
7367a9d5
authored
Jan 22, 2022
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: don't cast raw data to a `git_oid``
Create an object id from raw data instead of casting.
parent
c569738c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
4 deletions
+12
-4
tests/libgit2/object/raw/hash.c
+8
-3
tests/libgit2/object/raw/short.c
+4
-1
No files found.
tests/libgit2/object/raw/hash.c
View file @
7367a9d5
...
...
@@ -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
);
}
...
...
tests/libgit2/object/raw/short.c
View file @
7367a9d5
...
...
@@ -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
]);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment