/* convert paths to dirs */ void test_core_path__07_path_to_dir(void) { check_path_to_dir("", ""); check_path_to_dir(".", "./"); check_path_to_dir("./", "./"); check_path_to_dir("a/", "a/"); check_path_to_dir("ab", "ab/"); /* make sure we try just under and just over an expansion that will * require a realloc */ check_path_to_dir("abcdef", "abcdef/"); check_path_to_dir("abcdefg", "abcdefg/"); check_path_to_dir("abcdefgh", "abcdefgh/"); check_path_to_dir("abcdefghi", "abcdefghi/"); check_path_to_dir(REP1024("abcd") "/", REP1024("abcd") "/"); check_path_to_dir(REP1024("abcd"), REP1024("abcd") "/"); check_string_to_dir("", 1, ""); check_string_to_dir(".", 1, "."); check_string_to_dir(".", 2, "./"); check_string_to_dir(".", 3, "./"); check_string_to_dir("abcd", 3, "abcd"); check_string_to_dir("abcd", 4, "abcd"); check_string_to_dir("abcd", 5, "abcd/"); check_string_to_dir("abcd", 6, "abcd/"); }
/* get the base name of a path */ void test_core_path__01_basename(void) { check_basename(NULL, "."); check_basename("", "."); check_basename("a", "a"); check_basename("/", "/"); check_basename("/usr", "usr"); check_basename("/usr/", "usr"); check_basename("/usr/lib", "lib"); check_basename("/usr/lib//", "lib"); check_basename("usr/lib", "lib"); check_basename(REP16("/abc"), "abc"); check_basename(REP1024("/abc"), "abc"); }
void test_object_tree_write__cruel_paths(void) { static const char *the_paths[] = { "C:\\", " : * ? \" \n < > |", "a\\b", "\\\\b\a", ":\\", "COM1", "foo.aux", REP1024("1234"), /* 4096 char string */ REP1024("12345678"), /* 8192 char string */ "\xC5\xAA\x6E\xC4\xAD\x63\xC5\x8D\x64\x65\xCC\xBD", /* Ūnĭcōde̽ */ NULL }; git_treebuilder *builder; git_tree *tree; git_oid id, bid, subid; const char **scan; int count = 0, i, j; git_tree_entry *te; git_oid_fromstr(&bid, blob_oid); /* create tree */ cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL)); for (scan = the_paths; *scan; ++scan) { cl_git_pass(git_treebuilder_insert( NULL, builder, *scan, &bid, GIT_FILEMODE_BLOB)); count++; } cl_git_pass(git_treebuilder_write(&id, builder)); git_treebuilder_free(builder); /* check data is correct */ cl_git_pass(git_tree_lookup(&tree, g_repo, &id)); cl_assert_equal_i(count, git_tree_entrycount(tree)); for (scan = the_paths; *scan; ++scan) { const git_tree_entry *cte = git_tree_entry_byname(tree, *scan); cl_assert(cte != NULL); cl_assert_equal_s(*scan, git_tree_entry_name(cte)); } for (scan = the_paths; *scan; ++scan) { cl_git_pass(git_tree_entry_bypath(&te, tree, *scan)); cl_assert_equal_s(*scan, git_tree_entry_name(te)); git_tree_entry_free(te); } git_tree_free(tree); /* let's try longer paths */ cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL)); for (scan = the_paths; *scan; ++scan) { cl_git_pass(git_treebuilder_insert( NULL, builder, *scan, &id, GIT_FILEMODE_TREE)); } cl_git_pass(git_treebuilder_write(&subid, builder)); git_treebuilder_free(builder); /* check data is correct */ cl_git_pass(git_tree_lookup(&tree, g_repo, &subid)); cl_assert_equal_i(count, git_tree_entrycount(tree)); for (i = 0; i < count; ++i) { for (j = 0; j < count; ++j) { git_buf b = GIT_BUF_INIT; cl_git_pass(git_buf_joinpath(&b, the_paths[i], the_paths[j])); cl_git_pass(git_tree_entry_bypath(&te, tree, b.ptr)); cl_assert_equal_s(the_paths[j], git_tree_entry_name(te)); git_tree_entry_free(te); git_buf_free(&b); } } git_tree_free(tree); }
/* properly join path components for more than one path */ void test_core_path__06_long_joins(void) { check_joinpath_n("", "", "", "", ""); check_joinpath_n("", "a", "", "", "a/"); check_joinpath_n("a", "", "", "", "a/"); check_joinpath_n("", "", "", "a", "a"); check_joinpath_n("a", "b", "", "/c/d/", "a/b/c/d/"); check_joinpath_n("a", "b", "", "/c/d", "a/b/c/d"); check_joinpath_n("abcd", "efgh", "ijkl", "mnop", "abcd/efgh/ijkl/mnop"); check_joinpath_n("abcd/", "efgh/", "ijkl/", "mnop/", "abcd/efgh/ijkl/mnop/"); check_joinpath_n("/abcd/", "/efgh/", "/ijkl/", "/mnop/", "/abcd/efgh/ijkl/mnop/"); check_joinpath_n(REP1024("a"), REP1024("b"), REP1024("c"), REP1024("d"), REP1024("a") "/" REP1024("b") "/" REP1024("c") "/" REP1024("d")); check_joinpath_n(REP1024("/a"), REP1024("/b"), REP1024("/c"), REP1024("/d"), REP1024("/a") REP1024("/b") REP1024("/c") REP1024("/d")); }
/* properly join path components */ void test_core_path__05_joins(void) { check_joinpath("", "", ""); check_joinpath("", "a", "a"); check_joinpath("", "/a", "/a"); check_joinpath("a", "", "a/"); check_joinpath("a", "/", "a/"); check_joinpath("a", "b", "a/b"); check_joinpath("/", "a", "/a"); check_joinpath("/", "", "/"); check_joinpath("/a", "/b", "/a/b"); check_joinpath("/a", "/b/", "/a/b/"); check_joinpath("/a/", "b/", "/a/b/"); check_joinpath("/a/", "/b/", "/a/b/"); check_joinpath("/abcd", "/defg", "/abcd/defg"); check_joinpath("/abcd", "/defg/", "/abcd/defg/"); check_joinpath("/abcd/", "defg/", "/abcd/defg/"); check_joinpath("/abcd/", "/defg/", "/abcd/defg/"); check_joinpath("/abcdefgh", "/12345678", "/abcdefgh/12345678"); check_joinpath("/abcdefgh", "/12345678/", "/abcdefgh/12345678/"); check_joinpath("/abcdefgh/", "12345678/", "/abcdefgh/12345678/"); check_joinpath(REP1024("aaaa"), "", REP1024("aaaa") "/"); check_joinpath(REP1024("aaaa/"), "", REP1024("aaaa/")); check_joinpath(REP1024("/aaaa"), "", REP1024("/aaaa") "/"); check_joinpath(REP1024("aaaa"), REP1024("bbbb"), REP1024("aaaa") "/" REP1024("bbbb")); check_joinpath(REP1024("/aaaa"), REP1024("/bbbb"), REP1024("/aaaa") REP1024("/bbbb")); }