Blame tests/object/raw/chars.c

Packit Service 20376f
Packit Service 20376f
#include "clar_libgit2.h"
Packit Service 20376f
Packit Service 20376f
#include "odb.h"
Packit Service 20376f
Packit Service 20376f
void test_object_raw_chars__find_invalid_chars_in_oid(void)
Packit Service 20376f
{
Packit Service 20376f
	git_oid out;
Packit Service 20376f
	unsigned char exp[] = {
Packit Service 20376f
		0x16, 0xa6, 0x77, 0x70, 0xb7,
Packit Service 20376f
		0xd8, 0xd7, 0x23, 0x17, 0xc4,
Packit Service 20376f
		0xb7, 0x75, 0x21, 0x3c, 0x23,
Packit Service 20376f
		0xa8, 0xbd, 0x74, 0xf5, 0xe0,
Packit Service 20376f
	};
Packit Service 20376f
	char in[] = "16a67770b7d8d72317c4b775213c23a8bd74f5e0";
Packit Service 20376f
	unsigned int i;
Packit Service 20376f
Packit Service 20376f
	for (i = 0; i < 256; i++) {
Packit Service 20376f
		in[38] = (char)i;
Packit Service 20376f
		if (git__fromhex(i) >= 0) {
Packit Service 20376f
			exp[19] = (unsigned char)(git__fromhex(i) << 4);
Packit Service 20376f
			cl_git_pass(git_oid_fromstr(&out, in));
Packit Service 20376f
			cl_assert(memcmp(out.id, exp, sizeof(out.id)) == 0);
Packit Service 20376f
		} else {
Packit Service 20376f
			cl_git_fail(git_oid_fromstr(&out, in));
Packit Service 20376f
		}
Packit Service 20376f
	}
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_object_raw_chars__build_valid_oid_from_raw_bytes(void)
Packit Service 20376f
{
Packit Service 20376f
	git_oid out;
Packit Service 20376f
	unsigned char exp[] = {
Packit Service 20376f
		0x16, 0xa6, 0x77, 0x70, 0xb7,
Packit Service 20376f
		0xd8, 0xd7, 0x23, 0x17, 0xc4,
Packit Service 20376f
		0xb7, 0x75, 0x21, 0x3c, 0x23,
Packit Service 20376f
		0xa8, 0xbd, 0x74, 0xf5, 0xe0,
Packit Service 20376f
	};
Packit Service 20376f
	git_oid_fromraw(&out, exp);
Packit Service 20376f
	cl_git_pass(memcmp(out.id, exp, sizeof(out.id)));
Packit Service 20376f
}