mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-08 19:51:31 +00:00
Merge pull request #463 from schu/tests-clay-object-raw
tests-clay: move t01-rawobj.c to clay
This commit is contained in:
commit
d533c8885b
@ -57,6 +57,17 @@ void cl_fixture_cleanup(const char *fixture_name);
|
||||
/**
|
||||
* 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__traverse_subfolder(void);
|
||||
extern void test_core_dirent__traverse_slash_terminated_folder(void);
|
||||
@ -82,21 +93,40 @@ extern void test_core_strtol__int64(void);
|
||||
extern void test_core_vector__0(void);
|
||||
extern void test_core_vector__1(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__cleanup(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_invalid_path(void);
|
||||
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_object_raw_chars__find_invalid_chars_in_oid(void);
|
||||
extern void test_object_raw_chars__build_valid_oid_from_raw_bytes(void);
|
||||
extern void test_object_raw_compare__succeed_on_copy_oid(void);
|
||||
extern void test_object_raw_compare__succeed_on_oid_comparison_lesser(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
|
||||
|
@ -660,123 +660,201 @@ cl_fs_cleanup(void)
|
||||
|
||||
|
||||
static const struct clay_func _all_callbacks[] = {
|
||||
{"dont_traverse_dot", &test_core_dirent__dont_traverse_dot, 0},
|
||||
{"traverse_subfolder", &test_core_dirent__traverse_subfolder, 0},
|
||||
{"traverse_slash_terminated_folder", &test_core_dirent__traverse_slash_terminated_folder, 0},
|
||||
{"dont_traverse_empty_folders", &test_core_dirent__dont_traverse_empty_folders, 0},
|
||||
{"traverse_weird_filenames", &test_core_dirent__traverse_weird_filenames, 0},
|
||||
{"0", &test_core_filebuf__0, 1},
|
||||
{"1", &test_core_filebuf__1, 1},
|
||||
{"2", &test_core_filebuf__2, 1},
|
||||
{"streq", &test_core_oid__streq, 2},
|
||||
{"0", &test_core_path__0, 3},
|
||||
{"1", &test_core_path__1, 3},
|
||||
{"2", &test_core_path__2, 3},
|
||||
{"5", &test_core_path__5, 3},
|
||||
{"6", &test_core_path__6, 3},
|
||||
{"delete_recursive", &test_core_rmdir__delete_recursive, 4},
|
||||
{"fail_to_delete_non_empty_dir", &test_core_rmdir__fail_to_delete_non_empty_dir, 4},
|
||||
{"0", &test_core_string__0, 5},
|
||||
{"1", &test_core_string__1, 5},
|
||||
{"int32", &test_core_strtol__int32, 6},
|
||||
{"int64", &test_core_strtol__int64, 6},
|
||||
{"0", &test_core_vector__0, 7},
|
||||
{"1", &test_core_vector__1, 7},
|
||||
{"2", &test_core_vector__2, 7},
|
||||
{"parsing", &test_network_remotes__parsing, 8},
|
||||
{"refspec_parsing", &test_network_remotes__refspec_parsing, 8},
|
||||
{"fnmatch", &test_network_remotes__fnmatch, 8},
|
||||
{"transform", &test_network_remotes__transform, 8},
|
||||
{"retrieve_tree_from_path_to_treeentry", &test_object_tree_frompath__retrieve_tree_from_path_to_treeentry, 9},
|
||||
{"fail_when_processing_an_unknown_tree_segment", &test_object_tree_frompath__fail_when_processing_an_unknown_tree_segment, 9},
|
||||
{"fail_when_processing_an_invalid_path", &test_object_tree_frompath__fail_when_processing_an_invalid_path, 9},
|
||||
{"hash_single_file", &test_status_single__hash_single_file, 10},
|
||||
{"whole_repository", &test_status_worktree__whole_repository, 11},
|
||||
{"empty_repository", &test_status_worktree__empty_repository, 11}
|
||||
{"hash_single_file", &test_status_single__hash_single_file, 0},
|
||||
{"whole_repository", &test_status_worktree__whole_repository, 1},
|
||||
{"empty_repository", &test_status_worktree__empty_repository, 1},
|
||||
{"parsing", &test_network_remotes__parsing, 2},
|
||||
{"refspec_parsing", &test_network_remotes__refspec_parsing, 2},
|
||||
{"fnmatch", &test_network_remotes__fnmatch, 2},
|
||||
{"transform", &test_network_remotes__transform, 2},
|
||||
{"dont_traverse_dot", &test_core_dirent__dont_traverse_dot, 3},
|
||||
{"traverse_subfolder", &test_core_dirent__traverse_subfolder, 3},
|
||||
{"traverse_slash_terminated_folder", &test_core_dirent__traverse_slash_terminated_folder, 3},
|
||||
{"dont_traverse_empty_folders", &test_core_dirent__dont_traverse_empty_folders, 3},
|
||||
{"traverse_weird_filenames", &test_core_dirent__traverse_weird_filenames, 3},
|
||||
{"0", &test_core_filebuf__0, 4},
|
||||
{"1", &test_core_filebuf__1, 4},
|
||||
{"2", &test_core_filebuf__2, 4},
|
||||
{"streq", &test_core_oid__streq, 5},
|
||||
{"0", &test_core_path__0, 6},
|
||||
{"1", &test_core_path__1, 6},
|
||||
{"2", &test_core_path__2, 6},
|
||||
{"5", &test_core_path__5, 6},
|
||||
{"6", &test_core_path__6, 6},
|
||||
{"delete_recursive", &test_core_rmdir__delete_recursive, 7},
|
||||
{"fail_to_delete_non_empty_dir", &test_core_rmdir__fail_to_delete_non_empty_dir, 7},
|
||||
{"0", &test_core_string__0, 8},
|
||||
{"1", &test_core_string__1, 8},
|
||||
{"int32", &test_core_strtol__int32, 9},
|
||||
{"int64", &test_core_strtol__int64, 9},
|
||||
{"0", &test_core_vector__0, 10},
|
||||
{"1", &test_core_vector__1, 10},
|
||||
{"2", &test_core_vector__2, 10},
|
||||
{"retrieve_tree_from_path_to_treeentry", &test_object_tree_frompath__retrieve_tree_from_path_to_treeentry, 11},
|
||||
{"fail_when_processing_an_unknown_tree_segment", &test_object_tree_frompath__fail_when_processing_an_unknown_tree_segment, 11},
|
||||
{"fail_when_processing_an_invalid_path", &test_object_tree_frompath__fail_when_processing_an_invalid_path, 11},
|
||||
{"find_invalid_chars_in_oid", &test_object_raw_chars__find_invalid_chars_in_oid, 12},
|
||||
{"build_valid_oid_from_raw_bytes", &test_object_raw_chars__build_valid_oid_from_raw_bytes, 12},
|
||||
{"succeed_on_copy_oid", &test_object_raw_compare__succeed_on_copy_oid, 13},
|
||||
{"succeed_on_oid_comparison_lesser", &test_object_raw_compare__succeed_on_oid_comparison_lesser, 13},
|
||||
{"succeed_on_oid_comparison_equal", &test_object_raw_compare__succeed_on_oid_comparison_equal, 13},
|
||||
{"succeed_on_oid_comparison_greater", &test_object_raw_compare__succeed_on_oid_comparison_greater, 13},
|
||||
{"compare_fmt_oids", &test_object_raw_compare__compare_fmt_oids, 13},
|
||||
{"compare_allocfmt_oids", &test_object_raw_compare__compare_allocfmt_oids, 13},
|
||||
{"compare_pathfmt_oids", &test_object_raw_compare__compare_pathfmt_oids, 13},
|
||||
{"succeed_on_oid_to_string_conversion", &test_object_raw_convert__succeed_on_oid_to_string_conversion, 14},
|
||||
{"succeed_on_oid_to_string_conversion_big", &test_object_raw_convert__succeed_on_oid_to_string_conversion_big, 14},
|
||||
{"fail_on_invalid_oid_string", &test_object_raw_fromstr__fail_on_invalid_oid_string, 15},
|
||||
{"succeed_on_valid_oid_string", &test_object_raw_fromstr__succeed_on_valid_oid_string, 15},
|
||||
{"hash_by_blocks", &test_object_raw_hash__hash_by_blocks, 16},
|
||||
{"hash_buffer_in_single_call", &test_object_raw_hash__hash_buffer_in_single_call, 16},
|
||||
{"hash_vector", &test_object_raw_hash__hash_vector, 16},
|
||||
{"hash_junk_data", &test_object_raw_hash__hash_junk_data, 16},
|
||||
{"hash_commit_object", &test_object_raw_hash__hash_commit_object, 16},
|
||||
{"hash_tree_object", &test_object_raw_hash__hash_tree_object, 16},
|
||||
{"hash_tag_object", &test_object_raw_hash__hash_tag_object, 16},
|
||||
{"hash_zero_length_object", &test_object_raw_hash__hash_zero_length_object, 16},
|
||||
{"hash_one_byte_object", &test_object_raw_hash__hash_one_byte_object, 16},
|
||||
{"hash_two_byte_object", &test_object_raw_hash__hash_two_byte_object, 16},
|
||||
{"hash_multi_byte_object", &test_object_raw_hash__hash_multi_byte_object, 16},
|
||||
{"oid_shortener_no_duplicates", &test_object_raw_short__oid_shortener_no_duplicates, 17},
|
||||
{"oid_shortener_stresstest_git_oid_shorten", &test_object_raw_short__oid_shortener_stresstest_git_oid_shorten, 17},
|
||||
{"validate_oid_size", &test_object_raw_size__validate_oid_size, 18},
|
||||
{"convert_type_to_string", &test_object_raw_type2string__convert_type_to_string, 19},
|
||||
{"convert_string_to_type", &test_object_raw_type2string__convert_string_to_type, 19},
|
||||
{"check_type_is_loose", &test_object_raw_type2string__check_type_is_loose, 19}
|
||||
};
|
||||
|
||||
static const struct clay_suite _all_suites[] = {
|
||||
{
|
||||
"status::single",
|
||||
{NULL, NULL, 0},
|
||||
{NULL, NULL, 0},
|
||||
&_all_callbacks[0], 1
|
||||
},
|
||||
{
|
||||
"status::worktree",
|
||||
{"initialize", &test_status_worktree__initialize, 1},
|
||||
{"cleanup", &test_status_worktree__cleanup, 1},
|
||||
&_all_callbacks[1], 2
|
||||
},
|
||||
{
|
||||
"network::remotes",
|
||||
{"initialize", &test_network_remotes__initialize, 2},
|
||||
{"cleanup", &test_network_remotes__cleanup, 2},
|
||||
&_all_callbacks[3], 4
|
||||
},
|
||||
{
|
||||
"core::dirent",
|
||||
{NULL, NULL, 0},
|
||||
{NULL, NULL, 0},
|
||||
&_all_callbacks[0], 5
|
||||
&_all_callbacks[7], 5
|
||||
},
|
||||
{
|
||||
"core::filebuf",
|
||||
{NULL, NULL, 0},
|
||||
{NULL, NULL, 0},
|
||||
&_all_callbacks[5], 3
|
||||
&_all_callbacks[12], 3
|
||||
},
|
||||
{
|
||||
"core::oid",
|
||||
{"initialize", &test_core_oid__initialize, 2},
|
||||
{"initialize", &test_core_oid__initialize, 5},
|
||||
{NULL, NULL, 0},
|
||||
&_all_callbacks[8], 1
|
||||
&_all_callbacks[15], 1
|
||||
},
|
||||
{
|
||||
"core::path",
|
||||
{NULL, NULL, 0},
|
||||
{NULL, NULL, 0},
|
||||
&_all_callbacks[9], 5
|
||||
&_all_callbacks[16], 5
|
||||
},
|
||||
{
|
||||
"core::rmdir",
|
||||
{"initialize", &test_core_rmdir__initialize, 4},
|
||||
{"initialize", &test_core_rmdir__initialize, 7},
|
||||
{NULL, NULL, 0},
|
||||
&_all_callbacks[14], 2
|
||||
&_all_callbacks[21], 2
|
||||
},
|
||||
{
|
||||
"core::string",
|
||||
{NULL, NULL, 0},
|
||||
{NULL, NULL, 0},
|
||||
&_all_callbacks[16], 2
|
||||
&_all_callbacks[23], 2
|
||||
},
|
||||
{
|
||||
"core::strtol",
|
||||
{NULL, NULL, 0},
|
||||
{NULL, NULL, 0},
|
||||
&_all_callbacks[18], 2
|
||||
&_all_callbacks[25], 2
|
||||
},
|
||||
{
|
||||
"core::vector",
|
||||
{NULL, NULL, 0},
|
||||
{NULL, NULL, 0},
|
||||
&_all_callbacks[20], 3
|
||||
},
|
||||
{
|
||||
"network::remotes",
|
||||
{"initialize", &test_network_remotes__initialize, 8},
|
||||
{"cleanup", &test_network_remotes__cleanup, 8},
|
||||
&_all_callbacks[23], 4
|
||||
},
|
||||
{
|
||||
"object::tree::frompath",
|
||||
{"initialize", &test_object_tree_frompath__initialize, 9},
|
||||
{"cleanup", &test_object_tree_frompath__cleanup, 9},
|
||||
&_all_callbacks[27], 3
|
||||
},
|
||||
{
|
||||
"status::single",
|
||||
{NULL, NULL, 0},
|
||||
{NULL, NULL, 0},
|
||||
&_all_callbacks[30], 1
|
||||
"object::tree::frompath",
|
||||
{"initialize", &test_object_tree_frompath__initialize, 11},
|
||||
{"cleanup", &test_object_tree_frompath__cleanup, 11},
|
||||
&_all_callbacks[30], 3
|
||||
},
|
||||
{
|
||||
"status::worktree",
|
||||
{"initialize", &test_status_worktree__initialize, 11},
|
||||
{"cleanup", &test_status_worktree__cleanup, 11},
|
||||
&_all_callbacks[31], 2
|
||||
"object::raw::chars",
|
||||
{NULL, NULL, 0},
|
||||
{NULL, NULL, 0},
|
||||
&_all_callbacks[33], 2
|
||||
},
|
||||
{
|
||||
"object::raw::compare",
|
||||
{NULL, NULL, 0},
|
||||
{NULL, NULL, 0},
|
||||
&_all_callbacks[35], 7
|
||||
},
|
||||
{
|
||||
"object::raw::convert",
|
||||
{NULL, NULL, 0},
|
||||
{NULL, NULL, 0},
|
||||
&_all_callbacks[42], 2
|
||||
},
|
||||
{
|
||||
"object::raw::fromstr",
|
||||
{NULL, NULL, 0},
|
||||
{NULL, NULL, 0},
|
||||
&_all_callbacks[44], 2
|
||||
},
|
||||
{
|
||||
"object::raw::hash",
|
||||
{NULL, NULL, 0},
|
||||
{NULL, NULL, 0},
|
||||
&_all_callbacks[46], 11
|
||||
},
|
||||
{
|
||||
"object::raw::short",
|
||||
{NULL, NULL, 0},
|
||||
{NULL, NULL, 0},
|
||||
&_all_callbacks[57], 2
|
||||
},
|
||||
{
|
||||
"object::raw::size",
|
||||
{NULL, NULL, 0},
|
||||
{NULL, NULL, 0},
|
||||
&_all_callbacks[59], 1
|
||||
},
|
||||
{
|
||||
"object::raw::type2string",
|
||||
{NULL, NULL, 0},
|
||||
{NULL, NULL, 0},
|
||||
&_all_callbacks[60], 3
|
||||
}
|
||||
};
|
||||
|
||||
static const char _suites_str[] = "core::dirent, core::filebuf, core::oid, core::path, core::rmdir, core::string, core::strtol, core::vector, network::remotes, object::tree::frompath, status::single, status::worktree";
|
||||
static const char _suites_str[] = "status::single, status::worktree, network::remotes, core::dirent, core::filebuf, core::oid, core::path, core::rmdir, core::string, core::strtol, core::vector, object::tree::frompath, object::raw::chars, object::raw::compare, object::raw::convert, object::raw::fromstr, object::raw::hash, object::raw::short, object::raw::size, object::raw::type2string";
|
||||
|
||||
int _MAIN_CC main(int argc, char *argv[])
|
||||
{
|
||||
return clay_test(
|
||||
argc, argv, _suites_str,
|
||||
_all_callbacks, 33,
|
||||
_all_suites, 12
|
||||
_all_callbacks, 63,
|
||||
_all_suites, 20
|
||||
);
|
||||
}
|
||||
|
52
tests-clay/object/raw/chars.c
Normal file
52
tests-clay/object/raw/chars.c
Normal file
@ -0,0 +1,52 @@
|
||||
|
||||
#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)));
|
||||
}
|
124
tests-clay/object/raw/compare.c
Normal file
124
tests-clay/object/raw/compare.c
Normal file
@ -0,0 +1,124 @@
|
||||
|
||||
#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);
|
||||
}
|
75
tests-clay/object/raw/convert.c
Normal file
75
tests-clay/object/raw/convert.c
Normal file
@ -0,0 +1,75 @@
|
||||
|
||||
#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');
|
||||
}
|
323
tests-clay/object/raw/data.h
Normal file
323
tests-clay/object/raw/data.h
Normal file
@ -0,0 +1,323 @@
|
||||
|
||||
/*
|
||||
* Raw data
|
||||
*/
|
||||
static unsigned char commit_data[] = {
|
||||
0x74, 0x72, 0x65, 0x65, 0x20, 0x64, 0x66, 0x66,
|
||||
0x32, 0x64, 0x61, 0x39, 0x30, 0x62, 0x32, 0x35,
|
||||
0x34, 0x65, 0x31, 0x62, 0x65, 0x62, 0x38, 0x38,
|
||||
0x39, 0x64, 0x31, 0x66, 0x31, 0x66, 0x31, 0x32,
|
||||
0x38, 0x38, 0x62, 0x65, 0x31, 0x38, 0x30, 0x33,
|
||||
0x37, 0x38, 0x32, 0x64, 0x66, 0x0a, 0x61, 0x75,
|
||||
0x74, 0x68, 0x6f, 0x72, 0x20, 0x41, 0x20, 0x55,
|
||||
0x20, 0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61,
|
||||
0x75, 0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78,
|
||||
0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
|
||||
0x6d, 0x3e, 0x20, 0x31, 0x32, 0x32, 0x37, 0x38,
|
||||
0x31, 0x34, 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30,
|
||||
0x30, 0x30, 0x30, 0x0a, 0x63, 0x6f, 0x6d, 0x6d,
|
||||
0x69, 0x74, 0x74, 0x65, 0x72, 0x20, 0x43, 0x20,
|
||||
0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72,
|
||||
0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74,
|
||||
0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d,
|
||||
0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e,
|
||||
0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34,
|
||||
0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30,
|
||||
0x30, 0x0a, 0x0a, 0x41, 0x20, 0x6f, 0x6e, 0x65,
|
||||
0x2d, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x63, 0x6f,
|
||||
0x6d, 0x6d, 0x69, 0x74, 0x20, 0x73, 0x75, 0x6d,
|
||||
0x6d, 0x61, 0x72, 0x79, 0x0a, 0x0a, 0x54, 0x68,
|
||||
0x65, 0x20, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x6f,
|
||||
0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f,
|
||||
0x6d, 0x6d, 0x69, 0x74, 0x20, 0x6d, 0x65, 0x73,
|
||||
0x73, 0x61, 0x67, 0x65, 0x2c, 0x20, 0x63, 0x6f,
|
||||
0x6e, 0x74, 0x61, 0x69, 0x6e, 0x69, 0x6e, 0x67,
|
||||
0x20, 0x66, 0x75, 0x72, 0x74, 0x68, 0x65, 0x72,
|
||||
0x20, 0x65, 0x78, 0x70, 0x6c, 0x61, 0x6e, 0x61,
|
||||
0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x6f, 0x66, 0x20,
|
||||
0x74, 0x68, 0x65, 0x20, 0x70, 0x75, 0x72, 0x70,
|
||||
0x6f, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74,
|
||||
0x68, 0x65, 0x20, 0x63, 0x68, 0x61, 0x6e, 0x67,
|
||||
0x65, 0x73, 0x20, 0x69, 0x6e, 0x74, 0x72, 0x6f,
|
||||
0x64, 0x75, 0x63, 0x65, 0x64, 0x20, 0x62, 0x79,
|
||||
0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x6d,
|
||||
0x6d, 0x69, 0x74, 0x2e, 0x0a, 0x0a, 0x53, 0x69,
|
||||
0x67, 0x6e, 0x65, 0x64, 0x2d, 0x6f, 0x66, 0x2d,
|
||||
0x62, 0x79, 0x3a, 0x20, 0x41, 0x20, 0x55, 0x20,
|
||||
0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61, 0x75,
|
||||
0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78, 0x61,
|
||||
0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d,
|
||||
0x3e, 0x0a,
|
||||
};
|
||||
|
||||
|
||||
static unsigned char tree_data[] = {
|
||||
0x31, 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x6f,
|
||||
0x6e, 0x65, 0x00, 0x8b, 0x13, 0x78, 0x91, 0x79,
|
||||
0x1f, 0xe9, 0x69, 0x27, 0xad, 0x78, 0xe6, 0x4b,
|
||||
0x0a, 0xad, 0x7b, 0xde, 0xd0, 0x8b, 0xdc, 0x31,
|
||||
0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x73, 0x6f,
|
||||
0x6d, 0x65, 0x00, 0xfd, 0x84, 0x30, 0xbc, 0x86,
|
||||
0x4c, 0xfc, 0xd5, 0xf1, 0x0e, 0x55, 0x90, 0xf8,
|
||||
0xa4, 0x47, 0xe0, 0x1b, 0x94, 0x2b, 0xfe, 0x31,
|
||||
0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x74, 0x77,
|
||||
0x6f, 0x00, 0x78, 0x98, 0x19, 0x22, 0x61, 0x3b,
|
||||
0x2a, 0xfb, 0x60, 0x25, 0x04, 0x2f, 0xf6, 0xbd,
|
||||
0x87, 0x8a, 0xc1, 0x99, 0x4e, 0x85, 0x31, 0x30,
|
||||
0x30, 0x36, 0x34, 0x34, 0x20, 0x7a, 0x65, 0x72,
|
||||
0x6f, 0x00, 0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1,
|
||||
0xd6, 0x43, 0x4b, 0x8b, 0x29, 0xae, 0x77, 0x5a,
|
||||
0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91,
|
||||
};
|
||||
|
||||
static unsigned char tag_data[] = {
|
||||
0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x33,
|
||||
0x64, 0x37, 0x66, 0x38, 0x61, 0x36, 0x61, 0x66,
|
||||
0x30, 0x37, 0x36, 0x63, 0x38, 0x63, 0x33, 0x66,
|
||||
0x32, 0x30, 0x30, 0x37, 0x31, 0x61, 0x38, 0x39,
|
||||
0x33, 0x35, 0x63, 0x64, 0x62, 0x65, 0x38, 0x32,
|
||||
0x32, 0x38, 0x35, 0x39, 0x34, 0x64, 0x31, 0x0a,
|
||||
0x74, 0x79, 0x70, 0x65, 0x20, 0x63, 0x6f, 0x6d,
|
||||
0x6d, 0x69, 0x74, 0x0a, 0x74, 0x61, 0x67, 0x20,
|
||||
0x76, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x0a, 0x74,
|
||||
0x61, 0x67, 0x67, 0x65, 0x72, 0x20, 0x43, 0x20,
|
||||
0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72,
|
||||
0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74,
|
||||
0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d,
|
||||
0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e,
|
||||
0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34,
|
||||
0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30,
|
||||
0x30, 0x0a, 0x0a, 0x54, 0x68, 0x69, 0x73, 0x20,
|
||||
0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74,
|
||||
0x61, 0x67, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63,
|
||||
0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x72, 0x65,
|
||||
0x6c, 0x65, 0x61, 0x73, 0x65, 0x20, 0x76, 0x30,
|
||||
0x2e, 0x30, 0x2e, 0x31, 0x0a,
|
||||
};
|
||||
|
||||
/*
|
||||
* Dummy data
|
||||
*/
|
||||
static unsigned char zero_data[] = {
|
||||
0x00,
|
||||
};
|
||||
|
||||
static unsigned char one_data[] = {
|
||||
0x0a,
|
||||
};
|
||||
|
||||
static unsigned char two_data[] = {
|
||||
0x61, 0x0a,
|
||||
};
|
||||
|
||||
static unsigned char some_data[] = {
|
||||
0x2f, 0x2a, 0x0a, 0x20, 0x2a, 0x20, 0x54, 0x68,
|
||||
0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20,
|
||||
0x69, 0x73, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20,
|
||||
0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65,
|
||||
0x3b, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x63, 0x61,
|
||||
0x6e, 0x20, 0x72, 0x65, 0x64, 0x69, 0x73, 0x74,
|
||||
0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x69,
|
||||
0x74, 0x20, 0x61, 0x6e, 0x64, 0x2f, 0x6f, 0x72,
|
||||
0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x0a,
|
||||
0x20, 0x2a, 0x20, 0x69, 0x74, 0x20, 0x75, 0x6e,
|
||||
0x64, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20,
|
||||
0x74, 0x65, 0x72, 0x6d, 0x73, 0x20, 0x6f, 0x66,
|
||||
0x20, 0x74, 0x68, 0x65, 0x20, 0x47, 0x4e, 0x55,
|
||||
0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c,
|
||||
0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20,
|
||||
0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2c,
|
||||
0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
|
||||
0x20, 0x32, 0x2c, 0x0a, 0x20, 0x2a, 0x20, 0x61,
|
||||
0x73, 0x20, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73,
|
||||
0x68, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x74,
|
||||
0x68, 0x65, 0x20, 0x46, 0x72, 0x65, 0x65, 0x20,
|
||||
0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65,
|
||||
0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74,
|
||||
0x69, 0x6f, 0x6e, 0x2e, 0x0a, 0x20, 0x2a, 0x0a,
|
||||
0x20, 0x2a, 0x20, 0x49, 0x6e, 0x20, 0x61, 0x64,
|
||||
0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74,
|
||||
0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x65,
|
||||
0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e,
|
||||
0x73, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65,
|
||||
0x20, 0x47, 0x4e, 0x55, 0x20, 0x47, 0x65, 0x6e,
|
||||
0x65, 0x72, 0x61, 0x6c, 0x20, 0x50, 0x75, 0x62,
|
||||
0x6c, 0x69, 0x63, 0x20, 0x4c, 0x69, 0x63, 0x65,
|
||||
0x6e, 0x73, 0x65, 0x2c, 0x0a, 0x20, 0x2a, 0x20,
|
||||
0x74, 0x68, 0x65, 0x20, 0x61, 0x75, 0x74, 0x68,
|
||||
0x6f, 0x72, 0x73, 0x20, 0x67, 0x69, 0x76, 0x65,
|
||||
0x20, 0x79, 0x6f, 0x75, 0x20, 0x75, 0x6e, 0x6c,
|
||||
0x69, 0x6d, 0x69, 0x74, 0x65, 0x64, 0x20, 0x70,
|
||||
0x65, 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f,
|
||||
0x6e, 0x20, 0x74, 0x6f, 0x20, 0x6c, 0x69, 0x6e,
|
||||
0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f,
|
||||
0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x0a, 0x20,
|
||||
0x2a, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f,
|
||||
0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x69,
|
||||
0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x69,
|
||||
0x6e, 0x74, 0x6f, 0x20, 0x63, 0x6f, 0x6d, 0x62,
|
||||
0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73,
|
||||
0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x6f, 0x74,
|
||||
0x68, 0x65, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x67,
|
||||
0x72, 0x61, 0x6d, 0x73, 0x2c, 0x0a, 0x20, 0x2a,
|
||||
0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x6f, 0x20,
|
||||
0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75,
|
||||
0x74, 0x65, 0x20, 0x74, 0x68, 0x6f, 0x73, 0x65,
|
||||
0x20, 0x63, 0x6f, 0x6d, 0x62, 0x69, 0x6e, 0x61,
|
||||
0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x77, 0x69,
|
||||
0x74, 0x68, 0x6f, 0x75, 0x74, 0x20, 0x61, 0x6e,
|
||||
0x79, 0x20, 0x72, 0x65, 0x73, 0x74, 0x72, 0x69,
|
||||
0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x20, 0x2a,
|
||||
0x20, 0x63, 0x6f, 0x6d, 0x69, 0x6e, 0x67, 0x20,
|
||||
0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65,
|
||||
0x20, 0x75, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20,
|
||||
0x74, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c,
|
||||
0x65, 0x2e, 0x20, 0x20, 0x28, 0x54, 0x68, 0x65,
|
||||
0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c,
|
||||
0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20,
|
||||
0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x0a,
|
||||
0x20, 0x2a, 0x20, 0x72, 0x65, 0x73, 0x74, 0x72,
|
||||
0x69, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20,
|
||||
0x64, 0x6f, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79,
|
||||
0x20, 0x69, 0x6e, 0x20, 0x6f, 0x74, 0x68, 0x65,
|
||||
0x72, 0x20, 0x72, 0x65, 0x73, 0x70, 0x65, 0x63,
|
||||
0x74, 0x73, 0x3b, 0x20, 0x66, 0x6f, 0x72, 0x20,
|
||||
0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2c,
|
||||
0x20, 0x74, 0x68, 0x65, 0x79, 0x20, 0x63, 0x6f,
|
||||
0x76, 0x65, 0x72, 0x0a, 0x20, 0x2a, 0x20, 0x6d,
|
||||
0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74,
|
||||
0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74,
|
||||
0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x2c,
|
||||
0x20, 0x61, 0x6e, 0x64, 0x20, 0x64, 0x69, 0x73,
|
||||
0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f,
|
||||
0x6e, 0x20, 0x77, 0x68, 0x65, 0x6e, 0x20, 0x6e,
|
||||
0x6f, 0x74, 0x20, 0x6c, 0x69, 0x6e, 0x6b, 0x65,
|
||||
0x64, 0x20, 0x69, 0x6e, 0x74, 0x6f, 0x0a, 0x20,
|
||||
0x2a, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x6d, 0x62,
|
||||
0x69, 0x6e, 0x65, 0x64, 0x20, 0x65, 0x78, 0x65,
|
||||
0x63, 0x75, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e,
|
||||
0x29, 0x0a, 0x20, 0x2a, 0x0a, 0x20, 0x2a, 0x20,
|
||||
0x54, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c,
|
||||
0x65, 0x20, 0x69, 0x73, 0x20, 0x64, 0x69, 0x73,
|
||||
0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64,
|
||||
0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20,
|
||||
0x68, 0x6f, 0x70, 0x65, 0x20, 0x74, 0x68, 0x61,
|
||||
0x74, 0x20, 0x69, 0x74, 0x20, 0x77, 0x69, 0x6c,
|
||||
0x6c, 0x20, 0x62, 0x65, 0x20, 0x75, 0x73, 0x65,
|
||||
0x66, 0x75, 0x6c, 0x2c, 0x20, 0x62, 0x75, 0x74,
|
||||
0x0a, 0x20, 0x2a, 0x20, 0x57, 0x49, 0x54, 0x48,
|
||||
0x4f, 0x55, 0x54, 0x20, 0x41, 0x4e, 0x59, 0x20,
|
||||
0x57, 0x41, 0x52, 0x52, 0x41, 0x4e, 0x54, 0x59,
|
||||
0x3b, 0x20, 0x77, 0x69, 0x74, 0x68, 0x6f, 0x75,
|
||||
0x74, 0x20, 0x65, 0x76, 0x65, 0x6e, 0x20, 0x74,
|
||||
0x68, 0x65, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x69,
|
||||
0x65, 0x64, 0x20, 0x77, 0x61, 0x72, 0x72, 0x61,
|
||||
0x6e, 0x74, 0x79, 0x20, 0x6f, 0x66, 0x0a, 0x20,
|
||||
0x2a, 0x20, 0x4d, 0x45, 0x52, 0x43, 0x48, 0x41,
|
||||
0x4e, 0x54, 0x41, 0x42, 0x49, 0x4c, 0x49, 0x54,
|
||||
0x59, 0x20, 0x6f, 0x72, 0x20, 0x46, 0x49, 0x54,
|
||||
0x4e, 0x45, 0x53, 0x53, 0x20, 0x46, 0x4f, 0x52,
|
||||
0x20, 0x41, 0x20, 0x50, 0x41, 0x52, 0x54, 0x49,
|
||||
0x43, 0x55, 0x4c, 0x41, 0x52, 0x20, 0x50, 0x55,
|
||||
0x52, 0x50, 0x4f, 0x53, 0x45, 0x2e, 0x20, 0x20,
|
||||
0x53, 0x65, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20,
|
||||
0x47, 0x4e, 0x55, 0x0a, 0x20, 0x2a, 0x20, 0x47,
|
||||
0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x50,
|
||||
0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, 0x4c, 0x69,
|
||||
0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x66, 0x6f,
|
||||
0x72, 0x20, 0x6d, 0x6f, 0x72, 0x65, 0x20, 0x64,
|
||||
0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x2e, 0x0a,
|
||||
0x20, 0x2a, 0x0a, 0x20, 0x2a, 0x20, 0x59, 0x6f,
|
||||
0x75, 0x20, 0x73, 0x68, 0x6f, 0x75, 0x6c, 0x64,
|
||||
0x20, 0x68, 0x61, 0x76, 0x65, 0x20, 0x72, 0x65,
|
||||
0x63, 0x65, 0x69, 0x76, 0x65, 0x64, 0x20, 0x61,
|
||||
0x20, 0x63, 0x6f, 0x70, 0x79, 0x20, 0x6f, 0x66,
|
||||
0x20, 0x74, 0x68, 0x65, 0x20, 0x47, 0x4e, 0x55,
|
||||
0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c,
|
||||
0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20,
|
||||
0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x0a,
|
||||
0x20, 0x2a, 0x20, 0x61, 0x6c, 0x6f, 0x6e, 0x67,
|
||||
0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68,
|
||||
0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
|
||||
0x61, 0x6d, 0x3b, 0x20, 0x73, 0x65, 0x65, 0x20,
|
||||
0x74, 0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65,
|
||||
0x20, 0x43, 0x4f, 0x50, 0x59, 0x49, 0x4e, 0x47,
|
||||
0x2e, 0x20, 0x20, 0x49, 0x66, 0x20, 0x6e, 0x6f,
|
||||
0x74, 0x2c, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65,
|
||||
0x20, 0x74, 0x6f, 0x0a, 0x20, 0x2a, 0x20, 0x74,
|
||||
0x68, 0x65, 0x20, 0x46, 0x72, 0x65, 0x65, 0x20,
|
||||
0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65,
|
||||
0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74,
|
||||
0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x35, 0x31, 0x20,
|
||||
0x46, 0x72, 0x61, 0x6e, 0x6b, 0x6c, 0x69, 0x6e,
|
||||
0x20, 0x53, 0x74, 0x72, 0x65, 0x65, 0x74, 0x2c,
|
||||
0x20, 0x46, 0x69, 0x66, 0x74, 0x68, 0x20, 0x46,
|
||||
0x6c, 0x6f, 0x6f, 0x72, 0x2c, 0x0a, 0x20, 0x2a,
|
||||
0x20, 0x42, 0x6f, 0x73, 0x74, 0x6f, 0x6e, 0x2c,
|
||||
0x20, 0x4d, 0x41, 0x20, 0x30, 0x32, 0x31, 0x31,
|
||||
0x30, 0x2d, 0x31, 0x33, 0x30, 0x31, 0x2c, 0x20,
|
||||
0x55, 0x53, 0x41, 0x2e, 0x0a, 0x20, 0x2a, 0x2f,
|
||||
0x0a,
|
||||
};
|
||||
|
||||
/*
|
||||
* SHA1 Hashes
|
||||
*/
|
||||
static char *commit_id = "3d7f8a6af076c8c3f20071a8935cdbe8228594d1";
|
||||
static char *tree_id = "dff2da90b254e1beb889d1f1f1288be1803782df";
|
||||
static char *tag_id = "09d373e1dfdc16b129ceec6dd649739911541e05";
|
||||
static char *zero_id = "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391";
|
||||
static char *one_id = "8b137891791fe96927ad78e64b0aad7bded08bdc";
|
||||
static char *two_id = "78981922613b2afb6025042ff6bd878ac1994e85";
|
||||
static char *some_id = "fd8430bc864cfcd5f10e5590f8a447e01b942bfe";
|
||||
|
||||
/*
|
||||
* In-memory objects
|
||||
*/
|
||||
static git_rawobj tree_obj = {
|
||||
tree_data,
|
||||
sizeof(tree_data),
|
||||
GIT_OBJ_TREE
|
||||
};
|
||||
|
||||
static git_rawobj tag_obj = {
|
||||
tag_data,
|
||||
sizeof(tag_data),
|
||||
GIT_OBJ_TAG
|
||||
};
|
||||
|
||||
static git_rawobj zero_obj = {
|
||||
zero_data,
|
||||
0,
|
||||
GIT_OBJ_BLOB
|
||||
};
|
||||
|
||||
static git_rawobj one_obj = {
|
||||
one_data,
|
||||
sizeof(one_data),
|
||||
GIT_OBJ_BLOB
|
||||
};
|
||||
|
||||
static git_rawobj two_obj = {
|
||||
two_data,
|
||||
sizeof(two_data),
|
||||
GIT_OBJ_BLOB
|
||||
};
|
||||
|
||||
static git_rawobj commit_obj = {
|
||||
commit_data,
|
||||
sizeof(commit_data),
|
||||
GIT_OBJ_COMMIT
|
||||
};
|
||||
|
||||
static git_rawobj some_obj = {
|
||||
some_data,
|
||||
sizeof(some_data),
|
||||
GIT_OBJ_BLOB
|
||||
};
|
||||
|
||||
static git_rawobj junk_obj = {
|
||||
NULL,
|
||||
0,
|
||||
GIT_OBJ_BAD
|
||||
};
|
30
tests-clay/object/raw/fromstr.c
Normal file
30
tests-clay/object/raw/fromstr.c
Normal file
@ -0,0 +1,30 @@
|
||||
|
||||
#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)));
|
||||
|
||||
}
|
162
tests-clay/object/raw/hash.c
Normal file
162
tests-clay/object/raw/hash.c
Normal file
@ -0,0 +1,162 @@
|
||||
|
||||
#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);
|
||||
}
|
94
tests-clay/object/raw/short.c
Normal file
94
tests-clay/object/raw/short.c
Normal file
@ -0,0 +1,94 @@
|
||||
|
||||
#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
|
||||
}
|
13
tests-clay/object/raw/size.c
Normal file
13
tests-clay/object/raw/size.c
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
#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);
|
||||
}
|
54
tests-clay/object/raw/type2string.c
Normal file
54
tests-clay/object/raw/type2string.c
Normal file
@ -0,0 +1,54 @@
|
||||
|
||||
#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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user