Add unit tests for Commit parsing
[libgit2.git] / tests / t0101-hash.c
blob6e9df7119d93ba93371c317285688b49a40f56c9
1 #include "test_lib.h"
2 #include "hash.h"
3 #include <git/oid.h>
5 static char *hello_id = "22596363b3de40b06f981fb85d82312e8c0ed511";
6 static char *hello_text = "hello world\n";
8 static char *bye_id = "ce08fe4884650f067bd5703b6a59a8b3b3c99a09";
9 static char *bye_text = "bye world\n";
11 BEGIN_TEST(hash_iuf)
12 git_hash_ctx *ctx;
13 git_oid id1, id2;
15 must_be_true((ctx = git_hash_new_ctx()) != NULL);
17 /* should already be init'd */
18 git_hash_update(ctx, hello_text, strlen(hello_text));
19 git_hash_final(&id2, ctx);
20 must_pass(git_oid_mkstr(&id1, hello_id));
21 must_be_true(git_oid_cmp(&id1, &id2) == 0);
23 /* reinit should permit reuse */
24 git_hash_init(ctx);
25 git_hash_update(ctx, bye_text, strlen(bye_text));
26 git_hash_final(&id2, ctx);
27 must_pass(git_oid_mkstr(&id1, bye_id));
28 must_be_true(git_oid_cmp(&id1, &id2) == 0);
30 git_hash_free_ctx(ctx);
31 END_TEST
33 BEGIN_TEST(hash_buf)
34 git_oid id1, id2;
36 must_pass(git_oid_mkstr(&id1, hello_id));
38 git_hash_buf(&id2, hello_text, strlen(hello_text));
40 must_be_true(git_oid_cmp(&id1, &id2) == 0);
41 END_TEST
43 BEGIN_TEST(hash_vec)
44 git_oid id1, id2;
45 git_buf_vec vec[2];
47 must_pass(git_oid_mkstr(&id1, hello_id));
49 vec[0].data = hello_text;
50 vec[0].len = 4;
51 vec[1].data = hello_text+4;
52 vec[1].len = strlen(hello_text)-4;
54 git_hash_vec(&id2, vec, 2);
56 must_be_true(git_oid_cmp(&id1, &id2) == 0);
57 END_TEST