Commit 9ff46db9 by schu

tests-clay: move t01-rawobj.c to clay

Signed-off-by: schu <schu-github@schulog.org>
parent c2fbe423
...@@ -57,6 +57,17 @@ void cl_fixture_cleanup(const char *fixture_name); ...@@ -57,6 +57,17 @@ void cl_fixture_cleanup(const char *fixture_name);
/** /**
* Test method declarations * Test method declarations
*/ */
extern void test_status_single__hash_single_file(void);
extern void test_status_worktree__initialize(void);
extern void test_status_worktree__cleanup(void);
extern void test_status_worktree__whole_repository(void);
extern void test_status_worktree__empty_repository(void);
extern void test_network_remotes__initialize(void);
extern void test_network_remotes__cleanup(void);
extern void test_network_remotes__parsing(void);
extern void test_network_remotes__refspec_parsing(void);
extern void test_network_remotes__fnmatch(void);
extern void test_network_remotes__transform(void);
extern void test_core_dirent__dont_traverse_dot(void); extern void test_core_dirent__dont_traverse_dot(void);
extern void test_core_dirent__traverse_subfolder(void); extern void test_core_dirent__traverse_subfolder(void);
extern void test_core_dirent__traverse_slash_terminated_folder(void); extern void test_core_dirent__traverse_slash_terminated_folder(void);
...@@ -82,21 +93,40 @@ extern void test_core_strtol__int64(void); ...@@ -82,21 +93,40 @@ extern void test_core_strtol__int64(void);
extern void test_core_vector__0(void); extern void test_core_vector__0(void);
extern void test_core_vector__1(void); extern void test_core_vector__1(void);
extern void test_core_vector__2(void); extern void test_core_vector__2(void);
extern void test_network_remotes__initialize(void);
extern void test_network_remotes__cleanup(void);
extern void test_network_remotes__parsing(void);
extern void test_network_remotes__refspec_parsing(void);
extern void test_network_remotes__fnmatch(void);
extern void test_network_remotes__transform(void);
extern void test_object_tree_frompath__initialize(void); extern void test_object_tree_frompath__initialize(void);
extern void test_object_tree_frompath__cleanup(void); extern void test_object_tree_frompath__cleanup(void);
extern void test_object_tree_frompath__retrieve_tree_from_path_to_treeentry(void); extern void test_object_tree_frompath__retrieve_tree_from_path_to_treeentry(void);
extern void test_object_tree_frompath__fail_when_processing_an_unknown_tree_segment(void); extern void test_object_tree_frompath__fail_when_processing_an_unknown_tree_segment(void);
extern void test_object_tree_frompath__fail_when_processing_an_invalid_path(void); extern void test_object_tree_frompath__fail_when_processing_an_invalid_path(void);
extern void test_status_single__hash_single_file(void); extern void test_object_raw_chars__find_invalid_chars_in_oid(void);
extern void test_status_worktree__initialize(void); extern void test_object_raw_chars__build_valid_oid_from_raw_bytes(void);
extern void test_status_worktree__cleanup(void); extern void test_object_raw_compare__succeed_on_copy_oid(void);
extern void test_status_worktree__whole_repository(void); extern void test_object_raw_compare__succeed_on_oid_comparison_lesser(void);
extern void test_status_worktree__empty_repository(void); extern void test_object_raw_compare__succeed_on_oid_comparison_equal(void);
extern void test_object_raw_compare__succeed_on_oid_comparison_greater(void);
extern void test_object_raw_compare__compare_fmt_oids(void);
extern void test_object_raw_compare__compare_allocfmt_oids(void);
extern void test_object_raw_compare__compare_pathfmt_oids(void);
extern void test_object_raw_convert__succeed_on_oid_to_string_conversion(void);
extern void test_object_raw_convert__succeed_on_oid_to_string_conversion_big(void);
extern void test_object_raw_fromstr__fail_on_invalid_oid_string(void);
extern void test_object_raw_fromstr__succeed_on_valid_oid_string(void);
extern void test_object_raw_hash__hash_by_blocks(void);
extern void test_object_raw_hash__hash_buffer_in_single_call(void);
extern void test_object_raw_hash__hash_vector(void);
extern void test_object_raw_hash__hash_junk_data(void);
extern void test_object_raw_hash__hash_commit_object(void);
extern void test_object_raw_hash__hash_tree_object(void);
extern void test_object_raw_hash__hash_tag_object(void);
extern void test_object_raw_hash__hash_zero_length_object(void);
extern void test_object_raw_hash__hash_one_byte_object(void);
extern void test_object_raw_hash__hash_two_byte_object(void);
extern void test_object_raw_hash__hash_multi_byte_object(void);
extern void test_object_raw_short__oid_shortener_no_duplicates(void);
extern void test_object_raw_short__oid_shortener_stresstest_git_oid_shorten(void);
extern void test_object_raw_size__validate_oid_size(void);
extern void test_object_raw_type2string__convert_type_to_string(void);
extern void test_object_raw_type2string__convert_string_to_type(void);
extern void test_object_raw_type2string__check_type_is_loose(void);
#endif #endif
#include "clay_libgit2.h"
#include "odb.h"
static int from_hex(unsigned int i)
{
if (i >= '0' && i <= '9')
return i - '0';
if (i >= 'a' && i <= 'f')
return 10 + (i - 'a');
if (i >= 'A' && i <= 'F')
return 10 + (i - 'A');
return -1;
}
void test_object_raw_chars__find_invalid_chars_in_oid(void)
{
git_oid out;
unsigned char exp[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
0xd8, 0xd7, 0x23, 0x17, 0xc4,
0xb7, 0x75, 0x21, 0x3c, 0x23,
0xa8, 0xbd, 0x74, 0xf5, 0xe0,
};
char in[41] = "16a67770b7d8d72317c4b775213c23a8bd74f5e0";
unsigned int i;
for (i = 0; i < 256; i++) {
in[38] = (char)i;
if (from_hex(i) >= 0) {
exp[19] = (unsigned char)(from_hex(i) << 4);
cl_git_pass(git_oid_fromstr(&out, in));
cl_assert(memcmp(out.id, exp, sizeof(out.id)) == 0);
} else {
cl_git_fail(git_oid_fromstr(&out, in));
}
}
}
void test_object_raw_chars__build_valid_oid_from_raw_bytes(void)
{
git_oid out;
unsigned char exp[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
0xd8, 0xd7, 0x23, 0x17, 0xc4,
0xb7, 0x75, 0x21, 0x3c, 0x23,
0xa8, 0xbd, 0x74, 0xf5, 0xe0,
};
git_oid_fromraw(&out, exp);
cl_git_pass(memcmp(out.id, exp, sizeof(out.id)));
}
#include "clay_libgit2.h"
#include "odb.h"
void test_object_raw_compare__succeed_on_copy_oid(void)
{
git_oid a, b;
unsigned char exp[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
0xd8, 0xd7, 0x23, 0x17, 0xc4,
0xb7, 0x75, 0x21, 0x3c, 0x23,
0xa8, 0xbd, 0x74, 0xf5, 0xe0,
};
memset(&b, 0, sizeof(b));
git_oid_fromraw(&a, exp);
git_oid_cpy(&b, &a);
cl_git_pass(memcmp(a.id, exp, sizeof(a.id)));
}
void test_object_raw_compare__succeed_on_oid_comparison_lesser(void)
{
git_oid a, b;
unsigned char a_in[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
0xd8, 0xd7, 0x23, 0x17, 0xc4,
0xb7, 0x75, 0x21, 0x3c, 0x23,
0xa8, 0xbd, 0x74, 0xf5, 0xe0,
};
unsigned char b_in[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
0xd8, 0xd7, 0x23, 0x17, 0xc4,
0xb7, 0x75, 0x21, 0x3c, 0x23,
0xa8, 0xbd, 0x74, 0xf5, 0xf0,
};
git_oid_fromraw(&a, a_in);
git_oid_fromraw(&b, b_in);
cl_assert(git_oid_cmp(&a, &b) < 0);
}
void test_object_raw_compare__succeed_on_oid_comparison_equal(void)
{
git_oid a, b;
unsigned char a_in[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
0xd8, 0xd7, 0x23, 0x17, 0xc4,
0xb7, 0x75, 0x21, 0x3c, 0x23,
0xa8, 0xbd, 0x74, 0xf5, 0xe0,
};
git_oid_fromraw(&a, a_in);
git_oid_fromraw(&b, a_in);
cl_assert(git_oid_cmp(&a, &b) == 0);
}
void test_object_raw_compare__succeed_on_oid_comparison_greater(void)
{
git_oid a, b;
unsigned char a_in[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
0xd8, 0xd7, 0x23, 0x17, 0xc4,
0xb7, 0x75, 0x21, 0x3c, 0x23,
0xa8, 0xbd, 0x74, 0xf5, 0xe0,
};
unsigned char b_in[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
0xd8, 0xd7, 0x23, 0x17, 0xc4,
0xb7, 0x75, 0x21, 0x3c, 0x23,
0xa8, 0xbd, 0x74, 0xf5, 0xd0,
};
git_oid_fromraw(&a, a_in);
git_oid_fromraw(&b, b_in);
cl_assert(git_oid_cmp(&a, &b) > 0);
}
void test_object_raw_compare__compare_fmt_oids(void)
{
const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0";
git_oid in;
char out[GIT_OID_HEXSZ + 1];
cl_git_pass(git_oid_fromstr(&in, exp));
/* Format doesn't touch the last byte */
out[GIT_OID_HEXSZ] = 'Z';
git_oid_fmt(out, &in);
cl_assert(out[GIT_OID_HEXSZ] == 'Z');
/* Format produced the right result */
out[GIT_OID_HEXSZ] = '\0';
cl_assert(strcmp(exp, out) == 0);
}
void test_object_raw_compare__compare_allocfmt_oids(void)
{
const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0";
git_oid in;
char *out;
cl_git_pass(git_oid_fromstr(&in, exp));
out = git_oid_allocfmt(&in);
cl_assert(out);
cl_assert(strcmp(exp, out) == 0);
free(out);
}
void test_object_raw_compare__compare_pathfmt_oids(void)
{
const char *exp1 = "16a0123456789abcdef4b775213c23a8bd74f5e0";
const char *exp2 = "16/a0123456789abcdef4b775213c23a8bd74f5e0";
git_oid in;
char out[GIT_OID_HEXSZ + 2];
cl_git_pass(git_oid_fromstr(&in, exp1));
/* Format doesn't touch the last byte */
out[GIT_OID_HEXSZ + 1] = 'Z';
git_oid_pathfmt(out, &in);
cl_assert(out[GIT_OID_HEXSZ + 1] == 'Z');
/* Format produced the right result */
out[GIT_OID_HEXSZ + 1] = '\0';
cl_assert(strcmp(exp2, out) == 0);
}
#include "clay_libgit2.h"
#include "odb.h"
void test_object_raw_convert__succeed_on_oid_to_string_conversion(void)
{
const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0";
git_oid in;
char out[GIT_OID_HEXSZ + 1];
char *str;
int i;
cl_git_pass(git_oid_fromstr(&in, exp));
/* NULL buffer pointer, returns static empty string */
str = git_oid_to_string(NULL, sizeof(out), &in);
cl_assert(str && *str == '\0' && str != out);
/* zero buffer size, returns static empty string */
str = git_oid_to_string(out, 0, &in);
cl_assert(str && *str == '\0' && str != out);
/* NULL oid pointer, returns static empty string */
str = git_oid_to_string(out, sizeof(out), NULL);
cl_assert(str && *str == '\0' && str != out);
/* n == 1, returns out as an empty string */
str = git_oid_to_string(out, 1, &in);
cl_assert(str && *str == '\0' && str == out);
for (i = 1; i < GIT_OID_HEXSZ; i++) {
out[i+1] = 'Z';
str = git_oid_to_string(out, i+1, &in);
/* returns out containing c-string */
cl_assert(str && str == out);
/* must be '\0' terminated */
cl_assert(*(str+i) == '\0');
/* must not touch bytes past end of string */
cl_assert(*(str+(i+1)) == 'Z');
/* i == n-1 charaters of string */
cl_git_pass(strncmp(exp, out, i));
}
/* returns out as hex formatted c-string */
str = git_oid_to_string(out, sizeof(out), &in);
cl_assert(str && str == out && *(str+GIT_OID_HEXSZ) == '\0');
cl_assert(strcmp(exp, out) == 0);
}
void test_object_raw_convert__succeed_on_oid_to_string_conversion_big(void)
{
const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0";
git_oid in;
char big[GIT_OID_HEXSZ + 1 + 3]; /* note + 4 => big buffer */
char *str;
cl_git_pass(git_oid_fromstr(&in, exp));
/* place some tail material */
big[GIT_OID_HEXSZ+0] = 'W'; /* should be '\0' afterwards */
big[GIT_OID_HEXSZ+1] = 'X'; /* should remain untouched */
big[GIT_OID_HEXSZ+2] = 'Y'; /* ditto */
big[GIT_OID_HEXSZ+3] = 'Z'; /* ditto */
/* returns big as hex formatted c-string */
str = git_oid_to_string(big, sizeof(big), &in);
cl_assert(str && str == big && *(str+GIT_OID_HEXSZ) == '\0');
cl_assert(strcmp(exp, big) == 0);
/* check tail material is untouched */
cl_assert(str && str == big && *(str+GIT_OID_HEXSZ+1) == 'X');
cl_assert(str && str == big && *(str+GIT_OID_HEXSZ+2) == 'Y');
cl_assert(str && str == big && *(str+GIT_OID_HEXSZ+3) == 'Z');
}
#include "clay_libgit2.h"
#include "odb.h"
void test_object_raw_fromstr__fail_on_invalid_oid_string(void)
{
git_oid out;
cl_git_fail(git_oid_fromstr(&out, ""));
cl_git_fail(git_oid_fromstr(&out, "moo"));
cl_git_fail(git_oid_fromstr(&out, "16a67770b7d8d72317c4b775213c23a8bd74f5ez"));
}
void test_object_raw_fromstr__succeed_on_valid_oid_string(void)
{
git_oid out;
unsigned char exp[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
0xd8, 0xd7, 0x23, 0x17, 0xc4,
0xb7, 0x75, 0x21, 0x3c, 0x23,
0xa8, 0xbd, 0x74, 0xf5, 0xe0,
};
cl_git_pass(git_oid_fromstr(&out, "16a67770b7d8d72317c4b775213c23a8bd74f5e0"));
cl_git_pass(memcmp(out.id, exp, sizeof(out.id)));
cl_git_pass(git_oid_fromstr(&out, "16A67770B7D8D72317C4b775213C23A8BD74F5E0"));
cl_git_pass(memcmp(out.id, exp, sizeof(out.id)));
}
#include "clay_libgit2.h"
#include "odb.h"
#include "hash.h"
#include "data.h"
static int hash_object(git_oid *oid, git_rawobj *obj)
{
return git_odb_hash(oid, obj->data, obj->len, obj->type);
}
static char *hello_id = "22596363b3de40b06f981fb85d82312e8c0ed511";
static char *hello_text = "hello world\n";
static char *bye_id = "ce08fe4884650f067bd5703b6a59a8b3b3c99a09";
static char *bye_text = "bye world\n";
void test_object_raw_hash__hash_by_blocks(void)
{
git_hash_ctx *ctx;
git_oid id1, id2;
cl_assert((ctx = git_hash_new_ctx()) != NULL);
/* should already be init'd */
git_hash_update(ctx, hello_text, strlen(hello_text));
git_hash_final(&id2, ctx);
cl_git_pass(git_oid_fromstr(&id1, hello_id));
cl_assert(git_oid_cmp(&id1, &id2) == 0);
/* reinit should permit reuse */
git_hash_init(ctx);
git_hash_update(ctx, bye_text, strlen(bye_text));
git_hash_final(&id2, ctx);
cl_git_pass(git_oid_fromstr(&id1, bye_id));
cl_assert(git_oid_cmp(&id1, &id2) == 0);
git_hash_free_ctx(ctx);
}
void test_object_raw_hash__hash_buffer_in_single_call(void)
{
git_oid id1, id2;
cl_git_pass(git_oid_fromstr(&id1, hello_id));
git_hash_buf(&id2, hello_text, strlen(hello_text));
cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_vector(void)
{
git_oid id1, id2;
git_buf_vec vec[2];
cl_git_pass(git_oid_fromstr(&id1, hello_id));
vec[0].data = hello_text;
vec[0].len = 4;
vec[1].data = hello_text+4;
vec[1].len = strlen(hello_text)-4;
git_hash_vec(&id2, vec, 2);
cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_junk_data(void)
{
git_oid id, id_zero;
cl_git_pass(git_oid_fromstr(&id_zero, zero_id));
/* invalid types: */
junk_obj.data = some_data;
cl_git_fail(hash_object(&id, &junk_obj));
junk_obj.type = GIT_OBJ__EXT1;
cl_git_fail(hash_object(&id, &junk_obj));
junk_obj.type = GIT_OBJ__EXT2;
cl_git_fail(hash_object(&id, &junk_obj));
junk_obj.type = GIT_OBJ_OFS_DELTA;
cl_git_fail(hash_object(&id, &junk_obj));
junk_obj.type = GIT_OBJ_REF_DELTA;
cl_git_fail(hash_object(&id, &junk_obj));
/* data can be NULL only if len is zero: */
junk_obj.type = GIT_OBJ_BLOB;
junk_obj.data = NULL;
cl_git_pass(hash_object(&id, &junk_obj));
cl_assert(git_oid_cmp(&id, &id_zero) == 0);
junk_obj.len = 1;
cl_git_fail(hash_object(&id, &junk_obj));
}
void test_object_raw_hash__hash_commit_object(void)
{
git_oid id1, id2;
cl_git_pass(git_oid_fromstr(&id1, commit_id));
cl_git_pass(hash_object(&id2, &commit_obj));
cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_tree_object(void)
{
git_oid id1, id2;
cl_git_pass(git_oid_fromstr(&id1, tree_id));
cl_git_pass(hash_object(&id2, &tree_obj));
cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_tag_object(void)
{
git_oid id1, id2;
cl_git_pass(git_oid_fromstr(&id1, tag_id));
cl_git_pass(hash_object(&id2, &tag_obj));
cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_zero_length_object(void)
{
git_oid id1, id2;
cl_git_pass(git_oid_fromstr(&id1, zero_id));
cl_git_pass(hash_object(&id2, &zero_obj));
cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_one_byte_object(void)
{
git_oid id1, id2;
cl_git_pass(git_oid_fromstr(&id1, one_id));
cl_git_pass(hash_object(&id2, &one_obj));
cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_two_byte_object(void)
{
git_oid id1, id2;
cl_git_pass(git_oid_fromstr(&id1, two_id));
cl_git_pass(hash_object(&id2, &two_obj));
cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_multi_byte_object(void)
{
git_oid id1, id2;
cl_git_pass(git_oid_fromstr(&id1, some_id));
cl_git_pass(hash_object(&id2, &some_obj));
cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
#include "clay_libgit2.h"
#include "odb.h"
#include "hash.h"
void test_object_raw_short__oid_shortener_no_duplicates(void)
{
git_oid_shorten *os;
int min_len;
os = git_oid_shorten_new(0);
cl_assert(os != NULL);
git_oid_shorten_add(os, "22596363b3de40b06f981fb85d82312e8c0ed511");
git_oid_shorten_add(os, "ce08fe4884650f067bd5703b6a59a8b3b3c99a09");
git_oid_shorten_add(os, "16a0123456789abcdef4b775213c23a8bd74f5e0");
min_len = git_oid_shorten_add(os, "ce08fe4884650f067bd5703b6a59a8b3b3c99a09");
cl_assert(min_len == GIT_OID_HEXSZ + 1);
git_oid_shorten_free(os);
}
void test_object_raw_short__oid_shortener_stresstest_git_oid_shorten(void)
{
#define MAX_OIDS 1000
git_oid_shorten *os;
char *oids[MAX_OIDS];
char number_buffer[16];
git_oid oid;
size_t i, j;
int min_len = 0, found_collision;
os = git_oid_shorten_new(0);
cl_assert(os != NULL);
/*
* Insert in the shortener 1000 unique SHA1 ids
*/
for (i = 0; i < MAX_OIDS; ++i) {
char *oid_text;
sprintf(number_buffer, "%u", (unsigned int)i);
git_hash_buf(&oid, number_buffer, strlen(number_buffer));
oid_text = git__malloc(GIT_OID_HEXSZ + 1);
git_oid_fmt(oid_text, &oid);
oid_text[GIT_OID_HEXSZ] = 0;
min_len = git_oid_shorten_add(os, oid_text);
cl_assert(min_len >= 0);
oids[i] = oid_text;
}
/*
* Compare the first `min_char - 1` characters of each
* SHA1 OID. If the minimizer worked, we should find at
* least one collision
*/
found_collision = 0;
for (i = 0; i < MAX_OIDS; ++i) {
for (j = 0; j < MAX_OIDS; ++j) {
if (i != j && memcmp(oids[i], oids[j], min_len - 1) == 0)
found_collision = 1;
}
}
cl_assert(found_collision == 1);
/*
* Compare the first `min_char` characters of each
* SHA1 OID. If the minimizer worked, every single preffix
* should be unique.
*/
found_collision = 0;
for (i = 0; i < MAX_OIDS; ++i) {
for (j = 0; j < MAX_OIDS; ++j) {
if (i != j && memcmp(oids[i], oids[j], min_len) == 0)
found_collision = 1;
}
}
cl_assert(found_collision == 0);
/* cleanup */
for (i = 0; i < MAX_OIDS; ++i)
free(oids[i]);
git_oid_shorten_free(os);
#undef MAX_OIDS
}
#include "clay_libgit2.h"
#include "odb.h"
void test_object_raw_size__validate_oid_size(void)
{
git_oid out;
cl_assert(20 == GIT_OID_RAWSZ);
cl_assert(40 == GIT_OID_HEXSZ);
cl_assert(sizeof(out) == GIT_OID_RAWSZ);
cl_assert(sizeof(out.id) == GIT_OID_RAWSZ);
}
#include "clay_libgit2.h"
#include "odb.h"
#include "hash.h"
void test_object_raw_type2string__convert_type_to_string(void)
{
cl_assert(!strcmp(git_object_type2string(GIT_OBJ_BAD), ""));
cl_assert(!strcmp(git_object_type2string(GIT_OBJ__EXT1), ""));
cl_assert(!strcmp(git_object_type2string(GIT_OBJ_COMMIT), "commit"));
cl_assert(!strcmp(git_object_type2string(GIT_OBJ_TREE), "tree"));
cl_assert(!strcmp(git_object_type2string(GIT_OBJ_BLOB), "blob"));
cl_assert(!strcmp(git_object_type2string(GIT_OBJ_TAG), "tag"));
cl_assert(!strcmp(git_object_type2string(GIT_OBJ__EXT2), ""));
cl_assert(!strcmp(git_object_type2string(GIT_OBJ_OFS_DELTA), "OFS_DELTA"));
cl_assert(!strcmp(git_object_type2string(GIT_OBJ_REF_DELTA), "REF_DELTA"));
cl_assert(!strcmp(git_object_type2string(-2), ""));
cl_assert(!strcmp(git_object_type2string(8), ""));
cl_assert(!strcmp(git_object_type2string(1234), ""));
}
void test_object_raw_type2string__convert_string_to_type(void)
{
cl_assert(git_object_string2type(NULL) == GIT_OBJ_BAD);
cl_assert(git_object_string2type("") == GIT_OBJ_BAD);
cl_assert(git_object_string2type("commit") == GIT_OBJ_COMMIT);
cl_assert(git_object_string2type("tree") == GIT_OBJ_TREE);
cl_assert(git_object_string2type("blob") == GIT_OBJ_BLOB);
cl_assert(git_object_string2type("tag") == GIT_OBJ_TAG);
cl_assert(git_object_string2type("OFS_DELTA") == GIT_OBJ_OFS_DELTA);
cl_assert(git_object_string2type("REF_DELTA") == GIT_OBJ_REF_DELTA);
cl_assert(git_object_string2type("CoMmIt") == GIT_OBJ_BAD);
cl_assert(git_object_string2type("hohoho") == GIT_OBJ_BAD);
}
void test_object_raw_type2string__check_type_is_loose(void)
{
cl_assert(git_object_typeisloose(GIT_OBJ_BAD) == 0);
cl_assert(git_object_typeisloose(GIT_OBJ__EXT1) == 0);
cl_assert(git_object_typeisloose(GIT_OBJ_COMMIT) == 1);
cl_assert(git_object_typeisloose(GIT_OBJ_TREE) == 1);
cl_assert(git_object_typeisloose(GIT_OBJ_BLOB) == 1);
cl_assert(git_object_typeisloose(GIT_OBJ_TAG) == 1);
cl_assert(git_object_typeisloose(GIT_OBJ__EXT2) == 0);
cl_assert(git_object_typeisloose(GIT_OBJ_OFS_DELTA) == 0);
cl_assert(git_object_typeisloose(GIT_OBJ_REF_DELTA) == 0);
cl_assert(git_object_typeisloose(-2) == 0);
cl_assert(git_object_typeisloose(8) == 0);
cl_assert(git_object_typeisloose(1234) == 0);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment