summaryrefslogtreecommitdiff
path: root/tests-clay
diff options
context:
space:
mode:
authorVicent Martí <tanoku@gmail.com>2012-01-04 22:40:59 +0100
committerVicent Martí <tanoku@gmail.com>2012-01-04 22:43:11 +0100
commitf2114d0a35b95efef294f7527dfd64fbef61d993 (patch)
treeccb5ed2313c8d660cefb3730cd9ca279361ff927 /tests-clay
parentb0df89d90b4c2aee6e7083031a93667ff9c85ab3 (diff)
parente2580375dc76f46dce9963225449fcc872e86b0b (diff)
downloadlibgit2-f2114d0a35b95efef294f7527dfd64fbef61d993.tar.gz
Merge remote-tracking branch 'nulltoken/topix/path_fromurl' into development
Conflicts: tests-clay/clay.h tests-clay/clay_main.c
Diffstat (limited to 'tests-clay')
-rw-r--r--tests-clay/core/hex.c22
-rw-r--r--tests-clay/core/path.c77
-rw-r--r--tests-clay/network/remotelocal.c52
-rw-r--r--tests-clay/object/raw/chars.c15
4 files changed, 138 insertions, 28 deletions
diff --git a/tests-clay/core/hex.c b/tests-clay/core/hex.c
new file mode 100644
index 000000000..391a286be
--- /dev/null
+++ b/tests-clay/core/hex.c
@@ -0,0 +1,22 @@
+#include "clay_libgit2.h"
+#include "util.h"
+
+void test_core_hex__fromhex(void)
+{
+ /* Passing cases */
+ cl_assert(git__fromhex('0') == 0x0);
+ cl_assert(git__fromhex('1') == 0x1);
+ cl_assert(git__fromhex('3') == 0x3);
+ cl_assert(git__fromhex('9') == 0x9);
+ cl_assert(git__fromhex('A') == 0xa);
+ cl_assert(git__fromhex('C') == 0xc);
+ cl_assert(git__fromhex('F') == 0xf);
+ cl_assert(git__fromhex('a') == 0xa);
+ cl_assert(git__fromhex('c') == 0xc);
+ cl_assert(git__fromhex('f') == 0xf);
+
+ /* Failing cases */
+ cl_assert(git__fromhex('g') == -1);
+ cl_assert(git__fromhex('z') == -1);
+ cl_assert(git__fromhex('X') == -1);
+}
diff --git a/tests-clay/core/path.c b/tests-clay/core/path.c
index 49f85f085..bdebfb9c5 100644
--- a/tests-clay/core/path.c
+++ b/tests-clay/core/path.c
@@ -70,7 +70,7 @@ check_joinpath_n(
/* get the dirname of a path */
-void test_core_path__0_dirname(void)
+void test_core_path__00_dirname(void)
{
check_dirname(NULL, ".");
check_dirname("", ".");
@@ -90,7 +90,7 @@ void test_core_path__0_dirname(void)
}
/* get the base name of a path */
-void test_core_path__1_basename(void)
+void test_core_path__01_basename(void)
{
check_basename(NULL, ".");
check_basename("", ".");
@@ -107,7 +107,7 @@ void test_core_path__1_basename(void)
}
/* get the latest component in a path */
-void test_core_path__2_topdir(void)
+void test_core_path__02_topdir(void)
{
check_topdir(".git/", ".git/");
check_topdir("/.git/", ".git/");
@@ -124,7 +124,7 @@ void test_core_path__2_topdir(void)
}
/* properly join path components */
-void test_core_path__5_joins(void)
+void test_core_path__05_joins(void)
{
check_joinpath("", "", "");
check_joinpath("", "a", "a");
@@ -159,7 +159,7 @@ void test_core_path__5_joins(void)
}
/* properly join path components for more than one path */
-void test_core_path__6_long_joins(void)
+void test_core_path__06_long_joins(void)
{
check_joinpath_n("", "", "", "", "");
check_joinpath_n("", "a", "", "", "a/");
@@ -212,7 +212,7 @@ check_string_to_dir(
}
/* convert paths to dirs */
-void test_core_path__7_path_to_dir(void)
+void test_core_path__07_path_to_dir(void)
{
check_path_to_dir("", "");
check_path_to_dir(".", "./");
@@ -240,7 +240,7 @@ void test_core_path__7_path_to_dir(void)
}
/* join path to itself */
-void test_core_path__8_self_join(void)
+void test_core_path__08_self_join(void)
{
git_buf path = GIT_BUF_INIT;
ssize_t asize = 0;
@@ -273,3 +273,66 @@ void test_core_path__8_self_join(void)
git_buf_free(&path);
}
+
+static void check_percent_decoding(const char *expected_result, const char *input)
+{
+ git_buf buf = GIT_BUF_INIT;
+
+ cl_git_pass(git__percent_decode(&buf, input));
+ cl_assert_strequal(expected_result, git_buf_cstr(&buf));
+
+ git_buf_free(&buf);
+}
+
+void test_core_path__09_percent_decode(void)
+{
+ check_percent_decoding("abcd", "abcd");
+ check_percent_decoding("a2%", "a2%");
+ check_percent_decoding("a2%3", "a2%3");
+ check_percent_decoding("a2%%3", "a2%%3");
+ check_percent_decoding("a2%3z", "a2%3z");
+ check_percent_decoding("a,", "a%2c");
+ check_percent_decoding("a21", "a2%31");
+ check_percent_decoding("a2%1", "a2%%31");
+ check_percent_decoding("a bc ", "a%20bc%20");
+ check_percent_decoding("Vicent Mart" "\355", "Vicent%20Mart%ED");
+}
+
+static void check_fromurl(const char *expected_result, const char *input, int should_fail)
+{
+ git_buf buf = GIT_BUF_INIT;
+
+ assert(should_fail || expected_result);
+
+ if (!should_fail) {
+ cl_git_pass(git_path_fromurl(&buf, input));
+ cl_assert_strequal(expected_result, git_buf_cstr(&buf));
+ } else
+ cl_git_fail(git_path_fromurl(&buf, input));
+
+ git_buf_free(&buf);
+}
+
+#ifdef _MSC_VER
+#define ABS_PATH_MARKER ""
+#else
+#define ABS_PATH_MARKER "/"
+#endif
+
+void test_core_path__10_fromurl(void)
+{
+ /* Failing cases */
+ check_fromurl(NULL, "a", 1);
+ check_fromurl(NULL, "http:///c:/Temp%20folder/note.txt", 1);
+ check_fromurl(NULL, "file://c:/Temp%20folder/note.txt", 1);
+ check_fromurl(NULL, "file:////c:/Temp%20folder/note.txt", 1);
+ check_fromurl(NULL, "file:///", 1);
+ check_fromurl(NULL, "file:////", 1);
+ check_fromurl(NULL, "file://servername/c:/Temp%20folder/note.txt", 1);
+
+ /* Passing cases */
+ check_fromurl(ABS_PATH_MARKER "c:/Temp folder/note.txt", "file:///c:/Temp%20folder/note.txt", 0);
+ check_fromurl(ABS_PATH_MARKER "c:/Temp folder/note.txt", "file://localhost/c:/Temp%20folder/note.txt", 0);
+ check_fromurl(ABS_PATH_MARKER "c:/Temp+folder/note.txt", "file:///c:/Temp+folder/note.txt", 0);
+ check_fromurl(ABS_PATH_MARKER "a", "file:///a", 0);
+}
diff --git a/tests-clay/network/remotelocal.c b/tests-clay/network/remotelocal.c
index b9003e7ca..961c623a1 100644
--- a/tests-clay/network/remotelocal.c
+++ b/tests-clay/network/remotelocal.c
@@ -2,6 +2,7 @@
#include "transport.h"
#include "buffer.h"
#include "path.h"
+#include "posix.h"
static git_repository *repo;
static git_buf file_path_buf = GIT_BUF_INIT;
@@ -9,9 +10,11 @@ static git_remote *remote;
static void build_local_file_url(git_buf *out, const char *fixture)
{
+ const char *in_buf;
+
git_buf path_buf = GIT_BUF_INIT;
- cl_git_pass(git_path_prettify_dir(&path_buf, cl_fixture(fixture), NULL));
+ cl_git_pass(git_path_prettify_dir(&path_buf, fixture, NULL));
cl_git_pass(git_buf_puts(out, "file://"));
#ifdef _MSC_VER
@@ -27,21 +30,27 @@ static void build_local_file_url(git_buf *out, const char *fixture)
cl_git_pass(git_buf_putc(out, '/'));
#endif
- cl_git_pass(git_buf_puts(out, git_buf_cstr(&path_buf)));
+ in_buf = git_buf_cstr(&path_buf);
+
+ /*
+ * A very hacky Url encoding that only takes care of escaping the spaces
+ */
+ while (*in_buf) {
+ if (*in_buf == ' ')
+ cl_git_pass(git_buf_puts(out, "%20"));
+ else
+ cl_git_pass(git_buf_putc(out, *in_buf));
+
+ in_buf++;
+ }
git_buf_free(&path_buf);
}
void test_network_remotelocal__initialize(void)
{
- cl_fixture("remotelocal");
cl_git_pass(git_repository_init(&repo, "remotelocal/", 0));
cl_assert(repo != NULL);
-
- build_local_file_url(&file_path_buf, "testrepo.git");
-
- cl_git_pass(git_remote_new(&remote, repo, git_buf_cstr(&file_path_buf), NULL));
- cl_git_pass(git_remote_connect(remote, GIT_DIR_FETCH));
}
void test_network_remotelocal__cleanup(void)
@@ -62,11 +71,38 @@ static int count_ref__cb(git_remote_head *head, void *payload)
return GIT_SUCCESS;
}
+static void connect_to_local_repository(const char *local_repository)
+{
+ build_local_file_url(&file_path_buf, local_repository);
+
+ cl_git_pass(git_remote_new(&remote, repo, git_buf_cstr(&file_path_buf), NULL));
+ cl_git_pass(git_remote_connect(remote, GIT_DIR_FETCH));
+
+}
+
void test_network_remotelocal__retrieve_advertised_references(void)
{
int how_many_refs = 0;
+ connect_to_local_repository(cl_fixture("testrepo.git"));
+
cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
cl_assert(how_many_refs == 12); /* 1 HEAD + 9 refs + 2 peeled tags */
}
+
+void test_network_remotelocal__retrieve_advertised_references_from_spaced_repository(void)
+{
+ int how_many_refs = 0;
+
+ cl_fixture_sandbox("testrepo.git");
+ cl_git_pass(p_rename("testrepo.git", "spaced testrepo.git"));
+
+ connect_to_local_repository("spaced testrepo.git");
+
+ cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
+
+ cl_assert(how_many_refs == 12); /* 1 HEAD */
+
+ cl_fixture_cleanup("spaced testrepo.git");
+}
diff --git a/tests-clay/object/raw/chars.c b/tests-clay/object/raw/chars.c
index eba352b40..83bcbeb79 100644
--- a/tests-clay/object/raw/chars.c
+++ b/tests-clay/object/raw/chars.c
@@ -3,17 +3,6 @@
#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;
@@ -28,8 +17,8 @@ void test_object_raw_chars__find_invalid_chars_in_oid(void)
for (i = 0; i < 256; i++) {
in[38] = (char)i;
- if (from_hex(i) >= 0) {
- exp[19] = (unsigned char)(from_hex(i) << 4);
+ if (git__fromhex(i) >= 0) {
+ exp[19] = (unsigned char)(git__fromhex(i) << 4);
cl_git_pass(git_oid_fromstr(&out, in));
cl_assert(memcmp(out.id, exp, sizeof(out.id)) == 0);
} else {