Blame tests/object/raw/compare.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_compare__succeed_on_copy_oid(void)
Packit Service 20376f
{
Packit Service 20376f
	git_oid a, b;
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
	memset(&b, 0, sizeof(b));
Packit Service 20376f
	git_oid_fromraw(&a, exp);
Packit Service 20376f
	git_oid_cpy(&b, &a);
Packit Service 20376f
	cl_git_pass(memcmp(a.id, exp, sizeof(a.id)));
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_object_raw_compare__succeed_on_oid_comparison_lesser(void)
Packit Service 20376f
{
Packit Service 20376f
	git_oid a, b;
Packit Service 20376f
	unsigned char a_in[] = {
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
	unsigned char b_in[] = {
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, 0xf0,
Packit Service 20376f
	};
Packit Service 20376f
	git_oid_fromraw(&a, a_in);
Packit Service 20376f
	git_oid_fromraw(&b, b_in);
Packit Service 20376f
	cl_assert(git_oid_cmp(&a, &b) < 0);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_object_raw_compare__succeed_on_oid_comparison_equal(void)
Packit Service 20376f
{
Packit Service 20376f
	git_oid a, b;
Packit Service 20376f
	unsigned char a_in[] = {
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(&a, a_in);
Packit Service 20376f
	git_oid_fromraw(&b, a_in);
Packit Service 20376f
	cl_assert(git_oid_cmp(&a, &b) == 0);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_object_raw_compare__succeed_on_oid_comparison_greater(void)
Packit Service 20376f
{
Packit Service 20376f
	git_oid a, b;
Packit Service 20376f
	unsigned char a_in[] = {
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
	unsigned char b_in[] = {
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, 0xd0,
Packit Service 20376f
	};
Packit Service 20376f
	git_oid_fromraw(&a, a_in);
Packit Service 20376f
	git_oid_fromraw(&b, b_in);
Packit Service 20376f
	cl_assert(git_oid_cmp(&a, &b) > 0);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_object_raw_compare__compare_fmt_oids(void)
Packit Service 20376f
{
Packit Service 20376f
	const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0";
Packit Service 20376f
	git_oid in;
Packit Service 20376f
	char out[GIT_OID_HEXSZ + 1];
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_oid_fromstr(&in, exp));
Packit Service 20376f
Packit Service 20376f
	/* Format doesn't touch the last byte */
Packit Service 20376f
	out[GIT_OID_HEXSZ] = 'Z';
Packit Service 20376f
	git_oid_fmt(out, &in);
Packit Service 20376f
	cl_assert(out[GIT_OID_HEXSZ] == 'Z');
Packit Service 20376f
Packit Service 20376f
	/* Format produced the right result */
Packit Service 20376f
	out[GIT_OID_HEXSZ] = '\0';
Packit Service 20376f
	cl_assert_equal_s(exp, out);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_object_raw_compare__compare_static_oids(void)
Packit Service 20376f
{
Packit Service 20376f
	const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0";
Packit Service 20376f
	git_oid in;
Packit Service 20376f
	char *out;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_oid_fromstr(&in, exp));
Packit Service 20376f
Packit Service 20376f
	out = git_oid_tostr_s(&in);
Packit Service 20376f
	cl_assert(out);
Packit Service 20376f
	cl_assert_equal_s(exp, out);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_object_raw_compare__compare_pathfmt_oids(void)
Packit Service 20376f
{
Packit Service 20376f
	const char *exp1 = "16a0123456789abcdef4b775213c23a8bd74f5e0";
Packit Service 20376f
	const char *exp2 = "16/a0123456789abcdef4b775213c23a8bd74f5e0";
Packit Service 20376f
	git_oid in;
Packit Service 20376f
	char out[GIT_OID_HEXSZ + 2];
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_oid_fromstr(&in, exp1));
Packit Service 20376f
Packit Service 20376f
	/* Format doesn't touch the last byte */
Packit Service 20376f
	out[GIT_OID_HEXSZ + 1] = 'Z';
Packit Service 20376f
	git_oid_pathfmt(out, &in);
Packit Service 20376f
	cl_assert(out[GIT_OID_HEXSZ + 1] == 'Z');
Packit Service 20376f
Packit Service 20376f
	/* Format produced the right result */
Packit Service 20376f
	out[GIT_OID_HEXSZ + 1] = '\0';
Packit Service 20376f
	cl_assert_equal_s(exp2, out);
Packit Service 20376f
}