summaryrefslogtreecommitdiff
path: root/tests-clay
diff options
context:
space:
mode:
Diffstat (limited to 'tests-clay')
-rw-r--r--tests-clay/README.md2
-rwxr-xr-xtests-clay/clay217
-rw-r--r--tests-clay/clay.h66
-rw-r--r--tests-clay/clay_libgit2.h2
-rw-r--r--tests-clay/clay_main.c533
-rw-r--r--tests-clay/config/stress.c41
-rw-r--r--tests-clay/core/dirent.c6
-rw-r--r--tests-clay/core/filebuf.c6
-rw-r--r--tests-clay/core/path.c4
-rw-r--r--tests-clay/core/rmdir.c14
-rw-r--r--tests-clay/core/vector.c4
-rw-r--r--tests-clay/index/rename.c60
-rw-r--r--tests-clay/object/raw/chars.c52
-rw-r--r--tests-clay/object/raw/compare.c124
-rw-r--r--tests-clay/object/raw/convert.c75
-rw-r--r--tests-clay/object/raw/data.h323
-rw-r--r--tests-clay/object/raw/fromstr.c30
-rw-r--r--tests-clay/object/raw/hash.c162
-rw-r--r--tests-clay/object/raw/short.c94
-rw-r--r--tests-clay/object/raw/size.c13
-rw-r--r--tests-clay/object/raw/type2string.c54
-rw-r--r--tests-clay/object/tree/frompath.c2
-rw-r--r--tests-clay/status/single.c2
-rw-r--r--tests-clay/status/worktree.c2
24 files changed, 1590 insertions, 298 deletions
diff --git a/tests-clay/README.md b/tests-clay/README.md
index 4939f5717..6b5a659f8 100644
--- a/tests-clay/README.md
+++ b/tests-clay/README.md
@@ -11,7 +11,7 @@ https://github.com/tanoku/clay
* Mix the tests:
- ./clay
+ ./clay -vtap .
* Make sure you actually build the tests by setting:
diff --git a/tests-clay/clay b/tests-clay/clay
index d042a2a1c..a40f6601a 100755
--- a/tests-clay/clay
+++ b/tests-clay/clay
@@ -4,13 +4,13 @@ from __future__ import with_statement
from string import Template
import re, fnmatch, os
-VERSION = "0.8.0"
+VERSION = "0.9.0"
-TEST_FUNC_REGEX = r"^(void\s+(test_%s__(\w+))\(\s*(void)?\s*\))\s*\{"
+TEST_FUNC_REGEX = r"^(void\s+(test_%s__(\w+))\(\s*void\s*\))\s*\{"
CLAY_HEADER = """
/*
- * Clay v0.7.0
+ * Clay v0.9.0
*
* This is an autogenerated file. Do not modify.
* To add new unit tests or suites, regenerate the whole
@@ -18,27 +18,17 @@ CLAY_HEADER = """
*/
"""
-TEMPLATE_SUITE = Template(
-r"""
- {
- "${clean_name}",
- ${initialize},
- ${cleanup},
- ${cb_ptr}, ${cb_count}
- }
-""")
-
def main():
from optparse import OptionParser
parser = OptionParser()
parser.add_option('-c', '--clay-path', dest='clay_path')
- parser.add_option('-v', '--report-to', dest='print_mode', default='stdout')
+ parser.add_option('-v', '--report-to', dest='print_mode', default='default')
options, args = parser.parse_args()
- for folder in args:
+ for folder in args or ['.']:
builder = ClayTestBuilder(folder,
clay_path = options.clay_path,
print_mode = options.print_mode)
@@ -47,17 +37,22 @@ def main():
class ClayTestBuilder:
- def __init__(self, path, clay_path = None, print_mode = 'stdout'):
+ def __init__(self, path, clay_path = None, print_mode = 'default'):
self.declarations = []
- self.callbacks = []
- self.suites = []
- self.suite_list = []
+ self.suite_names = []
+ self.callback_data = {}
+ self.suite_data = {}
self.clay_path = os.path.abspath(clay_path) if clay_path else None
- self.print_mode = print_mode
self.path = os.path.abspath(path)
- self.modules = ["clay_sandbox.c", "clay_fixtures.c", "clay_fs.c"]
+ self.modules = [
+ "clay_sandbox.c",
+ "clay_fixtures.c",
+ "clay_fs.c"
+ ]
+
+ self.modules.append("clay_print_%s.c" % print_mode)
print("Loading test suites...")
@@ -66,7 +61,6 @@ class ClayTestBuilder:
module_root = [c for c in module_root.split(os.sep) if c]
tests_in_module = fnmatch.filter(files, "*.c")
- tests_in_module.sort()
for test_file in tests_in_module:
full_path = os.path.join(root, test_file)
@@ -75,51 +69,107 @@ class ClayTestBuilder:
with open(full_path) as f:
self._process_test_file(test_name, f.read())
- if not self.suites:
+ if not self.suite_data:
raise RuntimeError(
'No tests found under "%s"' % folder_name)
def render(self):
main_file = os.path.join(self.path, 'clay_main.c')
with open(main_file, "w") as out:
- template = Template(self._load_file('clay.c'))
+ out.write(self._render_main())
+
+ header_file = os.path.join(self.path, 'clay.h')
+ with open(header_file, "w") as out:
+ out.write(self._render_header())
+
+ print ('Written Clay suite to "%s"' % self.path)
+
+ #####################################################
+ # Internal methods
+ #####################################################
+
+ def _render_cb(self, cb):
+ return '{"%s", &%s}' % (cb['short_name'], cb['symbol'])
+
+ def _render_suite(self, suite):
+ template = Template(
+r"""
+ {
+ "${clean_name}",
+ ${initialize},
+ ${cleanup},
+ ${cb_ptr}, ${cb_count}
+ }
+""")
- output = template.substitute(
- clay_print = self._get_print_method(),
- clay_modules = self._get_modules(),
+ callbacks = {}
+ for cb in ['initialize', 'cleanup']:
+ callbacks[cb] = (self._render_cb(suite[cb])
+ if suite[cb] else "{NULL, NULL}")
+
+ return template.substitute(
+ clean_name = suite['name'].replace("_", "::"),
+ initialize = callbacks['initialize'],
+ cleanup = callbacks['cleanup'],
+ cb_ptr = "_clay_cb_%s" % suite['name'],
+ cb_count = suite['cb_count']
+ ).strip()
- suites_str = ", ".join(self.suite_list),
+ def _render_callbacks(self, suite_name, callbacks):
+ template = Template(
+r"""
+static const struct clay_func _clay_cb_${suite_name}[] = {
+ ${callbacks}
+};
+""")
+ callbacks = [
+ self._render_cb(cb)
+ for cb in callbacks
+ if cb['short_name'] not in ('initialize', 'cleanup')
+ ]
+
+ return template.substitute(
+ suite_name = suite_name,
+ callbacks = ",\n\t".join(callbacks)
+ ).strip()
- test_callbacks = ",\n\t".join(self.callbacks),
- cb_count = len(self.callbacks),
+ def _render_header(self):
+ template = Template(self._load_file('clay.h'))
- test_suites = ",\n\t".join(self.suites),
- suite_count = len(self.suites),
- )
+ declarations = "\n".join(
+ "extern %s;" % decl
+ for decl in sorted(self.declarations)
+ )
- out.write(output)
+ return template.substitute(
+ extern_declarations = declarations,
+ )
- header_file = os.path.join(self.path, 'clay.h')
- with open(header_file, "w") as out:
- template = Template(self._load_file('clay.h'))
+ def _render_main(self):
+ template = Template(self._load_file('clay.c'))
+ suite_names = sorted(self.suite_names)
- output = template.substitute(
- extern_declarations = "\n".join(self.declarations),
- )
+ suite_data = [
+ self._render_suite(self.suite_data[s])
+ for s in suite_names
+ ]
- out.write(output)
+ callbacks = [
+ self._render_callbacks(s, self.callback_data[s])
+ for s in suite_names
+ ]
- print ('Written Clay suite to "%s"' % self.path)
+ callback_count = sum(
+ len(cbs) for cbs in self.callback_data.values()
+ )
- #####################################################
- # Internal methods
- #####################################################
- def _get_print_method(self):
- return {
- 'stdout' : 'printf(__VA_ARGS__)',
- 'stderr' : 'fprintf(stderr, __VA_ARGS__)',
- 'silent' : ''
- }[self.print_mode]
+ return template.substitute(
+ clay_modules = self._get_modules(),
+ clay_callbacks = "\n".join(callbacks),
+ clay_suites = ",\n\t".join(suite_data),
+ clay_suite_count = len(suite_data),
+ clay_callback_count = callback_count,
+ )
def _load_file(self, filename):
if self.clay_path:
@@ -151,52 +201,67 @@ class ClayTestBuilder:
return comment
- def _process_test_file(self, test_name, contents):
- regex_string = TEST_FUNC_REGEX % test_name
+ def _process_test_file(self, suite_name, contents):
+ regex_string = TEST_FUNC_REGEX % suite_name
regex = re.compile(regex_string, re.MULTILINE)
callbacks = []
- initialize = cleanup = "{NULL, NULL, 0}"
+ initialize = cleanup = None
- for (declaration, symbol, short_name, _) in regex.findall(contents):
- self.declarations.append("extern %s;" % declaration)
- func_ptr = '{"%s", &%s, %d}' % (
- short_name, symbol, len(self.suites)
- )
+ for (declaration, symbol, short_name) in regex.findall(contents):
+ data = {
+ "short_name" : short_name,
+ "declaration" : declaration,
+ "symbol" : symbol
+ }
if short_name == 'initialize':
- initialize = func_ptr
+ initialize = data
elif short_name == 'cleanup':
- cleanup = func_ptr
+ cleanup = data
else:
- callbacks.append(func_ptr)
+ callbacks.append(data)
if not callbacks:
return
- clean_name = test_name.replace("_", "::")
+ tests_in_suite = len(callbacks)
- suite = TEMPLATE_SUITE.substitute(
- clean_name = clean_name,
- initialize = initialize,
- cleanup = cleanup,
- cb_ptr = "&_all_callbacks[%d]" % len(self.callbacks),
- cb_count = len(callbacks)
- ).strip()
+ suite = {
+ "name" : suite_name,
+ "initialize" : initialize,
+ "cleanup" : cleanup,
+ "cb_count" : tests_in_suite
+ }
+
+ if initialize:
+ self.declarations.append(initialize['declaration'])
+
+ if cleanup:
+ self.declarations.append(cleanup['declaration'])
+
+ self.declarations += [
+ callback['declaration']
+ for callback in callbacks
+ ]
+
+ callbacks.sort(key=lambda x: x['short_name'])
+ self.callback_data[suite_name] = callbacks
+ self.suite_data[suite_name] = suite
+ self.suite_names.append(suite_name)
- self.callbacks += callbacks
- self.suites.append(suite)
- self.suite_list.append(clean_name)
+ print(" %s (%d tests)" % (suite_name, tests_in_suite))
- print(" %s (%d tests)" % (clean_name, len(callbacks)))
CLAY_FILES = {
-"clay.c" : r"""eJy9GWtT20jys/wrZk3AEggHyDd74SqVu1xRl2WrAqlsFaFUsjTGc9HDqxkFONb//brnpdHLux+uji+gnu6efndPc8CKJKtTSn6OOaeVmG+uJgcWxqn4d77twESasVUPxsouqGLFYxuWx2KDkMnbY1LR32tW0ZSsy4rwuEhX5TMQkOO3LpMX/la8bCnv8AYwF7EUdnKQ0jUrKEmy+CXawqXCn8/nAXnz2kB2gMbWgEiir9c37y4mB55l9sSKtHxSNzRQrU4D4BuaZfGWdcAp6JBoQTwtSfTL++ub6MMHEkVJSpPMOUKp/S2YIYQ/AxK1vxu8/Dsw1gd5mVJAbUAOXrKxQBI5Hw1GnCSU8zarPsyVsErrrQ+/pHj2A5Vg60LaMPrl+uafX99dRBEAvW0VP+YxSco8p2B8CI6QTKW53l1MkbPDuki2L74oQ7Kuyjwkoow4+w+IpI8iLg812GBFd5+/3Hx4f/cPl9nX6Nd/kbMLB3IbXd/+/fqz/xwQ338mRyQCyEeABOSnS3LmEuffBc23kTFBRgtp4B4QSGiRsvXEwyhE3UHQOhHKceT27v1ddLecHNCM01awQIA+xQzjgkCs459blvoXgQzvBq8uGKSOCqlO8PSu7NwoxWpyYorBPt9MJx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yeSg=="""
}
if __name__ == '__main__':
main()
diff --git a/tests-clay/clay.h b/tests-clay/clay.h
index bc4267b66..db3a475b2 100644
--- a/tests-clay/clay.h
+++ b/tests-clay/clay.h
@@ -37,16 +37,16 @@ void cl_fixture_cleanup(const char *fixture_name);
/**
* Assertion macros with no error message
*/
-#define cl_must_pass(expr) cl_must_pass_((expr), NULL)
-#define cl_must_fail(expr) cl_must_fail_((expr), NULL)
-#define cl_assert(expr) cl_assert_((expr), NULL)
+#define cl_must_pass(expr) cl_must_pass_(expr, NULL)
+#define cl_must_fail(expr) cl_must_fail_(expr, NULL)
+#define cl_assert(expr) cl_assert_(expr, NULL)
/**
* Check macros with no error message
*/
-#define cl_check_pass(expr) cl_check_pass_((expr), NULL)
-#define cl_check_fail(expr) cl_check_fail_((expr), NULL)
-#define cl_check(expr) cl_check_((expr), NULL)
+#define cl_check_pass(expr) cl_check_pass_(expr, NULL)
+#define cl_check_fail(expr) cl_check_fail_(expr, NULL)
+#define cl_check(expr) cl_check_(expr, NULL)
/**
* Forced failure/warning
@@ -57,10 +57,13 @@ void cl_fixture_cleanup(const char *fixture_name);
/**
* Test method declarations
*/
+extern void test_config_stress__cleanup(void);
+extern void test_config_stress__dont_break_on_invalid_input(void);
+extern void test_config_stress__initialize(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);
extern void test_core_dirent__dont_traverse_empty_folders(void);
+extern void test_core_dirent__traverse_slash_terminated_folder(void);
+extern void test_core_dirent__traverse_subfolder(void);
extern void test_core_dirent__traverse_weird_filenames(void);
extern void test_core_filebuf__0(void);
extern void test_core_filebuf__1(void);
@@ -72,9 +75,9 @@ extern void test_core_path__1(void);
extern void test_core_path__2(void);
extern void test_core_path__5(void);
extern void test_core_path__6(void);
-extern void test_core_rmdir__initialize(void);
extern void test_core_rmdir__delete_recursive(void);
extern void test_core_rmdir__fail_to_delete_non_empty_dir(void);
+extern void test_core_rmdir__initialize(void);
extern void test_core_string__0(void);
extern void test_core_string__1(void);
extern void test_core_strtol__int32(void);
@@ -82,21 +85,52 @@ 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_index_rename__single_file(void);
extern void test_network_remotes__cleanup(void);
+extern void test_network_remotes__fnmatch(void);
+extern void test_network_remotes__initialize(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_raw_chars__build_valid_oid_from_raw_bytes(void);
+extern void test_object_raw_chars__find_invalid_chars_in_oid(void);
+extern void test_object_raw_compare__compare_allocfmt_oids(void);
+extern void test_object_raw_compare__compare_fmt_oids(void);
+extern void test_object_raw_compare__compare_pathfmt_oids(void);
+extern void test_object_raw_compare__succeed_on_copy_oid(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__succeed_on_oid_comparison_lesser(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_buffer_in_single_call(void);
+extern void test_object_raw_hash__hash_by_blocks(void);
+extern void test_object_raw_hash__hash_commit_object(void);
+extern void test_object_raw_hash__hash_junk_data(void);
+extern void test_object_raw_hash__hash_multi_byte_object(void);
+extern void test_object_raw_hash__hash_one_byte_object(void);
+extern void test_object_raw_hash__hash_tag_object(void);
+extern void test_object_raw_hash__hash_tree_object(void);
+extern void test_object_raw_hash__hash_two_byte_object(void);
+extern void test_object_raw_hash__hash_vector(void);
+extern void test_object_raw_hash__hash_zero_length_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__check_type_is_loose(void);
+extern void test_object_raw_type2string__convert_string_to_type(void);
+extern void test_object_raw_type2string__convert_type_to_string(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_object_tree_frompath__fail_when_processing_an_unknown_tree_segment(void);
+extern void test_object_tree_frompath__initialize(void);
+extern void test_object_tree_frompath__retrieve_tree_from_path_to_treeentry(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_status_worktree__initialize(void);
+extern void test_status_worktree__whole_repository(void);
#endif
diff --git a/tests-clay/clay_libgit2.h b/tests-clay/clay_libgit2.h
index ab3cf67ec..a5208962e 100644
--- a/tests-clay/clay_libgit2.h
+++ b/tests-clay/clay_libgit2.h
@@ -23,6 +23,6 @@
* just for consistency. Use with `git_` library
* calls that are supposed to fail!
*/
-#define cl_git_fail(expr) cl_must_fail((expr))
+#define cl_git_fail(expr) cl_must_fail(expr)
#endif
diff --git a/tests-clay/clay_main.c b/tests-clay/clay_main.c
index da90872ce..4ad6fc467 100644
--- a/tests-clay/clay_main.c
+++ b/tests-clay/clay_main.c
@@ -4,13 +4,12 @@
#include <stdio.h>
#include <string.h>
#include <math.h>
+#include <stdarg.h>
/* required for sandboxing */
#include <sys/types.h>
#include <sys/stat.h>
-#define clay_print(...) printf(__VA_ARGS__)
-
#ifdef _WIN32
# include <windows.h>
# include <io.h>
@@ -82,7 +81,6 @@ static struct {
struct clay_func {
const char *name;
void (*ptr)(void);
- size_t suite_n;
};
struct clay_suite {
@@ -93,10 +91,268 @@ struct clay_suite {
size_t test_count;
};
+/* From clay_print_*.c */
+static void clay_print_init(int test_count, int suite_count, const char *suite_names);
+static void clay_print_shutdown(int test_count, int suite_count, int error_count);
+static void clay_print_error(int num, const struct clay_error *error);
+static void clay_print_ontest(const char *test_name, int test_number, int failed);
+static void clay_print_onsuite(const char *suite_name);
+static void clay_print_onabort(const char *msg, ...);
+
/* From clay_sandbox.c */
static void clay_unsandbox(void);
static int clay_sandbox(void);
+/* Autogenerated test data by clay */
+static const struct clay_func _clay_cb_config_stress[] = {
+ {"dont_break_on_invalid_input", &test_config_stress__dont_break_on_invalid_input}
+};
+static const struct clay_func _clay_cb_core_dirent[] = {
+ {"dont_traverse_dot", &test_core_dirent__dont_traverse_dot},
+ {"dont_traverse_empty_folders", &test_core_dirent__dont_traverse_empty_folders},
+ {"traverse_slash_terminated_folder", &test_core_dirent__traverse_slash_terminated_folder},
+ {"traverse_subfolder", &test_core_dirent__traverse_subfolder},
+ {"traverse_weird_filenames", &test_core_dirent__traverse_weird_filenames}
+};
+static const struct clay_func _clay_cb_core_filebuf[] = {
+ {"0", &test_core_filebuf__0},
+ {"1", &test_core_filebuf__1},
+ {"2", &test_core_filebuf__2}
+};
+static const struct clay_func _clay_cb_core_oid[] = {
+ {"streq", &test_core_oid__streq}
+};
+static const struct clay_func _clay_cb_core_path[] = {
+ {"0", &test_core_path__0},
+ {"1", &test_core_path__1},
+ {"2", &test_core_path__2},
+ {"5", &test_core_path__5},
+ {"6", &test_core_path__6}
+};
+static const struct clay_func _clay_cb_core_rmdir[] = {
+ {"delete_recursive", &test_core_rmdir__delete_recursive},
+ {"fail_to_delete_non_empty_dir", &test_core_rmdir__fail_to_delete_non_empty_dir}
+};
+static const struct clay_func _clay_cb_core_string[] = {
+ {"0", &test_core_string__0},
+ {"1", &test_core_string__1}
+};
+static const struct clay_func _clay_cb_core_strtol[] = {
+ {"int32", &test_core_strtol__int32},
+ {"int64", &test_core_strtol__int64}
+};
+static const struct clay_func _clay_cb_core_vector[] = {
+ {"0", &test_core_vector__0},
+ {"1", &test_core_vector__1},
+ {"2", &test_core_vector__2}
+};
+static const struct clay_func _clay_cb_index_rename[] = {
+ {"single_file", &test_index_rename__single_file}
+};
+static const struct clay_func _clay_cb_network_remotes[] = {
+ {"fnmatch", &test_network_remotes__fnmatch},
+ {"parsing", &test_network_remotes__parsing},
+ {"refspec_parsing", &test_network_remotes__refspec_parsing},
+ {"transform", &test_network_remotes__transform}
+};
+static const struct clay_func _clay_cb_object_raw_chars[] = {
+ {"build_valid_oid_from_raw_bytes", &test_object_raw_chars__build_valid_oid_from_raw_bytes},
+ {"find_invalid_chars_in_oid", &test_object_raw_chars__find_invalid_chars_in_oid}
+};
+static const struct clay_func _clay_cb_object_raw_compare[] = {
+ {"compare_allocfmt_oids", &test_object_raw_compare__compare_allocfmt_oids},
+ {"compare_fmt_oids", &test_object_raw_compare__compare_fmt_oids},
+ {"compare_pathfmt_oids", &test_object_raw_compare__compare_pathfmt_oids},
+ {"succeed_on_copy_oid", &test_object_raw_compare__succeed_on_copy_oid},
+ {"succeed_on_oid_comparison_equal", &test_object_raw_compare__succeed_on_oid_comparison_equal},
+ {"succeed_on_oid_comparison_greater", &test_object_raw_compare__succeed_on_oid_comparison_greater},
+ {"succeed_on_oid_comparison_lesser", &test_object_raw_compare__succeed_on_oid_comparison_lesser}
+};
+static const struct clay_func _clay_cb_object_raw_convert[] = {
+ {"succeed_on_oid_to_string_conversion", &test_object_raw_convert__succeed_on_oid_to_string_conversion},
+ {"succeed_on_oid_to_string_conversion_big", &test_object_raw_convert__succeed_on_oid_to_string_conversion_big}
+};
+static const struct clay_func _clay_cb_object_raw_fromstr[] = {
+ {"fail_on_invalid_oid_string", &test_object_raw_fromstr__fail_on_invalid_oid_string},
+ {"succeed_on_valid_oid_string", &test_object_raw_fromstr__succeed_on_valid_oid_string}
+};
+static const struct clay_func _clay_cb_object_raw_hash[] = {
+ {"hash_buffer_in_single_call", &test_object_raw_hash__hash_buffer_in_single_call},
+ {"hash_by_blocks", &test_object_raw_hash__hash_by_blocks},
+ {"hash_commit_object", &test_object_raw_hash__hash_commit_object},
+ {"hash_junk_data", &test_object_raw_hash__hash_junk_data},
+ {"hash_multi_byte_object", &test_object_raw_hash__hash_multi_byte_object},
+ {"hash_one_byte_object", &test_object_raw_hash__hash_one_byte_object},
+ {"hash_tag_object", &test_object_raw_hash__hash_tag_object},
+ {"hash_tree_object", &test_object_raw_hash__hash_tree_object},
+ {"hash_two_byte_object", &test_object_raw_hash__hash_two_byte_object},
+ {"hash_vector", &test_object_raw_hash__hash_vector},
+ {"hash_zero_length_object", &test_object_raw_hash__hash_zero_length_object}
+};
+static const struct clay_func _clay_cb_object_raw_short[] = {
+ {"oid_shortener_no_duplicates", &test_object_raw_short__oid_shortener_no_duplicates},
+ {"oid_shortener_stresstest_git_oid_shorten", &test_object_raw_short__oid_shortener_stresstest_git_oid_shorten}
+};
+static const struct clay_func _clay_cb_object_raw_size[] = {
+ {"validate_oid_size", &test_object_raw_size__validate_oid_size}
+};
+static const struct clay_func _clay_cb_object_raw_type2string[] = {
+ {"check_type_is_loose", &test_object_raw_type2string__check_type_is_loose},
+ {"convert_string_to_type", &test_object_raw_type2string__convert_string_to_type},
+ {"convert_type_to_string", &test_object_raw_type2string__convert_type_to_string}
+};
+static const struct clay_func _clay_cb_object_tree_frompath[] = {
+ {"fail_when_processing_an_invalid_path", &test_object_tree_frompath__fail_when_processing_an_invalid_path},
+ {"fail_when_processing_an_unknown_tree_segment", &test_object_tree_frompath__fail_when_processing_an_unknown_tree_segment},
+ {"retrieve_tree_from_path_to_treeentry", &test_object_tree_frompath__retrieve_tree_from_path_to_treeentry}
+};
+static const struct clay_func _clay_cb_status_single[] = {
+ {"hash_single_file", &test_status_single__hash_single_file}
+};
+static const struct clay_func _clay_cb_status_worktree[] = {
+ {"empty_repository", &test_status_worktree__empty_repository},
+ {"whole_repository", &test_status_worktree__whole_repository}
+};
+
+static const struct clay_suite _clay_suites[] = {
+ {
+ "config::stress",
+ {"initialize", &test_config_stress__initialize},
+ {"cleanup", &test_config_stress__cleanup},
+ _clay_cb_config_stress, 1
+ },
+ {
+ "core::dirent",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_core_dirent, 5
+ },
+ {
+ "core::filebuf",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_core_filebuf, 3
+ },
+ {
+ "core::oid",
+ {"initialize", &test_core_oid__initialize},
+ {NULL, NULL},
+ _clay_cb_core_oid, 1
+ },
+ {
+ "core::path",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_core_path, 5
+ },
+ {
+ "core::rmdir",
+ {"initialize", &test_core_rmdir__initialize},
+ {NULL, NULL},
+ _clay_cb_core_rmdir, 2
+ },
+ {
+ "core::string",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_core_string, 2
+ },
+ {
+ "core::strtol",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_core_strtol, 2
+ },
+ {
+ "core::vector",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_core_vector, 3
+ },
+ {
+ "index::rename",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_index_rename, 1
+ },
+ {
+ "network::remotes",
+ {"initialize", &test_network_remotes__initialize},
+ {"cleanup", &test_network_remotes__cleanup},
+ _clay_cb_network_remotes, 4
+ },
+ {
+ "object::raw::chars",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_object_raw_chars, 2
+ },
+ {
+ "object::raw::compare",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_object_raw_compare, 7
+ },
+ {
+ "object::raw::convert",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_object_raw_convert, 2
+ },
+ {
+ "object::raw::fromstr",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_object_raw_fromstr, 2
+ },
+ {
+ "object::raw::hash",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_object_raw_hash, 11
+ },
+ {
+ "object::raw::short",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_object_raw_short, 2
+ },
+ {
+ "object::raw::size",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_object_raw_size, 1
+ },
+ {
+ "object::raw::type2string",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_object_raw_type2string, 3
+ },
+ {
+ "object::tree::frompath",
+ {"initialize", &test_object_tree_frompath__initialize},
+ {"cleanup", &test_object_tree_frompath__cleanup},
+ _clay_cb_object_tree_frompath, 3
+ },
+ {
+ "status::single",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_status_single, 1
+ },
+ {
+ "status::worktree",
+ {"initialize", &test_status_worktree__initialize},
+ {"cleanup", &test_status_worktree__cleanup},
+ _clay_cb_status_worktree, 2
+ }
+};
+
+static size_t _clay_suite_count = 22;
+static size_t _clay_callback_count = 65;
+
+/* Core test functions */
static void
clay_run_test(
const struct clay_func *test,
@@ -128,28 +384,11 @@ clay_run_test(
_clay.local_cleanup = NULL;
_clay.local_cleanup_payload = NULL;
- clay_print("%c", (_clay.suite_errors > error_st) ? 'F' : '.');
-}
-
-static void
-clay_print_error(int num, const struct clay_error *error)
-{
- clay_print(" %d) Failure:\n", num);
-
- clay_print("%s::%s (%s) [%s:%d] [-t%d]\n",
- error->suite,
- error->test,
- "no description",
- error->file,
- error->line_number,
- error->test_number);
-
- clay_print(" %s\n", error->error_msg);
-
- if (error->description != NULL)
- clay_print(" %s\n", error->description);
-
- clay_print("\n");
+ clay_print_ontest(
+ test->name,
+ _clay.test_count,
+ (_clay.suite_errors > error_st)
+ );
}
static void
@@ -166,6 +405,8 @@ clay_report_errors(void)
free(error);
error = next;
}
+
+ _clay.errors = _clay.last_error = NULL;
}
static void
@@ -174,6 +415,8 @@ clay_run_suite(const struct clay_suite *suite)
const struct clay_func *test = suite->tests;
size_t i;
+ clay_print_onsuite(suite->name);
+
_clay.active_suite = suite->name;
_clay.suite_errors = 0;
@@ -183,6 +426,7 @@ clay_run_suite(const struct clay_suite *suite)
}
}
+#if 0 /* temporarily disabled */
static void
clay_run_single(const struct clay_func *test,
const struct clay_suite *suite)
@@ -193,24 +437,20 @@ clay_run_single(const struct clay_func *test,
clay_run_test(test, &suite->initialize, &suite->cleanup);
}
+#endif
static void
clay_usage(const char *arg)
{
printf("Usage: %s [options]\n\n", arg);
printf("Options:\n");
- printf(" -tXX\t\tRun only the test number XX\n");
+// printf(" -tXX\t\tRun only the test number XX\n");
printf(" -sXX\t\tRun only the suite number XX\n");
exit(-1);
}
static void
-clay_parse_args(
- int argc, char **argv,
- const struct clay_func *callbacks,
- size_t cb_count,
- const struct clay_suite *suites,
- size_t suite_count)
+clay_parse_args(int argc, char **argv)
{
int i;
@@ -229,27 +469,13 @@ clay_parse_args(
clay_usage(argv[0]);
switch (action) {
- case 't':
- if ((size_t)num >= cb_count) {
- fprintf(stderr, "Test number %d does not exist.\n", num);
- exit(-1);
- }
-
- clay_print("Started (%s::%s)\n",
- suites[callbacks[num].suite_n].name,
- callbacks[num].name);
-
- clay_run_single(&callbacks[num], &suites[callbacks[num].suite_n]);
- break;
-
case 's':
- if ((size_t)num >= suite_count) {
- fprintf(stderr, "Suite number %d does not exist.\n", num);
+ if ((size_t)num >= _clay_suite_count) {
+ clay_print_onabort("Suite number %d does not exist.\n", num);
exit(-1);
}
- clay_print("Started (%s::*)\n", suites[num].name);
- clay_run_suite(&suites[num]);
+ clay_run_suite(&_clay_suites[num]);
break;
default:
@@ -259,15 +485,13 @@ clay_parse_args(
}
static int
-clay_test(
- int argc, char **argv,
- const char *suites_str,
- const struct clay_func *callbacks,
- size_t cb_count,
- const struct clay_suite *suites,
- size_t suite_count)
+clay_test(int argc, char **argv)
{
- clay_print("Loaded %d suites: %s\n", (int)suite_count, suites_str);
+ clay_print_init(
+ (int)_clay_callback_count,
+ (int)_clay_suite_count,
+ ""
+ );
if (clay_sandbox() < 0) {
fprintf(stderr,
@@ -276,21 +500,18 @@ clay_test(
}
if (argc > 1) {
- clay_parse_args(argc, argv,
- callbacks, cb_count, suites, suite_count);
-
+ clay_parse_args(argc, argv);
} else {
size_t i;
- clay_print("Started\n");
-
- for (i = 0; i < suite_count; ++i) {
- const struct clay_suite *s = &suites[i];
- clay_run_suite(s);
- }
+ for (i = 0; i < _clay_suite_count; ++i)
+ clay_run_suite(&_clay_suites[i]);
}
- clay_print("\n\n");
- clay_report_errors();
+ clay_print_shutdown(
+ (int)_clay_callback_count,
+ (int)_clay_suite_count,
+ _clay.total_errors
+ );
clay_unsandbox();
return _clay.total_errors;
@@ -335,7 +556,7 @@ clay__assert(
if (should_abort) {
if (!_clay.trampoline_enabled) {
- fprintf(stderr,
+ clay_print_onabort(
"Fatal error: a cleanup method raised an exception.");
exit(-1);
}
@@ -659,124 +880,68 @@ cl_fs_cleanup(void)
#endif
-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}
-};
+static void clay_print_init(int test_count, int suite_count, const char *suite_names)
+{
+ (void)suite_names;
+ (void)suite_count;
+ printf("TAP version 13\n");
+ printf("1..%d\n", test_count);
+}
-static const struct clay_suite _all_suites[] = {
- {
- "core::dirent",
- {NULL, NULL, 0},
- {NULL, NULL, 0},
- &_all_callbacks[0], 5
- },
- {
- "core::filebuf",
- {NULL, NULL, 0},
- {NULL, NULL, 0},
- &_all_callbacks[5], 3
- },
- {
- "core::oid",
- {"initialize", &test_core_oid__initialize, 2},
- {NULL, NULL, 0},
- &_all_callbacks[8], 1
- },
- {
- "core::path",
- {NULL, NULL, 0},
- {NULL, NULL, 0},
- &_all_callbacks[9], 5
- },
- {
- "core::rmdir",
- {"initialize", &test_core_rmdir__initialize, 4},
- {NULL, NULL, 0},
- &_all_callbacks[14], 2
- },
- {
- "core::string",
- {NULL, NULL, 0},
- {NULL, NULL, 0},
- &_all_callbacks[16], 2
- },
- {
- "core::strtol",
- {NULL, NULL, 0},
- {NULL, NULL, 0},
- &_all_callbacks[18], 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
- },
- {
- "status::worktree",
- {"initialize", &test_status_worktree__initialize, 11},
- {"cleanup", &test_status_worktree__cleanup, 11},
- &_all_callbacks[31], 2
- }
-};
+static void clay_print_shutdown(int test_count, int suite_count, int error_count)
+{
+ (void)test_count;
+ (void)suite_count;
+ (void)error_count;
+
+ printf("\n");
+}
+
+static void clay_print_error(int num, const struct clay_error *error)
+{
+ (void)num;
+
+ printf(" ---\n");
+ printf(" message : %s\n", error->error_msg);
+ printf(" severity: fail\n");
+ printf(" suite : %s\n", error->suite);
+ printf(" test : %s\n", error->test);
+ printf(" file : %s\n", error->file);
+ printf(" line : %d\n", error->line_number);
+
+ if (error->description != NULL)
+ printf(" description: %s\n", error->description);
+
+ printf(" ...\n");
+}
+
+static void clay_print_ontest(const char *test_name, int test_number, int failed)
+{
+ printf("%s %d - %s\n",
+ failed ? "not ok" : "ok",
+ test_number,
+ test_name
+ );
+
+ clay_report_errors();
+}
+
+static void clay_print_onsuite(const char *suite_name)
+{
+ printf("# *** %s ***\n", suite_name);
+}
+
+static void clay_print_onabort(const char *msg, ...)
+{
+ va_list argp;
+ va_start(argp, msg);
+ fprintf(stdout, "Bail out! ");
+ vfprintf(stdout, msg, argp);
+ va_end(argp);
+}
-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";
int _MAIN_CC main(int argc, char *argv[])
{
- return clay_test(
- argc, argv, _suites_str,
- _all_callbacks, 33,
- _all_suites, 12
- );
+ return clay_test(argc, argv);
}
diff --git a/tests-clay/config/stress.c b/tests-clay/config/stress.c
new file mode 100644
index 000000000..7b81400c1
--- /dev/null
+++ b/tests-clay/config/stress.c
@@ -0,0 +1,41 @@
+#include "clay_libgit2.h"
+
+#include "filebuf.h"
+#include "fileops.h"
+#include "posix.h"
+
+#define TEST_CONFIG "git-test-config"
+
+void test_config_stress__initialize(void)
+{
+ git_filebuf file;
+
+ git_filebuf_open(&file, TEST_CONFIG, 0);
+
+ git_filebuf_printf(&file, "[color]\n\tui = auto\n");
+ git_filebuf_printf(&file, "[core]\n\teditor = \n");
+
+ git_filebuf_commit(&file, 0666);
+}
+
+void test_config_stress__cleanup(void)
+{
+ p_unlink(TEST_CONFIG);
+}
+
+void test_config_stress__dont_break_on_invalid_input(void)
+{
+ const char *editor, *color;
+ struct git_config_file *file;
+ git_config *config;
+
+ cl_git_pass(git_futils_exists(TEST_CONFIG));
+ cl_git_pass(git_config_file__ondisk(&file, TEST_CONFIG));
+ cl_git_pass(git_config_new(&config));
+ cl_git_pass(git_config_add_file(config, file, 0));
+
+ cl_git_pass(git_config_get_string(config, "color.ui", &color));
+ cl_git_pass(git_config_get_string(config, "core.editor", &editor));
+
+ git_config_free(config);
+}
diff --git a/tests-clay/core/dirent.c b/tests-clay/core/dirent.c
index 73f571595..105e8d8f0 100644
--- a/tests-clay/core/dirent.c
+++ b/tests-clay/core/dirent.c
@@ -20,18 +20,18 @@ static void setup(walk_data *d)
{
name_data *n;
- cl_must_pass(p_mkdir(top_dir, 0755));
+ cl_must_pass(p_mkdir(top_dir, 0777));
cl_must_pass(p_chdir(top_dir));
if (strcmp(d->sub, ".") != 0)
- cl_must_pass(p_mkdir(d->sub, 0755));
+ cl_must_pass(p_mkdir(d->sub, 0777));
strcpy(path_buffer, d->sub);
state_loc = d;
for (n = d->names; n->name; n++) {
- git_file fd = p_creat(n->name, 0600);
+ git_file fd = p_creat(n->name, 0666);
cl_assert(fd >= 0);
p_close(fd);
n->count = 0;
diff --git a/tests-clay/core/filebuf.c b/tests-clay/core/filebuf.c
index e00e20497..e1ecb2798 100644
--- a/tests-clay/core/filebuf.c
+++ b/tests-clay/core/filebuf.c
@@ -27,14 +27,14 @@ void test_core_filebuf__1(void)
int fd;
char test[] = "test";
- fd = p_creat(test, 0644);
+ fd = p_creat(test, 0666);
cl_must_pass(fd);
cl_must_pass(p_write(fd, "libgit2 rocks\n", 14));
cl_must_pass(p_close(fd));
cl_git_pass(git_filebuf_open(&file, test, GIT_FILEBUF_APPEND));
cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks"));
- cl_git_pass(git_filebuf_commit(&file));
+ cl_git_pass(git_filebuf_commit(&file, 0666));
cl_must_pass(p_unlink(test));
}
@@ -51,7 +51,7 @@ void test_core_filebuf__2(void)
cl_git_pass(git_filebuf_open(&file, test, 0));
cl_git_pass(git_filebuf_write(&file, buf, sizeof(buf)));
- cl_git_pass(git_filebuf_commit(&file));
+ cl_git_pass(git_filebuf_commit(&file, 0666));
cl_must_pass(p_unlink(test));
}
diff --git a/tests-clay/core/path.c b/tests-clay/core/path.c
index db8f33d21..c394c7285 100644
--- a/tests-clay/core/path.c
+++ b/tests-clay/core/path.c
@@ -11,7 +11,7 @@ check_dirname(const char *A, const char *B)
cl_assert((dir2 = git_path_dirname(A)) != NULL);
cl_assert(strcmp(dir2, B) == 0);
- free(dir2);
+ git__free(dir2);
}
static void
@@ -24,7 +24,7 @@ check_basename(const char *A, const char *B)
cl_assert((base2 = git_path_basename(A)) != NULL);
cl_assert(strcmp(base2, B) == 0);
- free(base2);
+ git__free(base2);
}
static void
diff --git a/tests-clay/core/rmdir.c b/tests-clay/core/rmdir.c
index aa21c6a3d..20cc8f5f0 100644
--- a/tests-clay/core/rmdir.c
+++ b/tests-clay/core/rmdir.c
@@ -7,22 +7,22 @@ void test_core_rmdir__initialize(void)
{
char path[GIT_PATH_MAX];
- cl_must_pass(p_mkdir(empty_tmp_dir, 0755));
+ cl_must_pass(p_mkdir(empty_tmp_dir, 0777));
git_path_join(path, empty_tmp_dir, "/one");
- cl_must_pass(p_mkdir(path, 0755));
+ cl_must_pass(p_mkdir(path, 0777));
git_path_join(path, empty_tmp_dir, "/one/two_one");
- cl_must_pass(p_mkdir(path, 0755));
+ cl_must_pass(p_mkdir(path, 0777));
git_path_join(path, empty_tmp_dir, "/one/two_two");
- cl_must_pass(p_mkdir(path, 0755));
+ cl_must_pass(p_mkdir(path, 0777));
git_path_join(path, empty_tmp_dir, "/one/two_two/three");
- cl_must_pass(p_mkdir(path, 0755));
+ cl_must_pass(p_mkdir(path, 0777));
git_path_join(path, empty_tmp_dir, "/two");
- cl_must_pass(p_mkdir(path, 0755));
+ cl_must_pass(p_mkdir(path, 0777));
}
/* make sure empty dir can be deleted recusively */
@@ -39,7 +39,7 @@ void test_core_rmdir__fail_to_delete_non_empty_dir(void)
git_path_join(file, empty_tmp_dir, "/two/file.txt");
- fd = p_creat(file, 0755);
+ fd = p_creat(file, 0666);
cl_assert(fd >= 0);
cl_must_pass(p_close(fd));
diff --git a/tests-clay/core/vector.c b/tests-clay/core/vector.c
index 44e6d873d..b8a853c60 100644
--- a/tests-clay/core/vector.c
+++ b/tests-clay/core/vector.c
@@ -59,8 +59,8 @@ void test_core_vector__2(void)
git_vector_free(&x);
- free(ptrs[0]);
- free(ptrs[1]);
+ git__free(ptrs[0]);
+ git__free(ptrs[1]);
}
diff --git a/tests-clay/index/rename.c b/tests-clay/index/rename.c
new file mode 100644
index 000000000..ba72b62f7
--- /dev/null
+++ b/tests-clay/index/rename.c
@@ -0,0 +1,60 @@
+#include "clay_libgit2.h"
+#include "posix.h"
+
+static void file_create(const char *filename, const char *content)
+{
+ int fd;
+
+ fd = p_creat(filename, 0666);
+ cl_assert(fd != 0);
+ cl_git_pass(p_write(fd, content, strlen(content)));
+ cl_git_pass(p_close(fd))
+}
+
+void test_index_rename__single_file(void)
+{
+ git_repository *repo;
+ git_index *index;
+ int position;
+ git_oid expected;
+ git_index_entry *entry;
+
+ p_mkdir("rename", 0700);
+
+ cl_git_pass(git_repository_init(&repo, "./rename", 0));
+ cl_git_pass(git_repository_index(&index, repo));
+
+ cl_assert(git_index_entrycount(index) == 0);
+
+ file_create("./rename/lame.name.txt", "new_file\n");
+
+ /* This should add a new blob to the object database in 'd4/fa8600b4f37d7516bef4816ae2c64dbf029e3a' */
+ cl_git_pass(git_index_add(index, "lame.name.txt", 0));
+ cl_assert(git_index_entrycount(index) == 1);
+
+ cl_git_pass(git_oid_fromstr(&expected, "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a"));
+
+ position = git_index_find(index, "lame.name.txt");
+
+ entry = git_index_get(index, position);
+ cl_assert(git_oid_cmp(&expected, &entry->oid) == 0);
+
+ /* This removes the entry from the index, but not from the object database */
+ cl_git_pass(git_index_remove(index, position));
+ cl_assert(git_index_entrycount(index) == 0);
+
+ p_rename("./rename/lame.name.txt", "./rename/fancy.name.txt");
+
+ cl_git_pass(git_index_add(index, "fancy.name.txt", 0));
+ cl_assert(git_index_entrycount(index) == 1);
+
+ position = git_index_find(index, "fancy.name.txt");
+
+ entry = git_index_get(index, position);
+ cl_assert(git_oid_cmp(&expected, &entry->oid) == 0);
+
+ git_index_free(index);
+ git_repository_free(repo);
+
+ cl_fixture_cleanup("rename");
+}
diff --git a/tests-clay/object/raw/chars.c b/tests-clay/object/raw/chars.c
new file mode 100644
index 000000000..eba352b40
--- /dev/null
+++ b/tests-clay/object/raw/chars.c
@@ -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)));
+}
diff --git a/tests-clay/object/raw/compare.c b/tests-clay/object/raw/compare.c
new file mode 100644
index 000000000..94b196945
--- /dev/null
+++ b/tests-clay/object/raw/compare.c
@@ -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);
+ git__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);
+}
diff --git a/tests-clay/object/raw/convert.c b/tests-clay/object/raw/convert.c
new file mode 100644
index 000000000..f69f5f924
--- /dev/null
+++ b/tests-clay/object/raw/convert.c
@@ -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');
+}
diff --git a/tests-clay/object/raw/data.h b/tests-clay/object/raw/data.h
new file mode 100644
index 000000000..cf23819f1
--- /dev/null
+++ b/tests-clay/object/raw/data.h
@@ -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
+};
diff --git a/tests-clay/object/raw/fromstr.c b/tests-clay/object/raw/fromstr.c
new file mode 100644
index 000000000..6d732d4eb
--- /dev/null
+++ b/tests-clay/object/raw/fromstr.c
@@ -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)));
+
+}
diff --git a/tests-clay/object/raw/hash.c b/tests-clay/object/raw/hash.c
new file mode 100644
index 000000000..9974ed6ef
--- /dev/null
+++ b/tests-clay/object/raw/hash.c
@@ -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);
+}
diff --git a/tests-clay/object/raw/short.c b/tests-clay/object/raw/short.c
new file mode 100644
index 000000000..996f3f7b4
--- /dev/null
+++ b/tests-clay/object/raw/short.c
@@ -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)
+ git__free(oids[i]);
+
+ git_oid_shorten_free(os);
+
+#undef MAX_OIDS
+}
diff --git a/tests-clay/object/raw/size.c b/tests-clay/object/raw/size.c
new file mode 100644
index 000000000..44c5b6cd1
--- /dev/null
+++ b/tests-clay/object/raw/size.c
@@ -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);
+}
diff --git a/tests-clay/object/raw/type2string.c b/tests-clay/object/raw/type2string.c
new file mode 100644
index 000000000..109bc1112
--- /dev/null
+++ b/tests-clay/object/raw/type2string.c
@@ -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);
+}
diff --git a/tests-clay/object/tree/frompath.c b/tests-clay/object/tree/frompath.c
index 23cb416fe..651a86d86 100644
--- a/tests-clay/object/tree/frompath.c
+++ b/tests-clay/object/tree/frompath.c
@@ -30,7 +30,7 @@ static void assert_tree_from_path(git_tree *root, const char *path, int expected
{
git_tree *containing_tree = NULL;
- cl_assert(git_tree_frompath(&containing_tree, root, path) == expected_result);
+ cl_assert(git_tree_get_subtree(&containing_tree, root, path) == expected_result);
if (containing_tree == NULL && expected_result != GIT_SUCCESS)
return;
diff --git a/tests-clay/status/single.c b/tests-clay/status/single.c
index ea1c77fa0..4fd6e6ff4 100644
--- a/tests-clay/status/single.c
+++ b/tests-clay/status/single.c
@@ -10,7 +10,7 @@ cleanup__remove_file(void *_file)
static void
file_create(const char *filename, const char *content)
{
- int fd = p_creat(filename, 0644);
+ int fd = p_creat(filename, 0666);
cl_assert(fd >= 0);
cl_must_pass(p_write(fd, content, strlen(content)));
cl_must_pass(p_close(fd));
diff --git a/tests-clay/status/worktree.c b/tests-clay/status/worktree.c
index 74dfd4898..7d120ecb5 100644
--- a/tests-clay/status/worktree.c
+++ b/tests-clay/status/worktree.c
@@ -71,7 +71,7 @@ void test_status_worktree__initialize(void)
* inside the fixtures folder in our libgit2 repo.
*/
cl_git_pass(
- git_futils_mv_atomic("status/.gitted", "status/.git")
+ p_rename("status/.gitted", "status/.git")
);
/*