]> git.proxmox.com Git - libgit2.git/blob - tests/object/raw/chars.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / object / raw / chars.c
1
2 #include "clar_libgit2.h"
3
4 #include "odb.h"
5
6 void test_object_raw_chars__find_invalid_chars_in_oid(void)
7 {
8 git_oid out;
9 unsigned char exp[] = {
10 0x16, 0xa6, 0x77, 0x70, 0xb7,
11 0xd8, 0xd7, 0x23, 0x17, 0xc4,
12 0xb7, 0x75, 0x21, 0x3c, 0x23,
13 0xa8, 0xbd, 0x74, 0xf5, 0xe0,
14 };
15 char in[] = "16a67770b7d8d72317c4b775213c23a8bd74f5e0";
16 unsigned int i;
17
18 for (i = 0; i < 256; i++) {
19 in[38] = (char)i;
20 if (git__fromhex(i) >= 0) {
21 exp[19] = (unsigned char)(git__fromhex(i) << 4);
22 cl_git_pass(git_oid_fromstr(&out, in));
23 cl_assert(memcmp(out.id, exp, sizeof(out.id)) == 0);
24 } else {
25 cl_git_fail(git_oid_fromstr(&out, in));
26 }
27 }
28 }
29
30 void test_object_raw_chars__build_valid_oid_from_raw_bytes(void)
31 {
32 git_oid out;
33 unsigned char exp[] = {
34 0x16, 0xa6, 0x77, 0x70, 0xb7,
35 0xd8, 0xd7, 0x23, 0x17, 0xc4,
36 0xb7, 0x75, 0x21, 0x3c, 0x23,
37 0xa8, 0xbd, 0x74, 0xf5, 0xe0,
38 };
39 git_oid_fromraw(&out, exp);
40 cl_git_pass(memcmp(out.id, exp, sizeof(out.id)));
41 }